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

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