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