1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** 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::FontAbsoluteLetterSpacing:
398 f.setLetterSpacing(QFont::AbsoluteSpacing, props.at(i).value.toReal());
400 case QTextFormat::FontLetterSpacing:
401 f.setLetterSpacing(QFont::PercentageSpacing, props.at(i).value.toReal());
403 case QTextFormat::FontWordSpacing:
404 f.setWordSpacing(props.at(i).value.toReal());
406 case QTextFormat::FontCapitalization:
407 f.setCapitalization(static_cast<QFont::Capitalization> (props.at(i).value.toInt()));
409 case QTextFormat::FontFixedPitch: {
410 const bool value = props.at(i).value.toBool();
411 if (f.fixedPitch() != value)
412 f.setFixedPitch(value);
414 case QTextFormat::FontStretch:
415 f.setStretch(props.at(i).value.toInt());
417 case QTextFormat::FontStyleHint:
418 f.setStyleHint(static_cast<QFont::StyleHint>(props.at(i).value.toInt()), f.styleStrategy());
420 case QTextFormat::FontHintingPreference:
421 f.setHintingPreference(static_cast<QFont::HintingPreference>(props.at(i).value.toInt()));
423 case QTextFormat::FontStyleStrategy:
424 f.setStyleStrategy(static_cast<QFont::StyleStrategy>(props.at(i).value.toInt()));
426 case QTextFormat::FontKerning:
427 f.setKerning(props.at(i).value.toBool());
437 #ifndef QT_NO_DATASTREAM
438 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QTextFormat &fmt)
440 stream << fmt.format_type << fmt.properties();
444 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QTextFormat &fmt)
446 QMap<qint32, QVariant> properties;
447 stream >> fmt.format_type >> properties;
449 // QTextFormat's default constructor doesn't allocate the private structure, so
450 // we have to do this, in case fmt is a default constructed value.
452 fmt.d = new QTextFormatPrivate();
454 for (QMap<qint32, QVariant>::ConstIterator it = properties.constBegin();
455 it != properties.constEnd(); ++it)
456 fmt.d->insertProperty(it.key(), it.value());
460 #endif // QT_NO_DATASTREAM
466 \brief The QTextFormat class provides formatting information for a
469 \ingroup richtext-processing
472 A QTextFormat is a generic class used for describing the format of
473 parts of a QTextDocument. The derived classes QTextCharFormat,
474 QTextBlockFormat, QTextListFormat, and QTextTableFormat are usually
475 more useful, and describe the formatting that is applied to
476 specific parts of the document.
478 A format has a \c FormatType which specifies the kinds of text item it
479 can format; e.g. a block of text, a list, a table, etc. A format
480 also has various properties (some specific to particular format
481 types), as described by the Property enum. Every property has a
482 corresponding Property.
484 The format type is given by type(), and the format can be tested
485 with isCharFormat(), isBlockFormat(), isListFormat(),
486 isTableFormat(), isFrameFormat(), and isImageFormat(). If the
487 type is determined, it can be retrieved with toCharFormat(),
488 toBlockFormat(), toListFormat(), toTableFormat(), toFrameFormat(),
491 A format's properties can be set with the setProperty() functions,
492 and retrieved with boolProperty(), intProperty(), doubleProperty(),
493 and stringProperty() as appropriate. All the property IDs used in
494 the format can be retrieved with allPropertyIds(). One format can
495 be merged into another using merge().
497 A format's object index can be set with setObjectIndex(), and
498 retrieved with objectIndex(). These methods can be used to
499 associate the format with a QTextObject. It is used to represent
500 lists, frames, and tables inside the document.
502 \sa {Rich Text Processing}
506 \enum QTextFormat::FormatType
508 This enum describes the text item a QTextFormat object is formatting.
510 \value InvalidFormat An invalid format as created by the default
512 \value BlockFormat The object formats a text block
513 \value CharFormat The object formats a single character
514 \value ListFormat The object formats a list
515 \value TableFormat The object formats a table
516 \value FrameFormat The object formats a frame
520 \sa QTextCharFormat, QTextBlockFormat, QTextListFormat,
521 QTextTableFormat, type()
525 \enum QTextFormat::Property
527 This enum describes the different properties a format can have.
529 \value ObjectIndex The index of the formatted object. See objectIndex().
531 Paragraph and character properties
533 \value CssFloat How a frame is located relative to the surrounding text
534 \value LayoutDirection The layout direction of the text in the document
535 (Qt::LayoutDirection).
538 \value ForegroundBrush
539 \value BackgroundBrush
540 \value BackgroundImageUrl
544 \value BlockAlignment
545 \value BlockTopMargin
546 \value BlockBottomMargin
547 \value BlockLeftMargin
548 \value BlockRightMargin
550 \value TabPositions Specifies the tab positions. The tab positions are structs of QTextOption::Tab which are stored in
551 a QList (internally, in a QList<QVariant>).
554 \value LineHeightType
555 \value BlockNonBreakableLines
556 \value BlockTrailingHorizontalRulerWidth The width of a horizontal ruler element.
563 \value FontSizeAdjustment Specifies the change in size given to the fontsize already set using
564 FontPointSize or FontPixelSize.
565 \value FontFixedPitch
566 \omitvalue FontSizeIncrement
569 \value FontUnderline \e{This property has been deprecated.} Use QTextFormat::TextUnderlineStyle instead.
572 \value FontCapitalization Specifies the capitalization type that is to be applied to the text.
573 \value FontAbsoluteLetterSpacing If true FontLetterSpacing is absolute
574 \value FontLetterSpacing Changes the default spacing between individual letters in the font. The value is
575 specified in percentage, with 100 as the default value.
576 \value FontWordSpacing Changes the default spacing between individual words. A positive value increases the word spacing
577 by the corresponding pixels; a negative value decreases the spacing.
578 \value FontStretch Corresponds to the QFont::Stretch property
579 \value FontStyleHint Corresponds to the QFont::StyleHint property
580 \value FontStyleStrategy Corresponds to the QFont::StyleStrategy property
581 \value FontKerning Specifies whether the font has kerning turned on.
582 \value FontHintingPreference Controls the use of hinting according to values
583 of the QFont::HintingPreference enum.
585 \omitvalue FirstFontProperty
586 \omitvalue LastFontProperty
588 \value TextUnderlineColor
589 \value TextVerticalAlignment
591 \value TextUnderlineStyle
592 \value TextToolTip Specifies the (optional) tool tip to be displayed for a fragment of text.
601 \value ListStyle Specifies the style used for the items in a list,
602 described by values of the QTextListFormat::Style enum.
603 \value ListIndent Specifies the amount of indentation used for a list.
604 \value ListNumberPrefix Defines the text which is prepended to item numbers in
606 \value ListNumberSuffix Defines the text which is appended to item numbers in
609 Table and frame properties
612 \value FrameBorderBrush
613 \value FrameBorderStyle See the \l{QTextFrameFormat::BorderStyle}{BorderStyle} enum.
614 \value FrameBottomMargin
616 \value FrameLeftMargin
619 \value FrameRightMargin
620 \value FrameTopMargin
622 \value TableCellSpacing
623 \value TableCellPadding
625 \value TableColumnWidthConstraints
626 \value TableHeaderRowCount
628 Table cell properties
630 \value TableCellRowSpan
631 \value TableCellColumnSpan
632 \value TableCellLeftPadding
633 \value TableCellRightPadding
634 \value TableCellTopPadding
635 \value TableCellBottomPadding
645 \value FullWidthSelection When set on the characterFormat of a selection,
646 the whole width of the text will be shown selected.
648 Page break properties
650 \value PageBreakPolicy Specifies how pages are broken. See the PageBreakFlag enum.
654 \sa property(), setProperty()
658 \enum QTextFormat::ObjectTypes
660 This enum describes what kind of QTextObject this format is associated with.
665 \value TableCellObject
666 \value UserObject The first object that can be used for application-specific purposes.
668 \sa QTextObject, QTextTable, QTextObject::format()
672 \enum QTextFormat::PageBreakFlag
675 This enum describes how page breaking is performed when printing. It maps to the
676 corresponding css properties.
678 \value PageBreak_Auto The page break is determined automatically depending on the
679 available space on the current page
680 \value PageBreak_AlwaysBefore The page is always broken before the paragraph/table
681 \value PageBreak_AlwaysAfter A new page is always started after the paragraph/table
683 \sa QTextBlockFormat::pageBreakPolicy(), QTextFrameFormat::pageBreakPolicy(),
688 \fn bool QTextFormat::isValid() const
690 Returns true if the format is valid (i.e. is not
691 InvalidFormat); otherwise returns false.
695 \fn bool QTextFormat::isCharFormat() const
697 Returns true if this text format is a \c CharFormat; otherwise
703 \fn bool QTextFormat::isBlockFormat() const
705 Returns true if this text format is a \c BlockFormat; otherwise
711 \fn bool QTextFormat::isListFormat() const
713 Returns true if this text format is a \c ListFormat; otherwise
719 \fn bool QTextFormat::isTableFormat() const
721 Returns true if this text format is a \c TableFormat; otherwise
727 \fn bool QTextFormat::isFrameFormat() const
729 Returns true if this text format is a \c FrameFormat; otherwise
735 \fn bool QTextFormat::isImageFormat() const
737 Returns true if this text format is an image format; otherwise
743 \fn bool QTextFormat::isTableCellFormat() const
746 Returns true if this text format is a \c TableCellFormat; otherwise
752 Creates a new text format with an \c InvalidFormat.
756 QTextFormat::QTextFormat()
757 : format_type(InvalidFormat)
762 Creates a new text format of the given \a type.
766 QTextFormat::QTextFormat(int type)
773 \fn QTextFormat::QTextFormat(const QTextFormat &other)
775 Creates a new text format with the same attributes as the \a other
778 QTextFormat::QTextFormat(const QTextFormat &rhs)
779 : d(rhs.d), format_type(rhs.format_type)
784 \fn QTextFormat &QTextFormat::operator=(const QTextFormat &other)
786 Assigns the \a other text format to this text format, and returns a
787 reference to this text format.
789 QTextFormat &QTextFormat::operator=(const QTextFormat &rhs)
792 format_type = rhs.format_type;
797 Destroys this text format.
799 QTextFormat::~QTextFormat()
805 Returns the text format as a QVariant
807 QTextFormat::operator QVariant() const
809 return QVariant(QVariant::TextFormat, this);
813 Merges the \a other format with this format; where there are
814 conflicts the \a other format takes precedence.
816 void QTextFormat::merge(const QTextFormat &other)
818 if (format_type != other.format_type)
829 QTextFormatPrivate *d = this->d;
831 const QVector<QTextFormatPrivate::Property> &otherProps = other.d->props;
832 d->props.reserve(d->props.size() + otherProps.size());
833 for (int i = 0; i < otherProps.count(); ++i) {
834 const QTextFormatPrivate::Property &p = otherProps.at(i);
835 d->insertProperty(p.key, p.value);
840 Returns the type of this format.
844 int QTextFormat::type() const
850 Returns this format as a block format.
852 QTextBlockFormat QTextFormat::toBlockFormat() const
854 return QTextBlockFormat(*this);
858 Returns this format as a character format.
860 QTextCharFormat QTextFormat::toCharFormat() const
862 return QTextCharFormat(*this);
866 Returns this format as a list format.
868 QTextListFormat QTextFormat::toListFormat() const
870 return QTextListFormat(*this);
874 Returns this format as a table format.
876 QTextTableFormat QTextFormat::toTableFormat() const
878 return QTextTableFormat(*this);
882 Returns this format as a frame format.
884 QTextFrameFormat QTextFormat::toFrameFormat() const
886 return QTextFrameFormat(*this);
890 Returns this format as an image format.
892 QTextImageFormat QTextFormat::toImageFormat() const
894 return QTextImageFormat(*this);
900 Returns this format as a table cell format.
902 QTextTableCellFormat QTextFormat::toTableCellFormat() const
904 return QTextTableCellFormat(*this);
908 Returns the value of the property specified by \a propertyId. If the
909 property isn't of QTextFormat::Bool type, false is returned instead.
911 \sa setProperty(), intProperty(), doubleProperty(), stringProperty(), colorProperty(),
912 lengthProperty(), lengthVectorProperty(), Property
914 bool QTextFormat::boolProperty(int propertyId) const
918 const QVariant prop = d->property(propertyId);
919 if (prop.userType() != QVariant::Bool)
921 return prop.toBool();
925 Returns the value of the property specified by \a propertyId. If the
926 property is not of QTextFormat::Integer type, 0 is returned instead.
928 \sa setProperty(), boolProperty(), doubleProperty(), stringProperty(), colorProperty(),
929 lengthProperty(), lengthVectorProperty(), Property
931 int QTextFormat::intProperty(int propertyId) const
933 // required, since the default layout direction has to be LayoutDirectionAuto, which is not integer 0
934 int def = (propertyId == QTextFormat::LayoutDirection) ? int(Qt::LayoutDirectionAuto) : 0;
938 const QVariant prop = d->property(propertyId);
939 if (prop.userType() != QVariant::Int)
945 Returns the value of the property specified by \a propertyId. If the
946 property isn't of QVariant::Double or QMetaType::Float type, 0 is
949 \sa setProperty(), boolProperty(), intProperty(), stringProperty(), colorProperty(),
950 lengthProperty(), lengthVectorProperty(), Property
952 qreal QTextFormat::doubleProperty(int propertyId) const
956 const QVariant prop = d->property(propertyId);
957 if (prop.userType() != QVariant::Double && prop.userType() != QMetaType::Float)
959 return qvariant_cast<qreal>(prop);
963 Returns the value of the property given by \a propertyId; if the
964 property isn't of QVariant::String type, an empty string is
967 \sa setProperty(), boolProperty(), intProperty(), doubleProperty(), colorProperty(),
968 lengthProperty(), lengthVectorProperty(), Property
970 QString QTextFormat::stringProperty(int propertyId) const
974 const QVariant prop = d->property(propertyId);
975 if (prop.userType() != QVariant::String)
977 return prop.toString();
981 Returns the value of the property given by \a propertyId; if the
982 property isn't of QVariant::Color type, an invalid color is
985 \sa setProperty(), boolProperty(), intProperty(), doubleProperty(),
986 stringProperty(), lengthProperty(), lengthVectorProperty(), Property
988 QColor QTextFormat::colorProperty(int propertyId) const
992 const QVariant prop = d->property(propertyId);
993 if (prop.userType() != QVariant::Color)
995 return qvariant_cast<QColor>(prop);
999 Returns the value of the property given by \a propertyId; if the
1000 property isn't of QVariant::Pen type, Qt::NoPen is
1003 \sa setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(),
1004 lengthProperty(), lengthVectorProperty(), Property
1006 QPen QTextFormat::penProperty(int propertyId) const
1009 return QPen(Qt::NoPen);
1010 const QVariant prop = d->property(propertyId);
1011 if (prop.userType() != QVariant::Pen)
1012 return QPen(Qt::NoPen);
1013 return qvariant_cast<QPen>(prop);
1017 Returns the value of the property given by \a propertyId; if the
1018 property isn't of QVariant::Brush type, Qt::NoBrush is
1021 \sa setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(),
1022 lengthProperty(), lengthVectorProperty(), Property
1024 QBrush QTextFormat::brushProperty(int propertyId) const
1027 return QBrush(Qt::NoBrush);
1028 const QVariant prop = d->property(propertyId);
1029 if (prop.userType() != QVariant::Brush)
1030 return QBrush(Qt::NoBrush);
1031 return qvariant_cast<QBrush>(prop);
1035 Returns the value of the property given by \a propertyId.
1037 \sa setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(),
1038 colorProperty(), lengthVectorProperty(), Property
1040 QTextLength QTextFormat::lengthProperty(int propertyId) const
1043 return QTextLength();
1044 return qvariant_cast<QTextLength>(d->property(propertyId));
1048 Returns the value of the property given by \a propertyId. If the
1049 property isn't of QTextFormat::LengthVector type, an empty length
1050 vector is returned instead.
1052 \sa setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(),
1053 colorProperty(), lengthProperty(), Property
1055 QVector<QTextLength> QTextFormat::lengthVectorProperty(int propertyId) const
1057 QVector<QTextLength> vector;
1060 const QVariant prop = d->property(propertyId);
1061 if (prop.userType() != QVariant::List)
1064 QList<QVariant> propertyList = prop.toList();
1065 for (int i=0; i<propertyList.size(); ++i) {
1066 QVariant var = propertyList.at(i);
1067 if (var.userType() == QVariant::TextLength)
1068 vector.append(qvariant_cast<QTextLength>(var));
1075 Returns the property specified by the given \a propertyId.
1079 QVariant QTextFormat::property(int propertyId) const
1081 return d ? d->property(propertyId) : QVariant();
1085 Sets the property specified by the \a propertyId to the given \a value.
1089 void QTextFormat::setProperty(int propertyId, const QVariant &value)
1092 d = new QTextFormatPrivate;
1093 if (!value.isValid())
1094 clearProperty(propertyId);
1096 d->insertProperty(propertyId, value);
1100 Sets the value of the property given by \a propertyId to \a value.
1102 \sa lengthVectorProperty(), Property
1104 void QTextFormat::setProperty(int propertyId, const QVector<QTextLength> &value)
1107 d = new QTextFormatPrivate;
1109 for (int i=0; i<value.size(); ++i)
1110 list << value.at(i);
1111 d->insertProperty(propertyId, list);
1115 Clears the value of the property given by \a propertyId
1119 void QTextFormat::clearProperty(int propertyId)
1123 d->clearProperty(propertyId);
1128 \fn void QTextFormat::setObjectType(int type)
1130 Sets the text format's object type to \a type.
1132 \sa ObjectTypes, objectType()
1137 \fn int QTextFormat::objectType() const
1139 Returns the text format's object type.
1141 \sa ObjectTypes, setObjectType()
1146 Returns the index of the format object, or -1 if the format object is invalid.
1148 \sa setObjectIndex()
1150 int QTextFormat::objectIndex() const
1154 const QVariant prop = d->property(ObjectIndex);
1155 if (prop.userType() != QVariant::Int) // ####
1157 return prop.toInt();
1161 \fn void QTextFormat::setObjectIndex(int index)
1163 Sets the format object's object \a index.
1167 void QTextFormat::setObjectIndex(int o)
1171 d->clearProperty(ObjectIndex);
1174 d = new QTextFormatPrivate;
1176 d->insertProperty(ObjectIndex, o);
1181 Returns true if the text format has a property with the given \a
1182 propertyId; otherwise returns false.
1184 \sa properties(), Property
1186 bool QTextFormat::hasProperty(int propertyId) const
1188 return d ? d->hasProperty(propertyId) : false;
1192 Returns the property type for the given \a propertyId.
1194 \sa hasProperty(), allPropertyIds(), Property
1198 Returns a map with all properties of this text format.
1200 QMap<int, QVariant> QTextFormat::properties() const
1202 QMap<int, QVariant> map;
1204 for (int i = 0; i < d->props.count(); ++i)
1205 map.insert(d->props.at(i).key, d->props.at(i).value);
1212 Returns the number of properties stored in the format.
1214 int QTextFormat::propertyCount() const
1216 return d ? d->props.count() : 0;
1220 \fn bool QTextFormat::operator!=(const QTextFormat &other) const
1222 Returns true if this text format is different from the \a other text
1228 \fn bool QTextFormat::operator==(const QTextFormat &other) const
1230 Returns true if this text format is the same as the \a other text
1233 bool QTextFormat::operator==(const QTextFormat &rhs) const
1235 if (format_type != rhs.format_type)
1241 if (d && d->props.isEmpty() && !rhs.d)
1244 if (!d && rhs.d && rhs.d->props.isEmpty())
1250 return *d == *rhs.d;
1254 \class QTextCharFormat
1257 \brief The QTextCharFormat class provides formatting information for
1258 characters in a QTextDocument.
1260 \ingroup richtext-processing
1262 The character format of text in a document specifies the visual properties
1263 of the text, as well as information about its role in a hypertext document.
1265 The font used can be set by supplying a font to the setFont() function, and
1266 each aspect of its appearance can be adjusted to give the desired effect.
1267 setFontFamily() and setFontPointSize() define the font's family (e.g. Times)
1268 and printed size; setFontWeight() and setFontItalic() provide control over
1269 the style of the font. setFontUnderline(), setFontOverline(),
1270 setFontStrikeOut(), and setFontFixedPitch() provide additional effects for
1273 The color is set with setForeground(). If the text is intended to be used
1274 as an anchor (for hyperlinks), this can be enabled with setAnchor(). The
1275 setAnchorHref() and setAnchorNames() functions are used to specify the
1276 information about the hyperlink's destination and the anchor's name.
1278 \sa QTextFormat, QTextBlockFormat, QTextTableFormat, QTextListFormat
1282 \enum QTextCharFormat::VerticalAlignment
1284 This enum describes the ways that adjacent characters can be vertically
1287 \value AlignNormal Adjacent characters are positioned in the standard
1288 way for text in the writing system in use.
1289 \value AlignSuperScript Characters are placed above the base line for
1291 \value AlignSubScript Characters are placed below the base line for
1293 \value AlignMiddle The center of the object is vertically aligned with the
1294 base line. Currently, this is only implemented for
1296 \value AlignBottom The bottom edge of the object is vertically aligned with
1298 \value AlignTop The top edge of the object is vertically aligned with
1300 \value AlignBaseline The base lines of the characters are aligned.
1304 \enum QTextCharFormat::UnderlineStyle
1306 This enum describes the different ways drawing underlined text.
1308 \value NoUnderline Text is draw without any underlining decoration.
1309 \value SingleUnderline A line is drawn using Qt::SolidLine.
1310 \value DashUnderline Dashes are drawn using Qt::DashLine.
1311 \value DotLine Dots are drawn using Qt::DotLine;
1312 \value DashDotLine Dashs and dots are drawn using Qt::DashDotLine.
1313 \value DashDotDotLine Underlines draw drawn using Qt::DashDotDotLine.
1314 \value WaveUnderline The text is underlined using a wave shaped line.
1315 \value SpellCheckUnderline The underline is drawn depending on the QStyle::SH_SpellCeckUnderlineStyle
1316 style hint of the QApplication style. By default this is mapped to
1317 WaveUnderline, on Mac OS X it is mapped to DashDotLine.
1323 \fn QTextCharFormat::QTextCharFormat()
1325 Constructs a new character format object.
1327 QTextCharFormat::QTextCharFormat() : QTextFormat(CharFormat) {}
1331 \fn QTextCharFormat::QTextCharFormat(const QTextFormat &other)
1333 Creates a new character format with the same attributes as the \a given
1336 QTextCharFormat::QTextCharFormat(const QTextFormat &fmt)
1342 \fn bool QTextCharFormat::isValid() const
1344 Returns true if this character format is valid; otherwise returns
1350 \fn void QTextCharFormat::setFontFamily(const QString &family)
1352 Sets the text format's font \a family.
1359 \fn QString QTextCharFormat::fontFamily() const
1361 Returns the text format's font family.
1368 \fn void QTextCharFormat::setFontPointSize(qreal size)
1370 Sets the text format's font \a size.
1377 \fn qreal QTextCharFormat::fontPointSize() const
1379 Returns the font size used to display text in this format.
1386 \fn void QTextCharFormat::setFontWeight(int weight)
1388 Sets the text format's font weight to \a weight.
1390 \sa setFont(), QFont::Weight
1395 \fn int QTextCharFormat::fontWeight() const
1397 Returns the text format's font weight.
1399 \sa font(), QFont::Weight
1404 \fn void QTextCharFormat::setFontItalic(bool italic)
1406 If \a italic is true, sets the text format's font to be italic; otherwise
1407 the font will be non-italic.
1414 \fn bool QTextCharFormat::fontItalic() const
1416 Returns true if the text format's font is italic; otherwise
1424 \fn void QTextCharFormat::setFontUnderline(bool underline)
1426 If \a underline is true, sets the text format's font to be underlined;
1427 otherwise it is displayed non-underlined.
1434 \fn bool QTextCharFormat::fontUnderline() const
1436 Returns true if the text format's font is underlined; otherwise
1441 bool QTextCharFormat::fontUnderline() const
1443 if (hasProperty(TextUnderlineStyle))
1444 return underlineStyle() == SingleUnderline;
1445 return boolProperty(FontUnderline);
1449 \fn UnderlineStyle QTextCharFormat::underlineStyle() const
1452 Returns the style of underlining the text.
1456 \fn void QTextCharFormat::setUnderlineStyle(UnderlineStyle style)
1459 Sets the style of underlining the text to \a style.
1461 void QTextCharFormat::setUnderlineStyle(UnderlineStyle style)
1463 setProperty(TextUnderlineStyle, style);
1464 // for compatibility
1465 setProperty(FontUnderline, style == SingleUnderline);
1469 \fn void QTextCharFormat::setFontOverline(bool overline)
1471 If \a overline is true, sets the text format's font to be overlined;
1472 otherwise the font is displayed non-overlined.
1479 \fn bool QTextCharFormat::fontOverline() const
1481 Returns true if the text format's font is overlined; otherwise
1489 \fn void QTextCharFormat::setFontStrikeOut(bool strikeOut)
1491 If \a strikeOut is true, sets the text format's font with strike-out
1492 enabled (with a horizontal line through it); otherwise it is displayed
1500 \fn bool QTextCharFormat::fontStrikeOut() const
1502 Returns true if the text format's font is struck out (has a horizontal line
1503 drawn through it); otherwise returns false.
1511 \fn void QTextCharFormat::setFontStyleHint(QFont::StyleHint hint, QFont::StyleStrategy strategy)
1513 Sets the font style \a hint and \a strategy.
1515 Qt does not support style hints on X11 since this information is not provided by the window system.
1518 \sa QFont::setStyleHint()
1524 \fn void QTextCharFormat::setFontStyleStrategy(QFont::StyleStrategy strategy)
1526 Sets the font style \a strategy.
1529 \sa QFont::setStyleStrategy()
1535 \fn void QTextCharFormat::setFontKerning(bool enable)
1536 Enables kerning for this font if \a enable is true; otherwise disables it.
1538 When kerning is enabled, glyph metrics do not add up anymore, even for
1539 Latin text. In other words, the assumption that width('a') + width('b')
1540 is equal to width("ab") is not neccesairly true.
1547 \fn QTextCharFormat::StyleHint QTextCharFormat::fontStyleHint() const
1550 Returns the font style hint.
1552 \sa setFontStyleHint(), font()
1558 \fn QTextCharFormat::StyleStrategy QTextCharFormat::fontStyleStrategy() const
1560 Returns the current font style strategy.
1562 \sa setFontStyleStrategy()
1569 \fn bool QTextCharFormat::fontKerning() const
1570 Returns true if the font kerning is enabled.
1572 \sa setFontKerning()
1578 \fn void QTextCharFormat::setFontFixedPitch(bool fixedPitch)
1580 If \a fixedPitch is true, sets the text format's font to be fixed pitch;
1581 otherwise a non-fixed pitch font is used.
1588 \fn bool QTextCharFormat::fontFixedPitch() const
1590 Returns true if the text format's font is fixed pitch; otherwise
1599 \fn void QTextCharFormat::setFontHintingPreference(QFont::HintingPreference hintingPreference)
1601 Sets the hinting preference of the text format's font to be \a hintingPreference.
1603 \sa setFont(), QFont::setHintingPreference()
1609 \fn QFont::HintingPreference QTextCharFormat::fontHintingPreference() const
1611 Returns the hinting preference set for this text format.
1613 \sa font(), QFont::hintingPreference()
1617 \fn QPen QTextCharFormat::textOutline() const
1619 Returns the pen used to draw the outlines of characters in this format.
1624 \fn void QTextCharFormat::setTextOutline(const QPen &pen)
1626 Sets the pen used to draw the outlines of characters to the given \a pen.
1630 \fn void QTextCharFormat::setToolTip(const QString &text)
1633 Sets the tool tip for a fragment of text to the given \a text.
1637 \fn QString QTextCharFormat::toolTip() const
1640 Returns the tool tip that is displayed for a fragment of text.
1644 \fn void QTextFormat::setForeground(const QBrush &brush)
1646 Sets the foreground brush to the specified \a brush. The foreground
1647 brush is mostly used to render text.
1649 \sa foreground(), clearForeground(), setBackground()
1654 \fn QBrush QTextFormat::foreground() const
1656 Returns the brush used to render foreground details, such as text,
1657 frame outlines, and table borders.
1659 \sa setForeground(), clearForeground(), background()
1663 \fn void QTextFormat::clearForeground()
1665 Clears the brush used to paint the document's foreground. The default
1668 \sa foreground(), setForeground(), clearBackground()
1673 \fn void QTextCharFormat::setAnchor(bool anchor)
1675 If \a anchor is true, text with this format represents an anchor, and is
1676 formatted in the appropriate way; otherwise the text is formatted normally.
1677 (Anchors are hyperlinks which are often shown underlined and in a different
1678 color from plain text.)
1680 The way the text is rendered is independent of whether or not the format
1681 has a valid anchor defined. Use setAnchorHref(), and optionally
1682 setAnchorNames() to create a hypertext link.
1689 \fn bool QTextCharFormat::isAnchor() const
1691 Returns true if the text is formatted as an anchor; otherwise
1694 \sa setAnchor(), setAnchorHref(), setAnchorNames()
1699 \fn void QTextCharFormat::setAnchorHref(const QString &value)
1701 Sets the hypertext link for the text format to the given \a value.
1702 This is typically a URL like "http://example.com/index.html".
1704 The anchor will be displayed with the \a value as its display text;
1705 if you want to display different text call setAnchorNames().
1707 To format the text as a hypertext link use setAnchor().
1712 \fn QString QTextCharFormat::anchorHref() const
1714 Returns the text format's hypertext link, or an empty string if
1720 \fn void QTextCharFormat::setAnchorName(const QString &name)
1723 This function is deprecated. Use setAnchorNames() instead.
1725 Sets the text format's anchor \a name. For the anchor to work as a
1726 hyperlink, the destination must be set with setAnchorHref() and
1727 the anchor must be enabled with setAnchor().
1731 \fn void QTextCharFormat::setAnchorNames(const QStringList &names)
1734 Sets the text format's anchor \a names. For the anchor to work as a
1735 hyperlink, the destination must be set with setAnchorHref() and
1736 the anchor must be enabled with setAnchor().
1740 \fn QString QTextCharFormat::anchorName() const
1743 This function is deprecated. Use anchorNames() instead.
1745 Returns the anchor name associated with this text format, or an empty
1746 string if none has been set. If the anchor name is set, text with this
1747 format can be the destination of a hypertext link.
1749 QString QTextCharFormat::anchorName() const
1751 QVariant prop = property(AnchorName);
1752 if (prop.userType() == QVariant::StringList)
1753 return prop.toStringList().value(0);
1754 else if (prop.userType() != QVariant::String)
1756 return prop.toString();
1760 \fn QStringList QTextCharFormat::anchorNames() const
1763 Returns the anchor names associated with this text format, or an empty
1764 string list if none has been set. If the anchor names are set, text with this
1765 format can be the destination of a hypertext link.
1767 QStringList QTextCharFormat::anchorNames() const
1769 QVariant prop = property(AnchorName);
1770 if (prop.userType() == QVariant::StringList)
1771 return prop.toStringList();
1772 else if (prop.userType() != QVariant::String)
1773 return QStringList();
1774 return QStringList(prop.toString());
1779 \fn void QTextCharFormat::setTableCellRowSpan(int tableCellRowSpan)
1782 If this character format is applied to characters in a table cell,
1783 the cell will span \a tableCellRowSpan rows.
1788 \fn int QTextCharFormat::tableCellRowSpan() const
1791 If this character format is applied to characters in a table cell,
1792 this function returns the number of rows spanned by the text (this may
1793 be 1); otherwise it returns 1.
1797 \fn void QTextCharFormat::setTableCellColumnSpan(int tableCellColumnSpan)
1800 If this character format is applied to characters in a table cell,
1801 the cell will span \a tableCellColumnSpan columns.
1806 \fn int QTextCharFormat::tableCellColumnSpan() const
1809 If this character format is applied to characters in a table cell,
1810 this function returns the number of columns spanned by the text (this
1811 may be 1); otherwise it returns 1.
1815 \fn void QTextCharFormat::setUnderlineColor(const QColor &color)
1817 Sets the underline color used for the characters with this format to
1818 the \a color specified.
1820 \sa underlineColor()
1824 \fn QColor QTextCharFormat::underlineColor() const
1826 Returns the color used to underline the characters with this format.
1828 \sa setUnderlineColor()
1832 \fn void QTextCharFormat::setVerticalAlignment(VerticalAlignment alignment)
1834 Sets the vertical alignment used for the characters with this format to
1835 the \a alignment specified.
1837 \sa verticalAlignment()
1841 \fn VerticalAlignment QTextCharFormat::verticalAlignment() const
1843 Returns the vertical alignment used for characters with this format.
1845 \sa setVerticalAlignment()
1849 Sets the text format's \a font.
1851 void QTextCharFormat::setFont(const QFont &font)
1853 setFontFamily(font.family());
1855 const qreal pointSize = font.pointSizeF();
1856 if (pointSize > 0) {
1857 setFontPointSize(pointSize);
1859 const int pixelSize = font.pixelSize();
1861 setProperty(QTextFormat::FontPixelSize, pixelSize);
1864 setFontWeight(font.weight());
1865 setFontItalic(font.italic());
1866 setUnderlineStyle(font.underline() ? SingleUnderline : NoUnderline);
1867 setFontOverline(font.overline());
1868 setFontStrikeOut(font.strikeOut());
1869 setFontFixedPitch(font.fixedPitch());
1870 setFontCapitalization(font.capitalization());
1871 setFontWordSpacing(font.wordSpacing());
1872 if (font.letterSpacingType() == QFont::AbsoluteSpacing) {
1873 setFontAbsoluteLetterSpacing(font.letterSpacing());
1875 setFontLetterSpacing(font.letterSpacing());
1877 setFontStretch(font.stretch());
1878 setFontStyleHint(font.styleHint());
1879 setFontStyleStrategy(font.styleStrategy());
1880 setFontKerning(font.kerning());
1884 Returns the font for this character format.
1886 QFont QTextCharFormat::font() const
1888 return d ? d->font() : QFont();
1892 \class QTextBlockFormat
1895 \brief The QTextBlockFormat class provides formatting information for
1896 blocks of text in a QTextDocument.
1898 \ingroup richtext-processing
1900 A document is composed of a list of blocks, represented by QTextBlock
1901 objects. Each block can contain an item of some kind, such as a
1902 paragraph of text, a table, a list, or an image. Every block has an
1903 associated QTextBlockFormat that specifies its characteristics.
1905 To cater for left-to-right and right-to-left languages you can set
1906 a block's direction with setDirection(). Paragraph alignment is
1907 set with setAlignment(). Margins are controlled by setTopMargin(),
1908 setBottomMargin(), setLeftMargin(), setRightMargin(). Overall
1909 indentation is set with setIndent(), the indentation of the first
1910 line with setTextIndent().
1912 Line spacing is set with setLineHeight() and retrieved via lineHeight()
1913 and lineHeightType(). The types of line spacing available are in the
1914 LineHeightTypes enum.
1916 Line breaking can be enabled and disabled with setNonBreakableLines().
1918 The brush used to paint the paragraph's background
1919 is set with \l{QTextFormat::setBackground()}{setBackground()}, and other
1920 aspects of the text's appearance can be customized by using the
1921 \l{QTextFormat::setProperty()}{setProperty()} function with the
1922 \c OutlinePen, \c ForegroundBrush, and \c BackgroundBrush
1923 \l{QTextFormat::Property} values.
1925 If a text block is part of a list, it can also have a list format that
1926 is accessible with the listFormat() function.
1928 \sa QTextBlock, QTextCharFormat
1933 \enum QTextBlockFormat::LineHeightTypes
1935 This enum describes the various types of line spacing support paragraphs can have.
1937 \value SingleHeight This is the default line height: single spacing.
1938 \value ProportionalHeight This sets the spacing proportional to the line (in percentage).
1939 For example, set to 200 for double spacing.
1940 \value FixedHeight This sets the line height to a fixed line height (in pixels).
1941 \value MinimumHeight This sets the minimum line height (in pixels).
1942 \value LineDistanceHeight This adds the specified height between lines (in pixels).
1944 \sa lineHeight(), lineHeightType(), setLineHeight()
1948 \fn QTextBlockFormat::QTextBlockFormat()
1950 Constructs a new QTextBlockFormat.
1952 QTextBlockFormat::QTextBlockFormat() : QTextFormat(BlockFormat) {}
1956 \fn QTextBlockFormat::QTextBlockFormat(const QTextFormat &other)
1958 Creates a new block format with the same attributes as the \a given
1961 QTextBlockFormat::QTextBlockFormat(const QTextFormat &fmt)
1968 Sets the tab positions for the text block to those specified by
1973 void QTextBlockFormat::setTabPositions(const QList<QTextOption::Tab> &tabs)
1975 QList<QVariant> list;
1976 QList<QTextOption::Tab>::ConstIterator iter = tabs.constBegin();
1977 while (iter != tabs.constEnd()) {
1979 v.setValue<QTextOption::Tab>(*iter);
1983 setProperty(TabPositions, list);
1988 Returns a list of tab positions defined for the text block.
1990 \sa setTabPositions()
1992 QList<QTextOption::Tab> QTextBlockFormat::tabPositions() const
1994 QVariant variant = property(TabPositions);
1995 if(variant.isNull())
1996 return QList<QTextOption::Tab>();
1997 QList<QTextOption::Tab> answer;
1998 QList<QVariant> variantsList = qvariant_cast<QList<QVariant> >(variant);
1999 QList<QVariant>::Iterator iter = variantsList.begin();
2000 while(iter != variantsList.end()) {
2001 answer.append( qvariant_cast<QTextOption::Tab>(*iter));
2008 \fn QTextBlockFormat::isValid() const
2010 Returns true if this block format is valid; otherwise returns
2015 \fn void QTextFormat::setLayoutDirection(Qt::LayoutDirection direction)
2017 Sets the document's layout direction to the specified \a direction.
2019 \sa layoutDirection()
2024 \fn Qt::LayoutDirection QTextFormat::layoutDirection() const
2026 Returns the document's layout direction.
2028 \sa setLayoutDirection()
2033 \fn void QTextBlockFormat::setAlignment(Qt::Alignment alignment)
2035 Sets the paragraph's \a alignment.
2042 \fn Qt::Alignment QTextBlockFormat::alignment() const
2044 Returns the paragraph's alignment.
2051 \fn void QTextBlockFormat::setTopMargin(qreal margin)
2053 Sets the paragraph's top \a margin.
2055 \sa topMargin(), setBottomMargin(), setLeftMargin(), setRightMargin()
2060 \fn qreal QTextBlockFormat::topMargin() const
2062 Returns the paragraph's top margin.
2064 \sa setTopMargin(), bottomMargin()
2069 \fn void QTextBlockFormat::setBottomMargin(qreal margin)
2071 Sets the paragraph's bottom \a margin.
2073 \sa bottomMargin(), setTopMargin(), setLeftMargin(), setRightMargin()
2078 \fn qreal QTextBlockFormat::bottomMargin() const
2080 Returns the paragraph's bottom margin.
2082 \sa setBottomMargin(), topMargin()
2087 \fn void QTextBlockFormat::setLeftMargin(qreal margin)
2089 Sets the paragraph's left \a margin. Indentation can be applied separately
2092 \sa leftMargin(), setRightMargin(), setTopMargin(), setBottomMargin()
2097 \fn qreal QTextBlockFormat::leftMargin() const
2099 Returns the paragraph's left margin.
2101 \sa setLeftMargin(), rightMargin(), indent()
2106 \fn void QTextBlockFormat::setRightMargin(qreal margin)
2108 Sets the paragraph's right \a margin.
2110 \sa rightMargin(), setLeftMargin(), setTopMargin(), setBottomMargin()
2115 \fn qreal QTextBlockFormat::rightMargin() const
2117 Returns the paragraph's right margin.
2119 \sa setRightMargin(), leftMargin()
2124 \fn void QTextBlockFormat::setTextIndent(qreal indent)
2126 Sets the \a indent for the first line in the block. This allows the first
2127 line of a paragraph to be indented differently to the other lines,
2128 enhancing the readability of the text.
2130 \sa textIndent(), setLeftMargin(), setRightMargin(), setTopMargin(), setBottomMargin()
2135 \fn qreal QTextBlockFormat::textIndent() const
2137 Returns the paragraph's text indent.
2144 \fn void QTextBlockFormat::setIndent(int indentation)
2146 Sets the paragraph's \a indentation. Margins are set independently of
2147 indentation with setLeftMargin() and setTextIndent().
2148 The \a indentation is an integer that is multiplied with the document-wide
2149 standard indent, resulting in the actual indent of the paragraph.
2151 \sa indent(), QTextDocument::indentWidth()
2156 \fn int QTextBlockFormat::indent() const
2158 Returns the paragraph's indent.
2165 \fn void QTextBlockFormat::setLineHeight(qreal height, int heightType)
2168 Sets the line height for the paragraph to the value given by \a height
2169 which is dependent on \a heightType in the way described by the
2170 LineHeightTypes enum.
2172 \sa LineHeightTypes, lineHeight(), lineHeightType()
2177 \fn qreal QTextBlockFormat::lineHeight(qreal scriptLineHeight, qreal scaling) const
2180 Returns the height of the lines in the paragraph based on the height of the
2181 script line given by \a scriptLineHeight and the specified \a scaling
2184 The value that is returned is also dependent on the given LineHeightType of
2185 the paragraph as well as the LineHeight setting that has been set for the
2188 The scaling is needed for heights that include a fixed number of pixels, to
2189 scale them appropriately for printing.
2191 \sa LineHeightTypes, setLineHeight(), lineHeightType()
2196 \fn qreal QTextBlockFormat::lineHeight() const
2199 This returns the LineHeight property for the paragraph.
2201 \sa LineHeightTypes, setLineHeight(), lineHeightType()
2206 \fn qreal QTextBlockFormat::lineHeightType() const
2209 This returns the LineHeightType property of the paragraph.
2211 \sa LineHeightTypes, setLineHeight(), lineHeight()
2216 \fn void QTextBlockFormat::setNonBreakableLines(bool b)
2218 If \a b is true, the lines in the paragraph are treated as
2219 non-breakable; otherwise they are breakable.
2221 \sa nonBreakableLines()
2226 \fn bool QTextBlockFormat::nonBreakableLines() const
2228 Returns true if the lines in the paragraph are non-breakable;
2229 otherwise returns false.
2231 \sa setNonBreakableLines()
2235 \fn QTextFormat::PageBreakFlags QTextBlockFormat::pageBreakPolicy() const
2238 Returns the currently set page break policy for the paragraph. The default is
2239 QTextFormat::PageBreak_Auto.
2241 \sa setPageBreakPolicy()
2245 \fn void QTextBlockFormat::setPageBreakPolicy(PageBreakFlags policy)
2248 Sets the page break policy for the paragraph to \a policy.
2250 \sa pageBreakPolicy()
2254 \class QTextListFormat
2257 \brief The QTextListFormat class provides formatting information for
2258 lists in a QTextDocument.
2260 \ingroup richtext-processing
2262 A list is composed of one or more items, represented as text blocks.
2263 The list's format specifies the appearance of items in the list.
2264 In particular, it determines the indentation and the style of each item.
2266 The indentation of the items is an integer value that causes each item to
2267 be offset from the left margin by a certain amount. This value is read with
2268 indent() and set with setIndent().
2270 The style used to decorate each item is set with setStyle() and can be read
2271 with the style() function. The style controls the type of bullet points and
2272 numbering scheme used for items in the list. Note that lists that use the
2273 decimal numbering scheme begin counting at 1 rather than 0.
2275 Style properties can be set to further configure the appearance of list
2276 items; for example, the ListNumberPrefix and ListNumberSuffix properties
2277 can be used to customize the numbers used in an ordered list so that they
2278 appear as (1), (2), (3), etc.:
2280 \snippet textdocument-listitemstyles/mainwindow.cpp add a styled, ordered list
2286 \enum QTextListFormat::Style
2288 This enum describes the symbols used to decorate list items:
2290 \value ListDisc a filled circle
2291 \value ListCircle an empty circle
2292 \value ListSquare a filled square
2293 \value ListDecimal decimal values in ascending order
2294 \value ListLowerAlpha lower case Latin characters in alphabetical order
2295 \value ListUpperAlpha upper case Latin characters in alphabetical order
2296 \value ListLowerRoman lower case roman numerals (supports up to 4999 items only)
2297 \value ListUpperRoman upper case roman numerals (supports up to 4999 items only)
2298 \omitvalue ListStyleUndefined
2302 \fn QTextListFormat::QTextListFormat()
2304 Constructs a new list format object.
2306 QTextListFormat::QTextListFormat()
2307 : QTextFormat(ListFormat)
2314 \fn QTextListFormat::QTextListFormat(const QTextFormat &other)
2316 Creates a new list format with the same attributes as the \a given
2319 QTextListFormat::QTextListFormat(const QTextFormat &fmt)
2325 \fn bool QTextListFormat::isValid() const
2327 Returns true if this list format is valid; otherwise
2332 \fn void QTextListFormat::setStyle(Style style)
2334 Sets the list format's \a style.
2340 \fn Style QTextListFormat::style() const
2342 Returns the list format's style.
2344 \sa setStyle(), Style
2349 \fn void QTextListFormat::setIndent(int indentation)
2351 Sets the list format's \a indentation.
2352 The indentation is multiplied by the QTextDocument::indentWidth
2353 property to get the effective indent in pixels.
2360 \fn int QTextListFormat::indent() const
2362 Returns the list format's indentation.
2363 The indentation is multiplied by the QTextDocument::indentWidth
2364 property to get the effective indent in pixels.
2370 \fn void QTextListFormat::setNumberPrefix(const QString &numberPrefix)
2373 Sets the list format's number prefix to the string specified by
2374 \a numberPrefix. This can be used with all sorted list types. It does not
2375 have any effect on unsorted list types.
2377 The default prefix is an empty string.
2383 \fn int QTextListFormat::numberPrefix() const
2386 Returns the list format's number prefix.
2388 \sa setNumberPrefix()
2392 \fn void QTextListFormat::setNumberSuffix(const QString &numberSuffix)
2395 Sets the list format's number suffix to the string specified by
2396 \a numberSuffix. This can be used with all sorted list types. It does not
2397 have any effect on unsorted list types.
2399 The default suffix is ".".
2405 \fn int QTextListFormat::numberSuffix() const
2408 Returns the list format's number suffix.
2410 \sa setNumberSuffix()
2414 \class QTextFrameFormat
2417 \brief The QTextFrameFormat class provides formatting information for
2418 frames in a QTextDocument.
2420 \ingroup richtext-processing
2422 A text frame groups together one or more blocks of text, providing a layer
2423 of structure larger than the paragraph. The format of a frame specifies
2424 how it is rendered and positioned on the screen. It does not directly
2425 specify the behavior of the text formatting within, but provides
2426 constraints on the layout of its children.
2428 The frame format defines the width() and height() of the frame on the
2429 screen. Each frame can have a border() that surrounds its contents with
2430 a rectangular box. The border is surrounded by a margin() around the frame,
2431 and the contents of the frame are kept separate from the border by the
2432 frame's padding(). This scheme is similar to the box model used by Cascading
2433 Style Sheets for HTML pages.
2435 \img qtextframe-style.png
2437 The position() of a frame is set using setPosition() and determines how it
2438 is located relative to the surrounding text.
2440 The validity of a QTextFrameFormat object can be determined with the
2443 \sa QTextFrame, QTextBlockFormat
2447 \enum QTextFrameFormat::Position
2449 This enum describes how a frame is located relative to the surrounding text.
2455 \sa position(), CssFloat
2459 \enum QTextFrameFormat::BorderStyle
2462 This enum describes different border styles for the text frame.
2464 \value BorderStyle_None
2465 \value BorderStyle_Dotted
2466 \value BorderStyle_Dashed
2467 \value BorderStyle_Solid
2468 \value BorderStyle_Double
2469 \value BorderStyle_DotDash
2470 \value BorderStyle_DotDotDash
2471 \value BorderStyle_Groove
2472 \value BorderStyle_Ridge
2473 \value BorderStyle_Inset
2474 \value BorderStyle_Outset
2476 \sa borderStyle(), FrameBorderStyle
2480 \fn QTextFrameFormat::QTextFrameFormat()
2482 Constructs a text frame format object with the default properties.
2484 QTextFrameFormat::QTextFrameFormat() : QTextFormat(FrameFormat)
2486 setBorderStyle(BorderStyle_Outset);
2487 setBorderBrush(Qt::darkGray);
2492 \fn QTextFrameFormat::QTextFrameFormat(const QTextFormat &other)
2494 Creates a new frame format with the same attributes as the \a given
2497 QTextFrameFormat::QTextFrameFormat(const QTextFormat &fmt)
2503 \fn QTextFrameFormat::isValid() const
2505 Returns true if the format description is valid; otherwise returns false.
2509 \fn QTextFrameFormat::setPosition(Position policy)
2511 Sets the \a policy for positioning frames with this frame format.
2516 \fn Position QTextFrameFormat::position() const
2518 Returns the positioning policy for frames with this frame format.
2522 \fn QTextFrameFormat::setBorder(qreal width)
2524 Sets the \a width (in pixels) of the frame's border.
2528 \fn qreal QTextFrameFormat::border() const
2530 Returns the width of the border in pixels.
2534 \fn QTextFrameFormat::setBorderBrush(const QBrush &brush)
2537 Sets the \a brush used for the frame's border.
2541 \fn QBrush QTextFrameFormat::borderBrush() const
2544 Returns the brush used for the frame's border.
2548 \fn QTextFrameFormat::setBorderStyle(BorderStyle style)
2551 Sets the \a style of the frame's border.
2555 \fn BorderStyle QTextFrameFormat::borderStyle() const
2558 Returns the style of the frame's border.
2562 \fn QTextFrameFormat::setMargin(qreal margin)
2564 Sets the frame's \a margin in pixels.
2565 This method also sets the left, right, top and bottom margins
2566 of the frame to the same value. The individual margins override
2569 void QTextFrameFormat::setMargin(qreal amargin)
2571 setProperty(FrameMargin, amargin);
2572 setProperty(FrameTopMargin, amargin);
2573 setProperty(FrameBottomMargin, amargin);
2574 setProperty(FrameLeftMargin, amargin);
2575 setProperty(FrameRightMargin, amargin);
2580 \fn qreal QTextFrameFormat::margin() const
2582 Returns the width of the frame's external margin in pixels.
2586 \fn QTextFrameFormat::setTopMargin(qreal margin)
2589 Sets the frame's top \a margin in pixels.
2593 \fn qreal QTextFrameFormat::topMargin() const
2596 Returns the width of the frame's top margin in pixels.
2598 qreal QTextFrameFormat::topMargin() const
2600 if (!hasProperty(FrameTopMargin))
2602 return doubleProperty(FrameTopMargin);
2606 \fn QTextFrameFormat::setBottomMargin(qreal margin)
2609 Sets the frame's bottom \a margin in pixels.
2613 \fn qreal QTextFrameFormat::bottomMargin() const
2616 Returns the width of the frame's bottom margin in pixels.
2618 qreal QTextFrameFormat::bottomMargin() const
2620 if (!hasProperty(FrameBottomMargin))
2622 return doubleProperty(FrameBottomMargin);
2626 \fn QTextFrameFormat::setLeftMargin(qreal margin)
2629 Sets the frame's left \a margin in pixels.
2633 \fn qreal QTextFrameFormat::leftMargin() const
2636 Returns the width of the frame's left margin in pixels.
2638 qreal QTextFrameFormat::leftMargin() const
2640 if (!hasProperty(FrameLeftMargin))
2642 return doubleProperty(FrameLeftMargin);
2646 \fn QTextFrameFormat::setRightMargin(qreal margin)
2649 Sets the frame's right \a margin in pixels.
2653 \fn qreal QTextFrameFormat::rightMargin() const
2656 Returns the width of the frame's right margin in pixels.
2658 qreal QTextFrameFormat::rightMargin() const
2660 if (!hasProperty(FrameRightMargin))
2662 return doubleProperty(FrameRightMargin);
2666 \fn QTextFrameFormat::setPadding(qreal width)
2668 Sets the \a width of the frame's internal padding in pixels.
2672 \fn qreal QTextFrameFormat::padding() const
2674 Returns the width of the frame's internal padding in pixels.
2678 \fn QTextFrameFormat::setWidth(const QTextLength &width)
2680 Sets the frame's border rectangle's \a width.
2686 \fn QTextFrameFormat::setWidth(qreal width)
2689 Convenience method that sets the width of the frame's border
2690 rectangle's width to the specified fixed \a width.
2694 \fn QTextFormat::PageBreakFlags QTextFrameFormat::pageBreakPolicy() const
2697 Returns the currently set page break policy for the frame/table. The default is
2698 QTextFormat::PageBreak_Auto.
2700 \sa setPageBreakPolicy()
2704 \fn void QTextFrameFormat::setPageBreakPolicy(PageBreakFlags policy)
2707 Sets the page break policy for the frame/table to \a policy.
2709 \sa pageBreakPolicy()
2713 \fn QTextLength QTextFrameFormat::width() const
2715 Returns the width of the frame's border rectangle.
2721 \fn void QTextFrameFormat::setHeight(const QTextLength &height)
2723 Sets the frame's \a height.
2727 \fn void QTextFrameFormat::setHeight(qreal height)
2730 Sets the frame's \a height.
2734 \fn qreal QTextFrameFormat::height() const
2736 Returns the height of the frame's border rectangle.
2740 \class QTextTableFormat
2743 \brief The QTextTableFormat class provides formatting information for
2744 tables in a QTextDocument.
2746 \ingroup richtext-processing
2748 A table is a group of cells ordered into rows and columns. Each table
2749 contains at least one row and one column. Each cell contains a block.
2750 Tables in rich text documents are formatted using the properties
2751 defined in this class.
2753 Tables are horizontally justified within their parent frame according to the
2754 table's alignment. This can be read with the alignment() function and set
2755 with setAlignment().
2757 Cells within the table are separated by cell spacing. The number of pixels
2758 between cells is set with setCellSpacing() and read with cellSpacing().
2759 The contents of each cell is surrounded by cell padding. The number of pixels
2760 between each cell edge and its contents is set with setCellPadding() and read
2763 \image qtexttableformat-cell.png
2765 The table's background color can be read with the background() function,
2766 and can be specified with setBackground(). The background color of each
2767 cell can be set independently, and will control the color of the cell within
2770 The table format also provides a way to constrain the widths of the columns
2771 in the table. Columns can be assigned a fixed width, a variable width, or
2772 a percentage of the available width (see QTextLength). The columns() function
2773 returns the number of columns with constraints, and the
2774 columnWidthConstraints() function returns the constraints defined for the
2775 table. These quantities can also be set by calling setColumnWidthConstraints()
2776 with a vector containing new constraints. If no constraints are
2777 required, clearColumnWidthConstraints() can be used to remove them.
2779 \sa QTextTable, QTextTableCell, QTextLength
2783 \fn QTextTableFormat::QTextTableFormat()
2785 Constructs a new table format object.
2787 QTextTableFormat::QTextTableFormat()
2788 : QTextFrameFormat()
2790 setObjectType(TableObject);
2797 \fn QTextTableFormat::QTextTableFormat(const QTextFormat &other)
2799 Creates a new table format with the same attributes as the \a given
2802 QTextTableFormat::QTextTableFormat(const QTextFormat &fmt)
2803 : QTextFrameFormat(fmt)
2808 \fn bool QTextTableFormat::isValid() const
2810 Returns true if this table format is valid; otherwise
2816 \fn int QTextTableFormat::columns() const
2818 Returns the number of columns specified by the table format.
2824 \fn void QTextTableFormat::setColumns(int columns)
2826 Sets the number of \a columns required by the table format.
2832 \fn void QTextTableFormat::clearColumnWidthConstraints()
2834 Clears the column width constraints for the table.
2836 \sa columnWidthConstraints(), setColumnWidthConstraints()
2840 \fn void QTextTableFormat::setColumnWidthConstraints(const QVector<QTextLength> &constraints)
2842 Sets the column width \a constraints for the table.
2844 \sa columnWidthConstraints(), clearColumnWidthConstraints()
2848 \fn QVector<QTextLength> QTextTableFormat::columnWidthConstraints() const
2850 Returns a list of constraints used by this table format to control the
2851 appearance of columns in a table.
2853 \sa setColumnWidthConstraints()
2857 \fn qreal QTextTableFormat::cellSpacing() const
2859 Returns the table's cell spacing. This describes the distance between
2864 \fn void QTextTableFormat::setCellSpacing(qreal spacing)
2866 Sets the cell \a spacing for the table. This determines the distance
2867 between adjacent cells.
2871 \fn qreal QTextTableFormat::cellPadding() const
2873 Returns the table's cell padding. This describes the distance between
2874 the border of a cell and its contents.
2878 \fn void QTextTableFormat::setCellPadding(qreal padding)
2880 Sets the cell \a padding for the table. This determines the distance
2881 between the border of a cell and its contents.
2885 \fn void QTextTableFormat::setAlignment(Qt::Alignment alignment)
2887 Sets the table's \a alignment.
2893 \fn Qt::Alignment QTextTableFormat::alignment() const
2895 Returns the table's alignment.
2901 \fn void QTextTableFormat::setHeaderRowCount(int count)
2904 Declares the first \a count rows of the table as table header.
2905 The table header rows get repeated when a table is broken
2906 across a page boundary.
2910 \fn int QTextTableFormat::headerRowCount() const
2913 Returns the number of rows in the table that define the header.
2915 \sa setHeaderRowCount()
2919 \fn void QTextFormat::setBackground(const QBrush &brush)
2921 Sets the brush use to paint the document's background to the
2924 \sa background(), clearBackground(), setForeground()
2928 \fn QColor QTextFormat::background() const
2930 Returns the brush used to paint the document's background.
2932 \sa setBackground(), clearBackground(), foreground()
2936 \fn void QTextFormat::clearBackground()
2938 Clears the brush used to paint the document's background. The default
2941 \sa background(), setBackground(), clearForeground()
2946 \class QTextImageFormat
2949 \brief The QTextImageFormat class provides formatting information for
2950 images in a QTextDocument.
2952 \ingroup richtext-processing
2954 Inline images are represented by an object replacement character
2955 (0xFFFC in Unicode) which has an associated QTextImageFormat. The
2956 image format specifies a name with setName() that is used to
2957 locate the image. The size of the rectangle that the image will
2958 occupy is specified using setWidth() and setHeight().
2960 Images can be supplied in any format for which Qt has an image
2961 reader, so SVG drawings can be included alongside PNG, TIFF and
2962 other bitmap formats.
2964 \sa QImage, QImageReader
2968 \fn QTextImageFormat::QTextImageFormat()
2970 Creates a new image format object.
2972 QTextImageFormat::QTextImageFormat() : QTextCharFormat() { setObjectType(ImageObject); }
2976 \fn QTextImageFormat::QTextImageFormat(const QTextFormat &other)
2978 Creates a new image format with the same attributes as the \a given
2981 QTextImageFormat::QTextImageFormat(const QTextFormat &fmt)
2982 : QTextCharFormat(fmt)
2987 \fn bool QTextImageFormat::isValid() const
2989 Returns true if this image format is valid; otherwise returns false.
2994 \fn void QTextImageFormat::setName(const QString &name)
2996 Sets the \a name of the image. The \a name is used to locate the image
2997 in the application's resources.
3004 \fn QString QTextImageFormat::name() const
3006 Returns the name of the image. The name refers to an entry in the
3007 application's resources file.
3013 \fn void QTextImageFormat::setWidth(qreal width)
3015 Sets the \a width of the rectangle occupied by the image.
3017 \sa width(), setHeight()
3022 \fn qreal QTextImageFormat::width() const
3024 Returns the width of the rectangle occupied by the image.
3026 \sa height(), setWidth()
3031 \fn void QTextImageFormat::setHeight(qreal height)
3033 Sets the \a height of the rectangle occupied by the image.
3035 \sa height(), setWidth()
3040 \fn qreal QTextImageFormat::height() const
3042 Returns the height of the rectangle occupied by the image.
3044 \sa width(), setHeight()
3048 \fn void QTextCharFormat::setFontCapitalization(QFont::Capitalization capitalization)
3051 Sets the capitalization of the text that apppears in this font to \a capitalization.
3053 A font's capitalization makes the text appear in the selected capitalization mode.
3055 \sa fontCapitalization()
3059 \fn Capitalization QTextCharFormat::fontCapitalization() const
3062 Returns the current capitalization type of the font.
3066 \fn void QTextCharFormat::setFontAbsoluteLetterSpacing(bool absolute)
3069 Sets the letter spacing type of this format to absolute.
3070 \sa fontAbsoluteLetterSpacing()
3071 \sa setFontLetterSpacing()
3072 \sa fontLetterSpacing()
3076 \fn bool QTextCharFormat::fontAbsoluteLetterSpacing() const
3079 Returns if the current letter spacing is absolute (or percentage).
3080 \sa setFontAbsoluteLetterSpacing()
3081 \sa setFontLetterSpacing()
3082 \sa fontLetterSpacing()
3086 \fn void QTextCharFormat::setFontLetterSpacing(qreal spacing)
3089 Sets the letter spacing of this format to the given \a spacing.
3090 Depending on fontAbsoluteLetterSpacing the value is given in absolutes or in percent.
3091 For percent a value of 100 indicates default spacing; a value of 200 doubles the amount
3092 of space a letter takes.
3094 \sa fontLetterSpacing()
3095 \sa setFontAbsoluteLetterSpacing()
3096 \sa fontAbsoluteLetterSpacing()
3100 \fn qreal QTextCharFormat::fontLetterSpacing() const
3103 Returns the current letter spacing percentage.
3107 \fn void QTextCharFormat::setFontWordSpacing(qreal spacing)
3110 Sets the word spacing of this format to the given \a spacing, in pixels.
3112 \sa fontWordSpacing()
3116 \fn qreal QTextCharFormat::fontWordSpacing() const
3119 Returns the current word spacing value.
3123 \fn void QTextCharFormat::setFontStretch(int factor)
3126 Sets the stretch factor for the font.
3128 The stretch factor changes the width of all characters in the font by factor percent. For example, setting factor to 150 results in all characters in the font being 1.5 times (ie. 150%) wider. The default stretch factor is 100. The minimum stretch factor is 1, and the maximum stretch factor is 4000.
3130 The stretch factor is only applied to outline fonts. The stretch factor is ignored for bitmap fonts.
3132 NOTE: QFont cannot stretch XLFD fonts. When loading XLFD fonts on X11, the stretch factor is matched against a predefined set of values for the SETWIDTH_NAME field of the XLFD.
3137 \fn int QTextCharFormat::fontStretch() const
3140 Returns the current font stretching.
3141 \sa setFontStretch()
3145 \fn qreal QTextTableCellFormat::topPadding() const
3148 Gets the top padding of the table cell.
3150 \sa setTopPadding(), leftPadding(), rightPadding(), bottomPadding()
3154 \fn qreal QTextTableCellFormat::bottomPadding() const
3157 Gets the bottom padding of the table cell.
3159 \sa setBottomPadding(), leftPadding(), rightPadding(), topPadding()
3163 \fn qreal QTextTableCellFormat::leftPadding() const
3166 Gets the left padding of the table cell.
3168 \sa setLeftPadding(), rightPadding(), topPadding(), bottomPadding()
3172 \fn qreal QTextTableCellFormat::rightPadding() const
3175 Gets the right padding of the table cell.
3177 \sa setRightPadding(), leftPadding(), topPadding(), bottomPadding()
3181 \fn void QTextTableCellFormat::setTopPadding(qreal padding)
3184 Sets the top \a padding of the table cell.
3186 \sa topPadding(), setLeftPadding(), setRightPadding(), setBottomPadding()
3190 \fn void QTextTableCellFormat::setBottomPadding(qreal padding)
3193 Sets the bottom \a padding of the table cell.
3195 \sa bottomPadding(), setLeftPadding(), setRightPadding(), setTopPadding()
3199 \fn void QTextTableCellFormat::setLeftPadding(qreal padding)
3202 Sets the left \a padding of the table cell.
3204 \sa leftPadding(), setRightPadding(), setTopPadding(), setBottomPadding()
3208 \fn void QTextTableCellFormat::setRightPadding(qreal padding)
3211 Sets the right \a padding of the table cell.
3213 \sa rightPadding(), setLeftPadding(), setTopPadding(), setBottomPadding()
3217 \fn void QTextTableCellFormat::setPadding(qreal padding)
3220 Sets the left, right, top, and bottom \a padding of the table cell.
3222 \sa setLeftPadding(), setRightPadding(), setTopPadding(), setBottomPadding()
3226 \fn bool QTextTableCellFormat::isValid() const
3229 Returns true if this table cell format is valid; otherwise returns false.
3233 \fn QTextTableCellFormat::QTextTableCellFormat()
3236 Constructs a new table cell format object.
3238 QTextTableCellFormat::QTextTableCellFormat()
3241 setObjectType(TableCellObject);
3246 \fn QTextTableCellFormat::QTextTableCellFormat(const QTextFormat &other)
3248 Creates a new table cell format with the same attributes as the \a given
3251 QTextTableCellFormat::QTextTableCellFormat(const QTextFormat &fmt)
3252 : QTextCharFormat(fmt)
3257 \class QTextTableCellFormat
3261 \brief The QTextTableCellFormat class provides formatting information for
3262 table cells in a QTextDocument.
3264 \ingroup richtext-processing
3266 The table cell format of a table cell in a document specifies the visual
3267 properties of the table cell.
3269 The padding properties of a table cell are controlled by setLeftPadding(),
3270 setRightPadding(), setTopPadding(), and setBottomPadding(). All the paddings
3271 can be set at once using setPadding().
3273 \sa QTextFormat, QTextBlockFormat, QTextTableFormat, QTextCharFormat
3276 // ------------------------------------------------------
3279 QTextFormatCollection::QTextFormatCollection(const QTextFormatCollection &rhs)
3281 formats = rhs.formats;
3282 objFormats = rhs.objFormats;
3285 QTextFormatCollection &QTextFormatCollection::operator=(const QTextFormatCollection &rhs)
3287 formats = rhs.formats;
3288 objFormats = rhs.objFormats;
3292 QTextFormatCollection::~QTextFormatCollection()
3296 int QTextFormatCollection::indexForFormat(const QTextFormat &format)
3298 uint hash = getHash(format.d, format.format_type);
3299 QMultiHash<uint, int>::const_iterator i = hashes.constFind(hash);
3300 while (i != hashes.constEnd() && i.key() == hash) {
3301 if (formats.value(i.value()) == format) {
3307 int idx = formats.size();
3308 formats.append(format);
3311 QTextFormat &f = formats.last();
3313 f.d = new QTextFormatPrivate;
3314 f.d->resolveFont(defaultFnt);
3316 if (!hashes.contains(hash, idx))
3317 hashes.insert(hash, idx);
3326 bool QTextFormatCollection::hasFormatCached(const QTextFormat &format) const
3328 uint hash = getHash(format.d, format.format_type);
3329 QMultiHash<uint, int>::const_iterator i = hashes.find(hash);
3330 while (i != hashes.end() && i.key() == hash) {
3331 if (formats.value(i.value()) == format) {
3339 QTextFormat QTextFormatCollection::objectFormat(int objectIndex) const
3341 if (objectIndex == -1)
3342 return QTextFormat();
3343 return format(objFormats.at(objectIndex));
3346 void QTextFormatCollection::setObjectFormat(int objectIndex, const QTextFormat &f)
3348 const int formatIndex = indexForFormat(f);
3349 objFormats[objectIndex] = formatIndex;
3352 int QTextFormatCollection::objectFormatIndex(int objectIndex) const
3354 if (objectIndex == -1)
3356 return objFormats.at(objectIndex);
3359 void QTextFormatCollection::setObjectFormatIndex(int objectIndex, int formatIndex)
3361 objFormats[objectIndex] = formatIndex;
3364 int QTextFormatCollection::createObjectIndex(const QTextFormat &f)
3366 const int objectIndex = objFormats.size();
3367 objFormats.append(indexForFormat(f));
3371 QTextFormat QTextFormatCollection::format(int idx) const
3373 if (idx < 0 || idx >= formats.count())
3374 return QTextFormat();
3376 return formats.at(idx);
3379 void QTextFormatCollection::setDefaultFont(const QFont &f)
3382 for (int i = 0; i < formats.count(); ++i)
3384 formats[i].d->resolveFont(defaultFnt);
3387 #ifndef QT_NO_DEBUG_STREAM
3388 QDebug operator<<(QDebug dbg, const QTextLength &l)
3390 dbg.nospace() << "QTextLength(QTextLength::Type(" << l.type() << "))";
3394 QDebug operator<<(QDebug dbg, const QTextFormat &f)
3396 dbg.nospace() << "QTextFormat(QTextFormat::FormatType(" << f.type() << "))";