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