File indexing completed on 2025-09-17 09:10:22
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 ImageMaxWidth = 0x5015,
0245
0246
0247
0248
0249
0250
0251
0252
0253 FullWidthSelection = 0x06000,
0254
0255
0256 PageBreakPolicy = 0x7000,
0257
0258
0259 UserProperty = 0x100000
0260 };
0261 Q_ENUM(Property)
0262
0263 enum ObjectTypes {
0264 NoObject,
0265 ImageObject,
0266 TableObject,
0267 TableCellObject,
0268
0269 UserObject = 0x1000
0270 };
0271 Q_ENUM(ObjectTypes)
0272
0273 enum PageBreakFlag {
0274 PageBreak_Auto = 0,
0275 PageBreak_AlwaysBefore = 0x001,
0276 PageBreak_AlwaysAfter = 0x010
0277
0278 };
0279 Q_DECLARE_FLAGS(PageBreakFlags, PageBreakFlag)
0280
0281 QTextFormat();
0282
0283 explicit QTextFormat(int type);
0284
0285 QTextFormat(const QTextFormat &rhs);
0286 QTextFormat &operator=(const QTextFormat &rhs);
0287 ~QTextFormat();
0288
0289 void swap(QTextFormat &other)
0290 { d.swap(other.d); std::swap(format_type, other.format_type); }
0291
0292 void merge(const QTextFormat &other);
0293
0294 inline bool isValid() const { return type() != InvalidFormat; }
0295 inline bool isEmpty() const { return propertyCount() == 0; }
0296
0297 int type() const;
0298
0299 int objectIndex() const;
0300 void setObjectIndex(int object);
0301
0302 QVariant property(int propertyId) const;
0303 void setProperty(int propertyId, const QVariant &value);
0304 void clearProperty(int propertyId);
0305 bool hasProperty(int propertyId) const;
0306
0307 bool boolProperty(int propertyId) const;
0308 int intProperty(int propertyId) const;
0309 qreal doubleProperty(int propertyId) const;
0310 QString stringProperty(int propertyId) const;
0311 QColor colorProperty(int propertyId) const;
0312 QPen penProperty(int propertyId) const;
0313 QBrush brushProperty(int propertyId) const;
0314 QTextLength lengthProperty(int propertyId) const;
0315 QList<QTextLength> lengthVectorProperty(int propertyId) const;
0316
0317 void setProperty(int propertyId, const QList<QTextLength> &lengths);
0318
0319 QMap<int, QVariant> properties() const;
0320 int propertyCount() const;
0321
0322 inline void setObjectType(int type);
0323 inline int objectType() const
0324 { return intProperty(ObjectType); }
0325
0326 inline bool isCharFormat() const { return type() == CharFormat; }
0327 inline bool isBlockFormat() const { return type() == BlockFormat; }
0328 inline bool isListFormat() const { return type() == ListFormat; }
0329 inline bool isFrameFormat() const { return type() == FrameFormat; }
0330 inline bool isImageFormat() const { return type() == CharFormat && objectType() == ImageObject; }
0331 inline bool isTableFormat() const { return type() == FrameFormat && objectType() == TableObject; }
0332 inline bool isTableCellFormat() const { return type() == CharFormat && objectType() == TableCellObject; }
0333
0334 QTextBlockFormat toBlockFormat() const;
0335 QTextCharFormat toCharFormat() const;
0336 QTextListFormat toListFormat() const;
0337 QTextTableFormat toTableFormat() const;
0338 QTextFrameFormat toFrameFormat() const;
0339 QTextImageFormat toImageFormat() const;
0340 QTextTableCellFormat toTableCellFormat() const;
0341
0342 bool operator==(const QTextFormat &rhs) const;
0343 inline bool operator!=(const QTextFormat &rhs) const { return !operator==(rhs); }
0344 operator QVariant() const;
0345
0346 inline void setLayoutDirection(Qt::LayoutDirection direction)
0347 { setProperty(QTextFormat::LayoutDirection, direction); }
0348 inline Qt::LayoutDirection layoutDirection() const
0349 { return Qt::LayoutDirection(intProperty(QTextFormat::LayoutDirection)); }
0350
0351 inline void setBackground(const QBrush &brush)
0352 { setProperty(BackgroundBrush, brush); }
0353 inline QBrush background() const
0354 { return brushProperty(BackgroundBrush); }
0355 inline void clearBackground()
0356 { clearProperty(BackgroundBrush); }
0357
0358 inline void setForeground(const QBrush &brush)
0359 { setProperty(ForegroundBrush, brush); }
0360 inline QBrush foreground() const
0361 { return brushProperty(ForegroundBrush); }
0362 inline void clearForeground()
0363 { clearProperty(ForegroundBrush); }
0364
0365 private:
0366 QSharedDataPointer<QTextFormatPrivate> d;
0367 qint32 format_type;
0368
0369 friend class QTextFormatCollection;
0370 friend class QTextCharFormat;
0371 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextFormat &);
0372 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextFormat &);
0373 };
0374
0375 Q_DECLARE_SHARED(QTextFormat)
0376
0377 inline void QTextFormat::setObjectType(int atype)
0378 { setProperty(ObjectType, atype); }
0379
0380 Q_DECLARE_OPERATORS_FOR_FLAGS(QTextFormat::PageBreakFlags)
0381
0382 class Q_GUI_EXPORT QTextCharFormat : public QTextFormat
0383 {
0384 public:
0385 enum VerticalAlignment {
0386 AlignNormal = 0,
0387 AlignSuperScript,
0388 AlignSubScript,
0389 AlignMiddle,
0390 AlignTop,
0391 AlignBottom,
0392 AlignBaseline
0393 };
0394 enum UnderlineStyle {
0395 NoUnderline,
0396 SingleUnderline,
0397 DashUnderline,
0398 DotLine,
0399 DashDotLine,
0400 DashDotDotLine,
0401 WaveUnderline,
0402 SpellCheckUnderline
0403 };
0404
0405 QTextCharFormat();
0406
0407 bool isValid() const { return isCharFormat(); }
0408
0409 enum FontPropertiesInheritanceBehavior {
0410 FontPropertiesSpecifiedOnly,
0411 FontPropertiesAll
0412 };
0413 void setFont(const QFont &font, FontPropertiesInheritanceBehavior behavior = FontPropertiesAll);
0414 QFont font() const;
0415
0416 #if QT_DEPRECATED_SINCE(6, 1)
0417 QT_DEPRECATED_VERSION_X_6_1("Use setFontFamilies instead") inline void setFontFamily(const QString &family)
0418 { setProperty(FontFamilies, QVariant(QStringList(family))); }
0419 QT_DEPRECATED_VERSION_X_6_1("Use fontFamilies instead") inline QString fontFamily() const
0420 { return property(FontFamilies).toStringList().first(); }
0421 #endif
0422
0423 inline void setFontFamilies(const QStringList &families)
0424 { setProperty(FontFamilies, QVariant(families)); }
0425 #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
0426 inline QVariant fontFamilies() const
0427 { return property(FontFamilies); }
0428 #else
0429 inline QStringList fontFamilies() const
0430 { return property(FontFamilies).toStringList(); }
0431 #endif
0432
0433 inline void setFontStyleName(const QString &styleName)
0434 { setProperty(FontStyleName, styleName); }
0435 #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
0436 inline QVariant fontStyleName() const
0437 { return property(FontStyleName); }
0438 #else
0439 inline QStringList fontStyleName() const
0440 { return property(FontStyleName).toStringList(); }
0441 #endif
0442
0443 inline void setFontPointSize(qreal size)
0444 { setProperty(FontPointSize, size); }
0445 inline qreal fontPointSize() const
0446 { return doubleProperty(FontPointSize); }
0447
0448 inline void setFontWeight(int weight)
0449 { setProperty(FontWeight, weight); }
0450 inline int fontWeight() const
0451 { return hasProperty(FontWeight) ? intProperty(FontWeight) : QFont::Normal; }
0452 inline void setFontItalic(bool italic)
0453 { setProperty(FontItalic, italic); }
0454 inline bool fontItalic() const
0455 { return boolProperty(FontItalic); }
0456 inline void setFontCapitalization(QFont::Capitalization capitalization)
0457 { setProperty(FontCapitalization, capitalization); }
0458 inline QFont::Capitalization fontCapitalization() const
0459 { return static_cast<QFont::Capitalization>(intProperty(FontCapitalization)); }
0460 inline void setFontLetterSpacingType(QFont::SpacingType letterSpacingType)
0461 { setProperty(FontLetterSpacingType, letterSpacingType); }
0462 inline QFont::SpacingType fontLetterSpacingType() const
0463 { return static_cast<QFont::SpacingType>(intProperty(FontLetterSpacingType)); }
0464 inline void setFontLetterSpacing(qreal spacing)
0465 { setProperty(FontLetterSpacing, spacing); }
0466 inline qreal fontLetterSpacing() const
0467 { return doubleProperty(FontLetterSpacing); }
0468 inline void setFontWordSpacing(qreal spacing)
0469 { setProperty(FontWordSpacing, spacing); }
0470 inline qreal fontWordSpacing() const
0471 { return doubleProperty(FontWordSpacing); }
0472
0473 inline void setFontUnderline(bool underline)
0474 { setProperty(TextUnderlineStyle, underline ? SingleUnderline : NoUnderline); }
0475 bool fontUnderline() const;
0476
0477 inline void setFontOverline(bool overline)
0478 { setProperty(FontOverline, overline); }
0479 inline bool fontOverline() const
0480 { return boolProperty(FontOverline); }
0481
0482 inline void setFontStrikeOut(bool strikeOut)
0483 { setProperty(FontStrikeOut, strikeOut); }
0484 inline bool fontStrikeOut() const
0485 { return boolProperty(FontStrikeOut); }
0486
0487 inline void setUnderlineColor(const QColor &color)
0488 { setProperty(TextUnderlineColor, color); }
0489 inline QColor underlineColor() const
0490 { return colorProperty(TextUnderlineColor); }
0491
0492 inline void setFontFixedPitch(bool fixedPitch)
0493 { setProperty(FontFixedPitch, fixedPitch); }
0494 inline bool fontFixedPitch() const
0495 { return boolProperty(FontFixedPitch); }
0496
0497 inline void setFontStretch(int factor)
0498 { setProperty(FontStretch, factor); }
0499 inline int fontStretch() const
0500 { return intProperty(FontStretch); }
0501
0502 inline void setFontStyleHint(QFont::StyleHint hint, QFont::StyleStrategy strategy = QFont::PreferDefault)
0503 { setProperty(FontStyleHint, hint); setProperty(FontStyleStrategy, strategy); }
0504 inline void setFontStyleStrategy(QFont::StyleStrategy strategy)
0505 { setProperty(FontStyleStrategy, strategy); }
0506 QFont::StyleHint fontStyleHint() const
0507 { return static_cast<QFont::StyleHint>(intProperty(FontStyleHint)); }
0508 QFont::StyleStrategy fontStyleStrategy() const
0509 { return static_cast<QFont::StyleStrategy>(intProperty(FontStyleStrategy)); }
0510
0511 inline void setFontHintingPreference(QFont::HintingPreference hintingPreference)
0512 {
0513 setProperty(FontHintingPreference, hintingPreference);
0514 }
0515
0516 inline QFont::HintingPreference fontHintingPreference() const
0517 {
0518 return static_cast<QFont::HintingPreference>(intProperty(FontHintingPreference));
0519 }
0520
0521 inline void setFontKerning(bool enable)
0522 { setProperty(FontKerning, enable); }
0523 inline bool fontKerning() const
0524 { return boolProperty(FontKerning); }
0525
0526 void setUnderlineStyle(UnderlineStyle style);
0527 inline UnderlineStyle underlineStyle() const
0528 { return static_cast<UnderlineStyle>(intProperty(TextUnderlineStyle)); }
0529
0530 inline void setVerticalAlignment(VerticalAlignment alignment)
0531 { setProperty(TextVerticalAlignment, alignment); }
0532 inline VerticalAlignment verticalAlignment() const
0533 { return static_cast<VerticalAlignment>(intProperty(TextVerticalAlignment)); }
0534
0535 inline void setTextOutline(const QPen &pen)
0536 { setProperty(TextOutline, pen); }
0537 inline QPen textOutline() const
0538 { return penProperty(TextOutline); }
0539
0540 inline void setToolTip(const QString &tip)
0541 { setProperty(TextToolTip, tip); }
0542 inline QString toolTip() const
0543 { return stringProperty(TextToolTip); }
0544
0545 inline void setSuperScriptBaseline(qreal baseline)
0546 { setProperty(TextSuperScriptBaseline, baseline); }
0547 inline qreal superScriptBaseline() const
0548 { return hasProperty(TextSuperScriptBaseline) ? doubleProperty(TextSuperScriptBaseline) : 50.0; }
0549
0550 inline void setSubScriptBaseline(qreal baseline)
0551 { setProperty(TextSubScriptBaseline, baseline); }
0552 inline qreal subScriptBaseline() const
0553 { return hasProperty(TextSubScriptBaseline) ? doubleProperty(TextSubScriptBaseline) : 100.0 / 6.0; }
0554
0555 inline void setBaselineOffset(qreal baseline)
0556 { setProperty(TextBaselineOffset, baseline); }
0557 inline qreal baselineOffset() const
0558 { return hasProperty(TextBaselineOffset) ? doubleProperty(TextBaselineOffset) : 0.0; }
0559
0560 inline void setAnchor(bool anchor)
0561 { setProperty(IsAnchor, anchor); }
0562 inline bool isAnchor() const
0563 { return boolProperty(IsAnchor); }
0564
0565 inline void setAnchorHref(const QString &value)
0566 { setProperty(AnchorHref, value); }
0567 inline QString anchorHref() const
0568 { return stringProperty(AnchorHref); }
0569
0570 inline void setAnchorNames(const QStringList &names)
0571 { setProperty(AnchorName, names); }
0572 QStringList anchorNames() const;
0573
0574 inline void setTableCellRowSpan(int tableCellRowSpan);
0575 inline int tableCellRowSpan() const
0576 { int s = intProperty(TableCellRowSpan); if (s == 0) s = 1; return s; }
0577 inline void setTableCellColumnSpan(int tableCellColumnSpan);
0578 inline int tableCellColumnSpan() const
0579 { int s = intProperty(TableCellColumnSpan); if (s == 0) s = 1; return s; }
0580
0581 protected:
0582 explicit QTextCharFormat(const QTextFormat &fmt);
0583 friend class QTextFormat;
0584 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextCharFormat &);
0585 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextCharFormat &);
0586 };
0587
0588 Q_DECLARE_SHARED(QTextCharFormat)
0589
0590 inline void QTextCharFormat::setTableCellRowSpan(int _tableCellRowSpan)
0591 {
0592 if (_tableCellRowSpan <= 1)
0593 clearProperty(TableCellRowSpan);
0594 else
0595 setProperty(TableCellRowSpan, _tableCellRowSpan);
0596 }
0597
0598 inline void QTextCharFormat::setTableCellColumnSpan(int _tableCellColumnSpan)
0599 {
0600 if (_tableCellColumnSpan <= 1)
0601 clearProperty(TableCellColumnSpan);
0602 else
0603 setProperty(TableCellColumnSpan, _tableCellColumnSpan);
0604 }
0605
0606 class Q_GUI_EXPORT QTextBlockFormat : public QTextFormat
0607 {
0608 public:
0609 enum LineHeightTypes {
0610 SingleHeight = 0,
0611 ProportionalHeight = 1,
0612 FixedHeight = 2,
0613 MinimumHeight = 3,
0614 LineDistanceHeight = 4
0615 };
0616
0617 enum class MarkerType {
0618 NoMarker = 0,
0619 Unchecked = 1,
0620 Checked = 2
0621 };
0622
0623 QTextBlockFormat();
0624
0625 bool isValid() const { return isBlockFormat(); }
0626
0627 inline void setAlignment(Qt::Alignment alignment);
0628 inline Qt::Alignment alignment() const
0629 { int a = intProperty(BlockAlignment); if (a == 0) a = Qt::AlignLeft; return QFlag(a); }
0630
0631 inline void setTopMargin(qreal margin)
0632 { setProperty(BlockTopMargin, margin); }
0633 inline qreal topMargin() const
0634 { return doubleProperty(BlockTopMargin); }
0635
0636 inline void setBottomMargin(qreal margin)
0637 { setProperty(BlockBottomMargin, margin); }
0638 inline qreal bottomMargin() const
0639 { return doubleProperty(BlockBottomMargin); }
0640
0641 inline void setLeftMargin(qreal margin)
0642 { setProperty(BlockLeftMargin, margin); }
0643 inline qreal leftMargin() const
0644 { return doubleProperty(BlockLeftMargin); }
0645
0646 inline void setRightMargin(qreal margin)
0647 { setProperty(BlockRightMargin, margin); }
0648 inline qreal rightMargin() const
0649 { return doubleProperty(BlockRightMargin); }
0650
0651 inline void setTextIndent(qreal aindent)
0652 { setProperty(TextIndent, aindent); }
0653 inline qreal textIndent() const
0654 { return doubleProperty(TextIndent); }
0655
0656 inline void setIndent(int indent);
0657 inline int indent() const
0658 { return intProperty(BlockIndent); }
0659
0660 inline void setHeadingLevel(int alevel)
0661 { setProperty(HeadingLevel, alevel); }
0662 inline int headingLevel() const
0663 { return intProperty(HeadingLevel); }
0664
0665 inline void setLineHeight(qreal height, int heightType)
0666 { setProperty(LineHeight, height); setProperty(LineHeightType, heightType); }
0667 inline qreal lineHeight(qreal scriptLineHeight, qreal scaling) const;
0668 inline qreal lineHeight() const
0669 { return doubleProperty(LineHeight); }
0670 inline int lineHeightType() const
0671 { return intProperty(LineHeightType); }
0672
0673 inline void setNonBreakableLines(bool b)
0674 { setProperty(BlockNonBreakableLines, b); }
0675 inline bool nonBreakableLines() const
0676 { return boolProperty(BlockNonBreakableLines); }
0677
0678 inline void setPageBreakPolicy(PageBreakFlags flags)
0679 { setProperty(PageBreakPolicy, int(flags.toInt())); }
0680 inline PageBreakFlags pageBreakPolicy() const
0681 { return PageBreakFlags(intProperty(PageBreakPolicy)); }
0682
0683 void setTabPositions(const QList<QTextOption::Tab> &tabs);
0684 QList<QTextOption::Tab> tabPositions() const;
0685
0686 inline void setMarker(MarkerType marker)
0687 { setProperty(BlockMarker, int(marker)); }
0688 inline MarkerType marker() const
0689 { return MarkerType(intProperty(BlockMarker)); }
0690
0691 protected:
0692 explicit QTextBlockFormat(const QTextFormat &fmt);
0693 friend class QTextFormat;
0694 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextBlockFormat &);
0695 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextBlockFormat &);
0696 };
0697
0698 Q_DECLARE_SHARED(QTextBlockFormat)
0699
0700 inline void QTextBlockFormat::setAlignment(Qt::Alignment aalignment)
0701 { setProperty(BlockAlignment, int(aalignment.toInt())); }
0702
0703 inline void QTextBlockFormat::setIndent(int aindent)
0704 { setProperty(BlockIndent, aindent); }
0705
0706 inline qreal QTextBlockFormat::lineHeight(qreal scriptLineHeight, qreal scaling = 1.0) const
0707 {
0708 switch(intProperty(LineHeightType)) {
0709 case SingleHeight:
0710 return(scriptLineHeight);
0711 case ProportionalHeight:
0712 return(scriptLineHeight * doubleProperty(LineHeight) / 100.0);
0713 case FixedHeight:
0714 return(doubleProperty(LineHeight) * scaling);
0715 case MinimumHeight:
0716 return(qMax(scriptLineHeight, doubleProperty(LineHeight) * scaling));
0717 case LineDistanceHeight:
0718 return(scriptLineHeight + doubleProperty(LineHeight) * scaling);
0719 }
0720 return(0);
0721 }
0722
0723 class Q_GUI_EXPORT QTextListFormat : public QTextFormat
0724 {
0725 public:
0726 QTextListFormat();
0727
0728 bool isValid() const { return isListFormat(); }
0729
0730 enum Style {
0731 ListDisc = -1,
0732 ListCircle = -2,
0733 ListSquare = -3,
0734 ListDecimal = -4,
0735 ListLowerAlpha = -5,
0736 ListUpperAlpha = -6,
0737 ListLowerRoman = -7,
0738 ListUpperRoman = -8,
0739 ListStyleUndefined = 0
0740 };
0741
0742 inline void setStyle(Style style);
0743 inline Style style() const
0744 { return static_cast<Style>(intProperty(ListStyle)); }
0745
0746 inline void setIndent(int indent);
0747 inline int indent() const
0748 { return intProperty(ListIndent); }
0749
0750 inline void setNumberPrefix(const QString &numberPrefix);
0751 inline QString numberPrefix() const
0752 { return stringProperty(ListNumberPrefix); }
0753
0754 inline void setNumberSuffix(const QString &numberSuffix);
0755 inline QString numberSuffix() const
0756 { return stringProperty(ListNumberSuffix); }
0757
0758 inline void setStart(int indent);
0759 inline int start() const { return intProperty(ListStart); }
0760
0761 protected:
0762 explicit QTextListFormat(const QTextFormat &fmt);
0763 friend class QTextFormat;
0764 };
0765
0766 Q_DECLARE_SHARED(QTextListFormat)
0767
0768 inline void QTextListFormat::setStyle(Style astyle)
0769 { setProperty(ListStyle, astyle); }
0770
0771 inline void QTextListFormat::setIndent(int aindent)
0772 { setProperty(ListIndent, aindent); }
0773
0774 inline void QTextListFormat::setNumberPrefix(const QString &np)
0775 { setProperty(ListNumberPrefix, np); }
0776
0777 inline void QTextListFormat::setNumberSuffix(const QString &ns)
0778 { setProperty(ListNumberSuffix, ns); }
0779
0780 inline void QTextListFormat::setStart(int astart)
0781 {
0782 setProperty(ListStart, astart);
0783 }
0784
0785 class Q_GUI_EXPORT QTextImageFormat : public QTextCharFormat
0786 {
0787 public:
0788 QTextImageFormat();
0789
0790 bool isValid() const { return isImageFormat(); }
0791
0792 inline void setName(const QString &name);
0793 inline QString name() const
0794 { return stringProperty(ImageName); }
0795
0796 inline void setWidth(qreal width);
0797 inline qreal width() const
0798 { return doubleProperty(ImageWidth); }
0799
0800 inline void setMaximumWidth(QTextLength maxWidth);
0801 inline QTextLength maximumWidth() const
0802 { return lengthProperty(ImageMaxWidth); }
0803
0804 inline void setHeight(qreal height);
0805 inline qreal height() const
0806 { return doubleProperty(ImageHeight); }
0807
0808 inline void setQuality(int quality);
0809 #if QT_DEPRECATED_SINCE(6, 3)
0810 QT_DEPRECATED_VERSION_X_6_3("Pass a quality value, the default is 100") inline void setQuality()
0811 { setQuality(100); }
0812 #endif
0813 inline int quality() const
0814 { return intProperty(ImageQuality); }
0815
0816 protected:
0817 explicit QTextImageFormat(const QTextFormat &format);
0818 friend class QTextFormat;
0819 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextListFormat &);
0820 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextListFormat &);
0821 };
0822
0823 Q_DECLARE_SHARED(QTextImageFormat)
0824
0825 inline void QTextImageFormat::setName(const QString &aname)
0826 { setProperty(ImageName, aname); }
0827
0828 inline void QTextImageFormat::setWidth(qreal awidth)
0829 { setProperty(ImageWidth, awidth); }
0830
0831 inline void QTextImageFormat::setMaximumWidth(QTextLength maxWidth)
0832 { setProperty(ImageMaxWidth, maxWidth); }
0833
0834 inline void QTextImageFormat::setHeight(qreal aheight)
0835 { setProperty(ImageHeight, aheight); }
0836
0837 inline void QTextImageFormat::setQuality(int aquality)
0838 { setProperty(ImageQuality, aquality); }
0839
0840 class Q_GUI_EXPORT QTextFrameFormat : public QTextFormat
0841 {
0842 public:
0843 QTextFrameFormat();
0844
0845 bool isValid() const { return isFrameFormat(); }
0846
0847 enum Position {
0848 InFlow,
0849 FloatLeft,
0850 FloatRight
0851
0852
0853 };
0854
0855 enum BorderStyle {
0856 BorderStyle_None,
0857 BorderStyle_Dotted,
0858 BorderStyle_Dashed,
0859 BorderStyle_Solid,
0860 BorderStyle_Double,
0861 BorderStyle_DotDash,
0862 BorderStyle_DotDotDash,
0863 BorderStyle_Groove,
0864 BorderStyle_Ridge,
0865 BorderStyle_Inset,
0866 BorderStyle_Outset
0867 };
0868
0869 inline void setPosition(Position f)
0870 { setProperty(CssFloat, f); }
0871 inline Position position() const
0872 { return static_cast<Position>(intProperty(CssFloat)); }
0873
0874 inline void setBorder(qreal border);
0875 inline qreal border() const
0876 { return doubleProperty(FrameBorder); }
0877
0878 inline void setBorderBrush(const QBrush &brush)
0879 { setProperty(FrameBorderBrush, brush); }
0880 inline QBrush borderBrush() const
0881 { return brushProperty(FrameBorderBrush); }
0882
0883 inline void setBorderStyle(BorderStyle style)
0884 { setProperty(FrameBorderStyle, style); }
0885 inline BorderStyle borderStyle() const
0886 { return static_cast<BorderStyle>(intProperty(FrameBorderStyle)); }
0887
0888 void setMargin(qreal margin);
0889 inline qreal margin() const
0890 { return doubleProperty(FrameMargin); }
0891
0892 inline void setTopMargin(qreal margin);
0893 qreal topMargin() const;
0894
0895 inline void setBottomMargin(qreal margin);
0896 qreal bottomMargin() const;
0897
0898 inline void setLeftMargin(qreal margin);
0899 qreal leftMargin() const;
0900
0901 inline void setRightMargin(qreal margin);
0902 qreal rightMargin() const;
0903
0904 inline void setPadding(qreal padding);
0905 inline qreal padding() const
0906 { return doubleProperty(FramePadding); }
0907
0908 inline void setWidth(qreal width);
0909 inline void setWidth(const QTextLength &length)
0910 { setProperty(FrameWidth, length); }
0911 inline QTextLength width() const
0912 { return lengthProperty(FrameWidth); }
0913
0914 inline void setHeight(qreal height);
0915 inline void setHeight(const QTextLength &height);
0916 inline QTextLength height() const
0917 { return lengthProperty(FrameHeight); }
0918
0919 inline void setPageBreakPolicy(PageBreakFlags flags)
0920 { setProperty(PageBreakPolicy, int(flags.toInt())); }
0921 inline PageBreakFlags pageBreakPolicy() const
0922 { return PageBreakFlags(intProperty(PageBreakPolicy)); }
0923
0924 protected:
0925 explicit QTextFrameFormat(const QTextFormat &fmt);
0926 friend class QTextFormat;
0927 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextFrameFormat &);
0928 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextFrameFormat &);
0929 };
0930
0931 Q_DECLARE_SHARED(QTextFrameFormat)
0932
0933 inline void QTextFrameFormat::setBorder(qreal aborder)
0934 { setProperty(FrameBorder, aborder); }
0935
0936 inline void QTextFrameFormat::setPadding(qreal apadding)
0937 { setProperty(FramePadding, apadding); }
0938
0939 inline void QTextFrameFormat::setWidth(qreal awidth)
0940 { setProperty(FrameWidth, QTextLength(QTextLength::FixedLength, awidth)); }
0941
0942 inline void QTextFrameFormat::setHeight(qreal aheight)
0943 { setProperty(FrameHeight, QTextLength(QTextLength::FixedLength, aheight)); }
0944 inline void QTextFrameFormat::setHeight(const QTextLength &aheight)
0945 { setProperty(FrameHeight, aheight); }
0946
0947 inline void QTextFrameFormat::setTopMargin(qreal amargin)
0948 { setProperty(FrameTopMargin, amargin); }
0949
0950 inline void QTextFrameFormat::setBottomMargin(qreal amargin)
0951 { setProperty(FrameBottomMargin, amargin); }
0952
0953 inline void QTextFrameFormat::setLeftMargin(qreal amargin)
0954 { setProperty(FrameLeftMargin, amargin); }
0955
0956 inline void QTextFrameFormat::setRightMargin(qreal amargin)
0957 { setProperty(FrameRightMargin, amargin); }
0958
0959 class Q_GUI_EXPORT QTextTableFormat : public QTextFrameFormat
0960 {
0961 public:
0962 QTextTableFormat();
0963
0964 inline bool isValid() const { return isTableFormat(); }
0965
0966 inline int columns() const
0967 { int cols = intProperty(TableColumns); if (cols == 0) cols = 1; return cols; }
0968 inline void setColumns(int columns);
0969
0970 inline void setColumnWidthConstraints(const QList<QTextLength> &constraints)
0971 { setProperty(TableColumnWidthConstraints, constraints); }
0972
0973 inline QList<QTextLength> columnWidthConstraints() const
0974 { return lengthVectorProperty(TableColumnWidthConstraints); }
0975
0976 inline void clearColumnWidthConstraints()
0977 { clearProperty(TableColumnWidthConstraints); }
0978
0979 inline qreal cellSpacing() const
0980 { return doubleProperty(TableCellSpacing); }
0981 inline void setCellSpacing(qreal spacing)
0982 { setProperty(TableCellSpacing, spacing); }
0983
0984 inline qreal cellPadding() const
0985 { return doubleProperty(TableCellPadding); }
0986 inline void setCellPadding(qreal padding);
0987
0988 inline void setAlignment(Qt::Alignment alignment);
0989 inline Qt::Alignment alignment() const
0990 { return QFlag(intProperty(BlockAlignment)); }
0991
0992 inline void setHeaderRowCount(int count)
0993 { setProperty(TableHeaderRowCount, count); }
0994 inline int headerRowCount() const
0995 { return intProperty(TableHeaderRowCount); }
0996
0997 inline void setBorderCollapse(bool borderCollapse)
0998 { setProperty(TableBorderCollapse, borderCollapse); }
0999 inline bool borderCollapse() const
1000 { return boolProperty(TableBorderCollapse); }
1001
1002 protected:
1003 explicit QTextTableFormat(const QTextFormat &fmt);
1004 friend class QTextFormat;
1005 };
1006
1007 Q_DECLARE_SHARED(QTextTableFormat)
1008
1009 inline void QTextTableFormat::setColumns(int acolumns)
1010 {
1011 if (acolumns == 1)
1012 acolumns = 0;
1013 setProperty(TableColumns, acolumns);
1014 }
1015
1016 inline void QTextTableFormat::setCellPadding(qreal apadding)
1017 { setProperty(TableCellPadding, apadding); }
1018
1019 inline void QTextTableFormat::setAlignment(Qt::Alignment aalignment)
1020 { setProperty(BlockAlignment, int(aalignment.toInt())); }
1021
1022 class Q_GUI_EXPORT QTextTableCellFormat : public QTextCharFormat
1023 {
1024 public:
1025 QTextTableCellFormat();
1026
1027 inline bool isValid() const { return isTableCellFormat(); }
1028
1029 inline void setTopPadding(qreal padding);
1030 inline qreal topPadding() const;
1031
1032 inline void setBottomPadding(qreal padding);
1033 inline qreal bottomPadding() const;
1034
1035 inline void setLeftPadding(qreal padding);
1036 inline qreal leftPadding() const;
1037
1038 inline void setRightPadding(qreal padding);
1039 inline qreal rightPadding() const;
1040
1041 inline void setPadding(qreal padding);
1042
1043 inline void setTopBorder(qreal width)
1044 { setProperty(TableCellTopBorder, width); }
1045 inline qreal topBorder() const
1046 { return doubleProperty(TableCellTopBorder); }
1047
1048 inline void setBottomBorder(qreal width)
1049 { setProperty(TableCellBottomBorder, width); }
1050 inline qreal bottomBorder() const
1051 { return doubleProperty(TableCellBottomBorder); }
1052
1053 inline void setLeftBorder(qreal width)
1054 { setProperty(TableCellLeftBorder, width); }
1055 inline qreal leftBorder() const
1056 { return doubleProperty(TableCellLeftBorder); }
1057
1058 inline void setRightBorder(qreal width)
1059 { setProperty(TableCellRightBorder, width); }
1060 inline qreal rightBorder() const
1061 { return doubleProperty(TableCellRightBorder); }
1062
1063 inline void setBorder(qreal width);
1064
1065 inline void setTopBorderStyle(QTextFrameFormat::BorderStyle style)
1066 { setProperty(TableCellTopBorderStyle, style); }
1067 inline QTextFrameFormat::BorderStyle topBorderStyle() const
1068 { return static_cast<QTextFrameFormat::BorderStyle>(intProperty(TableCellTopBorderStyle)); }
1069
1070 inline void setBottomBorderStyle(QTextFrameFormat::BorderStyle style)
1071 { setProperty(TableCellBottomBorderStyle, style); }
1072 inline QTextFrameFormat::BorderStyle bottomBorderStyle() const
1073 { return static_cast<QTextFrameFormat::BorderStyle>(intProperty(TableCellBottomBorderStyle)); }
1074
1075 inline void setLeftBorderStyle(QTextFrameFormat::BorderStyle style)
1076 { setProperty(TableCellLeftBorderStyle, style); }
1077 inline QTextFrameFormat::BorderStyle leftBorderStyle() const
1078 { return static_cast<QTextFrameFormat::BorderStyle>(intProperty(TableCellLeftBorderStyle)); }
1079
1080 inline void setRightBorderStyle(QTextFrameFormat::BorderStyle style)
1081 { setProperty(TableCellRightBorderStyle, style); }
1082 inline QTextFrameFormat::BorderStyle rightBorderStyle() const
1083 { return static_cast<QTextFrameFormat::BorderStyle>(intProperty(TableCellRightBorderStyle)); }
1084
1085 inline void setBorderStyle(QTextFrameFormat::BorderStyle style);
1086
1087 inline void setTopBorderBrush(const QBrush &brush)
1088 { setProperty(TableCellTopBorderBrush, brush); }
1089 inline QBrush topBorderBrush() const
1090 { return brushProperty(TableCellTopBorderBrush); }
1091
1092 inline void setBottomBorderBrush(const QBrush &brush)
1093 { setProperty(TableCellBottomBorderBrush, brush); }
1094 inline QBrush bottomBorderBrush() const
1095 { return brushProperty(TableCellBottomBorderBrush); }
1096
1097 inline void setLeftBorderBrush(const QBrush &brush)
1098 { setProperty(TableCellLeftBorderBrush, brush); }
1099 inline QBrush leftBorderBrush() const
1100 { return brushProperty(TableCellLeftBorderBrush); }
1101
1102 inline void setRightBorderBrush(const QBrush &brush)
1103 { setProperty(TableCellRightBorderBrush, brush); }
1104 inline QBrush rightBorderBrush() const
1105 { return brushProperty(TableCellRightBorderBrush); }
1106
1107 inline void setBorderBrush(const QBrush &brush);
1108
1109 protected:
1110 explicit QTextTableCellFormat(const QTextFormat &fmt);
1111 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextTableCellFormat &);
1112 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextTableCellFormat &);
1113 friend class QTextFormat;
1114 };
1115
1116 Q_DECLARE_SHARED(QTextTableCellFormat)
1117
1118 inline void QTextTableCellFormat::setTopPadding(qreal padding)
1119 {
1120 setProperty(TableCellTopPadding, padding);
1121 }
1122
1123 inline qreal QTextTableCellFormat::topPadding() const
1124 {
1125 return doubleProperty(TableCellTopPadding);
1126 }
1127
1128 inline void QTextTableCellFormat::setBottomPadding(qreal padding)
1129 {
1130 setProperty(TableCellBottomPadding, padding);
1131 }
1132
1133 inline qreal QTextTableCellFormat::bottomPadding() const
1134 {
1135 return doubleProperty(TableCellBottomPadding);
1136 }
1137
1138 inline void QTextTableCellFormat::setLeftPadding(qreal padding)
1139 {
1140 setProperty(TableCellLeftPadding, padding);
1141 }
1142
1143 inline qreal QTextTableCellFormat::leftPadding() const
1144 {
1145 return doubleProperty(TableCellLeftPadding);
1146 }
1147
1148 inline void QTextTableCellFormat::setRightPadding(qreal padding)
1149 {
1150 setProperty(TableCellRightPadding, padding);
1151 }
1152
1153 inline qreal QTextTableCellFormat::rightPadding() const
1154 {
1155 return doubleProperty(TableCellRightPadding);
1156 }
1157
1158 inline void QTextTableCellFormat::setPadding(qreal padding)
1159 {
1160 setTopPadding(padding);
1161 setBottomPadding(padding);
1162 setLeftPadding(padding);
1163 setRightPadding(padding);
1164 }
1165
1166 inline void QTextTableCellFormat::setBorder(qreal width)
1167 {
1168 setTopBorder(width);
1169 setBottomBorder(width);
1170 setLeftBorder(width);
1171 setRightBorder(width);
1172 }
1173
1174 inline void QTextTableCellFormat::setBorderStyle(QTextFrameFormat::BorderStyle style)
1175 {
1176 setTopBorderStyle(style);
1177 setBottomBorderStyle(style);
1178 setLeftBorderStyle(style);
1179 setRightBorderStyle(style);
1180 }
1181
1182 inline void QTextTableCellFormat::setBorderBrush(const QBrush &brush)
1183 {
1184 setTopBorderBrush(brush);
1185 setBottomBorderBrush(brush);
1186 setLeftBorderBrush(brush);
1187 setRightBorderBrush(brush);
1188 }
1189
1190 QT_END_NAMESPACE
1191
1192 #endif