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