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