QtGui/qtextformat.h Source File

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