source: trunk/src/gui/text/qtextformat.h@ 371

Last change on this file since 371 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

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