1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qtextformat.h"
43 #include "qtextformat_p.h"
46 #include <qdatastream.h>
57 \brief The QTextLength class encapsulates the different types of length
58 used in a QTextDocument.
60 \ingroup richtext-processing
62 When we specify a value for the length of an element in a text document,
63 we often need to provide some other information so that the length is
64 used in the way we expect. For example, when we specify a table width,
65 the value can represent a fixed number of pixels, or it can be a percentage
66 value. This information changes both the meaning of the value and the way
69 Generally, this class is used to specify table widths. These can be
70 specified either as a fixed amount of pixels, as a percentage of the
71 containing frame's width, or by a variable width that allows it to take
72 up just the space it requires.
78 \fn explicit QTextLength::QTextLength()
80 Constructs a new length object which represents a variable size.
84 \fn QTextLength::QTextLength(Type type, qreal value)
86 Constructs a new length object of the given \a type and \a value.
90 \fn Type QTextLength::type() const
92 Returns the type of this length object.
98 \fn qreal QTextLength::value(qreal maximumLength) const
100 Returns the effective length, constrained by the type of the length object
101 and the specified \a maximumLength.
107 \fn qreal QTextLength::rawValue() const
109 Returns the constraint value that is specific for the type of the length.
110 If the length is QTextLength::PercentageLength then the raw value is in
111 percent, in the range of 0 to 100. If the length is QTextLength::FixedLength
112 then that fixed amount is returned. For variable lengths, zero is returned.
116 \fn bool QTextLength::operator==(const QTextLength &other) const
118 Returns true if this text length is the same as the \a other text
123 \fn bool QTextLength::operator!=(const QTextLength &other) const
125 Returns true if this text length is different from the \a other text
130 \enum QTextLength::Type
132 This enum describes the different types a length object can
135 \value VariableLength The width of the object is variable
136 \value FixedLength The width of the object is fixed
137 \value PercentageLength The width of the object is in
138 percentage of the maximum width
144 Returns the text length as a QVariant
146 QTextLength::operator QVariant() const
148 return QVariant(QVariant::TextLength, this);
151 #ifndef QT_NO_DATASTREAM
152 QDataStream &operator<<(QDataStream &stream, const QTextLength &length)
154 return stream << qint32(length.lengthType) << double(length.fixedValueOrPercentage);
157 QDataStream &operator>>(QDataStream &stream, QTextLength &length)
160 double fixedValueOrPercentage;
161 stream >> type >> fixedValueOrPercentage;
162 length.fixedValueOrPercentage = fixedValueOrPercentage;
163 length.lengthType = QTextLength::Type(type);
166 #endif // QT_NO_DATASTREAM
168 class QTextFormatPrivate : public QSharedData
171 QTextFormatPrivate() : hashDirty(true), fontDirty(true), hashValue(0) {}
175 inline Property(qint32 k, const QVariant &v) : key(k), value(v) {}
181 inline bool operator==(const Property &other) const
182 { return key == other.key && value == other.value; }
183 inline bool operator!=(const Property &other) const
184 { return key != other.key || value != other.value; }
187 inline uint hash() const
194 inline bool operator==(const QTextFormatPrivate &rhs) const {
195 if (hash() != rhs.hash())
198 return props == rhs.props;
201 inline void insertProperty(qint32 key, const QVariant &value)
204 if (key >= QTextFormat::FirstFontProperty && key <= QTextFormat::LastFontProperty)
206 for (int i = 0; i < props.count(); ++i)
207 if (props.at(i).key == key) {
208 props[i].value = value;
211 props.append(Property(key, value));
214 inline void clearProperty(qint32 key)
216 for (int i = 0; i < props.count(); ++i)
217 if (props.at(i).key == key) {
219 if (key >= QTextFormat::FirstFontProperty && key <= QTextFormat::LastFontProperty)
226 inline int propertyIndex(qint32 key) const
228 for (int i = 0; i < props.count(); ++i)
229 if (props.at(i).key == key)
234 inline QVariant property(qint32 key) const
236 const int idx = propertyIndex(key);
239 return props.at(idx).value;
242 inline bool hasProperty(qint32 key) const
243 { return propertyIndex(key) != -1; }
245 void resolveFont(const QFont &defaultFont);
247 inline const QFont &font() const {
253 QVector<Property> props;
256 uint recalcHash() const;
257 void recalcFont() const;
259 mutable bool hashDirty;
260 mutable bool fontDirty;
261 mutable uint hashValue;
264 friend QDataStream &operator<<(QDataStream &, const QTextFormat &);
265 friend QDataStream &operator>>(QDataStream &, QTextFormat &);
268 // this is only safe because sizeof(int) == sizeof(float)
269 static inline uint hash(float d)
272 // this is a GCC extension and isn't guaranteed to work in other compilers
273 // the reinterpret_cast below generates a strict-aliasing warning with GCC
274 union { float f; uint u; } cvt;
278 return reinterpret_cast<uint&>(d);
282 static inline uint hash(const QColor &color)
284 return (color.isValid()) ? color.rgba() : 0x234109;
287 static inline uint hash(const QPen &pen)
289 return hash(pen.color()) + hash(pen.widthF());
292 static inline uint hash(const QBrush &brush)
294 return hash(brush.color()) + (brush.style() << 3);
297 static inline uint variantHash(const QVariant &variant)
299 // simple and fast hash functions to differentiate between type and value
300 switch (variant.userType()) { // sorted by occurrence frequency
301 case QVariant::String: return qHash(variant.toString());
302 case QVariant::Double: return hash(variant.toDouble());
303 case QVariant::Int: return 0x811890 + variant.toInt();
304 case QVariant::Brush:
305 return 0x01010101 + hash(qvariant_cast<QBrush>(variant));
306 case QVariant::Bool: return 0x371818 + variant.toBool();
307 case QVariant::Pen: return 0x02020202 + hash(qvariant_cast<QPen>(variant));
309 return 0x8377 + qvariant_cast<QVariantList>(variant).count();
310 case QVariant::Color: return hash(qvariant_cast<QColor>(variant));
311 case QVariant::TextLength:
312 return 0x377 + hash(qvariant_cast<QTextLength>(variant).rawValue());
313 case QMetaType::Float: return hash(variant.toFloat());
314 case QVariant::Invalid: return 0;
317 return qHash(variant.typeName());
320 static inline int getHash(const QTextFormatPrivate *d, int format)
322 return (d ? d->hash() : 0) + format;
325 uint QTextFormatPrivate::recalcHash() const
328 for (QVector<Property>::ConstIterator it = props.constBegin(); it != props.constEnd(); ++it)
329 hashValue += (it->key << 16) + variantHash(it->value);
336 void QTextFormatPrivate::resolveFont(const QFont &defaultFont)
339 const uint oldMask = fnt.resolve();
340 fnt = fnt.resolve(defaultFont);
342 if (hasProperty(QTextFormat::FontSizeAdjustment)) {
343 const qreal scaleFactors[7] = {qreal(0.7), qreal(0.8), qreal(1.0), qreal(1.2), qreal(1.5), qreal(2), qreal(2.4)};
345 const int htmlFontSize = qBound(0, property(QTextFormat::FontSizeAdjustment).toInt() + 3 - 1, 6);
348 if (defaultFont.pointSize() <= 0) {
349 qreal pixelSize = scaleFactors[htmlFontSize] * defaultFont.pixelSize();
350 fnt.setPixelSize(qRound(pixelSize));
352 qreal pointSize = scaleFactors[htmlFontSize] * defaultFont.pointSizeF();
353 fnt.setPointSizeF(pointSize);
357 fnt.resolve(oldMask);
360 void QTextFormatPrivate::recalcFont() const
362 // update cached font as well
365 for (int i = 0; i < props.count(); ++i) {
366 switch (props.at(i).key) {
367 case QTextFormat::FontFamily:
368 f.setFamily(props.at(i).value.toString());
370 case QTextFormat::FontPointSize:
371 f.setPointSizeF(props.at(i).value.toReal());
373 case QTextFormat::FontPixelSize:
374 f.setPixelSize(props.at(i).value.toInt());
376 case QTextFormat::FontWeight: {
377 int weight = props.at(i).value.toInt();
378 if (weight == 0) weight = QFont::Normal;
381 case QTextFormat::FontItalic:
382 f.setItalic(props.at(i).value.toBool());
384 case QTextFormat::FontUnderline:
385 if (! hasProperty(QTextFormat::TextUnderlineStyle)) // don't use the old one if the new one is there.
386 f.setUnderline(props.at(i).value.toBool());
388 case QTextFormat::TextUnderlineStyle:
389 f.setUnderline(static_cast<QTextCharFormat::UnderlineStyle>(props.at(i).value.toInt()) == QTextCharFormat::SingleUnderline);
391 case QTextFormat::FontOverline:
392 f.setOverline(props.at(i).value.toBool());
394 case QTextFormat::FontStrikeOut:
395 f.setStrikeOut(props.at(i).value.toBool());
397 case QTextFormat::FontLetterSpacing:
398 f.setLetterSpacing(QFont::PercentageSpacing, props.at(i).value.toReal());
400 case QTextFormat::FontWordSpacing:
401 f.setWordSpacing(props.at(i).value.toReal());
403 case QTextFormat::FontCapitalization:
404 f.setCapitalization(static_cast<QFont::Capitalization> (props.at(i).value.toInt()));
406 case QTextFormat::FontFixedPitch: {
407 const bool value = props.at(i).value.toBool();
408 if (f.fixedPitch() != value)
409 f.setFixedPitch(value);
411 case QTextFormat::FontStyleHint:
412 f.setStyleHint(static_cast<QFont::StyleHint>(props.at(i).value.toInt()), f.styleStrategy());
414 case QTextFormat::FontHintingPreference:
415 f.setHintingPreference(static_cast<QFont::HintingPreference>(props.at(i).value.toInt()));
417 case QTextFormat::FontStyleStrategy:
418 f.setStyleStrategy(static_cast<QFont::StyleStrategy>(props.at(i).value.toInt()));
420 case QTextFormat::FontKerning:
421 f.setKerning(props.at(i).value.toBool());
431 #ifndef QT_NO_DATASTREAM
432 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QTextFormat &fmt)
434 stream << fmt.format_type << fmt.properties();
438 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QTextFormat &fmt)
440 QMap<qint32, QVariant> properties;
441 stream >> fmt.format_type >> properties;
443 // QTextFormat's default constructor doesn't allocate the private structure, so
444 // we have to do this, in case fmt is a default constructed value.
446 fmt.d = new QTextFormatPrivate();
448 for (QMap<qint32, QVariant>::ConstIterator it = properties.constBegin();
449 it != properties.constEnd(); ++it)
450 fmt.d->insertProperty(it.key(), it.value());
454 #endif // QT_NO_DATASTREAM
460 \brief The QTextFormat class provides formatting information for a
463 \ingroup richtext-processing
466 A QTextFormat is a generic class used for describing the format of
467 parts of a QTextDocument. The derived classes QTextCharFormat,
468 QTextBlockFormat, QTextListFormat, and QTextTableFormat are usually
469 more useful, and describe the formatting that is applied to
470 specific parts of the document.
472 A format has a \c FormatType which specifies the kinds of text item it
473 can format; e.g. a block of text, a list, a table, etc. A format
474 also has various properties (some specific to particular format
475 types), as described by the Property enum. Every property has a
476 corresponding Property.
478 The format type is given by type(), and the format can be tested
479 with isCharFormat(), isBlockFormat(), isListFormat(),
480 isTableFormat(), isFrameFormat(), and isImageFormat(). If the
481 type is determined, it can be retrieved with toCharFormat(),
482 toBlockFormat(), toListFormat(), toTableFormat(), toFrameFormat(),
485 A format's properties can be set with the setProperty() functions,
486 and retrieved with boolProperty(), intProperty(), doubleProperty(),
487 and stringProperty() as appropriate. All the property IDs used in
488 the format can be retrieved with allPropertyIds(). One format can
489 be merged into another using merge().
491 A format's object index can be set with setObjectIndex(), and
492 retrieved with objectIndex(). These methods can be used to
493 associate the format with a QTextObject. It is used to represent
494 lists, frames, and tables inside the document.
496 \sa {Rich Text Processing}
500 \enum QTextFormat::FormatType
502 This enum describes the text item a QTextFormat object is formatting.
504 \value InvalidFormat An invalid format as created by the default
506 \value BlockFormat The object formats a text block
507 \value CharFormat The object formats a single character
508 \value ListFormat The object formats a list
509 \value TableFormat The object formats a table
510 \value FrameFormat The object formats a frame
514 \sa QTextCharFormat, QTextBlockFormat, QTextListFormat,
515 QTextTableFormat, type()
519 \enum QTextFormat::Property
521 This enum describes the different properties a format can have.
523 \value ObjectIndex The index of the formatted object. See objectIndex().
525 Paragraph and character properties
527 \value CssFloat How a frame is located relative to the surrounding text
528 \value LayoutDirection The layout direction of the text in the document
529 (Qt::LayoutDirection).
532 \value ForegroundBrush
533 \value BackgroundBrush
534 \value BackgroundImageUrl
538 \value BlockAlignment
539 \value BlockTopMargin
540 \value BlockBottomMargin
541 \value BlockLeftMargin
542 \value BlockRightMargin
544 \value TabPositions Specifies the tab positions. The tab positions are structs of QTextOption::Tab which are stored in
545 a QList (internally, in a QList<QVariant>).
548 \value LineHeightType
549 \value BlockNonBreakableLines
550 \value BlockTrailingHorizontalRulerWidth The width of a horizontal ruler element.
557 \value FontSizeAdjustment Specifies the change in size given to the fontsize already set using
558 FontPointSize or FontPixelSize.
559 \value FontFixedPitch
560 \omitvalue FontSizeIncrement
563 \value FontUnderline \e{This property has been deprecated.} Use QTextFormat::TextUnderlineStyle instead.
566 \value FontCapitalization Specifies the capitalization type that is to be applied to the text.
567 \value FontLetterSpacing Changes the default spacing between individual letters in the font. The value is
568 specified in percentage, with 100 as the default value.
569 \value FontWordSpacing Changes the default spacing between individual words. A positive value increases the word spacing
570 by the corresponding pixels; a negative value decreases the spacing.
571 \value FontStyleHint Corresponds to the QFont::StyleHint property
572 \value FontStyleStrategy Corresponds to the QFont::StyleStrategy property
573 \value FontKerning Specifies whether the font has kerning turned on.
574 \value FontHintingPreference Controls the use of hinting according to values
575 of the QFont::HintingPreference enum.
577 \omitvalue FirstFontProperty
578 \omitvalue LastFontProperty
580 \value TextUnderlineColor
581 \value TextVerticalAlignment
583 \value TextUnderlineStyle
584 \value TextToolTip Specifies the (optional) tool tip to be displayed for a fragment of text.
593 \value ListStyle Specifies the style used for the items in a list,
594 described by values of the QTextListFormat::Style enum.
595 \value ListIndent Specifies the amount of indentation used for a list.
596 \value ListNumberPrefix Defines the text which is prepended to item numbers in
598 \value ListNumberSuffix Defines the text which is appended to item numbers in
601 Table and frame properties
604 \value FrameBorderBrush
605 \value FrameBorderStyle See the \l{QTextFrameFormat::BorderStyle}{BorderStyle} enum.
606 \value FrameBottomMargin
608 \value FrameLeftMargin
611 \value FrameRightMargin
612 \value FrameTopMargin
614 \value TableCellSpacing
615 \value TableCellPadding
617 \value TableColumnWidthConstraints
618 \value TableHeaderRowCount
620 Table cell properties
622 \value TableCellRowSpan
623 \value TableCellColumnSpan
624 \value TableCellLeftPadding
625 \value TableCellRightPadding
626 \value TableCellTopPadding
627 \value TableCellBottomPadding
637 \value FullWidthSelection When set on the characterFormat of a selection,
638 the whole width of the text will be shown selected.
640 Page break properties
642 \value PageBreakPolicy Specifies how pages are broken. See the PageBreakFlag enum.
646 \sa property(), setProperty()
650 \enum QTextFormat::ObjectTypes
652 This enum describes what kind of QTextObject this format is associated with.
657 \value TableCellObject
658 \value UserObject The first object that can be used for application-specific purposes.
660 \sa QTextObject, QTextTable, QTextObject::format()
664 \enum QTextFormat::PageBreakFlag
667 This enum describes how page breaking is performed when printing. It maps to the
668 corresponding css properties.
670 \value PageBreak_Auto The page break is determined automatically depending on the
671 available space on the current page
672 \value PageBreak_AlwaysBefore The page is always broken before the paragraph/table
673 \value PageBreak_AlwaysAfter A new page is always started after the paragraph/table
675 \sa QTextBlockFormat::pageBreakPolicy(), QTextFrameFormat::pageBreakPolicy(),
680 \fn bool QTextFormat::isValid() const
682 Returns true if the format is valid (i.e. is not
683 InvalidFormat); otherwise returns false.
687 \fn bool QTextFormat::isCharFormat() const
689 Returns true if this text format is a \c CharFormat; otherwise
695 \fn bool QTextFormat::isBlockFormat() const
697 Returns true if this text format is a \c BlockFormat; otherwise
703 \fn bool QTextFormat::isListFormat() const
705 Returns true if this text format is a \c ListFormat; otherwise
711 \fn bool QTextFormat::isTableFormat() const
713 Returns true if this text format is a \c TableFormat; otherwise
719 \fn bool QTextFormat::isFrameFormat() const
721 Returns true if this text format is a \c FrameFormat; otherwise
727 \fn bool QTextFormat::isImageFormat() const
729 Returns true if this text format is an image format; otherwise
735 \fn bool QTextFormat::isTableCellFormat() const
738 Returns true if this text format is a \c TableCellFormat; otherwise
744 Creates a new text format with an \c InvalidFormat.
748 QTextFormat::QTextFormat()
749 : format_type(InvalidFormat)
754 Creates a new text format of the given \a type.
758 QTextFormat::QTextFormat(int type)
765 \fn QTextFormat::QTextFormat(const QTextFormat &other)
767 Creates a new text format with the same attributes as the \a other
770 QTextFormat::QTextFormat(const QTextFormat &rhs)
771 : d(rhs.d), format_type(rhs.format_type)
776 \fn QTextFormat &QTextFormat::operator=(const QTextFormat &other)
778 Assigns the \a other text format to this text format, and returns a
779 reference to this text format.
781 QTextFormat &QTextFormat::operator=(const QTextFormat &rhs)
784 format_type = rhs.format_type;
789 Destroys this text format.
791 QTextFormat::~QTextFormat()
797 Returns the text format as a QVariant
799 QTextFormat::operator QVariant() const
801 return QVariant(QVariant::TextFormat, this);
805 Merges the \a other format with this format; where there are
806 conflicts the \a other format takes precedence.
808 void QTextFormat::merge(const QTextFormat &other)
810 if (format_type != other.format_type)
821 QTextFormatPrivate *d = this->d;
823 const QVector<QTextFormatPrivate::Property> &otherProps = other.d->props;
824 d->props.reserve(d->props.size() + otherProps.size());
825 for (int i = 0; i < otherProps.count(); ++i) {
826 const QTextFormatPrivate::Property &p = otherProps.at(i);
827 d->insertProperty(p.key, p.value);
832 Returns the type of this format.
836 int QTextFormat::type() const
842 Returns this format as a block format.
844 QTextBlockFormat QTextFormat::toBlockFormat() const
846 return QTextBlockFormat(*this);
850 Returns this format as a character format.
852 QTextCharFormat QTextFormat::toCharFormat() const
854 return QTextCharFormat(*this);
858 Returns this format as a list format.
860 QTextListFormat QTextFormat::toListFormat() const
862 return QTextListFormat(*this);
866 Returns this format as a table format.
868 QTextTableFormat QTextFormat::toTableFormat() const
870 return QTextTableFormat(*this);
874 Returns this format as a frame format.
876 QTextFrameFormat QTextFormat::toFrameFormat() const
878 return QTextFrameFormat(*this);
882 Returns this format as an image format.
884 QTextImageFormat QTextFormat::toImageFormat() const
886 return QTextImageFormat(*this);
892 Returns this format as a table cell format.
894 QTextTableCellFormat QTextFormat::toTableCellFormat() const
896 return QTextTableCellFormat(*this);
900 Returns the value of the property specified by \a propertyId. If the
901 property isn't of QTextFormat::Bool type, false is returned instead.
903 \sa setProperty() intProperty() doubleProperty() stringProperty() colorProperty() lengthProperty() lengthVectorProperty() Property
905 bool QTextFormat::boolProperty(int propertyId) const
909 const QVariant prop = d->property(propertyId);
910 if (prop.userType() != QVariant::Bool)
912 return prop.toBool();
916 Returns the value of the property specified by \a propertyId. If the
917 property is not of QTextFormat::Integer type, 0 is returned instead.
919 \sa setProperty() boolProperty() doubleProperty() stringProperty() colorProperty() lengthProperty() lengthVectorProperty() Property
921 int QTextFormat::intProperty(int propertyId) const
923 // required, since the default layout direction has to be LayoutDirectionAuto, which is not integer 0
924 int def = (propertyId == QTextFormat::LayoutDirection) ? int(Qt::LayoutDirectionAuto) : 0;
928 const QVariant prop = d->property(propertyId);
929 if (prop.userType() != QVariant::Int)
935 Returns the value of the property specified by \a propertyId. If the
936 property isn't of QVariant::Double or QMetaType::Float type, 0 is
939 \sa setProperty() boolProperty() intProperty() stringProperty() colorProperty() lengthProperty() lengthVectorProperty() Property
941 qreal QTextFormat::doubleProperty(int propertyId) const
945 const QVariant prop = d->property(propertyId);
946 if (prop.userType() != QVariant::Double && prop.userType() != QMetaType::Float)
948 return qvariant_cast<qreal>(prop);
952 Returns the value of the property given by \a propertyId; if the
953 property isn't of QVariant::String type, an empty string is
956 \sa setProperty() boolProperty() intProperty() doubleProperty() colorProperty() lengthProperty() lengthVectorProperty() Property
958 QString QTextFormat::stringProperty(int propertyId) const
962 const QVariant prop = d->property(propertyId);
963 if (prop.userType() != QVariant::String)
965 return prop.toString();
969 Returns the value of the property given by \a propertyId; if the
970 property isn't of QVariant::Color type, an invalid color is
973 \sa setProperty(), boolProperty(), intProperty(), doubleProperty(),
974 stringProperty(), lengthProperty(), lengthVectorProperty(), Property
976 QColor QTextFormat::colorProperty(int propertyId) const
980 const QVariant prop = d->property(propertyId);
981 if (prop.userType() != QVariant::Color)
983 return qvariant_cast<QColor>(prop);
987 Returns the value of the property given by \a propertyId; if the
988 property isn't of QVariant::Pen type, Qt::NoPen is
991 \sa setProperty() boolProperty() intProperty() doubleProperty() stringProperty() lengthProperty() lengthVectorProperty() Property
993 QPen QTextFormat::penProperty(int propertyId) const
996 return QPen(Qt::NoPen);
997 const QVariant prop = d->property(propertyId);
998 if (prop.userType() != QVariant::Pen)
999 return QPen(Qt::NoPen);
1000 return qvariant_cast<QPen>(prop);
1004 Returns the value of the property given by \a propertyId; if the
1005 property isn't of QVariant::Brush type, Qt::NoBrush is
1008 \sa setProperty() boolProperty() intProperty() doubleProperty() stringProperty() lengthProperty() lengthVectorProperty() Property
1010 QBrush QTextFormat::brushProperty(int propertyId) const
1013 return QBrush(Qt::NoBrush);
1014 const QVariant prop = d->property(propertyId);
1015 if (prop.userType() != QVariant::Brush)
1016 return QBrush(Qt::NoBrush);
1017 return qvariant_cast<QBrush>(prop);
1021 Returns the value of the property given by \a propertyId.
1023 \sa setProperty() boolProperty() intProperty() doubleProperty() stringProperty() colorProperty() lengthVectorProperty() Property
1025 QTextLength QTextFormat::lengthProperty(int propertyId) const
1028 return QTextLength();
1029 return qvariant_cast<QTextLength>(d->property(propertyId));
1033 Returns the value of the property given by \a propertyId. If the
1034 property isn't of QTextFormat::LengthVector type, an empty length
1035 vector is returned instead.
1037 \sa setProperty() boolProperty() intProperty() doubleProperty() stringProperty() colorProperty() lengthProperty() Property
1039 QVector<QTextLength> QTextFormat::lengthVectorProperty(int propertyId) const
1041 QVector<QTextLength> vector;
1044 const QVariant prop = d->property(propertyId);
1045 if (prop.userType() != QVariant::List)
1048 QList<QVariant> propertyList = prop.toList();
1049 for (int i=0; i<propertyList.size(); ++i) {
1050 QVariant var = propertyList.at(i);
1051 if (var.userType() == QVariant::TextLength)
1052 vector.append(qvariant_cast<QTextLength>(var));
1059 Returns the property specified by the given \a propertyId.
1063 QVariant QTextFormat::property(int propertyId) const
1065 return d ? d->property(propertyId) : QVariant();
1069 Sets the property specified by the \a propertyId to the given \a value.
1073 void QTextFormat::setProperty(int propertyId, const QVariant &value)
1076 d = new QTextFormatPrivate;
1077 if (!value.isValid())
1078 clearProperty(propertyId);
1080 d->insertProperty(propertyId, value);
1084 Sets the value of the property given by \a propertyId to \a value.
1086 \sa lengthVectorProperty() Property
1088 void QTextFormat::setProperty(int propertyId, const QVector<QTextLength> &value)
1091 d = new QTextFormatPrivate;
1093 for (int i=0; i<value.size(); ++i)
1094 list << value.at(i);
1095 d->insertProperty(propertyId, list);
1099 Clears the value of the property given by \a propertyId
1103 void QTextFormat::clearProperty(int propertyId)
1107 d->clearProperty(propertyId);
1112 \fn void QTextFormat::setObjectType(int type)
1114 Sets the text format's object type to \a type.
1116 \sa ObjectTypes, objectType()
1121 \fn int QTextFormat::objectType() const
1123 Returns the text format's object type.
1125 \sa ObjectTypes, setObjectType()
1130 Returns the index of the format object, or -1 if the format object is invalid.
1132 \sa setObjectIndex()
1134 int QTextFormat::objectIndex() const
1138 const QVariant prop = d->property(ObjectIndex);
1139 if (prop.userType() != QVariant::Int) // ####
1141 return prop.toInt();
1145 \fn void QTextFormat::setObjectIndex(int index)
1147 Sets the format object's object \a index.
1151 void QTextFormat::setObjectIndex(int o)
1155 d->clearProperty(ObjectIndex);
1158 d = new QTextFormatPrivate;
1160 d->insertProperty(ObjectIndex, o);
1165 Returns true if the text format has a property with the given \a
1166 propertyId; otherwise returns false.
1168 \sa properties() Property
1170 bool QTextFormat::hasProperty(int propertyId) const
1172 return d ? d->hasProperty(propertyId) : false;
1176 Returns the property type for the given \a propertyId.
1178 \sa hasProperty() allPropertyIds() Property
1182 Returns a map with all properties of this text format.
1184 QMap<int, QVariant> QTextFormat::properties() const
1186 QMap<int, QVariant> map;
1188 for (int i = 0; i < d->props.count(); ++i)
1189 map.insert(d->props.at(i).key, d->props.at(i).value);
1196 Returns the number of properties stored in the format.
1198 int QTextFormat::propertyCount() const
1200 return d ? d->props.count() : 0;
1204 \fn bool QTextFormat::operator!=(const QTextFormat &other) const
1206 Returns true if this text format is different from the \a other text
1212 \fn bool QTextFormat::operator==(const QTextFormat &other) const
1214 Returns true if this text format is the same as the \a other text
1217 bool QTextFormat::operator==(const QTextFormat &rhs) const
1219 if (format_type != rhs.format_type)
1225 if (d && d->props.isEmpty() && !rhs.d)
1228 if (!d && rhs.d && rhs.d->props.isEmpty())
1234 return *d == *rhs.d;
1238 \class QTextCharFormat
1241 \brief The QTextCharFormat class provides formatting information for
1242 characters in a QTextDocument.
1244 \ingroup richtext-processing
1246 The character format of text in a document specifies the visual properties
1247 of the text, as well as information about its role in a hypertext document.
1249 The font used can be set by supplying a font to the setFont() function, and
1250 each aspect of its appearance can be adjusted to give the desired effect.
1251 setFontFamily() and setFontPointSize() define the font's family (e.g. Times)
1252 and printed size; setFontWeight() and setFontItalic() provide control over
1253 the style of the font. setFontUnderline(), setFontOverline(),
1254 setFontStrikeOut(), and setFontFixedPitch() provide additional effects for
1257 The color is set with setForeground(). If the text is intended to be used
1258 as an anchor (for hyperlinks), this can be enabled with setAnchor(). The
1259 setAnchorHref() and setAnchorNames() functions are used to specify the
1260 information about the hyperlink's destination and the anchor's name.
1262 \sa QTextFormat QTextBlockFormat QTextTableFormat QTextListFormat
1266 \enum QTextCharFormat::VerticalAlignment
1268 This enum describes the ways that adjacent characters can be vertically
1271 \value AlignNormal Adjacent characters are positioned in the standard
1272 way for text in the writing system in use.
1273 \value AlignSuperScript Characters are placed above the base line for
1275 \value AlignSubScript Characters are placed below the base line for
1277 \value AlignMiddle The center of the object is vertically aligned with the
1278 base line. Currently, this is only implemented for
1280 \value AlignBottom The bottom edge of the object is vertically aligned with
1282 \value AlignTop The top edge of the object is vertically aligned with
1284 \value AlignBaseline The base lines of the characters are aligned.
1288 \enum QTextCharFormat::UnderlineStyle
1290 This enum describes the different ways drawing underlined text.
1292 \value NoUnderline Text is draw without any underlining decoration.
1293 \value SingleUnderline A line is drawn using Qt::SolidLine.
1294 \value DashUnderline Dashes are drawn using Qt::DashLine.
1295 \value DotLine Dots are drawn using Qt::DotLine;
1296 \value DashDotLine Dashs and dots are drawn using Qt::DashDotLine.
1297 \value DashDotDotLine Underlines draw drawn using Qt::DashDotDotLine.
1298 \value WaveUnderline The text is underlined using a wave shaped line.
1299 \value SpellCheckUnderline The underline is drawn depending on the QStyle::SH_SpellCeckUnderlineStyle
1300 style hint of the QApplication style. By default this is mapped to
1301 WaveUnderline, on Mac OS X it is mapped to DashDotLine.
1307 \fn QTextCharFormat::QTextCharFormat()
1309 Constructs a new character format object.
1311 QTextCharFormat::QTextCharFormat() : QTextFormat(CharFormat) {}
1315 \fn QTextCharFormat::QTextCharFormat(const QTextFormat &other)
1317 Creates a new character format with the same attributes as the \a given
1320 QTextCharFormat::QTextCharFormat(const QTextFormat &fmt)
1326 \fn bool QTextCharFormat::isValid() const
1328 Returns true if this character format is valid; otherwise returns
1334 \fn void QTextCharFormat::setFontFamily(const QString &family)
1336 Sets the text format's font \a family.
1343 \fn QString QTextCharFormat::fontFamily() const
1345 Returns the text format's font family.
1352 \fn void QTextCharFormat::setFontPointSize(qreal size)
1354 Sets the text format's font \a size.
1361 \fn qreal QTextCharFormat::fontPointSize() const
1363 Returns the font size used to display text in this format.
1370 \fn void QTextCharFormat::setFontWeight(int weight)
1372 Sets the text format's font weight to \a weight.
1374 \sa setFont(), QFont::Weight
1379 \fn int QTextCharFormat::fontWeight() const
1381 Returns the text format's font weight.
1383 \sa font(), QFont::Weight
1388 \fn void QTextCharFormat::setFontItalic(bool italic)
1390 If \a italic is true, sets the text format's font to be italic; otherwise
1391 the font will be non-italic.
1398 \fn bool QTextCharFormat::fontItalic() const
1400 Returns true if the text format's font is italic; otherwise
1408 \fn void QTextCharFormat::setFontUnderline(bool underline)
1410 If \a underline is true, sets the text format's font to be underlined;
1411 otherwise it is displayed non-underlined.
1418 \fn bool QTextCharFormat::fontUnderline() const
1420 Returns true if the text format's font is underlined; otherwise
1425 bool QTextCharFormat::fontUnderline() const
1427 if (hasProperty(TextUnderlineStyle))
1428 return underlineStyle() == SingleUnderline;
1429 return boolProperty(FontUnderline);
1433 \fn UnderlineStyle QTextCharFormat::underlineStyle() const
1436 Returns the style of underlining the text.
1440 \fn void QTextCharFormat::setUnderlineStyle(UnderlineStyle style)
1443 Sets the style of underlining the text to \a style.
1445 void QTextCharFormat::setUnderlineStyle(UnderlineStyle style)
1447 setProperty(TextUnderlineStyle, style);
1448 // for compatibility
1449 setProperty(FontUnderline, style == SingleUnderline);
1453 \fn void QTextCharFormat::setFontOverline(bool overline)
1455 If \a overline is true, sets the text format's font to be overlined;
1456 otherwise the font is displayed non-overlined.
1463 \fn bool QTextCharFormat::fontOverline() const
1465 Returns true if the text format's font is overlined; otherwise
1473 \fn void QTextCharFormat::setFontStrikeOut(bool strikeOut)
1475 If \a strikeOut is true, sets the text format's font with strike-out
1476 enabled (with a horizontal line through it); otherwise it is displayed
1484 \fn bool QTextCharFormat::fontStrikeOut() const
1486 Returns true if the text format's font is struck out (has a horizontal line
1487 drawn through it); otherwise returns false.
1495 \fn void QTextCharFormat::setFontStyleHint(QFont::StyleHint hint, QFont::StyleStrategy strategy)
1497 Sets the font style \a hint and \a strategy.
1499 Qt does not support style hints on X11 since this information is not provided by the window system.
1502 \sa QFont::setStyleHint()
1508 \fn void QTextCharFormat::setFontStyleStrategy(QFont::StyleStrategy strategy)
1510 Sets the font style \a strategy.
1513 \sa QFont::setStyleStrategy()
1519 \fn void QTextCharFormat::setFontKerning(bool enable)
1520 Enables kerning for this font if \a enable is true; otherwise disables it.
1522 When kerning is enabled, glyph metrics do not add up anymore, even for
1523 Latin text. In other words, the assumption that width('a') + width('b')
1524 is equal to width("ab") is not neccesairly true.
1531 \fn QTextCharFormat::StyleHint QTextCharFormat::fontStyleHint() const
1534 Returns the font style hint.
1536 \sa setFontStyleHint(), font()
1542 \fn QTextCharFormat::StyleStrategy QTextCharFormat::fontStyleStrategy() const
1544 Returns the current font style strategy.
1546 \sa setFontStyleStrategy()
1553 \fn bool QTextCharFormat::fontKerning() const
1554 Returns true if the font kerning is enabled.
1556 \sa setFontKerning()
1562 \fn void QTextCharFormat::setFontFixedPitch(bool fixedPitch)
1564 If \a fixedPitch is true, sets the text format's font to be fixed pitch;
1565 otherwise a non-fixed pitch font is used.
1572 \fn bool QTextCharFormat::fontFixedPitch() const
1574 Returns true if the text format's font is fixed pitch; otherwise
1583 \fn void QTextCharFormat::setFontHintingPreference(QFont::HintingPreference hintingPreference)
1585 Sets the hinting preference of the text format's font to be \a hintingPreference.
1587 \sa setFont(), QFont::setHintingPreference()
1593 \fn QFont::HintingPreference QTextCharFormat::fontHintingPreference() const
1595 Returns the hinting preference set for this text format.
1597 \sa font(), QFont::hintingPreference()
1601 \fn QPen QTextCharFormat::textOutline() const
1603 Returns the pen used to draw the outlines of characters in this format.
1608 \fn void QTextCharFormat::setTextOutline(const QPen &pen)
1610 Sets the pen used to draw the outlines of characters to the given \a pen.
1614 \fn void QTextCharFormat::setToolTip(const QString &text)
1617 Sets the tool tip for a fragment of text to the given \a text.
1621 \fn QString QTextCharFormat::toolTip() const
1624 Returns the tool tip that is displayed for a fragment of text.
1628 \fn void QTextFormat::setForeground(const QBrush &brush)
1630 Sets the foreground brush to the specified \a brush. The foreground
1631 brush is mostly used to render text.
1633 \sa foreground() clearForeground() setBackground()
1638 \fn QBrush QTextFormat::foreground() const
1640 Returns the brush used to render foreground details, such as text,
1641 frame outlines, and table borders.
1643 \sa setForeground() clearForeground() background()
1647 \fn void QTextFormat::clearForeground()
1649 Clears the brush used to paint the document's foreground. The default
1652 \sa foreground() setForeground() clearBackground()
1657 \fn void QTextCharFormat::setAnchor(bool anchor)
1659 If \a anchor is true, text with this format represents an anchor, and is
1660 formatted in the appropriate way; otherwise the text is formatted normally.
1661 (Anchors are hyperlinks which are often shown underlined and in a different
1662 color from plain text.)
1664 The way the text is rendered is independent of whether or not the format
1665 has a valid anchor defined. Use setAnchorHref(), and optionally
1666 setAnchorNames() to create a hypertext link.
1673 \fn bool QTextCharFormat::isAnchor() const
1675 Returns true if the text is formatted as an anchor; otherwise
1678 \sa setAnchor() setAnchorHref() setAnchorNames()
1683 \fn void QTextCharFormat::setAnchorHref(const QString &value)
1685 Sets the hypertext link for the text format to the given \a value.
1686 This is typically a URL like "http://example.com/index.html".
1688 The anchor will be displayed with the \a value as its display text;
1689 if you want to display different text call setAnchorNames().
1691 To format the text as a hypertext link use setAnchor().
1696 \fn QString QTextCharFormat::anchorHref() const
1698 Returns the text format's hypertext link, or an empty string if
1704 \fn void QTextCharFormat::setAnchorName(const QString &name)
1707 This function is deprecated. Use setAnchorNames() instead.
1709 Sets the text format's anchor \a name. For the anchor to work as a
1710 hyperlink, the destination must be set with setAnchorHref() and
1711 the anchor must be enabled with setAnchor().
1715 \fn void QTextCharFormat::setAnchorNames(const QStringList &names)
1718 Sets the text format's anchor \a names. For the anchor to work as a
1719 hyperlink, the destination must be set with setAnchorHref() and
1720 the anchor must be enabled with setAnchor().
1724 \fn QString QTextCharFormat::anchorName() const
1727 This function is deprecated. Use anchorNames() instead.
1729 Returns the anchor name associated with this text format, or an empty
1730 string if none has been set. If the anchor name is set, text with this
1731 format can be the destination of a hypertext link.
1733 QString QTextCharFormat::anchorName() const
1735 QVariant prop = property(AnchorName);
1736 if (prop.userType() == QVariant::StringList)
1737 return prop.toStringList().value(0);
1738 else if (prop.userType() != QVariant::String)
1740 return prop.toString();
1744 \fn QStringList QTextCharFormat::anchorNames() const
1747 Returns the anchor names associated with this text format, or an empty
1748 string list if none has been set. If the anchor names are set, text with this
1749 format can be the destination of a hypertext link.
1751 QStringList QTextCharFormat::anchorNames() const
1753 QVariant prop = property(AnchorName);
1754 if (prop.userType() == QVariant::StringList)
1755 return prop.toStringList();
1756 else if (prop.userType() != QVariant::String)
1757 return QStringList();
1758 return QStringList(prop.toString());
1763 \fn void QTextCharFormat::setTableCellRowSpan(int tableCellRowSpan)
1766 If this character format is applied to characters in a table cell,
1767 the cell will span \a tableCellRowSpan rows.
1772 \fn int QTextCharFormat::tableCellRowSpan() const
1775 If this character format is applied to characters in a table cell,
1776 this function returns the number of rows spanned by the text (this may
1777 be 1); otherwise it returns 1.
1781 \fn void QTextCharFormat::setTableCellColumnSpan(int tableCellColumnSpan)
1784 If this character format is applied to characters in a table cell,
1785 the cell will span \a tableCellColumnSpan columns.
1790 \fn int QTextCharFormat::tableCellColumnSpan() const
1793 If this character format is applied to characters in a table cell,
1794 this function returns the number of columns spanned by the text (this
1795 may be 1); otherwise it returns 1.
1799 \fn void QTextCharFormat::setUnderlineColor(const QColor &color)
1801 Sets the underline color used for the characters with this format to
1802 the \a color specified.
1804 \sa underlineColor()
1808 \fn QColor QTextCharFormat::underlineColor() const
1810 Returns the color used to underline the characters with this format.
1812 \sa setUnderlineColor()
1816 \fn void QTextCharFormat::setVerticalAlignment(VerticalAlignment alignment)
1818 Sets the vertical alignment used for the characters with this format to
1819 the \a alignment specified.
1821 \sa verticalAlignment()
1825 \fn VerticalAlignment QTextCharFormat::verticalAlignment() const
1827 Returns the vertical alignment used for characters with this format.
1829 \sa setVerticalAlignment()
1833 Sets the text format's \a font.
1835 void QTextCharFormat::setFont(const QFont &font)
1837 setFontFamily(font.family());
1839 const qreal pointSize = font.pointSizeF();
1840 if (pointSize > 0) {
1841 setFontPointSize(pointSize);
1843 const int pixelSize = font.pixelSize();
1845 setProperty(QTextFormat::FontPixelSize, pixelSize);
1848 setFontWeight(font.weight());
1849 setFontItalic(font.italic());
1850 setUnderlineStyle(font.underline() ? SingleUnderline : NoUnderline);
1851 setFontOverline(font.overline());
1852 setFontStrikeOut(font.strikeOut());
1853 setFontFixedPitch(font.fixedPitch());
1854 setFontCapitalization(font.capitalization());
1855 setFontWordSpacing(font.wordSpacing());
1856 if (font.letterSpacingType() == QFont::PercentageSpacing)
1857 setFontLetterSpacing(font.letterSpacing());
1858 setFontStyleHint(font.styleHint());
1859 setFontStyleStrategy(font.styleStrategy());
1860 setFontKerning(font.kerning());
1864 Returns the font for this character format.
1866 QFont QTextCharFormat::font() const
1868 return d ? d->font() : QFont();
1872 \class QTextBlockFormat
1875 \brief The QTextBlockFormat class provides formatting information for
1876 blocks of text in a QTextDocument.
1878 \ingroup richtext-processing
1880 A document is composed of a list of blocks, represented by QTextBlock
1881 objects. Each block can contain an item of some kind, such as a
1882 paragraph of text, a table, a list, or an image. Every block has an
1883 associated QTextBlockFormat that specifies its characteristics.
1885 To cater for left-to-right and right-to-left languages you can set
1886 a block's direction with setDirection(). Paragraph alignment is
1887 set with setAlignment(). Margins are controlled by setTopMargin(),
1888 setBottomMargin(), setLeftMargin(), setRightMargin(). Overall
1889 indentation is set with setIndent(), the indentation of the first
1890 line with setTextIndent().
1892 Line spacing is set with setLineHeight() and retrieved via lineHeight()
1893 and lineHeightType(). The types of line spacing available are in the
1894 LineHeightTypes enum.
1896 Line breaking can be enabled and disabled with setNonBreakableLines().
1898 The brush used to paint the paragraph's background
1899 is set with \l{QTextFormat::setBackground()}{setBackground()}, and other
1900 aspects of the text's appearance can be customized by using the
1901 \l{QTextFormat::setProperty()}{setProperty()} function with the
1902 \c OutlinePen, \c ForegroundBrush, and \c BackgroundBrush
1903 \l{QTextFormat::Property} values.
1905 If a text block is part of a list, it can also have a list format that
1906 is accessible with the listFormat() function.
1908 \sa QTextBlock, QTextCharFormat
1913 \enum QTextBlockFormat::LineHeightTypes
1915 This enum describes the various types of line spacing support paragraphs can have.
1917 \value SingleHeight This is the default line height: single spacing.
1918 \value ProportionalHeight This sets the spacing proportional to the line (in percentage).
1919 For example, set to 200 for double spacing.
1920 \value FixedHeight This sets the line height to a fixed line height (in pixels).
1921 \value MinimumHeight This sets the minimum line height (in pixels).
1922 \value LineDistanceHeight This adds the specified height between lines (in pixels).
1924 \sa lineHeight(), lineHeightType(), setLineHeight()
1928 \fn QTextBlockFormat::QTextBlockFormat()
1930 Constructs a new QTextBlockFormat.
1932 QTextBlockFormat::QTextBlockFormat() : QTextFormat(BlockFormat) {}
1936 \fn QTextBlockFormat::QTextBlockFormat(const QTextFormat &other)
1938 Creates a new block format with the same attributes as the \a given
1941 QTextBlockFormat::QTextBlockFormat(const QTextFormat &fmt)
1948 Sets the tab positions for the text block to those specified by
1953 void QTextBlockFormat::setTabPositions(const QList<QTextOption::Tab> &tabs)
1955 QList<QVariant> list;
1956 QList<QTextOption::Tab>::ConstIterator iter = tabs.constBegin();
1957 while (iter != tabs.constEnd()) {
1959 v.setValue<QTextOption::Tab>(*iter);
1963 setProperty(TabPositions, list);
1968 Returns a list of tab positions defined for the text block.
1970 \sa setTabPositions()
1972 QList<QTextOption::Tab> QTextBlockFormat::tabPositions() const
1974 QVariant variant = property(TabPositions);
1975 if(variant.isNull())
1976 return QList<QTextOption::Tab>();
1977 QList<QTextOption::Tab> answer;
1978 QList<QVariant> variantsList = qvariant_cast<QList<QVariant> >(variant);
1979 QList<QVariant>::Iterator iter = variantsList.begin();
1980 while(iter != variantsList.end()) {
1981 answer.append( qvariant_cast<QTextOption::Tab>(*iter));
1988 \fn QTextBlockFormat::isValid() const
1990 Returns true if this block format is valid; otherwise returns
1995 \fn void QTextFormat::setLayoutDirection(Qt::LayoutDirection direction)
1997 Sets the document's layout direction to the specified \a direction.
1999 \sa layoutDirection()
2004 \fn Qt::LayoutDirection QTextFormat::layoutDirection() const
2006 Returns the document's layout direction.
2008 \sa setLayoutDirection()
2013 \fn void QTextBlockFormat::setAlignment(Qt::Alignment alignment)
2015 Sets the paragraph's \a alignment.
2022 \fn Qt::Alignment QTextBlockFormat::alignment() const
2024 Returns the paragraph's alignment.
2031 \fn void QTextBlockFormat::setTopMargin(qreal margin)
2033 Sets the paragraph's top \a margin.
2035 \sa topMargin() setBottomMargin() setLeftMargin() setRightMargin()
2040 \fn qreal QTextBlockFormat::topMargin() const
2042 Returns the paragraph's top margin.
2044 \sa setTopMargin() bottomMargin()
2049 \fn void QTextBlockFormat::setBottomMargin(qreal margin)
2051 Sets the paragraph's bottom \a margin.
2053 \sa bottomMargin() setTopMargin() setLeftMargin() setRightMargin()
2058 \fn qreal QTextBlockFormat::bottomMargin() const
2060 Returns the paragraph's bottom margin.
2062 \sa setBottomMargin() topMargin()
2067 \fn void QTextBlockFormat::setLeftMargin(qreal margin)
2069 Sets the paragraph's left \a margin. Indentation can be applied separately
2072 \sa leftMargin() setRightMargin() setTopMargin() setBottomMargin()
2077 \fn qreal QTextBlockFormat::leftMargin() const
2079 Returns the paragraph's left margin.
2081 \sa setLeftMargin() rightMargin() indent()
2086 \fn void QTextBlockFormat::setRightMargin(qreal margin)
2088 Sets the paragraph's right \a margin.
2090 \sa rightMargin() setLeftMargin() setTopMargin() setBottomMargin()
2095 \fn qreal QTextBlockFormat::rightMargin() const
2097 Returns the paragraph's right margin.
2099 \sa setRightMargin() leftMargin()
2104 \fn void QTextBlockFormat::setTextIndent(qreal indent)
2106 Sets the \a indent for the first line in the block. This allows the first
2107 line of a paragraph to be indented differently to the other lines,
2108 enhancing the readability of the text.
2110 \sa textIndent() setLeftMargin() setRightMargin() setTopMargin() setBottomMargin()
2115 \fn qreal QTextBlockFormat::textIndent() const
2117 Returns the paragraph's text indent.
2124 \fn void QTextBlockFormat::setIndent(int indentation)
2126 Sets the paragraph's \a indentation. Margins are set independently of
2127 indentation with setLeftMargin() and setTextIndent().
2128 The \a indentation is an integer that is multiplied with the document-wide
2129 standard indent, resulting in the actual indent of the paragraph.
2131 \sa indent() QTextDocument::indentWidth()
2136 \fn int QTextBlockFormat::indent() const
2138 Returns the paragraph's indent.
2145 \fn void QTextBlockFormat::setLineHeight(qreal height, int heightType)
2148 Sets the line height for the paragraph to the value given by \a height
2149 which is dependent on \a heightType in the way described by the
2150 LineHeightTypes enum.
2152 \sa LineHeightTypes, lineHeight(), lineHeightType()
2157 \fn qreal QTextBlockFormat::lineHeight(qreal scriptLineHeight, qreal scaling) const
2160 Returns the height of the lines in the paragraph based on the height of the
2161 script line given by \a scriptLineHeight and the specified \a scaling
2164 The value that is returned is also dependent on the given LineHeightType of
2165 the paragraph as well as the LineHeight setting that has been set for the
2168 The scaling is needed for heights that include a fixed number of pixels, to
2169 scale them appropriately for printing.
2171 \sa LineHeightTypes, setLineHeight(), lineHeightType()
2176 \fn qreal QTextBlockFormat::lineHeight() const
2179 This returns the LineHeight property for the paragraph.
2181 \sa LineHeightTypes, setLineHeight(), lineHeightType()
2186 \fn qreal QTextBlockFormat::lineHeightType() const
2189 This returns the LineHeightType property of the paragraph.
2191 \sa LineHeightTypes, setLineHeight(), lineHeight()
2196 \fn void QTextBlockFormat::setNonBreakableLines(bool b)
2198 If \a b is true, the lines in the paragraph are treated as
2199 non-breakable; otherwise they are breakable.
2201 \sa nonBreakableLines()
2206 \fn bool QTextBlockFormat::nonBreakableLines() const
2208 Returns true if the lines in the paragraph are non-breakable;
2209 otherwise returns false.
2211 \sa setNonBreakableLines()
2215 \fn QTextFormat::PageBreakFlags QTextBlockFormat::pageBreakPolicy() const
2218 Returns the currently set page break policy for the paragraph. The default is
2219 QTextFormat::PageBreak_Auto.
2221 \sa setPageBreakPolicy()
2225 \fn void QTextBlockFormat::setPageBreakPolicy(PageBreakFlags policy)
2228 Sets the page break policy for the paragraph to \a policy.
2230 \sa pageBreakPolicy()
2234 \class QTextListFormat
2237 \brief The QTextListFormat class provides formatting information for
2238 lists in a QTextDocument.
2240 \ingroup richtext-processing
2242 A list is composed of one or more items, represented as text blocks.
2243 The list's format specifies the appearance of items in the list.
2244 In particular, it determines the indentation and the style of each item.
2246 The indentation of the items is an integer value that causes each item to
2247 be offset from the left margin by a certain amount. This value is read with
2248 indent() and set with setIndent().
2250 The style used to decorate each item is set with setStyle() and can be read
2251 with the style() function. The style controls the type of bullet points and
2252 numbering scheme used for items in the list. Note that lists that use the
2253 decimal numbering scheme begin counting at 1 rather than 0.
2255 Style properties can be set to further configure the appearance of list
2256 items; for example, the ListNumberPrefix and ListNumberSuffix properties
2257 can be used to customize the numbers used in an ordered list so that they
2258 appear as (1), (2), (3), etc.:
2260 \snippet doc/src/snippets/textdocument-listitemstyles/mainwindow.cpp add a styled, ordered list
2266 \enum QTextListFormat::Style
2268 This enum describes the symbols used to decorate list items:
2270 \value ListDisc a filled circle
2271 \value ListCircle an empty circle
2272 \value ListSquare a filled square
2273 \value ListDecimal decimal values in ascending order
2274 \value ListLowerAlpha lower case Latin characters in alphabetical order
2275 \value ListUpperAlpha upper case Latin characters in alphabetical order
2276 \value ListLowerRoman lower case roman numerals (supports up to 4999 items only)
2277 \value ListUpperRoman upper case roman numerals (supports up to 4999 items only)
2278 \omitvalue ListStyleUndefined
2282 \fn QTextListFormat::QTextListFormat()
2284 Constructs a new list format object.
2286 QTextListFormat::QTextListFormat()
2287 : QTextFormat(ListFormat)
2294 \fn QTextListFormat::QTextListFormat(const QTextFormat &other)
2296 Creates a new list format with the same attributes as the \a given
2299 QTextListFormat::QTextListFormat(const QTextFormat &fmt)
2305 \fn bool QTextListFormat::isValid() const
2307 Returns true if this list format is valid; otherwise
2312 \fn void QTextListFormat::setStyle(Style style)
2314 Sets the list format's \a style.
2320 \fn Style QTextListFormat::style() const
2322 Returns the list format's style.
2324 \sa setStyle() Style
2329 \fn void QTextListFormat::setIndent(int indentation)
2331 Sets the list format's \a indentation.
2332 The indentation is multiplied by the QTextDocument::indentWidth
2333 property to get the effective indent in pixels.
2340 \fn int QTextListFormat::indent() const
2342 Returns the list format's indentation.
2343 The indentation is multiplied by the QTextDocument::indentWidth
2344 property to get the effective indent in pixels.
2350 \fn void QTextListFormat::setNumberPrefix(const QString &numberPrefix)
2353 Sets the list format's number prefix to the string specified by
2354 \a numberPrefix. This can be used with all sorted list types. It does not
2355 have any effect on unsorted list types.
2357 The default prefix is an empty string.
2363 \fn int QTextListFormat::numberPrefix() const
2366 Returns the list format's number prefix.
2368 \sa setNumberPrefix()
2372 \fn void QTextListFormat::setNumberSuffix(const QString &numberSuffix)
2375 Sets the list format's number suffix to the string specified by
2376 \a numberSuffix. This can be used with all sorted list types. It does not
2377 have any effect on unsorted list types.
2379 The default suffix is ".".
2385 \fn int QTextListFormat::numberSuffix() const
2388 Returns the list format's number suffix.
2390 \sa setNumberSuffix()
2394 \class QTextFrameFormat
2397 \brief The QTextFrameFormat class provides formatting information for
2398 frames in a QTextDocument.
2400 \ingroup richtext-processing
2402 A text frame groups together one or more blocks of text, providing a layer
2403 of structure larger than the paragraph. The format of a frame specifies
2404 how it is rendered and positioned on the screen. It does not directly
2405 specify the behavior of the text formatting within, but provides
2406 constraints on the layout of its children.
2408 The frame format defines the width() and height() of the frame on the
2409 screen. Each frame can have a border() that surrounds its contents with
2410 a rectangular box. The border is surrounded by a margin() around the frame,
2411 and the contents of the frame are kept separate from the border by the
2412 frame's padding(). This scheme is similar to the box model used by Cascading
2413 Style Sheets for HTML pages.
2415 \img qtextframe-style.png
2417 The position() of a frame is set using setPosition() and determines how it
2418 is located relative to the surrounding text.
2420 The validity of a QTextFrameFormat object can be determined with the
2423 \sa QTextFrame QTextBlockFormat
2427 \enum QTextFrameFormat::Position
2429 This enum describes how a frame is located relative to the surrounding text.
2435 \sa position() CssFloat
2439 \enum QTextFrameFormat::BorderStyle
2442 This enum describes different border styles for the text frame.
2444 \value BorderStyle_None
2445 \value BorderStyle_Dotted
2446 \value BorderStyle_Dashed
2447 \value BorderStyle_Solid
2448 \value BorderStyle_Double
2449 \value BorderStyle_DotDash
2450 \value BorderStyle_DotDotDash
2451 \value BorderStyle_Groove
2452 \value BorderStyle_Ridge
2453 \value BorderStyle_Inset
2454 \value BorderStyle_Outset
2456 \sa borderStyle() FrameBorderStyle
2460 \fn QTextFrameFormat::QTextFrameFormat()
2462 Constructs a text frame format object with the default properties.
2464 QTextFrameFormat::QTextFrameFormat() : QTextFormat(FrameFormat)
2466 setBorderStyle(BorderStyle_Outset);
2467 setBorderBrush(Qt::darkGray);
2472 \fn QTextFrameFormat::QTextFrameFormat(const QTextFormat &other)
2474 Creates a new frame format with the same attributes as the \a given
2477 QTextFrameFormat::QTextFrameFormat(const QTextFormat &fmt)
2483 \fn QTextFrameFormat::isValid() const
2485 Returns true if the format description is valid; otherwise returns false.
2489 \fn QTextFrameFormat::setPosition(Position policy)
2491 Sets the \a policy for positioning frames with this frame format.
2496 \fn Position QTextFrameFormat::position() const
2498 Returns the positioning policy for frames with this frame format.
2502 \fn QTextFrameFormat::setBorder(qreal width)
2504 Sets the \a width (in pixels) of the frame's border.
2508 \fn qreal QTextFrameFormat::border() const
2510 Returns the width of the border in pixels.
2514 \fn QTextFrameFormat::setBorderBrush(const QBrush &brush)
2517 Sets the \a brush used for the frame's border.
2521 \fn QBrush QTextFrameFormat::borderBrush() const
2524 Returns the brush used for the frame's border.
2528 \fn QTextFrameFormat::setBorderStyle(BorderStyle style)
2531 Sets the \a style of the frame's border.
2535 \fn BorderStyle QTextFrameFormat::borderStyle() const
2538 Returns the style of the frame's border.
2542 \fn QTextFrameFormat::setMargin(qreal margin)
2544 Sets the frame's \a margin in pixels.
2545 This method also sets the left, right, top and bottom margins
2546 of the frame to the same value. The individual margins override
2549 void QTextFrameFormat::setMargin(qreal amargin)
2551 setProperty(FrameMargin, amargin);
2552 setProperty(FrameTopMargin, amargin);
2553 setProperty(FrameBottomMargin, amargin);
2554 setProperty(FrameLeftMargin, amargin);
2555 setProperty(FrameRightMargin, amargin);
2560 \fn qreal QTextFrameFormat::margin() const
2562 Returns the width of the frame's external margin in pixels.
2566 \fn QTextFrameFormat::setTopMargin(qreal margin)
2569 Sets the frame's top \a margin in pixels.
2573 \fn qreal QTextFrameFormat::topMargin() const
2576 Returns the width of the frame's top margin in pixels.
2578 qreal QTextFrameFormat::topMargin() const
2580 if (!hasProperty(FrameTopMargin))
2582 return doubleProperty(FrameTopMargin);
2586 \fn QTextFrameFormat::setBottomMargin(qreal margin)
2589 Sets the frame's bottom \a margin in pixels.
2593 \fn qreal QTextFrameFormat::bottomMargin() const
2596 Returns the width of the frame's bottom margin in pixels.
2598 qreal QTextFrameFormat::bottomMargin() const
2600 if (!hasProperty(FrameBottomMargin))
2602 return doubleProperty(FrameBottomMargin);
2606 \fn QTextFrameFormat::setLeftMargin(qreal margin)
2609 Sets the frame's left \a margin in pixels.
2613 \fn qreal QTextFrameFormat::leftMargin() const
2616 Returns the width of the frame's left margin in pixels.
2618 qreal QTextFrameFormat::leftMargin() const
2620 if (!hasProperty(FrameLeftMargin))
2622 return doubleProperty(FrameLeftMargin);
2626 \fn QTextFrameFormat::setRightMargin(qreal margin)
2629 Sets the frame's right \a margin in pixels.
2633 \fn qreal QTextFrameFormat::rightMargin() const
2636 Returns the width of the frame's right margin in pixels.
2638 qreal QTextFrameFormat::rightMargin() const
2640 if (!hasProperty(FrameRightMargin))
2642 return doubleProperty(FrameRightMargin);
2646 \fn QTextFrameFormat::setPadding(qreal width)
2648 Sets the \a width of the frame's internal padding in pixels.
2652 \fn qreal QTextFrameFormat::padding() const
2654 Returns the width of the frame's internal padding in pixels.
2658 \fn QTextFrameFormat::setWidth(const QTextLength &width)
2660 Sets the frame's border rectangle's \a width.
2666 \fn QTextFrameFormat::setWidth(qreal width)
2669 Convenience method that sets the width of the frame's border
2670 rectangle's width to the specified fixed \a width.
2674 \fn QTextFormat::PageBreakFlags QTextFrameFormat::pageBreakPolicy() const
2677 Returns the currently set page break policy for the frame/table. The default is
2678 QTextFormat::PageBreak_Auto.
2680 \sa setPageBreakPolicy()
2684 \fn void QTextFrameFormat::setPageBreakPolicy(PageBreakFlags policy)
2687 Sets the page break policy for the frame/table to \a policy.
2689 \sa pageBreakPolicy()
2693 \fn QTextLength QTextFrameFormat::width() const
2695 Returns the width of the frame's border rectangle.
2701 \fn void QTextFrameFormat::setHeight(const QTextLength &height)
2703 Sets the frame's \a height.
2707 \fn void QTextFrameFormat::setHeight(qreal height)
2710 Sets the frame's \a height.
2714 \fn qreal QTextFrameFormat::height() const
2716 Returns the height of the frame's border rectangle.
2720 \class QTextTableFormat
2723 \brief The QTextTableFormat class provides formatting information for
2724 tables in a QTextDocument.
2726 \ingroup richtext-processing
2728 A table is a group of cells ordered into rows and columns. Each table
2729 contains at least one row and one column. Each cell contains a block.
2730 Tables in rich text documents are formatted using the properties
2731 defined in this class.
2733 Tables are horizontally justified within their parent frame according to the
2734 table's alignment. This can be read with the alignment() function and set
2735 with setAlignment().
2737 Cells within the table are separated by cell spacing. The number of pixels
2738 between cells is set with setCellSpacing() and read with cellSpacing().
2739 The contents of each cell is surrounded by cell padding. The number of pixels
2740 between each cell edge and its contents is set with setCellPadding() and read
2743 \image qtexttableformat-cell.png
2745 The table's background color can be read with the background() function,
2746 and can be specified with setBackground(). The background color of each
2747 cell can be set independently, and will control the color of the cell within
2750 The table format also provides a way to constrain the widths of the columns
2751 in the table. Columns can be assigned a fixed width, a variable width, or
2752 a percentage of the available width (see QTextLength). The columns() function
2753 returns the number of columns with constraints, and the
2754 columnWidthConstraints() function returns the constraints defined for the
2755 table. These quantities can also be set by calling setColumnWidthConstraints()
2756 with a vector containing new constraints. If no constraints are
2757 required, clearColumnWidthConstraints() can be used to remove them.
2759 \sa QTextTable QTextTableCell QTextLength
2763 \fn QTextTableFormat::QTextTableFormat()
2765 Constructs a new table format object.
2767 QTextTableFormat::QTextTableFormat()
2768 : QTextFrameFormat()
2770 setObjectType(TableObject);
2777 \fn QTextTableFormat::QTextTableFormat(const QTextFormat &other)
2779 Creates a new table format with the same attributes as the \a given
2782 QTextTableFormat::QTextTableFormat(const QTextFormat &fmt)
2783 : QTextFrameFormat(fmt)
2788 \fn bool QTextTableFormat::isValid() const
2790 Returns true if this table format is valid; otherwise
2796 \fn int QTextTableFormat::columns() const
2798 Returns the number of columns specified by the table format.
2804 \fn void QTextTableFormat::setColumns(int columns)
2806 Sets the number of \a columns required by the table format.
2812 \fn void QTextTableFormat::clearColumnWidthConstraints()
2814 Clears the column width constraints for the table.
2816 \sa columnWidthConstraints() setColumnWidthConstraints()
2820 \fn void QTextTableFormat::setColumnWidthConstraints(const QVector<QTextLength> &constraints)
2822 Sets the column width \a constraints for the table.
2824 \sa columnWidthConstraints() clearColumnWidthConstraints()
2828 \fn QVector<QTextLength> QTextTableFormat::columnWidthConstraints() const
2830 Returns a list of constraints used by this table format to control the
2831 appearance of columns in a table.
2833 \sa setColumnWidthConstraints()
2837 \fn qreal QTextTableFormat::cellSpacing() const
2839 Returns the table's cell spacing. This describes the distance between
2844 \fn void QTextTableFormat::setCellSpacing(qreal spacing)
2846 Sets the cell \a spacing for the table. This determines the distance
2847 between adjacent cells.
2851 \fn qreal QTextTableFormat::cellPadding() const
2853 Returns the table's cell padding. This describes the distance between
2854 the border of a cell and its contents.
2858 \fn void QTextTableFormat::setCellPadding(qreal padding)
2860 Sets the cell \a padding for the table. This determines the distance
2861 between the border of a cell and its contents.
2865 \fn void QTextTableFormat::setAlignment(Qt::Alignment alignment)
2867 Sets the table's \a alignment.
2873 \fn Qt::Alignment QTextTableFormat::alignment() const
2875 Returns the table's alignment.
2881 \fn void QTextTableFormat::setHeaderRowCount(int count)
2884 Declares the first \a count rows of the table as table header.
2885 The table header rows get repeated when a table is broken
2886 across a page boundary.
2890 \fn int QTextTableFormat::headerRowCount() const
2893 Returns the number of rows in the table that define the header.
2895 \sa setHeaderRowCount()
2899 \fn void QTextFormat::setBackground(const QBrush &brush)
2901 Sets the brush use to paint the document's background to the
2904 \sa background() clearBackground() setForeground()
2908 \fn QColor QTextFormat::background() const
2910 Returns the brush used to paint the document's background.
2912 \sa setBackground() clearBackground() foreground()
2916 \fn void QTextFormat::clearBackground()
2918 Clears the brush used to paint the document's background. The default
2921 \sa background() setBackground() clearForeground()
2926 \class QTextImageFormat
2929 \brief The QTextImageFormat class provides formatting information for
2930 images in a QTextDocument.
2932 \ingroup richtext-processing
2934 Inline images are represented by an object replacement character
2935 (0xFFFC in Unicode) which has an associated QTextImageFormat. The
2936 image format specifies a name with setName() that is used to
2937 locate the image. The size of the rectangle that the image will
2938 occupy is specified using setWidth() and setHeight().
2940 Images can be supplied in any format for which Qt has an image
2941 reader, so SVG drawings can be included alongside PNG, TIFF and
2942 other bitmap formats.
2944 \sa QImage, QImageReader
2948 \fn QTextImageFormat::QTextImageFormat()
2950 Creates a new image format object.
2952 QTextImageFormat::QTextImageFormat() : QTextCharFormat() { setObjectType(ImageObject); }
2956 \fn QTextImageFormat::QTextImageFormat(const QTextFormat &other)
2958 Creates a new image format with the same attributes as the \a given
2961 QTextImageFormat::QTextImageFormat(const QTextFormat &fmt)
2962 : QTextCharFormat(fmt)
2967 \fn bool QTextImageFormat::isValid() const
2969 Returns true if this image format is valid; otherwise returns false.
2974 \fn void QTextImageFormat::setName(const QString &name)
2976 Sets the \a name of the image. The \a name is used to locate the image
2977 in the application's resources.
2984 \fn QString QTextImageFormat::name() const
2986 Returns the name of the image. The name refers to an entry in the
2987 application's resources file.
2993 \fn void QTextImageFormat::setWidth(qreal width)
2995 Sets the \a width of the rectangle occupied by the image.
2997 \sa width() setHeight()
3001 // ### Qt5 qreal replace with a QTextLength
3003 \fn qreal QTextImageFormat::width() const
3005 Returns the width of the rectangle occupied by the image.
3007 \sa height() setWidth()
3012 \fn void QTextImageFormat::setHeight(qreal height)
3014 Sets the \a height of the rectangle occupied by the image.
3016 \sa height() setWidth()
3020 // ### Qt5 qreal replace with a QTextLength
3022 \fn qreal QTextImageFormat::height() const
3024 Returns the height of the rectangle occupied by the image.
3026 \sa width() setHeight()
3030 \fn void QTextCharFormat::setFontCapitalization(QFont::Capitalization capitalization)
3033 Sets the capitalization of the text that apppears in this font to \a capitalization.
3035 A font's capitalization makes the text appear in the selected capitalization mode.
3037 \sa fontCapitalization()
3041 \fn Capitalization QTextCharFormat::fontCapitalization() const
3044 Returns the current capitalization type of the font.
3048 \fn void QTextCharFormat::setFontLetterSpacing(qreal spacing)
3051 Sets the letter spacing of this format to the given \a spacing, in percent.
3052 A value of 100 indicates default spacing; a value of 200 doubles the amount
3053 of space a letter takes.
3055 \sa fontLetterSpacing()
3059 \fn qreal QTextCharFormat::fontLetterSpacing() const
3062 Returns the current letter spacing percentage.
3066 \fn void QTextCharFormat::setFontWordSpacing(qreal spacing)
3069 Sets the word spacing of this format to the given \a spacing, in pixels.
3071 \sa fontWordSpacing()
3075 \fn qreal QTextCharFormat::fontWordSpacing() const
3078 Returns the current word spacing value.
3082 \fn qreal QTextTableCellFormat::topPadding() const
3085 Gets the top padding of the table cell.
3087 \sa setTopPadding(), leftPadding(), rightPadding(), bottomPadding()
3091 \fn qreal QTextTableCellFormat::bottomPadding() const
3094 Gets the bottom padding of the table cell.
3096 \sa setBottomPadding(), leftPadding(), rightPadding(), topPadding()
3100 \fn qreal QTextTableCellFormat::leftPadding() const
3103 Gets the left padding of the table cell.
3105 \sa setLeftPadding(), rightPadding(), topPadding(), bottomPadding()
3109 \fn qreal QTextTableCellFormat::rightPadding() const
3112 Gets the right padding of the table cell.
3114 \sa setRightPadding(), leftPadding(), topPadding(), bottomPadding()
3118 \fn void QTextTableCellFormat::setTopPadding(qreal padding)
3121 Sets the top \a padding of the table cell.
3123 \sa topPadding(), setLeftPadding(), setRightPadding(), setBottomPadding()
3127 \fn void QTextTableCellFormat::setBottomPadding(qreal padding)
3130 Sets the bottom \a padding of the table cell.
3132 \sa bottomPadding(), setLeftPadding(), setRightPadding(), setTopPadding()
3136 \fn void QTextTableCellFormat::setLeftPadding(qreal padding)
3139 Sets the left \a padding of the table cell.
3141 \sa leftPadding(), setRightPadding(), setTopPadding(), setBottomPadding()
3145 \fn void QTextTableCellFormat::setRightPadding(qreal padding)
3148 Sets the right \a padding of the table cell.
3150 \sa rightPadding(), setLeftPadding(), setTopPadding(), setBottomPadding()
3154 \fn void QTextTableCellFormat::setPadding(qreal padding)
3157 Sets the left, right, top, and bottom \a padding of the table cell.
3159 \sa setLeftPadding(), setRightPadding(), setTopPadding(), setBottomPadding()
3163 \fn bool QTextTableCellFormat::isValid() const
3166 Returns true if this table cell format is valid; otherwise returns false.
3170 \fn QTextTableCellFormat::QTextTableCellFormat()
3173 Constructs a new table cell format object.
3175 QTextTableCellFormat::QTextTableCellFormat()
3178 setObjectType(TableCellObject);
3183 \fn QTextTableCellFormat::QTextTableCellFormat(const QTextFormat &other)
3185 Creates a new table cell format with the same attributes as the \a given
3188 QTextTableCellFormat::QTextTableCellFormat(const QTextFormat &fmt)
3189 : QTextCharFormat(fmt)
3194 \class QTextTableCellFormat
3198 \brief The QTextTableCellFormat class provides formatting information for
3199 table cells in a QTextDocument.
3201 \ingroup richtext-processing
3203 The table cell format of a table cell in a document specifies the visual
3204 properties of the table cell.
3206 The padding properties of a table cell are controlled by setLeftPadding(),
3207 setRightPadding(), setTopPadding(), and setBottomPadding(). All the paddings
3208 can be set at once using setPadding().
3210 \sa QTextFormat QTextBlockFormat QTextTableFormat QTextCharFormat
3213 // ------------------------------------------------------
3216 QTextFormatCollection::QTextFormatCollection(const QTextFormatCollection &rhs)
3218 formats = rhs.formats;
3219 objFormats = rhs.objFormats;
3222 QTextFormatCollection &QTextFormatCollection::operator=(const QTextFormatCollection &rhs)
3224 formats = rhs.formats;
3225 objFormats = rhs.objFormats;
3229 QTextFormatCollection::~QTextFormatCollection()
3233 int QTextFormatCollection::indexForFormat(const QTextFormat &format)
3235 uint hash = getHash(format.d, format.format_type);
3236 QMultiHash<uint, int>::const_iterator i = hashes.find(hash);
3237 while (i != hashes.end() && i.key() == hash) {
3238 if (formats.value(i.value()) == format) {
3244 int idx = formats.size();
3245 formats.append(format);
3248 QTextFormat &f = formats.last();
3250 f.d = new QTextFormatPrivate;
3251 f.d->resolveFont(defaultFnt);
3253 if (!hashes.contains(hash, idx))
3254 hashes.insert(hash, idx);
3263 bool QTextFormatCollection::hasFormatCached(const QTextFormat &format) const
3265 uint hash = getHash(format.d, format.format_type);
3266 QMultiHash<uint, int>::const_iterator i = hashes.find(hash);
3267 while (i != hashes.end() && i.key() == hash) {
3268 if (formats.value(i.value()) == format) {
3276 QTextFormat QTextFormatCollection::objectFormat(int objectIndex) const
3278 if (objectIndex == -1)
3279 return QTextFormat();
3280 return format(objFormats.at(objectIndex));
3283 void QTextFormatCollection::setObjectFormat(int objectIndex, const QTextFormat &f)
3285 const int formatIndex = indexForFormat(f);
3286 objFormats[objectIndex] = formatIndex;
3289 int QTextFormatCollection::objectFormatIndex(int objectIndex) const
3291 if (objectIndex == -1)
3293 return objFormats.at(objectIndex);
3296 void QTextFormatCollection::setObjectFormatIndex(int objectIndex, int formatIndex)
3298 objFormats[objectIndex] = formatIndex;
3301 int QTextFormatCollection::createObjectIndex(const QTextFormat &f)
3303 const int objectIndex = objFormats.size();
3304 objFormats.append(indexForFormat(f));
3308 QTextFormat QTextFormatCollection::format(int idx) const
3310 if (idx < 0 || idx >= formats.count())
3311 return QTextFormat();
3313 return formats.at(idx);
3316 void QTextFormatCollection::setDefaultFont(const QFont &f)
3319 for (int i = 0; i < formats.count(); ++i)
3321 formats[i].d->resolveFont(defaultFnt);