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