From ffeefaac6273b8bdb81876a5cc26e15cb9353955 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 31 Oct 2018 10:33:07 +0100 Subject: Support style name property in QTextCharFormat The support for setting the style name in the QTextDocument API was never added, as revealed by the example in the linked bug report. The actual bug reported there (style names not working with some Helvetica Neue) is not reproducible anymore. [ChangeLog][QtGui][Text] Added support for setting the font's style name in QTextCharFormat. Task-number: QTBUG-22813 Change-Id: I8f4d12151c3611aa30965fd963bc93f7c4264e23 Reviewed-by: Lars Knoll --- src/gui/text/qtextformat.cpp | 25 +++++++++++++++++++++++++ src/gui/text/qtextformat.h | 6 ++++++ 2 files changed, 31 insertions(+) diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp index e814f4f718..136e7dc140 100644 --- a/src/gui/text/qtextformat.cpp +++ b/src/gui/text/qtextformat.cpp @@ -364,6 +364,9 @@ void QTextFormatPrivate::recalcFont() const case QTextFormat::FontFamilies: f.setFamilies(props.at(i).value.toStringList()); break; + case QTextFormat::FontStyleName: + f.setStyleName(props.at(i).value.toString()); + break; case QTextFormat::FontPointSize: f.setPointSizeF(props.at(i).value.toReal()); break; @@ -566,6 +569,7 @@ Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QTextFormat &fmt) \value FontFamily \value FontFamilies + \value FontStyleName \value FontPointSize \value FontPixelSize \value FontSizeAdjustment Specifies the change in size given to the fontsize already set using @@ -1412,6 +1416,25 @@ QTextCharFormat::QTextCharFormat(const QTextFormat &fmt) \sa font() */ + +/*! + \fn void QTextCharFormat::setFontStyleName(const QString &styleName) + \since 5.13 + + Sets the text format's font \a style name. + + \sa setFont(), QFont::setStyleName() +*/ + +/*! + \fn QStringList QTextCharFormat::fontStyleName() const + \since 5.13 + + Returns the text format's font style name. + + \sa font(), QFont::styleName() +*/ + /*! \fn void QTextCharFormat::setFontPointSize(qreal size) @@ -1942,6 +1965,8 @@ void QTextCharFormat::setFont(const QFont &font, FontPropertiesInheritanceBehavi setFontFamily(font.family()); if (mask & QFont::FamiliesResolved) setFontFamilies(font.families()); + if (mask & QFont::StyleNameResolved) + setFontStyleName(font.styleName()); if (mask & QFont::SizeResolved) { const qreal pointSize = font.pointSizeF(); diff --git a/src/gui/text/qtextformat.h b/src/gui/text/qtextformat.h index d27d2e7f17..f292feabe8 100644 --- a/src/gui/text/qtextformat.h +++ b/src/gui/text/qtextformat.h @@ -189,6 +189,7 @@ public: FontKerning = 0x1FE5, FontHintingPreference = 0x1FE6, FontFamilies = 0x1FE7, + FontStyleName = 0x1FE8, FontFamily = 0x2000, FontPointSize = 0x2001, FontSizeAdjustment = 0x2002, @@ -434,6 +435,11 @@ public: inline QVariant fontFamilies() const { return property(FontFamilies); } + inline void setFontStyleName(const QString &styleName) + { setProperty(FontStyleName, styleName); } + inline QVariant fontStyleName() const + { return property(FontStyleName); } + inline void setFontPointSize(qreal size) { setProperty(FontPointSize, size); } inline qreal fontPointSize() const -- cgit v1.2.3