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