📄 qtextformat.cpp
字号:
}/*! Merges the \a other format with this format; where there are conflicts the \a other format takes precedence.*/void QTextFormat::merge(const QTextFormat &other){ if (format_type != other.format_type) return; if (!d) { d = other.d; return; } if (!other.d) return; // don't use QMap's += operator, as it uses insertMulti! for (QTextFormatPrivate::PropertyMap::ConstIterator it = other.d->properties().begin(); it != other.d->properties().end(); ++it) { d->insertProperty(it.key(), it.value()); }}/*! Returns the type of this format. \sa ObjectTypes*/int QTextFormat::type() const{ return format_type;}/*! Returns this format as a block format.*/QTextBlockFormat QTextFormat::toBlockFormat() const{ QTextBlockFormat f; f.QTextFormat::operator=(*this); return f;}/*! Returns this format as a character format.*/QTextCharFormat QTextFormat::toCharFormat() const{ QTextCharFormat f; f.QTextFormat::operator=(*this); return f;}/*! Returns this format as a list format.*/QTextListFormat QTextFormat::toListFormat() const{ QTextListFormat f; f.QTextFormat::operator=(*this); return f;}/*! Returns this format as a table format.*/QTextTableFormat QTextFormat::toTableFormat() const{ QTextTableFormat f; f.QTextFormat::operator=(*this); return f;}/*! Returns this format as a frame format.*/QTextFrameFormat QTextFormat::toFrameFormat() const{ QTextFrameFormat f; f.QTextFormat::operator=(*this); return f;}/*! Returns this format as an image format.*/QTextImageFormat QTextFormat::toImageFormat() const{ QTextImageFormat f; f.QTextFormat::operator=(*this); return f;}/*! Returns the value of the property specified by \a propertyId. If the property isn't of QTextFormat::Bool type, false is returned instead. \sa setProperty() intProperty() doubleProperty() stringProperty() colorProperty() lengthProperty() lengthVectorProperty() Property*/bool QTextFormat::boolProperty(int propertyId) const{ if (!d) return false; const QVariant prop = d->properties().value(propertyId); if (prop.type() != QVariant::Bool) return false; return prop.toBool();}/*! Returns the value of the property specified by \a propertyId. If the property is not of QTextFormat::Integer type, 0 is returned instead. \sa setProperty() boolProperty() doubleProperty() stringProperty() colorProperty() lengthProperty() lengthVectorProperty() Property*/int QTextFormat::intProperty(int propertyId) const{ if (!d) return 0; const QVariant prop = d->properties().value(propertyId); if (prop.type() != QVariant::Int) return 0; return prop.toInt();}/*! Returns the value of the property specified by \a propertyId. If the property isn't of QVariant::Double type, 0 is returned instead. \sa setProperty() boolProperty() intProperty() stringProperty() colorProperty() lengthProperty() lengthVectorProperty() Property*/qreal QTextFormat::doubleProperty(int propertyId) const{ if (!d) return 0.; const QVariant prop = d->properties().value(propertyId); if (prop.type() != QVariant::Double) return 0.; return prop.toDouble(); // ####}/*! Returns the value of the property given by \a propertyId; if the property isn't of QVariant::String type, an empty string is returned instead. \sa setProperty() boolProperty() intProperty() doubleProperty() colorProperty() lengthProperty() lengthVectorProperty() Property*/QString QTextFormat::stringProperty(int propertyId) const{ if (!d) return QString(); const QVariant prop = d->properties().value(propertyId); if (prop.type() != QVariant::String) return QString(); return prop.toString();}/*! Returns the value of the property given by \a propertyId; if the property isn't of QVariant::Color type, an invalid color is returned instead. \sa setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(), lengthProperty(), lengthVectorProperty(), Property*/QColor QTextFormat::colorProperty(int propertyId) const{ if (!d) return QColor(); const QVariant prop = d->properties().value(propertyId); if (prop.type() != QVariant::Color) return QColor(); return qvariant_cast<QColor>(prop);}/*! Returns the value of the property given by \a propertyId; if the property isn't of QVariant::Pen type, Qt::NoPen is returned instead. \sa setProperty() boolProperty() intProperty() doubleProperty() stringProperty() lengthProperty() lengthVectorProperty() Property*/QPen QTextFormat::penProperty(int propertyId) const{ if (!d) return QPen(Qt::NoPen); const QVariant prop = d->properties().value(propertyId); if (prop.type() != QVariant::Pen) return QPen(Qt::NoPen); return qvariant_cast<QPen>(prop);}/*! Returns the value of the property given by \a propertyId; if the property isn't of QVariant::Brush type, Qt::NoBrush is returned instead. \sa setProperty() boolProperty() intProperty() doubleProperty() stringProperty() lengthProperty() lengthVectorProperty() Property*/QBrush QTextFormat::brushProperty(int propertyId) const{ if (!d) return QBrush(Qt::NoBrush); const QVariant prop = d->properties().value(propertyId); if (prop.type() != QVariant::Brush) return QBrush(Qt::NoBrush); return qvariant_cast<QBrush>(prop);}/*! Returns the value of the property given by \a propertyId. \sa setProperty() boolProperty() intProperty() doubleProperty() stringProperty() colorProperty() lengthVectorProperty() Property*/QTextLength QTextFormat::lengthProperty(int propertyId) const{ if (!d) return QTextLength(); return qvariant_cast<QTextLength>(d->properties().value(propertyId));}/*! Returns the value of the property given by \a propertyId. If the property isn't of QTextFormat::LengthVector type, an empty length vector is returned instead. \sa setProperty() boolProperty() intProperty() doubleProperty() stringProperty() colorProperty() lengthProperty() Property*/QVector<QTextLength> QTextFormat::lengthVectorProperty(int propertyId) const{ QVector<QTextLength> vector; if (!d) return vector; const QVariant prop = d->properties().value(propertyId); if (prop.type() != QVariant::List) return vector; QList<QVariant> propertyList = prop.toList(); for (int i=0; i<propertyList.size(); ++i) { QVariant var = propertyList.at(i); if (var.type() == QVariant::TextLength) vector.append(qvariant_cast<QTextLength>(var)); } return vector;}/*! Returns the property specified by the given \a propertyId.*/QVariant QTextFormat::property(int propertyId) const{ return d ? d->properties().value(propertyId) : QVariant();}/*! Sets the property specified by the \a propertyId to the given \a value.*/void QTextFormat::setProperty(int propertyId, const QVariant &value){ if (!d) d = new QTextFormatPrivate; if (!value.isValid()) clearProperty(propertyId); else d->insertProperty(propertyId, value);}/*! Sets the value of the property given by \a propertyId to \a value. \sa lengthVectorProperty() Property*/void QTextFormat::setProperty(int propertyId, const QVector<QTextLength> &value){ if (!d) d = new QTextFormatPrivate; QVariantList list; for (int i=0; i<value.size(); ++i) list << value.at(i); d->insertProperty(propertyId, list);}/*! Clears the value of the property given by \a propertyId */void QTextFormat::clearProperty(int propertyId){ if (!d) return; d->clearProperty(propertyId);}/*! \fn void QTextFormat::setObjectType(int type) Sets the text format's object \a type. See \c{ObjectTypes}.*//*! \fn int QTextFormat::objectType() const Returns the text format's object type. See \c{ObjectTypes}.*//*! Returns the index of the format object, or -1 if the format object is invalid. \sa setObjectIndex()*/int QTextFormat::objectIndex() const{ if (!d) return -1; const QVariant prop = d->properties().value(ObjectIndex); if (prop.type() != QVariant::Int) // #### return -1; return prop.toInt();}/*! \fn void QTextFormat::setObjectIndex(int index) Sets the format object's object \a index. \sa objectIndex()*/void QTextFormat::setObjectIndex(int o){ if (o == -1) { if (d) d->clearProperty(ObjectIndex); } else { if (!d) d = new QTextFormatPrivate; // ### type d->insertProperty(ObjectIndex, o); }}/*! Returns true if the text format has a property with the given \a propertyId; otherwise returns false. \sa properties() Property*/bool QTextFormat::hasProperty(int propertyId) const{ return d ? d->properties().contains(propertyId) : false;}/* Returns the property type for the given \a propertyId. \sa hasProperty() allPropertyIds() Property*//*! Returns a map with all properties of this text format.*/QMap<int, QVariant> QTextFormat::properties() const{ return d ? d->properties() : QMap<int, QVariant>();}/*! \fn bool QTextFormat::operator!=(const QTextFormat &other) const Returns true if this text format is different from the \a other text format.*//*! \fn bool QTextFormat::operator==(const QTextFormat &other) const Returns true if this text format is the same as the \a other text format.*/bool QTextFormat::operator==(const QTextFormat &rhs) const{ if (format_type != rhs.format_type) return false; if (d == rhs.d) return true; if (d && d->properties().isEmpty() && !rhs.d) return true; if (!d && rhs.d && rhs.d->properties().isEmpty()) return true; if (!d || !rhs.d) return false; return *d == *rhs.d;}/*! \class QTextCharFormat qtextformat.h \brief The QTextCharFormat class provides formatting information for characters in a QTextDocument. \ingroup text The character format of text in a document specifies the visual properties of the text, as well as information about its role in a hypertext document. The font used can be set by supplying a font to the setFont() function, and each aspect of its appearance can be adjusted to give the desired effect. setFontFamily() and setFontPointSize() define the font's family (e.g. Times) and printed size; setFontWeight() and setFontItalic() provide control over the style of the font. setFontUnderline(), setFontOverline(), setFontStrikeOut(), and setFontFixedPitch() provide additional effects for text. The color is set with setForeground(). If the text is intended to be used as an anchor (for hyperlinks), this can be enabled with setAnchor(). The setAnchorHref() and setAnchorName() functions are used to specify the information about the hyperlink's destination and the anchor's name. If the text is written within a table, it can be made to span a number of rows and columns with the setTableCellRowSpan() and setTableCellColumnSpan() functions. \sa QTextFormat QTextBlockFormat QTextTableFormat QTextListFormat*//*! \enum QTextCharFormat::VerticalAlignment This enum describes the ways that adjacent characters can be vertically aligned. \value AlignNormal Adjacent characters are positioned in the standard way for text in the writing system in use. \value AlignSuperScript Characters are placed above the baseline for normal text. \value AlignSubScript Characters are placed below the baseline for normal text.*//*! \fn QTextCharFormat::QTextCharFormat() Constructs a new character format object.*/QTextCharFormat::QTextCharFormat() : QTextFormat(CharFormat) {}/*! \fn bool QTextCharFormat::isValid() const Returns true if this character format is valid; otherwise returns false.*//*! \fn void QTextCharFormat::setFontFamily(const QString &family) Sets the text format's font \a family. \sa setFont()*//*! \fn QString QTextCharFormat::fontFamily() const Returns the text format's font family. \sa font()*//*! \fn void QTextCharFormat::setFontPointSize(qreal size) Sets the text format's font \a size. \sa setFont()*//*! \fn qreal QTextCharFormat::fontPointSize() const Returns the font size used to display text in this format. \sa font()*//*! \fn void QTextCharFormat::setFontWeight(int weight) Sets the text format's font weight to \a weight. \sa setFont()*//*! \fn int QTextCharFormat::fontWeight() const Returns the text format's font weight. \sa font()*//*! \fn void QTextCharFormat::setFontItalic(bool italic) If \a italic is true, sets the text format's font to be italic; otherwise the font will be non-italic. \sa setFont()*//*! \fn bool QTextCharFormat::fontItalic() const Returns true if the text format's font is italic; otherwise returns false. \sa font()*//*! \fn void QTextCharFormat::setFontUnderline(bool underline) If \a underline is true, sets the text format's font to be underlined; otherwise it is displayed non-underlined. \sa setFont()*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -