File indexing completed on 2025-01-18 10:08:17
0001
0002
0003
0004 #ifndef QTEXTFORMAT_H
0005 #define QTEXTFORMAT_H
0006
0007 #include <QtGui/qbrush.h>
0008 #include <QtGui/qcolor.h>
0009 #include <QtGui/qfont.h>
0010 #include <QtGui/qpen.h>
0011 #include <QtGui/qtextoption.h>
0012 #include <QtGui/qtguiglobal.h>
0013
0014 #include <QtCore/qlist.h>
0015 #include <QtCore/qshareddata.h>
0016 #include <QtCore/qvariant.h>
0017
0018 QT_BEGIN_NAMESPACE
0019
0020
0021 class QString;
0022 class QVariant;
0023 class QFont;
0024
0025 class QTextFormatCollection;
0026 class QTextFormatPrivate;
0027 class QTextBlockFormat;
0028 class QTextCharFormat;
0029 class QTextListFormat;
0030 class QTextTableFormat;
0031 class QTextFrameFormat;
0032 class QTextImageFormat;
0033 class QTextTableCellFormat;
0034 class QTextFormat;
0035 class QTextObject;
0036 class QTextCursor;
0037 class QTextDocument;
0038 class QTextLength;
0039
0040 #ifndef QT_NO_DEBUG_STREAM
0041 Q_GUI_EXPORT QDebug operator<<(QDebug, const QTextLength &);
0042 #endif
0043
0044 class Q_GUI_EXPORT QTextLength
0045 {
0046 public:
0047 enum Type { VariableLength = 0, FixedLength, PercentageLength };
0048
0049 inline QTextLength() : lengthType(VariableLength), fixedValueOrPercentage(0) {}
0050
0051 inline explicit QTextLength(Type type, qreal value);
0052
0053 inline Type type() const { return lengthType; }
0054 inline qreal value(qreal maximumLength) const
0055 {
0056 switch (lengthType) {
0057 case FixedLength: return fixedValueOrPercentage;
0058 case VariableLength: return maximumLength;
0059 case PercentageLength: return fixedValueOrPercentage * maximumLength / qreal(100);
0060 }
0061 return -1;
0062 }
0063
0064 inline qreal rawValue() const { return fixedValueOrPercentage; }
0065
0066 inline bool operator==(const QTextLength &other) const
0067 { return lengthType == other.lengthType
0068 && qFuzzyCompare(fixedValueOrPercentage, other.fixedValueOrPercentage); }
0069 inline bool operator!=(const QTextLength &other) const
0070 { return lengthType != other.lengthType
0071 || !qFuzzyCompare(fixedValueOrPercentage, other.fixedValueOrPercentage); }
0072 operator QVariant() const;
0073
0074 private:
0075 Type lengthType;
0076 qreal fixedValueOrPercentage;
0077 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextLength &);
0078 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextLength &);
0079 };
0080 Q_DECLARE_TYPEINFO(QTextLength, Q_PRIMITIVE_TYPE);
0081
0082 inline QTextLength::QTextLength(Type atype, qreal avalue)
0083 : lengthType(atype), fixedValueOrPercentage(avalue) {}
0084
0085 #ifndef QT_NO_DEBUG_STREAM
0086 Q_GUI_EXPORT QDebug operator<<(QDebug, const QTextFormat &);
0087 #endif
0088
0089 class Q_GUI_EXPORT QTextFormat
0090 {
0091 Q_GADGET
0092 public:
0093 enum FormatType {
0094 InvalidFormat = -1,
0095 BlockFormat = 1,
0096 CharFormat = 2,
0097 ListFormat = 3,
0098 FrameFormat = 5,
0099
0100 UserFormat = 100
0101 };
0102 Q_ENUM(FormatType)
0103
0104 enum Property {
0105 ObjectIndex = 0x0,
0106
0107
0108 CssFloat = 0x0800,
0109 LayoutDirection = 0x0801,
0110
0111 OutlinePen = 0x810,
0112 BackgroundBrush = 0x820,
0113 ForegroundBrush = 0x821,
0114
0115 BackgroundImageUrl = 0x823,
0116
0117
0118 BlockAlignment = 0x1010,
0119 BlockTopMargin = 0x1030,
0120 BlockBottomMargin = 0x1031,
0121 BlockLeftMargin = 0x1032,
0122 BlockRightMargin = 0x1033,
0123 TextIndent = 0x1034,
0124 TabPositions = 0x1035,
0125 BlockIndent = 0x1040,
0126 LineHeight = 0x1048,
0127 LineHeightType = 0x1049,
0128 BlockNonBreakableLines = 0x1050,
0129 BlockTrailingHorizontalRulerWidth = 0x1060,
0130 HeadingLevel = 0x1070,
0131 BlockQuoteLevel = 0x1080,
0132 BlockCodeLanguage = 0x1090,
0133 BlockCodeFence = 0x1091,
0134 BlockMarker = 0x10A0,
0135
0136
0137 FirstFontProperty = 0x1FE0,
0138 FontCapitalization = FirstFontProperty,
0139 FontLetterSpacing = 0x1FE1,
0140 FontWordSpacing = 0x1FE2,
0141 FontStyleHint = 0x1FE3,
0142 FontStyleStrategy = 0x1FE4,
0143 FontKerning = 0x1FE5,
0144 FontHintingPreference = 0x1FE6,
0145 FontFamilies = 0x1FE7,
0146 FontStyleName = 0x1FE8,
0147 FontLetterSpacingType = 0x1FE9,
0148 FontStretch = 0x1FEA,
0149 #if QT_DEPRECATED_SINCE(6, 0)
0150 FontFamily = 0x2000,
0151 #endif
0152 FontPointSize = 0x2001,
0153 FontSizeAdjustment = 0x2002,
0154 FontSizeIncrement = FontSizeAdjustment,
0155 FontWeight = 0x2003,
0156 FontItalic = 0x2004,
0157 FontUnderline = 0x2005,
0158 FontOverline = 0x2006,
0159 FontStrikeOut = 0x2007,
0160 FontFixedPitch = 0x2008,
0161 FontPixelSize = 0x2009,
0162 LastFontProperty = FontPixelSize,
0163
0164 TextUnderlineColor = 0x2020,
0165 TextVerticalAlignment = 0x2021,
0166 TextOutline = 0x2022,
0167 TextUnderlineStyle = 0x2023,
0168 TextToolTip = 0x2024,
0169 TextSuperScriptBaseline = 0x2025,
0170 TextSubScriptBaseline = 0x2026,
0171 TextBaselineOffset = 0x2027,
0172
0173 IsAnchor = 0x2030,
0174 AnchorHref = 0x2031,
0175 AnchorName = 0x2032,
0176
0177
0178
0179 OldFontLetterSpacingType = 0x2033,
0180 OldFontStretch = 0x2034,
0181 OldTextUnderlineColor = 0x2010,
0182 OldFontFamily = 0x2000,
0183
0184 ObjectType = 0x2f00,
0185
0186
0187 ListStyle = 0x3000,
0188 ListIndent = 0x3001,
0189 ListNumberPrefix = 0x3002,
0190 ListNumberSuffix = 0x3003,
0191 ListStart = 0x3004,
0192
0193
0194 FrameBorder = 0x4000,
0195 FrameMargin = 0x4001,
0196 FramePadding = 0x4002,
0197 FrameWidth = 0x4003,
0198 FrameHeight = 0x4004,
0199 FrameTopMargin = 0x4005,
0200 FrameBottomMargin = 0x4006,
0201 FrameLeftMargin = 0x4007,
0202 FrameRightMargin = 0x4008,
0203 FrameBorderBrush = 0x4009,
0204 FrameBorderStyle = 0x4010,
0205
0206 TableColumns = 0x4100,
0207 TableColumnWidthConstraints = 0x4101,
0208 TableCellSpacing = 0x4102,
0209 TableCellPadding = 0x4103,
0210 TableHeaderRowCount = 0x4104,
0211 TableBorderCollapse = 0x4105,
0212
0213
0214 TableCellRowSpan = 0x4810,
0215 TableCellColumnSpan = 0x4811,
0216
0217 TableCellTopPadding = 0x4812,
0218 TableCellBottomPadding = 0x4813,
0219 TableCellLeftPadding = 0x4814,
0220 TableCellRightPadding = 0x4815,
0221
0222 TableCellTopBorder = 0x4816,
0223 TableCellBottomBorder = 0x4817,
0224 TableCellLeftBorder = 0x4818,
0225 TableCellRightBorder = 0x4819,
0226
0227 TableCellTopBorderStyle = 0x481a,
0228 TableCellBottomBorderStyle = 0x481b,
0229 TableCellLeftBorderStyle = 0x481c,
0230 TableCellRightBorderStyle = 0x481d,
0231
0232 TableCellTopBorderBrush = 0x481e,
0233 TableCellBottomBorderBrush = 0x481f,
0234 TableCellLeftBorderBrush = 0x4820,
0235 TableCellRightBorderBrush = 0x4821,
0236
0237
0238 ImageName = 0x5000,
0239 ImageTitle = 0x5001,
0240 ImageAltText = 0x5002,
0241 ImageWidth = 0x5010,
0242 ImageHeight = 0x5011,
0243 ImageQuality = 0x5014,
0244
0245
0246
0247
0248
0249
0250
0251
0252 FullWidthSelection = 0x06000,
0253
0254
0255 PageBreakPolicy = 0x7000,
0256
0257
0258 UserProperty = 0x100000
0259 };
0260 Q_ENUM(Property)
0261
0262 enum ObjectTypes {
0263 NoObject,
0264 ImageObject,
0265 TableObject,
0266 TableCellObject,
0267
0268 UserObject = 0x1000
0269 };
0270 Q_ENUM(ObjectTypes)
0271
0272 enum PageBreakFlag {
0273 PageBreak_Auto = 0,
0274 PageBreak_AlwaysBefore = 0x001,
0275 PageBreak_AlwaysAfter = 0x010
0276
0277 };
0278 Q_DECLARE_FLAGS(PageBreakFlags, PageBreakFlag)
0279
0280 QTextFormat();
0281
0282 explicit QTextFormat(int type);
0283
0284 QTextFormat(const QTextFormat &rhs);
0285 QTextFormat &operator=(const QTextFormat &rhs);
0286 ~QTextFormat();
0287
0288 void swap(QTextFormat &other)
0289 { d.swap(other.d); std::swap(format_type, other.format_type); }
0290
0291 void merge(const QTextFormat &other);
0292
0293 inline bool isValid() const { return type() != InvalidFormat; }
0294 inline bool isEmpty() const { return propertyCount() == 0; }
0295
0296 int type() const;
0297
0298 int objectIndex() const;
0299 void setObjectIndex(int object);
0300
0301 QVariant property(int propertyId) const;
0302 void setProperty(int propertyId, const QVariant &value);
0303 void clearProperty(int propertyId);
0304 bool hasProperty(int propertyId) const;
0305
0306 bool boolProperty(int propertyId) const;
0307 int intProperty(int propertyId) const;
0308 qreal doubleProperty(int propertyId) const;
0309 QString stringProperty(int propertyId) const;
0310 QColor colorProperty(int propertyId) const;
0311 QPen penProperty(int propertyId) const;
0312 QBrush brushProperty(int propertyId) const;
0313 QTextLength lengthProperty(int propertyId) const;
0314 QList<QTextLength> lengthVectorProperty(int propertyId) const;
0315
0316 void setProperty(int propertyId, const QList<QTextLength> &lengths);
0317
0318 QMap<int, QVariant> properties() const;
0319 int propertyCount() const;
0320
0321 inline void setObjectType(int type);
0322 inline int objectType() const
0323 { return intProperty(ObjectType); }
0324
0325 inline bool isCharFormat() const { return type() == CharFormat; }
0326 inline bool isBlockFormat() const { return type() == BlockFormat; }
0327 inline bool isListFormat() const { return type() == ListFormat; }
0328 inline bool isFrameFormat() const { return type() == FrameFormat; }
0329 inline bool isImageFormat() const { return type() == CharFormat && objectType() == ImageObject; }
0330 inline bool isTableFormat() const { return type() == FrameFormat && objectType() == TableObject; }
0331 inline bool isTableCellFormat() const { return type() == CharFormat && objectType() == TableCellObject; }
0332
0333 QTextBlockFormat toBlockFormat() const;
0334 QTextCharFormat toCharFormat() const;
0335 QTextListFormat toListFormat() const;
0336 QTextTableFormat toTableFormat() const;
0337 QTextFrameFormat toFrameFormat() const;
0338 QTextImageFormat toImageFormat() const;
0339 QTextTableCellFormat toTableCellFormat() const;
0340
0341 bool operator==(const QTextFormat &rhs) const;
0342 inline bool operator!=(const QTextFormat &rhs) const { return !operator==(rhs); }
0343 operator QVariant() const;
0344
0345 inline void setLayoutDirection(Qt::LayoutDirection direction)
0346 { setProperty(QTextFormat::LayoutDirection, direction); }
0347 inline Qt::LayoutDirection layoutDirection() const
0348 { return Qt::LayoutDirection(intProperty(QTextFormat::LayoutDirection)); }
0349
0350 inline void setBackground(const QBrush &brush)
0351 { setProperty(BackgroundBrush, brush); }
0352 inline QBrush background() const
0353 { return brushProperty(BackgroundBrush); }
0354 inline void clearBackground()
0355 { clearProperty(BackgroundBrush); }
0356
0357 inline void setForeground(const QBrush &brush)
0358 { setProperty(ForegroundBrush, brush); }
0359 inline QBrush foreground() const
0360 { return brushProperty(ForegroundBrush); }
0361 inline void clearForeground()
0362 { clearProperty(ForegroundBrush); }
0363
0364 private:
0365 QSharedDataPointer<QTextFormatPrivate> d;
0366 qint32 format_type;
0367
0368 friend class QTextFormatCollection;
0369 friend class QTextCharFormat;
0370 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextFormat &);
0371 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextFormat &);
0372 };
0373
0374 Q_DECLARE_SHARED(QTextFormat)
0375
0376 inline void QTextFormat::setObjectType(int atype)
0377 { setProperty(ObjectType, atype); }
0378
0379 Q_DECLARE_OPERATORS_FOR_FLAGS(QTextFormat::PageBreakFlags)
0380
0381 class Q_GUI_EXPORT QTextCharFormat : public QTextFormat
0382 {
0383 public:
0384 enum VerticalAlignment {
0385 AlignNormal = 0,
0386 AlignSuperScript,
0387 AlignSubScript,
0388 AlignMiddle,
0389 AlignTop,
0390 AlignBottom,
0391 AlignBaseline
0392 };
0393 enum UnderlineStyle {
0394 NoUnderline,
0395 SingleUnderline,
0396 DashUnderline,
0397 DotLine,
0398 DashDotLine,
0399 DashDotDotLine,
0400 WaveUnderline,
0401 SpellCheckUnderline
0402 };
0403
0404 QTextCharFormat();
0405
0406 bool isValid() const { return isCharFormat(); }
0407
0408 enum FontPropertiesInheritanceBehavior {
0409 FontPropertiesSpecifiedOnly,
0410 FontPropertiesAll
0411 };
0412 void setFont(const QFont &font, FontPropertiesInheritanceBehavior behavior = FontPropertiesAll);
0413 QFont font() const;
0414
0415 #if QT_DEPRECATED_SINCE(6, 1)
0416 QT_DEPRECATED_VERSION_X_6_1("Use setFontFamilies instead") inline void setFontFamily(const QString &family)
0417 { setProperty(FontFamilies, QVariant(QStringList(family))); }
0418 QT_DEPRECATED_VERSION_X_6_1("Use fontFamilies instead") inline QString fontFamily() const
0419 { return property(FontFamilies).toStringList().first(); }
0420 #endif
0421
0422 inline void setFontFamilies(const QStringList &families)
0423 { setProperty(FontFamilies, QVariant(families)); }
0424 #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
0425 inline QVariant fontFamilies() const
0426 { return property(FontFamilies); }
0427 #else
0428 inline QStringList fontFamilies() const
0429 { return property(FontFamilies).toStringList(); }
0430 #endif
0431
0432 inline void setFontStyleName(const QString &styleName)
0433 { setProperty(FontStyleName, styleName); }
0434 #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
0435 inline QVariant fontStyleName() const
0436 { return property(FontStyleName); }
0437 #else
0438 inline QStringList fontStyleName() const
0439 { return property(FontStyleName).toStringList(); }
0440 #endif
0441
0442 inline void setFontPointSize(qreal size)
0443 { setProperty(FontPointSize, size); }
0444 inline qreal fontPointSize() const
0445 { return doubleProperty(FontPointSize); }
0446
0447 inline void setFontWeight(int weight)
0448 { setProperty(FontWeight, weight); }
0449 inline int fontWeight() const
0450 { return hasProperty(FontWeight) ? intProperty(FontWeight) : QFont::Normal; }
0451 inline void setFontItalic(bool italic)
0452 { setProperty(FontItalic, italic); }
0453 inline bool fontItalic() const
0454 { return boolProperty(FontItalic); }
0455 inline void setFontCapitalization(QFont::Capitalization capitalization)
0456 { setProperty(FontCapitalization, capitalization); }
0457 inline QFont::Capitalization fontCapitalization() const
0458 { return static_cast<QFont::Capitalization>(intProperty(FontCapitalization)); }
0459 inline void setFontLetterSpacingType(QFont::SpacingType letterSpacingType)
0460 { setProperty(FontLetterSpacingType, letterSpacingType); }
0461 inline QFont::SpacingType fontLetterSpacingType() const
0462 { return static_cast<QFont::SpacingType>(intProperty(FontLetterSpacingType)); }
0463 inline void setFontLetterSpacing(qreal spacing)
0464 { setProperty(FontLetterSpacing, spacing); }
0465 inline qreal fontLetterSpacing() const
0466 { return doubleProperty(FontLetterSpacing); }
0467 inline void setFontWordSpacing(qreal spacing)
0468 { setProperty(FontWordSpacing, spacing); }
0469 inline qreal fontWordSpacing() const
0470 { return doubleProperty(FontWordSpacing); }
0471
0472 inline void setFontUnderline(bool underline)
0473 { setProperty(TextUnderlineStyle, underline ? SingleUnderline : NoUnderline); }
0474 bool fontUnderline() const;
0475
0476 inline void setFontOverline(bool overline)
0477 { setProperty(FontOverline, overline); }
0478 inline bool fontOverline() const
0479 { return boolProperty(FontOverline); }
0480
0481 inline void setFontStrikeOut(bool strikeOut)
0482 { setProperty(FontStrikeOut, strikeOut); }
0483 inline bool fontStrikeOut() const
0484 { return boolProperty(FontStrikeOut); }
0485
0486 inline void setUnderlineColor(const QColor &color)
0487 { setProperty(TextUnderlineColor, color); }
0488 inline QColor underlineColor() const
0489 { return colorProperty(TextUnderlineColor); }
0490
0491 inline void setFontFixedPitch(bool fixedPitch)
0492 { setProperty(FontFixedPitch, fixedPitch); }
0493 inline bool fontFixedPitch() const
0494 { return boolProperty(FontFixedPitch); }
0495
0496 inline void setFontStretch(int factor)
0497 { setProperty(FontStretch, factor); }
0498 inline int fontStretch() const
0499 { return intProperty(FontStretch); }
0500
0501 inline void setFontStyleHint(QFont::StyleHint hint, QFont::StyleStrategy strategy = QFont::PreferDefault)
0502 { setProperty(FontStyleHint, hint); setProperty(FontStyleStrategy, strategy); }
0503 inline void setFontStyleStrategy(QFont::StyleStrategy strategy)
0504 { setProperty(FontStyleStrategy, strategy); }
0505 QFont::StyleHint fontStyleHint() const
0506 { return static_cast<QFont::StyleHint>(intProperty(FontStyleHint)); }
0507 QFont::StyleStrategy fontStyleStrategy() const
0508 { return static_cast<QFont::StyleStrategy>(intProperty(FontStyleStrategy)); }
0509
0510 inline void setFontHintingPreference(QFont::HintingPreference hintingPreference)
0511 {
0512 setProperty(FontHintingPreference, hintingPreference);
0513 }
0514
0515 inline QFont::HintingPreference fontHintingPreference() const
0516 {
0517 return static_cast<QFont::HintingPreference>(intProperty(FontHintingPreference));
0518 }
0519
0520 inline void setFontKerning(bool enable)
0521 { setProperty(FontKerning, enable); }
0522 inline bool fontKerning() const
0523 { return boolProperty(FontKerning); }
0524
0525 void setUnderlineStyle(UnderlineStyle style);
0526 inline UnderlineStyle underlineStyle() const
0527 { return static_cast<UnderlineStyle>(intProperty(TextUnderlineStyle)); }
0528
0529 inline void setVerticalAlignment(VerticalAlignment alignment)
0530 { setProperty(TextVerticalAlignment, alignment); }
0531 inline VerticalAlignment verticalAlignment() const
0532 { return static_cast<VerticalAlignment>(intProperty(TextVerticalAlignment)); }
0533
0534 inline void setTextOutline(const QPen &pen)
0535 { setProperty(TextOutline, pen); }
0536 inline QPen textOutline() const
0537 { return penProperty(TextOutline); }
0538
0539 inline void setToolTip(const QString &tip)
0540 { setProperty(TextToolTip, tip); }
0541 inline QString toolTip() const
0542 { return stringProperty(TextToolTip); }
0543
0544 inline void setSuperScriptBaseline(qreal baseline)
0545 { setProperty(TextSuperScriptBaseline, baseline); }
0546 inline qreal superScriptBaseline() const
0547 { return hasProperty(TextSuperScriptBaseline) ? doubleProperty(TextSuperScriptBaseline) : 50.0; }
0548
0549 inline void setSubScriptBaseline(qreal baseline)
0550 { setProperty(TextSubScriptBaseline, baseline); }
0551 inline qreal subScriptBaseline() const
0552 { return hasProperty(TextSubScriptBaseline) ? doubleProperty(TextSubScriptBaseline) : 100.0 / 6.0; }
0553
0554 inline void setBaselineOffset(qreal baseline)
0555 { setProperty(TextBaselineOffset, baseline); }
0556 inline qreal baselineOffset() const
0557 { return hasProperty(TextBaselineOffset) ? doubleProperty(TextBaselineOffset) : 0.0; }
0558
0559 inline void setAnchor(bool anchor)
0560 { setProperty(IsAnchor, anchor); }
0561 inline bool isAnchor() const
0562 { return boolProperty(IsAnchor); }
0563
0564 inline void setAnchorHref(const QString &value)
0565 { setProperty(AnchorHref, value); }
0566 inline QString anchorHref() const
0567 { return stringProperty(AnchorHref); }
0568
0569 inline void setAnchorNames(const QStringList &names)
0570 { setProperty(AnchorName, names); }
0571 QStringList anchorNames() const;
0572
0573 inline void setTableCellRowSpan(int tableCellRowSpan);
0574 inline int tableCellRowSpan() const
0575 { int s = intProperty(TableCellRowSpan); if (s == 0) s = 1; return s; }
0576 inline void setTableCellColumnSpan(int tableCellColumnSpan);
0577 inline int tableCellColumnSpan() const
0578 { int s = intProperty(TableCellColumnSpan); if (s == 0) s = 1; return s; }
0579
0580 protected:
0581 explicit QTextCharFormat(const QTextFormat &fmt);
0582 friend class QTextFormat;
0583 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextCharFormat &);
0584 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextCharFormat &);
0585 };
0586
0587 Q_DECLARE_SHARED(QTextCharFormat)
0588
0589 inline void QTextCharFormat::setTableCellRowSpan(int _tableCellRowSpan)
0590 {
0591 if (_tableCellRowSpan <= 1)
0592 clearProperty(TableCellRowSpan);
0593 else
0594 setProperty(TableCellRowSpan, _tableCellRowSpan);
0595 }
0596
0597 inline void QTextCharFormat::setTableCellColumnSpan(int _tableCellColumnSpan)
0598 {
0599 if (_tableCellColumnSpan <= 1)
0600 clearProperty(TableCellColumnSpan);
0601 else
0602 setProperty(TableCellColumnSpan, _tableCellColumnSpan);
0603 }
0604
0605 class Q_GUI_EXPORT QTextBlockFormat : public QTextFormat
0606 {
0607 public:
0608 enum LineHeightTypes {
0609 SingleHeight = 0,
0610 ProportionalHeight = 1,
0611 FixedHeight = 2,
0612 MinimumHeight = 3,
0613 LineDistanceHeight = 4
0614 };
0615
0616 enum class MarkerType {
0617 NoMarker = 0,
0618 Unchecked = 1,
0619 Checked = 2
0620 };
0621
0622 QTextBlockFormat();
0623
0624 bool isValid() const { return isBlockFormat(); }
0625
0626 inline void setAlignment(Qt::Alignment alignment);
0627 inline Qt::Alignment alignment() const
0628 { int a = intProperty(BlockAlignment); if (a == 0) a = Qt::AlignLeft; return QFlag(a); }
0629
0630 inline void setTopMargin(qreal margin)
0631 { setProperty(BlockTopMargin, margin); }
0632 inline qreal topMargin() const
0633 { return doubleProperty(BlockTopMargin); }
0634
0635 inline void setBottomMargin(qreal margin)
0636 { setProperty(BlockBottomMargin, margin); }
0637 inline qreal bottomMargin() const
0638 { return doubleProperty(BlockBottomMargin); }
0639
0640 inline void setLeftMargin(qreal margin)
0641 { setProperty(BlockLeftMargin, margin); }
0642 inline qreal leftMargin() const
0643 { return doubleProperty(BlockLeftMargin); }
0644
0645 inline void setRightMargin(qreal margin)
0646 { setProperty(BlockRightMargin, margin); }
0647 inline qreal rightMargin() const
0648 { return doubleProperty(BlockRightMargin); }
0649
0650 inline void setTextIndent(qreal aindent)
0651 { setProperty(TextIndent, aindent); }
0652 inline qreal textIndent() const
0653 { return doubleProperty(TextIndent); }
0654
0655 inline void setIndent(int indent);
0656 inline int indent() const
0657 { return intProperty(BlockIndent); }
0658
0659 inline void setHeadingLevel(int alevel)
0660 { setProperty(HeadingLevel, alevel); }
0661 inline int headingLevel() const
0662 { return intProperty(HeadingLevel); }
0663
0664 inline void setLineHeight(qreal height, int heightType)
0665 { setProperty(LineHeight, height); setProperty(LineHeightType, heightType); }
0666 inline qreal lineHeight(qreal scriptLineHeight, qreal scaling) const;
0667 inline qreal lineHeight() const
0668 { return doubleProperty(LineHeight); }
0669 inline int lineHeightType() const
0670 { return intProperty(LineHeightType); }
0671
0672 inline void setNonBreakableLines(bool b)
0673 { setProperty(BlockNonBreakableLines, b); }
0674 inline bool nonBreakableLines() const
0675 { return boolProperty(BlockNonBreakableLines); }
0676
0677 inline void setPageBreakPolicy(PageBreakFlags flags)
0678 { setProperty(PageBreakPolicy, int(flags.toInt())); }
0679 inline PageBreakFlags pageBreakPolicy() const
0680 { return PageBreakFlags(intProperty(PageBreakPolicy)); }
0681
0682 void setTabPositions(const QList<QTextOption::Tab> &tabs);
0683 QList<QTextOption::Tab> tabPositions() const;
0684
0685 inline void setMarker(MarkerType marker)
0686 { setProperty(BlockMarker, int(marker)); }
0687 inline MarkerType marker() const
0688 { return MarkerType(intProperty(BlockMarker)); }
0689
0690 protected:
0691 explicit QTextBlockFormat(const QTextFormat &fmt);
0692 friend class QTextFormat;
0693 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextBlockFormat &);
0694 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextBlockFormat &);
0695 };
0696
0697 Q_DECLARE_SHARED(QTextBlockFormat)
0698
0699 inline void QTextBlockFormat::setAlignment(Qt::Alignment aalignment)
0700 { setProperty(BlockAlignment, int(aalignment.toInt())); }
0701
0702 inline void QTextBlockFormat::setIndent(int aindent)
0703 { setProperty(BlockIndent, aindent); }
0704
0705 inline qreal QTextBlockFormat::lineHeight(qreal scriptLineHeight, qreal scaling = 1.0) const
0706 {
0707 switch(intProperty(LineHeightType)) {
0708 case SingleHeight:
0709 return(scriptLineHeight);
0710 case ProportionalHeight:
0711 return(scriptLineHeight * doubleProperty(LineHeight) / 100.0);
0712 case FixedHeight:
0713 return(doubleProperty(LineHeight) * scaling);
0714 case MinimumHeight:
0715 return(qMax(scriptLineHeight, doubleProperty(LineHeight) * scaling));
0716 case LineDistanceHeight:
0717 return(scriptLineHeight + doubleProperty(LineHeight) * scaling);
0718 }
0719 return(0);
0720 }
0721
0722 class Q_GUI_EXPORT QTextListFormat : public QTextFormat
0723 {
0724 public:
0725 QTextListFormat();
0726
0727 bool isValid() const { return isListFormat(); }
0728
0729 enum Style {
0730 ListDisc = -1,
0731 ListCircle = -2,
0732 ListSquare = -3,
0733 ListDecimal = -4,
0734 ListLowerAlpha = -5,
0735 ListUpperAlpha = -6,
0736 ListLowerRoman = -7,
0737 ListUpperRoman = -8,
0738 ListStyleUndefined = 0
0739 };
0740
0741 inline void setStyle(Style style);
0742 inline Style style() const
0743 { return static_cast<Style>(intProperty(ListStyle)); }
0744
0745 inline void setIndent(int indent);
0746 inline int indent() const
0747 { return intProperty(ListIndent); }
0748
0749 inline void setNumberPrefix(const QString &numberPrefix);
0750 inline QString numberPrefix() const
0751 { return stringProperty(ListNumberPrefix); }
0752
0753 inline void setNumberSuffix(const QString &numberSuffix);
0754 inline QString numberSuffix() const
0755 { return stringProperty(ListNumberSuffix); }
0756
0757 inline void setStart(int indent);
0758 inline int start() const { return intProperty(ListStart); }
0759
0760 protected:
0761 explicit QTextListFormat(const QTextFormat &fmt);
0762 friend class QTextFormat;
0763 };
0764
0765 Q_DECLARE_SHARED(QTextListFormat)
0766
0767 inline void QTextListFormat::setStyle(Style astyle)
0768 { setProperty(ListStyle, astyle); }
0769
0770 inline void QTextListFormat::setIndent(int aindent)
0771 { setProperty(ListIndent, aindent); }
0772
0773 inline void QTextListFormat::setNumberPrefix(const QString &np)
0774 { setProperty(ListNumberPrefix, np); }
0775
0776 inline void QTextListFormat::setNumberSuffix(const QString &ns)
0777 { setProperty(ListNumberSuffix, ns); }
0778
0779 inline void QTextListFormat::setStart(int astart)
0780 {
0781 setProperty(ListStart, astart);
0782 }
0783
0784 class Q_GUI_EXPORT QTextImageFormat : public QTextCharFormat
0785 {
0786 public:
0787 QTextImageFormat();
0788
0789 bool isValid() const { return isImageFormat(); }
0790
0791 inline void setName(const QString &name);
0792 inline QString name() const
0793 { return stringProperty(ImageName); }
0794
0795 inline void setWidth(qreal width);
0796 inline qreal width() const
0797 { return doubleProperty(ImageWidth); }
0798
0799 inline void setHeight(qreal height);
0800 inline qreal height() const
0801 { return doubleProperty(ImageHeight); }
0802
0803 inline void setQuality(int quality);
0804 #if QT_DEPRECATED_SINCE(6, 3)
0805 QT_DEPRECATED_VERSION_X_6_3("Pass a quality value, the default is 100") inline void setQuality()
0806 { setQuality(100); }
0807 #endif
0808 inline int quality() const
0809 { return intProperty(ImageQuality); }
0810
0811 protected:
0812 explicit QTextImageFormat(const QTextFormat &format);
0813 friend class QTextFormat;
0814 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextListFormat &);
0815 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextListFormat &);
0816 };
0817
0818 Q_DECLARE_SHARED(QTextImageFormat)
0819
0820 inline void QTextImageFormat::setName(const QString &aname)
0821 { setProperty(ImageName, aname); }
0822
0823 inline void QTextImageFormat::setWidth(qreal awidth)
0824 { setProperty(ImageWidth, awidth); }
0825
0826 inline void QTextImageFormat::setHeight(qreal aheight)
0827 { setProperty(ImageHeight, aheight); }
0828
0829 inline void QTextImageFormat::setQuality(int aquality)
0830 { setProperty(ImageQuality, aquality); }
0831
0832 class Q_GUI_EXPORT QTextFrameFormat : public QTextFormat
0833 {
0834 public:
0835 QTextFrameFormat();
0836
0837 bool isValid() const { return isFrameFormat(); }
0838
0839 enum Position {
0840 InFlow,
0841 FloatLeft,
0842 FloatRight
0843
0844
0845 };
0846
0847 enum BorderStyle {
0848 BorderStyle_None,
0849 BorderStyle_Dotted,
0850 BorderStyle_Dashed,
0851 BorderStyle_Solid,
0852 BorderStyle_Double,
0853 BorderStyle_DotDash,
0854 BorderStyle_DotDotDash,
0855 BorderStyle_Groove,
0856 BorderStyle_Ridge,
0857 BorderStyle_Inset,
0858 BorderStyle_Outset
0859 };
0860
0861 inline void setPosition(Position f)
0862 { setProperty(CssFloat, f); }
0863 inline Position position() const
0864 { return static_cast<Position>(intProperty(CssFloat)); }
0865
0866 inline void setBorder(qreal border);
0867 inline qreal border() const
0868 { return doubleProperty(FrameBorder); }
0869
0870 inline void setBorderBrush(const QBrush &brush)
0871 { setProperty(FrameBorderBrush, brush); }
0872 inline QBrush borderBrush() const
0873 { return brushProperty(FrameBorderBrush); }
0874
0875 inline void setBorderStyle(BorderStyle style)
0876 { setProperty(FrameBorderStyle, style); }
0877 inline BorderStyle borderStyle() const
0878 { return static_cast<BorderStyle>(intProperty(FrameBorderStyle)); }
0879
0880 void setMargin(qreal margin);
0881 inline qreal margin() const
0882 { return doubleProperty(FrameMargin); }
0883
0884 inline void setTopMargin(qreal margin);
0885 qreal topMargin() const;
0886
0887 inline void setBottomMargin(qreal margin);
0888 qreal bottomMargin() const;
0889
0890 inline void setLeftMargin(qreal margin);
0891 qreal leftMargin() const;
0892
0893 inline void setRightMargin(qreal margin);
0894 qreal rightMargin() const;
0895
0896 inline void setPadding(qreal padding);
0897 inline qreal padding() const
0898 { return doubleProperty(FramePadding); }
0899
0900 inline void setWidth(qreal width);
0901 inline void setWidth(const QTextLength &length)
0902 { setProperty(FrameWidth, length); }
0903 inline QTextLength width() const
0904 { return lengthProperty(FrameWidth); }
0905
0906 inline void setHeight(qreal height);
0907 inline void setHeight(const QTextLength &height);
0908 inline QTextLength height() const
0909 { return lengthProperty(FrameHeight); }
0910
0911 inline void setPageBreakPolicy(PageBreakFlags flags)
0912 { setProperty(PageBreakPolicy, int(flags.toInt())); }
0913 inline PageBreakFlags pageBreakPolicy() const
0914 { return PageBreakFlags(intProperty(PageBreakPolicy)); }
0915
0916 protected:
0917 explicit QTextFrameFormat(const QTextFormat &fmt);
0918 friend class QTextFormat;
0919 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextFrameFormat &);
0920 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextFrameFormat &);
0921 };
0922
0923 Q_DECLARE_SHARED(QTextFrameFormat)
0924
0925 inline void QTextFrameFormat::setBorder(qreal aborder)
0926 { setProperty(FrameBorder, aborder); }
0927
0928 inline void QTextFrameFormat::setPadding(qreal apadding)
0929 { setProperty(FramePadding, apadding); }
0930
0931 inline void QTextFrameFormat::setWidth(qreal awidth)
0932 { setProperty(FrameWidth, QTextLength(QTextLength::FixedLength, awidth)); }
0933
0934 inline void QTextFrameFormat::setHeight(qreal aheight)
0935 { setProperty(FrameHeight, QTextLength(QTextLength::FixedLength, aheight)); }
0936 inline void QTextFrameFormat::setHeight(const QTextLength &aheight)
0937 { setProperty(FrameHeight, aheight); }
0938
0939 inline void QTextFrameFormat::setTopMargin(qreal amargin)
0940 { setProperty(FrameTopMargin, amargin); }
0941
0942 inline void QTextFrameFormat::setBottomMargin(qreal amargin)
0943 { setProperty(FrameBottomMargin, amargin); }
0944
0945 inline void QTextFrameFormat::setLeftMargin(qreal amargin)
0946 { setProperty(FrameLeftMargin, amargin); }
0947
0948 inline void QTextFrameFormat::setRightMargin(qreal amargin)
0949 { setProperty(FrameRightMargin, amargin); }
0950
0951 class Q_GUI_EXPORT QTextTableFormat : public QTextFrameFormat
0952 {
0953 public:
0954 QTextTableFormat();
0955
0956 inline bool isValid() const { return isTableFormat(); }
0957
0958 inline int columns() const
0959 { int cols = intProperty(TableColumns); if (cols == 0) cols = 1; return cols; }
0960 inline void setColumns(int columns);
0961
0962 inline void setColumnWidthConstraints(const QList<QTextLength> &constraints)
0963 { setProperty(TableColumnWidthConstraints, constraints); }
0964
0965 inline QList<QTextLength> columnWidthConstraints() const
0966 { return lengthVectorProperty(TableColumnWidthConstraints); }
0967
0968 inline void clearColumnWidthConstraints()
0969 { clearProperty(TableColumnWidthConstraints); }
0970
0971 inline qreal cellSpacing() const
0972 { return doubleProperty(TableCellSpacing); }
0973 inline void setCellSpacing(qreal spacing)
0974 { setProperty(TableCellSpacing, spacing); }
0975
0976 inline qreal cellPadding() const
0977 { return doubleProperty(TableCellPadding); }
0978 inline void setCellPadding(qreal padding);
0979
0980 inline void setAlignment(Qt::Alignment alignment);
0981 inline Qt::Alignment alignment() const
0982 { return QFlag(intProperty(BlockAlignment)); }
0983
0984 inline void setHeaderRowCount(int count)
0985 { setProperty(TableHeaderRowCount, count); }
0986 inline int headerRowCount() const
0987 { return intProperty(TableHeaderRowCount); }
0988
0989 inline void setBorderCollapse(bool borderCollapse)
0990 { setProperty(TableBorderCollapse, borderCollapse); }
0991 inline bool borderCollapse() const
0992 { return boolProperty(TableBorderCollapse); }
0993
0994 protected:
0995 explicit QTextTableFormat(const QTextFormat &fmt);
0996 friend class QTextFormat;
0997 };
0998
0999 Q_DECLARE_SHARED(QTextTableFormat)
1000
1001 inline void QTextTableFormat::setColumns(int acolumns)
1002 {
1003 if (acolumns == 1)
1004 acolumns = 0;
1005 setProperty(TableColumns, acolumns);
1006 }
1007
1008 inline void QTextTableFormat::setCellPadding(qreal apadding)
1009 { setProperty(TableCellPadding, apadding); }
1010
1011 inline void QTextTableFormat::setAlignment(Qt::Alignment aalignment)
1012 { setProperty(BlockAlignment, int(aalignment.toInt())); }
1013
1014 class Q_GUI_EXPORT QTextTableCellFormat : public QTextCharFormat
1015 {
1016 public:
1017 QTextTableCellFormat();
1018
1019 inline bool isValid() const { return isTableCellFormat(); }
1020
1021 inline void setTopPadding(qreal padding);
1022 inline qreal topPadding() const;
1023
1024 inline void setBottomPadding(qreal padding);
1025 inline qreal bottomPadding() const;
1026
1027 inline void setLeftPadding(qreal padding);
1028 inline qreal leftPadding() const;
1029
1030 inline void setRightPadding(qreal padding);
1031 inline qreal rightPadding() const;
1032
1033 inline void setPadding(qreal padding);
1034
1035 inline void setTopBorder(qreal width)
1036 { setProperty(TableCellTopBorder, width); }
1037 inline qreal topBorder() const
1038 { return doubleProperty(TableCellTopBorder); }
1039
1040 inline void setBottomBorder(qreal width)
1041 { setProperty(TableCellBottomBorder, width); }
1042 inline qreal bottomBorder() const
1043 { return doubleProperty(TableCellBottomBorder); }
1044
1045 inline void setLeftBorder(qreal width)
1046 { setProperty(TableCellLeftBorder, width); }
1047 inline qreal leftBorder() const
1048 { return doubleProperty(TableCellLeftBorder); }
1049
1050 inline void setRightBorder(qreal width)
1051 { setProperty(TableCellRightBorder, width); }
1052 inline qreal rightBorder() const
1053 { return doubleProperty(TableCellRightBorder); }
1054
1055 inline void setBorder(qreal width);
1056
1057 inline void setTopBorderStyle(QTextFrameFormat::BorderStyle style)
1058 { setProperty(TableCellTopBorderStyle, style); }
1059 inline QTextFrameFormat::BorderStyle topBorderStyle() const
1060 { return static_cast<QTextFrameFormat::BorderStyle>(intProperty(TableCellTopBorderStyle)); }
1061
1062 inline void setBottomBorderStyle(QTextFrameFormat::BorderStyle style)
1063 { setProperty(TableCellBottomBorderStyle, style); }
1064 inline QTextFrameFormat::BorderStyle bottomBorderStyle() const
1065 { return static_cast<QTextFrameFormat::BorderStyle>(intProperty(TableCellBottomBorderStyle)); }
1066
1067 inline void setLeftBorderStyle(QTextFrameFormat::BorderStyle style)
1068 { setProperty(TableCellLeftBorderStyle, style); }
1069 inline QTextFrameFormat::BorderStyle leftBorderStyle() const
1070 { return static_cast<QTextFrameFormat::BorderStyle>(intProperty(TableCellLeftBorderStyle)); }
1071
1072 inline void setRightBorderStyle(QTextFrameFormat::BorderStyle style)
1073 { setProperty(TableCellRightBorderStyle, style); }
1074 inline QTextFrameFormat::BorderStyle rightBorderStyle() const
1075 { return static_cast<QTextFrameFormat::BorderStyle>(intProperty(TableCellRightBorderStyle)); }
1076
1077 inline void setBorderStyle(QTextFrameFormat::BorderStyle style);
1078
1079 inline void setTopBorderBrush(const QBrush &brush)
1080 { setProperty(TableCellTopBorderBrush, brush); }
1081 inline QBrush topBorderBrush() const
1082 { return brushProperty(TableCellTopBorderBrush); }
1083
1084 inline void setBottomBorderBrush(const QBrush &brush)
1085 { setProperty(TableCellBottomBorderBrush, brush); }
1086 inline QBrush bottomBorderBrush() const
1087 { return brushProperty(TableCellBottomBorderBrush); }
1088
1089 inline void setLeftBorderBrush(const QBrush &brush)
1090 { setProperty(TableCellLeftBorderBrush, brush); }
1091 inline QBrush leftBorderBrush() const
1092 { return brushProperty(TableCellLeftBorderBrush); }
1093
1094 inline void setRightBorderBrush(const QBrush &brush)
1095 { setProperty(TableCellRightBorderBrush, brush); }
1096 inline QBrush rightBorderBrush() const
1097 { return brushProperty(TableCellRightBorderBrush); }
1098
1099 inline void setBorderBrush(const QBrush &brush);
1100
1101 protected:
1102 explicit QTextTableCellFormat(const QTextFormat &fmt);
1103 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextTableCellFormat &);
1104 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextTableCellFormat &);
1105 friend class QTextFormat;
1106 };
1107
1108 Q_DECLARE_SHARED(QTextTableCellFormat)
1109
1110 inline void QTextTableCellFormat::setTopPadding(qreal padding)
1111 {
1112 setProperty(TableCellTopPadding, padding);
1113 }
1114
1115 inline qreal QTextTableCellFormat::topPadding() const
1116 {
1117 return doubleProperty(TableCellTopPadding);
1118 }
1119
1120 inline void QTextTableCellFormat::setBottomPadding(qreal padding)
1121 {
1122 setProperty(TableCellBottomPadding, padding);
1123 }
1124
1125 inline qreal QTextTableCellFormat::bottomPadding() const
1126 {
1127 return doubleProperty(TableCellBottomPadding);
1128 }
1129
1130 inline void QTextTableCellFormat::setLeftPadding(qreal padding)
1131 {
1132 setProperty(TableCellLeftPadding, padding);
1133 }
1134
1135 inline qreal QTextTableCellFormat::leftPadding() const
1136 {
1137 return doubleProperty(TableCellLeftPadding);
1138 }
1139
1140 inline void QTextTableCellFormat::setRightPadding(qreal padding)
1141 {
1142 setProperty(TableCellRightPadding, padding);
1143 }
1144
1145 inline qreal QTextTableCellFormat::rightPadding() const
1146 {
1147 return doubleProperty(TableCellRightPadding);
1148 }
1149
1150 inline void QTextTableCellFormat::setPadding(qreal padding)
1151 {
1152 setTopPadding(padding);
1153 setBottomPadding(padding);
1154 setLeftPadding(padding);
1155 setRightPadding(padding);
1156 }
1157
1158 inline void QTextTableCellFormat::setBorder(qreal width)
1159 {
1160 setTopBorder(width);
1161 setBottomBorder(width);
1162 setLeftBorder(width);
1163 setRightBorder(width);
1164 }
1165
1166 inline void QTextTableCellFormat::setBorderStyle(QTextFrameFormat::BorderStyle style)
1167 {
1168 setTopBorderStyle(style);
1169 setBottomBorderStyle(style);
1170 setLeftBorderStyle(style);
1171 setRightBorderStyle(style);
1172 }
1173
1174 inline void QTextTableCellFormat::setBorderBrush(const QBrush &brush)
1175 {
1176 setTopBorderBrush(brush);
1177 setBottomBorderBrush(brush);
1178 setLeftBorderBrush(brush);
1179 setRightBorderBrush(brush);
1180 }
1181
1182 QT_END_NAMESPACE
1183
1184 #endif