From e01bea8999d2f58add58874bd3e6792f509b131b Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 13 May 2015 15:31:37 +0200 Subject: [PATCH] Font matching by font stylename Some fonts may have styles that does not directly match to QFont properties. To support those QFontDatabase supports matching by style name. This patch exposes that to QML. Change-Id: I9896f2e3d9f6b56fb51f5694b018b456bcd05ed6 Task-number: QTBUG-30851 Reviewed-by: Simon Hausmann Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/imports/qtquick2/plugins.qmltypes | 1 + src/quick/items/qquicktext.cpp | 10 ++++++++++ src/quick/items/qquicktextedit.cpp | 11 +++++++++++ src/quick/items/qquicktextinput.cpp | 10 ++++++++++ src/quick/util/qquickglobal.cpp | 5 +++++ src/quick/util/qquickvaluetypes.cpp | 10 ++++++++++ src/quick/util/qquickvaluetypes_p.h | 4 ++++ 7 files changed, 51 insertions(+) diff --git a/src/imports/qtquick2/plugins.qmltypes b/src/imports/qtquick2/plugins.qmltypes index d98e9e6..050d0f7 100644 --- a/src/imports/qtquick2/plugins.qmltypes +++ b/src/imports/qtquick2/plugins.qmltypes @@ -1728,6 +1728,7 @@ Module { } } Property { name: "family"; type: "string" } + Property { name: "styleName"; type: "string" } Property { name: "bold"; type: "bool" } Property { name: "weight"; type: "FontWeight" } Property { name: "italic"; type: "bool" } diff --git a/src/quick/items/qquicktext.cpp b/src/quick/items/qquicktext.cpp index 2475d19..a91e6b4 100644 --- a/src/quick/items/qquicktext.cpp +++ b/src/quick/items/qquicktext.cpp @@ -1444,6 +1444,16 @@ QQuickText::~QQuickText() */ /*! + \qmlproperty string QtQuick::Text::font.styleName + \since 5.6 + + Sets the style name of the font. + + The style name is case insensitive. If set, the font will be matched against style name instead + of the font properties \l weight, \l bold and \l italic. +*/ + +/*! \qmlproperty bool QtQuick::Text::font.bold Sets whether the font weight is bold. diff --git a/src/quick/items/qquicktextedit.cpp b/src/quick/items/qquicktextedit.cpp index 2887dad..cf7e91f 100644 --- a/src/quick/items/qquicktextedit.cpp +++ b/src/quick/items/qquicktextedit.cpp @@ -206,6 +206,17 @@ QString QQuickTextEdit::text() const */ /*! + \qmlproperty string QtQuick::TextEdit::font.styleName + \since 5.6 + + Sets the style name of the font. + + The style name is case insensitive. If set, the font will be matched against style name instead + of the font properties \l weight, \l bold and \l italic. +*/ + + +/*! \qmlproperty bool QtQuick::TextEdit::font.bold Sets whether the font weight is bold. diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp index b458f80..3154945 100644 --- a/src/quick/items/qquicktextinput.cpp +++ b/src/quick/items/qquicktextinput.cpp @@ -229,6 +229,16 @@ QString QQuickTextInputPrivate::realText() const */ /*! + \qmlproperty string QtQuick::TextInput::font.styleName + \since 5.6 + + Sets the style name of the font. + + The style name is case insensitive. If set, the font will be matched against style name instead + of the font properties \l weight, \l bold and \l italic. +*/ + +/*! \qmlproperty bool QtQuick::TextInput::font.bold Sets whether the font weight is bold. diff --git a/src/quick/util/qquickglobal.cpp b/src/quick/util/qquickglobal.cpp index 6aa7bed..0680a49 100644 --- a/src/quick/util/qquickglobal.cpp +++ b/src/quick/util/qquickglobal.cpp @@ -285,6 +285,7 @@ public: QV4::ScopedValue vbold(scope, obj->get((s = v4->newString(QStringLiteral("bold"))))); QV4::ScopedValue vcap(scope, obj->get((s = v4->newString(QStringLiteral("capitalization"))))); QV4::ScopedValue vfam(scope, obj->get((s = v4->newString(QStringLiteral("family"))))); + QV4::ScopedValue vstyle(scope, obj->get((s = v4->newString(QStringLiteral("styleName"))))); QV4::ScopedValue vital(scope, obj->get((s = v4->newString(QStringLiteral("italic"))))); QV4::ScopedValue vlspac(scope, obj->get((s = v4->newString(QStringLiteral("letterSpacing"))))); QV4::ScopedValue vpixsz(scope, obj->get((s = v4->newString(QStringLiteral("pixelSize"))))); @@ -307,6 +308,10 @@ public: retn.setFamily(vfam->toQString()); if (ok) *ok = true; } + if (vstyle->isString()) { + retn.setStyleName(vstyle->toQString()); + if (ok) *ok = true; + } if (vital->isBoolean()) { retn.setItalic(vital->booleanValue()); if (ok) *ok = true; diff --git a/src/quick/util/qquickvaluetypes.cpp b/src/quick/util/qquickvaluetypes.cpp index fef6dfd..1f0d54e 100644 --- a/src/quick/util/qquickvaluetypes.cpp +++ b/src/quick/util/qquickvaluetypes.cpp @@ -533,6 +533,16 @@ void QQuickFontValueType::setFamily(const QString &family) v.setFamily(family); } +QString QQuickFontValueType::styleName() const +{ + return v.styleName(); +} + +void QQuickFontValueType::setStyleName(const QString &style) +{ + v.setStyleName(style); +} + bool QQuickFontValueType::bold() const { return v.bold(); diff --git a/src/quick/util/qquickvaluetypes_p.h b/src/quick/util/qquickvaluetypes_p.h index 1436d8e..7a2e888 100644 --- a/src/quick/util/qquickvaluetypes_p.h +++ b/src/quick/util/qquickvaluetypes_p.h @@ -268,6 +268,7 @@ class QQuickFontValueType Q_GADGET Q_PROPERTY(QString family READ family WRITE setFamily FINAL) + Q_PROPERTY(QString styleName READ styleName WRITE setStyleName FINAL) Q_PROPERTY(bool bold READ bold WRITE setBold FINAL) Q_PROPERTY(FontWeight weight READ weight WRITE setWeight FINAL) Q_PROPERTY(bool italic READ italic WRITE setItalic FINAL) @@ -303,6 +304,9 @@ public: QString family() const; void setFamily(const QString &); + QString styleName() const; + void setStyleName(const QString &); + bool bold() const; void setBold(bool b); -- 2.7.4