Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtextformat.h
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QTEXTFORMAT_H
5#define QTEXTFORMAT_H
6
7#include <QtGui/qbrush.h>
8#include <QtGui/qcolor.h>
9#include <QtGui/qfont.h>
10#include <QtGui/qpen.h>
11#include <QtGui/qtextoption.h>
12#include <QtGui/qtguiglobal.h>
13
14#include <QtCore/qlist.h>
15#include <QtCore/qshareddata.h>
16#include <QtCore/qvariant.h>
17#include <QtCore/qhash.h>
18
20
21
22class QString;
23class QVariant;
24class QFont;
25
26class QTextFormatCollection;
28class QTextBlockFormat;
29class QTextCharFormat;
30class QTextListFormat;
31class QTextTableFormat;
32class QTextFrameFormat;
33class QTextImageFormat;
34class QTextTableCellFormat;
35class QTextFormat;
36class QTextObject;
37class QTextCursor;
38class QTextDocument;
39class QTextLength;
40
41#ifndef QT_NO_DEBUG_STREAM
42Q_GUI_EXPORT QDebug operator<<(QDebug, const QTextLength &);
43#endif
44
45class Q_GUI_EXPORT QTextLength
46{
47public:
48 enum Type { VariableLength = 0, FixedLength, PercentageLength };
49
50 inline QTextLength() : lengthType(VariableLength), fixedValueOrPercentage(0) {}
51
52 inline explicit QTextLength(Type type, qreal value);
53
54 inline Type type() const { return lengthType; }
55 inline qreal value(qreal maximumLength) const
56 {
57 switch (lengthType) {
58 case FixedLength: return fixedValueOrPercentage;
59 case VariableLength: return maximumLength;
60 case PercentageLength: return fixedValueOrPercentage * maximumLength / qreal(100);
61 }
62 return -1;
63 }
64
65 inline qreal rawValue() const { return fixedValueOrPercentage; }
66
67 inline bool operator==(const QTextLength &other) const
68 { return lengthType == other.lengthType
69 && qFuzzyCompare(fixedValueOrPercentage, other.fixedValueOrPercentage); }
70 inline bool operator!=(const QTextLength &other) const
71 { return lengthType != other.lengthType
72 || !qFuzzyCompare(fixedValueOrPercentage, other.fixedValueOrPercentage); }
73 operator QVariant() const;
74
75private:
76 Type lengthType;
77 qreal fixedValueOrPercentage;
78 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextLength &);
79 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextLength &);
80};
82
83inline QTextLength::QTextLength(Type atype, qreal avalue)
84 : lengthType(atype), fixedValueOrPercentage(avalue) {}
85
86#ifndef QT_NO_DEBUG_STREAM
87Q_GUI_EXPORT QDebug operator<<(QDebug, const QTextFormat &);
88#endif
89
90class Q_GUI_EXPORT QTextFormat
91{
92 Q_GADGET
93public:
94 enum FormatType {
95 InvalidFormat = -1,
96 BlockFormat = 1,
97 CharFormat = 2,
98 ListFormat = 3,
99 FrameFormat = 5,
100
101 UserFormat = 100
102 };
103 Q_ENUM(FormatType)
104
105 enum Property {
106 ObjectIndex = 0x0,
107
108 // paragraph and char
109 CssFloat = 0x0800,
110 LayoutDirection = 0x0801,
111
112 OutlinePen = 0x810,
113 BackgroundBrush = 0x820,
114 ForegroundBrush = 0x821,
115 // Internal to qtextlayout.cpp: ObjectSelectionBrush = 0x822
116 BackgroundImageUrl = 0x823,
117
118 // paragraph
119 BlockAlignment = 0x1010,
120 BlockTopMargin = 0x1030,
121 BlockBottomMargin = 0x1031,
122 BlockLeftMargin = 0x1032,
123 BlockRightMargin = 0x1033,
124 TextIndent = 0x1034,
125 TabPositions = 0x1035,
126 BlockIndent = 0x1040,
127 LineHeight = 0x1048,
128 LineHeightType = 0x1049,
129 BlockNonBreakableLines = 0x1050,
130 BlockTrailingHorizontalRulerWidth = 0x1060,
131 HeadingLevel = 0x1070,
132 BlockQuoteLevel = 0x1080,
133 BlockCodeLanguage = 0x1090,
134 BlockCodeFence = 0x1091,
135 BlockMarker = 0x10A0,
136
137 // character properties
138 FirstFontProperty = 0x1FE0,
139 FontCapitalization = FirstFontProperty,
140 FontLetterSpacing = 0x1FE1,
141 FontWordSpacing = 0x1FE2,
142 FontStyleHint = 0x1FE3,
143 FontStyleStrategy = 0x1FE4,
144 FontKerning = 0x1FE5,
145 FontHintingPreference = 0x1FE6,
146 FontFamilies = 0x1FE7,
147 FontStyleName = 0x1FE8,
148 FontLetterSpacingType = 0x1FE9,
149 FontStretch = 0x1FEA,
150#if QT_DEPRECATED_SINCE(6, 0)
151 FontFamily = 0x2000,
152#endif
153 FontPointSize = 0x2001,
154 FontSizeAdjustment = 0x2002,
155 FontSizeIncrement = FontSizeAdjustment, // old name, compat
156 FontWeight = 0x2003,
157 FontItalic = 0x2004,
158 FontUnderline = 0x2005, // deprecated, use TextUnderlineStyle instead
159 FontOverline = 0x2006,
160 FontStrikeOut = 0x2007,
161 FontFixedPitch = 0x2008,
162 FontPixelSize = 0x2009,
163 FontFeatures = 0x2010, // Note: Same as OldTextUnderlineColor
164 FontVariableAxes = 0x2011,
165 LastFontProperty = FontVariableAxes,
166
167 TextUnderlineColor = 0x2020,
168 TextVerticalAlignment = 0x2021,
169 TextOutline = 0x2022,
170 TextUnderlineStyle = 0x2023,
171 TextToolTip = 0x2024,
172 TextSuperScriptBaseline = 0x2025,
173 TextSubScriptBaseline = 0x2026,
174 TextBaselineOffset = 0x2027,
175
176 IsAnchor = 0x2030,
177 AnchorHref = 0x2031,
178 AnchorName = 0x2032,
179
180 // Included for backwards compatibility with old QDataStreams.
181 // Should not be referenced in user code.
182 OldFontLetterSpacingType = 0x2033,
183 OldFontStretch = 0x2034,
184 OldTextUnderlineColor = 0x2010,
185 OldFontFamily = 0x2000, // same as FontFamily
186
187 ObjectType = 0x2f00,
188
189 // list properties
190 ListStyle = 0x3000,
191 ListIndent = 0x3001,
192 ListNumberPrefix = 0x3002,
193 ListNumberSuffix = 0x3003,
194 ListStart = 0x3004,
195
196 // table and frame properties
197 FrameBorder = 0x4000,
198 FrameMargin = 0x4001,
199 FramePadding = 0x4002,
200 FrameWidth = 0x4003,
201 FrameHeight = 0x4004,
202 FrameTopMargin = 0x4005,
203 FrameBottomMargin = 0x4006,
204 FrameLeftMargin = 0x4007,
205 FrameRightMargin = 0x4008,
206 FrameBorderBrush = 0x4009,
207 FrameBorderStyle = 0x4010,
208
209 TableColumns = 0x4100,
210 TableColumnWidthConstraints = 0x4101,
211 TableCellSpacing = 0x4102,
212 TableCellPadding = 0x4103,
213 TableHeaderRowCount = 0x4104,
214 TableBorderCollapse = 0x4105,
215
216 // table cell properties
217 TableCellRowSpan = 0x4810,
218 TableCellColumnSpan = 0x4811,
219
220 TableCellTopPadding = 0x4812,
221 TableCellBottomPadding = 0x4813,
222 TableCellLeftPadding = 0x4814,
223 TableCellRightPadding = 0x4815,
224
225 TableCellTopBorder = 0x4816,
226 TableCellBottomBorder = 0x4817,
227 TableCellLeftBorder = 0x4818,
228 TableCellRightBorder = 0x4819,
229
230 TableCellTopBorderStyle = 0x481a,
231 TableCellBottomBorderStyle = 0x481b,
232 TableCellLeftBorderStyle = 0x481c,
233 TableCellRightBorderStyle = 0x481d,
234
235 TableCellTopBorderBrush = 0x481e,
236 TableCellBottomBorderBrush = 0x481f,
237 TableCellLeftBorderBrush = 0x4820,
238 TableCellRightBorderBrush = 0x4821,
239
240 // image properties
241 ImageName = 0x5000,
242 ImageTitle = 0x5001,
243 ImageAltText = 0x5002,
244 ImageWidth = 0x5010,
245 ImageHeight = 0x5011,
246 ImageQuality = 0x5014,
247 ImageMaxWidth = 0x5015,
248
249 // internal
250 /*
251 SuppressText = 0x5012,
252 SuppressBackground = 0x513
253 */
254
255 // selection properties
256 FullWidthSelection = 0x06000,
257
258 // page break properties
259 PageBreakPolicy = 0x7000,
260
261 // --
262 UserProperty = 0x100000
263 };
264 Q_ENUM(Property)
265
266 enum ObjectTypes {
267 NoObject,
268 ImageObject,
269 TableObject,
270 TableCellObject,
271
272 UserObject = 0x1000
273 };
274 Q_ENUM(ObjectTypes)
275
276 enum PageBreakFlag {
277 PageBreak_Auto = 0,
278 PageBreak_AlwaysBefore = 0x001,
279 PageBreak_AlwaysAfter = 0x010
280 // PageBreak_AlwaysInside = 0x100
281 };
282 Q_DECLARE_FLAGS(PageBreakFlags, PageBreakFlag)
283
284 QTextFormat();
285
286 explicit QTextFormat(int type);
287
288 QTextFormat(const QTextFormat &rhs);
289 QTextFormat &operator=(const QTextFormat &rhs);
290 ~QTextFormat();
291
292 void swap(QTextFormat &other)
293 { d.swap(other.d); std::swap(format_type, other.format_type); }
294
295 void merge(const QTextFormat &other);
296
297 inline bool isValid() const { return type() != InvalidFormat; }
298 inline bool isEmpty() const { return propertyCount() == 0; }
299
300 int type() const;
301
302 int objectIndex() const;
303 void setObjectIndex(int object);
304
305 QVariant property(int propertyId) const;
306 void setProperty(int propertyId, const QVariant &value);
307 void clearProperty(int propertyId);
308 bool hasProperty(int propertyId) const;
309
310 bool boolProperty(int propertyId) const;
311 int intProperty(int propertyId) const;
312 qreal doubleProperty(int propertyId) const;
313 QString stringProperty(int propertyId) const;
314 QColor colorProperty(int propertyId) const;
315 QPen penProperty(int propertyId) const;
316 QBrush brushProperty(int propertyId) const;
317 QTextLength lengthProperty(int propertyId) const;
318 QList<QTextLength> lengthVectorProperty(int propertyId) const;
319
320 void setProperty(int propertyId, const QList<QTextLength> &lengths);
321
322 QMap<int, QVariant> properties() const;
323 int propertyCount() const;
324
325 inline void setObjectType(int type);
326 inline int objectType() const
327 { return intProperty(ObjectType); }
328
329 inline bool isCharFormat() const { return type() == CharFormat; }
330 inline bool isBlockFormat() const { return type() == BlockFormat; }
331 inline bool isListFormat() const { return type() == ListFormat; }
332 inline bool isFrameFormat() const { return type() == FrameFormat; }
333 inline bool isImageFormat() const { return type() == CharFormat && objectType() == ImageObject; }
334 inline bool isTableFormat() const { return type() == FrameFormat && objectType() == TableObject; }
335 inline bool isTableCellFormat() const { return type() == CharFormat && objectType() == TableCellObject; }
336
337 QTextBlockFormat toBlockFormat() const;
338 QTextCharFormat toCharFormat() const;
339 QTextListFormat toListFormat() const;
340 QTextTableFormat toTableFormat() const;
341 QTextFrameFormat toFrameFormat() const;
342 QTextImageFormat toImageFormat() const;
343 QTextTableCellFormat toTableCellFormat() const;
344
345 bool operator==(const QTextFormat &rhs) const;
346 inline bool operator!=(const QTextFormat &rhs) const { return !operator==(rhs); }
347 operator QVariant() const;
348
349 inline void setLayoutDirection(Qt::LayoutDirection direction)
350 { setProperty(QTextFormat::LayoutDirection, direction); }
351 inline Qt::LayoutDirection layoutDirection() const
352 { return Qt::LayoutDirection(intProperty(QTextFormat::LayoutDirection)); }
353
354 inline void setBackground(const QBrush &brush)
355 { setProperty(BackgroundBrush, brush); }
356 inline QBrush background() const
357 { return brushProperty(BackgroundBrush); }
358 inline void clearBackground()
359 { clearProperty(BackgroundBrush); }
360
361 inline void setForeground(const QBrush &brush)
362 { setProperty(ForegroundBrush, brush); }
363 inline QBrush foreground() const
364 { return brushProperty(ForegroundBrush); }
365 inline void clearForeground()
366 { clearProperty(ForegroundBrush); }
367
368private:
369 QSharedDataPointer<QTextFormatPrivate> d;
370 qint32 format_type;
371
372 friend class QTextFormatCollection;
373 friend class QTextCharFormat;
374 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextFormat &);
375 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextFormat &);
376};
377
379
380inline void QTextFormat::setObjectType(int atype)
381{ setProperty(ObjectType, atype); }
382
383Q_DECLARE_OPERATORS_FOR_FLAGS(QTextFormat::PageBreakFlags)
384
385class Q_GUI_EXPORT QTextCharFormat : public QTextFormat
386{
387public:
388 enum VerticalAlignment {
389 AlignNormal = 0,
390 AlignSuperScript,
391 AlignSubScript,
392 AlignMiddle,
393 AlignTop,
394 AlignBottom,
395 AlignBaseline
396 };
397 enum UnderlineStyle { // keep in sync with Qt::PenStyle!
398 NoUnderline,
399 SingleUnderline,
400 DashUnderline,
401 DotLine,
402 DashDotLine,
403 DashDotDotLine,
404 WaveUnderline,
405 SpellCheckUnderline
406 };
407
408 QTextCharFormat();
409
410 bool isValid() const { return isCharFormat(); }
411
412 enum FontPropertiesInheritanceBehavior {
413 FontPropertiesSpecifiedOnly,
414 FontPropertiesAll
415 };
416 void setFont(const QFont &font, FontPropertiesInheritanceBehavior behavior = FontPropertiesAll);
417 QFont font() const;
418
419#if QT_DEPRECATED_SINCE(6, 1)
420 QT_DEPRECATED_VERSION_X_6_1("Use setFontFamilies instead") inline void setFontFamily(const QString &family)
421 { setProperty(FontFamilies, QVariant(QStringList(family))); }
422 QT_DEPRECATED_VERSION_X_6_1("Use fontFamilies instead") inline QString fontFamily() const
423 { return property(FontFamilies).toStringList().first(); }
424#endif
425
426 inline void setFontFamilies(const QStringList &families)
427 { setProperty(FontFamilies, QVariant(families)); }
428#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
429 inline QVariant fontFamilies() const
430 { return property(FontFamilies); }
431#else
432 inline QStringList fontFamilies() const
433 { return property(FontFamilies).toStringList(); }
434#endif
435
436 inline void setFontStyleName(const QString &styleName)
437 { setProperty(FontStyleName, styleName); }
438#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
439 inline QVariant fontStyleName() const
440 { return property(FontStyleName); }
441#else
442 inline QStringList fontStyleName() const
443 { return property(FontStyleName).toStringList(); }
444#endif
445
446 inline void setFontPointSize(qreal size)
447 { setProperty(FontPointSize, size); }
448 inline qreal fontPointSize() const
449 { return doubleProperty(FontPointSize); }
450
451 inline void setFontWeight(int weight)
452 { setProperty(FontWeight, weight); }
453 inline int fontWeight() const
454 { return hasProperty(FontWeight) ? intProperty(FontWeight) : QFont::Normal; }
455 inline void setFontItalic(bool italic)
456 { setProperty(FontItalic, italic); }
457 inline bool fontItalic() const
458 { return boolProperty(FontItalic); }
459 inline void setFontCapitalization(QFont::Capitalization capitalization)
460 { setProperty(FontCapitalization, capitalization); }
461 inline QFont::Capitalization fontCapitalization() const
462 { return static_cast<QFont::Capitalization>(intProperty(FontCapitalization)); }
463 inline void setFontLetterSpacingType(QFont::SpacingType letterSpacingType)
464 { setProperty(FontLetterSpacingType, letterSpacingType); }
465 inline QFont::SpacingType fontLetterSpacingType() const
466 { return static_cast<QFont::SpacingType>(intProperty(FontLetterSpacingType)); }
467 inline void setFontLetterSpacing(qreal spacing)
468 { setProperty(FontLetterSpacing, spacing); }
469 inline qreal fontLetterSpacing() const
470 { return doubleProperty(FontLetterSpacing); }
471 inline void setFontWordSpacing(qreal spacing)
472 { setProperty(FontWordSpacing, spacing); }
473 inline qreal fontWordSpacing() const
474 { return doubleProperty(FontWordSpacing); }
475
476 inline void setFontUnderline(bool underline)
477 { setProperty(TextUnderlineStyle, underline ? SingleUnderline : NoUnderline); }
478 bool fontUnderline() const;
479
480 inline void setFontOverline(bool overline)
481 { setProperty(FontOverline, overline); }
482 inline bool fontOverline() const
483 { return boolProperty(FontOverline); }
484
485 inline void setFontStrikeOut(bool strikeOut)
486 { setProperty(FontStrikeOut, strikeOut); }
487 inline bool fontStrikeOut() const
488 { return boolProperty(FontStrikeOut); }
489
490 inline void setUnderlineColor(const QColor &color)
491 { setProperty(TextUnderlineColor, color); }
492 inline QColor underlineColor() const
493 { return colorProperty(TextUnderlineColor); }
494
495 inline void setFontFixedPitch(bool fixedPitch)
496 { setProperty(FontFixedPitch, fixedPitch); }
497 inline bool fontFixedPitch() const
498 { return boolProperty(FontFixedPitch); }
499
500 inline void setFontStretch(int factor)
501 { setProperty(FontStretch, factor); }
502 inline int fontStretch() const
503 { return intProperty(FontStretch); }
504
505 inline void setFontStyleHint(QFont::StyleHint hint, QFont::StyleStrategy strategy = QFont::PreferDefault)
506 { setProperty(FontStyleHint, hint); setProperty(FontStyleStrategy, strategy); }
507 inline void setFontStyleStrategy(QFont::StyleStrategy strategy)
508 { setProperty(FontStyleStrategy, strategy); }
509 QFont::StyleHint fontStyleHint() const
510 { return static_cast<QFont::StyleHint>(intProperty(FontStyleHint)); }
511 QFont::StyleStrategy fontStyleStrategy() const
512 { return static_cast<QFont::StyleStrategy>(intProperty(FontStyleStrategy)); }
513
514 inline void setFontHintingPreference(QFont::HintingPreference hintingPreference)
515 {
516 setProperty(FontHintingPreference, hintingPreference);
517 }
518
519 inline QFont::HintingPreference fontHintingPreference() const
520 {
521 return static_cast<QFont::HintingPreference>(intProperty(FontHintingPreference));
522 }
523
524 void setFontFeatures(const QHash<QFont::Tag, quint32> &fontFeatures);
525 QHash<QFont::Tag, quint32> fontFeatures() const;
526 void setFontVariableAxes(const QHash<QFont::Tag, float> &fontVariableAxes);
527 QHash<QFont::Tag, float> fontVariableAxes() const;
528
529 inline void setFontKerning(bool enable)
530 { setProperty(FontKerning, enable); }
531 inline bool fontKerning() const
532 { return boolProperty(FontKerning); }
533
534 void setUnderlineStyle(UnderlineStyle style);
535 inline UnderlineStyle underlineStyle() const
536 { return static_cast<UnderlineStyle>(intProperty(TextUnderlineStyle)); }
537
538 inline void setVerticalAlignment(VerticalAlignment alignment)
539 { setProperty(TextVerticalAlignment, alignment); }
540 inline VerticalAlignment verticalAlignment() const
541 { return static_cast<VerticalAlignment>(intProperty(TextVerticalAlignment)); }
542
543 inline void setTextOutline(const QPen &pen)
544 { setProperty(TextOutline, pen); }
545 inline QPen textOutline() const
546 { return penProperty(TextOutline); }
547
548 inline void setToolTip(const QString &tip)
549 { setProperty(TextToolTip, tip); }
550 inline QString toolTip() const
551 { return stringProperty(TextToolTip); }
552
553 inline void setSuperScriptBaseline(qreal baseline)
554 { setProperty(TextSuperScriptBaseline, baseline); }
555 inline qreal superScriptBaseline() const
556 { return hasProperty(TextSuperScriptBaseline) ? doubleProperty(TextSuperScriptBaseline) : 50.0; }
557
558 inline void setSubScriptBaseline(qreal baseline)
559 { setProperty(TextSubScriptBaseline, baseline); }
560 inline qreal subScriptBaseline() const
561 { return hasProperty(TextSubScriptBaseline) ? doubleProperty(TextSubScriptBaseline) : 100.0 / 6.0; }
562
563 inline void setBaselineOffset(qreal baseline)
564 { setProperty(TextBaselineOffset, baseline); }
565 inline qreal baselineOffset() const
566 { return hasProperty(TextBaselineOffset) ? doubleProperty(TextBaselineOffset) : 0.0; }
567
568 inline void setAnchor(bool anchor)
569 { setProperty(IsAnchor, anchor); }
570 inline bool isAnchor() const
571 { return boolProperty(IsAnchor); }
572
573 inline void setAnchorHref(const QString &value)
574 { setProperty(AnchorHref, value); }
575 inline QString anchorHref() const
576 { return stringProperty(AnchorHref); }
577
578 inline void setAnchorNames(const QStringList &names)
579 { setProperty(AnchorName, names); }
580 QStringList anchorNames() const;
581
582 inline void setTableCellRowSpan(int tableCellRowSpan);
583 inline int tableCellRowSpan() const
584 { int s = intProperty(TableCellRowSpan); if (s == 0) s = 1; return s; }
585 inline void setTableCellColumnSpan(int tableCellColumnSpan);
586 inline int tableCellColumnSpan() const
587 { int s = intProperty(TableCellColumnSpan); if (s == 0) s = 1; return s; }
588
589protected:
590 explicit QTextCharFormat(const QTextFormat &fmt);
591 friend class QTextFormat;
592 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextCharFormat &);
593 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextCharFormat &);
594};
595
596Q_DECLARE_SHARED(QTextCharFormat)
597
598inline void QTextCharFormat::setTableCellRowSpan(int _tableCellRowSpan)
599{
600 if (_tableCellRowSpan <= 1)
601 clearProperty(TableCellRowSpan); // the getter will return 1 here.
602 else
603 setProperty(TableCellRowSpan, _tableCellRowSpan);
604}
605
606inline void QTextCharFormat::setTableCellColumnSpan(int _tableCellColumnSpan)
607{
608 if (_tableCellColumnSpan <= 1)
609 clearProperty(TableCellColumnSpan); // the getter will return 1 here.
610 else
611 setProperty(TableCellColumnSpan, _tableCellColumnSpan);
612}
613
614class Q_GUI_EXPORT QTextBlockFormat : public QTextFormat
615{
616public:
617 enum LineHeightTypes {
618 SingleHeight = 0,
619 ProportionalHeight = 1,
620 FixedHeight = 2,
621 MinimumHeight = 3,
622 LineDistanceHeight = 4
623 };
624
625 enum class MarkerType {
626 NoMarker = 0,
627 Unchecked = 1,
628 Checked = 2
629 };
630
631 QTextBlockFormat();
632
633 bool isValid() const { return isBlockFormat(); }
634
635 inline void setAlignment(Qt::Alignment alignment);
636 inline Qt::Alignment alignment() const
637 { int a = intProperty(BlockAlignment); if (a == 0) a = Qt::AlignLeft; return QFlag(a); }
638
639 inline void setTopMargin(qreal margin)
640 { setProperty(BlockTopMargin, margin); }
641 inline qreal topMargin() const
642 { return doubleProperty(BlockTopMargin); }
643
644 inline void setBottomMargin(qreal margin)
645 { setProperty(BlockBottomMargin, margin); }
646 inline qreal bottomMargin() const
647 { return doubleProperty(BlockBottomMargin); }
648
649 inline void setLeftMargin(qreal margin)
650 { setProperty(BlockLeftMargin, margin); }
651 inline qreal leftMargin() const
652 { return doubleProperty(BlockLeftMargin); }
653
654 inline void setRightMargin(qreal margin)
655 { setProperty(BlockRightMargin, margin); }
656 inline qreal rightMargin() const
657 { return doubleProperty(BlockRightMargin); }
658
659 inline void setTextIndent(qreal aindent)
660 { setProperty(TextIndent, aindent); }
661 inline qreal textIndent() const
662 { return doubleProperty(TextIndent); }
663
664 inline void setIndent(int indent);
665 inline int indent() const
666 { return intProperty(BlockIndent); }
667
668 inline void setHeadingLevel(int alevel)
669 { setProperty(HeadingLevel, alevel); }
670 inline int headingLevel() const
671 { return intProperty(HeadingLevel); }
672
673 inline void setLineHeight(qreal height, int heightType)
674 { setProperty(LineHeight, height); setProperty(LineHeightType, heightType); }
675 inline qreal lineHeight(qreal scriptLineHeight, qreal scaling) const;
676 inline qreal lineHeight() const
677 { return doubleProperty(LineHeight); }
678 inline int lineHeightType() const
679 { return intProperty(LineHeightType); }
680
681 inline void setNonBreakableLines(bool b)
682 { setProperty(BlockNonBreakableLines, b); }
683 inline bool nonBreakableLines() const
684 { return boolProperty(BlockNonBreakableLines); }
685
686 inline void setPageBreakPolicy(PageBreakFlags flags)
687 { setProperty(PageBreakPolicy, int(flags.toInt())); }
688 inline PageBreakFlags pageBreakPolicy() const
689 { return PageBreakFlags(intProperty(PageBreakPolicy)); }
690
691 void setTabPositions(const QList<QTextOption::Tab> &tabs);
692 QList<QTextOption::Tab> tabPositions() const;
693
694 inline void setMarker(MarkerType marker)
695 { setProperty(BlockMarker, int(marker)); }
696 inline MarkerType marker() const
697 { return MarkerType(intProperty(BlockMarker)); }
698
699protected:
700 explicit QTextBlockFormat(const QTextFormat &fmt);
701 friend class QTextFormat;
702 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextBlockFormat &);
703 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextBlockFormat &);
704};
705
707
708inline void QTextBlockFormat::setAlignment(Qt::Alignment aalignment)
709{ setProperty(BlockAlignment, int(aalignment.toInt())); }
710
711inline void QTextBlockFormat::setIndent(int aindent)
712{ setProperty(BlockIndent, aindent); }
713
714inline qreal QTextBlockFormat::lineHeight(qreal scriptLineHeight, qreal scaling = 1.0) const
715{
716 switch(intProperty(LineHeightType)) {
717 case SingleHeight:
718 return(scriptLineHeight);
719 case ProportionalHeight:
720 return(scriptLineHeight * doubleProperty(LineHeight) / 100.0);
721 case FixedHeight:
722 return(doubleProperty(LineHeight) * scaling);
723 case MinimumHeight:
724 return(qMax(scriptLineHeight, doubleProperty(LineHeight) * scaling));
725 case LineDistanceHeight:
726 return(scriptLineHeight + doubleProperty(LineHeight) * scaling);
727 }
728 return(0);
729}
730
731class Q_GUI_EXPORT QTextListFormat : public QTextFormat
732{
733public:
734 QTextListFormat();
735
736 bool isValid() const { return isListFormat(); }
737
738 enum Style {
739 ListDisc = -1,
740 ListCircle = -2,
741 ListSquare = -3,
742 ListDecimal = -4,
743 ListLowerAlpha = -5,
744 ListUpperAlpha = -6,
745 ListLowerRoman = -7,
746 ListUpperRoman = -8,
747 ListStyleUndefined = 0
748 };
749
750 inline void setStyle(Style style);
751 inline Style style() const
752 { return static_cast<Style>(intProperty(ListStyle)); }
753
754 inline void setIndent(int indent);
755 inline int indent() const
756 { return intProperty(ListIndent); }
757
758 inline void setNumberPrefix(const QString &numberPrefix);
759 inline QString numberPrefix() const
760 { return stringProperty(ListNumberPrefix); }
761
762 inline void setNumberSuffix(const QString &numberSuffix);
763 inline QString numberSuffix() const
764 { return stringProperty(ListNumberSuffix); }
765
766 inline void setStart(int indent);
767 inline int start() const { return intProperty(ListStart); }
768
769protected:
770 explicit QTextListFormat(const QTextFormat &fmt);
771 friend class QTextFormat;
772};
773
775
776inline void QTextListFormat::setStyle(Style astyle)
777{ setProperty(ListStyle, astyle); }
778
779inline void QTextListFormat::setIndent(int aindent)
780{ setProperty(ListIndent, aindent); }
781
782inline void QTextListFormat::setNumberPrefix(const QString &np)
783{ setProperty(ListNumberPrefix, np); }
784
785inline void QTextListFormat::setNumberSuffix(const QString &ns)
786{ setProperty(ListNumberSuffix, ns); }
787
788inline void QTextListFormat::setStart(int astart)
789{
790 setProperty(ListStart, astart);
791}
792
793class Q_GUI_EXPORT QTextImageFormat : public QTextCharFormat
794{
795public:
796 QTextImageFormat();
797
798 bool isValid() const { return isImageFormat(); }
799
800 inline void setName(const QString &name);
801 inline QString name() const
802 { return stringProperty(ImageName); }
803
804 inline void setWidth(qreal width);
805 inline qreal width() const
806 { return doubleProperty(ImageWidth); }
807
808 inline void setMaximumWidth(QTextLength maxWidth);
809 inline QTextLength maximumWidth() const
810 { return lengthProperty(ImageMaxWidth); }
811
812 inline void setHeight(qreal height);
813 inline qreal height() const
814 { return doubleProperty(ImageHeight); }
815
816 inline void setQuality(int quality);
817#if QT_DEPRECATED_SINCE(6, 3)
818 QT_DEPRECATED_VERSION_X_6_3("Pass a quality value, the default is 100") inline void setQuality()
819 { setQuality(100); }
820#endif
821 inline int quality() const
822 { return intProperty(ImageQuality); }
823
824protected:
825 explicit QTextImageFormat(const QTextFormat &format);
826 friend class QTextFormat;
827 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextListFormat &);
828 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextListFormat &);
829};
830
832
833inline void QTextImageFormat::setName(const QString &aname)
834{ setProperty(ImageName, aname); }
835
836inline void QTextImageFormat::setWidth(qreal awidth)
837{ setProperty(ImageWidth, awidth); }
838
839inline void QTextImageFormat::setMaximumWidth(QTextLength maxWidth)
840{ setProperty(ImageMaxWidth, maxWidth); }
841
842inline void QTextImageFormat::setHeight(qreal aheight)
843{ setProperty(ImageHeight, aheight); }
844
845inline void QTextImageFormat::setQuality(int aquality)
846{ setProperty(ImageQuality, aquality); }
847
848class Q_GUI_EXPORT QTextFrameFormat : public QTextFormat
849{
850public:
851 QTextFrameFormat();
852
853 bool isValid() const { return isFrameFormat(); }
854
855 enum Position {
856 InFlow,
857 FloatLeft,
858 FloatRight
859 // ######
860// Absolute
861 };
862
863 enum BorderStyle {
864 BorderStyle_None,
865 BorderStyle_Dotted,
866 BorderStyle_Dashed,
867 BorderStyle_Solid,
868 BorderStyle_Double,
869 BorderStyle_DotDash,
870 BorderStyle_DotDotDash,
871 BorderStyle_Groove,
872 BorderStyle_Ridge,
873 BorderStyle_Inset,
874 BorderStyle_Outset
875 };
876
877 inline void setPosition(Position f)
878 { setProperty(CssFloat, f); }
879 inline Position position() const
880 { return static_cast<Position>(intProperty(CssFloat)); }
881
882 inline void setBorder(qreal border);
883 inline qreal border() const
884 { return doubleProperty(FrameBorder); }
885
886 inline void setBorderBrush(const QBrush &brush)
887 { setProperty(FrameBorderBrush, brush); }
888 inline QBrush borderBrush() const
889 { return brushProperty(FrameBorderBrush); }
890
891 inline void setBorderStyle(BorderStyle style)
892 { setProperty(FrameBorderStyle, style); }
893 inline BorderStyle borderStyle() const
894 { return static_cast<BorderStyle>(intProperty(FrameBorderStyle)); }
895
896 void setMargin(qreal margin);
897 inline qreal margin() const
898 { return doubleProperty(FrameMargin); }
899
900 inline void setTopMargin(qreal margin);
901 qreal topMargin() const;
902
903 inline void setBottomMargin(qreal margin);
904 qreal bottomMargin() const;
905
906 inline void setLeftMargin(qreal margin);
907 qreal leftMargin() const;
908
909 inline void setRightMargin(qreal margin);
910 qreal rightMargin() const;
911
912 inline void setPadding(qreal padding);
913 inline qreal padding() const
914 { return doubleProperty(FramePadding); }
915
916 inline void setWidth(qreal width);
917 inline void setWidth(const QTextLength &length)
918 { setProperty(FrameWidth, length); }
919 inline QTextLength width() const
920 { return lengthProperty(FrameWidth); }
921
922 inline void setHeight(qreal height);
923 inline void setHeight(const QTextLength &height);
924 inline QTextLength height() const
925 { return lengthProperty(FrameHeight); }
926
927 inline void setPageBreakPolicy(PageBreakFlags flags)
928 { setProperty(PageBreakPolicy, int(flags.toInt())); }
929 inline PageBreakFlags pageBreakPolicy() const
930 { return PageBreakFlags(intProperty(PageBreakPolicy)); }
931
932protected:
933 explicit QTextFrameFormat(const QTextFormat &fmt);
934 friend class QTextFormat;
935 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextFrameFormat &);
936 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextFrameFormat &);
937};
938
940
941inline void QTextFrameFormat::setBorder(qreal aborder)
942{ setProperty(FrameBorder, aborder); }
943
944inline void QTextFrameFormat::setPadding(qreal apadding)
945{ setProperty(FramePadding, apadding); }
946
947inline void QTextFrameFormat::setWidth(qreal awidth)
948{ setProperty(FrameWidth, QTextLength(QTextLength::FixedLength, awidth)); }
949
950inline void QTextFrameFormat::setHeight(qreal aheight)
951{ setProperty(FrameHeight, QTextLength(QTextLength::FixedLength, aheight)); }
952inline void QTextFrameFormat::setHeight(const QTextLength &aheight)
953{ setProperty(FrameHeight, aheight); }
954
955inline void QTextFrameFormat::setTopMargin(qreal amargin)
956{ setProperty(FrameTopMargin, amargin); }
957
958inline void QTextFrameFormat::setBottomMargin(qreal amargin)
959{ setProperty(FrameBottomMargin, amargin); }
960
961inline void QTextFrameFormat::setLeftMargin(qreal amargin)
962{ setProperty(FrameLeftMargin, amargin); }
963
964inline void QTextFrameFormat::setRightMargin(qreal amargin)
965{ setProperty(FrameRightMargin, amargin); }
966
967class Q_GUI_EXPORT QTextTableFormat : public QTextFrameFormat
968{
969public:
970 QTextTableFormat();
971
972 inline bool isValid() const { return isTableFormat(); }
973
974 inline int columns() const
975 { int cols = intProperty(TableColumns); if (cols == 0) cols = 1; return cols; }
976 inline void setColumns(int columns);
977
978 inline void setColumnWidthConstraints(const QList<QTextLength> &constraints)
979 { setProperty(TableColumnWidthConstraints, constraints); }
980
981 inline QList<QTextLength> columnWidthConstraints() const
982 { return lengthVectorProperty(TableColumnWidthConstraints); }
983
984 inline void clearColumnWidthConstraints()
985 { clearProperty(TableColumnWidthConstraints); }
986
987 inline qreal cellSpacing() const
988 { return doubleProperty(TableCellSpacing); }
989 inline void setCellSpacing(qreal spacing)
990 { setProperty(TableCellSpacing, spacing); }
991
992 inline qreal cellPadding() const
993 { return doubleProperty(TableCellPadding); }
994 inline void setCellPadding(qreal padding);
995
996 inline void setAlignment(Qt::Alignment alignment);
997 inline Qt::Alignment alignment() const
998 { return QFlag(intProperty(BlockAlignment)); }
999
1000 inline void setHeaderRowCount(int count)
1001 { setProperty(TableHeaderRowCount, count); }
1002 inline int headerRowCount() const
1003 { return intProperty(TableHeaderRowCount); }
1004
1005 inline void setBorderCollapse(bool borderCollapse)
1006 { setProperty(TableBorderCollapse, borderCollapse); }
1007 inline bool borderCollapse() const
1008 { return boolProperty(TableBorderCollapse); }
1009
1010protected:
1011 explicit QTextTableFormat(const QTextFormat &fmt);
1012 friend class QTextFormat;
1013};
1014
1016
1017inline void QTextTableFormat::setColumns(int acolumns)
1018{
1019 if (acolumns == 1)
1020 acolumns = 0;
1021 setProperty(TableColumns, acolumns);
1022}
1023
1024inline void QTextTableFormat::setCellPadding(qreal apadding)
1025{ setProperty(TableCellPadding, apadding); }
1026
1027inline void QTextTableFormat::setAlignment(Qt::Alignment aalignment)
1028{ setProperty(BlockAlignment, int(aalignment.toInt())); }
1029
1030class Q_GUI_EXPORT QTextTableCellFormat : public QTextCharFormat
1031{
1032public:
1033 QTextTableCellFormat();
1034
1035 inline bool isValid() const { return isTableCellFormat(); }
1036
1037 inline void setTopPadding(qreal padding);
1038 inline qreal topPadding() const;
1039
1040 inline void setBottomPadding(qreal padding);
1041 inline qreal bottomPadding() const;
1042
1043 inline void setLeftPadding(qreal padding);
1044 inline qreal leftPadding() const;
1045
1046 inline void setRightPadding(qreal padding);
1047 inline qreal rightPadding() const;
1048
1049 inline void setPadding(qreal padding);
1050
1051 inline void setTopBorder(qreal width)
1052 { setProperty(TableCellTopBorder, width); }
1053 inline qreal topBorder() const
1054 { return doubleProperty(TableCellTopBorder); }
1055
1056 inline void setBottomBorder(qreal width)
1057 { setProperty(TableCellBottomBorder, width); }
1058 inline qreal bottomBorder() const
1059 { return doubleProperty(TableCellBottomBorder); }
1060
1061 inline void setLeftBorder(qreal width)
1062 { setProperty(TableCellLeftBorder, width); }
1063 inline qreal leftBorder() const
1064 { return doubleProperty(TableCellLeftBorder); }
1065
1066 inline void setRightBorder(qreal width)
1067 { setProperty(TableCellRightBorder, width); }
1068 inline qreal rightBorder() const
1069 { return doubleProperty(TableCellRightBorder); }
1070
1071 inline void setBorder(qreal width);
1072
1073 inline void setTopBorderStyle(QTextFrameFormat::BorderStyle style)
1074 { setProperty(TableCellTopBorderStyle, style); }
1075 inline QTextFrameFormat::BorderStyle topBorderStyle() const
1076 { return static_cast<QTextFrameFormat::BorderStyle>(intProperty(TableCellTopBorderStyle)); }
1077
1078 inline void setBottomBorderStyle(QTextFrameFormat::BorderStyle style)
1079 { setProperty(TableCellBottomBorderStyle, style); }
1080 inline QTextFrameFormat::BorderStyle bottomBorderStyle() const
1081 { return static_cast<QTextFrameFormat::BorderStyle>(intProperty(TableCellBottomBorderStyle)); }
1082
1083 inline void setLeftBorderStyle(QTextFrameFormat::BorderStyle style)
1084 { setProperty(TableCellLeftBorderStyle, style); }
1085 inline QTextFrameFormat::BorderStyle leftBorderStyle() const
1086 { return static_cast<QTextFrameFormat::BorderStyle>(intProperty(TableCellLeftBorderStyle)); }
1087
1088 inline void setRightBorderStyle(QTextFrameFormat::BorderStyle style)
1089 { setProperty(TableCellRightBorderStyle, style); }
1090 inline QTextFrameFormat::BorderStyle rightBorderStyle() const
1091 { return static_cast<QTextFrameFormat::BorderStyle>(intProperty(TableCellRightBorderStyle)); }
1092
1093 inline void setBorderStyle(QTextFrameFormat::BorderStyle style);
1094
1095 inline void setTopBorderBrush(const QBrush &brush)
1096 { setProperty(TableCellTopBorderBrush, brush); }
1097 inline QBrush topBorderBrush() const
1098 { return brushProperty(TableCellTopBorderBrush); }
1099
1100 inline void setBottomBorderBrush(const QBrush &brush)
1101 { setProperty(TableCellBottomBorderBrush, brush); }
1102 inline QBrush bottomBorderBrush() const
1103 { return brushProperty(TableCellBottomBorderBrush); }
1104
1105 inline void setLeftBorderBrush(const QBrush &brush)
1106 { setProperty(TableCellLeftBorderBrush, brush); }
1107 inline QBrush leftBorderBrush() const
1108 { return brushProperty(TableCellLeftBorderBrush); }
1109
1110 inline void setRightBorderBrush(const QBrush &brush)
1111 { setProperty(TableCellRightBorderBrush, brush); }
1112 inline QBrush rightBorderBrush() const
1113 { return brushProperty(TableCellRightBorderBrush); }
1114
1115 inline void setBorderBrush(const QBrush &brush);
1116
1117protected:
1118 explicit QTextTableCellFormat(const QTextFormat &fmt);
1119 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextTableCellFormat &);
1120 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextTableCellFormat &);
1121 friend class QTextFormat;
1122};
1123
1125
1126inline void QTextTableCellFormat::setTopPadding(qreal padding)
1127{
1128 setProperty(TableCellTopPadding, padding);
1129}
1130
1131inline qreal QTextTableCellFormat::topPadding() const
1132{
1133 return doubleProperty(TableCellTopPadding);
1134}
1135
1136inline void QTextTableCellFormat::setBottomPadding(qreal padding)
1137{
1138 setProperty(TableCellBottomPadding, padding);
1139}
1140
1141inline qreal QTextTableCellFormat::bottomPadding() const
1142{
1143 return doubleProperty(TableCellBottomPadding);
1144}
1145
1146inline void QTextTableCellFormat::setLeftPadding(qreal padding)
1147{
1148 setProperty(TableCellLeftPadding, padding);
1149}
1150
1151inline qreal QTextTableCellFormat::leftPadding() const
1152{
1153 return doubleProperty(TableCellLeftPadding);
1154}
1155
1156inline void QTextTableCellFormat::setRightPadding(qreal padding)
1157{
1158 setProperty(TableCellRightPadding, padding);
1159}
1160
1161inline qreal QTextTableCellFormat::rightPadding() const
1162{
1163 return doubleProperty(TableCellRightPadding);
1164}
1165
1166inline void QTextTableCellFormat::setPadding(qreal padding)
1167{
1168 setTopPadding(padding);
1169 setBottomPadding(padding);
1170 setLeftPadding(padding);
1171 setRightPadding(padding);
1172}
1173
1174inline void QTextTableCellFormat::setBorder(qreal width)
1175{
1176 setTopBorder(width);
1177 setBottomBorder(width);
1178 setLeftBorder(width);
1179 setRightBorder(width);
1180}
1181
1182inline void QTextTableCellFormat::setBorderStyle(QTextFrameFormat::BorderStyle style)
1183{
1184 setTopBorderStyle(style);
1185 setBottomBorderStyle(style);
1186 setLeftBorderStyle(style);
1187 setRightBorderStyle(style);
1188}
1189
1190inline void QTextTableCellFormat::setBorderBrush(const QBrush &brush)
1191{
1192 setTopBorderBrush(brush);
1193 setBottomBorderBrush(brush);
1194 setLeftBorderBrush(brush);
1195 setRightBorderBrush(brush);
1196}
1197
1198QT_END_NAMESPACE
1199
1200#endif // QTEXTFORMAT_H
\inmodule QtGui
Definition qbrush.h:29
\inmodule QtGui
Definition qbrush.h:468
\inmodule QtCore\reentrant
Definition qdatastream.h:50
\inmodule QtGui
Definition qbrush.h:157
\inmodule QtGui
Definition qbrush.h:416
\inmodule QtGui
Definition qpen.h:28
\inmodule QtGui
Definition qbrush.h:434
\reentrant
Definition qtextformat.h:91
\reentrant
Definition qtextformat.h:46
QList< QGradientStop > QGradientStops
Definition qbrush.h:154
std::pair< qreal, QColor > QGradientStop
Definition qbrush.h:153
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2568
void qRegisterGuiVariant()
Q_DECLARE_TYPEINFO(QTextLength, Q_PRIMITIVE_TYPE)
void operator()(QBrushData *d) const noexcept
Definition qbrush.cpp:250
Qt::BrushStyle style
Definition qbrush.h:134
QBrushData()=default
QTransform transform
Definition qbrush.h:136
QAtomicInt ref
Definition qbrush.h:133
QColor color
Definition qbrush.h:135
static const QtPrivate::QMetaTypeInterface * interfaceForType(int type)
static bool convert(const void *from, int fromTypeId, void *to, int toTypeId)