1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qtextformat.h"
5#include "qtextformat_p.h"
6
7#include <qvariant.h>
8#include <qdatastream.h>
9#include <qdebug.h>
10#include <qmap.h>
11#include <qhashfunctions.h>
12
13QT_BEGIN_NAMESPACE
14
15/*!
16 \class QTextLength
17 \reentrant
18
19 \brief The QTextLength class encapsulates the different types of length
20 used in a QTextDocument.
21 \inmodule QtGui
22
23 \ingroup richtext-processing
24
25 When we specify a value for the length of an element in a text document,
26 we often need to provide some other information so that the length is
27 used in the way we expect. For example, when we specify a table width,
28 the value can represent a fixed number of pixels, or it can be a percentage
29 value. This information changes both the meaning of the value and the way
30 it is used.
31
32 Generally, this class is used to specify table widths. These can be
33 specified either as a fixed amount of pixels, as a percentage of the
34 containing frame's width, or by a variable width that allows it to take
35 up just the space it requires.
36
37 \sa QTextTable
38*/
39
40/*!
41 \fn explicit QTextLength::QTextLength()
42
43 Constructs a new length object which represents a variable size.
44*/
45
46/*!
47 \fn QTextLength::QTextLength(Type type, qreal value)
48
49 Constructs a new length object of the given \a type and \a value.
50*/
51
52/*!
53 \fn Type QTextLength::type() const
54
55 Returns the type of this length object.
56
57 \sa QTextLength::Type
58*/
59
60/*!
61 \fn qreal QTextLength::value(qreal maximumLength) const
62
63 Returns the effective length, constrained by the type of the length object
64 and the specified \a maximumLength.
65
66 \sa type()
67*/
68
69/*!
70 \fn qreal QTextLength::rawValue() const
71
72 Returns the constraint value that is specific for the type of the length.
73 If the length is QTextLength::PercentageLength then the raw value is in
74 percent, in the range of 0 to 100. If the length is QTextLength::FixedLength
75 then that fixed amount is returned. For variable lengths, zero is returned.
76*/
77
78/*!
79 \fn bool QTextLength::operator==(const QTextLength &other) const
80
81 Returns \c true if this text length is the same as the \a other text
82 length.
83*/
84
85/*!
86 \fn bool QTextLength::operator!=(const QTextLength &other) const
87
88 Returns \c true if this text length is different from the \a other text
89 length.
90*/
91
92/*!
93 \enum QTextLength::Type
94
95 This enum describes the different types a length object can
96 have.
97
98 \value VariableLength The width of the object is variable
99 \value FixedLength The width of the object is fixed
100 \value PercentageLength The width of the object is in
101 percentage of the maximum width
102
103 \sa type()
104*/
105
106/*!
107 Returns the text length as a QVariant
108*/
109QTextLength::operator QVariant() const
110{
111 return QVariant::fromValue(value: *this);
112}
113
114#ifndef QT_NO_DATASTREAM
115QDataStream &operator<<(QDataStream &stream, const QTextLength &length)
116{
117 return stream << qint32(length.lengthType) << double(length.fixedValueOrPercentage);
118}
119
120QDataStream &operator>>(QDataStream &stream, QTextLength &length)
121{
122 qint32 type;
123 double fixedValueOrPercentage;
124 stream >> type >> fixedValueOrPercentage;
125 length.fixedValueOrPercentage = fixedValueOrPercentage;
126 length.lengthType = QTextLength::Type(type);
127 return stream;
128}
129#endif // QT_NO_DATASTREAM
130
131namespace {
132struct Property
133{
134 inline Property(qint32 k, const QVariant &v) : key(k), value(v) {}
135 inline Property() {}
136
137 qint32 key = -1;
138 QVariant value;
139
140 inline bool operator==(const Property &other) const
141 { return key == other.key && value == other.value; }
142};
143}
144Q_DECLARE_TYPEINFO(Property, Q_RELOCATABLE_TYPE);
145
146class QTextFormatPrivate : public QSharedData
147{
148public:
149 QTextFormatPrivate() : hashDirty(true), fontDirty(true), hashValue(0) {}
150
151 inline size_t hash() const
152 {
153 if (!hashDirty)
154 return hashValue;
155 return recalcHash();
156 }
157
158 inline bool operator==(const QTextFormatPrivate &rhs) const {
159 if (hash() != rhs.hash())
160 return false;
161
162 return props == rhs.props;
163 }
164
165 inline void insertProperty(qint32 key, const QVariant &value)
166 {
167 hashDirty = true;
168 if (key >= QTextFormat::FirstFontProperty && key <= QTextFormat::LastFontProperty)
169 fontDirty = true;
170
171 for (int i = 0; i < props.size(); ++i)
172 if (props.at(i).key == key) {
173 props[i].value = value;
174 return;
175 }
176 props.append(t: Property(key, value));
177 }
178
179 inline void clearProperty(qint32 key)
180 {
181 for (int i = 0; i < props.size(); ++i)
182 if (props.at(i).key == key) {
183 hashDirty = true;
184 if (key >= QTextFormat::FirstFontProperty && key <= QTextFormat::LastFontProperty)
185 fontDirty = true;
186 props.remove(i);
187 return;
188 }
189 }
190
191 inline int propertyIndex(qint32 key) const
192 {
193 for (int i = 0; i < props.size(); ++i)
194 if (props.at(i).key == key)
195 return i;
196 return -1;
197 }
198
199 inline QVariant property(qint32 key) const
200 {
201 const int idx = propertyIndex(key);
202 if (idx < 0)
203 return QVariant();
204 return props.at(i: idx).value;
205 }
206
207 inline bool hasProperty(qint32 key) const
208 { return propertyIndex(key) != -1; }
209
210 void resolveFont(const QFont &defaultFont);
211
212 inline const QFont &font() const {
213 if (fontDirty)
214 recalcFont();
215 return fnt;
216 }
217
218 QList<Property> props;
219private:
220
221 size_t recalcHash() const;
222 void recalcFont() const;
223
224 mutable bool hashDirty;
225 mutable bool fontDirty;
226 mutable size_t hashValue;
227 mutable QFont fnt;
228
229 friend QDataStream &operator<<(QDataStream &, const QTextFormat &);
230 friend QDataStream &operator>>(QDataStream &, QTextFormat &);
231};
232
233static inline size_t hash(const QColor &color)
234{
235 return (color.isValid()) ? color.rgba() : 0x234109;
236}
237
238static inline size_t hash(const QPen &pen)
239{
240 return hash(color: pen.color()) + qHash(key: pen.widthF());
241}
242
243static inline size_t hash(const QBrush &brush)
244{
245 return hash(color: brush.color()) + (brush.style() << 3);
246}
247
248static inline size_t variantHash(const QVariant &variant)
249{
250 // simple and fast hash functions to differentiate between type and value
251 switch (variant.userType()) { // sorted by occurrence frequency
252 case QMetaType::QString: return qHash(key: variant.toString());
253 case QMetaType::Double: return qHash(key: variant.toDouble());
254 case QMetaType::Int: return 0x811890U + variant.toInt();
255 case QMetaType::QBrush:
256 return 0x01010101 + hash(brush: qvariant_cast<QBrush>(v: variant));
257 case QMetaType::Bool: return 0x371818 + variant.toBool();
258 case QMetaType::QPen: return 0x02020202 + hash(pen: qvariant_cast<QPen>(v: variant));
259 case QMetaType::QVariantList:
260 return 0x8377U + qvariant_cast<QVariantList>(v: variant).size();
261 case QMetaType::QColor: return hash(color: qvariant_cast<QColor>(v: variant));
262 case QMetaType::QTextLength:
263 return 0x377 + hash(color: qvariant_cast<QTextLength>(v: variant).rawValue());
264 case QMetaType::Float: return qHash(key: variant.toFloat());
265 case QMetaType::UnknownType: return 0;
266 default: break;
267 }
268 return qHash(key: variant.typeName());
269}
270
271static inline size_t getHash(const QTextFormatPrivate *d, int format)
272{
273 return (d ? d->hash() : 0) + format;
274}
275
276size_t QTextFormatPrivate::recalcHash() const
277{
278 hashValue = 0;
279 const auto end = props.constEnd();
280 for (auto it = props.constBegin(); it != end; ++it)
281 hashValue += (static_cast<quint32>(it->key) << 16) + variantHash(variant: it->value);
282
283 hashDirty = false;
284
285 return hashValue;
286}
287
288void QTextFormatPrivate::resolveFont(const QFont &defaultFont)
289{
290 recalcFont();
291 const uint oldMask = fnt.resolveMask();
292 fnt = fnt.resolve(defaultFont);
293
294 if (hasProperty(key: QTextFormat::FontSizeAdjustment)) {
295 const qreal scaleFactors[7] = {qreal(0.7), qreal(0.8), qreal(1.0), qreal(1.2), qreal(1.5), qreal(2), qreal(2.4)};
296
297 const int htmlFontSize = qBound(min: 0, val: property(key: QTextFormat::FontSizeAdjustment).toInt() + 3 - 1, max: 6);
298
299
300 if (defaultFont.pointSize() <= 0) {
301 qreal pixelSize = scaleFactors[htmlFontSize] * defaultFont.pixelSize();
302 fnt.setPixelSize(qRound(d: pixelSize));
303 } else {
304 qreal pointSize = scaleFactors[htmlFontSize] * defaultFont.pointSizeF();
305 fnt.setPointSizeF(pointSize);
306 }
307 }
308
309 fnt.setResolveMask(oldMask);
310}
311
312void QTextFormatPrivate::recalcFont() const
313{
314 // update cached font as well
315 QFont f;
316
317 bool hasSpacingInformation = false;
318 QFont::SpacingType spacingType = QFont::PercentageSpacing;
319 qreal letterSpacing = 0.0;
320
321 for (int i = 0; i < props.size(); ++i) {
322 switch (props.at(i).key) {
323 case QTextFormat::FontFamilies:
324 f.setFamilies(props.at(i).value.toStringList());
325 break;
326 case QTextFormat::FontStyleName:
327 f.setStyleName(props.at(i).value.toString());
328 break;
329 case QTextFormat::FontPointSize:
330 f.setPointSizeF(props.at(i).value.toReal());
331 break;
332 case QTextFormat::FontPixelSize:
333 f.setPixelSize(props.at(i).value.toInt());
334 break;
335 case QTextFormat::FontWeight: {
336 const QVariant weightValue = props.at(i).value;
337 int weight = weightValue.toInt();
338 if (weight >= 0 && weightValue.isValid())
339 f.setWeight(QFont::Weight(weight));
340 break; }
341 case QTextFormat::FontItalic:
342 f.setItalic(props.at(i).value.toBool());
343 break;
344 case QTextFormat::FontUnderline:
345 if (! hasProperty(key: QTextFormat::TextUnderlineStyle)) // don't use the old one if the new one is there.
346 f.setUnderline(props.at(i).value.toBool());
347 break;
348 case QTextFormat::TextUnderlineStyle:
349 f.setUnderline(static_cast<QTextCharFormat::UnderlineStyle>(props.at(i).value.toInt()) == QTextCharFormat::SingleUnderline);
350 break;
351 case QTextFormat::FontOverline:
352 f.setOverline(props.at(i).value.toBool());
353 break;
354 case QTextFormat::FontStrikeOut:
355 f.setStrikeOut(props.at(i).value.toBool());
356 break;
357 case QTextFormat::FontLetterSpacingType:
358 spacingType = static_cast<QFont::SpacingType>(props.at(i).value.toInt());
359 hasSpacingInformation = true;
360 break;
361 case QTextFormat::FontLetterSpacing:
362 letterSpacing = props.at(i).value.toReal();
363 hasSpacingInformation = true;
364 break;
365 case QTextFormat::FontWordSpacing:
366 f.setWordSpacing(props.at(i).value.toReal());
367 break;
368 case QTextFormat::FontCapitalization:
369 f.setCapitalization(static_cast<QFont::Capitalization> (props.at(i).value.toInt()));
370 break;
371 case QTextFormat::FontFixedPitch: {
372 const bool value = props.at(i).value.toBool();
373 if (f.fixedPitch() != value)
374 f.setFixedPitch(value);
375 break; }
376 case QTextFormat::FontStretch:
377 f.setStretch(props.at(i).value.toInt());
378 break;
379 case QTextFormat::FontStyleHint:
380 f.setStyleHint(static_cast<QFont::StyleHint>(props.at(i).value.toInt()), f.styleStrategy());
381 break;
382 case QTextFormat::FontHintingPreference:
383 f.setHintingPreference(static_cast<QFont::HintingPreference>(props.at(i).value.toInt()));
384 break;
385 case QTextFormat::FontStyleStrategy:
386 f.setStyleStrategy(static_cast<QFont::StyleStrategy>(props.at(i).value.toInt()));
387 break;
388 case QTextFormat::FontKerning:
389 f.setKerning(props.at(i).value.toBool());
390 break;
391 default:
392 break;
393 }
394 }
395
396 if (hasSpacingInformation)
397 f.setLetterSpacing(type: spacingType, spacing: letterSpacing);
398
399 fnt = f;
400 fontDirty = false;
401}
402
403#ifndef QT_NO_DATASTREAM
404Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QTextFormat &fmt)
405{
406 QMap<int, QVariant> properties = fmt.properties();
407 if (stream.version() < QDataStream::Qt_6_0) {
408 auto it = properties.constFind(key: QTextFormat::FontLetterSpacingType);
409 if (it != properties.cend()) {
410 properties[QTextFormat::OldFontLetterSpacingType] = it.value();
411 properties.erase(it);
412 }
413
414 it = properties.constFind(key: QTextFormat::FontStretch);
415 if (it != properties.cend()) {
416 properties[QTextFormat::OldFontStretch] = it.value();
417 properties.erase(it);
418 }
419
420 it = properties.constFind(key: QTextFormat::TextUnderlineColor);
421 if (it != properties.cend()) {
422 properties[QTextFormat::OldTextUnderlineColor] = it.value();
423 properties.erase(it);
424 }
425
426 it = properties.constFind(key: QTextFormat::FontFamilies);
427 if (it != properties.cend()) {
428 properties[QTextFormat::OldFontFamily] = QVariant(it.value().toStringList().constFirst());
429 properties.erase(it);
430 }
431 }
432
433 stream << fmt.format_type << properties;
434 return stream;
435}
436
437Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QTextFormat &fmt)
438{
439 QMap<qint32, QVariant> properties;
440 stream >> fmt.format_type >> properties;
441
442 // QTextFormat's default constructor doesn't allocate the private structure, so
443 // we have to do this, in case fmt is a default constructed value.
444 if (!fmt.d)
445 fmt.d = new QTextFormatPrivate();
446
447 for (QMap<qint32, QVariant>::ConstIterator it = properties.constBegin();
448 it != properties.constEnd(); ++it) {
449 qint32 key = it.key();
450 if (key == QTextFormat::OldFontLetterSpacingType)
451 key = QTextFormat::FontLetterSpacingType;
452 else if (key == QTextFormat::OldFontStretch)
453 key = QTextFormat::FontStretch;
454 else if (key == QTextFormat::OldTextUnderlineColor)
455 key = QTextFormat::TextUnderlineColor;
456 else if (key == QTextFormat::OldFontFamily)
457 key = QTextFormat::FontFamilies;
458 fmt.d->insertProperty(key, value: it.value());
459 }
460
461 return stream;
462}
463
464Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QTextCharFormat &fmt)
465{
466 return stream << static_cast<const QTextFormat &>(fmt);
467}
468
469Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QTextCharFormat &fmt)
470{
471 return stream >> static_cast<QTextFormat &>(fmt);
472}
473
474Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QTextBlockFormat &fmt)
475{
476 return stream << static_cast<const QTextFormat &>(fmt);
477}
478
479Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QTextBlockFormat &fmt)
480{
481 return stream >> static_cast<QTextFormat &>(fmt);
482}
483
484Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QTextListFormat &fmt)
485{
486 return stream << static_cast<const QTextFormat &>(fmt);
487}
488
489Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QTextListFormat &fmt)
490{
491 return stream >> static_cast<QTextFormat &>(fmt);
492}
493
494Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QTextFrameFormat &fmt)
495{
496 return stream << static_cast<const QTextFormat &>(fmt);
497}
498
499Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QTextFrameFormat &fmt)
500{
501 return stream >> static_cast<QTextFormat &>(fmt);
502}
503
504Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QTextTableCellFormat &fmt)
505{
506 return stream << static_cast<const QTextFormat &>(fmt);
507}
508
509Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QTextTableCellFormat &fmt)
510{
511 return stream >> static_cast<QTextFormat &>(fmt);
512}
513#endif // QT_NO_DATASTREAM
514
515/*!
516 \class QTextFormat
517 \reentrant
518
519 \brief The QTextFormat class provides formatting information for a
520 QTextDocument.
521 \inmodule QtGui
522
523 \ingroup richtext-processing
524 \ingroup shared
525
526 A QTextFormat is a generic class used for describing the format of
527 parts of a QTextDocument. The derived classes QTextCharFormat,
528 QTextBlockFormat, QTextListFormat, and QTextTableFormat are usually
529 more useful, and describe the formatting that is applied to
530 specific parts of the document.
531
532 A format has a \c FormatType which specifies the kinds of text item it
533 can format; e.g. a block of text, a list, a table, etc. A format
534 also has various properties (some specific to particular format
535 types), as described by the Property enum. Every property has a
536 corresponding Property.
537
538 The format type is given by type(), and the format can be tested
539 with isCharFormat(), isBlockFormat(), isListFormat(),
540 isTableFormat(), isFrameFormat(), and isImageFormat(). If the
541 type is determined, it can be retrieved with toCharFormat(),
542 toBlockFormat(), toListFormat(), toTableFormat(), toFrameFormat(),
543 and toImageFormat().
544
545 A format's properties can be set with the setProperty() functions,
546 and retrieved with boolProperty(), intProperty(), doubleProperty(),
547 and stringProperty() as appropriate. All the property IDs used in
548 the format can be retrieved with allPropertyIds(). One format can
549 be merged into another using merge().
550
551 A format's object index can be set with setObjectIndex(), and
552 retrieved with objectIndex(). These methods can be used to
553 associate the format with a QTextObject. It is used to represent
554 lists, frames, and tables inside the document.
555
556 \sa {Rich Text Processing}
557*/
558
559/*!
560 \enum QTextFormat::FormatType
561
562 This enum describes the text item a QTextFormat object is formatting.
563
564 \value InvalidFormat An invalid format as created by the default
565 constructor
566 \value BlockFormat The object formats a text block
567 \value CharFormat The object formats a single character
568 \value ListFormat The object formats a list
569 \value FrameFormat The object formats a frame
570
571 \value UserFormat
572
573 \sa QTextCharFormat, QTextBlockFormat, QTextListFormat,
574 QTextTableFormat, type()
575*/
576
577/*!
578 \enum QTextFormat::Property
579
580 This enum describes the different properties a format can have.
581
582 \value ObjectIndex The index of the formatted object. See objectIndex().
583
584 Paragraph and character properties
585
586 \value CssFloat How a frame is located relative to the surrounding text
587 \value LayoutDirection The layout direction of the text in the document
588 (Qt::LayoutDirection).
589
590 \value OutlinePen
591 \value ForegroundBrush
592 \value BackgroundBrush
593 \value BackgroundImageUrl
594
595 Paragraph properties
596
597 \value BlockAlignment
598 \value BlockTopMargin
599 \value BlockBottomMargin
600 \value BlockLeftMargin
601 \value BlockRightMargin
602 \value TextIndent
603 \value TabPositions Specifies the tab positions. The tab positions are structs of QTextOption::Tab which are stored in
604 a QList (internally, in a QList<QVariant>).
605 \value BlockIndent
606 \value LineHeight
607 \value LineHeightType
608 \value BlockNonBreakableLines
609 \value BlockTrailingHorizontalRulerWidth The width of a horizontal ruler element.
610 \value HeadingLevel The level of a heading, for example 1 corresponds to an HTML H1 tag; otherwise 0.
611 This enum value has been added in Qt 5.12.
612 \value BlockCodeFence The character that was used in the "fences" around a Markdown code block.
613 If the code block was indented rather than fenced, the block should not have this property.
614 This enum value has been added in Qt 5.14.
615
616 \value BlockQuoteLevel The depth of nested quoting on this block: 1 means the block is a top-level block quote.
617 Blocks that are not block quotes should not have this property.
618 This enum value has been added in Qt 5.14.
619 \value BlockCodeLanguage The programming language in a preformatted or code block.
620 Blocks that do not contain code should not have this property.
621 This enum value has been added in Qt 5.14.
622 \value BlockMarker The \l{QTextBlockFormat::MarkerType}{type of adornment} to be shown alongside the block.
623 This enum value has been added in Qt 5.14.
624
625 Character properties
626
627 \value FontFamily e{This property has been deprecated.} Use QTextFormat::FontFamilies instead.
628 \omitvalue OldFontFamily
629 \value FontFamilies
630 \value FontStyleName
631 \value FontPointSize
632 \value FontPixelSize
633 \value FontSizeAdjustment Specifies the change in size given to the fontsize already set using
634 FontPointSize or FontPixelSize.
635 \value FontFixedPitch
636 \omitvalue FontSizeIncrement
637 \value FontWeight
638 \value FontItalic
639 \value FontUnderline \e{This property has been deprecated.} Use QTextFormat::TextUnderlineStyle instead.
640 \value FontOverline
641 \value FontStrikeOut
642 \value FontCapitalization Specifies the capitalization type that is to be applied to the text.
643 \value FontLetterSpacingType Specifies the meaning of the FontLetterSpacing property. The default
644 is QFont::PercentageSpacing.
645 \value FontLetterSpacing Changes the default spacing between individual letters in the font. The value is
646 specified as a percentage or absolute value, depending on FontLetterSpacingType.
647 The default value is 100%.
648 \value FontWordSpacing Changes the default spacing between individual words. A positive value increases the word spacing
649 by the corresponding pixels; a negative value decreases the spacing.
650 \value FontStretch Corresponds to the QFont::Stretch property
651 \value FontStyleHint Corresponds to the QFont::StyleHint property
652 \value FontStyleStrategy Corresponds to the QFont::StyleStrategy property
653 \value FontKerning Specifies whether the font has kerning turned on.
654 \value FontHintingPreference Controls the use of hinting according to values
655 of the QFont::HintingPreference enum.
656
657 \omitvalue FirstFontProperty
658 \omitvalue LastFontProperty
659
660 \value TextUnderlineColor Specifies the color to draw underlines, overlines and strikeouts.
661 \value TextVerticalAlignment Specifies the type of text vertical alignment according to
662 the values of the QTextCharFormat::VerticalAlignment enum.
663 \value TextOutline Specifies a \l QPen used to draw the text outline.
664 \value TextUnderlineStyle Specifies the style of text underline according to
665 the values of the QTextCharFormat::UnderlineStyle enum.
666 \value TextToolTip Specifies the (optional) tool tip to be displayed for a fragment of text.
667 \value TextSuperScriptBaseline Specifies the baseline (in % of height) of superscript texts.
668 \value TextSubScriptBaseline Specifies the baseline (in % of height) of subscript texts.
669 \value TextBaselineOffset Specifies the baseline (in % of height) of text. A positive value moves up the text,
670 by the corresponding %; a negative value moves it down.
671
672 \value IsAnchor
673 \value AnchorHref
674 \value AnchorName
675 \omitvalue OldFontLetterSpacingType
676 \omitvalue OldFontStretch
677 \omitvalue OldTextUnderlineColor
678 \value ObjectType
679
680 List properties
681
682 \value ListStyle Specifies the style used for the items in a list,
683 described by values of the QTextListFormat::Style enum.
684 \value ListIndent Specifies the amount of indentation used for a list.
685 \value ListNumberPrefix Defines the text which is prepended to item numbers in
686 numeric lists.
687 \value ListNumberSuffix Defines the text which is appended to item numbers in
688 numeric lists.
689 \value [since 6.6] ListStart
690 Defines the first value of a list.
691
692 Table and frame properties
693
694 \value FrameBorder
695 \value FrameBorderBrush
696 \value FrameBorderStyle See the \l{QTextFrameFormat::BorderStyle}{BorderStyle} enum.
697 \value FrameBottomMargin
698 \value FrameHeight
699 \value FrameLeftMargin
700 \value FrameMargin
701 \value FramePadding
702 \value FrameRightMargin
703 \value FrameTopMargin
704 \value FrameWidth
705 \value TableCellSpacing
706 \value TableCellPadding
707 \value TableColumns
708 \value TableColumnWidthConstraints
709 \value TableHeaderRowCount
710 \value TableBorderCollapse Specifies the \l QTextTableFormat::borderCollapse property.
711
712 Table cell properties
713
714 \value TableCellRowSpan
715 \value TableCellColumnSpan
716 \value TableCellLeftPadding
717 \value TableCellRightPadding
718 \value TableCellTopPadding
719 \value TableCellBottomPadding
720
721 Table cell properties intended for use with \l QTextTableFormat::borderCollapse enabled
722
723 \value TableCellTopBorder
724 \value TableCellBottomBorder
725 \value TableCellLeftBorder
726 \value TableCellRightBorder
727
728 \value TableCellTopBorderStyle
729 \value TableCellBottomBorderStyle
730 \value TableCellLeftBorderStyle
731 \value TableCellRightBorderStyle
732
733 \value TableCellTopBorderBrush
734 \value TableCellBottomBorderBrush
735 \value TableCellLeftBorderBrush
736 \value TableCellRightBorderBrush
737
738 Image properties
739
740 \value ImageName The filename or source of the image.
741 \value ImageTitle The title attribute of an HTML image tag, or
742 the quoted string that comes after the URL in a Markdown image link.
743 This enum value has been added in Qt 5.14.
744 \value ImageAltText The alt attribute of an HTML image tag, or
745 the image description in a Markdown image link.
746 This enum value has been added in Qt 5.14.
747 \value ImageWidth
748 \value ImageHeight
749 \value ImageQuality
750 \value ImageMaxWidth This enum value has been added in Qt 6.8.
751
752 Selection properties
753
754 \value FullWidthSelection When set on the characterFormat of a selection,
755 the whole width of the text will be shown selected.
756
757 Page break properties
758
759 \value PageBreakPolicy Specifies how pages are broken. See the PageBreakFlag enum.
760
761 \value UserProperty
762
763 \sa property(), setProperty()
764*/
765
766/*!
767 \enum QTextFormat::ObjectTypes
768
769 This enum describes what kind of QTextObject this format is associated with.
770
771 \value NoObject
772 \value ImageObject
773 \value TableObject
774 \value TableCellObject
775 \value UserObject The first object that can be used for application-specific purposes.
776
777 \sa QTextObject, QTextTable, QTextObject::format()
778*/
779
780/*!
781 \enum QTextFormat::PageBreakFlag
782 \since 4.2
783
784 This enum describes how page breaking is performed when printing. It maps to the
785 corresponding css properties.
786
787 \value PageBreak_Auto The page break is determined automatically depending on the
788 available space on the current page
789 \value PageBreak_AlwaysBefore The page is always broken before the paragraph/table
790 \value PageBreak_AlwaysAfter A new page is always started after the paragraph/table
791
792 \sa QTextBlockFormat::pageBreakPolicy(), QTextFrameFormat::pageBreakPolicy(),
793 PageBreakPolicy
794*/
795
796/*!
797 \fn bool QTextFormat::isValid() const
798
799 Returns \c true if the format is valid (i.e. is not
800 InvalidFormat); otherwise returns \c false.
801*/
802
803/*!
804 \fn bool QTextFormat::isEmpty() const
805 \since 5.3
806
807 Returns true if the format does not store any properties; false otherwise.
808
809 \sa propertyCount(), properties()
810*/
811
812/*!
813 \fn bool QTextFormat::isCharFormat() const
814
815 Returns \c true if this text format is a \c CharFormat; otherwise
816 returns \c false.
817*/
818
819
820/*!
821 \fn bool QTextFormat::isBlockFormat() const
822
823 Returns \c true if this text format is a \c BlockFormat; otherwise
824 returns \c false.
825*/
826
827
828/*!
829 \fn bool QTextFormat::isListFormat() const
830
831 Returns \c true if this text format is a \c ListFormat; otherwise
832 returns \c false.
833*/
834
835
836/*!
837 \fn bool QTextFormat::isTableFormat() const
838
839 Returns \c true if this text format is a \c TableFormat; otherwise
840 returns \c false.
841*/
842
843
844/*!
845 \fn bool QTextFormat::isFrameFormat() const
846
847 Returns \c true if this text format is a \c FrameFormat; otherwise
848 returns \c false.
849*/
850
851
852/*!
853 \fn bool QTextFormat::isImageFormat() const
854
855 Returns \c true if this text format is an image format; otherwise
856 returns \c false.
857*/
858
859
860/*!
861 \fn bool QTextFormat::isTableCellFormat() const
862 \since 4.4
863
864 Returns \c true if this text format is a \c TableCellFormat; otherwise
865 returns \c false.
866*/
867
868
869/*!
870 Creates a new text format with an \c InvalidFormat.
871
872 \sa FormatType
873*/
874QTextFormat::QTextFormat()
875 : format_type(InvalidFormat)
876{
877}
878
879/*!
880 Creates a new text format of the given \a type.
881
882 \sa FormatType
883*/
884QTextFormat::QTextFormat(int type)
885 : format_type(type)
886{
887}
888
889
890/*!
891 \fn QTextFormat::QTextFormat(const QTextFormat &other)
892
893 Creates a new text format with the same attributes as the \a other
894 text format.
895*/
896QTextFormat::QTextFormat(const QTextFormat &rhs)
897 : d(rhs.d), format_type(rhs.format_type)
898{
899}
900
901/*!
902 \fn QTextFormat &QTextFormat::operator=(const QTextFormat &other)
903
904 Assigns the \a other text format to this text format, and returns a
905 reference to this text format.
906*/
907QTextFormat &QTextFormat::operator=(const QTextFormat &rhs)
908{
909 d = rhs.d;
910 format_type = rhs.format_type;
911 return *this;
912}
913
914/*!
915 \fn void QTextFormat::swap(QTextFormat &other)
916 \since 5.0
917 \memberswap{text format}
918*/
919
920/*!
921 Destroys this text format.
922*/
923QTextFormat::~QTextFormat()
924{
925}
926
927
928/*!
929 Returns the text format as a QVariant
930*/
931QTextFormat::operator QVariant() const
932{
933 return QVariant::fromValue(value: *this);
934}
935
936/*!
937 Merges the \a other format with this format; where there are
938 conflicts the \a other format takes precedence.
939*/
940void QTextFormat::merge(const QTextFormat &other)
941{
942 if (format_type != other.format_type)
943 return;
944
945 if (!d) {
946 d = other.d;
947 return;
948 }
949
950 if (!other.d)
951 return;
952
953 QTextFormatPrivate *p = d.data();
954
955 const QList<QT_PREPEND_NAMESPACE(Property)> &otherProps = other.d.constData()->props;
956 p->props.reserve(asize: p->props.size() + otherProps.size());
957 for (int i = 0; i < otherProps.size(); ++i) {
958 const QT_PREPEND_NAMESPACE(Property) &prop = otherProps.at(i);
959 if (prop.value.isValid()) {
960 p->insertProperty(key: prop.key, value: prop.value);
961 } else {
962 p->clearProperty(key: prop.key);
963 }
964 }
965}
966
967/*!
968 Returns the type of this format.
969
970 \sa FormatType
971*/
972int QTextFormat::type() const
973{
974 return format_type;
975}
976
977/*!
978 Returns this format as a block format.
979*/
980QTextBlockFormat QTextFormat::toBlockFormat() const
981{
982 return QTextBlockFormat(*this);
983}
984
985/*!
986 Returns this format as a character format.
987*/
988QTextCharFormat QTextFormat::toCharFormat() const
989{
990 return QTextCharFormat(*this);
991}
992
993/*!
994 Returns this format as a list format.
995*/
996QTextListFormat QTextFormat::toListFormat() const
997{
998 return QTextListFormat(*this);
999}
1000
1001/*!
1002 Returns this format as a table format.
1003*/
1004QTextTableFormat QTextFormat::toTableFormat() const
1005{
1006 return QTextTableFormat(*this);
1007}
1008
1009/*!
1010 Returns this format as a frame format.
1011*/
1012QTextFrameFormat QTextFormat::toFrameFormat() const
1013{
1014 return QTextFrameFormat(*this);
1015}
1016
1017/*!
1018 Returns this format as an image format.
1019*/
1020QTextImageFormat QTextFormat::toImageFormat() const
1021{
1022 return QTextImageFormat(*this);
1023}
1024
1025/*!
1026 \since 4.4
1027
1028 Returns this format as a table cell format.
1029*/
1030QTextTableCellFormat QTextFormat::toTableCellFormat() const
1031{
1032 return QTextTableCellFormat(*this);
1033}
1034
1035/*!
1036 Returns the value of the property specified by \a propertyId. If the
1037 property isn't of QTextFormat::Bool type, false is returned instead.
1038
1039 \sa setProperty(), intProperty(), doubleProperty(), stringProperty(), colorProperty(),
1040 lengthProperty(), lengthVectorProperty(), Property
1041*/
1042bool QTextFormat::boolProperty(int propertyId) const
1043{
1044 if (!d)
1045 return false;
1046 const QVariant prop = d->property(key: propertyId);
1047 if (prop.userType() != QMetaType::Bool)
1048 return false;
1049 return prop.toBool();
1050}
1051
1052/*!
1053 Returns the value of the property specified by \a propertyId. If the
1054 property is not of QTextFormat::Integer type, 0 is returned instead.
1055
1056 \sa setProperty(), boolProperty(), doubleProperty(), stringProperty(), colorProperty(),
1057 lengthProperty(), lengthVectorProperty(), Property
1058*/
1059int QTextFormat::intProperty(int propertyId) const
1060{
1061 // required, since the default layout direction has to be LayoutDirectionAuto, which is not integer 0
1062 int def = (propertyId == QTextFormat::LayoutDirection) ? int(Qt::LayoutDirectionAuto) : 0;
1063
1064 if (!d)
1065 return def;
1066 const QVariant prop = d->property(key: propertyId);
1067 if (prop.userType() != QMetaType::Int)
1068 return def;
1069 return prop.toInt();
1070}
1071
1072/*!
1073 Returns the value of the property specified by \a propertyId. If the
1074 property isn't of QMetaType::Double or QMetaType::Float type, 0 is
1075 returned instead.
1076
1077 \sa setProperty(), boolProperty(), intProperty(), stringProperty(), colorProperty(),
1078 lengthProperty(), lengthVectorProperty(), Property
1079*/
1080qreal QTextFormat::doubleProperty(int propertyId) const
1081{
1082 if (!d)
1083 return 0.;
1084 const QVariant prop = d->property(key: propertyId);
1085 if (prop.userType() != QMetaType::Double && prop.userType() != QMetaType::Float)
1086 return 0.;
1087 return qvariant_cast<qreal>(v: prop);
1088}
1089
1090/*!
1091 Returns the value of the property given by \a propertyId; if the
1092 property isn't of QMetaType::QString type, an empty string is
1093 returned instead.
1094
1095 \sa setProperty(), boolProperty(), intProperty(), doubleProperty(), colorProperty(),
1096 lengthProperty(), lengthVectorProperty(), Property
1097*/
1098QString QTextFormat::stringProperty(int propertyId) const
1099{
1100 if (!d)
1101 return QString();
1102 const QVariant prop = d->property(key: propertyId);
1103 if (prop.userType() != QMetaType::QString)
1104 return QString();
1105 return prop.toString();
1106}
1107
1108/*!
1109 Returns the value of the property given by \a propertyId; if the
1110 property isn't of QMetaType::QColor type, an invalid color is
1111 returned instead.
1112
1113 \sa setProperty(), boolProperty(), intProperty(), doubleProperty(),
1114 stringProperty(), lengthProperty(), lengthVectorProperty(), Property
1115*/
1116QColor QTextFormat::colorProperty(int propertyId) const
1117{
1118 if (!d)
1119 return QColor();
1120 const QVariant prop = d->property(key: propertyId);
1121 if (prop.userType() != QMetaType::QColor)
1122 return QColor();
1123 return qvariant_cast<QColor>(v: prop);
1124}
1125
1126/*!
1127 Returns the value of the property given by \a propertyId; if the
1128 property isn't of QMetaType::QPen type, Qt::NoPen is
1129 returned instead.
1130
1131 \sa setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(),
1132 lengthProperty(), lengthVectorProperty(), Property
1133*/
1134QPen QTextFormat::penProperty(int propertyId) const
1135{
1136 if (!d)
1137 return QPen(Qt::NoPen);
1138 const QVariant prop = d->property(key: propertyId);
1139 if (prop.userType() != QMetaType::QPen)
1140 return QPen(Qt::NoPen);
1141 return qvariant_cast<QPen>(v: prop);
1142}
1143
1144/*!
1145 Returns the value of the property given by \a propertyId; if the
1146 property isn't of QMetaType::QBrush type, Qt::NoBrush is
1147 returned instead.
1148
1149 \sa setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(),
1150 lengthProperty(), lengthVectorProperty(), Property
1151*/
1152QBrush QTextFormat::brushProperty(int propertyId) const
1153{
1154 if (!d)
1155 return QBrush(Qt::NoBrush);
1156 const QVariant prop = d->property(key: propertyId);
1157 if (prop.userType() != QMetaType::QBrush)
1158 return QBrush(Qt::NoBrush);
1159 return qvariant_cast<QBrush>(v: prop);
1160}
1161
1162/*!
1163 Returns the value of the property given by \a propertyId.
1164
1165 \sa setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(),
1166 colorProperty(), lengthVectorProperty(), Property
1167*/
1168QTextLength QTextFormat::lengthProperty(int propertyId) const
1169{
1170 if (!d)
1171 return QTextLength();
1172 return qvariant_cast<QTextLength>(v: d->property(key: propertyId));
1173}
1174
1175/*!
1176 Returns the value of the property given by \a propertyId. If the
1177 property isn't of QTextFormat::LengthVector type, an empty
1178 list is returned instead.
1179
1180 \sa setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(),
1181 colorProperty(), lengthProperty(), Property
1182*/
1183QList<QTextLength> QTextFormat::lengthVectorProperty(int propertyId) const
1184{
1185 QList<QTextLength> list;
1186 if (!d)
1187 return list;
1188 const QVariant prop = d->property(key: propertyId);
1189 if (prop.userType() != QMetaType::QVariantList)
1190 return list;
1191
1192 const QList<QVariant> propertyList = prop.toList();
1193 for (const auto &var : propertyList) {
1194 if (var.userType() == QMetaType::QTextLength)
1195 list.append(t: qvariant_cast<QTextLength>(v: var));
1196 }
1197
1198 return list;
1199}
1200
1201/*!
1202 Returns the property specified by the given \a propertyId.
1203
1204 \sa Property
1205*/
1206QVariant QTextFormat::property(int propertyId) const
1207{
1208 return d ? d->property(key: propertyId) : QVariant();
1209}
1210
1211/*!
1212 Sets the property specified by the \a propertyId to the given \a value.
1213
1214 \sa Property
1215*/
1216void QTextFormat::setProperty(int propertyId, const QVariant &value)
1217{
1218 if (!d)
1219 d = new QTextFormatPrivate;
1220
1221 d->insertProperty(key: propertyId, value);
1222}
1223
1224/*!
1225 Sets the value of the property given by \a propertyId to \a value.
1226
1227 \sa lengthVectorProperty(), Property
1228*/
1229void QTextFormat::setProperty(int propertyId, const QList<QTextLength> &value)
1230{
1231 if (!d)
1232 d = new QTextFormatPrivate;
1233 QVariantList list;
1234 const int numValues = value.size();
1235 list.reserve(asize: numValues);
1236 for (int i = 0; i < numValues; ++i)
1237 list << value.at(i);
1238 d->insertProperty(key: propertyId, value: list);
1239}
1240
1241/*!
1242 Clears the value of the property given by \a propertyId
1243
1244 \sa Property
1245*/
1246void QTextFormat::clearProperty(int propertyId)
1247{
1248 if (!d)
1249 return;
1250 d->clearProperty(key: propertyId);
1251}
1252
1253
1254/*!
1255 \fn void QTextFormat::setObjectType(int type)
1256
1257 Sets the text format's object type to \a type.
1258
1259 \sa ObjectTypes, objectType()
1260*/
1261
1262
1263/*!
1264 \fn int QTextFormat::objectType() const
1265
1266 Returns the text format's object type.
1267
1268 \sa ObjectTypes, setObjectType()
1269*/
1270
1271
1272/*!
1273 Returns the index of the format object, or -1 if the format object is invalid.
1274
1275 \sa setObjectIndex()
1276*/
1277int QTextFormat::objectIndex() const
1278{
1279 if (!d)
1280 return -1;
1281 const QVariant prop = d->property(key: ObjectIndex);
1282 if (prop.userType() != QMetaType::Int) // ####
1283 return -1;
1284 return prop.toInt();
1285}
1286
1287/*!
1288 \fn void QTextFormat::setObjectIndex(int index)
1289
1290 Sets the format object's object \a index.
1291
1292 \sa objectIndex()
1293*/
1294void QTextFormat::setObjectIndex(int o)
1295{
1296 if (o == -1) {
1297 if (d.constData())
1298 d->clearProperty(key: ObjectIndex);
1299 } else {
1300 if (!d.constData())
1301 d = new QTextFormatPrivate;
1302 // ### type
1303 d->insertProperty(key: ObjectIndex, value: o);
1304 }
1305}
1306
1307/*!
1308 Returns \c true if the text format has a property with the given \a
1309 propertyId; otherwise returns \c false.
1310
1311 \sa properties(), Property
1312*/
1313bool QTextFormat::hasProperty(int propertyId) const
1314{
1315 return d ? d->hasProperty(key: propertyId) : false;
1316}
1317
1318/*
1319 Returns the property type for the given \a propertyId.
1320
1321 \sa hasProperty(), allPropertyIds(), Property
1322*/
1323
1324/*!
1325 Returns a map with all properties of this text format.
1326*/
1327QMap<int, QVariant> QTextFormat::properties() const
1328{
1329 QMap<int, QVariant> map;
1330 if (d) {
1331 for (int i = 0; i < d->props.size(); ++i)
1332 map.insert(key: d->props.at(i).key, value: d->props.at(i).value);
1333 }
1334 return map;
1335}
1336
1337/*!
1338 \since 4.3
1339 Returns the number of properties stored in the format.
1340*/
1341int QTextFormat::propertyCount() const
1342{
1343 return d ? d->props.size() : 0;
1344}
1345
1346/*!
1347 \fn bool QTextFormat::operator!=(const QTextFormat &other) const
1348
1349 Returns \c true if this text format is different from the \a other text
1350 format.
1351*/
1352
1353
1354/*!
1355 \fn bool QTextFormat::operator==(const QTextFormat &other) const
1356
1357 Returns \c true if this text format is the same as the \a other text
1358 format.
1359*/
1360bool QTextFormat::operator==(const QTextFormat &rhs) const
1361{
1362 if (format_type != rhs.format_type)
1363 return false;
1364
1365 if (d == rhs.d)
1366 return true;
1367
1368 if (d && d->props.isEmpty() && !rhs.d)
1369 return true;
1370
1371 if (!d && rhs.d && rhs.d->props.isEmpty())
1372 return true;
1373
1374 if (!d || !rhs.d)
1375 return false;
1376
1377 return *d == *rhs.d;
1378}
1379
1380/*!
1381 \class QTextCharFormat
1382 \reentrant
1383
1384 \brief The QTextCharFormat class provides formatting information for
1385 characters in a QTextDocument.
1386 \inmodule QtGui
1387
1388 \ingroup richtext-processing
1389 \ingroup shared
1390
1391 The character format of text in a document specifies the visual properties
1392 of the text, as well as information about its role in a hypertext document.
1393
1394 The font used can be set by supplying a font to the setFont() function, and
1395 each aspect of its appearance can be adjusted to give the desired effect.
1396 setFontFamilies() and setFontPointSize() define the font's family (e.g. Times)
1397 and printed size; setFontWeight() and setFontItalic() provide control over
1398 the style of the font. setFontUnderline(), setFontOverline(),
1399 setFontStrikeOut(), and setFontFixedPitch() provide additional effects for
1400 text.
1401
1402 The color is set with setForeground(). If the text is intended to be used
1403 as an anchor (for hyperlinks), this can be enabled with setAnchor(). The
1404 setAnchorHref() and setAnchorNames() functions are used to specify the
1405 information about the hyperlink's destination and the anchor's name.
1406
1407 \sa QTextFormat, QTextBlockFormat, QTextTableFormat, QTextListFormat
1408*/
1409
1410/*!
1411 \enum QTextCharFormat::VerticalAlignment
1412
1413 This enum describes the ways that adjacent characters can be vertically
1414 aligned.
1415
1416 \value AlignNormal Adjacent characters are positioned in the standard
1417 way for text in the writing system in use.
1418 \value AlignSuperScript Characters are placed above the base line for
1419 normal text.
1420 \value AlignSubScript Characters are placed below the base line for
1421 normal text.
1422 \value AlignMiddle The center of the object is vertically aligned with the
1423 base line. Currently, this is only implemented for
1424 inline objects.
1425 \value AlignBottom The bottom edge of the object is vertically aligned with
1426 the base line.
1427 \value AlignTop The top edge of the object is vertically aligned with
1428 the base line.
1429 \value AlignBaseline The base lines of the characters are aligned.
1430*/
1431
1432/*!
1433 \enum QTextCharFormat::UnderlineStyle
1434
1435 This enum describes the different ways drawing underlined text.
1436
1437 \value NoUnderline Text is draw without any underlining decoration.
1438 \value SingleUnderline A line is drawn using Qt::SolidLine.
1439 \value DashUnderline Dashes are drawn using Qt::DashLine.
1440 \value DotLine Dots are drawn using Qt::DotLine;
1441 \value DashDotLine Dashes and dots are drawn using Qt::DashDotLine.
1442 \value DashDotDotLine Underlines draw drawn using Qt::DashDotDotLine.
1443 \value WaveUnderline The text is underlined using a wave shaped line.
1444 \value SpellCheckUnderline The underline is drawn depending on the SpellCheckUnderlineStyle
1445 theme hint of QPlatformTheme. By default this is mapped to
1446 WaveUnderline, on \macos it is mapped to DotLine.
1447
1448 \sa Qt::PenStyle
1449*/
1450
1451/*!
1452 \fn QTextCharFormat::QTextCharFormat()
1453
1454 Constructs a new character format object.
1455*/
1456QTextCharFormat::QTextCharFormat() : QTextFormat(CharFormat) {}
1457
1458/*!
1459 \internal
1460 \fn QTextCharFormat::QTextCharFormat(const QTextFormat &other)
1461
1462 Creates a new character format with the same attributes as the \a given
1463 text format.
1464*/
1465QTextCharFormat::QTextCharFormat(const QTextFormat &fmt)
1466 : QTextFormat(fmt)
1467{
1468}
1469
1470/*!
1471 \fn bool QTextCharFormat::isValid() const
1472
1473 Returns \c true if this character format is valid; otherwise returns
1474 false.
1475*/
1476
1477
1478/*!
1479 \fn void QTextCharFormat::setFontFamily(const QString &family)
1480 \deprecated [6.1] Use setFontFamilies() instead.
1481
1482 Sets the text format's font \a family.
1483
1484 \sa setFont()
1485*/
1486
1487
1488/*!
1489 \fn QString QTextCharFormat::fontFamily() const
1490 \deprecated [6.1] Use fontFamilies() instead.
1491
1492 Returns the text format's font family.
1493
1494 \sa font()
1495*/
1496
1497/*!
1498 \fn void QTextCharFormat::setFontFamilies(const QStringList &families)
1499 \since 5.13
1500
1501 Sets the text format's font \a families.
1502
1503 \sa setFont()
1504*/
1505
1506#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
1507/*!
1508 \fn QVariant QTextCharFormat::fontFamilies() const
1509 \since 5.13
1510
1511 Returns the text format's font families.
1512
1513 \note This function returns a QVariant for historical reasons. It will be
1514 corrected to return QStringList in Qt 7. The variant contains a QStringList
1515 object, which can be extracted by calling \c{toStringList()} on it.
1516
1517 \sa font()
1518*/
1519#else
1520/* // Qt 7 documents this function
1521 \fn QStringList QTextCharFormat::fontFamilies() const
1522 \since 5.13
1523
1524 Returns the text format's font families.
1525
1526 \sa font()
1527*/
1528#endif
1529
1530/*!
1531 \fn void QTextCharFormat::setFontStyleName(const QString &styleName)
1532 \since 5.13
1533
1534 Sets the text format's font \a styleName.
1535
1536 \sa setFont(), QFont::setStyleName()
1537*/
1538
1539#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
1540/*!
1541 \fn QVariant QTextCharFormat::fontStyleName() const
1542 \since 5.13
1543
1544 Returns the text format's font style name.
1545
1546 \note This function returns a QVariant for historical reasons. It will be
1547 corrected to return QStringList in Qt 7. The variant contains a QStringList
1548 object, which can be extracted by calling \c{toStringList()} on it.
1549
1550 \sa font(), QFont::styleName()
1551*/
1552#else
1553/* // Qt 7 documents this function
1554 \fn QStringList QTextCharFormat::fontStyleName() const
1555 \since 5.13
1556
1557 Returns the text format's font style name.
1558
1559 \sa font(), QFont::styleName()
1560*/
1561#endif
1562
1563/*!
1564 \fn void QTextCharFormat::setFontPointSize(qreal size)
1565
1566 Sets the text format's font \a size.
1567
1568 \sa setFont()
1569*/
1570
1571
1572/*!
1573 \fn qreal QTextCharFormat::fontPointSize() const
1574
1575 Returns the font size used to display text in this format.
1576
1577 \sa font()
1578*/
1579
1580
1581/*!
1582 \fn void QTextCharFormat::setFontWeight(int weight)
1583
1584 Sets the text format's font weight to \a weight.
1585
1586 \sa setFont(), QFont::Weight
1587*/
1588
1589
1590/*!
1591 \fn int QTextCharFormat::fontWeight() const
1592
1593 Returns the text format's font weight.
1594
1595 \sa font(), QFont::Weight
1596*/
1597
1598
1599/*!
1600 \fn void QTextCharFormat::setFontItalic(bool italic)
1601
1602 If \a italic is true, sets the text format's font to be italic; otherwise
1603 the font will be non-italic.
1604
1605 \sa setFont()
1606*/
1607
1608
1609/*!
1610 \fn bool QTextCharFormat::fontItalic() const
1611
1612 Returns \c true if the text format's font is italic; otherwise
1613 returns \c false.
1614
1615 \sa font()
1616*/
1617
1618
1619/*!
1620 \fn void QTextCharFormat::setFontUnderline(bool underline)
1621
1622 If \a underline is true, sets the text format's font to be underlined;
1623 otherwise it is displayed non-underlined.
1624
1625 \sa setFont()
1626*/
1627
1628
1629/*!
1630 \fn bool QTextCharFormat::fontUnderline() const
1631
1632 Returns \c true if the text format's font is underlined; otherwise
1633 returns \c false.
1634
1635 \sa font()
1636*/
1637bool QTextCharFormat::fontUnderline() const
1638{
1639 if (hasProperty(propertyId: TextUnderlineStyle))
1640 return underlineStyle() == SingleUnderline;
1641 return boolProperty(propertyId: FontUnderline);
1642}
1643
1644/*!
1645 \fn UnderlineStyle QTextCharFormat::underlineStyle() const
1646 \since 4.2
1647
1648 Returns the style of underlining the text.
1649*/
1650
1651/*!
1652 \fn void QTextCharFormat::setUnderlineStyle(UnderlineStyle style)
1653 \since 4.2
1654
1655 Sets the style of underlining the text to \a style.
1656*/
1657void QTextCharFormat::setUnderlineStyle(UnderlineStyle style)
1658{
1659 setProperty(propertyId: TextUnderlineStyle, value: style);
1660 // for compatibility
1661 setProperty(propertyId: FontUnderline, value: style == SingleUnderline);
1662}
1663
1664/*!
1665 \fn void QTextCharFormat::setFontOverline(bool overline)
1666
1667 If \a overline is true, sets the text format's font to be overlined;
1668 otherwise the font is displayed non-overlined.
1669
1670 \sa setFont()
1671*/
1672
1673
1674/*!
1675 \fn bool QTextCharFormat::fontOverline() const
1676
1677 Returns \c true if the text format's font is overlined; otherwise
1678 returns \c false.
1679
1680 \sa font()
1681*/
1682
1683
1684/*!
1685 \fn void QTextCharFormat::setFontStrikeOut(bool strikeOut)
1686
1687 If \a strikeOut is true, sets the text format's font with strike-out
1688 enabled (with a horizontal line through it); otherwise it is displayed
1689 without strikeout.
1690
1691 \sa setFont()
1692*/
1693
1694
1695/*!
1696 \fn bool QTextCharFormat::fontStrikeOut() const
1697
1698 Returns \c true if the text format's font is struck out (has a horizontal line
1699 drawn through it); otherwise returns \c false.
1700
1701 \sa font()
1702*/
1703
1704
1705/*!
1706 \since 4.5
1707 \fn void QTextCharFormat::setFontStyleHint(QFont::StyleHint hint, QFont::StyleStrategy strategy)
1708
1709 Sets the font style \a hint and \a strategy.
1710
1711 Qt does not support style hints on X11 since this information is not provided by the window system.
1712
1713 \sa setFont()
1714 \sa QFont::setStyleHint()
1715*/
1716
1717
1718/*!
1719 \since 4.5
1720 \fn void QTextCharFormat::setFontStyleStrategy(QFont::StyleStrategy strategy)
1721
1722 Sets the font style \a strategy.
1723
1724 \sa setFont()
1725 \sa QFont::setStyleStrategy()
1726*/
1727
1728
1729/*!
1730 \since 4.5
1731 \fn void QTextCharFormat::setFontKerning(bool enable)
1732 Enables kerning for this font if \a enable is true; otherwise disables it.
1733
1734 When kerning is enabled, glyph metrics do not add up anymore, even for
1735 Latin text. In other words, the assumption that width('a') + width('b')
1736 is equal to width("ab") is not neccesairly true.
1737
1738 \sa setFont()
1739*/
1740
1741
1742/*!
1743 \fn QTextCharFormat::StyleHint QTextCharFormat::fontStyleHint() const
1744 \since 4.5
1745
1746 Returns the font style hint.
1747
1748 \sa setFontStyleHint(), font()
1749*/
1750
1751
1752/*!
1753 \since 4.5
1754 \fn QTextCharFormat::StyleStrategy QTextCharFormat::fontStyleStrategy() const
1755
1756 Returns the current font style strategy.
1757
1758 \sa setFontStyleStrategy()
1759 \sa font()
1760*/
1761
1762
1763/*!
1764 \since 4.5
1765 \fn bool QTextCharFormat::fontKerning() const
1766 Returns \c true if the font kerning is enabled.
1767
1768 \sa setFontKerning()
1769 \sa font()
1770*/
1771
1772
1773/*!
1774 \fn void QTextCharFormat::setFontFixedPitch(bool fixedPitch)
1775
1776 If \a fixedPitch is true, sets the text format's font to be fixed pitch;
1777 otherwise a non-fixed pitch font is used.
1778
1779 \sa setFont()
1780*/
1781
1782
1783/*!
1784 \fn bool QTextCharFormat::fontFixedPitch() const
1785
1786 Returns \c true if the text format's font is fixed pitch; otherwise
1787 returns \c false.
1788
1789 \sa font()
1790*/
1791
1792/*!
1793 \since 4.8
1794
1795 \fn void QTextCharFormat::setFontHintingPreference(QFont::HintingPreference hintingPreference)
1796
1797 Sets the hinting preference of the text format's font to be \a hintingPreference.
1798
1799 \sa setFont(), QFont::setHintingPreference()
1800*/
1801
1802/*!
1803 \since 4.8
1804
1805 \fn QFont::HintingPreference QTextCharFormat::fontHintingPreference() const
1806
1807 Returns the hinting preference set for this text format.
1808
1809 \sa font(), QFont::hintingPreference()
1810*/
1811
1812/*!
1813 \fn QPen QTextCharFormat::textOutline() const
1814
1815 Returns the pen used to draw the outlines of characters in this format.
1816*/
1817
1818
1819/*!
1820 \fn void QTextCharFormat::setTextOutline(const QPen &pen)
1821
1822 Sets the pen used to draw the outlines of characters to the given \a pen.
1823*/
1824
1825/*!
1826 \fn void QTextCharFormat::setToolTip(const QString &text)
1827 \since 4.3
1828
1829 Sets the tool tip for a fragment of text to the given \a text.
1830*/
1831
1832/*!
1833 \fn QString QTextCharFormat::toolTip() const
1834 \since 4.3
1835
1836 Returns the tool tip that is displayed for a fragment of text.
1837*/
1838
1839/*!
1840 \fn void QTextFormat::setForeground(const QBrush &brush)
1841
1842 Sets the foreground brush to the specified \a brush. The foreground
1843 brush is mostly used to render text.
1844
1845 \sa foreground(), clearForeground(), setBackground()
1846*/
1847
1848
1849/*!
1850 \fn QBrush QTextFormat::foreground() const
1851
1852 Returns the brush used to render foreground details, such as text,
1853 frame outlines, and table borders.
1854
1855 \sa setForeground(), clearForeground(), background()
1856*/
1857
1858/*!
1859 \fn void QTextFormat::clearForeground()
1860
1861 Clears the brush used to paint the document's foreground. The default
1862 brush will be used.
1863
1864 \sa foreground(), setForeground(), clearBackground()
1865*/
1866
1867/*!
1868 \fn void QTextCharFormat::setSuperScriptBaseline(qreal baseline)
1869 \since 6.0
1870
1871 Sets the superscript's base line as a % of font height to \a baseline.
1872 The default value is 50% (1/2 of height).
1873
1874 \sa superScriptBaseline(), setSubScriptBaseline(), subScriptBaseline(), setBaselineOffset(), baselineOffset()
1875*/
1876
1877/*!
1878 \fn qreal QTextCharFormat::superScriptBaseline() const
1879 \since 6.0
1880
1881 Returns the superscript's base line as a % of font height.
1882
1883 \sa setSuperScriptBaseline(), setSubScriptBaseline(), subScriptBaseline(), setBaselineOffset(), baselineOffset()
1884*/
1885
1886/*!
1887 \fn void QTextCharFormat::setSubScriptBaseline(qreal baseline)
1888 \since 6.0
1889
1890 Sets the subscript's base line as a % of font height to \a baseline.
1891 The default value is 16.67% (1/6 of height)
1892
1893 \sa subScriptBaseline(), setSuperScriptBaseline(), superScriptBaseline(), setBaselineOffset(), baselineOffset()
1894*/
1895
1896/*!
1897 \fn qreal QTextCharFormat::subScriptBaseline() const
1898 \since 6.0
1899
1900 Returns the subscript's base line as a % of font height.
1901
1902 \sa setSubScriptBaseline(), setSuperScriptBaseline(), superScriptBaseline(), setBaselineOffset(), baselineOffset()
1903*/
1904
1905/*!
1906 \fn void QTextCharFormat::setBaselineOffset(qreal baseline)
1907 \since 6.0
1908
1909 Sets the base line (in % of height) of text to \a baseline. A positive value moves the text
1910 up, by the corresponding %; a negative value moves it down. The default value is 0.
1911
1912 \sa baselineOffset(), setSubScriptBaseline(), subScriptBaseline(), setSuperScriptBaseline(), superScriptBaseline()
1913*/
1914
1915/*!
1916 \fn qreal QTextCharFormat::baselineOffset() const
1917 \since 6.0
1918
1919 Returns the the baseline offset in %.
1920
1921 \sa setBaselineOffset(), setSubScriptBaseline(), subScriptBaseline(), setSuperScriptBaseline(), superScriptBaseline()
1922*/
1923
1924/*!
1925 \fn void QTextCharFormat::setAnchor(bool anchor)
1926
1927 If \a anchor is true, text with this format represents an anchor, and is
1928 formatted in the appropriate way; otherwise the text is formatted normally.
1929 (Anchors are hyperlinks which are often shown underlined and in a different
1930 color from plain text.)
1931
1932 The way the text is rendered is independent of whether or not the format
1933 has a valid anchor defined. Use setAnchorHref(), and optionally
1934 setAnchorNames() to create a hypertext link.
1935
1936 \sa isAnchor()
1937*/
1938
1939
1940/*!
1941 \fn bool QTextCharFormat::isAnchor() const
1942
1943 Returns \c true if the text is formatted as an anchor; otherwise
1944 returns \c false.
1945
1946 \sa setAnchor(), setAnchorHref(), setAnchorNames()
1947*/
1948
1949
1950/*!
1951 \fn void QTextCharFormat::setAnchorHref(const QString &value)
1952
1953 Sets the hypertext link for the text format to the given \a value.
1954 This is typically a URL like "http://example.com/index.html".
1955
1956 The anchor will be displayed with the \a value as its display text;
1957 if you want to display different text call setAnchorNames().
1958
1959 To format the text as a hypertext link use setAnchor().
1960*/
1961
1962
1963/*!
1964 \fn QString QTextCharFormat::anchorHref() const
1965
1966 Returns the text format's hypertext link, or an empty string if
1967 none has been set.
1968*/
1969
1970/*!
1971 \fn void QTextCharFormat::setAnchorNames(const QStringList &names)
1972 \since 4.3
1973
1974 Sets the text format's anchor \a names. For the anchor to work as a
1975 hyperlink, the destination must be set with setAnchorHref() and
1976 the anchor must be enabled with setAnchor().
1977*/
1978
1979/*!
1980 \fn QStringList QTextCharFormat::anchorNames() const
1981 \since 4.3
1982
1983 Returns the anchor names associated with this text format, or an empty
1984 string list if none has been set. If the anchor names are set, text with this
1985 format can be the destination of a hypertext link.
1986*/
1987QStringList QTextCharFormat::anchorNames() const
1988{
1989 QVariant prop = property(propertyId: AnchorName);
1990 if (prop.userType() == QMetaType::QStringList)
1991 return prop.toStringList();
1992 else if (prop.userType() != QMetaType::QString)
1993 return QStringList();
1994 return QStringList(prop.toString());
1995}
1996
1997
1998/*!
1999 \fn void QTextCharFormat::setTableCellRowSpan(int tableCellRowSpan)
2000 \internal
2001
2002 If this character format is applied to characters in a table cell,
2003 the cell will span \a tableCellRowSpan rows.
2004*/
2005
2006
2007/*!
2008 \fn int QTextCharFormat::tableCellRowSpan() const
2009 \internal
2010
2011 If this character format is applied to characters in a table cell,
2012 this function returns the number of rows spanned by the text (this may
2013 be 1); otherwise it returns 1.
2014*/
2015
2016/*!
2017 \fn void QTextCharFormat::setTableCellColumnSpan(int tableCellColumnSpan)
2018 \internal
2019
2020 If this character format is applied to characters in a table cell,
2021 the cell will span \a tableCellColumnSpan columns.
2022*/
2023
2024
2025/*!
2026 \fn int QTextCharFormat::tableCellColumnSpan() const
2027 \internal
2028
2029 If this character format is applied to characters in a table cell,
2030 this function returns the number of columns spanned by the text (this
2031 may be 1); otherwise it returns 1.
2032*/
2033
2034/*!
2035 \fn void QTextCharFormat::setUnderlineColor(const QColor &color)
2036
2037 Sets the color used to draw underlines, overlines and strikeouts on the
2038 characters with this format to the \a color specified.
2039
2040 \sa underlineColor()
2041*/
2042
2043/*!
2044 \fn QColor QTextCharFormat::underlineColor() const
2045
2046 Returns the color used to draw underlines, overlines and strikeouts
2047 on the characters with this format.
2048
2049 \sa setUnderlineColor()
2050*/
2051
2052/*!
2053 \fn void QTextCharFormat::setVerticalAlignment(VerticalAlignment alignment)
2054
2055 Sets the vertical alignment used for the characters with this format to
2056 the \a alignment specified.
2057
2058 \sa verticalAlignment()
2059*/
2060
2061/*!
2062 \fn VerticalAlignment QTextCharFormat::verticalAlignment() const
2063
2064 Returns the vertical alignment used for characters with this format.
2065
2066 \sa setVerticalAlignment()
2067*/
2068
2069/*!
2070 \enum QTextCharFormat::FontPropertiesInheritanceBehavior
2071 \since 5.3
2072
2073 This enum specifies how the setFont() function should behave with
2074 respect to unset font properties.
2075
2076 \value FontPropertiesSpecifiedOnly If a property is not explicitly set, do not
2077 change the text format's property value.
2078 \value FontPropertiesAll If a property is not explicitly set, override the
2079 text format's property with a default value.
2080
2081 \sa setFont()
2082*/
2083
2084/*!
2085 \since 5.3
2086
2087 Sets the text format's \a font.
2088
2089 If \a behavior is QTextCharFormat::FontPropertiesAll, the font property that
2090 has not been explicitly set is treated like as it were set with default value;
2091 If \a behavior is QTextCharFormat::FontPropertiesSpecifiedOnly, the font property that
2092 has not been explicitly set is ignored and the respective property value
2093 remains unchanged.
2094
2095 \sa font()
2096*/
2097void QTextCharFormat::setFont(const QFont &font, FontPropertiesInheritanceBehavior behavior)
2098{
2099 const uint mask = behavior == FontPropertiesAll ? uint(QFont::AllPropertiesResolved)
2100 : font.resolveMask();
2101
2102 if (mask & QFont::FamiliesResolved)
2103 setFontFamilies(font.families());
2104 if (mask & QFont::StyleNameResolved)
2105 setFontStyleName(font.styleName());
2106
2107 if (mask & QFont::SizeResolved) {
2108 const qreal pointSize = font.pointSizeF();
2109 if (pointSize > 0) {
2110 setFontPointSize(pointSize);
2111 } else {
2112 const int pixelSize = font.pixelSize();
2113 if (pixelSize > 0)
2114 setProperty(propertyId: QTextFormat::FontPixelSize, value: pixelSize);
2115 }
2116 }
2117
2118 if (mask & QFont::WeightResolved)
2119 setFontWeight(font.weight());
2120 if (mask & QFont::StyleResolved)
2121 setFontItalic(font.style() != QFont::StyleNormal);
2122 if (mask & QFont::UnderlineResolved)
2123 setUnderlineStyle(font.underline() ? SingleUnderline : NoUnderline);
2124 if (mask & QFont::OverlineResolved)
2125 setFontOverline(font.overline());
2126 if (mask & QFont::StrikeOutResolved)
2127 setFontStrikeOut(font.strikeOut());
2128 if (mask & QFont::FixedPitchResolved)
2129 setFontFixedPitch(font.fixedPitch());
2130 if (mask & QFont::CapitalizationResolved)
2131 setFontCapitalization(font.capitalization());
2132 if (mask & QFont::WordSpacingResolved)
2133 setFontWordSpacing(font.wordSpacing());
2134 if (mask & QFont::LetterSpacingResolved) {
2135 setFontLetterSpacingType(font.letterSpacingType());
2136 setFontLetterSpacing(font.letterSpacing());
2137 }
2138 if (mask & QFont::StretchResolved)
2139 setFontStretch(font.stretch());
2140 if (mask & QFont::StyleHintResolved)
2141 setFontStyleHint(hint: font.styleHint());
2142 if (mask & QFont::StyleStrategyResolved)
2143 setFontStyleStrategy(font.styleStrategy());
2144 if (mask & QFont::HintingPreferenceResolved)
2145 setFontHintingPreference(font.hintingPreference());
2146 if (mask & QFont::KerningResolved)
2147 setFontKerning(font.kerning());
2148}
2149
2150/*!
2151 Returns the font for this character format.
2152
2153 This function takes into account the format's font attributes (such as fontWeight()
2154 and fontPointSize()) and resolves them on top of the default font, defined as follows.
2155 If the format is part of a document, that is the document's default font.
2156 Otherwise the properties are resolved on top of a default constructed QFont.
2157
2158 For example, if this format's font size hasn't been changed from the default font,
2159 fontPointSize() returns 0, while \c {font().pointSize()} returns the actual
2160 size used for drawing.
2161
2162 \sa QTextDocument::defaultFont()
2163*/
2164QFont QTextCharFormat::font() const
2165{
2166 return d ? d->font() : QFont();
2167}
2168
2169/*!
2170 \class QTextBlockFormat
2171 \reentrant
2172
2173 \brief The QTextBlockFormat class provides formatting information for
2174 blocks of text in a QTextDocument.
2175 \inmodule QtGui
2176
2177 \ingroup richtext-processing
2178 \ingroup shared
2179
2180 A document is composed of a list of blocks, represented by QTextBlock
2181 objects. Each block can contain an item of some kind, such as a
2182 paragraph of text, a table, a list, or an image. Every block has an
2183 associated QTextBlockFormat that specifies its characteristics.
2184
2185 To cater for left-to-right and right-to-left languages you can set
2186 a block's direction with setLayoutDirection(). Paragraph alignment is
2187 set with setAlignment(). Margins are controlled by setTopMargin(),
2188 setBottomMargin(), setLeftMargin(), setRightMargin(). Overall
2189 indentation is set with setIndent(), the indentation of the first
2190 line with setTextIndent().
2191
2192 Line spacing is set with setLineHeight() and retrieved via lineHeight()
2193 and lineHeightType(). The types of line spacing available are in the
2194 LineHeightTypes enum.
2195
2196 Line breaking can be enabled and disabled with setNonBreakableLines().
2197
2198 The brush used to paint the paragraph's background
2199 is set with \l{QTextFormat::setBackground()}{setBackground()}, and other
2200 aspects of the text's appearance can be customized by using the
2201 \l{QTextFormat::setProperty()}{setProperty()} function with the
2202 \c OutlinePen, \c ForegroundBrush, and \c BackgroundBrush
2203 \l{QTextFormat::Property} values.
2204
2205 If a text block is part of a list, it can also have a list format that
2206 is accessible with the listFormat() function.
2207
2208 \sa QTextBlock, QTextCharFormat
2209*/
2210
2211/*!
2212 \since 4.8
2213 \enum QTextBlockFormat::LineHeightTypes
2214
2215 This enum describes the various types of line spacing support paragraphs can have.
2216
2217 \value SingleHeight This is the default line height: single spacing.
2218 \value ProportionalHeight This sets the spacing proportional to the line (in percentage).
2219 For example, set to 200 for double spacing.
2220 \value FixedHeight This sets the line height to a fixed line height (in pixels).
2221 \value MinimumHeight This sets the minimum line height (in pixels).
2222 \value LineDistanceHeight This adds the specified height between lines (in pixels).
2223
2224 \sa lineHeight(), lineHeightType(), setLineHeight()
2225*/
2226
2227/*!
2228 \fn QTextBlockFormat::QTextBlockFormat()
2229
2230 Constructs a new QTextBlockFormat.
2231*/
2232QTextBlockFormat::QTextBlockFormat() : QTextFormat(BlockFormat) {}
2233
2234/*!
2235 \internal
2236 \fn QTextBlockFormat::QTextBlockFormat(const QTextFormat &other)
2237
2238 Creates a new block format with the same attributes as the \a given
2239 text format.
2240*/
2241QTextBlockFormat::QTextBlockFormat(const QTextFormat &fmt)
2242 : QTextFormat(fmt)
2243{
2244}
2245
2246/*!
2247 \since 4.4
2248 Sets the tab positions for the text block to those specified by
2249 \a tabs.
2250
2251 \sa tabPositions()
2252*/
2253void QTextBlockFormat::setTabPositions(const QList<QTextOption::Tab> &tabs)
2254{
2255 QList<QVariant> list;
2256 list.reserve(asize: tabs.size());
2257 for (const auto &e : tabs)
2258 list.append(t: QVariant::fromValue(value: e));
2259 setProperty(propertyId: TabPositions, value: list);
2260}
2261
2262/*!
2263 \since 4.4
2264 Returns a list of tab positions defined for the text block.
2265
2266 \sa setTabPositions()
2267*/
2268QList<QTextOption::Tab> QTextBlockFormat::tabPositions() const
2269{
2270 QVariant variant = property(propertyId: TabPositions);
2271 if (variant.isNull())
2272 return QList<QTextOption::Tab>();
2273 QList<QTextOption::Tab> answer;
2274 const QList<QVariant> variantsList = qvariant_cast<QList<QVariant> >(v: variant);
2275 answer.reserve(asize: variantsList.size());
2276 for (const auto &e: variantsList)
2277 answer.append(t: qvariant_cast<QTextOption::Tab>(v: e));
2278 return answer;
2279}
2280
2281/*!
2282 \fn QTextBlockFormat::isValid() const
2283
2284 Returns \c true if this block format is valid; otherwise returns
2285 false.
2286*/
2287
2288/*!
2289 \fn void QTextFormat::setLayoutDirection(Qt::LayoutDirection direction)
2290
2291 Sets the document's layout direction to the specified \a direction.
2292
2293 \sa layoutDirection()
2294*/
2295
2296
2297/*!
2298 \fn Qt::LayoutDirection QTextFormat::layoutDirection() const
2299
2300 Returns the document's layout direction.
2301
2302 \sa setLayoutDirection()
2303*/
2304
2305
2306/*!
2307 \fn void QTextBlockFormat::setAlignment(Qt::Alignment alignment)
2308
2309 Sets the paragraph's \a alignment.
2310
2311 \sa alignment()
2312*/
2313
2314
2315/*!
2316 \fn Qt::Alignment QTextBlockFormat::alignment() const
2317
2318 Returns the paragraph's alignment.
2319
2320 \sa setAlignment()
2321*/
2322
2323
2324/*!
2325 \fn void QTextBlockFormat::setTopMargin(qreal margin)
2326
2327 Sets the paragraph's top \a margin.
2328
2329 \sa topMargin(), setBottomMargin(), setLeftMargin(), setRightMargin()
2330*/
2331
2332
2333/*!
2334 \fn qreal QTextBlockFormat::topMargin() const
2335
2336 Returns the paragraph's top margin.
2337
2338 \sa setTopMargin(), bottomMargin()
2339*/
2340
2341
2342/*!
2343 \fn void QTextBlockFormat::setBottomMargin(qreal margin)
2344
2345 Sets the paragraph's bottom \a margin.
2346
2347 \sa bottomMargin(), setTopMargin(), setLeftMargin(), setRightMargin()
2348*/
2349
2350
2351/*!
2352 \fn qreal QTextBlockFormat::bottomMargin() const
2353
2354 Returns the paragraph's bottom margin.
2355
2356 \sa setBottomMargin(), topMargin()
2357*/
2358
2359
2360/*!
2361 \fn void QTextBlockFormat::setLeftMargin(qreal margin)
2362
2363 Sets the paragraph's left \a margin. Indentation can be applied separately
2364 with setIndent().
2365
2366 \sa leftMargin(), setRightMargin(), setTopMargin(), setBottomMargin()
2367*/
2368
2369
2370/*!
2371 \fn qreal QTextBlockFormat::leftMargin() const
2372
2373 Returns the paragraph's left margin.
2374
2375 \sa setLeftMargin(), rightMargin(), indent()
2376*/
2377
2378
2379/*!
2380 \fn void QTextBlockFormat::setRightMargin(qreal margin)
2381
2382 Sets the paragraph's right \a margin.
2383
2384 \sa rightMargin(), setLeftMargin(), setTopMargin(), setBottomMargin()
2385*/
2386
2387
2388/*!
2389 \fn qreal QTextBlockFormat::rightMargin() const
2390
2391 Returns the paragraph's right margin.
2392
2393 \sa setRightMargin(), leftMargin()
2394*/
2395
2396
2397/*!
2398 \fn void QTextBlockFormat::setTextIndent(qreal indent)
2399
2400 Sets the \a indent for the first line in the block. This allows the first
2401 line of a paragraph to be indented differently to the other lines,
2402 enhancing the readability of the text.
2403
2404 \sa textIndent(), setLeftMargin(), setRightMargin(), setTopMargin(), setBottomMargin()
2405*/
2406
2407
2408/*!
2409 \fn qreal QTextBlockFormat::textIndent() const
2410
2411 Returns the paragraph's text indent.
2412
2413 \sa setTextIndent()
2414*/
2415
2416
2417/*!
2418 \fn void QTextBlockFormat::setIndent(int indentation)
2419
2420 Sets the paragraph's \a indentation. Margins are set independently of
2421 indentation with setLeftMargin() and setTextIndent().
2422 The \a indentation is an integer that is multiplied with the document-wide
2423 standard indent, resulting in the actual indent of the paragraph.
2424
2425 \sa indent(), QTextDocument::indentWidth()
2426*/
2427
2428
2429/*!
2430 \fn int QTextBlockFormat::indent() const
2431
2432 Returns the paragraph's indent.
2433
2434 \sa setIndent()
2435*/
2436
2437
2438/*!
2439 \fn void QTextBlockFormat::setHeadingLevel(int level)
2440 \since 5.12
2441
2442 Sets the paragraph's heading \a level, where 1 is the highest-level heading
2443 type (usually with the largest possible heading font size), and increasing
2444 values are progressively deeper into the document (and usually with smaller
2445 font sizes). For example when reading an HTML H1 tag, the heading level is
2446 set to 1. Setting the heading level does not automatically change the font
2447 size; however QTextDocumentFragment::fromHtml() sets both the heading level
2448 and the font size simultaneously.
2449
2450 If the paragraph is not a heading, the level should be set to 0 (the default).
2451
2452 \sa headingLevel()
2453*/
2454
2455
2456/*!
2457 \fn int QTextBlockFormat::headingLevel() const
2458 \since 5.12
2459
2460 Returns the paragraph's heading level if it is a heading, or 0 if not.
2461
2462 \sa setHeadingLevel()
2463*/
2464
2465
2466/*!
2467 \fn void QTextBlockFormat::setMarker(MarkerType marker)
2468 \since 5.14
2469
2470 Sets the type of adornment that should be rendered alongside the paragraph to \a marker.
2471 For example, a list item can be adorned with a checkbox, either checked
2472 or unchecked, as a replacement for its bullet. The default is \c NoMarker.
2473
2474 \sa marker()
2475*/
2476
2477
2478/*!
2479 \fn MarkerType QTextBlockFormat::marker() const
2480 \since 5.14
2481
2482 Returns the paragraph's marker if one has been set, or \c NoMarker if not.
2483
2484 \sa setMarker()
2485*/
2486
2487
2488/*!
2489 \since 5.14
2490 \enum QTextBlockFormat::MarkerType
2491
2492 This enum describes the types of markers a list item can have.
2493 If a list item (a paragraph for which \l QTextBlock::textList() returns the list)
2494 has a marker, it is rendered instead of the normal bullet.
2495 In this way, checkable list items can be mixed with plain list items in the
2496 same list, overriding the type of bullet specified by the
2497 \l QTextListFormat::style() for the entire list.
2498
2499 \value NoMarker This is the default: the list item's bullet will be shown.
2500 \value Unchecked Instead of the list item's bullet, an unchecked checkbox will be shown.
2501 \value Checked Instead of the list item's bullet, a checked checkbox will be shown.
2502
2503 In the future, this may be extended to specify other types of paragraph
2504 decorations.
2505
2506 \sa QTextListFormat::style()
2507*/
2508
2509
2510/*!
2511 \fn void QTextBlockFormat::setLineHeight(qreal height, int heightType)
2512 \since 4.8
2513
2514 Sets the line height for the paragraph to the value given by \a height
2515 which is dependent on \a heightType in the way described by the
2516 LineHeightTypes enum.
2517
2518 \sa LineHeightTypes, lineHeight(), lineHeightType()
2519*/
2520
2521
2522/*!
2523 \fn qreal QTextBlockFormat::lineHeight(qreal scriptLineHeight, qreal scaling) const
2524 \since 4.8
2525
2526 Returns the height of the lines in the paragraph based on the height of the
2527 script line given by \a scriptLineHeight and the specified \a scaling
2528 factor.
2529
2530 The value that is returned is also dependent on the given LineHeightType of
2531 the paragraph as well as the LineHeight setting that has been set for the
2532 paragraph.
2533
2534 The scaling is needed for heights that include a fixed number of pixels, to
2535 scale them appropriately for printing.
2536
2537 \sa LineHeightTypes, setLineHeight(), lineHeightType()
2538*/
2539
2540
2541/*!
2542 \fn qreal QTextBlockFormat::lineHeight() const
2543 \since 4.8
2544
2545 This returns the LineHeight property for the paragraph.
2546
2547 \sa LineHeightTypes, setLineHeight(), lineHeightType()
2548*/
2549
2550
2551/*!
2552 \fn qreal QTextBlockFormat::lineHeightType() const
2553 \since 4.8
2554
2555 This returns the LineHeightType property of the paragraph.
2556
2557 \sa LineHeightTypes, setLineHeight(), lineHeight()
2558*/
2559
2560
2561/*!
2562 \fn void QTextBlockFormat::setNonBreakableLines(bool b)
2563
2564 If \a b is true, the lines in the paragraph are treated as
2565 non-breakable; otherwise they are breakable.
2566
2567 \sa nonBreakableLines()
2568*/
2569
2570
2571/*!
2572 \fn bool QTextBlockFormat::nonBreakableLines() const
2573
2574 Returns \c true if the lines in the paragraph are non-breakable;
2575 otherwise returns \c false.
2576
2577 \sa setNonBreakableLines()
2578*/
2579
2580/*!
2581 \fn QTextFormat::PageBreakFlags QTextBlockFormat::pageBreakPolicy() const
2582 \since 4.2
2583
2584 Returns the currently set page break policy for the paragraph. The default is
2585 QTextFormat::PageBreak_Auto.
2586
2587 \sa setPageBreakPolicy()
2588*/
2589
2590/*!
2591 \fn void QTextBlockFormat::setPageBreakPolicy(PageBreakFlags policy)
2592 \since 4.2
2593
2594 Sets the page break policy for the paragraph to \a policy.
2595
2596 \sa pageBreakPolicy()
2597*/
2598
2599/*!
2600 \class QTextListFormat
2601 \reentrant
2602
2603 \brief The QTextListFormat class provides formatting information for
2604 lists in a QTextDocument.
2605 \inmodule QtGui
2606
2607 \ingroup richtext-processing
2608 \ingroup shared
2609
2610 A list is composed of one or more items, represented as text blocks.
2611 The list's format specifies the appearance of items in the list.
2612 In particular, it determines the indentation and the style of each item.
2613
2614 The indentation of the items is an integer value that causes each item to
2615 be offset from the left margin by a certain amount. This value is read with
2616 indent() and set with setIndent().
2617
2618 The style used to decorate each item is set with setStyle() and can be read
2619 with the style() function. The style controls the type of bullet points and
2620 numbering scheme used for items in the list. Note that lists that use the
2621 decimal numbering scheme begin counting at 1 rather than 0, unless it has
2622 been overridden via setStart().
2623
2624 Style properties can be set to further configure the appearance of list
2625 items; for example, the ListNumberPrefix and ListNumberSuffix properties
2626 can be used to customize the numbers used in an ordered list so that they
2627 appear as (1), (2), (3), etc.:
2628
2629 \snippet textdocument-listitemstyles/mainwindow.cpp add a styled, ordered list
2630
2631 \sa QTextList
2632*/
2633
2634/*!
2635 \enum QTextListFormat::Style
2636
2637 This enum describes the symbols used to decorate list items:
2638
2639 \value ListDisc a filled circle
2640 \value ListCircle an empty circle
2641 \value ListSquare a filled square
2642 \value ListDecimal decimal values in ascending order
2643 \value ListLowerAlpha lower case Latin characters in alphabetical order
2644 \value ListUpperAlpha upper case Latin characters in alphabetical order
2645 \value ListLowerRoman lower case roman numerals (supports up to 4999 items only)
2646 \value ListUpperRoman upper case roman numerals (supports up to 4999 items only)
2647 \omitvalue ListStyleUndefined
2648*/
2649
2650/*!
2651 \fn QTextListFormat::QTextListFormat()
2652
2653 Constructs a new list format object.
2654*/
2655QTextListFormat::QTextListFormat()
2656 : QTextFormat(ListFormat)
2657{
2658 setIndent(1);
2659 setStart(1);
2660}
2661
2662/*!
2663 \internal
2664 \fn QTextListFormat::QTextListFormat(const QTextFormat &other)
2665
2666 Creates a new list format with the same attributes as the \a given
2667 text format.
2668*/
2669QTextListFormat::QTextListFormat(const QTextFormat &fmt)
2670 : QTextFormat(fmt)
2671{
2672}
2673
2674/*!
2675 \fn bool QTextListFormat::isValid() const
2676
2677 Returns \c true if this list format is valid; otherwise
2678 returns \c false.
2679*/
2680
2681/*!
2682 \fn void QTextListFormat::setStyle(Style style)
2683
2684 Sets the list format's \a style.
2685
2686 \sa style(), Style
2687*/
2688
2689/*!
2690 \fn Style QTextListFormat::style() const
2691
2692 Returns the list format's style.
2693
2694 \sa setStyle(), Style
2695*/
2696
2697
2698/*!
2699 \fn void QTextListFormat::setIndent(int indentation)
2700
2701 Sets the list format's \a indentation.
2702 The indentation is multiplied by the QTextDocument::indentWidth
2703 property to get the effective indent in pixels.
2704
2705 \sa indent()
2706*/
2707
2708
2709/*!
2710 \fn int QTextListFormat::indent() const
2711
2712 Returns the list format's indentation.
2713 The indentation is multiplied by the QTextDocument::indentWidth
2714 property to get the effective indent in pixels.
2715
2716 \sa setIndent()
2717*/
2718
2719/*!
2720 \fn void QTextListFormat::setNumberPrefix(const QString &numberPrefix)
2721 \since 4.8
2722
2723 Sets the list format's number prefix to the string specified by
2724 \a numberPrefix. This can be used with all sorted list types. It does not
2725 have any effect on unsorted list types.
2726
2727 The default prefix is an empty string.
2728
2729 \sa numberPrefix()
2730*/
2731
2732/*!
2733 \fn int QTextListFormat::numberPrefix() const
2734 \since 4.8
2735
2736 Returns the list format's number prefix.
2737
2738 \sa setNumberPrefix()
2739*/
2740
2741/*!
2742 \fn void QTextListFormat::setNumberSuffix(const QString &numberSuffix)
2743 \since 4.8
2744
2745 Sets the list format's number suffix to the string specified by
2746 \a numberSuffix. This can be used with all sorted list types. It does not
2747 have any effect on unsorted list types.
2748
2749 The default suffix is ".".
2750
2751 \sa numberSuffix()
2752*/
2753
2754/*!
2755 \fn int QTextListFormat::numberSuffix() const
2756 \since 4.8
2757
2758 Returns the list format's number suffix.
2759
2760 \sa setNumberSuffix()
2761*/
2762
2763/*!
2764 \fn void QTextListFormat::setStart(int start)
2765 \since 6.6
2766
2767 Sets the list format's \a start index.
2768
2769 This allows you to start a list with an index other than 1. This can be
2770 used with all sorted list types: for example if the style() is
2771 QTextListFormat::ListLowerAlpha and start() is \c 4, the first list item
2772 begins with "d". It does not have any effect on unsorted list types.
2773
2774 The default start is \c 1.
2775
2776 \sa start()
2777*/
2778
2779/*!
2780 \fn int QTextListFormat::start() const
2781 \since 6.6
2782
2783 Returns the number to be shown by the first list item, if the style() is
2784 QTextListFormat::ListDecimal, or to offset other sorted list types.
2785
2786 \sa setStart()
2787*/
2788
2789/*!
2790 \class QTextFrameFormat
2791 \reentrant
2792
2793 \brief The QTextFrameFormat class provides formatting information for
2794 frames in a QTextDocument.
2795 \inmodule QtGui
2796
2797 \ingroup richtext-processing
2798 \ingroup shared
2799
2800 A text frame groups together one or more blocks of text, providing a layer
2801 of structure larger than the paragraph. The format of a frame specifies
2802 how it is rendered and positioned on the screen. It does not directly
2803 specify the behavior of the text formatting within, but provides
2804 constraints on the layout of its children.
2805
2806 The frame format defines the width() and height() of the frame on the
2807 screen. Each frame can have a border() that surrounds its contents with
2808 a rectangular box. The border is surrounded by a margin() around the frame,
2809 and the contents of the frame are kept separate from the border by the
2810 frame's padding(). This scheme is similar to the box model used by Cascading
2811 Style Sheets for HTML pages.
2812
2813 \image qtextframe-style.png
2814
2815 The position() of a frame is set using setPosition() and determines how it
2816 is located relative to the surrounding text.
2817
2818 The validity of a QTextFrameFormat object can be determined with the
2819 isValid() function.
2820
2821 \sa QTextFrame, QTextBlockFormat
2822*/
2823
2824/*!
2825 \enum QTextFrameFormat::Position
2826
2827 This enum describes how a frame is located relative to the surrounding text.
2828
2829 \value InFlow
2830 \value FloatLeft
2831 \value FloatRight
2832
2833 \sa position(), CssFloat
2834*/
2835
2836/*!
2837 \enum QTextFrameFormat::BorderStyle
2838 \since 4.3
2839
2840 This enum describes different border styles for the text frame.
2841
2842 \value BorderStyle_None
2843 \value BorderStyle_Dotted
2844 \value BorderStyle_Dashed
2845 \value BorderStyle_Solid
2846 \value BorderStyle_Double
2847 \value BorderStyle_DotDash
2848 \value BorderStyle_DotDotDash
2849 \value BorderStyle_Groove
2850 \value BorderStyle_Ridge
2851 \value BorderStyle_Inset
2852 \value BorderStyle_Outset
2853
2854 \sa borderStyle(), FrameBorderStyle
2855*/
2856
2857/*!
2858 \fn QTextFrameFormat::QTextFrameFormat()
2859
2860 Constructs a text frame format object with the default properties.
2861*/
2862QTextFrameFormat::QTextFrameFormat() : QTextFormat(FrameFormat)
2863{
2864 setBorderStyle(BorderStyle_Outset);
2865 setBorderBrush(Qt::darkGray);
2866}
2867
2868/*!
2869 \internal
2870 \fn QTextFrameFormat::QTextFrameFormat(const QTextFormat &other)
2871
2872 Creates a new frame format with the same attributes as the \a given
2873 text format.
2874*/
2875QTextFrameFormat::QTextFrameFormat(const QTextFormat &fmt)
2876 : QTextFormat(fmt)
2877{
2878}
2879
2880/*!
2881 \fn bool QTextFrameFormat::isValid() const
2882
2883 Returns \c true if the format description is valid; otherwise returns \c false.
2884*/
2885
2886/*!
2887 \fn void QTextFrameFormat::setPosition(Position policy)
2888
2889 Sets the \a policy for positioning frames with this frame format.
2890
2891*/
2892
2893/*!
2894 \fn Position QTextFrameFormat::position() const
2895
2896 Returns the positioning policy for frames with this frame format.
2897*/
2898
2899/*!
2900 \fn void QTextFrameFormat::setBorder(qreal width)
2901
2902 Sets the \a width (in pixels) of the frame's border.
2903*/
2904
2905/*!
2906 \fn qreal QTextFrameFormat::border() const
2907
2908 Returns the width of the border in pixels.
2909*/
2910
2911/*!
2912 \fn void QTextFrameFormat::setBorderBrush(const QBrush &brush)
2913 \since 4.3
2914
2915 Sets the \a brush used for the frame's border.
2916*/
2917
2918/*!
2919 \fn QBrush QTextFrameFormat::borderBrush() const
2920 \since 4.3
2921
2922 Returns the brush used for the frame's border.
2923*/
2924
2925/*!
2926 \fn void QTextFrameFormat::setBorderStyle(BorderStyle style)
2927 \since 4.3
2928
2929 Sets the \a style of the frame's border.
2930*/
2931
2932/*!
2933 \fn BorderStyle QTextFrameFormat::borderStyle() const
2934 \since 4.3
2935
2936 Returns the style of the frame's border.
2937*/
2938
2939/*!
2940 \fn void QTextFrameFormat::setMargin(qreal margin)
2941
2942 Sets the frame's \a margin in pixels.
2943 This method also sets the left, right, top and bottom margins
2944 of the frame to the same value. The individual margins override
2945 the general margin.
2946*/
2947void QTextFrameFormat::setMargin(qreal amargin)
2948{
2949 setProperty(propertyId: FrameMargin, value: amargin);
2950 setProperty(propertyId: FrameTopMargin, value: amargin);
2951 setProperty(propertyId: FrameBottomMargin, value: amargin);
2952 setProperty(propertyId: FrameLeftMargin, value: amargin);
2953 setProperty(propertyId: FrameRightMargin, value: amargin);
2954}
2955
2956
2957/*!
2958 \fn qreal QTextFrameFormat::margin() const
2959
2960 Returns the width of the frame's external margin in pixels.
2961*/
2962
2963/*!
2964 \fn void QTextFrameFormat::setTopMargin(qreal margin)
2965 \since 4.3
2966
2967 Sets the frame's top \a margin in pixels.
2968*/
2969
2970/*!
2971 \fn qreal QTextFrameFormat::topMargin() const
2972 \since 4.3
2973
2974 Returns the width of the frame's top margin in pixels.
2975*/
2976qreal QTextFrameFormat::topMargin() const
2977{
2978 if (!hasProperty(propertyId: FrameTopMargin))
2979 return margin();
2980 return doubleProperty(propertyId: FrameTopMargin);
2981}
2982
2983/*!
2984 \fn void QTextFrameFormat::setBottomMargin(qreal margin)
2985 \since 4.3
2986
2987 Sets the frame's bottom \a margin in pixels.
2988*/
2989
2990/*!
2991 \fn qreal QTextFrameFormat::bottomMargin() const
2992 \since 4.3
2993
2994 Returns the width of the frame's bottom margin in pixels.
2995*/
2996qreal QTextFrameFormat::bottomMargin() const
2997{
2998 if (!hasProperty(propertyId: FrameBottomMargin))
2999 return margin();
3000 return doubleProperty(propertyId: FrameBottomMargin);
3001}
3002
3003/*!
3004 \fn void QTextFrameFormat::setLeftMargin(qreal margin)
3005 \since 4.3
3006
3007 Sets the frame's left \a margin in pixels.
3008*/
3009
3010/*!
3011 \fn qreal QTextFrameFormat::leftMargin() const
3012 \since 4.3
3013
3014 Returns the width of the frame's left margin in pixels.
3015*/
3016qreal QTextFrameFormat::leftMargin() const
3017{
3018 if (!hasProperty(propertyId: FrameLeftMargin))
3019 return margin();
3020 return doubleProperty(propertyId: FrameLeftMargin);
3021}
3022
3023/*!
3024 \fn void QTextFrameFormat::setRightMargin(qreal margin)
3025 \since 4.3
3026
3027 Sets the frame's right \a margin in pixels.
3028*/
3029
3030/*!
3031 \fn qreal QTextFrameFormat::rightMargin() const
3032 \since 4.3
3033
3034 Returns the width of the frame's right margin in pixels.
3035*/
3036qreal QTextFrameFormat::rightMargin() const
3037{
3038 if (!hasProperty(propertyId: FrameRightMargin))
3039 return margin();
3040 return doubleProperty(propertyId: FrameRightMargin);
3041}
3042
3043/*!
3044 \fn void QTextFrameFormat::setPadding(qreal width)
3045
3046 Sets the \a width of the frame's internal padding in pixels.
3047*/
3048
3049/*!
3050 \fn qreal QTextFrameFormat::padding() const
3051
3052 Returns the width of the frame's internal padding in pixels.
3053*/
3054
3055/*!
3056 \fn void QTextFrameFormat::setWidth(const QTextLength &width)
3057
3058 Sets the frame's border rectangle's \a width.
3059
3060 \sa QTextLength
3061*/
3062
3063/*!
3064 \fn void QTextFrameFormat::setWidth(qreal width)
3065 \overload
3066
3067 Convenience method that sets the width of the frame's border
3068 rectangle's width to the specified fixed \a width.
3069*/
3070
3071/*!
3072 \fn QTextFormat::PageBreakFlags QTextFrameFormat::pageBreakPolicy() const
3073 \since 4.2
3074
3075 Returns the currently set page break policy for the frame/table. The default is
3076 QTextFormat::PageBreak_Auto.
3077
3078 \sa setPageBreakPolicy()
3079*/
3080
3081/*!
3082 \fn void QTextFrameFormat::setPageBreakPolicy(PageBreakFlags policy)
3083 \since 4.2
3084
3085 Sets the page break policy for the frame/table to \a policy.
3086
3087 \sa pageBreakPolicy()
3088*/
3089
3090/*!
3091 \fn QTextLength QTextFrameFormat::width() const
3092
3093 Returns the width of the frame's border rectangle.
3094
3095 \sa QTextLength
3096*/
3097
3098/*!
3099 \fn void QTextFrameFormat::setHeight(const QTextLength &height)
3100
3101 Sets the frame's \a height.
3102*/
3103
3104/*!
3105 \fn void QTextFrameFormat::setHeight(qreal height)
3106 \overload
3107
3108 Sets the frame's \a height.
3109*/
3110
3111/*!
3112 \fn qreal QTextFrameFormat::height() const
3113
3114 Returns the height of the frame's border rectangle.
3115*/
3116
3117/*!
3118 \class QTextTableFormat
3119 \reentrant
3120
3121 \brief The QTextTableFormat class provides formatting information for
3122 tables in a QTextDocument.
3123 \inmodule QtGui
3124
3125 \ingroup richtext-processing
3126 \ingroup shared
3127
3128 A table is a group of cells ordered into rows and columns. Each table
3129 contains at least one row and one column. Each cell contains a block.
3130 Tables in rich text documents are formatted using the properties
3131 defined in this class.
3132
3133 Tables are horizontally justified within their parent frame according to the
3134 table's alignment. This can be read with the alignment() function and set
3135 with setAlignment().
3136
3137 Cells within the table are separated by cell spacing. The number of pixels
3138 between cells is set with setCellSpacing() and read with cellSpacing().
3139 The contents of each cell is surrounded by cell padding. The number of pixels
3140 between each cell edge and its contents is set with setCellPadding() and read
3141 with cellPadding().
3142
3143 \image qtexttableformat-cell.png
3144
3145 The table's background color can be read with the background() function,
3146 and can be specified with setBackground(). The background color of each
3147 cell can be set independently, and will control the color of the cell within
3148 the padded area.
3149
3150 The table format also provides a way to constrain the widths of the columns
3151 in the table. Columns can be assigned a fixed width, a variable width, or
3152 a percentage of the available width (see QTextLength). The columns() function
3153 returns the number of columns with constraints, and the
3154 columnWidthConstraints() function returns the constraints defined for the
3155 table. These quantities can also be set by calling setColumnWidthConstraints()
3156 with a list containing new constraints. If no constraints are
3157 required, clearColumnWidthConstraints() can be used to remove them.
3158
3159 \sa QTextTable, QTextTableCell, QTextLength
3160*/
3161
3162/*!
3163 \fn QTextTableFormat::QTextTableFormat()
3164
3165 Constructs a new table format object.
3166*/
3167QTextTableFormat::QTextTableFormat()
3168 : QTextFrameFormat()
3169{
3170 setObjectType(TableObject);
3171 setCellPadding(4);
3172 setBorderCollapse(true);
3173 setBorder(1);
3174}
3175
3176/*!
3177 \internal
3178 \fn QTextTableFormat::QTextTableFormat(const QTextFormat &other)
3179
3180 Creates a new table format with the same attributes as the \a given
3181 text format.
3182*/
3183QTextTableFormat::QTextTableFormat(const QTextFormat &fmt)
3184 : QTextFrameFormat(fmt)
3185{
3186}
3187
3188/*!
3189 \fn bool QTextTableFormat::isValid() const
3190
3191 Returns \c true if this table format is valid; otherwise
3192 returns \c false.
3193*/
3194
3195
3196/*!
3197 \fn int QTextTableFormat::columns() const
3198
3199 Returns the number of columns specified by the table format.
3200*/
3201
3202
3203/*!
3204 \internal
3205 \fn void QTextTableFormat::setColumns(int columns)
3206
3207 Sets the number of \a columns required by the table format.
3208
3209 \sa columns()
3210*/
3211
3212/*!
3213 \fn void QTextTableFormat::clearColumnWidthConstraints()
3214
3215 Clears the column width constraints for the table.
3216
3217 \sa columnWidthConstraints(), setColumnWidthConstraints()
3218*/
3219
3220/*!
3221 \fn void QTextTableFormat::setColumnWidthConstraints(const QList<QTextLength> &constraints)
3222
3223 Sets the column width \a constraints for the table.
3224
3225 \sa columnWidthConstraints(), clearColumnWidthConstraints()
3226*/
3227
3228/*!
3229 \fn QList<QTextLength> QTextTableFormat::columnWidthConstraints() const
3230
3231 Returns a list of constraints used by this table format to control the
3232 appearance of columns in a table.
3233
3234 \sa setColumnWidthConstraints()
3235*/
3236
3237/*!
3238 \fn qreal QTextTableFormat::cellSpacing() const
3239
3240 Returns the table's cell spacing. This describes the distance between
3241 adjacent cells.
3242*/
3243
3244/*!
3245 \fn void QTextTableFormat::setCellSpacing(qreal spacing)
3246
3247 Sets the cell \a spacing for the table. This determines the distance
3248 between adjacent cells.
3249
3250 This property will be ignored if \l borderCollapse is enabled.
3251*/
3252
3253/*!
3254 \fn qreal QTextTableFormat::cellPadding() const
3255
3256 Returns the table's cell padding. This describes the distance between
3257 the border of a cell and its contents.
3258*/
3259
3260/*!
3261 \fn void QTextTableFormat::setCellPadding(qreal padding)
3262
3263 Sets the cell \a padding for the table. This determines the distance
3264 between the border of a cell and its contents.
3265*/
3266
3267/*!
3268 \fn void QTextTableFormat::setAlignment(Qt::Alignment alignment)
3269
3270 Sets the table's \a alignment.
3271
3272 \sa alignment()
3273*/
3274
3275/*!
3276 \fn Qt::Alignment QTextTableFormat::alignment() const
3277
3278 Returns the table's alignment.
3279
3280 \sa setAlignment()
3281*/
3282
3283/*!
3284 \fn void QTextTableFormat::setHeaderRowCount(int count)
3285 \since 4.2
3286
3287 Declares the first \a count rows of the table as table header.
3288 The table header rows get repeated when a table is broken
3289 across a page boundary.
3290*/
3291
3292/*!
3293 \fn int QTextTableFormat::headerRowCount() const
3294 \since 4.2
3295
3296 Returns the number of rows in the table that define the header.
3297
3298 \sa setHeaderRowCount()
3299*/
3300
3301/*!
3302 \fn void QTextTableFormat::setBorderCollapse(bool borderCollapse)
3303 \since 5.14
3304
3305 By default, \l borderCollapse() is \c true, which has the following implications:
3306 \list
3307 \li The borders and grid of the table will be rendered following the
3308 CSS table \c border-collapse: \c collapse rules
3309 \li Setting the \c border property to a minimum value of \c 1 will render a
3310 one pixel solid inner table grid using the \l borderBrush property and an
3311 outer border as specified
3312 \li The various border style properties of \l QTextTableCellFormat can be used to
3313 customize the grid and have precedence over the border and grid of the table
3314 \li The \l cellSpacing property will be ignored
3315 \li For print pagination:
3316 \list
3317 \li Columns continued on a page will not have their top cell border rendered
3318 \li Repeated header rows will always have their bottom cell border rendered
3319 \endlist
3320 \endlist
3321
3322 With \a borderCollapse set to \c false, cell borders can still be styled
3323 using QTextTableCellFormat but styling will be applied only within
3324 the cell's frame, which is probably not very useful in practice.
3325
3326 \note In Qt versions prior to 6.8, the default value was \c false.
3327
3328 \sa setBorder(), setBorderBrush(), setBorderStyle()
3329 \sa QTextTableCellFormat
3330*/
3331
3332/*!
3333 \fn bool QTextTableFormat::borderCollapse() const
3334 \since 5.14
3335
3336 Returns \c true if table borders are to be collapsed. The default is \c true.
3337
3338 \sa setBorderCollapse()
3339*/
3340
3341/*!
3342 \fn void QTextFormat::setBackground(const QBrush &brush)
3343
3344 Sets the brush use to paint the document's background to the
3345 \a brush specified.
3346
3347 \sa background(), clearBackground(), setForeground()
3348*/
3349
3350/*!
3351 \fn QColor QTextFormat::background() const
3352
3353 Returns the brush used to paint the document's background.
3354
3355 \sa setBackground(), clearBackground(), foreground()
3356*/
3357
3358/*!
3359 \fn void QTextFormat::clearBackground()
3360
3361 Clears the brush used to paint the document's background. The default
3362 brush will be used.
3363
3364 \sa background(), setBackground(), clearForeground()
3365*/
3366
3367
3368/*!
3369 \class QTextImageFormat
3370 \reentrant
3371
3372 \brief The QTextImageFormat class provides formatting information for
3373 images in a QTextDocument.
3374 \inmodule QtGui
3375
3376 \ingroup richtext-processing
3377 \ingroup shared
3378
3379 Inline images are represented by a Unicode value U+FFFC (OBJECT
3380 REPLACEMENT CHARACTER) which has an associated QTextImageFormat. The
3381 image format specifies a name with setName() that is used to
3382 locate the image. The size of the rectangle that the image will
3383 occupy is specified in pixels using setWidth() and setHeight().
3384 The desired image quality may be set with setQuality().
3385
3386 Images can be supplied in any format for which Qt has an image
3387 reader, so SVG drawings can be included alongside PNG, TIFF and
3388 other bitmap formats.
3389
3390 \sa QImage, QImageReader
3391*/
3392
3393/*!
3394 \fn QTextImageFormat::QTextImageFormat()
3395
3396 Creates a new image format object.
3397*/
3398QTextImageFormat::QTextImageFormat() : QTextCharFormat() { setObjectType(ImageObject); }
3399
3400/*!
3401 \internal
3402 \fn QTextImageFormat::QTextImageFormat(const QTextFormat &other)
3403
3404 Creates a new image format with the same attributes as the \a given
3405 text format.
3406*/
3407QTextImageFormat::QTextImageFormat(const QTextFormat &fmt)
3408 : QTextCharFormat(fmt)
3409{
3410}
3411
3412/*!
3413 \fn bool QTextImageFormat::isValid() const
3414
3415 Returns \c true if this image format is valid; otherwise returns \c false.
3416*/
3417
3418
3419/*!
3420 \fn void QTextImageFormat::setName(const QString &name)
3421
3422 Sets the \a name of the image. The \a name is used to locate the image
3423 in the application's resources.
3424
3425 \sa name()
3426*/
3427
3428
3429/*!
3430 \fn QString QTextImageFormat::name() const
3431
3432 Returns the name of the image. The name refers to an entry in the
3433 application's resources file.
3434
3435 \sa setName()
3436*/
3437
3438/*!
3439 \fn void QTextImageFormat::setWidth(qreal width)
3440
3441 Sets the \a width of the rectangle occupied by the image.
3442
3443 \sa width(), setHeight(), maximumWidth()
3444*/
3445
3446
3447/*!
3448 \fn qreal QTextImageFormat::width() const
3449
3450 Returns the width of the rectangle occupied by the image.
3451
3452 \sa height(), setWidth()
3453*/
3454
3455/*!
3456 \fn void QTextImageFormat::setMaximumWidth(QTextLength maximumWidth)
3457
3458 Sets the \a maximumWidth of the rectangle occupied by the image. This
3459 can be an absolute number or a percentage of the available document size.
3460
3461 \sa width(), setHeight()
3462*/
3463
3464
3465/*!
3466 \fn QTextLength QTextImageFormat::maximumWidth() const
3467
3468 Returns the maximum width of the rectangle occupied by the image.
3469
3470 \sa width(), setMaximumWidth()
3471*/
3472
3473
3474/*!
3475 \fn void QTextImageFormat::setHeight(qreal height)
3476
3477 Sets the \a height of the rectangle occupied by the image.
3478
3479 \sa height(), setWidth()
3480*/
3481
3482
3483/*!
3484 \fn qreal QTextImageFormat::height() const
3485
3486 Returns the height of the rectangle occupied by the image.
3487
3488 \sa width(), setHeight()
3489*/
3490
3491/*!
3492 \fn void QTextImageFormat::setQuality(int quality = 100)
3493 \since 5.12
3494
3495 Sets the quality that should be used by exporters when exporting the image. QTextDocumentWriter
3496 will export jpg images with the \a quality set here when exporting to ODF files if \a quality is
3497 set to a value between 0 and 100. Or it will export png images if \a quality is set to 100
3498 (default) or greater.
3499
3500 \sa quality()
3501*/
3502
3503
3504/*!
3505 \fn qreal QTextImageFormat::quality() const
3506 \since 5.12
3507
3508 Returns the value set by setQuality().
3509
3510 \sa setQuality()
3511*/
3512
3513/*!
3514 \fn void QTextCharFormat::setFontCapitalization(QFont::Capitalization capitalization)
3515 \since 4.4
3516
3517 Sets the capitalization of the text that appears in this font to \a capitalization.
3518
3519 A font's capitalization makes the text appear in the selected capitalization mode.
3520
3521 \sa fontCapitalization()
3522*/
3523
3524/*!
3525 \fn Capitalization QTextCharFormat::fontCapitalization() const
3526 \since 4.4
3527
3528 Returns the current capitalization type of the font.
3529*/
3530
3531/*!
3532 \fn void QTextCharFormat::setFontLetterSpacingType(QFont::SpacingType letterSpacingType)
3533 \since 5.0
3534
3535 Sets the letter spacing type of this format to \a letterSpacingType.
3536
3537 \sa fontLetterSpacingType()
3538 \sa setFontLetterSpacing()
3539 \sa fontLetterSpacing()
3540*/
3541
3542/*!
3543 \fn QFont::SpacingType QTextCharFormat::fontLetterSpacingType() const
3544 \since 5.0
3545
3546 Returns the letter spacing type of this format..
3547
3548 \sa setFontLetterSpacingType()
3549 \sa setFontLetterSpacing()
3550 \sa fontLetterSpacing()
3551*/
3552
3553/*!
3554 \fn void QTextCharFormat::setFontLetterSpacing(qreal spacing)
3555 \since 4.4
3556
3557 Sets the letter spacing of this format to the given \a spacing. The meaning of the value
3558 depends on the font letter spacing type.
3559
3560 For percentage spacing a value of 100 indicates default spacing; a value of 200 doubles the
3561 amount of space a letter takes.
3562
3563 \sa fontLetterSpacing()
3564 \sa setFontLetterSpacingType()
3565 \sa fontLetterSpacingType()
3566*/
3567
3568/*!
3569 \fn qreal QTextCharFormat::fontLetterSpacing() const
3570 \since 4.4
3571
3572 Returns the current letter spacing.
3573
3574 \sa setFontLetterSpacing()
3575 \sa setFontLetterSpacingType()
3576 \sa fontLetterSpacingType()
3577*/
3578
3579/*!
3580 \fn void QTextCharFormat::setFontWordSpacing(qreal spacing)
3581 \since 4.4
3582
3583 Sets the word spacing of this format to the given \a spacing, in pixels.
3584
3585 \sa fontWordSpacing()
3586*/
3587
3588/*!
3589 \fn qreal QTextCharFormat::fontWordSpacing() const
3590 \since 4.4
3591
3592 Returns the current word spacing value.
3593*/
3594
3595/*!
3596 \fn void QTextCharFormat::setFontStretch(int factor)
3597 \since 5.0
3598
3599 Sets the stretch factor for the font to \a factor.
3600
3601 The stretch factor changes the width of all characters in the font by factor percent. For example, setting \a 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.
3602
3603 The stretch factor is only applied to outline fonts. The stretch factor is ignored for bitmap fonts.
3604
3605 \sa fontStretch()
3606*/
3607
3608/*!
3609 \fn int QTextCharFormat::fontStretch() const
3610 \since 5.0
3611
3612 Returns the current font stretching.
3613 \sa setFontStretch()
3614*/
3615
3616/*!
3617 \fn qreal QTextTableCellFormat::topPadding() const
3618 \since 4.4
3619
3620 Gets the top padding of the table cell.
3621
3622 \sa setTopPadding(), leftPadding(), rightPadding(), bottomPadding()
3623*/
3624
3625/*!
3626 \fn qreal QTextTableCellFormat::bottomPadding() const
3627 \since 4.4
3628
3629 Gets the bottom padding of the table cell.
3630
3631 \sa setBottomPadding(), leftPadding(), rightPadding(), topPadding()
3632*/
3633
3634/*!
3635 \fn qreal QTextTableCellFormat::leftPadding() const
3636 \since 4.4
3637
3638 Gets the left padding of the table cell.
3639
3640 \sa setLeftPadding(), rightPadding(), topPadding(), bottomPadding()
3641*/
3642
3643/*!
3644 \fn qreal QTextTableCellFormat::rightPadding() const
3645 \since 4.4
3646
3647 Gets the right padding of the table cell.
3648
3649 \sa setRightPadding(), leftPadding(), topPadding(), bottomPadding()
3650*/
3651
3652/*!
3653 \fn void QTextTableCellFormat::setTopPadding(qreal padding)
3654 \since 4.4
3655
3656 Sets the top \a padding of the table cell.
3657
3658 \sa topPadding(), setLeftPadding(), setRightPadding(), setBottomPadding()
3659*/
3660
3661/*!
3662 \fn void QTextTableCellFormat::setBottomPadding(qreal padding)
3663 \since 4.4
3664
3665 Sets the bottom \a padding of the table cell.
3666
3667 \sa bottomPadding(), setLeftPadding(), setRightPadding(), setTopPadding()
3668*/
3669
3670/*!
3671 \fn void QTextTableCellFormat::setLeftPadding(qreal padding)
3672 \since 4.4
3673
3674 Sets the left \a padding of the table cell.
3675
3676 \sa leftPadding(), setRightPadding(), setTopPadding(), setBottomPadding()
3677*/
3678
3679/*!
3680 \fn void QTextTableCellFormat::setRightPadding(qreal padding)
3681 \since 4.4
3682
3683 Sets the right \a padding of the table cell.
3684
3685 \sa rightPadding(), setLeftPadding(), setTopPadding(), setBottomPadding()
3686*/
3687
3688/*!
3689 \fn void QTextTableCellFormat::setPadding(qreal padding)
3690 \since 4.4
3691
3692 Sets the left, right, top, and bottom \a padding of the table cell.
3693
3694 \sa setLeftPadding(), setRightPadding(), setTopPadding(), setBottomPadding()
3695*/
3696
3697/*!
3698 \fn void QTextTableCellFormat::setTopBorder(qreal width)
3699 \since 5.14
3700
3701 Sets the top border \a width of the table cell.
3702
3703 \sa QTextTableFormat::setBorderCollapse
3704*/
3705
3706/*!
3707 \fn qreal QTextTableCellFormat::topBorder() const
3708 \since 5.14
3709
3710 Returns the top border width of the table cell.
3711*/
3712
3713/*!
3714 \fn void QTextTableCellFormat::setBottomBorder(qreal width)
3715 \since 5.14
3716
3717 Sets the bottom border \a width of the table cell.
3718
3719 \sa QTextTableFormat::setBorderCollapse
3720*/
3721
3722/*!
3723 \fn qreal QTextTableCellFormat::bottomBorder() const
3724 \since 5.14
3725
3726 Returns the bottom border width of the table cell.
3727*/
3728
3729/*!
3730 \fn void QTextTableCellFormat::setLeftBorder(qreal width)
3731 \since 5.14
3732
3733 Sets the left border \a width of the table cell.
3734
3735 \sa QTextTableFormat::setBorderCollapse
3736*/
3737
3738/*!
3739 \fn qreal QTextTableCellFormat::leftBorder() const
3740 \since 5.14
3741
3742 Returns the left border width of the table cell.
3743*/
3744
3745/*!
3746 \fn void QTextTableCellFormat::setRightBorder(qreal width)
3747 \since 5.14
3748
3749 Sets the right border \a width of the table cell.
3750
3751 \sa QTextTableFormat::setBorderCollapse
3752*/
3753
3754/*!
3755 \fn qreal QTextTableCellFormat::rightBorder() const
3756 \since 5.14
3757
3758 Returns the right border width of the table cell.
3759*/
3760
3761/*!
3762 \fn void QTextTableCellFormat::setBorder(qreal width)
3763 \since 5.14
3764
3765 Sets the left, right, top, and bottom border \a width of the table cell.
3766
3767 \sa setLeftBorder(), setRightBorder(), setTopBorder(), setBottomBorder()
3768 \sa QTextTableFormat::setBorderCollapse
3769*/
3770
3771/*!
3772 \fn void QTextTableCellFormat::setTopBorderStyle(QTextFrameFormat::BorderStyle style)
3773 \since 5.14
3774
3775 Sets the top border \a style of the table cell.
3776
3777 \sa QTextTableFormat::setBorderCollapse
3778*/
3779
3780/*!
3781 \fn QTextFrameFormat::BorderStyle QTextTableCellFormat::topBorderStyle() const
3782 \since 5.14
3783
3784 Returns the top border style of the table cell.
3785*/
3786
3787/*!
3788 \fn void QTextTableCellFormat::setBottomBorderStyle(QTextFrameFormat::BorderStyle style)
3789 \since 5.14
3790
3791 Sets the bottom border \a style of the table cell.
3792
3793 \sa QTextTableFormat::setBorderCollapse
3794*/
3795
3796/*!
3797 \fn QTextFrameFormat::BorderStyle QTextTableCellFormat::bottomBorderStyle() const
3798 \since 5.14
3799
3800 Returns the bottom border style of the table cell.
3801*/
3802
3803/*!
3804 \fn void QTextTableCellFormat::setLeftBorderStyle(QTextFrameFormat::BorderStyle style)
3805 \since 5.14
3806
3807 Sets the left border \a style of the table cell.
3808
3809 \sa QTextTableFormat::setBorderCollapse
3810*/
3811
3812/*!
3813 \fn QTextFrameFormat::BorderStyle QTextTableCellFormat::leftBorderStyle() const
3814 \since 5.14
3815
3816 Returns the left border style of the table cell.
3817*/
3818
3819/*!
3820 \fn void QTextTableCellFormat::setRightBorderStyle(QTextFrameFormat::BorderStyle style)
3821 \since 5.14
3822
3823 Sets the right border \a style of the table cell.
3824
3825 \sa QTextTableFormat::setBorderCollapse
3826*/
3827
3828/*!
3829 \fn QTextFrameFormat::BorderStyle QTextTableCellFormat::rightBorderStyle() const
3830 \since 5.14
3831
3832 Returns the right border style of the table cell.
3833*/
3834
3835/*!
3836 \fn void QTextTableCellFormat::setBorderStyle(QTextFrameFormat::BorderStyle style)
3837 \since 5.14
3838
3839 Sets the left, right, top, and bottom border \a style of the table cell.
3840
3841 \sa setLeftBorderStyle(), setRightBorderStyle(), setTopBorderStyle(), setBottomBorderStyle()
3842 \sa QTextTableFormat::setBorderCollapse
3843*/
3844
3845/*!
3846 \fn void QTextTableCellFormat::setTopBorderBrush(const QBrush &brush)
3847 \since 5.14
3848
3849 Sets the top border \a brush of the table cell.
3850
3851 \sa QTextTableFormat::setBorderCollapse
3852*/
3853
3854/*!
3855 \fn QBrush QTextTableCellFormat::topBorderBrush() const
3856 \since 5.14
3857
3858 Returns the top border brush of the table cell.
3859*/
3860
3861/*!
3862 \fn void QTextTableCellFormat::setBottomBorderBrush(const QBrush &brush)
3863 \since 5.14
3864
3865 Sets the bottom border \a brush of the table cell.
3866
3867 \sa QTextTableFormat::setBorderCollapse
3868*/
3869
3870/*!
3871 \fn QBrush QTextTableCellFormat::bottomBorderBrush() const
3872 \since 5.14
3873
3874 Returns the bottom border brush of the table cell.
3875*/
3876
3877/*!
3878 \fn void QTextTableCellFormat::setLeftBorderBrush(const QBrush &brush)
3879 \since 5.14
3880
3881 Sets the left border \a brush of the table cell.
3882
3883 \sa QTextTableFormat::setBorderCollapse
3884*/
3885
3886/*!
3887 \fn QBrush QTextTableCellFormat::leftBorderBrush() const
3888 \since 5.14
3889
3890 Returns the left border brush of the table cell.
3891*/
3892
3893/*!
3894 \fn void QTextTableCellFormat::setRightBorderBrush(const QBrush &brush)
3895 \since 5.14
3896
3897 Sets the right border \a brush of the table cell.
3898
3899 \sa QTextTableFormat::setBorderCollapse
3900*/
3901
3902/*!
3903 \fn QBrush QTextTableCellFormat::rightBorderBrush() const
3904 \since 5.14
3905
3906 Returns the right border brush of the table cell.
3907*/
3908
3909/*!
3910 \fn void QTextTableCellFormat::setBorderBrush(const QBrush &brush)
3911 \since 5.14
3912
3913 Sets the left, right, top, and bottom border \a brush of the table cell.
3914
3915 \sa setLeftBorderBrush(), setRightBorderBrush(), setTopBorderBrush(), setBottomBorderBrush()
3916 \sa QTextTableFormat::setBorderCollapse
3917*/
3918
3919/*!
3920 \fn bool QTextTableCellFormat::isValid() const
3921 \since 4.4
3922
3923 Returns \c true if this table cell format is valid; otherwise returns \c false.
3924*/
3925
3926/*!
3927 \fn QTextTableCellFormat::QTextTableCellFormat()
3928 \since 4.4
3929
3930 Constructs a new table cell format object.
3931*/
3932QTextTableCellFormat::QTextTableCellFormat()
3933 : QTextCharFormat()
3934{
3935 setObjectType(TableCellObject);
3936}
3937
3938/*!
3939 \internal
3940 \fn QTextTableCellFormat::QTextTableCellFormat(const QTextFormat &other)
3941
3942 Creates a new table cell format with the same attributes as the \a given
3943 text format.
3944*/
3945QTextTableCellFormat::QTextTableCellFormat(const QTextFormat &fmt)
3946 : QTextCharFormat(fmt)
3947{
3948}
3949
3950/*!
3951 \class QTextTableCellFormat
3952 \reentrant
3953 \since 4.4
3954
3955 \brief The QTextTableCellFormat class provides formatting information for
3956 table cells in a QTextDocument.
3957 \inmodule QtGui
3958
3959 \ingroup richtext-processing
3960 \ingroup shared
3961
3962 The table cell format of a table cell in a document specifies the visual
3963 properties of the table cell.
3964
3965 The padding properties of a table cell are controlled by setLeftPadding(),
3966 setRightPadding(), setTopPadding(), and setBottomPadding(). All the paddings
3967 can be set at once using setPadding().
3968
3969 \sa QTextFormat, QTextBlockFormat, QTextTableFormat, QTextCharFormat
3970*/
3971
3972// ------------------------------------------------------
3973
3974QTextFormatCollection::~QTextFormatCollection()
3975{
3976}
3977
3978void QTextFormatCollection::clear()
3979{
3980 formats.clear();
3981 objFormats.clear();
3982 hashes.clear();
3983}
3984
3985int QTextFormatCollection::indexForFormat(const QTextFormat &format)
3986{
3987 size_t hash = getHash(d: format.d, format: format.format_type);
3988 auto i = hashes.constFind(key: hash);
3989 while (i != hashes.constEnd() && i.key() == hash) {
3990 if (formats.value(i: i.value()) == format) {
3991 return i.value();
3992 }
3993 ++i;
3994 }
3995
3996 int idx = formats.size();
3997 formats.append(t: format);
3998
3999 QT_TRY{
4000 QTextFormat &f = formats.last();
4001 if (!f.d)
4002 f.d = new QTextFormatPrivate;
4003 f.d->resolveFont(defaultFont: defaultFnt);
4004
4005 hashes.insert(key: hash, value: idx);
4006
4007 } QT_CATCH(...) {
4008 formats.pop_back();
4009 QT_RETHROW;
4010 }
4011 return idx;
4012}
4013
4014bool QTextFormatCollection::hasFormatCached(const QTextFormat &format) const
4015{
4016 size_t hash = getHash(d: format.d, format: format.format_type);
4017 auto i = hashes.constFind(key: hash);
4018 while (i != hashes.constEnd() && i.key() == hash) {
4019 if (formats.value(i: i.value()) == format) {
4020 return true;
4021 }
4022 ++i;
4023 }
4024 return false;
4025}
4026
4027int QTextFormatCollection::objectFormatIndex(int objectIndex) const
4028{
4029 if (objectIndex == -1 || objectIndex >= objFormats.size())
4030 return -1;
4031 return objFormats.at(i: objectIndex);
4032}
4033
4034void QTextFormatCollection::setObjectFormatIndex(int objectIndex, int formatIndex)
4035{
4036 objFormats[objectIndex] = formatIndex;
4037}
4038
4039int QTextFormatCollection::createObjectIndex(const QTextFormat &f)
4040{
4041 const int objectIndex = objFormats.size();
4042 objFormats.append(t: indexForFormat(format: f));
4043 return objectIndex;
4044}
4045
4046QTextFormat QTextFormatCollection::format(int idx) const
4047{
4048 if (idx < 0 || idx >= formats.size())
4049 return QTextFormat();
4050
4051 return formats.at(i: idx);
4052}
4053
4054void QTextFormatCollection::setDefaultFont(const QFont &f)
4055{
4056 defaultFnt = f;
4057 for (int i = 0; i < formats.size(); ++i)
4058 if (formats.at(i).d)
4059 formats[i].d->resolveFont(defaultFont: defaultFnt);
4060}
4061
4062#ifndef QT_NO_DEBUG_STREAM
4063QDebug operator<<(QDebug dbg, const QTextLength &l)
4064{
4065 QDebugStateSaver saver(dbg);
4066 dbg.nospace() << "QTextLength(QTextLength::Type(" << l.type() << "))";
4067 return dbg;
4068}
4069
4070QDebug operator<<(QDebug dbg, const QTextFormat &f)
4071{
4072 QDebugStateSaver saver(dbg);
4073 dbg.nospace() << "QTextFormat(QTextFormat::FormatType(" << f.type() << "))";
4074 return dbg;
4075}
4076
4077#endif
4078
4079QT_END_NAMESPACE
4080
4081#include "moc_qtextformat.cpp"
4082

source code of qtbase/src/gui/text/qtextformat.cpp