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

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