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(fixedValueOrPercentage, other.fixedValueOrPercentage); }
109 inline bool operator!=(const QTextLength &other) const
110 { return lengthType != other.lengthType
111 || !qFuzzyCompare(fixedValueOrPercentage, 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
246 // table cell properties
247 TableCellRowSpan = 0x4810,
248 TableCellColumnSpan = 0x4811,
249
250 TableCellTopPadding = 0x4812,
251 TableCellBottomPadding = 0x4813,
252 TableCellLeftPadding = 0x4814,
253 TableCellRightPadding = 0x4815,
254
255 // image properties
256 ImageName = 0x5000,
257 ImageTitle = 0x5001,
258 ImageAltText = 0x5002,
259 ImageWidth = 0x5010,
260 ImageHeight = 0x5011,
261 ImageQuality = 0x5014,
262
263 // internal
264 /*
265 SuppressText = 0x5012,
266 SuppressBackground = 0x513
267 */
268
269 // selection properties
270 FullWidthSelection = 0x06000,
271
272 // page break properties
273 PageBreakPolicy = 0x7000,
274
275 // --
276 UserProperty = 0x100000
277 };
278 Q_ENUM(Property)
279
280 enum ObjectTypes {
281 NoObject,
282 ImageObject,
283 TableObject,
284 TableCellObject,
285
286 UserObject = 0x1000
287 };
288 Q_ENUM(ObjectTypes)
289
290 enum PageBreakFlag {
291 PageBreak_Auto = 0,
292 PageBreak_AlwaysBefore = 0x001,
293 PageBreak_AlwaysAfter = 0x010
294 // PageBreak_AlwaysInside = 0x100
295 };
296 Q_DECLARE_FLAGS(PageBreakFlags, PageBreakFlag)
297
298 QTextFormat();
299
300 explicit QTextFormat(int type);
301
302 QTextFormat(const QTextFormat &rhs);
303 QTextFormat &operator=(const QTextFormat &rhs);
304 ~QTextFormat();
305
306 void swap(QTextFormat &other)
307 { qSwap(d, other.d); qSwap(format_type, other.format_type); }
308
309 void merge(const QTextFormat &other);
310
311 inline bool isValid() const { return type() != InvalidFormat; }
312 inline bool isEmpty() const { return propertyCount() == 0; }
313
314 int type() const;
315
316 int objectIndex() const;
317 void setObjectIndex(int object);
318
319 QVariant property(int propertyId) const;
320 void setProperty(int propertyId, const QVariant &value);
321 void clearProperty(int propertyId);
322 bool hasProperty(int propertyId) const;
323
324 bool boolProperty(int propertyId) const;
325 int intProperty(int propertyId) const;
326 qreal doubleProperty(int propertyId) const;
327 QString stringProperty(int propertyId) const;
328 QColor colorProperty(int propertyId) const;
329 QPen penProperty(int propertyId) const;
330 QBrush brushProperty(int propertyId) const;
331 QTextLength lengthProperty(int propertyId) const;
332 QVector<QTextLength> lengthVectorProperty(int propertyId) const;
333
334 void setProperty(int propertyId, const QVector<QTextLength> &lengths);
335
336 QMap<int, QVariant> properties() const;
337 int propertyCount() const;
338
339 inline void setObjectType(int type);
340 inline int objectType() const
341 { return intProperty(ObjectType); }
342
343 inline bool isCharFormat() const { return type() == CharFormat; }
344 inline bool isBlockFormat() const { return type() == BlockFormat; }
345 inline bool isListFormat() const { return type() == ListFormat; }
346 inline bool isFrameFormat() const { return type() == FrameFormat; }
347 inline bool isImageFormat() const { return type() == CharFormat && objectType() == ImageObject; }
348 inline bool isTableFormat() const { return type() == FrameFormat && objectType() == TableObject; }
349 inline bool isTableCellFormat() const { return type() == CharFormat && objectType() == TableCellObject; }
350
351 QTextBlockFormat toBlockFormat() const;
352 QTextCharFormat toCharFormat() const;
353 QTextListFormat toListFormat() const;
354 QTextTableFormat toTableFormat() const;
355 QTextFrameFormat toFrameFormat() const;
356 QTextImageFormat toImageFormat() const;
357 QTextTableCellFormat toTableCellFormat() const;
358
359 bool operator==(const QTextFormat &rhs) const;
360 inline bool operator!=(const QTextFormat &rhs) const { return !operator==(rhs); }
361 operator QVariant() const;
362
363 inline void setLayoutDirection(Qt::LayoutDirection direction)
364 { setProperty(QTextFormat::LayoutDirection, direction); }
365 inline Qt::LayoutDirection layoutDirection() const
366 { return Qt::LayoutDirection(intProperty(QTextFormat::LayoutDirection)); }
367
368 inline void setBackground(const QBrush &brush)
369 { setProperty(BackgroundBrush, brush); }
370 inline QBrush background() const
371 { return brushProperty(BackgroundBrush); }
372 inline void clearBackground()
373 { clearProperty(BackgroundBrush); }
374
375 inline void setForeground(const QBrush &brush)
376 { setProperty(ForegroundBrush, brush); }
377 inline QBrush foreground() const
378 { return brushProperty(ForegroundBrush); }
379 inline void clearForeground()
380 { clearProperty(ForegroundBrush); }
381
382private:
383 QSharedDataPointer<QTextFormatPrivate> d;
384 qint32 format_type;
385
386 friend class QTextFormatCollection;
387 friend class QTextCharFormat;
388 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextFormat &);
389 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextFormat &);
390};
391
392Q_DECLARE_SHARED(QTextFormat)
393
394inline void QTextFormat::setObjectType(int atype)
395{ setProperty(ObjectType, atype); }
396
397Q_DECLARE_OPERATORS_FOR_FLAGS(QTextFormat::PageBreakFlags)
398
399class Q_GUI_EXPORT QTextCharFormat : public QTextFormat
400{
401public:
402 enum VerticalAlignment {
403 AlignNormal = 0,
404 AlignSuperScript,
405 AlignSubScript,
406 AlignMiddle,
407 AlignTop,
408 AlignBottom,
409 AlignBaseline
410 };
411 enum UnderlineStyle { // keep in sync with Qt::PenStyle!
412 NoUnderline,
413 SingleUnderline,
414 DashUnderline,
415 DotLine,
416 DashDotLine,
417 DashDotDotLine,
418 WaveUnderline,
419 SpellCheckUnderline
420 };
421
422 QTextCharFormat();
423
424 bool isValid() const { return isCharFormat(); }
425
426 enum FontPropertiesInheritanceBehavior {
427 FontPropertiesSpecifiedOnly,
428 FontPropertiesAll
429 };
430 void setFont(const QFont &font, FontPropertiesInheritanceBehavior behavior);
431 void setFont(const QFont &font); // ### Qt6: Merge with above
432 QFont font() const;
433
434 inline void setFontFamily(const QString &family)
435 { setProperty(FontFamily, family); }
436 inline QString fontFamily() const
437 { return stringProperty(FontFamily); }
438
439 inline void setFontFamilies(const QStringList &families)
440 { setProperty(FontFamilies, QVariant(families)); }
441 inline QVariant fontFamilies() const
442 { return property(FontFamilies); }
443
444 inline void setFontStyleName(const QString &styleName)
445 { setProperty(FontStyleName, styleName); }
446 inline QVariant fontStyleName() const
447 { return property(FontStyleName); }
448
449 inline void setFontPointSize(qreal size)
450 { setProperty(FontPointSize, size); }
451 inline qreal fontPointSize() const
452 { return doubleProperty(FontPointSize); }
453
454 inline void setFontWeight(int weight)
455 { setProperty(FontWeight, weight); }
456 inline int fontWeight() const
457 { return hasProperty(FontWeight) ? intProperty(FontWeight) : QFont::Normal; }
458 inline void setFontItalic(bool italic)
459 { setProperty(FontItalic, italic); }
460 inline bool fontItalic() const
461 { return boolProperty(FontItalic); }
462 inline void setFontCapitalization(QFont::Capitalization capitalization)
463 { setProperty(FontCapitalization, capitalization); }
464 inline QFont::Capitalization fontCapitalization() const
465 { return static_cast<QFont::Capitalization>(intProperty(FontCapitalization)); }
466 inline void setFontLetterSpacingType(QFont::SpacingType letterSpacingType)
467 { setProperty(FontLetterSpacingType, letterSpacingType); }
468 inline QFont::SpacingType fontLetterSpacingType() const
469 { return static_cast<QFont::SpacingType>(intProperty(FontLetterSpacingType)); }
470 inline void setFontLetterSpacing(qreal spacing)
471 { setProperty(FontLetterSpacing, spacing); }
472 inline qreal fontLetterSpacing() const
473 { return doubleProperty(FontLetterSpacing); }
474 inline void setFontWordSpacing(qreal spacing)
475 { setProperty(FontWordSpacing, spacing); }
476 inline qreal fontWordSpacing() const
477 { return doubleProperty(FontWordSpacing); }
478
479 inline void setFontUnderline(bool underline)
480 { setProperty(TextUnderlineStyle, underline ? SingleUnderline : NoUnderline); }
481 bool fontUnderline() const;
482
483 inline void setFontOverline(bool overline)
484 { setProperty(FontOverline, overline); }
485 inline bool fontOverline() const
486 { return boolProperty(FontOverline); }
487
488 inline void setFontStrikeOut(bool strikeOut)
489 { setProperty(FontStrikeOut, strikeOut); }
490 inline bool fontStrikeOut() const
491 { return boolProperty(FontStrikeOut); }
492
493 inline void setUnderlineColor(const QColor &color)
494 { setProperty(TextUnderlineColor, color); }
495 inline QColor underlineColor() const
496 { return colorProperty(TextUnderlineColor); }
497
498 inline void setFontFixedPitch(bool fixedPitch)
499 { setProperty(FontFixedPitch, fixedPitch); }
500 inline bool fontFixedPitch() const
501 { return boolProperty(FontFixedPitch); }
502
503 inline void setFontStretch(int factor)
504 { setProperty(FontStretch, factor); }
505 inline int fontStretch() const
506 { return intProperty(FontStretch); }
507
508 inline void setFontStyleHint(QFont::StyleHint hint, QFont::StyleStrategy strategy = QFont::PreferDefault)
509 { setProperty(FontStyleHint, hint); setProperty(FontStyleStrategy, strategy); }
510 inline void setFontStyleStrategy(QFont::StyleStrategy strategy)
511 { setProperty(FontStyleStrategy, strategy); }
512 QFont::StyleHint fontStyleHint() const
513 { return static_cast<QFont::StyleHint>(intProperty(FontStyleHint)); }
514 QFont::StyleStrategy fontStyleStrategy() const
515 { return static_cast<QFont::StyleStrategy>(intProperty(FontStyleStrategy)); }
516
517 inline void setFontHintingPreference(QFont::HintingPreference hintingPreference)
518 {
519 setProperty(FontHintingPreference, hintingPreference);
520 }
521
522 inline QFont::HintingPreference fontHintingPreference() const
523 {
524 return static_cast<QFont::HintingPreference>(intProperty(FontHintingPreference));
525 }
526
527 inline void setFontKerning(bool enable)
528 { setProperty(FontKerning, enable); }
529 inline bool fontKerning() const
530 { return boolProperty(FontKerning); }
531
532 void setUnderlineStyle(UnderlineStyle style);
533 inline UnderlineStyle underlineStyle() const
534 { return static_cast<UnderlineStyle>(intProperty(TextUnderlineStyle)); }
535
536 inline void setVerticalAlignment(VerticalAlignment alignment)
537 { setProperty(TextVerticalAlignment, alignment); }
538 inline VerticalAlignment verticalAlignment() const
539 { return static_cast<VerticalAlignment>(intProperty(TextVerticalAlignment)); }
540
541 inline void setTextOutline(const QPen &pen)
542 { setProperty(TextOutline, pen); }
543 inline QPen textOutline() const
544 { return penProperty(TextOutline); }
545
546 inline void setToolTip(const QString &tip)
547 { setProperty(TextToolTip, tip); }
548 inline QString toolTip() const
549 { return stringProperty(TextToolTip); }
550
551 inline void setAnchor(bool anchor)
552 { setProperty(IsAnchor, anchor); }
553 inline bool isAnchor() const
554 { return boolProperty(IsAnchor); }
555
556 inline void setAnchorHref(const QString &value)
557 { setProperty(AnchorHref, value); }
558 inline QString anchorHref() const
559 { return stringProperty(AnchorHref); }
560
561#if QT_DEPRECATED_SINCE(5, 13)
562 QT_DEPRECATED_X("Use setAnchorNames() instead")
563 inline void setAnchorName(const QString &name)
564 { setAnchorNames(QStringList(name)); }
565 QT_DEPRECATED_X("Use anchorNames() instead")
566 QString anchorName() const;
567#endif
568
569 inline void setAnchorNames(const QStringList &names)
570 { setProperty(AnchorName, names); }
571 QStringList anchorNames() const;
572
573 inline void setTableCellRowSpan(int tableCellRowSpan);
574 inline int tableCellRowSpan() const
575 { int s = intProperty(TableCellRowSpan); if (s == 0) s = 1; return s; }
576 inline void setTableCellColumnSpan(int tableCellColumnSpan);
577 inline int tableCellColumnSpan() const
578 { int s = intProperty(TableCellColumnSpan); if (s == 0) s = 1; return s; }
579
580protected:
581 explicit QTextCharFormat(const QTextFormat &fmt);
582 friend class QTextFormat;
583};
584
585Q_DECLARE_SHARED(QTextCharFormat)
586
587inline void QTextCharFormat::setTableCellRowSpan(int _tableCellRowSpan)
588{
589 if (_tableCellRowSpan <= 1)
590 clearProperty(TableCellRowSpan); // the getter will return 1 here.
591 else
592 setProperty(TableCellRowSpan, _tableCellRowSpan);
593}
594
595inline void QTextCharFormat::setTableCellColumnSpan(int _tableCellColumnSpan)
596{
597 if (_tableCellColumnSpan <= 1)
598 clearProperty(TableCellColumnSpan); // the getter will return 1 here.
599 else
600 setProperty(TableCellColumnSpan, _tableCellColumnSpan);
601}
602
603class Q_GUI_EXPORT QTextBlockFormat : public QTextFormat
604{
605public:
606 enum LineHeightTypes {
607 SingleHeight = 0,
608 ProportionalHeight = 1,
609 FixedHeight = 2,
610 MinimumHeight = 3,
611 LineDistanceHeight = 4
612 };
613
614 enum MarkerType {
615 NoMarker = 0,
616 Unchecked = 1,
617 Checked = 2
618 };
619
620 QTextBlockFormat();
621
622 bool isValid() const { return isBlockFormat(); }
623
624 inline void setAlignment(Qt::Alignment alignment);
625 inline Qt::Alignment alignment() const
626 { int a = intProperty(BlockAlignment); if (a == 0) a = Qt::AlignLeft; return QFlag(a); }
627
628 inline void setTopMargin(qreal margin)
629 { setProperty(BlockTopMargin, margin); }
630 inline qreal topMargin() const
631 { return doubleProperty(BlockTopMargin); }
632
633 inline void setBottomMargin(qreal margin)
634 { setProperty(BlockBottomMargin, margin); }
635 inline qreal bottomMargin() const
636 { return doubleProperty(BlockBottomMargin); }
637
638 inline void setLeftMargin(qreal margin)
639 { setProperty(BlockLeftMargin, margin); }
640 inline qreal leftMargin() const
641 { return doubleProperty(BlockLeftMargin); }
642
643 inline void setRightMargin(qreal margin)
644 { setProperty(BlockRightMargin, margin); }
645 inline qreal rightMargin() const
646 { return doubleProperty(BlockRightMargin); }
647
648 inline void setTextIndent(qreal aindent)
649 { setProperty(TextIndent, aindent); }
650 inline qreal textIndent() const
651 { return doubleProperty(TextIndent); }
652
653 inline void setIndent(int indent);
654 inline int indent() const
655 { return intProperty(BlockIndent); }
656
657 inline void setHeadingLevel(int alevel)
658 { setProperty(HeadingLevel, alevel); }
659 inline int headingLevel() const
660 { return intProperty(HeadingLevel); }
661
662 inline void setLineHeight(qreal height, int heightType)
663 { setProperty(LineHeight, height); setProperty(LineHeightType, heightType); }
664 inline qreal lineHeight(qreal scriptLineHeight, qreal scaling) const;
665 inline qreal lineHeight() const
666 { return doubleProperty(LineHeight); }
667 inline int lineHeightType() const
668 { return intProperty(LineHeightType); }
669
670 inline void setNonBreakableLines(bool b)
671 { setProperty(BlockNonBreakableLines, b); }
672 inline bool nonBreakableLines() const
673 { return boolProperty(BlockNonBreakableLines); }
674
675 inline void setPageBreakPolicy(PageBreakFlags flags)
676 { setProperty(PageBreakPolicy, int(flags)); }
677 inline PageBreakFlags pageBreakPolicy() const
678 { return PageBreakFlags(intProperty(PageBreakPolicy)); }
679
680 void setTabPositions(const QList<QTextOption::Tab> &tabs);
681 QList<QTextOption::Tab> tabPositions() const;
682
683 inline void setMarker(MarkerType marker)
684 { setProperty(BlockMarker, int(marker)); }
685 inline MarkerType marker() const
686 { return MarkerType(intProperty(BlockMarker)); }
687
688protected:
689 explicit QTextBlockFormat(const QTextFormat &fmt);
690 friend class QTextFormat;
691};
692
693Q_DECLARE_SHARED(QTextBlockFormat)
694
695inline void QTextBlockFormat::setAlignment(Qt::Alignment aalignment)
696{ setProperty(BlockAlignment, int(aalignment)); }
697
698inline void QTextBlockFormat::setIndent(int aindent)
699{ setProperty(BlockIndent, aindent); }
700
701inline qreal QTextBlockFormat::lineHeight(qreal scriptLineHeight, qreal scaling = 1.0) const
702{
703 switch(intProperty(LineHeightType)) {
704 case SingleHeight:
705 return(scriptLineHeight);
706 case ProportionalHeight:
707 return(scriptLineHeight * doubleProperty(LineHeight) / 100.0);
708 case FixedHeight:
709 return(doubleProperty(LineHeight) * scaling);
710 case MinimumHeight:
711 return(qMax(scriptLineHeight, doubleProperty(LineHeight) * scaling));
712 case LineDistanceHeight:
713 return(scriptLineHeight + doubleProperty(LineHeight) * scaling);
714 }
715 return(0);
716}
717
718class Q_GUI_EXPORT QTextListFormat : public QTextFormat
719{
720public:
721 QTextListFormat();
722
723 bool isValid() const { return isListFormat(); }
724
725 enum Style {
726 ListDisc = -1,
727 ListCircle = -2,
728 ListSquare = -3,
729 ListDecimal = -4,
730 ListLowerAlpha = -5,
731 ListUpperAlpha = -6,
732 ListLowerRoman = -7,
733 ListUpperRoman = -8,
734 ListStyleUndefined = 0
735 };
736
737 inline void setStyle(Style style);
738 inline Style style() const
739 { return static_cast<Style>(intProperty(ListStyle)); }
740
741 inline void setIndent(int indent);
742 inline int indent() const
743 { return intProperty(ListIndent); }
744
745 inline void setNumberPrefix(const QString &numberPrefix);
746 inline QString numberPrefix() const
747 { return stringProperty(ListNumberPrefix); }
748
749 inline void setNumberSuffix(const QString &numberSuffix);
750 inline QString numberSuffix() const
751 { return stringProperty(ListNumberSuffix); }
752
753protected:
754 explicit QTextListFormat(const QTextFormat &fmt);
755 friend class QTextFormat;
756};
757
758Q_DECLARE_SHARED(QTextListFormat)
759
760inline void QTextListFormat::setStyle(Style astyle)
761{ setProperty(ListStyle, astyle); }
762
763inline void QTextListFormat::setIndent(int aindent)
764{ setProperty(ListIndent, aindent); }
765
766inline void QTextListFormat::setNumberPrefix(const QString &np)
767{ setProperty(ListNumberPrefix, np); }
768
769inline void QTextListFormat::setNumberSuffix(const QString &ns)
770{ setProperty(ListNumberSuffix, ns); }
771
772class Q_GUI_EXPORT QTextImageFormat : public QTextCharFormat
773{
774public:
775 QTextImageFormat();
776
777 bool isValid() const { return isImageFormat(); }
778
779 inline void setName(const QString &name);
780 inline QString name() const
781 { return stringProperty(ImageName); }
782
783 inline void setWidth(qreal width);
784 inline qreal width() const
785 { return doubleProperty(ImageWidth); }
786
787 inline void setHeight(qreal height);
788 inline qreal height() const
789 { return doubleProperty(ImageHeight); }
790
791 inline void setQuality(int quality = 100);
792 inline int quality() const
793 { return intProperty(ImageQuality); }
794
795protected:
796 explicit QTextImageFormat(const QTextFormat &format);
797 friend class QTextFormat;
798};
799
800Q_DECLARE_SHARED(QTextImageFormat)
801
802inline void QTextImageFormat::setName(const QString &aname)
803{ setProperty(ImageName, aname); }
804
805inline void QTextImageFormat::setWidth(qreal awidth)
806{ setProperty(ImageWidth, awidth); }
807
808inline void QTextImageFormat::setHeight(qreal aheight)
809{ setProperty(ImageHeight, aheight); }
810
811inline void QTextImageFormat::setQuality(int aquality)
812{ setProperty(ImageQuality, aquality); }
813
814class Q_GUI_EXPORT QTextFrameFormat : public QTextFormat
815{
816public:
817 QTextFrameFormat();
818
819 bool isValid() const { return isFrameFormat(); }
820
821 enum Position {
822 InFlow,
823 FloatLeft,
824 FloatRight
825 // ######
826// Absolute
827 };
828
829 enum BorderStyle {
830 BorderStyle_None,
831 BorderStyle_Dotted,
832 BorderStyle_Dashed,
833 BorderStyle_Solid,
834 BorderStyle_Double,
835 BorderStyle_DotDash,
836 BorderStyle_DotDotDash,
837 BorderStyle_Groove,
838 BorderStyle_Ridge,
839 BorderStyle_Inset,
840 BorderStyle_Outset
841 };
842
843 inline void setPosition(Position f)
844 { setProperty(CssFloat, f); }
845 inline Position position() const
846 { return static_cast<Position>(intProperty(CssFloat)); }
847
848 inline void setBorder(qreal border);
849 inline qreal border() const
850 { return doubleProperty(FrameBorder); }
851
852 inline void setBorderBrush(const QBrush &brush)
853 { setProperty(FrameBorderBrush, brush); }
854 inline QBrush borderBrush() const
855 { return brushProperty(FrameBorderBrush); }
856
857 inline void setBorderStyle(BorderStyle style)
858 { setProperty(FrameBorderStyle, style); }
859 inline BorderStyle borderStyle() const
860 { return static_cast<BorderStyle>(intProperty(FrameBorderStyle)); }
861
862 void setMargin(qreal margin);
863 inline qreal margin() const
864 { return doubleProperty(FrameMargin); }
865
866 inline void setTopMargin(qreal margin);
867 qreal topMargin() const;
868
869 inline void setBottomMargin(qreal margin);
870 qreal bottomMargin() const;
871
872 inline void setLeftMargin(qreal margin);
873 qreal leftMargin() const;
874
875 inline void setRightMargin(qreal margin);
876 qreal rightMargin() const;
877
878 inline void setPadding(qreal padding);
879 inline qreal padding() const
880 { return doubleProperty(FramePadding); }
881
882 inline void setWidth(qreal width);
883 inline void setWidth(const QTextLength &length)
884 { setProperty(FrameWidth, length); }
885 inline QTextLength width() const
886 { return lengthProperty(FrameWidth); }
887
888 inline void setHeight(qreal height);
889 inline void setHeight(const QTextLength &height);
890 inline QTextLength height() const
891 { return lengthProperty(FrameHeight); }
892
893 inline void setPageBreakPolicy(PageBreakFlags flags)
894 { setProperty(PageBreakPolicy, int(flags)); }
895 inline PageBreakFlags pageBreakPolicy() const
896 { return PageBreakFlags(intProperty(PageBreakPolicy)); }
897
898protected:
899 explicit QTextFrameFormat(const QTextFormat &fmt);
900 friend class QTextFormat;
901};
902
903Q_DECLARE_SHARED(QTextFrameFormat)
904
905inline void QTextFrameFormat::setBorder(qreal aborder)
906{ setProperty(FrameBorder, aborder); }
907
908inline void QTextFrameFormat::setPadding(qreal apadding)
909{ setProperty(FramePadding, apadding); }
910
911inline void QTextFrameFormat::setWidth(qreal awidth)
912{ setProperty(FrameWidth, QTextLength(QTextLength::FixedLength, awidth)); }
913
914inline void QTextFrameFormat::setHeight(qreal aheight)
915{ setProperty(FrameHeight, QTextLength(QTextLength::FixedLength, aheight)); }
916inline void QTextFrameFormat::setHeight(const QTextLength &aheight)
917{ setProperty(FrameHeight, aheight); }
918
919inline void QTextFrameFormat::setTopMargin(qreal amargin)
920{ setProperty(FrameTopMargin, amargin); }
921
922inline void QTextFrameFormat::setBottomMargin(qreal amargin)
923{ setProperty(FrameBottomMargin, amargin); }
924
925inline void QTextFrameFormat::setLeftMargin(qreal amargin)
926{ setProperty(FrameLeftMargin, amargin); }
927
928inline void QTextFrameFormat::setRightMargin(qreal amargin)
929{ setProperty(FrameRightMargin, amargin); }
930
931class Q_GUI_EXPORT QTextTableFormat : public QTextFrameFormat
932{
933public:
934 QTextTableFormat();
935
936 inline bool isValid() const { return isTableFormat(); }
937
938 inline int columns() const
939 { int cols = intProperty(TableColumns); if (cols == 0) cols = 1; return cols; }
940 inline void setColumns(int columns);
941
942 inline void setColumnWidthConstraints(const QVector<QTextLength> &constraints)
943 { setProperty(TableColumnWidthConstraints, constraints); }
944
945 inline QVector<QTextLength> columnWidthConstraints() const
946 { return lengthVectorProperty(TableColumnWidthConstraints); }
947
948 inline void clearColumnWidthConstraints()
949 { clearProperty(TableColumnWidthConstraints); }
950
951 inline qreal cellSpacing() const
952 { return doubleProperty(TableCellSpacing); }
953 inline void setCellSpacing(qreal spacing)
954 { setProperty(TableCellSpacing, spacing); }
955
956 inline qreal cellPadding() const
957 { return doubleProperty(TableCellPadding); }
958 inline void setCellPadding(qreal padding);
959
960 inline void setAlignment(Qt::Alignment alignment);
961 inline Qt::Alignment alignment() const
962 { return QFlag(intProperty(BlockAlignment)); }
963
964 inline void setHeaderRowCount(int count)
965 { setProperty(TableHeaderRowCount, count); }
966 inline int headerRowCount() const
967 { return intProperty(TableHeaderRowCount); }
968
969protected:
970 explicit QTextTableFormat(const QTextFormat &fmt);
971 friend class QTextFormat;
972};
973
974Q_DECLARE_SHARED(QTextTableFormat)
975
976inline void QTextTableFormat::setColumns(int acolumns)
977{
978 if (acolumns == 1)
979 acolumns = 0;
980 setProperty(TableColumns, acolumns);
981}
982
983inline void QTextTableFormat::setCellPadding(qreal apadding)
984{ setProperty(TableCellPadding, apadding); }
985
986inline void QTextTableFormat::setAlignment(Qt::Alignment aalignment)
987{ setProperty(BlockAlignment, int(aalignment)); }
988
989class Q_GUI_EXPORT QTextTableCellFormat : public QTextCharFormat
990{
991public:
992 QTextTableCellFormat();
993
994 inline bool isValid() const { return isTableCellFormat(); }
995
996 inline void setTopPadding(qreal padding);
997 inline qreal topPadding() const;
998
999 inline void setBottomPadding(qreal padding);
1000 inline qreal bottomPadding() const;
1001
1002 inline void setLeftPadding(qreal padding);
1003 inline qreal leftPadding() const;
1004
1005 inline void setRightPadding(qreal padding);
1006 inline qreal rightPadding() const;
1007
1008 inline void setPadding(qreal padding);
1009
1010protected:
1011 explicit QTextTableCellFormat(const QTextFormat &fmt);
1012 friend class QTextFormat;
1013};
1014
1015Q_DECLARE_SHARED(QTextTableCellFormat)
1016
1017inline void QTextTableCellFormat::setTopPadding(qreal padding)
1018{
1019 setProperty(TableCellTopPadding, padding);
1020}
1021
1022inline qreal QTextTableCellFormat::topPadding() const
1023{
1024 return doubleProperty(TableCellTopPadding);
1025}
1026
1027inline void QTextTableCellFormat::setBottomPadding(qreal padding)
1028{
1029 setProperty(TableCellBottomPadding, padding);
1030}
1031
1032inline qreal QTextTableCellFormat::bottomPadding() const
1033{
1034 return doubleProperty(TableCellBottomPadding);
1035}
1036
1037inline void QTextTableCellFormat::setLeftPadding(qreal padding)
1038{
1039 setProperty(TableCellLeftPadding, padding);
1040}
1041
1042inline qreal QTextTableCellFormat::leftPadding() const
1043{
1044 return doubleProperty(TableCellLeftPadding);
1045}
1046
1047inline void QTextTableCellFormat::setRightPadding(qreal padding)
1048{
1049 setProperty(TableCellRightPadding, padding);
1050}
1051
1052inline qreal QTextTableCellFormat::rightPadding() const
1053{
1054 return doubleProperty(TableCellRightPadding);
1055}
1056
1057inline void QTextTableCellFormat::setPadding(qreal padding)
1058{
1059 setTopPadding(padding);
1060 setBottomPadding(padding);
1061 setLeftPadding(padding);
1062 setRightPadding(padding);
1063}
1064
1065
1066QT_END_NAMESPACE
1067
1068#endif // QTEXTFORMAT_H
1069