1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://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 http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://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 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QTEXTFORMAT_H
43 #define QTEXTFORMAT_H
44 
45 #include <QtGui/qcolor.h>
46 #include <QtGui/qfont.h>
47 #include <QtCore/qshareddata.h>
48 #include <QtCore/qvector.h>
49 #include <QtCore/qvariant.h>
50 #include <QtGui/qpen.h>
51 #include <QtGui/qbrush.h>
52 #include <QtGui/qtextoption.h>
53 
54 QT_BEGIN_HEADER
55 
56 QT_BEGIN_NAMESPACE
57 
58 QT_MODULE(Gui)
59 
60 class QString;
61 class QVariant;
62 class QFont;
63 
64 class QTextFormatCollection;
65 class QTextFormatPrivate;
66 class QTextBlockFormat;
67 class QTextCharFormat;
68 class QTextListFormat;
69 class QTextTableFormat;
70 class QTextFrameFormat;
71 class QTextImageFormat;
72 class QTextTableCellFormat;
73 class QTextFormat;
74 class QTextObject;
75 class QTextCursor;
76 class QTextDocument;
77 class QTextLength;
78 
79 #ifndef QT_NO_DATASTREAM
80 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextLength &);
81 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextLength &);
82 #endif
83 
84 class Q_GUI_EXPORT QTextLength
85 {
86 public:
87     enum Type { VariableLength = 0, FixedLength, PercentageLength };
88 
QTextLength()89     inline QTextLength() : lengthType(VariableLength), fixedValueOrPercentage(0) {}
90 
91     inline explicit QTextLength(Type type, qreal value);
92 
type()93     inline Type type() const { return lengthType; }
value(qreal maximumLength)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 
rawValue()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 
114 private:
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 };
120 
QTextLength(Type atype,qreal avalue)121 inline QTextLength::QTextLength(Type atype, qreal avalue)
122     : lengthType(atype), fixedValueOrPercentage(avalue) {}
123 
124 #ifndef QT_NO_DATASTREAM
125 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextFormat &);
126 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextFormat &);
127 #endif
128 
129 class Q_GUI_EXPORT QTextFormat
130 {
131     Q_GADGET
132     Q_ENUMS(FormatType Property ObjectTypes)
133 public:
134     enum FormatType {
135         InvalidFormat = -1,
136         BlockFormat = 1,
137         CharFormat = 2,
138         ListFormat = 3,
139         TableFormat = 4,
140         FrameFormat = 5,
141 
142         UserFormat = 100
143     };
144 
145     enum Property {
146         ObjectIndex = 0x0,
147 
148         // paragraph and char
149         CssFloat = 0x0800,
150         LayoutDirection = 0x0801,
151 
152         OutlinePen = 0x810,
153         BackgroundBrush = 0x820,
154         ForegroundBrush = 0x821,
155         // Internal to qtextlayout.cpp: ObjectSelectionBrush = 0x822
156         BackgroundImageUrl = 0x823,
157 
158         // paragraph
159         BlockAlignment = 0x1010,
160         BlockTopMargin = 0x1030,
161         BlockBottomMargin = 0x1031,
162         BlockLeftMargin = 0x1032,
163         BlockRightMargin = 0x1033,
164         TextIndent = 0x1034,
165         TabPositions = 0x1035,
166         BlockIndent = 0x1040,
167         LineHeight = 0x1048,
168         LineHeightType = 0x1049,
169         BlockNonBreakableLines = 0x1050,
170         BlockTrailingHorizontalRulerWidth = 0x1060,
171 
172         // character properties
173         FirstFontProperty = 0x1FE0,
174         FontCapitalization = FirstFontProperty,
175         FontLetterSpacing = 0x1FE1,
176         FontWordSpacing = 0x1FE2,
177         FontStyleHint = 0x1FE3,
178         FontStyleStrategy = 0x1FE4,
179         FontKerning = 0x1FE5,
180         FontHintingPreference = 0x1FE6,
181         FontFamily = 0x2000,
182         FontPointSize = 0x2001,
183         FontSizeAdjustment = 0x2002,
184         FontSizeIncrement = FontSizeAdjustment, // old name, compat
185         FontWeight = 0x2003,
186         FontItalic = 0x2004,
187         FontUnderline = 0x2005, // deprecated, use TextUnderlineStyle instead
188         FontOverline = 0x2006,
189         FontStrikeOut = 0x2007,
190         FontFixedPitch = 0x2008,
191         FontPixelSize = 0x2009,
192         LastFontProperty = FontPixelSize,
193 
194         TextUnderlineColor = 0x2010,
195         TextVerticalAlignment = 0x2021,
196         TextOutline = 0x2022,
197         TextUnderlineStyle = 0x2023,
198         TextToolTip = 0x2024,
199 
200         IsAnchor = 0x2030,
201         AnchorHref = 0x2031,
202         AnchorName = 0x2032,
203         ObjectType = 0x2f00,
204 
205         // list properties
206         ListStyle = 0x3000,
207         ListIndent = 0x3001,
208         ListNumberPrefix = 0x3002,
209         ListNumberSuffix = 0x3003,
210 
211         // table and frame properties
212         FrameBorder = 0x4000,
213         FrameMargin = 0x4001,
214         FramePadding = 0x4002,
215         FrameWidth = 0x4003,
216         FrameHeight = 0x4004,
217         FrameTopMargin    = 0x4005,
218         FrameBottomMargin = 0x4006,
219         FrameLeftMargin   = 0x4007,
220         FrameRightMargin  = 0x4008,
221         FrameBorderBrush = 0x4009,
222         FrameBorderStyle = 0x4010,
223 
224         TableColumns = 0x4100,
225         TableColumnWidthConstraints = 0x4101,
226         TableCellSpacing = 0x4102,
227         TableCellPadding = 0x4103,
228         TableHeaderRowCount = 0x4104,
229 
230         // table cell properties
231         TableCellRowSpan = 0x4810,
232         TableCellColumnSpan = 0x4811,
233 
234         TableCellTopPadding = 0x4812,
235         TableCellBottomPadding = 0x4813,
236         TableCellLeftPadding = 0x4814,
237         TableCellRightPadding = 0x4815,
238 
239         // image properties
240         ImageName = 0x5000,
241         ImageWidth = 0x5010,
242         ImageHeight = 0x5011,
243 
244         // internal
245         /*
246            SuppressText = 0x5012,
247            SuppressBackground = 0x513
248         */
249 
250         // selection properties
251         FullWidthSelection = 0x06000,
252 
253         // page break properties
254         PageBreakPolicy = 0x7000,
255 
256         // --
257         UserProperty = 0x100000
258     };
259 
260     enum ObjectTypes {
261         NoObject,
262         ImageObject,
263         TableObject,
264         TableCellObject,
265 
266         UserObject = 0x1000
267     };
268 
269     enum PageBreakFlag {
270         PageBreak_Auto = 0,
271         PageBreak_AlwaysBefore = 0x001,
272         PageBreak_AlwaysAfter  = 0x010
273         // PageBreak_AlwaysInside = 0x100
274     };
275     Q_DECLARE_FLAGS(PageBreakFlags, PageBreakFlag)
276 
277     QTextFormat();
278 
279     explicit QTextFormat(int type);
280 
281     QTextFormat(const QTextFormat &rhs);
282     QTextFormat &operator=(const QTextFormat &rhs);
283     ~QTextFormat();
284 
285     void merge(const QTextFormat &other);
286 
isValid()287     inline bool isValid() const { return type() != InvalidFormat; }
288 
289     int type() const;
290 
291     int objectIndex() const;
292     void setObjectIndex(int object);
293 
294     QVariant property(int propertyId) const;
295     void setProperty(int propertyId, const QVariant &value);
296     void clearProperty(int propertyId);
297     bool hasProperty(int propertyId) const;
298 
299     bool boolProperty(int propertyId) const;
300     int intProperty(int propertyId) const;
301     qreal doubleProperty(int propertyId) const;
302     QString stringProperty(int propertyId) const;
303     QColor colorProperty(int propertyId) const;
304     QPen penProperty(int propertyId) const;
305     QBrush brushProperty(int propertyId) const;
306     QTextLength lengthProperty(int propertyId) const;
307     QVector<QTextLength> lengthVectorProperty(int propertyId) const;
308 
309     void setProperty(int propertyId, const QVector<QTextLength> &lengths);
310 
311     QMap<int, QVariant> properties() const;
312     int propertyCount() const;
313 
314     inline void setObjectType(int type);
objectType()315     inline int objectType() const
316     { return intProperty(ObjectType); }
317 
isCharFormat()318     inline bool isCharFormat() const { return type() == CharFormat; }
isBlockFormat()319     inline bool isBlockFormat() const { return type() == BlockFormat; }
isListFormat()320     inline bool isListFormat() const { return type() == ListFormat; }
isFrameFormat()321     inline bool isFrameFormat() const { return type() == FrameFormat; }
isImageFormat()322     inline bool isImageFormat() const { return type() == CharFormat && objectType() == ImageObject; }
isTableFormat()323     inline bool isTableFormat() const { return type() == FrameFormat && objectType() == TableObject; }
isTableCellFormat()324     inline bool isTableCellFormat() const { return type() == CharFormat && objectType() == TableCellObject; }
325 
326     QTextBlockFormat toBlockFormat() const;
327     QTextCharFormat toCharFormat() const;
328     QTextListFormat toListFormat() const;
329     QTextTableFormat toTableFormat() const;
330     QTextFrameFormat toFrameFormat() const;
331     QTextImageFormat toImageFormat() const;
332     QTextTableCellFormat toTableCellFormat() const;
333 
334     bool operator==(const QTextFormat &rhs) const;
335     inline bool operator!=(const QTextFormat &rhs) const { return !operator==(rhs); }
336     operator QVariant() const;
337 
setLayoutDirection(Qt::LayoutDirection direction)338     inline void setLayoutDirection(Qt::LayoutDirection direction)
339         { setProperty(QTextFormat::LayoutDirection, direction); }
layoutDirection()340     inline Qt::LayoutDirection layoutDirection() const
341         { return Qt::LayoutDirection(intProperty(QTextFormat::LayoutDirection)); }
342 
setBackground(const QBrush & brush)343     inline void setBackground(const QBrush &brush)
344     { setProperty(BackgroundBrush, brush); }
background()345     inline QBrush background() const
346     { return brushProperty(BackgroundBrush); }
clearBackground()347     inline void clearBackground()
348     { clearProperty(BackgroundBrush); }
349 
setForeground(const QBrush & brush)350     inline void setForeground(const QBrush &brush)
351     { setProperty(ForegroundBrush, brush); }
foreground()352     inline QBrush foreground() const
353     { return brushProperty(ForegroundBrush); }
clearForeground()354     inline void clearForeground()
355     { clearProperty(ForegroundBrush); }
356 
357 private:
358     QSharedDataPointer<QTextFormatPrivate> d;
359     qint32 format_type;
360 
361     friend class QTextFormatCollection;
362     friend class QTextCharFormat;
363     friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextFormat &);
364     friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextFormat &);
365 };
366 
setObjectType(int atype)367 inline void QTextFormat::setObjectType(int atype)
368 { setProperty(ObjectType, atype); }
369 
Q_DECLARE_OPERATORS_FOR_FLAGS(QTextFormat::PageBreakFlags)370 Q_DECLARE_OPERATORS_FOR_FLAGS(QTextFormat::PageBreakFlags)
371 
372 class Q_GUI_EXPORT QTextCharFormat : public QTextFormat
373 {
374 public:
375     enum VerticalAlignment {
376         AlignNormal = 0,
377         AlignSuperScript,
378         AlignSubScript,
379         AlignMiddle,
380         AlignTop,
381         AlignBottom,
382         AlignBaseline
383     };
384     enum UnderlineStyle { // keep in sync with Qt::PenStyle!
385         NoUnderline,
386         SingleUnderline,
387         DashUnderline,
388         DotLine,
389         DashDotLine,
390         DashDotDotLine,
391         WaveUnderline,
392         SpellCheckUnderline
393     };
394 
395     QTextCharFormat();
396 
397     bool isValid() const { return isCharFormat(); }
398     void setFont(const QFont &font);
399     QFont font() const;
400 
401     inline void setFontFamily(const QString &family)
402     { setProperty(FontFamily, family); }
403     inline QString fontFamily() const
404     { return stringProperty(FontFamily); }
405 
406     inline void setFontPointSize(qreal size)
407     { setProperty(FontPointSize, size); }
408     inline qreal fontPointSize() const
409     { return doubleProperty(FontPointSize); }
410 
411     inline void setFontWeight(int weight)
412     { if (weight == QFont::Normal) weight = 0; setProperty(FontWeight, weight); }
413     inline int fontWeight() const
414     { int weight = intProperty(FontWeight); if (weight == 0) weight = QFont::Normal; return weight; }
415     inline void setFontItalic(bool italic)
416     { setProperty(FontItalic, italic); }
417     inline bool fontItalic() const
418     { return boolProperty(FontItalic); }
419     inline void setFontCapitalization(QFont::Capitalization capitalization)
420     { setProperty(FontCapitalization, capitalization); }
421     inline QFont::Capitalization fontCapitalization() const
422     { return static_cast<QFont::Capitalization>(intProperty(FontCapitalization)); }
423     inline void setFontLetterSpacing(qreal spacing)
424     { setProperty(FontLetterSpacing, spacing); }
425     inline qreal fontLetterSpacing() const
426     { return doubleProperty(FontLetterSpacing); }
427     inline void setFontWordSpacing(qreal spacing)
428     { setProperty(FontWordSpacing, spacing); }
429     inline qreal fontWordSpacing() const
430     { return doubleProperty(FontWordSpacing); }
431 
432     inline void setFontUnderline(bool underline)
433     { setProperty(TextUnderlineStyle, underline ? SingleUnderline : NoUnderline); }
434     bool fontUnderline() const;
435 
436     inline void setFontOverline(bool overline)
437     { setProperty(FontOverline, overline); }
438     inline bool fontOverline() const
439     { return boolProperty(FontOverline); }
440 
441     inline void setFontStrikeOut(bool strikeOut)
442     { setProperty(FontStrikeOut, strikeOut); }
443     inline bool fontStrikeOut() const
444     { return boolProperty(FontStrikeOut); }
445 
446     inline void setUnderlineColor(const QColor &color)
447     { setProperty(TextUnderlineColor, color); }
448     inline QColor underlineColor() const
449     { return colorProperty(TextUnderlineColor); }
450 
451     inline void setFontFixedPitch(bool fixedPitch)
452     { setProperty(FontFixedPitch, fixedPitch); }
453     inline bool fontFixedPitch() const
454     { return boolProperty(FontFixedPitch); }
455 
456     inline void setFontStyleHint(QFont::StyleHint hint, QFont::StyleStrategy strategy = QFont::PreferDefault)
457     { setProperty(FontStyleHint, hint); setProperty(FontStyleStrategy, strategy); }
458     inline void setFontStyleStrategy(QFont::StyleStrategy strategy)
459     { setProperty(FontStyleStrategy, strategy); }
460     QFont::StyleHint fontStyleHint() const
461     { return static_cast<QFont::StyleHint>(intProperty(FontStyleHint)); }
462     QFont::StyleStrategy fontStyleStrategy() const
463     { return static_cast<QFont::StyleStrategy>(intProperty(FontStyleStrategy)); }
464 
465     inline void setFontHintingPreference(QFont::HintingPreference hintingPreference)
466     {
467         setProperty(FontHintingPreference, hintingPreference);
468     }
469 
470     inline QFont::HintingPreference fontHintingPreference() const
471     {
472         return static_cast<QFont::HintingPreference>(intProperty(FontHintingPreference));
473     }
474 
475     inline void setFontKerning(bool enable)
476     { setProperty(FontKerning, enable); }
477     inline bool fontKerning() const
478     { return boolProperty(FontKerning); }
479 
480     void setUnderlineStyle(UnderlineStyle style);
481     inline UnderlineStyle underlineStyle() const
482     { return static_cast<UnderlineStyle>(intProperty(TextUnderlineStyle)); }
483 
484     inline void setVerticalAlignment(VerticalAlignment alignment)
485     { setProperty(TextVerticalAlignment, alignment); }
486     inline VerticalAlignment verticalAlignment() const
487     { return static_cast<VerticalAlignment>(intProperty(TextVerticalAlignment)); }
488 
489     inline void setTextOutline(const QPen &pen)
490     { setProperty(TextOutline, pen); }
491     inline QPen textOutline() const
492     { return penProperty(TextOutline); }
493 
494     inline void setToolTip(const QString &tip)
495     { setProperty(TextToolTip, tip); }
496     inline QString toolTip() const
497     { return stringProperty(TextToolTip); }
498 
499     inline void setAnchor(bool anchor)
500     { setProperty(IsAnchor, anchor); }
501     inline bool isAnchor() const
502     { return boolProperty(IsAnchor); }
503 
504     inline void setAnchorHref(const QString &value)
505     { setProperty(AnchorHref, value); }
506     inline QString anchorHref() const
507     { return stringProperty(AnchorHref); }
508 
509     inline void setAnchorName(const QString &name)
510     { setAnchorNames(QStringList(name)); }
511     QString anchorName() const;
512 
513     inline void setAnchorNames(const QStringList &names)
514     { setProperty(AnchorName, names); }
515     QStringList anchorNames() const;
516 
517     inline void setTableCellRowSpan(int tableCellRowSpan);
518     inline int tableCellRowSpan() const
519     { int s = intProperty(TableCellRowSpan); if (s == 0) s = 1; return s; }
520     inline void setTableCellColumnSpan(int tableCellColumnSpan);
521     inline int tableCellColumnSpan() const
522     { int s = intProperty(TableCellColumnSpan); if (s == 0) s = 1; return s; }
523 
524 protected:
525     explicit QTextCharFormat(const QTextFormat &fmt);
526     friend class QTextFormat;
527 };
528 
setTableCellRowSpan(int _tableCellRowSpan)529 inline void QTextCharFormat::setTableCellRowSpan(int _tableCellRowSpan)
530 {
531     if (_tableCellRowSpan <= 1)
532         clearProperty(TableCellRowSpan); // the getter will return 1 here.
533     else
534         setProperty(TableCellRowSpan, _tableCellRowSpan);
535 }
536 
setTableCellColumnSpan(int _tableCellColumnSpan)537 inline void QTextCharFormat::setTableCellColumnSpan(int _tableCellColumnSpan)
538 {
539     if (_tableCellColumnSpan <= 1)
540         clearProperty(TableCellColumnSpan); // the getter will return 1 here.
541     else
542         setProperty(TableCellColumnSpan, _tableCellColumnSpan);
543 }
544 
545 class Q_GUI_EXPORT QTextBlockFormat : public QTextFormat
546 {
547 public:
548     enum LineHeightTypes {
549         SingleHeight = 0,
550         ProportionalHeight = 1,
551         FixedHeight = 2,
552         MinimumHeight = 3,
553         LineDistanceHeight = 4
554     };
555 
556     QTextBlockFormat();
557 
isValid()558     bool isValid() const { return isBlockFormat(); }
559 
560     inline void setAlignment(Qt::Alignment alignment);
alignment()561     inline Qt::Alignment alignment() const
562     { int a = intProperty(BlockAlignment); if (a == 0) a = Qt::AlignLeft; return QFlag(a); }
563 
setTopMargin(qreal margin)564     inline void setTopMargin(qreal margin)
565     { setProperty(BlockTopMargin, margin); }
topMargin()566     inline qreal topMargin() const
567     { return doubleProperty(BlockTopMargin); }
568 
setBottomMargin(qreal margin)569     inline void setBottomMargin(qreal margin)
570     { setProperty(BlockBottomMargin, margin); }
bottomMargin()571     inline qreal bottomMargin() const
572     { return doubleProperty(BlockBottomMargin); }
573 
setLeftMargin(qreal margin)574     inline void setLeftMargin(qreal margin)
575     { setProperty(BlockLeftMargin, margin); }
leftMargin()576     inline qreal leftMargin() const
577     { return doubleProperty(BlockLeftMargin); }
578 
setRightMargin(qreal margin)579     inline void setRightMargin(qreal margin)
580     { setProperty(BlockRightMargin, margin); }
rightMargin()581     inline qreal rightMargin() const
582     { return doubleProperty(BlockRightMargin); }
583 
setTextIndent(qreal aindent)584     inline void setTextIndent(qreal aindent)
585     { setProperty(TextIndent, aindent); }
textIndent()586     inline qreal textIndent() const
587     { return doubleProperty(TextIndent); }
588 
589     inline void setIndent(int indent);
indent()590     inline int indent() const
591     { return intProperty(BlockIndent); }
592 
setLineHeight(qreal height,int heightType)593     inline void setLineHeight(qreal height, int heightType)
594     { setProperty(LineHeight, height); setProperty(LineHeightType, heightType); }
595     inline qreal lineHeight(qreal scriptLineHeight, qreal scaling) const;
lineHeight()596     inline qreal lineHeight() const
597     { return doubleProperty(LineHeight); }
lineHeightType()598     inline int lineHeightType() const
599     { return intProperty(LineHeightType); }
600 
setNonBreakableLines(bool b)601     inline void setNonBreakableLines(bool b)
602     { setProperty(BlockNonBreakableLines, b); }
nonBreakableLines()603     inline bool nonBreakableLines() const
604     { return boolProperty(BlockNonBreakableLines); }
605 
setPageBreakPolicy(PageBreakFlags flags)606     inline void setPageBreakPolicy(PageBreakFlags flags)
607     { setProperty(PageBreakPolicy, int(flags)); }
pageBreakPolicy()608     inline PageBreakFlags pageBreakPolicy() const
609     { return PageBreakFlags(intProperty(PageBreakPolicy)); }
610 
611     void setTabPositions(const QList<QTextOption::Tab> &tabs);
612     QList<QTextOption::Tab> tabPositions() const;
613 
614 protected:
615     explicit QTextBlockFormat(const QTextFormat &fmt);
616     friend class QTextFormat;
617 };
618 
setAlignment(Qt::Alignment aalignment)619 inline void QTextBlockFormat::setAlignment(Qt::Alignment aalignment)
620 { setProperty(BlockAlignment, int(aalignment)); }
621 
setIndent(int aindent)622 inline void QTextBlockFormat::setIndent(int aindent)
623 { setProperty(BlockIndent, aindent); }
624 
625 inline qreal QTextBlockFormat::lineHeight(qreal scriptLineHeight, qreal scaling = 1.0) const
626 {
627   switch(intProperty(LineHeightType)) {
628     case SingleHeight:
629       return(scriptLineHeight);
630     case ProportionalHeight:
631       return(scriptLineHeight * doubleProperty(LineHeight) / 100.0);
632     case FixedHeight:
633       return(doubleProperty(LineHeight) * scaling);
634     case MinimumHeight:
635       return(qMax(scriptLineHeight, doubleProperty(LineHeight) * scaling));
636     case LineDistanceHeight:
637       return(scriptLineHeight + doubleProperty(LineHeight) * scaling);
638   }
639   return(0);
640 }
641 
642 class Q_GUI_EXPORT QTextListFormat : public QTextFormat
643 {
644 public:
645     QTextListFormat();
646 
isValid()647     bool isValid() const { return isListFormat(); }
648 
649     enum Style {
650         ListDisc = -1,
651         ListCircle = -2,
652         ListSquare = -3,
653         ListDecimal = -4,
654         ListLowerAlpha = -5,
655         ListUpperAlpha = -6,
656         ListLowerRoman = -7,
657         ListUpperRoman = -8,
658         ListStyleUndefined = 0
659     };
660 
661     inline void setStyle(Style style);
style()662     inline Style style() const
663     { return static_cast<Style>(intProperty(ListStyle)); }
664 
665     inline void setIndent(int indent);
indent()666     inline int indent() const
667     { return intProperty(ListIndent); }
668 
669     inline void setNumberPrefix(const QString &numberPrefix);
numberPrefix()670     inline QString numberPrefix() const
671     { return stringProperty(ListNumberPrefix); }
672 
673     inline void setNumberSuffix(const QString &numberSuffix);
numberSuffix()674     inline QString numberSuffix() const
675     { return stringProperty(ListNumberSuffix); }
676 
677 protected:
678     explicit QTextListFormat(const QTextFormat &fmt);
679     friend class QTextFormat;
680 };
681 
setStyle(Style astyle)682 inline void QTextListFormat::setStyle(Style astyle)
683 { setProperty(ListStyle, astyle); }
684 
setIndent(int aindent)685 inline void QTextListFormat::setIndent(int aindent)
686 { setProperty(ListIndent, aindent); }
687 
setNumberPrefix(const QString & np)688 inline void QTextListFormat::setNumberPrefix(const QString &np)
689 { setProperty(ListNumberPrefix, np); }
690 
setNumberSuffix(const QString & ns)691 inline void QTextListFormat::setNumberSuffix(const QString &ns)
692 { setProperty(ListNumberSuffix, ns); }
693 
694 class Q_GUI_EXPORT QTextImageFormat : public QTextCharFormat
695 {
696 public:
697     QTextImageFormat();
698 
isValid()699     bool isValid() const { return isImageFormat(); }
700 
701     inline void setName(const QString &name);
name()702     inline QString name() const
703     { return stringProperty(ImageName); }
704 
705     inline void setWidth(qreal width);
width()706     inline qreal width() const
707     { return doubleProperty(ImageWidth); }
708 
709     inline void setHeight(qreal height);
height()710     inline qreal height() const
711     { return doubleProperty(ImageHeight); }
712 
713 protected:
714     explicit QTextImageFormat(const QTextFormat &format);
715     friend class QTextFormat;
716 };
717 
setName(const QString & aname)718 inline void QTextImageFormat::setName(const QString &aname)
719 { setProperty(ImageName, aname); }
720 
setWidth(qreal awidth)721 inline void QTextImageFormat::setWidth(qreal awidth)
722 { setProperty(ImageWidth, awidth); }
723 
setHeight(qreal aheight)724 inline void QTextImageFormat::setHeight(qreal aheight)
725 { setProperty(ImageHeight, aheight); }
726 
727 class Q_GUI_EXPORT QTextFrameFormat : public QTextFormat
728 {
729 public:
730     QTextFrameFormat();
731 
isValid()732     bool isValid() const { return isFrameFormat(); }
733 
734     enum Position {
735         InFlow,
736         FloatLeft,
737         FloatRight
738         // ######
739 //        Absolute
740     };
741 
742     enum BorderStyle {
743         BorderStyle_None,
744         BorderStyle_Dotted,
745         BorderStyle_Dashed,
746         BorderStyle_Solid,
747         BorderStyle_Double,
748         BorderStyle_DotDash,
749         BorderStyle_DotDotDash,
750         BorderStyle_Groove,
751         BorderStyle_Ridge,
752         BorderStyle_Inset,
753         BorderStyle_Outset
754     };
755 
setPosition(Position f)756     inline void setPosition(Position f)
757     { setProperty(CssFloat, f); }
position()758     inline Position position() const
759     { return static_cast<Position>(intProperty(CssFloat)); }
760 
761     inline void setBorder(qreal border);
border()762     inline qreal border() const
763     { return doubleProperty(FrameBorder); }
764 
setBorderBrush(const QBrush & brush)765     inline void setBorderBrush(const QBrush &brush)
766     { setProperty(FrameBorderBrush, brush); }
borderBrush()767     inline QBrush borderBrush() const
768     { return brushProperty(FrameBorderBrush); }
769 
setBorderStyle(BorderStyle style)770     inline void setBorderStyle(BorderStyle style)
771     { setProperty(FrameBorderStyle, style); }
borderStyle()772     inline BorderStyle borderStyle() const
773     { return static_cast<BorderStyle>(intProperty(FrameBorderStyle)); }
774 
775     void setMargin(qreal margin);
margin()776     inline qreal margin() const
777     { return doubleProperty(FrameMargin); }
778 
779     inline void setTopMargin(qreal margin);
780     qreal topMargin() const;
781 
782     inline void setBottomMargin(qreal margin);
783     qreal bottomMargin() const;
784 
785     inline void setLeftMargin(qreal margin);
786     qreal leftMargin() const;
787 
788     inline void setRightMargin(qreal margin);
789     qreal rightMargin() const;
790 
791     inline void setPadding(qreal padding);
padding()792     inline qreal padding() const
793     { return doubleProperty(FramePadding); }
794 
795     inline void setWidth(qreal width);
setWidth(const QTextLength & length)796     inline void setWidth(const QTextLength &length)
797     { setProperty(FrameWidth, length); }
width()798     inline QTextLength width() const
799     { return lengthProperty(FrameWidth); }
800 
801     inline void setHeight(qreal height);
802     inline void setHeight(const QTextLength &height);
height()803     inline QTextLength height() const
804     { return lengthProperty(FrameHeight); }
805 
setPageBreakPolicy(PageBreakFlags flags)806     inline void setPageBreakPolicy(PageBreakFlags flags)
807     { setProperty(PageBreakPolicy, int(flags)); }
pageBreakPolicy()808     inline PageBreakFlags pageBreakPolicy() const
809     { return PageBreakFlags(intProperty(PageBreakPolicy)); }
810 
811 protected:
812     explicit QTextFrameFormat(const QTextFormat &fmt);
813     friend class QTextFormat;
814 };
815 
setBorder(qreal aborder)816 inline void QTextFrameFormat::setBorder(qreal aborder)
817 { setProperty(FrameBorder, aborder); }
818 
setPadding(qreal apadding)819 inline void QTextFrameFormat::setPadding(qreal apadding)
820 { setProperty(FramePadding, apadding); }
821 
setWidth(qreal awidth)822 inline void QTextFrameFormat::setWidth(qreal awidth)
823 { setProperty(FrameWidth, QTextLength(QTextLength::FixedLength, awidth)); }
824 
setHeight(qreal aheight)825 inline void QTextFrameFormat::setHeight(qreal aheight)
826 { setProperty(FrameHeight, QTextLength(QTextLength::FixedLength, aheight)); }
setHeight(const QTextLength & aheight)827 inline void QTextFrameFormat::setHeight(const QTextLength &aheight)
828 { setProperty(FrameHeight, aheight); }
829 
setTopMargin(qreal amargin)830 inline void QTextFrameFormat::setTopMargin(qreal amargin)
831 { setProperty(FrameTopMargin, amargin); }
832 
setBottomMargin(qreal amargin)833 inline void QTextFrameFormat::setBottomMargin(qreal amargin)
834 { setProperty(FrameBottomMargin, amargin); }
835 
setLeftMargin(qreal amargin)836 inline void QTextFrameFormat::setLeftMargin(qreal amargin)
837 { setProperty(FrameLeftMargin, amargin); }
838 
setRightMargin(qreal amargin)839 inline void QTextFrameFormat::setRightMargin(qreal amargin)
840 { setProperty(FrameRightMargin, amargin); }
841 
842 class Q_GUI_EXPORT QTextTableFormat : public QTextFrameFormat
843 {
844 public:
845     QTextTableFormat();
846 
isValid()847     inline bool isValid() const { return isTableFormat(); }
848 
columns()849     inline int columns() const
850     { int cols = intProperty(TableColumns); if (cols == 0) cols = 1; return cols; }
851     inline void setColumns(int columns);
852 
setColumnWidthConstraints(const QVector<QTextLength> & constraints)853     inline void setColumnWidthConstraints(const QVector<QTextLength> &constraints)
854     { setProperty(TableColumnWidthConstraints, constraints); }
855 
columnWidthConstraints()856     inline QVector<QTextLength> columnWidthConstraints() const
857     { return lengthVectorProperty(TableColumnWidthConstraints); }
858 
clearColumnWidthConstraints()859     inline void clearColumnWidthConstraints()
860     { clearProperty(TableColumnWidthConstraints); }
861 
cellSpacing()862     inline qreal cellSpacing() const
863     { return doubleProperty(TableCellSpacing); }
setCellSpacing(qreal spacing)864     inline void setCellSpacing(qreal spacing)
865     { setProperty(TableCellSpacing, spacing); }
866 
cellPadding()867     inline qreal cellPadding() const
868     { return doubleProperty(TableCellPadding); }
869     inline void setCellPadding(qreal padding);
870 
871     inline void setAlignment(Qt::Alignment alignment);
alignment()872     inline Qt::Alignment alignment() const
873     { return QFlag(intProperty(BlockAlignment)); }
874 
setHeaderRowCount(int count)875     inline void setHeaderRowCount(int count)
876     { setProperty(TableHeaderRowCount, count); }
headerRowCount()877     inline int headerRowCount() const
878     { return intProperty(TableHeaderRowCount); }
879 
880 protected:
881     explicit QTextTableFormat(const QTextFormat &fmt);
882     friend class QTextFormat;
883 };
884 
setColumns(int acolumns)885 inline void QTextTableFormat::setColumns(int acolumns)
886 {
887     if (acolumns == 1)
888         acolumns = 0;
889     setProperty(TableColumns, acolumns);
890 }
891 
setCellPadding(qreal apadding)892 inline void QTextTableFormat::setCellPadding(qreal apadding)
893 { setProperty(TableCellPadding, apadding); }
894 
setAlignment(Qt::Alignment aalignment)895 inline void QTextTableFormat::setAlignment(Qt::Alignment aalignment)
896 { setProperty(BlockAlignment, int(aalignment)); }
897 
898 class Q_GUI_EXPORT QTextTableCellFormat : public QTextCharFormat
899 {
900 public:
901     QTextTableCellFormat();
902 
isValid()903     inline bool isValid() const { return isTableCellFormat(); }
904 
905     inline void setTopPadding(qreal padding);
906     inline qreal topPadding() const;
907 
908     inline void setBottomPadding(qreal padding);
909     inline qreal bottomPadding() const;
910 
911     inline void setLeftPadding(qreal padding);
912     inline qreal leftPadding() const;
913 
914     inline void setRightPadding(qreal padding);
915     inline qreal rightPadding() const;
916 
917     inline void setPadding(qreal padding);
918 
919 protected:
920     explicit QTextTableCellFormat(const QTextFormat &fmt);
921     friend class QTextFormat;
922 };
923 
setTopPadding(qreal padding)924 inline void QTextTableCellFormat::setTopPadding(qreal padding)
925 {
926     setProperty(TableCellTopPadding, padding);
927 }
928 
topPadding()929 inline qreal QTextTableCellFormat::topPadding() const
930 {
931     return doubleProperty(TableCellTopPadding);
932 }
933 
setBottomPadding(qreal padding)934 inline void QTextTableCellFormat::setBottomPadding(qreal padding)
935 {
936     setProperty(TableCellBottomPadding, padding);
937 }
938 
bottomPadding()939 inline qreal QTextTableCellFormat::bottomPadding() const
940 {
941     return doubleProperty(TableCellBottomPadding);
942 }
943 
setLeftPadding(qreal padding)944 inline void QTextTableCellFormat::setLeftPadding(qreal padding)
945 {
946     setProperty(TableCellLeftPadding, padding);
947 }
948 
leftPadding()949 inline qreal QTextTableCellFormat::leftPadding() const
950 {
951     return doubleProperty(TableCellLeftPadding);
952 }
953 
setRightPadding(qreal padding)954 inline void QTextTableCellFormat::setRightPadding(qreal padding)
955 {
956     setProperty(TableCellRightPadding, padding);
957 }
958 
rightPadding()959 inline qreal QTextTableCellFormat::rightPadding() const
960 {
961     return doubleProperty(TableCellRightPadding);
962 }
963 
setPadding(qreal padding)964 inline void QTextTableCellFormat::setPadding(qreal padding)
965 {
966     setTopPadding(padding);
967     setBottomPadding(padding);
968     setLeftPadding(padding);
969     setRightPadding(padding);
970 }
971 
972 
973 QT_END_NAMESPACE
974 
975 QT_END_HEADER
976 
977 #endif // QTEXTFORMAT_H
978