Get started with patching up the Qt GUI docs
[profile/ivi/qtbase.git] / src / gui / text / qtextformat.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
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         FontAbsoluteLetterSpacing = 0x2033, // if true FontLetterSpacing is absolute
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 merge(const QTextFormat &other);
295
296     inline bool isValid() const { return type() != InvalidFormat; }
297
298     int type() const;
299
300     int objectIndex() const;
301     void setObjectIndex(int object);
302
303     QVariant property(int propertyId) const;
304     void setProperty(int propertyId, const QVariant &value);
305     void clearProperty(int propertyId);
306     bool hasProperty(int propertyId) const;
307
308     bool boolProperty(int propertyId) const;
309     int intProperty(int propertyId) const;
310     qreal doubleProperty(int propertyId) const;
311     QString stringProperty(int propertyId) const;
312     QColor colorProperty(int propertyId) const;
313     QPen penProperty(int propertyId) const;
314     QBrush brushProperty(int propertyId) const;
315     QTextLength lengthProperty(int propertyId) const;
316     QVector<QTextLength> lengthVectorProperty(int propertyId) const;
317
318     void setProperty(int propertyId, const QVector<QTextLength> &lengths);
319
320     QMap<int, QVariant> properties() const;
321     int propertyCount() const;
322
323     inline void setObjectType(int type);
324     inline int objectType() const
325     { return intProperty(ObjectType); }
326
327     inline bool isCharFormat() const { return type() == CharFormat; }
328     inline bool isBlockFormat() const { return type() == BlockFormat; }
329     inline bool isListFormat() const { return type() == ListFormat; }
330     inline bool isFrameFormat() const { return type() == FrameFormat; }
331     inline bool isImageFormat() const { return type() == CharFormat && objectType() == ImageObject; }
332     inline bool isTableFormat() const { return type() == FrameFormat && objectType() == TableObject; }
333     inline bool isTableCellFormat() const { return type() == CharFormat && objectType() == TableCellObject; }
334
335     QTextBlockFormat toBlockFormat() const;
336     QTextCharFormat toCharFormat() const;
337     QTextListFormat toListFormat() const;
338     QTextTableFormat toTableFormat() const;
339     QTextFrameFormat toFrameFormat() const;
340     QTextImageFormat toImageFormat() const;
341     QTextTableCellFormat toTableCellFormat() const;
342
343     bool operator==(const QTextFormat &rhs) const;
344     inline bool operator!=(const QTextFormat &rhs) const { return !operator==(rhs); }
345     operator QVariant() const;
346
347     inline void setLayoutDirection(Qt::LayoutDirection direction)
348         { setProperty(QTextFormat::LayoutDirection, direction); }
349     inline Qt::LayoutDirection layoutDirection() const
350         { return Qt::LayoutDirection(intProperty(QTextFormat::LayoutDirection)); }
351
352     inline void setBackground(const QBrush &brush)
353     { setProperty(BackgroundBrush, brush); }
354     inline QBrush background() const
355     { return brushProperty(BackgroundBrush); }
356     inline void clearBackground()
357     { clearProperty(BackgroundBrush); }
358
359     inline void setForeground(const QBrush &brush)
360     { setProperty(ForegroundBrush, brush); }
361     inline QBrush foreground() const
362     { return brushProperty(ForegroundBrush); }
363     inline void clearForeground()
364     { clearProperty(ForegroundBrush); }
365
366 private:
367     QSharedDataPointer<QTextFormatPrivate> d;
368     qint32 format_type;
369
370     friend class QTextFormatCollection;
371     friend class QTextCharFormat;
372     friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextFormat &);
373     friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextFormat &);
374 };
375
376 inline void QTextFormat::setObjectType(int atype)
377 { setProperty(ObjectType, atype); }
378
379 Q_DECLARE_OPERATORS_FOR_FLAGS(QTextFormat::PageBreakFlags)
380
381 class Q_GUI_EXPORT QTextCharFormat : public QTextFormat
382 {
383 public:
384     enum VerticalAlignment {
385         AlignNormal = 0,
386         AlignSuperScript,
387         AlignSubScript,
388         AlignMiddle,
389         AlignTop,
390         AlignBottom,
391         AlignBaseline
392     };
393     enum UnderlineStyle { // keep in sync with Qt::PenStyle!
394         NoUnderline,
395         SingleUnderline,
396         DashUnderline,
397         DotLine,
398         DashDotLine,
399         DashDotDotLine,
400         WaveUnderline,
401         SpellCheckUnderline
402     };
403
404     QTextCharFormat();
405
406     bool isValid() const { return isCharFormat(); }
407     void setFont(const QFont &font);
408     QFont font() const;
409
410     inline void setFontFamily(const QString &family)
411     { setProperty(FontFamily, family); }
412     inline QString fontFamily() const
413     { return stringProperty(FontFamily); }
414
415     inline void setFontPointSize(qreal size)
416     { setProperty(FontPointSize, size); }
417     inline qreal fontPointSize() const
418     { return doubleProperty(FontPointSize); }
419
420     inline void setFontWeight(int weight)
421     { if (weight == QFont::Normal) weight = 0; setProperty(FontWeight, weight); }
422     inline int fontWeight() const
423     { int weight = intProperty(FontWeight); if (weight == 0) weight = QFont::Normal; return weight; }
424     inline void setFontItalic(bool italic)
425     { setProperty(FontItalic, italic); }
426     inline bool fontItalic() const
427     { return boolProperty(FontItalic); }
428     inline void setFontCapitalization(QFont::Capitalization capitalization)
429     { setProperty(FontCapitalization, capitalization); }
430     inline QFont::Capitalization fontCapitalization() const
431     { return static_cast<QFont::Capitalization>(intProperty(FontCapitalization)); }
432     inline void setFontAbsoluteLetterSpacing(qreal absoluteSpacing)
433     { setProperty(FontAbsoluteLetterSpacing, absoluteSpacing);
434       clearProperty(FontLetterSpacing); }
435     inline qreal fontAbsoluteLetterSpacing() const
436     { return doubleProperty(FontAbsoluteLetterSpacing); }
437     inline void setFontLetterSpacing(qreal spacing)
438     { setProperty(FontLetterSpacing, spacing);
439       clearProperty(FontAbsoluteLetterSpacing); }
440     inline qreal fontLetterSpacing() const
441     { return doubleProperty(FontLetterSpacing); }
442     inline void setFontWordSpacing(qreal spacing)
443     { setProperty(FontWordSpacing, spacing); }
444     inline qreal fontWordSpacing() const
445     { return doubleProperty(FontWordSpacing); }
446
447     inline void setFontUnderline(bool underline)
448     { setProperty(TextUnderlineStyle, underline ? SingleUnderline : NoUnderline); }
449     bool fontUnderline() const;
450
451     inline void setFontOverline(bool overline)
452     { setProperty(FontOverline, overline); }
453     inline bool fontOverline() const
454     { return boolProperty(FontOverline); }
455
456     inline void setFontStrikeOut(bool strikeOut)
457     { setProperty(FontStrikeOut, strikeOut); }
458     inline bool fontStrikeOut() const
459     { return boolProperty(FontStrikeOut); }
460
461     inline void setUnderlineColor(const QColor &color)
462     { setProperty(TextUnderlineColor, color); }
463     inline QColor underlineColor() const
464     { return colorProperty(TextUnderlineColor); }
465
466     inline void setFontFixedPitch(bool fixedPitch)
467     { setProperty(FontFixedPitch, fixedPitch); }
468     inline bool fontFixedPitch() const
469     { return boolProperty(FontFixedPitch); }
470
471     inline void setFontStretch(qreal factor)
472     { setProperty(FontStretch, factor); }
473     inline int fontStretch() const
474     { return intProperty(FontStretch); }
475
476     inline void setFontStyleHint(QFont::StyleHint hint, QFont::StyleStrategy strategy = QFont::PreferDefault)
477     { setProperty(FontStyleHint, hint); setProperty(FontStyleStrategy, strategy); }
478     inline void setFontStyleStrategy(QFont::StyleStrategy strategy)
479     { setProperty(FontStyleStrategy, strategy); }
480     QFont::StyleHint fontStyleHint() const
481     { return static_cast<QFont::StyleHint>(intProperty(FontStyleHint)); }
482     QFont::StyleStrategy fontStyleStrategy() const
483     { return static_cast<QFont::StyleStrategy>(intProperty(FontStyleStrategy)); }
484
485     inline void setFontHintingPreference(QFont::HintingPreference hintingPreference)
486     {
487         setProperty(FontHintingPreference, hintingPreference);
488     }
489
490     inline QFont::HintingPreference fontHintingPreference() const
491     {
492         return static_cast<QFont::HintingPreference>(intProperty(FontHintingPreference));
493     }
494
495     inline void setFontKerning(bool enable)
496     { setProperty(FontKerning, enable); }
497     inline bool fontKerning() const
498     { return boolProperty(FontKerning); }
499
500     void setUnderlineStyle(UnderlineStyle style);
501     inline UnderlineStyle underlineStyle() const
502     { return static_cast<UnderlineStyle>(intProperty(TextUnderlineStyle)); }
503
504     inline void setVerticalAlignment(VerticalAlignment alignment)
505     { setProperty(TextVerticalAlignment, alignment); }
506     inline VerticalAlignment verticalAlignment() const
507     { return static_cast<VerticalAlignment>(intProperty(TextVerticalAlignment)); }
508
509     inline void setTextOutline(const QPen &pen)
510     { setProperty(TextOutline, pen); }
511     inline QPen textOutline() const
512     { return penProperty(TextOutline); }
513
514     inline void setToolTip(const QString &tip)
515     { setProperty(TextToolTip, tip); }
516     inline QString toolTip() const
517     { return stringProperty(TextToolTip); }
518
519     inline void setAnchor(bool anchor)
520     { setProperty(IsAnchor, anchor); }
521     inline bool isAnchor() const
522     { return boolProperty(IsAnchor); }
523
524     inline void setAnchorHref(const QString &value)
525     { setProperty(AnchorHref, value); }
526     inline QString anchorHref() const
527     { return stringProperty(AnchorHref); }
528
529     inline void setAnchorName(const QString &name)
530     { setAnchorNames(QStringList(name)); }
531     QString anchorName() const;
532
533     inline void setAnchorNames(const QStringList &names)
534     { setProperty(AnchorName, names); }
535     QStringList anchorNames() const;
536
537     inline void setTableCellRowSpan(int tableCellRowSpan);
538     inline int tableCellRowSpan() const
539     { int s = intProperty(TableCellRowSpan); if (s == 0) s = 1; return s; }
540     inline void setTableCellColumnSpan(int tableCellColumnSpan);
541     inline int tableCellColumnSpan() const
542     { int s = intProperty(TableCellColumnSpan); if (s == 0) s = 1; return s; }
543
544 protected:
545     explicit QTextCharFormat(const QTextFormat &fmt);
546     friend class QTextFormat;
547 };
548
549 inline void QTextCharFormat::setTableCellRowSpan(int _tableCellRowSpan)
550 {
551     if (_tableCellRowSpan <= 1)
552         clearProperty(TableCellRowSpan); // the getter will return 1 here.
553     else
554         setProperty(TableCellRowSpan, _tableCellRowSpan);
555 }
556
557 inline void QTextCharFormat::setTableCellColumnSpan(int _tableCellColumnSpan)
558 {
559     if (_tableCellColumnSpan <= 1)
560         clearProperty(TableCellColumnSpan); // the getter will return 1 here.
561     else
562         setProperty(TableCellColumnSpan, _tableCellColumnSpan);
563 }
564
565 class Q_GUI_EXPORT QTextBlockFormat : public QTextFormat
566 {
567 public:
568     enum LineHeightTypes {
569         SingleHeight = 0,
570         ProportionalHeight = 1,
571         FixedHeight = 2,
572         MinimumHeight = 3,
573         LineDistanceHeight = 4
574     };
575
576     QTextBlockFormat();
577
578     bool isValid() const { return isBlockFormat(); }
579
580     inline void setAlignment(Qt::Alignment alignment);
581     inline Qt::Alignment alignment() const
582     { int a = intProperty(BlockAlignment); if (a == 0) a = Qt::AlignLeft; return QFlag(a); }
583
584     inline void setTopMargin(qreal margin)
585     { setProperty(BlockTopMargin, margin); }
586     inline qreal topMargin() const
587     { return doubleProperty(BlockTopMargin); }
588
589     inline void setBottomMargin(qreal margin)
590     { setProperty(BlockBottomMargin, margin); }
591     inline qreal bottomMargin() const
592     { return doubleProperty(BlockBottomMargin); }
593
594     inline void setLeftMargin(qreal margin)
595     { setProperty(BlockLeftMargin, margin); }
596     inline qreal leftMargin() const
597     { return doubleProperty(BlockLeftMargin); }
598
599     inline void setRightMargin(qreal margin)
600     { setProperty(BlockRightMargin, margin); }
601     inline qreal rightMargin() const
602     { return doubleProperty(BlockRightMargin); }
603
604     inline void setTextIndent(qreal aindent)
605     { setProperty(TextIndent, aindent); }
606     inline qreal textIndent() const
607     { return doubleProperty(TextIndent); }
608
609     inline void setIndent(int indent);
610     inline int indent() const
611     { return intProperty(BlockIndent); }
612
613     inline void setLineHeight(qreal height, int heightType)
614     { setProperty(LineHeight, height); setProperty(LineHeightType, heightType); }
615     inline qreal lineHeight(qreal scriptLineHeight, qreal scaling) const;
616     inline qreal lineHeight() const
617     { return doubleProperty(LineHeight); }
618     inline int lineHeightType() const
619     { return intProperty(LineHeightType); }
620
621     inline void setNonBreakableLines(bool b)
622     { setProperty(BlockNonBreakableLines, b); }
623     inline bool nonBreakableLines() const
624     { return boolProperty(BlockNonBreakableLines); }
625
626     inline void setPageBreakPolicy(PageBreakFlags flags)
627     { setProperty(PageBreakPolicy, int(flags)); }
628     inline PageBreakFlags pageBreakPolicy() const
629     { return PageBreakFlags(intProperty(PageBreakPolicy)); }
630
631     void setTabPositions(const QList<QTextOption::Tab> &tabs);
632     QList<QTextOption::Tab> tabPositions() const;
633
634 protected:
635     explicit QTextBlockFormat(const QTextFormat &fmt);
636     friend class QTextFormat;
637 };
638
639 inline void QTextBlockFormat::setAlignment(Qt::Alignment aalignment)
640 { setProperty(BlockAlignment, int(aalignment)); }
641
642 inline void QTextBlockFormat::setIndent(int aindent)
643 { setProperty(BlockIndent, aindent); }
644
645 inline qreal QTextBlockFormat::lineHeight(qreal scriptLineHeight, qreal scaling = 1.0) const
646 {
647   switch(intProperty(LineHeightType)) {
648     case SingleHeight:
649       return(scriptLineHeight);
650     case ProportionalHeight:
651       return(scriptLineHeight * doubleProperty(LineHeight) / 100.0);
652     case FixedHeight:
653       return(doubleProperty(LineHeight) * scaling);
654     case MinimumHeight:
655       return(qMax(scriptLineHeight, doubleProperty(LineHeight) * scaling));
656     case LineDistanceHeight:
657       return(scriptLineHeight + doubleProperty(LineHeight) * scaling);
658   }
659   return(0);
660 }
661
662 class Q_GUI_EXPORT QTextListFormat : public QTextFormat
663 {
664 public:
665     QTextListFormat();
666
667     bool isValid() const { return isListFormat(); }
668
669     enum Style {
670         ListDisc = -1,
671         ListCircle = -2,
672         ListSquare = -3,
673         ListDecimal = -4,
674         ListLowerAlpha = -5,
675         ListUpperAlpha = -6,
676         ListLowerRoman = -7,
677         ListUpperRoman = -8,
678         ListStyleUndefined = 0
679     };
680
681     inline void setStyle(Style style);
682     inline Style style() const
683     { return static_cast<Style>(intProperty(ListStyle)); }
684
685     inline void setIndent(int indent);
686     inline int indent() const
687     { return intProperty(ListIndent); }
688
689     inline void setNumberPrefix(const QString &numberPrefix);
690     inline QString numberPrefix() const
691     { return stringProperty(ListNumberPrefix); }
692
693     inline void setNumberSuffix(const QString &numberSuffix);
694     inline QString numberSuffix() const
695     { return stringProperty(ListNumberSuffix); }
696
697 protected:
698     explicit QTextListFormat(const QTextFormat &fmt);
699     friend class QTextFormat;
700 };
701
702 inline void QTextListFormat::setStyle(Style astyle)
703 { setProperty(ListStyle, astyle); }
704
705 inline void QTextListFormat::setIndent(int aindent)
706 { setProperty(ListIndent, aindent); }
707
708 inline void QTextListFormat::setNumberPrefix(const QString &np)
709 { setProperty(ListNumberPrefix, np); }
710
711 inline void QTextListFormat::setNumberSuffix(const QString &ns)
712 { setProperty(ListNumberSuffix, ns); }
713
714 class Q_GUI_EXPORT QTextImageFormat : public QTextCharFormat
715 {
716 public:
717     QTextImageFormat();
718
719     bool isValid() const { return isImageFormat(); }
720
721     inline void setName(const QString &name);
722     inline QString name() const
723     { return stringProperty(ImageName); }
724
725     inline void setWidth(qreal width);
726     inline qreal width() const
727     { return doubleProperty(ImageWidth); }
728
729     inline void setHeight(qreal height);
730     inline qreal height() const
731     { return doubleProperty(ImageHeight); }
732
733 protected:
734     explicit QTextImageFormat(const QTextFormat &format);
735     friend class QTextFormat;
736 };
737
738 inline void QTextImageFormat::setName(const QString &aname)
739 { setProperty(ImageName, aname); }
740
741 inline void QTextImageFormat::setWidth(qreal awidth)
742 { setProperty(ImageWidth, awidth); }
743
744 inline void QTextImageFormat::setHeight(qreal aheight)
745 { setProperty(ImageHeight, aheight); }
746
747 class Q_GUI_EXPORT QTextFrameFormat : public QTextFormat
748 {
749 public:
750     QTextFrameFormat();
751
752     bool isValid() const { return isFrameFormat(); }
753
754     enum Position {
755         InFlow,
756         FloatLeft,
757         FloatRight
758         // ######
759 //        Absolute
760     };
761
762     enum BorderStyle {
763         BorderStyle_None,
764         BorderStyle_Dotted,
765         BorderStyle_Dashed,
766         BorderStyle_Solid,
767         BorderStyle_Double,
768         BorderStyle_DotDash,
769         BorderStyle_DotDotDash,
770         BorderStyle_Groove,
771         BorderStyle_Ridge,
772         BorderStyle_Inset,
773         BorderStyle_Outset
774     };
775
776     inline void setPosition(Position f)
777     { setProperty(CssFloat, f); }
778     inline Position position() const
779     { return static_cast<Position>(intProperty(CssFloat)); }
780
781     inline void setBorder(qreal border);
782     inline qreal border() const
783     { return doubleProperty(FrameBorder); }
784
785     inline void setBorderBrush(const QBrush &brush)
786     { setProperty(FrameBorderBrush, brush); }
787     inline QBrush borderBrush() const
788     { return brushProperty(FrameBorderBrush); }
789
790     inline void setBorderStyle(BorderStyle style)
791     { setProperty(FrameBorderStyle, style); }
792     inline BorderStyle borderStyle() const
793     { return static_cast<BorderStyle>(intProperty(FrameBorderStyle)); }
794
795     void setMargin(qreal margin);
796     inline qreal margin() const
797     { return doubleProperty(FrameMargin); }
798
799     inline void setTopMargin(qreal margin);
800     qreal topMargin() const;
801
802     inline void setBottomMargin(qreal margin);
803     qreal bottomMargin() const;
804
805     inline void setLeftMargin(qreal margin);
806     qreal leftMargin() const;
807
808     inline void setRightMargin(qreal margin);
809     qreal rightMargin() const;
810
811     inline void setPadding(qreal padding);
812     inline qreal padding() const
813     { return doubleProperty(FramePadding); }
814
815     inline void setWidth(qreal width);
816     inline void setWidth(const QTextLength &length)
817     { setProperty(FrameWidth, length); }
818     inline QTextLength width() const
819     { return lengthProperty(FrameWidth); }
820
821     inline void setHeight(qreal height);
822     inline void setHeight(const QTextLength &height);
823     inline QTextLength height() const
824     { return lengthProperty(FrameHeight); }
825
826     inline void setPageBreakPolicy(PageBreakFlags flags)
827     { setProperty(PageBreakPolicy, int(flags)); }
828     inline PageBreakFlags pageBreakPolicy() const
829     { return PageBreakFlags(intProperty(PageBreakPolicy)); }
830
831 protected:
832     explicit QTextFrameFormat(const QTextFormat &fmt);
833     friend class QTextFormat;
834 };
835
836 inline void QTextFrameFormat::setBorder(qreal aborder)
837 { setProperty(FrameBorder, aborder); }
838
839 inline void QTextFrameFormat::setPadding(qreal apadding)
840 { setProperty(FramePadding, apadding); }
841
842 inline void QTextFrameFormat::setWidth(qreal awidth)
843 { setProperty(FrameWidth, QTextLength(QTextLength::FixedLength, awidth)); }
844
845 inline void QTextFrameFormat::setHeight(qreal aheight)
846 { setProperty(FrameHeight, QTextLength(QTextLength::FixedLength, aheight)); }
847 inline void QTextFrameFormat::setHeight(const QTextLength &aheight)
848 { setProperty(FrameHeight, aheight); }
849
850 inline void QTextFrameFormat::setTopMargin(qreal amargin)
851 { setProperty(FrameTopMargin, amargin); }
852
853 inline void QTextFrameFormat::setBottomMargin(qreal amargin)
854 { setProperty(FrameBottomMargin, amargin); }
855
856 inline void QTextFrameFormat::setLeftMargin(qreal amargin)
857 { setProperty(FrameLeftMargin, amargin); }
858
859 inline void QTextFrameFormat::setRightMargin(qreal amargin)
860 { setProperty(FrameRightMargin, amargin); }
861
862 class Q_GUI_EXPORT QTextTableFormat : public QTextFrameFormat
863 {
864 public:
865     QTextTableFormat();
866
867     inline bool isValid() const { return isTableFormat(); }
868
869     inline int columns() const
870     { int cols = intProperty(TableColumns); if (cols == 0) cols = 1; return cols; }
871     inline void setColumns(int columns);
872
873     inline void setColumnWidthConstraints(const QVector<QTextLength> &constraints)
874     { setProperty(TableColumnWidthConstraints, constraints); }
875
876     inline QVector<QTextLength> columnWidthConstraints() const
877     { return lengthVectorProperty(TableColumnWidthConstraints); }
878
879     inline void clearColumnWidthConstraints()
880     { clearProperty(TableColumnWidthConstraints); }
881
882     inline qreal cellSpacing() const
883     { return doubleProperty(TableCellSpacing); }
884     inline void setCellSpacing(qreal spacing)
885     { setProperty(TableCellSpacing, spacing); }
886
887     inline qreal cellPadding() const
888     { return doubleProperty(TableCellPadding); }
889     inline void setCellPadding(qreal padding);
890
891     inline void setAlignment(Qt::Alignment alignment);
892     inline Qt::Alignment alignment() const
893     { return QFlag(intProperty(BlockAlignment)); }
894
895     inline void setHeaderRowCount(int count)
896     { setProperty(TableHeaderRowCount, count); }
897     inline int headerRowCount() const
898     { return intProperty(TableHeaderRowCount); }
899
900 protected:
901     explicit QTextTableFormat(const QTextFormat &fmt);
902     friend class QTextFormat;
903 };
904
905 inline void QTextTableFormat::setColumns(int acolumns)
906 {
907     if (acolumns == 1)
908         acolumns = 0;
909     setProperty(TableColumns, acolumns);
910 }
911
912 inline void QTextTableFormat::setCellPadding(qreal apadding)
913 { setProperty(TableCellPadding, apadding); }
914
915 inline void QTextTableFormat::setAlignment(Qt::Alignment aalignment)
916 { setProperty(BlockAlignment, int(aalignment)); }
917
918 class Q_GUI_EXPORT QTextTableCellFormat : public QTextCharFormat
919 {
920 public:
921     QTextTableCellFormat();
922
923     inline bool isValid() const { return isTableCellFormat(); }
924
925     inline void setTopPadding(qreal padding);
926     inline qreal topPadding() const;
927
928     inline void setBottomPadding(qreal padding);
929     inline qreal bottomPadding() const;
930
931     inline void setLeftPadding(qreal padding);
932     inline qreal leftPadding() const;
933
934     inline void setRightPadding(qreal padding);
935     inline qreal rightPadding() const;
936
937     inline void setPadding(qreal padding);
938
939 protected:
940     explicit QTextTableCellFormat(const QTextFormat &fmt);
941     friend class QTextFormat;
942 };
943
944 inline void QTextTableCellFormat::setTopPadding(qreal padding)
945 {
946     setProperty(TableCellTopPadding, padding);
947 }
948
949 inline qreal QTextTableCellFormat::topPadding() const
950 {
951     return doubleProperty(TableCellTopPadding);
952 }
953
954 inline void QTextTableCellFormat::setBottomPadding(qreal padding)
955 {
956     setProperty(TableCellBottomPadding, padding);
957 }
958
959 inline qreal QTextTableCellFormat::bottomPadding() const
960 {
961     return doubleProperty(TableCellBottomPadding);
962 }
963
964 inline void QTextTableCellFormat::setLeftPadding(qreal padding)
965 {
966     setProperty(TableCellLeftPadding, padding);
967 }
968
969 inline qreal QTextTableCellFormat::leftPadding() const
970 {
971     return doubleProperty(TableCellLeftPadding);
972 }
973
974 inline void QTextTableCellFormat::setRightPadding(qreal padding)
975 {
976     setProperty(TableCellRightPadding, padding);
977 }
978
979 inline qreal QTextTableCellFormat::rightPadding() const
980 {
981     return doubleProperty(TableCellRightPadding);
982 }
983
984 inline void QTextTableCellFormat::setPadding(qreal padding)
985 {
986     setTopPadding(padding);
987     setBottomPadding(padding);
988     setLeftPadding(padding);
989     setRightPadding(padding);
990 }
991
992
993 QT_END_NAMESPACE
994
995 QT_END_HEADER
996
997 #endif // QTEXTFORMAT_H