diff options
Diffstat (limited to 'src/gui/text/qtextformat.h')
-rw-r--r-- | src/gui/text/qtextformat.h | 182 |
1 files changed, 98 insertions, 84 deletions
diff --git a/src/gui/text/qtextformat.h b/src/gui/text/qtextformat.h index 28da0fe344..2fa86ed0d1 100644 --- a/src/gui/text/qtextformat.h +++ b/src/gui/text/qtextformat.h @@ -1,54 +1,19 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QTEXTFORMAT_H #define QTEXTFORMAT_H -#include <QtGui/qtguiglobal.h> +#include <QtGui/qbrush.h> #include <QtGui/qcolor.h> #include <QtGui/qfont.h> -#include <QtCore/qshareddata.h> -#include <QtCore/qvector.h> -#include <QtCore/qvariant.h> #include <QtGui/qpen.h> -#include <QtGui/qbrush.h> #include <QtGui/qtextoption.h> +#include <QtGui/qtguiglobal.h> + +#include <QtCore/qlist.h> +#include <QtCore/qshareddata.h> +#include <QtCore/qvariant.h> QT_BEGIN_NAMESPACE @@ -72,11 +37,6 @@ class QTextCursor; class QTextDocument; class QTextLength; -#ifndef QT_NO_DATASTREAM -Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextLength &); -Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextLength &); -#endif - #ifndef QT_NO_DEBUG_STREAM Q_GUI_EXPORT QDebug operator<<(QDebug, const QTextLength &); #endif @@ -117,16 +77,11 @@ private: friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextLength &); friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextLength &); }; -Q_DECLARE_TYPEINFO(QTextLength, QT_VERSION >= QT_VERSION_CHECK(6,0,0) ? Q_PRIMITIVE_TYPE : Q_RELOCATABLE_TYPE); +Q_DECLARE_TYPEINFO(QTextLength, Q_PRIMITIVE_TYPE); inline QTextLength::QTextLength(Type atype, qreal avalue) : lengthType(atype), fixedValueOrPercentage(avalue) {} -#ifndef QT_NO_DATASTREAM -Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextFormat &); -Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextFormat &); -#endif - #ifndef QT_NO_DEBUG_STREAM Q_GUI_EXPORT QDebug operator<<(QDebug, const QTextFormat &); #endif @@ -140,9 +95,6 @@ public: BlockFormat = 1, CharFormat = 2, ListFormat = 3, -#if QT_DEPRECATED_SINCE(5, 3) - TableFormat = 4, -#endif FrameFormat = 5, UserFormat = 100 @@ -184,17 +136,19 @@ public: // character properties FirstFontProperty = 0x1FE0, FontCapitalization = FirstFontProperty, - FontLetterSpacingType = 0x2033, FontLetterSpacing = 0x1FE1, FontWordSpacing = 0x1FE2, - FontStretch = 0x2034, FontStyleHint = 0x1FE3, FontStyleStrategy = 0x1FE4, FontKerning = 0x1FE5, FontHintingPreference = 0x1FE6, FontFamilies = 0x1FE7, FontStyleName = 0x1FE8, + FontLetterSpacingType = 0x1FE9, + FontStretch = 0x1FEA, +#if QT_DEPRECATED_SINCE(6, 0) FontFamily = 0x2000, +#endif FontPointSize = 0x2001, FontSizeAdjustment = 0x2002, FontSizeIncrement = FontSizeAdjustment, // old name, compat @@ -207,15 +161,26 @@ public: FontPixelSize = 0x2009, LastFontProperty = FontPixelSize, - TextUnderlineColor = 0x2010, + TextUnderlineColor = 0x2020, TextVerticalAlignment = 0x2021, TextOutline = 0x2022, TextUnderlineStyle = 0x2023, TextToolTip = 0x2024, + TextSuperScriptBaseline = 0x2025, + TextSubScriptBaseline = 0x2026, + TextBaselineOffset = 0x2027, IsAnchor = 0x2030, AnchorHref = 0x2031, AnchorName = 0x2032, + + // Included for backwards compatibility with old QDataStreams. + // Should not be referenced in user code. + OldFontLetterSpacingType = 0x2033, + OldFontStretch = 0x2034, + OldTextUnderlineColor = 0x2010, + OldFontFamily = 0x2000, // same as FontFamily + ObjectType = 0x2f00, // list properties @@ -223,6 +188,7 @@ public: ListIndent = 0x3001, ListNumberPrefix = 0x3002, ListNumberSuffix = 0x3003, + ListStart = 0x3004, // table and frame properties FrameBorder = 0x4000, @@ -275,6 +241,7 @@ public: ImageWidth = 0x5010, ImageHeight = 0x5011, ImageQuality = 0x5014, + ImageMaxWidth = 0x5015, // internal /* @@ -320,7 +287,7 @@ public: ~QTextFormat(); void swap(QTextFormat &other) - { qSwap(d, other.d); qSwap(format_type, other.format_type); } + { d.swap(other.d); std::swap(format_type, other.format_type); } void merge(const QTextFormat &other); @@ -345,9 +312,9 @@ public: QPen penProperty(int propertyId) const; QBrush brushProperty(int propertyId) const; QTextLength lengthProperty(int propertyId) const; - QVector<QTextLength> lengthVectorProperty(int propertyId) const; + QList<QTextLength> lengthVectorProperty(int propertyId) const; - void setProperty(int propertyId, const QVector<QTextLength> &lengths); + void setProperty(int propertyId, const QList<QTextLength> &lengths); QMap<int, QVariant> properties() const; int propertyCount() const; @@ -443,24 +410,35 @@ public: FontPropertiesSpecifiedOnly, FontPropertiesAll }; - void setFont(const QFont &font, FontPropertiesInheritanceBehavior behavior); - void setFont(const QFont &font); // ### Qt6: Merge with above + void setFont(const QFont &font, FontPropertiesInheritanceBehavior behavior = FontPropertiesAll); QFont font() const; - inline void setFontFamily(const QString &family) - { setProperty(FontFamily, family); } - inline QString fontFamily() const - { return stringProperty(FontFamily); } +#if QT_DEPRECATED_SINCE(6, 1) + QT_DEPRECATED_VERSION_X_6_1("Use setFontFamilies instead") inline void setFontFamily(const QString &family) + { setProperty(FontFamilies, QVariant(QStringList(family))); } + QT_DEPRECATED_VERSION_X_6_1("Use fontFamilies instead") inline QString fontFamily() const + { return property(FontFamilies).toStringList().first(); } +#endif inline void setFontFamilies(const QStringList &families) { setProperty(FontFamilies, QVariant(families)); } +#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) inline QVariant fontFamilies() const { return property(FontFamilies); } +#else + inline QStringList fontFamilies() const + { return property(FontFamilies).toStringList(); } +#endif inline void setFontStyleName(const QString &styleName) { setProperty(FontStyleName, styleName); } +#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) inline QVariant fontStyleName() const { return property(FontStyleName); } +#else + inline QStringList fontStyleName() const + { return property(FontStyleName).toStringList(); } +#endif inline void setFontPointSize(qreal size) { setProperty(FontPointSize, size); } @@ -564,6 +542,21 @@ public: inline QString toolTip() const { return stringProperty(TextToolTip); } + inline void setSuperScriptBaseline(qreal baseline) + { setProperty(TextSuperScriptBaseline, baseline); } + inline qreal superScriptBaseline() const + { return hasProperty(TextSuperScriptBaseline) ? doubleProperty(TextSuperScriptBaseline) : 50.0; } + + inline void setSubScriptBaseline(qreal baseline) + { setProperty(TextSubScriptBaseline, baseline); } + inline qreal subScriptBaseline() const + { return hasProperty(TextSubScriptBaseline) ? doubleProperty(TextSubScriptBaseline) : 100.0 / 6.0; } + + inline void setBaselineOffset(qreal baseline) + { setProperty(TextBaselineOffset, baseline); } + inline qreal baselineOffset() const + { return hasProperty(TextBaselineOffset) ? doubleProperty(TextBaselineOffset) : 0.0; } + inline void setAnchor(bool anchor) { setProperty(IsAnchor, anchor); } inline bool isAnchor() const @@ -574,14 +567,6 @@ public: inline QString anchorHref() const { return stringProperty(AnchorHref); } -#if QT_DEPRECATED_SINCE(5, 13) - QT_DEPRECATED_X("Use setAnchorNames() instead") - inline void setAnchorName(const QString &name) - { setAnchorNames(QStringList(name)); } - QT_DEPRECATED_X("Use anchorNames() instead") - QString anchorName() const; -#endif - inline void setAnchorNames(const QStringList &names) { setProperty(AnchorName, names); } QStringList anchorNames() const; @@ -596,6 +581,8 @@ public: protected: explicit QTextCharFormat(const QTextFormat &fmt); friend class QTextFormat; + friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextCharFormat &); + friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextCharFormat &); }; Q_DECLARE_SHARED(QTextCharFormat) @@ -689,7 +676,7 @@ public: { return boolProperty(BlockNonBreakableLines); } inline void setPageBreakPolicy(PageBreakFlags flags) - { setProperty(PageBreakPolicy, int(flags)); } + { setProperty(PageBreakPolicy, int(flags.toInt())); } inline PageBreakFlags pageBreakPolicy() const { return PageBreakFlags(intProperty(PageBreakPolicy)); } @@ -704,12 +691,14 @@ public: protected: explicit QTextBlockFormat(const QTextFormat &fmt); friend class QTextFormat; + friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextBlockFormat &); + friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextBlockFormat &); }; Q_DECLARE_SHARED(QTextBlockFormat) inline void QTextBlockFormat::setAlignment(Qt::Alignment aalignment) -{ setProperty(BlockAlignment, int(aalignment)); } +{ setProperty(BlockAlignment, int(aalignment.toInt())); } inline void QTextBlockFormat::setIndent(int aindent) { setProperty(BlockIndent, aindent); } @@ -766,6 +755,9 @@ public: inline QString numberSuffix() const { return stringProperty(ListNumberSuffix); } + inline void setStart(int indent); + inline int start() const { return intProperty(ListStart); } + protected: explicit QTextListFormat(const QTextFormat &fmt); friend class QTextFormat; @@ -785,6 +777,11 @@ inline void QTextListFormat::setNumberPrefix(const QString &np) inline void QTextListFormat::setNumberSuffix(const QString &ns) { setProperty(ListNumberSuffix, ns); } +inline void QTextListFormat::setStart(int astart) +{ + setProperty(ListStart, astart); +} + class Q_GUI_EXPORT QTextImageFormat : public QTextCharFormat { public: @@ -800,17 +797,27 @@ public: inline qreal width() const { return doubleProperty(ImageWidth); } + inline void setMaximumWidth(QTextLength maxWidth); + inline QTextLength maximumWidth() const + { return lengthProperty(ImageMaxWidth); } + inline void setHeight(qreal height); inline qreal height() const { return doubleProperty(ImageHeight); } - inline void setQuality(int quality = 100); + inline void setQuality(int quality); +#if QT_DEPRECATED_SINCE(6, 3) + QT_DEPRECATED_VERSION_X_6_3("Pass a quality value, the default is 100") inline void setQuality() + { setQuality(100); } +#endif inline int quality() const { return intProperty(ImageQuality); } protected: explicit QTextImageFormat(const QTextFormat &format); friend class QTextFormat; + friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextListFormat &); + friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextListFormat &); }; Q_DECLARE_SHARED(QTextImageFormat) @@ -821,6 +828,9 @@ inline void QTextImageFormat::setName(const QString &aname) inline void QTextImageFormat::setWidth(qreal awidth) { setProperty(ImageWidth, awidth); } +inline void QTextImageFormat::setMaximumWidth(QTextLength maxWidth) +{ setProperty(ImageMaxWidth, maxWidth); } + inline void QTextImageFormat::setHeight(qreal aheight) { setProperty(ImageHeight, aheight); } @@ -907,13 +917,15 @@ public: { return lengthProperty(FrameHeight); } inline void setPageBreakPolicy(PageBreakFlags flags) - { setProperty(PageBreakPolicy, int(flags)); } + { setProperty(PageBreakPolicy, int(flags.toInt())); } inline PageBreakFlags pageBreakPolicy() const { return PageBreakFlags(intProperty(PageBreakPolicy)); } protected: explicit QTextFrameFormat(const QTextFormat &fmt); friend class QTextFormat; + friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextFrameFormat &); + friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextFrameFormat &); }; Q_DECLARE_SHARED(QTextFrameFormat) @@ -955,10 +967,10 @@ public: { int cols = intProperty(TableColumns); if (cols == 0) cols = 1; return cols; } inline void setColumns(int columns); - inline void setColumnWidthConstraints(const QVector<QTextLength> &constraints) + inline void setColumnWidthConstraints(const QList<QTextLength> &constraints) { setProperty(TableColumnWidthConstraints, constraints); } - inline QVector<QTextLength> columnWidthConstraints() const + inline QList<QTextLength> columnWidthConstraints() const { return lengthVectorProperty(TableColumnWidthConstraints); } inline void clearColumnWidthConstraints() @@ -1005,7 +1017,7 @@ inline void QTextTableFormat::setCellPadding(qreal apadding) { setProperty(TableCellPadding, apadding); } inline void QTextTableFormat::setAlignment(Qt::Alignment aalignment) -{ setProperty(BlockAlignment, int(aalignment)); } +{ setProperty(BlockAlignment, int(aalignment.toInt())); } class Q_GUI_EXPORT QTextTableCellFormat : public QTextCharFormat { @@ -1096,6 +1108,8 @@ public: protected: explicit QTextTableCellFormat(const QTextFormat &fmt); + friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextTableCellFormat &); + friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextTableCellFormat &); friend class QTextFormat; }; |