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