aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <[email protected]>2024-06-04 14:40:21 +0200
committerEskil Abrahamsen Blomfeldt <[email protected]>2024-08-09 10:04:30 +0200
commite2cd4d623890cd67d1959f40f98fa9b043d86c98 (patch)
tree6ba664f2438eb5be2830dc88e10f24518b7f9ba5
parent0512185767f89413f43def25b7806f324917a254 (diff)
Add missing properties to QQuickFontValueType::create()
A few recently added font properties were missing from the QQuickFontValueType::create() function, meaning that they could not be added to the object created with Qt.font(). Pick-to: 6.7 Change-Id: I511e8f1e3a3804d8e48943e734e42019941b0452 Reviewed-by: Ulf Hermann <[email protected]> (cherry picked from commit c8a859655def06edc66c00f151e031f449c284d5)
-rw-r--r--src/quick/util/qquickvaluetypes.cpp61
-rw-r--r--tests/auto/qml/qqmlqt/data/fontProperties.qml7
-rw-r--r--tests/auto/qml/qqmlqt/tst_qqmlqt.cpp16
3 files changed, 84 insertions, 0 deletions
diff --git a/src/quick/util/qquickvaluetypes.cpp b/src/quick/util/qquickvaluetypes.cpp
index c8a66e1734..fca9d60b29 100644
--- a/src/quick/util/qquickvaluetypes.cpp
+++ b/src/quick/util/qquickvaluetypes.cpp
@@ -978,6 +978,67 @@ QVariant QQuickFontValueType::create(const QJSValue &params)
}
}
+ {
+ const QJSValue ctxFontMerging = params.property(QStringLiteral("contextFontMerging"));
+ if (ctxFontMerging.isBool()) {
+ const bool enable = ctxFontMerging.toBool();
+ const QFont::StyleStrategy strategy = ret.styleStrategy();
+ if (enable)
+ ret.setStyleStrategy(QFont::StyleStrategy(strategy | QFont::ContextFontMerging));
+ else
+ ret.setStyleStrategy(QFont::StyleStrategy(strategy & ~QFont::ContextFontMerging));
+ ok = true;
+ }
+ }
+
+ {
+ const QJSValue variableAxes = params.property(QStringLiteral("variableAxes"));
+ if (variableAxes.isObject()) {
+ QVariantMap variantMap = variableAxes.toVariant().toMap();
+ for (auto [variableAxisName, variableAxisValue] : variantMap.asKeyValueRange()) {
+ const auto maybeTag = QFont::Tag::fromString(variableAxisName);
+ if (!maybeTag) {
+ qWarning() << "Invalid variable axis" << variableAxisName << "ignored";
+ continue;
+ }
+
+ bool valueOk;
+ float value = variableAxisValue.toFloat(&valueOk);
+ if (!valueOk) {
+ qWarning() << "Variable axis" << variableAxisName << "value" << variableAxisValue << "is not a floating point value.";
+ continue;
+ }
+
+ ret.setVariableAxis(*maybeTag, value);
+ ok = true;
+ }
+ }
+ }
+
+ {
+ const QJSValue features = params.property(QStringLiteral("features"));
+ if (features.isObject()) {
+ QVariantMap variantMap = features.toVariant().toMap();
+ for (auto [featureName, featureValue] : variantMap.asKeyValueRange()) {
+ const auto maybeTag = QFont::Tag::fromString(featureName);
+ if (!maybeTag) {
+ qWarning() << "Invalid font feature" << featureName << "ignored";
+ continue;
+ }
+
+ bool valueOk;
+ quint32 value = featureValue.toUInt(&valueOk);
+ if (!valueOk) {
+ qWarning() << "Font feature" << featureName << "value" << featureValue << "is not an integer.";
+ continue;
+ }
+
+ ret.setFeature(*maybeTag, value);
+ ok = true;
+ }
+ }
+ }
+
return ok ? ret : QVariant();
}
diff --git a/tests/auto/qml/qqmlqt/data/fontProperties.qml b/tests/auto/qml/qqmlqt/data/fontProperties.qml
new file mode 100644
index 0000000000..596a25e546
--- /dev/null
+++ b/tests/auto/qml/qqmlqt/data/fontProperties.qml
@@ -0,0 +1,7 @@
+import QtQuick 2.0
+
+Item {
+ property font fontProperty: Qt.font({ contextFontMerging: true,
+ variableAxes: { "abcd": 23.0625 },
+ features: { "abcd": 23 } });
+}
diff --git a/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp b/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp
index 9fea41104d..fafa2e16d4 100644
--- a/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp
+++ b/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp
@@ -85,6 +85,8 @@ private slots:
void timeRoundtrip_data();
void timeRoundtrip();
+ void fontSetsProperties();
+
private:
QQmlEngine engine;
};
@@ -1469,6 +1471,20 @@ void tst_qqmlqt::timeRoundtrip()
QCOMPARE(tp.m_getTime, tp.m_putTime);
}
+void tst_qqmlqt::fontSetsProperties() {
+ QQmlComponent component(&engine, testFileUrl("fontProperties.qml"));
+
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY(object != nullptr);
+
+ QFont fontProperty = qvariant_cast<QFont>(object->property("fontProperty"));
+ QVERIFY(fontProperty.styleStrategy() & QFont::ContextFontMerging);
+ QCOMPARE(fontProperty.variableAxisTags().size(), 1);
+ QCOMPARE(fontProperty.variableAxisValue("abcd"), 23.0625);
+ QCOMPARE(fontProperty.featureTags().size(), 1);
+ QCOMPARE(fontProperty.featureValue("abcd"), 23);
+}
+
QTEST_MAIN(tst_qqmlqt)
#include "tst_qqmlqt.moc"