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 <lars.knoll@qt.io>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2018-10-31 10:33:07 +01:00
parent f213e818f0
commit ffeefaac62
2 changed files with 31 additions and 0 deletions

View File

@ -364,6 +364,9 @@ void QTextFormatPrivate::recalcFont() const
case QTextFormat::FontFamilies: case QTextFormat::FontFamilies:
f.setFamilies(props.at(i).value.toStringList()); f.setFamilies(props.at(i).value.toStringList());
break; break;
case QTextFormat::FontStyleName:
f.setStyleName(props.at(i).value.toString());
break;
case QTextFormat::FontPointSize: case QTextFormat::FontPointSize:
f.setPointSizeF(props.at(i).value.toReal()); f.setPointSizeF(props.at(i).value.toReal());
break; break;
@ -566,6 +569,7 @@ Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QTextFormat &fmt)
\value FontFamily \value FontFamily
\value FontFamilies \value FontFamilies
\value FontStyleName
\value FontPointSize \value FontPointSize
\value FontPixelSize \value FontPixelSize
\value FontSizeAdjustment Specifies the change in size given to the fontsize already set using \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() \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) \fn void QTextCharFormat::setFontPointSize(qreal size)
@ -1942,6 +1965,8 @@ void QTextCharFormat::setFont(const QFont &font, FontPropertiesInheritanceBehavi
setFontFamily(font.family()); setFontFamily(font.family());
if (mask & QFont::FamiliesResolved) if (mask & QFont::FamiliesResolved)
setFontFamilies(font.families()); setFontFamilies(font.families());
if (mask & QFont::StyleNameResolved)
setFontStyleName(font.styleName());
if (mask & QFont::SizeResolved) { if (mask & QFont::SizeResolved) {
const qreal pointSize = font.pointSizeF(); const qreal pointSize = font.pointSizeF();

View File

@ -189,6 +189,7 @@ public:
FontKerning = 0x1FE5, FontKerning = 0x1FE5,
FontHintingPreference = 0x1FE6, FontHintingPreference = 0x1FE6,
FontFamilies = 0x1FE7, FontFamilies = 0x1FE7,
FontStyleName = 0x1FE8,
FontFamily = 0x2000, FontFamily = 0x2000,
FontPointSize = 0x2001, FontPointSize = 0x2001,
FontSizeAdjustment = 0x2002, FontSizeAdjustment = 0x2002,
@ -434,6 +435,11 @@ public:
inline QVariant fontFamilies() const inline QVariant fontFamilies() const
{ return property(FontFamilies); } { return property(FontFamilies); }
inline void setFontStyleName(const QString &styleName)
{ setProperty(FontStyleName, styleName); }
inline QVariant fontStyleName() const
{ return property(FontStyleName); }
inline void setFontPointSize(qreal size) inline void setFontPointSize(qreal size)
{ setProperty(FontPointSize, size); } { setProperty(FontPointSize, size); }
inline qreal fontPointSize() const inline qreal fontPointSize() const