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.
61 \ingroup richtext-processing
63 When we specify a value for the length of an element in a text document,
64 we often need to provide some other information so that the length is
65 used in the way we expect. For example, when we specify a table width,
66 the value can represent a fixed number of pixels, or it can be a percentage
67 value. This information changes both the meaning of the value and the way
70 Generally, this class is used to specify table widths. These can be
71 specified either as a fixed amount of pixels, as a percentage of the
72 containing frame's width, or by a variable width that allows it to take
73 up just the space it requires.
79 \fn explicit QTextLength::QTextLength()
81 Constructs a new length object which represents a variable size.
85 \fn QTextLength::QTextLength(Type type, qreal value)
87 Constructs a new length object of the given \a type and \a value.
91 \fn Type QTextLength::type() const
93 Returns the type of this length object.
99 \fn qreal QTextLength::value(qreal maximumLength) const
101 Returns the effective length, constrained by the type of the length object
102 and the specified \a maximumLength.
108 \fn qreal QTextLength::rawValue() const
110 Returns the constraint value that is specific for the type of the length.
111 If the length is QTextLength::PercentageLength then the raw value is in
112 percent, in the range of 0 to 100. If the length is QTextLength::FixedLength
113 then that fixed amount is returned. For variable lengths, zero is returned.
117 \fn bool QTextLength::operator==(const QTextLength &other) const
119 Returns true if this text length is the same as the \a other text
124 \fn bool QTextLength::operator!=(const QTextLength &other) const
126 Returns true if this text length is different from the \a other text
131 \enum QTextLength::Type
133 This enum describes the different types a length object can
136 \value VariableLength The width of the object is variable
137 \value FixedLength The width of the object is fixed
138 \value PercentageLength The width of the object is in
139 percentage of the maximum width
145 Returns the text length as a QVariant
147 QTextLength::operator QVariant() const
149 return QVariant(QVariant::TextLength, this);
152 #ifndef QT_NO_DATASTREAM
153 QDataStream &operator<<(QDataStream &stream, const QTextLength &length)
155 return stream << qint32(length.lengthType) << double(length.fixedValueOrPercentage);
158 QDataStream &operator>>(QDataStream &stream, QTextLength &length)
161 double fixedValueOrPercentage;
162 stream >> type >> fixedValueOrPercentage;
163 length.fixedValueOrPercentage = fixedValueOrPercentage;
164 length.lengthType = QTextLength::Type(type);
167 #endif // QT_NO_DATASTREAM
169 class QTextFormatPrivate : public QSharedData
172 QTextFormatPrivate() : hashDirty(true), fontDirty(true), hashValue(0) {}
176 inline Property(qint32 k, const QVariant &v) : key(k), value(v) {}
182 inline bool operator==(const Property &other) const
183 { return key == other.key && value == other.value; }
184 inline bool operator!=(const Property &other) const
185 { return key != other.key || value != other.value; }
188 inline uint hash() const
195 inline bool operator==(const QTextFormatPrivate &rhs) const {
196 if (hash() != rhs.hash())
199 return props == rhs.props;
202 inline void insertProperty(qint32 key, const QVariant &value)
205 if (key >= QTextFormat::FirstFontProperty && key <= QTextFormat::LastFontProperty)
207 for (int i = 0; i < props.count(); ++i)
208 if (props.at(i).key == key) {
209 props[i].value = value;
212 props.append(Property(key, value));
215 inline void clearProperty(qint32 key)
217 for (int i = 0; i < props.count(); ++i)
218 if (props.at(i).key == key) {
220 if (key >= QTextFormat::FirstFontProperty && key <= QTextFormat::LastFontProperty)
227 inline int propertyIndex(qint32 key) const
229 for (int i = 0; i < props.count(); ++i)
230 if (props.at(i).key == key)
235 inline QVariant property(qint32 key) const
237 const int idx = propertyIndex(key);
240 return props.at(idx).value;
243 inline bool hasProperty(qint32 key) const
244 { return propertyIndex(key) != -1; }
246 void resolveFont(const QFont &defaultFont);
248 inline const QFont &font() const {
254 QVector<Property> props;
257 uint recalcHash() const;
258 void recalcFont() const;
260 mutable bool hashDirty;
261 mutable bool fontDirty;
262 mutable uint hashValue;
265 friend QDataStream &operator<<(QDataStream &, const QTextFormat &);
266 friend QDataStream &operator>>(QDataStream &, QTextFormat &);
269 // this is only safe because sizeof(int) == sizeof(float)
270 static inline uint hash(float d)
273 // this is a GCC extension and isn't guaranteed to work in other compilers
274 // the reinterpret_cast below generates a strict-aliasing warning with GCC
275 union { float f; uint u; } cvt;
279 return reinterpret_cast<uint&>(d);
283 static inline uint hash(const QColor &color)
285 return (color.isValid()) ? color.rgba() : 0x234109;
288 static inline uint hash(const QPen &pen)
290 return hash(pen.color()) + hash(pen.widthF());
293 static inline uint hash(const QBrush &brush)
295 return hash(brush.color()) + (brush.style() << 3);
298 static inline uint variantHash(const QVariant &variant)
300 // simple and fast hash functions to differentiate between type and value
301 switch (variant.userType()) { // sorted by occurrence frequency
302 case QVariant::String: return qHash(variant.toString());
303 case QVariant::Double: return hash(variant.toDouble());
304 case QVariant::Int: return 0x811890 + variant.toInt();
305 case QVariant::Brush:
306 return 0x01010101 + hash(qvariant_cast<QBrush>(variant));
307 case QVariant::Bool: return 0x371818 + variant.toBool();
308 case QVariant::Pen: return 0x02020202 + hash(qvariant_cast<QPen>(variant));
310 return 0x8377 + qvariant_cast<QVariantList>(variant).count();
311 case QVariant::Color: return hash(qvariant_cast<QColor>(variant));
312 case QVariant::TextLength:
313 return 0x377 + hash(qvariant_cast<QTextLength>(variant).rawValue());
314 case QMetaType::Float: return hash(variant.toFloat());
315 case QVariant::Invalid: return 0;
318 return qHash(variant.typeName());
321 static inline int getHash(const QTextFormatPrivate *d, int format)
323 return (d ? d->hash() : 0) + format;
326 uint QTextFormatPrivate::recalcHash() const
329 for (QVector<Property>::ConstIterator it = props.constBegin(); it != props.constEnd(); ++it)
330 hashValue += (it->key << 16) + variantHash(it->value);
337 void QTextFormatPrivate::resolveFont(const QFont &defaultFont)
340 const uint oldMask = fnt.resolve();
341 fnt = fnt.resolve(defaultFont);
343 if (hasProperty(QTextFormat::FontSizeAdjustment)) {
344 const qreal scaleFactors[7] = {qreal(0.7), qreal(0.8), qreal(1.0), qreal(1.2), qreal(1.5), qreal(2), qreal(2.4)};
346 const int htmlFontSize = qBound(0, property(QTextFormat::FontSizeAdjustment).toInt() + 3 - 1, 6);
349 if (defaultFont.pointSize() <= 0) {
350 qreal pixelSize = scaleFactors[htmlFontSize] * defaultFont.pixelSize();
351 fnt.setPixelSize(qRound(pixelSize));
353 qreal pointSize = scaleFactors[htmlFontSize] * defaultFont.pointSizeF();
354 fnt.setPointSizeF(pointSize);
358 fnt.resolve(oldMask);
361 void QTextFormatPrivate::recalcFont() const
363 // update cached font as well
366 for (int i = 0; i < props.count(); ++i) {
367 switch (props.at(i).key) {
368 case QTextFormat::FontFamily:
369 f.setFamily(props.at(i).value.toString());
371 case QTextFormat::FontPointSize:
372 f.setPointSizeF(props.at(i).value.toReal());
374 case QTextFormat::FontPixelSize:
375 f.setPixelSize(props.at(i).value.toInt());
377 case QTextFormat::FontWeight: {
378 int weight = props.at(i).value.toInt();
379 if (weight == 0) weight = QFont::Normal;
382 case QTextFormat::FontItalic:
383 f.setItalic(props.at(i).value.toBool());
385 case QTextFormat::FontUnderline:
386 if (! hasProperty(QTextFormat::TextUnderlineStyle)) // don't use the old one if the new one is there.
387 f.setUnderline(props.at(i).value.toBool());
389 case QTextFormat::TextUnderlineStyle:
390 f.setUnderline(static_cast<QTextCharFormat::UnderlineStyle>(props.at(i).value.toInt()) == QTextCharFormat::SingleUnderline);
392 case QTextFormat::FontOverline:
393 f.setOverline(props.at(i).value.toBool());
395 case QTextFormat::FontStrikeOut:
396 f.setStrikeOut(props.at(i).value.toBool());
398 case QTextFormat::FontAbsoluteLetterSpacing:
399 f.setLetterSpacing(QFont::AbsoluteSpacing, props.at(i).value.toReal());
401 case QTextFormat::FontLetterSpacing:
402 f.setLetterSpacing(QFont::PercentageSpacing, props.at(i).value.toReal());
404 case QTextFormat::FontWordSpacing:
405 f.setWordSpacing(props.at(i).value.toReal());
407 case QTextFormat::FontCapitalization:
408 f.setCapitalization(static_cast<QFont::Capitalization> (props.at(i).value.toInt()));
410 case QTextFormat::FontFixedPitch: {
411 const bool value = props.at(i).value.toBool();
412 if (f.fixedPitch() != value)
413 f.setFixedPitch(value);
415 case QTextFormat::FontStretch:
416 f.setStretch(props.at(i).value.toInt());
418 case QTextFormat::FontStyleHint:
419 f.setStyleHint(static_cast<QFont::StyleHint>(props.at(i).value.toInt()), f.styleStrategy());
421 case QTextFormat::FontHintingPreference:
422 f.setHintingPreference(static_cast<QFont::HintingPreference>(props.at(i).value.toInt()));
424 case QTextFormat::FontStyleStrategy:
425 f.setStyleStrategy(static_cast<QFont::StyleStrategy>(props.at(i).value.toInt()));
427 case QTextFormat::FontKerning:
428 f.setKerning(props.at(i).value.toBool());
438 #ifndef QT_NO_DATASTREAM
439 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QTextFormat &fmt)
441 stream << fmt.format_type << fmt.properties();
445 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QTextFormat &fmt)
447 QMap<qint32, QVariant> properties;
448 stream >> fmt.format_type >> properties;
450 // QTextFormat's default constructor doesn't allocate the private structure, so
451 // we have to do this, in case fmt is a default constructed value.
453 fmt.d = new QTextFormatPrivate();
455 for (QMap<qint32, QVariant>::ConstIterator it = properties.constBegin();
456 it != properties.constEnd(); ++it)
457 fmt.d->insertProperty(it.key(), it.value());
461 #endif // QT_NO_DATASTREAM
467 \brief The QTextFormat class provides formatting information for a
471 \ingroup richtext-processing
474 A QTextFormat is a generic class used for describing the format of
475 parts of a QTextDocument. The derived classes QTextCharFormat,
476 QTextBlockFormat, QTextListFormat, and QTextTableFormat are usually
477 more useful, and describe the formatting that is applied to
478 specific parts of the document.
480 A format has a \c FormatType which specifies the kinds of text item it
481 can format; e.g. a block of text, a list, a table, etc. A format
482 also has various properties (some specific to particular format
483 types), as described by the Property enum. Every property has a
484 corresponding Property.
486 The format type is given by type(), and the format can be tested
487 with isCharFormat(), isBlockFormat(), isListFormat(),
488 isTableFormat(), isFrameFormat(), and isImageFormat(). If the
489 type is determined, it can be retrieved with toCharFormat(),
490 toBlockFormat(), toListFormat(), toTableFormat(), toFrameFormat(),
493 A format's properties can be set with the setProperty() functions,
494 and retrieved with boolProperty(), intProperty(), doubleProperty(),
495 and stringProperty() as appropriate. All the property IDs used in
496 the format can be retrieved with allPropertyIds(). One format can
497 be merged into another using merge().
499 A format's object index can be set with setObjectIndex(), and
500 retrieved with objectIndex(). These methods can be used to
501 associate the format with a QTextObject. It is used to represent
502 lists, frames, and tables inside the document.
504 \sa {Rich Text Processing}
508 \enum QTextFormat::FormatType
510 This enum describes the text item a QTextFormat object is formatting.
512 \value InvalidFormat An invalid format as created by the default
514 \value BlockFormat The object formats a text block
515 \value CharFormat The object formats a single character
516 \value ListFormat The object formats a list
517 \value TableFormat The object formats a table
518 \value FrameFormat The object formats a frame
522 \sa QTextCharFormat, QTextBlockFormat, QTextListFormat,
523 QTextTableFormat, type()
527 \enum QTextFormat::Property
529 This enum describes the different properties a format can have.
531 \value ObjectIndex The index of the formatted object. See objectIndex().
533 Paragraph and character properties
535 \value CssFloat How a frame is located relative to the surrounding text
536 \value LayoutDirection The layout direction of the text in the document
537 (Qt::LayoutDirection).
540 \value ForegroundBrush
541 \value BackgroundBrush
542 \value BackgroundImageUrl
546 \value BlockAlignment
547 \value BlockTopMargin
548 \value BlockBottomMargin
549 \value BlockLeftMargin
550 \value BlockRightMargin
552 \value TabPositions Specifies the tab positions. The tab positions are structs of QTextOption::Tab which are stored in
553 a QList (internally, in a QList<QVariant>).
556 \value LineHeightType
557 \value BlockNonBreakableLines
558 \value BlockTrailingHorizontalRulerWidth The width of a horizontal ruler element.
565 \value FontSizeAdjustment Specifies the change in size given to the fontsize already set using
566 FontPointSize or FontPixelSize.
567 \value FontFixedPitch
568 \omitvalue FontSizeIncrement
571 \value FontUnderline \e{This property has been deprecated.} Use QTextFormat::TextUnderlineStyle instead.
574 \value FontCapitalization Specifies the capitalization type that is to be applied to the text.
575 \value FontAbsoluteLetterSpacing If true FontLetterSpacing is absolute
576 \value FontLetterSpacing Changes the default spacing between individual letters in the font. The value is
577 specified in percentage, with 100 as the default value.
578 \value FontWordSpacing Changes the default spacing between individual words. A positive value increases the word spacing
579 by the corresponding pixels; a negative value decreases the spacing.
580 \value FontStretch Corresponds to the QFont::Stretch property
581 \value FontStyleHint Corresponds to the QFont::StyleHint property
582 \value FontStyleStrategy Corresponds to the QFont::StyleStrategy property
583 \value FontKerning Specifies whether the font has kerning turned on.
584 \value FontHintingPreference Controls the use of hinting according to values
585 of the QFont::HintingPreference enum.
587 \omitvalue FirstFontProperty
588 \omitvalue LastFontProperty
590 \value TextUnderlineColor
591 \value TextVerticalAlignment
593 \value TextUnderlineStyle
594 \value TextToolTip Specifies the (optional) tool tip to be displayed for a fragment of text.
603 \value ListStyle Specifies the style used for the items in a list,
604 described by values of the QTextListFormat::Style enum.
605 \value ListIndent Specifies the amount of indentation used for a list.
606 \value ListNumberPrefix Defines the text which is prepended to item numbers in
608 \value ListNumberSuffix Defines the text which is appended to item numbers in
611 Table and frame properties
614 \value FrameBorderBrush
615 \value FrameBorderStyle See the \l{QTextFrameFormat::BorderStyle}{BorderStyle} enum.
616 \value FrameBottomMargin
618 \value FrameLeftMargin
621 \value FrameRightMargin
622 \value FrameTopMargin
624 \value TableCellSpacing
625 \value TableCellPadding
627 \value TableColumnWidthConstraints
628 \value TableHeaderRowCount
630 Table cell properties
632 \value TableCellRowSpan
633 \value TableCellColumnSpan
634 \value TableCellLeftPadding
635 \value TableCellRightPadding
636 \value TableCellTopPadding
637 \value TableCellBottomPadding
647 \value FullWidthSelection When set on the characterFormat of a selection,
648 the whole width of the text will be shown selected.
650 Page break properties
652 \value PageBreakPolicy Specifies how pages are broken. See the PageBreakFlag enum.
656 \sa property(), setProperty()
660 \enum QTextFormat::ObjectTypes
662 This enum describes what kind of QTextObject this format is associated with.
667 \value TableCellObject
668 \value UserObject The first object that can be used for application-specific purposes.
670 \sa QTextObject, QTextTable, QTextObject::format()
674 \enum QTextFormat::PageBreakFlag
677 This enum describes how page breaking is performed when printing. It maps to the
678 corresponding css properties.
680 \value PageBreak_Auto The page break is determined automatically depending on the
681 available space on the current page
682 \value PageBreak_AlwaysBefore The page is always broken before the paragraph/table
683 \value PageBreak_AlwaysAfter A new page is always started after the paragraph/table
685 \sa QTextBlockFormat::pageBreakPolicy(), QTextFrameFormat::pageBreakPolicy(),
690 \fn bool QTextFormat::isValid() const
692 Returns true if the format is valid (i.e. is not
693 InvalidFormat); otherwise returns false.
697 \fn bool QTextFormat::isCharFormat() const
699 Returns true if this text format is a \c CharFormat; otherwise
705 \fn bool QTextFormat::isBlockFormat() const
707 Returns true if this text format is a \c BlockFormat; otherwise
713 \fn bool QTextFormat::isListFormat() const
715 Returns true if this text format is a \c ListFormat; otherwise
721 \fn bool QTextFormat::isTableFormat() const
723 Returns true if this text format is a \c TableFormat; otherwise
729 \fn bool QTextFormat::isFrameFormat() const
731 Returns true if this text format is a \c FrameFormat; otherwise
737 \fn bool QTextFormat::isImageFormat() const
739 Returns true if this text format is an image format; otherwise
745 \fn bool QTextFormat::isTableCellFormat() const
748 Returns true if this text format is a \c TableCellFormat; otherwise
754 Creates a new text format with an \c InvalidFormat.
758 QTextFormat::QTextFormat()
759 : format_type(InvalidFormat)
764 Creates a new text format of the given \a type.
768 QTextFormat::QTextFormat(int type)
775 \fn QTextFormat::QTextFormat(const QTextFormat &other)
777 Creates a new text format with the same attributes as the \a other
780 QTextFormat::QTextFormat(const QTextFormat &rhs)
781 : d(rhs.d), format_type(rhs.format_type)
786 \fn QTextFormat &QTextFormat::operator=(const QTextFormat &other)
788 Assigns the \a other text format to this text format, and returns a
789 reference to this text format.
791 QTextFormat &QTextFormat::operator=(const QTextFormat &rhs)
794 format_type = rhs.format_type;
799 Destroys this text format.
801 QTextFormat::~QTextFormat()
807 Returns the text format as a QVariant
809 QTextFormat::operator QVariant() const
811 return QVariant(QVariant::TextFormat, this);
815 Merges the \a other format with this format; where there are
816 conflicts the \a other format takes precedence.
818 void QTextFormat::merge(const QTextFormat &other)
820 if (format_type != other.format_type)
831 QTextFormatPrivate *d = this->d;
833 const QVector<QTextFormatPrivate::Property> &otherProps = other.d->props;
834 d->props.reserve(d->props.size() + otherProps.size());
835 for (int i = 0; i < otherProps.count(); ++i) {
836 const QTextFormatPrivate::Property &p = otherProps.at(i);
837 d->insertProperty(p.key, p.value);
842 Returns the type of this format.
846 int QTextFormat::type() const
852 Returns this format as a block format.
854 QTextBlockFormat QTextFormat::toBlockFormat() const
856 return QTextBlockFormat(*this);
860 Returns this format as a character format.
862 QTextCharFormat QTextFormat::toCharFormat() const
864 return QTextCharFormat(*this);
868 Returns this format as a list format.
870 QTextListFormat QTextFormat::toListFormat() const
872 return QTextListFormat(*this);
876 Returns this format as a table format.
878 QTextTableFormat QTextFormat::toTableFormat() const
880 return QTextTableFormat(*this);
884 Returns this format as a frame format.
886 QTextFrameFormat QTextFormat::toFrameFormat() const
888 return QTextFrameFormat(*this);
892 Returns this format as an image format.
894 QTextImageFormat QTextFormat::toImageFormat() const
896 return QTextImageFormat(*this);
902 Returns this format as a table cell format.
904 QTextTableCellFormat QTextFormat::toTableCellFormat() const
906 return QTextTableCellFormat(*this);
910 Returns the value of the property specified by \a propertyId. If the
911 property isn't of QTextFormat::Bool type, false is returned instead.
913 \sa setProperty(), intProperty(), doubleProperty(), stringProperty(), colorProperty(),
914 lengthProperty(), lengthVectorProperty(), Property
916 bool QTextFormat::boolProperty(int propertyId) const
920 const QVariant prop = d->property(propertyId);
921 if (prop.userType() != QVariant::Bool)
923 return prop.toBool();
927 Returns the value of the property specified by \a propertyId. If the
928 property is not of QTextFormat::Integer type, 0 is returned instead.
930 \sa setProperty(), boolProperty(), doubleProperty(), stringProperty(), colorProperty(),
931 lengthProperty(), lengthVectorProperty(), Property
933 int QTextFormat::intProperty(int propertyId) const
935 // required, since the default layout direction has to be LayoutDirectionAuto, which is not integer 0
936 int def = (propertyId == QTextFormat::LayoutDirection) ? int(Qt::LayoutDirectionAuto) : 0;
940 const QVariant prop = d->property(propertyId);
941 if (prop.userType() != QVariant::Int)
947 Returns the value of the property specified by \a propertyId. If the
948 property isn't of QVariant::Double or QMetaType::Float type, 0 is
951 \sa setProperty(), boolProperty(), intProperty(), stringProperty(), colorProperty(),
952 lengthProperty(), lengthVectorProperty(), Property
954 qreal QTextFormat::doubleProperty(int propertyId) const
958 const QVariant prop = d->property(propertyId);
959 if (prop.userType() != QVariant::Double && prop.userType() != QMetaType::Float)
961 return qvariant_cast<qreal>(prop);
965 Returns the value of the property given by \a propertyId; if the
966 property isn't of QVariant::String type, an empty string is
969 \sa setProperty(), boolProperty(), intProperty(), doubleProperty(), colorProperty(),
970 lengthProperty(), lengthVectorProperty(), Property
972 QString QTextFormat::stringProperty(int propertyId) const
976 const QVariant prop = d->property(propertyId);
977 if (prop.userType() != QVariant::String)
979 return prop.toString();
983 Returns the value of the property given by \a propertyId; if the
984 property isn't of QVariant::Color type, an invalid color is
987 \sa setProperty(), boolProperty(), intProperty(), doubleProperty(),
988 stringProperty(), lengthProperty(), lengthVectorProperty(), Property
990 QColor QTextFormat::colorProperty(int propertyId) const
994 const QVariant prop = d->property(propertyId);
995 if (prop.userType() != QVariant::Color)
997 return qvariant_cast<QColor>(prop);
1001 Returns the value of the property given by \a propertyId; if the
1002 property isn't of QVariant::Pen type, Qt::NoPen is
1005 \sa setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(),
1006 lengthProperty(), lengthVectorProperty(), Property
1008 QPen QTextFormat::penProperty(int propertyId) const
1011 return QPen(Qt::NoPen);
1012 const QVariant prop = d->property(propertyId);
1013 if (prop.userType() != QVariant::Pen)
1014 return QPen(Qt::NoPen);
1015 return qvariant_cast<QPen>(prop);
1019 Returns the value of the property given by \a propertyId; if the
1020 property isn't of QVariant::Brush type, Qt::NoBrush is
1023 \sa setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(),
1024 lengthProperty(), lengthVectorProperty(), Property
1026 QBrush QTextFormat::brushProperty(int propertyId) const
1029 return QBrush(Qt::NoBrush);
1030 const QVariant prop = d->property(propertyId);
1031 if (prop.userType() != QVariant::Brush)
1032 return QBrush(Qt::NoBrush);
1033 return qvariant_cast<QBrush>(prop);
1037 Returns the value of the property given by \a propertyId.
1039 \sa setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(),
1040 colorProperty(), lengthVectorProperty(), Property
1042 QTextLength QTextFormat::lengthProperty(int propertyId) const
1045 return QTextLength();
1046 return qvariant_cast<QTextLength>(d->property(propertyId));
1050 Returns the value of the property given by \a propertyId. If the
1051 property isn't of QTextFormat::LengthVector type, an empty length
1052 vector is returned instead.
1054 \sa setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(),
1055 colorProperty(), lengthProperty(), Property
1057 QVector<QTextLength> QTextFormat::lengthVectorProperty(int propertyId) const
1059 QVector<QTextLength> vector;
1062 const QVariant prop = d->property(propertyId);
1063 if (prop.userType() != QVariant::List)
1066 QList<QVariant> propertyList = prop.toList();
1067 for (int i=0; i<propertyList.size(); ++i) {
1068 QVariant var = propertyList.at(i);
1069 if (var.userType() == QVariant::TextLength)
1070 vector.append(qvariant_cast<QTextLength>(var));
1077 Returns the property specified by the given \a propertyId.
1081 QVariant QTextFormat::property(int propertyId) const
1083 return d ? d->property(propertyId) : QVariant();
1087 Sets the property specified by the \a propertyId to the given \a value.
1091 void QTextFormat::setProperty(int propertyId, const QVariant &value)
1094 d = new QTextFormatPrivate;
1095 if (!value.isValid())
1096 clearProperty(propertyId);
1098 d->insertProperty(propertyId, value);
1102 Sets the value of the property given by \a propertyId to \a value.
1104 \sa lengthVectorProperty(), Property
1106 void QTextFormat::setProperty(int propertyId, const QVector<QTextLength> &value)
1109 d = new QTextFormatPrivate;
1111 for (int i=0; i<value.size(); ++i)
1112 list << value.at(i);
1113 d->insertProperty(propertyId, list);
1117 Clears the value of the property given by \a propertyId
1121 void QTextFormat::clearProperty(int propertyId)
1125 d->clearProperty(propertyId);
1130 \fn void QTextFormat::setObjectType(int type)
1132 Sets the text format's object type to \a type.
1134 \sa ObjectTypes, objectType()
1139 \fn int QTextFormat::objectType() const
1141 Returns the text format's object type.
1143 \sa ObjectTypes, setObjectType()
1148 Returns the index of the format object, or -1 if the format object is invalid.
1150 \sa setObjectIndex()
1152 int QTextFormat::objectIndex() const
1156 const QVariant prop = d->property(ObjectIndex);
1157 if (prop.userType() != QVariant::Int) // ####
1159 return prop.toInt();
1163 \fn void QTextFormat::setObjectIndex(int index)
1165 Sets the format object's object \a index.
1169 void QTextFormat::setObjectIndex(int o)
1173 d->clearProperty(ObjectIndex);
1176 d = new QTextFormatPrivate;
1178 d->insertProperty(ObjectIndex, o);
1183 Returns true if the text format has a property with the given \a
1184 propertyId; otherwise returns false.
1186 \sa properties(), Property
1188 bool QTextFormat::hasProperty(int propertyId) const
1190 return d ? d->hasProperty(propertyId) : false;
1194 Returns the property type for the given \a propertyId.
1196 \sa hasProperty(), allPropertyIds(), Property
1200 Returns a map with all properties of this text format.
1202 QMap<int, QVariant> QTextFormat::properties() const
1204 QMap<int, QVariant> map;
1206 for (int i = 0; i < d->props.count(); ++i)
1207 map.insert(d->props.at(i).key, d->props.at(i).value);
1214 Returns the number of properties stored in the format.
1216 int QTextFormat::propertyCount() const
1218 return d ? d->props.count() : 0;
1222 \fn bool QTextFormat::operator!=(const QTextFormat &other) const
1224 Returns true if this text format is different from the \a other text
1230 \fn bool QTextFormat::operator==(const QTextFormat &other) const
1232 Returns true if this text format is the same as the \a other text
1235 bool QTextFormat::operator==(const QTextFormat &rhs) const
1237 if (format_type != rhs.format_type)
1243 if (d && d->props.isEmpty() && !rhs.d)
1246 if (!d && rhs.d && rhs.d->props.isEmpty())
1252 return *d == *rhs.d;
1256 \class QTextCharFormat
1259 \brief The QTextCharFormat class provides formatting information for
1260 characters in a QTextDocument.
1263 \ingroup richtext-processing
1265 The character format of text in a document specifies the visual properties
1266 of the text, as well as information about its role in a hypertext document.
1268 The font used can be set by supplying a font to the setFont() function, and
1269 each aspect of its appearance can be adjusted to give the desired effect.
1270 setFontFamily() and setFontPointSize() define the font's family (e.g. Times)
1271 and printed size; setFontWeight() and setFontItalic() provide control over
1272 the style of the font. setFontUnderline(), setFontOverline(),
1273 setFontStrikeOut(), and setFontFixedPitch() provide additional effects for
1276 The color is set with setForeground(). If the text is intended to be used
1277 as an anchor (for hyperlinks), this can be enabled with setAnchor(). The
1278 setAnchorHref() and setAnchorNames() functions are used to specify the
1279 information about the hyperlink's destination and the anchor's name.
1281 \sa QTextFormat, QTextBlockFormat, QTextTableFormat, QTextListFormat
1285 \enum QTextCharFormat::VerticalAlignment
1287 This enum describes the ways that adjacent characters can be vertically
1290 \value AlignNormal Adjacent characters are positioned in the standard
1291 way for text in the writing system in use.
1292 \value AlignSuperScript Characters are placed above the base line for
1294 \value AlignSubScript Characters are placed below the base line for
1296 \value AlignMiddle The center of the object is vertically aligned with the
1297 base line. Currently, this is only implemented for
1299 \value AlignBottom The bottom edge of the object is vertically aligned with
1301 \value AlignTop The top edge of the object is vertically aligned with
1303 \value AlignBaseline The base lines of the characters are aligned.
1307 \enum QTextCharFormat::UnderlineStyle
1309 This enum describes the different ways drawing underlined text.
1311 \value NoUnderline Text is draw without any underlining decoration.
1312 \value SingleUnderline A line is drawn using Qt::SolidLine.
1313 \value DashUnderline Dashes are drawn using Qt::DashLine.
1314 \value DotLine Dots are drawn using Qt::DotLine;
1315 \value DashDotLine Dashs and dots are drawn using Qt::DashDotLine.
1316 \value DashDotDotLine Underlines draw drawn using Qt::DashDotDotLine.
1317 \value WaveUnderline The text is underlined using a wave shaped line.
1318 \value SpellCheckUnderline The underline is drawn depending on the QStyle::SH_SpellCeckUnderlineStyle
1319 style hint of the QApplication style. By default this is mapped to
1320 WaveUnderline, on Mac OS X it is mapped to DashDotLine.
1326 \fn QTextCharFormat::QTextCharFormat()
1328 Constructs a new character format object.
1330 QTextCharFormat::QTextCharFormat() : QTextFormat(CharFormat) {}
1334 \fn QTextCharFormat::QTextCharFormat(const QTextFormat &other)
1336 Creates a new character format with the same attributes as the \a given
1339 QTextCharFormat::QTextCharFormat(const QTextFormat &fmt)
1345 \fn bool QTextCharFormat::isValid() const
1347 Returns true if this character format is valid; otherwise returns
1353 \fn void QTextCharFormat::setFontFamily(const QString &family)
1355 Sets the text format's font \a family.
1362 \fn QString QTextCharFormat::fontFamily() const
1364 Returns the text format's font family.
1371 \fn void QTextCharFormat::setFontPointSize(qreal size)
1373 Sets the text format's font \a size.
1380 \fn qreal QTextCharFormat::fontPointSize() const
1382 Returns the font size used to display text in this format.
1389 \fn void QTextCharFormat::setFontWeight(int weight)
1391 Sets the text format's font weight to \a weight.
1393 \sa setFont(), QFont::Weight
1398 \fn int QTextCharFormat::fontWeight() const
1400 Returns the text format's font weight.
1402 \sa font(), QFont::Weight
1407 \fn void QTextCharFormat::setFontItalic(bool italic)
1409 If \a italic is true, sets the text format's font to be italic; otherwise
1410 the font will be non-italic.
1417 \fn bool QTextCharFormat::fontItalic() const
1419 Returns true if the text format's font is italic; otherwise
1427 \fn void QTextCharFormat::setFontUnderline(bool underline)
1429 If \a underline is true, sets the text format's font to be underlined;
1430 otherwise it is displayed non-underlined.
1437 \fn bool QTextCharFormat::fontUnderline() const
1439 Returns true if the text format's font is underlined; otherwise
1444 bool QTextCharFormat::fontUnderline() const
1446 if (hasProperty(TextUnderlineStyle))
1447 return underlineStyle() == SingleUnderline;
1448 return boolProperty(FontUnderline);
1452 \fn UnderlineStyle QTextCharFormat::underlineStyle() const
1455 Returns the style of underlining the text.
1459 \fn void QTextCharFormat::setUnderlineStyle(UnderlineStyle style)
1462 Sets the style of underlining the text to \a style.
1464 void QTextCharFormat::setUnderlineStyle(UnderlineStyle style)
1466 setProperty(TextUnderlineStyle, style);
1467 // for compatibility
1468 setProperty(FontUnderline, style == SingleUnderline);
1472 \fn void QTextCharFormat::setFontOverline(bool overline)
1474 If \a overline is true, sets the text format's font to be overlined;
1475 otherwise the font is displayed non-overlined.
1482 \fn bool QTextCharFormat::fontOverline() const
1484 Returns true if the text format's font is overlined; otherwise
1492 \fn void QTextCharFormat::setFontStrikeOut(bool strikeOut)
1494 If \a strikeOut is true, sets the text format's font with strike-out
1495 enabled (with a horizontal line through it); otherwise it is displayed
1503 \fn bool QTextCharFormat::fontStrikeOut() const
1505 Returns true if the text format's font is struck out (has a horizontal line
1506 drawn through it); otherwise returns false.
1514 \fn void QTextCharFormat::setFontStyleHint(QFont::StyleHint hint, QFont::StyleStrategy strategy)
1516 Sets the font style \a hint and \a strategy.
1518 Qt does not support style hints on X11 since this information is not provided by the window system.
1521 \sa QFont::setStyleHint()
1527 \fn void QTextCharFormat::setFontStyleStrategy(QFont::StyleStrategy strategy)
1529 Sets the font style \a strategy.
1532 \sa QFont::setStyleStrategy()
1538 \fn void QTextCharFormat::setFontKerning(bool enable)
1539 Enables kerning for this font if \a enable is true; otherwise disables it.
1541 When kerning is enabled, glyph metrics do not add up anymore, even for
1542 Latin text. In other words, the assumption that width('a') + width('b')
1543 is equal to width("ab") is not neccesairly true.
1550 \fn QTextCharFormat::StyleHint QTextCharFormat::fontStyleHint() const
1553 Returns the font style hint.
1555 \sa setFontStyleHint(), font()
1561 \fn QTextCharFormat::StyleStrategy QTextCharFormat::fontStyleStrategy() const
1563 Returns the current font style strategy.
1565 \sa setFontStyleStrategy()
1572 \fn bool QTextCharFormat::fontKerning() const
1573 Returns true if the font kerning is enabled.
1575 \sa setFontKerning()
1581 \fn void QTextCharFormat::setFontFixedPitch(bool fixedPitch)
1583 If \a fixedPitch is true, sets the text format's font to be fixed pitch;
1584 otherwise a non-fixed pitch font is used.
1591 \fn bool QTextCharFormat::fontFixedPitch() const
1593 Returns true if the text format's font is fixed pitch; otherwise
1602 \fn void QTextCharFormat::setFontHintingPreference(QFont::HintingPreference hintingPreference)
1604 Sets the hinting preference of the text format's font to be \a hintingPreference.
1606 \sa setFont(), QFont::setHintingPreference()
1612 \fn QFont::HintingPreference QTextCharFormat::fontHintingPreference() const
1614 Returns the hinting preference set for this text format.
1616 \sa font(), QFont::hintingPreference()
1620 \fn QPen QTextCharFormat::textOutline() const
1622 Returns the pen used to draw the outlines of characters in this format.
1627 \fn void QTextCharFormat::setTextOutline(const QPen &pen)
1629 Sets the pen used to draw the outlines of characters to the given \a pen.
1633 \fn void QTextCharFormat::setToolTip(const QString &text)
1636 Sets the tool tip for a fragment of text to the given \a text.
1640 \fn QString QTextCharFormat::toolTip() const
1643 Returns the tool tip that is displayed for a fragment of text.
1647 \fn void QTextFormat::setForeground(const QBrush &brush)
1649 Sets the foreground brush to the specified \a brush. The foreground
1650 brush is mostly used to render text.
1652 \sa foreground(), clearForeground(), setBackground()
1657 \fn QBrush QTextFormat::foreground() const
1659 Returns the brush used to render foreground details, such as text,
1660 frame outlines, and table borders.
1662 \sa setForeground(), clearForeground(), background()
1666 \fn void QTextFormat::clearForeground()
1668 Clears the brush used to paint the document's foreground. The default
1671 \sa foreground(), setForeground(), clearBackground()
1676 \fn void QTextCharFormat::setAnchor(bool anchor)
1678 If \a anchor is true, text with this format represents an anchor, and is
1679 formatted in the appropriate way; otherwise the text is formatted normally.
1680 (Anchors are hyperlinks which are often shown underlined and in a different
1681 color from plain text.)
1683 The way the text is rendered is independent of whether or not the format
1684 has a valid anchor defined. Use setAnchorHref(), and optionally
1685 setAnchorNames() to create a hypertext link.
1692 \fn bool QTextCharFormat::isAnchor() const
1694 Returns true if the text is formatted as an anchor; otherwise
1697 \sa setAnchor(), setAnchorHref(), setAnchorNames()
1702 \fn void QTextCharFormat::setAnchorHref(const QString &value)
1704 Sets the hypertext link for the text format to the given \a value.
1705 This is typically a URL like "http://example.com/index.html".
1707 The anchor will be displayed with the \a value as its display text;
1708 if you want to display different text call setAnchorNames().
1710 To format the text as a hypertext link use setAnchor().
1715 \fn QString QTextCharFormat::anchorHref() const
1717 Returns the text format's hypertext link, or an empty string if
1723 \fn void QTextCharFormat::setAnchorName(const QString &name)
1726 This function is deprecated. Use setAnchorNames() instead.
1728 Sets the text format's anchor \a name. For the anchor to work as a
1729 hyperlink, the destination must be set with setAnchorHref() and
1730 the anchor must be enabled with setAnchor().
1734 \fn void QTextCharFormat::setAnchorNames(const QStringList &names)
1737 Sets the text format's anchor \a names. For the anchor to work as a
1738 hyperlink, the destination must be set with setAnchorHref() and
1739 the anchor must be enabled with setAnchor().
1743 \fn QString QTextCharFormat::anchorName() const
1746 This function is deprecated. Use anchorNames() instead.
1748 Returns the anchor name associated with this text format, or an empty
1749 string if none has been set. If the anchor name is set, text with this
1750 format can be the destination of a hypertext link.
1752 QString QTextCharFormat::anchorName() const
1754 QVariant prop = property(AnchorName);
1755 if (prop.userType() == QVariant::StringList)
1756 return prop.toStringList().value(0);
1757 else if (prop.userType() != QVariant::String)
1759 return prop.toString();
1763 \fn QStringList QTextCharFormat::anchorNames() const
1766 Returns the anchor names associated with this text format, or an empty
1767 string list if none has been set. If the anchor names are set, text with this
1768 format can be the destination of a hypertext link.
1770 QStringList QTextCharFormat::anchorNames() const
1772 QVariant prop = property(AnchorName);
1773 if (prop.userType() == QVariant::StringList)
1774 return prop.toStringList();
1775 else if (prop.userType() != QVariant::String)
1776 return QStringList();
1777 return QStringList(prop.toString());
1782 \fn void QTextCharFormat::setTableCellRowSpan(int tableCellRowSpan)
1785 If this character format is applied to characters in a table cell,
1786 the cell will span \a tableCellRowSpan rows.
1791 \fn int QTextCharFormat::tableCellRowSpan() const
1794 If this character format is applied to characters in a table cell,
1795 this function returns the number of rows spanned by the text (this may
1796 be 1); otherwise it returns 1.
1800 \fn void QTextCharFormat::setTableCellColumnSpan(int tableCellColumnSpan)
1803 If this character format is applied to characters in a table cell,
1804 the cell will span \a tableCellColumnSpan columns.
1809 \fn int QTextCharFormat::tableCellColumnSpan() const
1812 If this character format is applied to characters in a table cell,
1813 this function returns the number of columns spanned by the text (this
1814 may be 1); otherwise it returns 1.
1818 \fn void QTextCharFormat::setUnderlineColor(const QColor &color)
1820 Sets the underline color used for the characters with this format to
1821 the \a color specified.
1823 \sa underlineColor()
1827 \fn QColor QTextCharFormat::underlineColor() const
1829 Returns the color used to underline the characters with this format.
1831 \sa setUnderlineColor()
1835 \fn void QTextCharFormat::setVerticalAlignment(VerticalAlignment alignment)
1837 Sets the vertical alignment used for the characters with this format to
1838 the \a alignment specified.
1840 \sa verticalAlignment()
1844 \fn VerticalAlignment QTextCharFormat::verticalAlignment() const
1846 Returns the vertical alignment used for characters with this format.
1848 \sa setVerticalAlignment()
1852 Sets the text format's \a font.
1854 void QTextCharFormat::setFont(const QFont &font)
1856 setFontFamily(font.family());
1858 const qreal pointSize = font.pointSizeF();
1859 if (pointSize > 0) {
1860 setFontPointSize(pointSize);
1862 const int pixelSize = font.pixelSize();
1864 setProperty(QTextFormat::FontPixelSize, pixelSize);
1867 setFontWeight(font.weight());
1868 setFontItalic(font.italic());
1869 setUnderlineStyle(font.underline() ? SingleUnderline : NoUnderline);
1870 setFontOverline(font.overline());
1871 setFontStrikeOut(font.strikeOut());
1872 setFontFixedPitch(font.fixedPitch());
1873 setFontCapitalization(font.capitalization());
1874 setFontWordSpacing(font.wordSpacing());
1875 if (font.letterSpacingType() == QFont::AbsoluteSpacing) {
1876 setFontAbsoluteLetterSpacing(font.letterSpacing());
1878 setFontLetterSpacing(font.letterSpacing());
1880 setFontStretch(font.stretch());
1881 setFontStyleHint(font.styleHint());
1882 setFontStyleStrategy(font.styleStrategy());
1883 setFontKerning(font.kerning());
1887 Returns the font for this character format.
1889 QFont QTextCharFormat::font() const
1891 return d ? d->font() : QFont();
1895 \class QTextBlockFormat
1898 \brief The QTextBlockFormat class provides formatting information for
1899 blocks of text in a QTextDocument.
1902 \ingroup richtext-processing
1904 A document is composed of a list of blocks, represented by QTextBlock
1905 objects. Each block can contain an item of some kind, such as a
1906 paragraph of text, a table, a list, or an image. Every block has an
1907 associated QTextBlockFormat that specifies its characteristics.
1909 To cater for left-to-right and right-to-left languages you can set
1910 a block's direction with setDirection(). Paragraph alignment is
1911 set with setAlignment(). Margins are controlled by setTopMargin(),
1912 setBottomMargin(), setLeftMargin(), setRightMargin(). Overall
1913 indentation is set with setIndent(), the indentation of the first
1914 line with setTextIndent().
1916 Line spacing is set with setLineHeight() and retrieved via lineHeight()
1917 and lineHeightType(). The types of line spacing available are in the
1918 LineHeightTypes enum.
1920 Line breaking can be enabled and disabled with setNonBreakableLines().
1922 The brush used to paint the paragraph's background
1923 is set with \l{QTextFormat::setBackground()}{setBackground()}, and other
1924 aspects of the text's appearance can be customized by using the
1925 \l{QTextFormat::setProperty()}{setProperty()} function with the
1926 \c OutlinePen, \c ForegroundBrush, and \c BackgroundBrush
1927 \l{QTextFormat::Property} values.
1929 If a text block is part of a list, it can also have a list format that
1930 is accessible with the listFormat() function.
1932 \sa QTextBlock, QTextCharFormat
1937 \enum QTextBlockFormat::LineHeightTypes
1939 This enum describes the various types of line spacing support paragraphs can have.
1941 \value SingleHeight This is the default line height: single spacing.
1942 \value ProportionalHeight This sets the spacing proportional to the line (in percentage).
1943 For example, set to 200 for double spacing.
1944 \value FixedHeight This sets the line height to a fixed line height (in pixels).
1945 \value MinimumHeight This sets the minimum line height (in pixels).
1946 \value LineDistanceHeight This adds the specified height between lines (in pixels).
1948 \sa lineHeight(), lineHeightType(), setLineHeight()
1952 \fn QTextBlockFormat::QTextBlockFormat()
1954 Constructs a new QTextBlockFormat.
1956 QTextBlockFormat::QTextBlockFormat() : QTextFormat(BlockFormat) {}
1960 \fn QTextBlockFormat::QTextBlockFormat(const QTextFormat &other)
1962 Creates a new block format with the same attributes as the \a given
1965 QTextBlockFormat::QTextBlockFormat(const QTextFormat &fmt)
1972 Sets the tab positions for the text block to those specified by
1977 void QTextBlockFormat::setTabPositions(const QList<QTextOption::Tab> &tabs)
1979 QList<QVariant> list;
1980 QList<QTextOption::Tab>::ConstIterator iter = tabs.constBegin();
1981 while (iter != tabs.constEnd()) {
1983 v.setValue<QTextOption::Tab>(*iter);
1987 setProperty(TabPositions, list);
1992 Returns a list of tab positions defined for the text block.
1994 \sa setTabPositions()
1996 QList<QTextOption::Tab> QTextBlockFormat::tabPositions() const
1998 QVariant variant = property(TabPositions);
1999 if(variant.isNull())
2000 return QList<QTextOption::Tab>();
2001 QList<QTextOption::Tab> answer;
2002 QList<QVariant> variantsList = qvariant_cast<QList<QVariant> >(variant);
2003 QList<QVariant>::Iterator iter = variantsList.begin();
2004 while(iter != variantsList.end()) {
2005 answer.append( qvariant_cast<QTextOption::Tab>(*iter));
2012 \fn QTextBlockFormat::isValid() const
2014 Returns true if this block format is valid; otherwise returns
2019 \fn void QTextFormat::setLayoutDirection(Qt::LayoutDirection direction)
2021 Sets the document's layout direction to the specified \a direction.
2023 \sa layoutDirection()
2028 \fn Qt::LayoutDirection QTextFormat::layoutDirection() const
2030 Returns the document's layout direction.
2032 \sa setLayoutDirection()
2037 \fn void QTextBlockFormat::setAlignment(Qt::Alignment alignment)
2039 Sets the paragraph's \a alignment.
2046 \fn Qt::Alignment QTextBlockFormat::alignment() const
2048 Returns the paragraph's alignment.
2055 \fn void QTextBlockFormat::setTopMargin(qreal margin)
2057 Sets the paragraph's top \a margin.
2059 \sa topMargin(), setBottomMargin(), setLeftMargin(), setRightMargin()
2064 \fn qreal QTextBlockFormat::topMargin() const
2066 Returns the paragraph's top margin.
2068 \sa setTopMargin(), bottomMargin()
2073 \fn void QTextBlockFormat::setBottomMargin(qreal margin)
2075 Sets the paragraph's bottom \a margin.
2077 \sa bottomMargin(), setTopMargin(), setLeftMargin(), setRightMargin()
2082 \fn qreal QTextBlockFormat::bottomMargin() const
2084 Returns the paragraph's bottom margin.
2086 \sa setBottomMargin(), topMargin()
2091 \fn void QTextBlockFormat::setLeftMargin(qreal margin)
2093 Sets the paragraph's left \a margin. Indentation can be applied separately
2096 \sa leftMargin(), setRightMargin(), setTopMargin(), setBottomMargin()
2101 \fn qreal QTextBlockFormat::leftMargin() const
2103 Returns the paragraph's left margin.
2105 \sa setLeftMargin(), rightMargin(), indent()
2110 \fn void QTextBlockFormat::setRightMargin(qreal margin)
2112 Sets the paragraph's right \a margin.
2114 \sa rightMargin(), setLeftMargin(), setTopMargin(), setBottomMargin()
2119 \fn qreal QTextBlockFormat::rightMargin() const
2121 Returns the paragraph's right margin.
2123 \sa setRightMargin(), leftMargin()
2128 \fn void QTextBlockFormat::setTextIndent(qreal indent)
2130 Sets the \a indent for the first line in the block. This allows the first
2131 line of a paragraph to be indented differently to the other lines,
2132 enhancing the readability of the text.
2134 \sa textIndent(), setLeftMargin(), setRightMargin(), setTopMargin(), setBottomMargin()
2139 \fn qreal QTextBlockFormat::textIndent() const
2141 Returns the paragraph's text indent.
2148 \fn void QTextBlockFormat::setIndent(int indentation)
2150 Sets the paragraph's \a indentation. Margins are set independently of
2151 indentation with setLeftMargin() and setTextIndent().
2152 The \a indentation is an integer that is multiplied with the document-wide
2153 standard indent, resulting in the actual indent of the paragraph.
2155 \sa indent(), QTextDocument::indentWidth()
2160 \fn int QTextBlockFormat::indent() const
2162 Returns the paragraph's indent.
2169 \fn void QTextBlockFormat::setLineHeight(qreal height, int heightType)
2172 Sets the line height for the paragraph to the value given by \a height
2173 which is dependent on \a heightType in the way described by the
2174 LineHeightTypes enum.
2176 \sa LineHeightTypes, lineHeight(), lineHeightType()
2181 \fn qreal QTextBlockFormat::lineHeight(qreal scriptLineHeight, qreal scaling) const
2184 Returns the height of the lines in the paragraph based on the height of the
2185 script line given by \a scriptLineHeight and the specified \a scaling
2188 The value that is returned is also dependent on the given LineHeightType of
2189 the paragraph as well as the LineHeight setting that has been set for the
2192 The scaling is needed for heights that include a fixed number of pixels, to
2193 scale them appropriately for printing.
2195 \sa LineHeightTypes, setLineHeight(), lineHeightType()
2200 \fn qreal QTextBlockFormat::lineHeight() const
2203 This returns the LineHeight property for the paragraph.
2205 \sa LineHeightTypes, setLineHeight(), lineHeightType()
2210 \fn qreal QTextBlockFormat::lineHeightType() const
2213 This returns the LineHeightType property of the paragraph.
2215 \sa LineHeightTypes, setLineHeight(), lineHeight()
2220 \fn void QTextBlockFormat::setNonBreakableLines(bool b)
2222 If \a b is true, the lines in the paragraph are treated as
2223 non-breakable; otherwise they are breakable.
2225 \sa nonBreakableLines()
2230 \fn bool QTextBlockFormat::nonBreakableLines() const
2232 Returns true if the lines in the paragraph are non-breakable;
2233 otherwise returns false.
2235 \sa setNonBreakableLines()
2239 \fn QTextFormat::PageBreakFlags QTextBlockFormat::pageBreakPolicy() const
2242 Returns the currently set page break policy for the paragraph. The default is
2243 QTextFormat::PageBreak_Auto.
2245 \sa setPageBreakPolicy()
2249 \fn void QTextBlockFormat::setPageBreakPolicy(PageBreakFlags policy)
2252 Sets the page break policy for the paragraph to \a policy.
2254 \sa pageBreakPolicy()
2258 \class QTextListFormat
2261 \brief The QTextListFormat class provides formatting information for
2262 lists in a QTextDocument.
2265 \ingroup richtext-processing
2267 A list is composed of one or more items, represented as text blocks.
2268 The list's format specifies the appearance of items in the list.
2269 In particular, it determines the indentation and the style of each item.
2271 The indentation of the items is an integer value that causes each item to
2272 be offset from the left margin by a certain amount. This value is read with
2273 indent() and set with setIndent().
2275 The style used to decorate each item is set with setStyle() and can be read
2276 with the style() function. The style controls the type of bullet points and
2277 numbering scheme used for items in the list. Note that lists that use the
2278 decimal numbering scheme begin counting at 1 rather than 0.
2280 Style properties can be set to further configure the appearance of list
2281 items; for example, the ListNumberPrefix and ListNumberSuffix properties
2282 can be used to customize the numbers used in an ordered list so that they
2283 appear as (1), (2), (3), etc.:
2285 \snippet textdocument-listitemstyles/mainwindow.cpp add a styled, ordered list
2291 \enum QTextListFormat::Style
2293 This enum describes the symbols used to decorate list items:
2295 \value ListDisc a filled circle
2296 \value ListCircle an empty circle
2297 \value ListSquare a filled square
2298 \value ListDecimal decimal values in ascending order
2299 \value ListLowerAlpha lower case Latin characters in alphabetical order
2300 \value ListUpperAlpha upper case Latin characters in alphabetical order
2301 \value ListLowerRoman lower case roman numerals (supports up to 4999 items only)
2302 \value ListUpperRoman upper case roman numerals (supports up to 4999 items only)
2303 \omitvalue ListStyleUndefined
2307 \fn QTextListFormat::QTextListFormat()
2309 Constructs a new list format object.
2311 QTextListFormat::QTextListFormat()
2312 : QTextFormat(ListFormat)
2319 \fn QTextListFormat::QTextListFormat(const QTextFormat &other)
2321 Creates a new list format with the same attributes as the \a given
2324 QTextListFormat::QTextListFormat(const QTextFormat &fmt)
2330 \fn bool QTextListFormat::isValid() const
2332 Returns true if this list format is valid; otherwise
2337 \fn void QTextListFormat::setStyle(Style style)
2339 Sets the list format's \a style.
2345 \fn Style QTextListFormat::style() const
2347 Returns the list format's style.
2349 \sa setStyle(), Style
2354 \fn void QTextListFormat::setIndent(int indentation)
2356 Sets the list format's \a indentation.
2357 The indentation is multiplied by the QTextDocument::indentWidth
2358 property to get the effective indent in pixels.
2365 \fn int QTextListFormat::indent() const
2367 Returns the list format's indentation.
2368 The indentation is multiplied by the QTextDocument::indentWidth
2369 property to get the effective indent in pixels.
2375 \fn void QTextListFormat::setNumberPrefix(const QString &numberPrefix)
2378 Sets the list format's number prefix to the string specified by
2379 \a numberPrefix. This can be used with all sorted list types. It does not
2380 have any effect on unsorted list types.
2382 The default prefix is an empty string.
2388 \fn int QTextListFormat::numberPrefix() const
2391 Returns the list format's number prefix.
2393 \sa setNumberPrefix()
2397 \fn void QTextListFormat::setNumberSuffix(const QString &numberSuffix)
2400 Sets the list format's number suffix to the string specified by
2401 \a numberSuffix. This can be used with all sorted list types. It does not
2402 have any effect on unsorted list types.
2404 The default suffix is ".".
2410 \fn int QTextListFormat::numberSuffix() const
2413 Returns the list format's number suffix.
2415 \sa setNumberSuffix()
2419 \class QTextFrameFormat
2422 \brief The QTextFrameFormat class provides formatting information for
2423 frames in a QTextDocument.
2426 \ingroup richtext-processing
2428 A text frame groups together one or more blocks of text, providing a layer
2429 of structure larger than the paragraph. The format of a frame specifies
2430 how it is rendered and positioned on the screen. It does not directly
2431 specify the behavior of the text formatting within, but provides
2432 constraints on the layout of its children.
2434 The frame format defines the width() and height() of the frame on the
2435 screen. Each frame can have a border() that surrounds its contents with
2436 a rectangular box. The border is surrounded by a margin() around the frame,
2437 and the contents of the frame are kept separate from the border by the
2438 frame's padding(). This scheme is similar to the box model used by Cascading
2439 Style Sheets for HTML pages.
2441 \img qtextframe-style.png
2443 The position() of a frame is set using setPosition() and determines how it
2444 is located relative to the surrounding text.
2446 The validity of a QTextFrameFormat object can be determined with the
2449 \sa QTextFrame, QTextBlockFormat
2453 \enum QTextFrameFormat::Position
2455 This enum describes how a frame is located relative to the surrounding text.
2461 \sa position(), CssFloat
2465 \enum QTextFrameFormat::BorderStyle
2468 This enum describes different border styles for the text frame.
2470 \value BorderStyle_None
2471 \value BorderStyle_Dotted
2472 \value BorderStyle_Dashed
2473 \value BorderStyle_Solid
2474 \value BorderStyle_Double
2475 \value BorderStyle_DotDash
2476 \value BorderStyle_DotDotDash
2477 \value BorderStyle_Groove
2478 \value BorderStyle_Ridge
2479 \value BorderStyle_Inset
2480 \value BorderStyle_Outset
2482 \sa borderStyle(), FrameBorderStyle
2486 \fn QTextFrameFormat::QTextFrameFormat()
2488 Constructs a text frame format object with the default properties.
2490 QTextFrameFormat::QTextFrameFormat() : QTextFormat(FrameFormat)
2492 setBorderStyle(BorderStyle_Outset);
2493 setBorderBrush(Qt::darkGray);
2498 \fn QTextFrameFormat::QTextFrameFormat(const QTextFormat &other)
2500 Creates a new frame format with the same attributes as the \a given
2503 QTextFrameFormat::QTextFrameFormat(const QTextFormat &fmt)
2509 \fn QTextFrameFormat::isValid() const
2511 Returns true if the format description is valid; otherwise returns false.
2515 \fn QTextFrameFormat::setPosition(Position policy)
2517 Sets the \a policy for positioning frames with this frame format.
2522 \fn Position QTextFrameFormat::position() const
2524 Returns the positioning policy for frames with this frame format.
2528 \fn QTextFrameFormat::setBorder(qreal width)
2530 Sets the \a width (in pixels) of the frame's border.
2534 \fn qreal QTextFrameFormat::border() const
2536 Returns the width of the border in pixels.
2540 \fn QTextFrameFormat::setBorderBrush(const QBrush &brush)
2543 Sets the \a brush used for the frame's border.
2547 \fn QBrush QTextFrameFormat::borderBrush() const
2550 Returns the brush used for the frame's border.
2554 \fn QTextFrameFormat::setBorderStyle(BorderStyle style)
2557 Sets the \a style of the frame's border.
2561 \fn BorderStyle QTextFrameFormat::borderStyle() const
2564 Returns the style of the frame's border.
2568 \fn QTextFrameFormat::setMargin(qreal margin)
2570 Sets the frame's \a margin in pixels.
2571 This method also sets the left, right, top and bottom margins
2572 of the frame to the same value. The individual margins override
2575 void QTextFrameFormat::setMargin(qreal amargin)
2577 setProperty(FrameMargin, amargin);
2578 setProperty(FrameTopMargin, amargin);
2579 setProperty(FrameBottomMargin, amargin);
2580 setProperty(FrameLeftMargin, amargin);
2581 setProperty(FrameRightMargin, amargin);
2586 \fn qreal QTextFrameFormat::margin() const
2588 Returns the width of the frame's external margin in pixels.
2592 \fn QTextFrameFormat::setTopMargin(qreal margin)
2595 Sets the frame's top \a margin in pixels.
2599 \fn qreal QTextFrameFormat::topMargin() const
2602 Returns the width of the frame's top margin in pixels.
2604 qreal QTextFrameFormat::topMargin() const
2606 if (!hasProperty(FrameTopMargin))
2608 return doubleProperty(FrameTopMargin);
2612 \fn QTextFrameFormat::setBottomMargin(qreal margin)
2615 Sets the frame's bottom \a margin in pixels.
2619 \fn qreal QTextFrameFormat::bottomMargin() const
2622 Returns the width of the frame's bottom margin in pixels.
2624 qreal QTextFrameFormat::bottomMargin() const
2626 if (!hasProperty(FrameBottomMargin))
2628 return doubleProperty(FrameBottomMargin);
2632 \fn QTextFrameFormat::setLeftMargin(qreal margin)
2635 Sets the frame's left \a margin in pixels.
2639 \fn qreal QTextFrameFormat::leftMargin() const
2642 Returns the width of the frame's left margin in pixels.
2644 qreal QTextFrameFormat::leftMargin() const
2646 if (!hasProperty(FrameLeftMargin))
2648 return doubleProperty(FrameLeftMargin);
2652 \fn QTextFrameFormat::setRightMargin(qreal margin)
2655 Sets the frame's right \a margin in pixels.
2659 \fn qreal QTextFrameFormat::rightMargin() const
2662 Returns the width of the frame's right margin in pixels.
2664 qreal QTextFrameFormat::rightMargin() const
2666 if (!hasProperty(FrameRightMargin))
2668 return doubleProperty(FrameRightMargin);
2672 \fn QTextFrameFormat::setPadding(qreal width)
2674 Sets the \a width of the frame's internal padding in pixels.
2678 \fn qreal QTextFrameFormat::padding() const
2680 Returns the width of the frame's internal padding in pixels.
2684 \fn QTextFrameFormat::setWidth(const QTextLength &width)
2686 Sets the frame's border rectangle's \a width.
2692 \fn QTextFrameFormat::setWidth(qreal width)
2695 Convenience method that sets the width of the frame's border
2696 rectangle's width to the specified fixed \a width.
2700 \fn QTextFormat::PageBreakFlags QTextFrameFormat::pageBreakPolicy() const
2703 Returns the currently set page break policy for the frame/table. The default is
2704 QTextFormat::PageBreak_Auto.
2706 \sa setPageBreakPolicy()
2710 \fn void QTextFrameFormat::setPageBreakPolicy(PageBreakFlags policy)
2713 Sets the page break policy for the frame/table to \a policy.
2715 \sa pageBreakPolicy()
2719 \fn QTextLength QTextFrameFormat::width() const
2721 Returns the width of the frame's border rectangle.
2727 \fn void QTextFrameFormat::setHeight(const QTextLength &height)
2729 Sets the frame's \a height.
2733 \fn void QTextFrameFormat::setHeight(qreal height)
2736 Sets the frame's \a height.
2740 \fn qreal QTextFrameFormat::height() const
2742 Returns the height of the frame's border rectangle.
2746 \class QTextTableFormat
2749 \brief The QTextTableFormat class provides formatting information for
2750 tables in a QTextDocument.
2753 \ingroup richtext-processing
2755 A table is a group of cells ordered into rows and columns. Each table
2756 contains at least one row and one column. Each cell contains a block.
2757 Tables in rich text documents are formatted using the properties
2758 defined in this class.
2760 Tables are horizontally justified within their parent frame according to the
2761 table's alignment. This can be read with the alignment() function and set
2762 with setAlignment().
2764 Cells within the table are separated by cell spacing. The number of pixels
2765 between cells is set with setCellSpacing() and read with cellSpacing().
2766 The contents of each cell is surrounded by cell padding. The number of pixels
2767 between each cell edge and its contents is set with setCellPadding() and read
2770 \image qtexttableformat-cell.png
2772 The table's background color can be read with the background() function,
2773 and can be specified with setBackground(). The background color of each
2774 cell can be set independently, and will control the color of the cell within
2777 The table format also provides a way to constrain the widths of the columns
2778 in the table. Columns can be assigned a fixed width, a variable width, or
2779 a percentage of the available width (see QTextLength). The columns() function
2780 returns the number of columns with constraints, and the
2781 columnWidthConstraints() function returns the constraints defined for the
2782 table. These quantities can also be set by calling setColumnWidthConstraints()
2783 with a vector containing new constraints. If no constraints are
2784 required, clearColumnWidthConstraints() can be used to remove them.
2786 \sa QTextTable, QTextTableCell, QTextLength
2790 \fn QTextTableFormat::QTextTableFormat()
2792 Constructs a new table format object.
2794 QTextTableFormat::QTextTableFormat()
2795 : QTextFrameFormat()
2797 setObjectType(TableObject);
2804 \fn QTextTableFormat::QTextTableFormat(const QTextFormat &other)
2806 Creates a new table format with the same attributes as the \a given
2809 QTextTableFormat::QTextTableFormat(const QTextFormat &fmt)
2810 : QTextFrameFormat(fmt)
2815 \fn bool QTextTableFormat::isValid() const
2817 Returns true if this table format is valid; otherwise
2823 \fn int QTextTableFormat::columns() const
2825 Returns the number of columns specified by the table format.
2831 \fn void QTextTableFormat::setColumns(int columns)
2833 Sets the number of \a columns required by the table format.
2839 \fn void QTextTableFormat::clearColumnWidthConstraints()
2841 Clears the column width constraints for the table.
2843 \sa columnWidthConstraints(), setColumnWidthConstraints()
2847 \fn void QTextTableFormat::setColumnWidthConstraints(const QVector<QTextLength> &constraints)
2849 Sets the column width \a constraints for the table.
2851 \sa columnWidthConstraints(), clearColumnWidthConstraints()
2855 \fn QVector<QTextLength> QTextTableFormat::columnWidthConstraints() const
2857 Returns a list of constraints used by this table format to control the
2858 appearance of columns in a table.
2860 \sa setColumnWidthConstraints()
2864 \fn qreal QTextTableFormat::cellSpacing() const
2866 Returns the table's cell spacing. This describes the distance between
2871 \fn void QTextTableFormat::setCellSpacing(qreal spacing)
2873 Sets the cell \a spacing for the table. This determines the distance
2874 between adjacent cells.
2878 \fn qreal QTextTableFormat::cellPadding() const
2880 Returns the table's cell padding. This describes the distance between
2881 the border of a cell and its contents.
2885 \fn void QTextTableFormat::setCellPadding(qreal padding)
2887 Sets the cell \a padding for the table. This determines the distance
2888 between the border of a cell and its contents.
2892 \fn void QTextTableFormat::setAlignment(Qt::Alignment alignment)
2894 Sets the table's \a alignment.
2900 \fn Qt::Alignment QTextTableFormat::alignment() const
2902 Returns the table's alignment.
2908 \fn void QTextTableFormat::setHeaderRowCount(int count)
2911 Declares the first \a count rows of the table as table header.
2912 The table header rows get repeated when a table is broken
2913 across a page boundary.
2917 \fn int QTextTableFormat::headerRowCount() const
2920 Returns the number of rows in the table that define the header.
2922 \sa setHeaderRowCount()
2926 \fn void QTextFormat::setBackground(const QBrush &brush)
2928 Sets the brush use to paint the document's background to the
2931 \sa background(), clearBackground(), setForeground()
2935 \fn QColor QTextFormat::background() const
2937 Returns the brush used to paint the document's background.
2939 \sa setBackground(), clearBackground(), foreground()
2943 \fn void QTextFormat::clearBackground()
2945 Clears the brush used to paint the document's background. The default
2948 \sa background(), setBackground(), clearForeground()
2953 \class QTextImageFormat
2956 \brief The QTextImageFormat class provides formatting information for
2957 images in a QTextDocument.
2960 \ingroup richtext-processing
2962 Inline images are represented by an object replacement character
2963 (0xFFFC in Unicode) which has an associated QTextImageFormat. The
2964 image format specifies a name with setName() that is used to
2965 locate the image. The size of the rectangle that the image will
2966 occupy is specified using setWidth() and setHeight().
2968 Images can be supplied in any format for which Qt has an image
2969 reader, so SVG drawings can be included alongside PNG, TIFF and
2970 other bitmap formats.
2972 \sa QImage, QImageReader
2976 \fn QTextImageFormat::QTextImageFormat()
2978 Creates a new image format object.
2980 QTextImageFormat::QTextImageFormat() : QTextCharFormat() { setObjectType(ImageObject); }
2984 \fn QTextImageFormat::QTextImageFormat(const QTextFormat &other)
2986 Creates a new image format with the same attributes as the \a given
2989 QTextImageFormat::QTextImageFormat(const QTextFormat &fmt)
2990 : QTextCharFormat(fmt)
2995 \fn bool QTextImageFormat::isValid() const
2997 Returns true if this image format is valid; otherwise returns false.
3002 \fn void QTextImageFormat::setName(const QString &name)
3004 Sets the \a name of the image. The \a name is used to locate the image
3005 in the application's resources.
3012 \fn QString QTextImageFormat::name() const
3014 Returns the name of the image. The name refers to an entry in the
3015 application's resources file.
3021 \fn void QTextImageFormat::setWidth(qreal width)
3023 Sets the \a width of the rectangle occupied by the image.
3025 \sa width(), setHeight()
3030 \fn qreal QTextImageFormat::width() const
3032 Returns the width of the rectangle occupied by the image.
3034 \sa height(), setWidth()
3039 \fn void QTextImageFormat::setHeight(qreal height)
3041 Sets the \a height of the rectangle occupied by the image.
3043 \sa height(), setWidth()
3048 \fn qreal QTextImageFormat::height() const
3050 Returns the height of the rectangle occupied by the image.
3052 \sa width(), setHeight()
3056 \fn void QTextCharFormat::setFontCapitalization(QFont::Capitalization capitalization)
3059 Sets the capitalization of the text that apppears in this font to \a capitalization.
3061 A font's capitalization makes the text appear in the selected capitalization mode.
3063 \sa fontCapitalization()
3067 \fn Capitalization QTextCharFormat::fontCapitalization() const
3070 Returns the current capitalization type of the font.
3074 \fn void QTextCharFormat::setFontAbsoluteLetterSpacing(bool absolute)
3077 Sets the letter spacing type of this format to absolute.
3078 \sa fontAbsoluteLetterSpacing()
3079 \sa setFontLetterSpacing()
3080 \sa fontLetterSpacing()
3084 \fn bool QTextCharFormat::fontAbsoluteLetterSpacing() const
3087 Returns if the current letter spacing is absolute (or percentage).
3088 \sa setFontAbsoluteLetterSpacing()
3089 \sa setFontLetterSpacing()
3090 \sa fontLetterSpacing()
3094 \fn void QTextCharFormat::setFontLetterSpacing(qreal spacing)
3097 Sets the letter spacing of this format to the given \a spacing.
3098 Depending on fontAbsoluteLetterSpacing the value is given in absolutes or in percent.
3099 For percent a value of 100 indicates default spacing; a value of 200 doubles the amount
3100 of space a letter takes.
3102 \sa fontLetterSpacing()
3103 \sa setFontAbsoluteLetterSpacing()
3104 \sa fontAbsoluteLetterSpacing()
3108 \fn qreal QTextCharFormat::fontLetterSpacing() const
3111 Returns the current letter spacing percentage.
3115 \fn void QTextCharFormat::setFontWordSpacing(qreal spacing)
3118 Sets the word spacing of this format to the given \a spacing, in pixels.
3120 \sa fontWordSpacing()
3124 \fn qreal QTextCharFormat::fontWordSpacing() const
3127 Returns the current word spacing value.
3131 \fn void QTextCharFormat::setFontStretch(int factor)
3134 Sets the stretch factor for the font.
3136 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.
3138 The stretch factor is only applied to outline fonts. The stretch factor is ignored for bitmap fonts.
3144 \fn int QTextCharFormat::fontStretch() const
3147 Returns the current font stretching.
3148 \sa setFontStretch()
3152 \fn qreal QTextTableCellFormat::topPadding() const
3155 Gets the top padding of the table cell.
3157 \sa setTopPadding(), leftPadding(), rightPadding(), bottomPadding()
3161 \fn qreal QTextTableCellFormat::bottomPadding() const
3164 Gets the bottom padding of the table cell.
3166 \sa setBottomPadding(), leftPadding(), rightPadding(), topPadding()
3170 \fn qreal QTextTableCellFormat::leftPadding() const
3173 Gets the left padding of the table cell.
3175 \sa setLeftPadding(), rightPadding(), topPadding(), bottomPadding()
3179 \fn qreal QTextTableCellFormat::rightPadding() const
3182 Gets the right padding of the table cell.
3184 \sa setRightPadding(), leftPadding(), topPadding(), bottomPadding()
3188 \fn void QTextTableCellFormat::setTopPadding(qreal padding)
3191 Sets the top \a padding of the table cell.
3193 \sa topPadding(), setLeftPadding(), setRightPadding(), setBottomPadding()
3197 \fn void QTextTableCellFormat::setBottomPadding(qreal padding)
3200 Sets the bottom \a padding of the table cell.
3202 \sa bottomPadding(), setLeftPadding(), setRightPadding(), setTopPadding()
3206 \fn void QTextTableCellFormat::setLeftPadding(qreal padding)
3209 Sets the left \a padding of the table cell.
3211 \sa leftPadding(), setRightPadding(), setTopPadding(), setBottomPadding()
3215 \fn void QTextTableCellFormat::setRightPadding(qreal padding)
3218 Sets the right \a padding of the table cell.
3220 \sa rightPadding(), setLeftPadding(), setTopPadding(), setBottomPadding()
3224 \fn void QTextTableCellFormat::setPadding(qreal padding)
3227 Sets the left, right, top, and bottom \a padding of the table cell.
3229 \sa setLeftPadding(), setRightPadding(), setTopPadding(), setBottomPadding()
3233 \fn bool QTextTableCellFormat::isValid() const
3236 Returns true if this table cell format is valid; otherwise returns false.
3240 \fn QTextTableCellFormat::QTextTableCellFormat()
3243 Constructs a new table cell format object.
3245 QTextTableCellFormat::QTextTableCellFormat()
3248 setObjectType(TableCellObject);
3253 \fn QTextTableCellFormat::QTextTableCellFormat(const QTextFormat &other)
3255 Creates a new table cell format with the same attributes as the \a given
3258 QTextTableCellFormat::QTextTableCellFormat(const QTextFormat &fmt)
3259 : QTextCharFormat(fmt)
3264 \class QTextTableCellFormat
3268 \brief The QTextTableCellFormat class provides formatting information for
3269 table cells in a QTextDocument.
3272 \ingroup richtext-processing
3274 The table cell format of a table cell in a document specifies the visual
3275 properties of the table cell.
3277 The padding properties of a table cell are controlled by setLeftPadding(),
3278 setRightPadding(), setTopPadding(), and setBottomPadding(). All the paddings
3279 can be set at once using setPadding().
3281 \sa QTextFormat, QTextBlockFormat, QTextTableFormat, QTextCharFormat
3284 // ------------------------------------------------------
3287 QTextFormatCollection::QTextFormatCollection(const QTextFormatCollection &rhs)
3289 formats = rhs.formats;
3290 objFormats = rhs.objFormats;
3293 QTextFormatCollection &QTextFormatCollection::operator=(const QTextFormatCollection &rhs)
3295 formats = rhs.formats;
3296 objFormats = rhs.objFormats;
3300 QTextFormatCollection::~QTextFormatCollection()
3304 int QTextFormatCollection::indexForFormat(const QTextFormat &format)
3306 uint hash = getHash(format.d, format.format_type);
3307 QMultiHash<uint, int>::const_iterator i = hashes.constFind(hash);
3308 while (i != hashes.constEnd() && i.key() == hash) {
3309 if (formats.value(i.value()) == format) {
3315 int idx = formats.size();
3316 formats.append(format);
3319 QTextFormat &f = formats.last();
3321 f.d = new QTextFormatPrivate;
3322 f.d->resolveFont(defaultFnt);
3324 if (!hashes.contains(hash, idx))
3325 hashes.insert(hash, idx);
3334 bool QTextFormatCollection::hasFormatCached(const QTextFormat &format) const
3336 uint hash = getHash(format.d, format.format_type);
3337 QMultiHash<uint, int>::const_iterator i = hashes.find(hash);
3338 while (i != hashes.end() && i.key() == hash) {
3339 if (formats.value(i.value()) == format) {
3347 QTextFormat QTextFormatCollection::objectFormat(int objectIndex) const
3349 if (objectIndex == -1)
3350 return QTextFormat();
3351 return format(objFormats.at(objectIndex));
3354 void QTextFormatCollection::setObjectFormat(int objectIndex, const QTextFormat &f)
3356 const int formatIndex = indexForFormat(f);
3357 objFormats[objectIndex] = formatIndex;
3360 int QTextFormatCollection::objectFormatIndex(int objectIndex) const
3362 if (objectIndex == -1)
3364 return objFormats.at(objectIndex);
3367 void QTextFormatCollection::setObjectFormatIndex(int objectIndex, int formatIndex)
3369 objFormats[objectIndex] = formatIndex;
3372 int QTextFormatCollection::createObjectIndex(const QTextFormat &f)
3374 const int objectIndex = objFormats.size();
3375 objFormats.append(indexForFormat(f));
3379 QTextFormat QTextFormatCollection::format(int idx) const
3381 if (idx < 0 || idx >= formats.count())
3382 return QTextFormat();
3384 return formats.at(idx);
3387 void QTextFormatCollection::setDefaultFont(const QFont &f)
3390 for (int i = 0; i < formats.count(); ++i)
3392 formats[i].d->resolveFont(defaultFnt);
3395 #ifndef QT_NO_DEBUG_STREAM
3396 QDebug operator<<(QDebug dbg, const QTextLength &l)
3398 dbg.nospace() << "QTextLength(QTextLength::Type(" << l.type() << "))";
3402 QDebug operator<<(QDebug dbg, const QTextFormat &f)
3404 dbg.nospace() << "QTextFormat(QTextFormat::FormatType(" << f.type() << "))";