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