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

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