From 01b0e2316771b495e3ef3586585f2bc626557394 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Thu, 15 Feb 2018 16:10:52 +0100 Subject: Fix QQuickTheme::font() and palette() Respect fonts and palettes from :/qtquickcontrols2.conf, but don't blatantly override the platform fonts and palettes with null values if the fonts and palettes are not set in :/qtquickcontrols2.conf. Even though fonts and palettes have technically same problem, testing the system palette is hard with 5.11 since QQuickDefaultTheme is a platform proxy theme and provides a custom system palette. It should be possible to have tst_palette::systemPalette() in dev, though, where we have removed the inheritance between QQuickTheme and QPlatformTheme. Task-number: QTBUG-66430 Change-Id: I6dfe678ccdc7e3990320c120612cfcc68723264d Reviewed-by: Mitch Curtis --- tests/auto/font/tst_font.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'tests/auto/font') diff --git a/tests/auto/font/tst_font.cpp b/tests/auto/font/tst_font.cpp index 660f4baf..75942286 100644 --- a/tests/auto/font/tst_font.cpp +++ b/tests/auto/font/tst_font.cpp @@ -54,6 +54,8 @@ class tst_font : public QQmlDataTest Q_OBJECT private slots: + void systemFont(); + void font_data(); void font(); @@ -67,6 +69,40 @@ private slots: void listView(); }; +static QFont testFont() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.setData("import QtQuick 2.0; import QtQuick.Controls 2.0; Text { }", QUrl()); + + QScopedPointer object(component.create()); + Q_ASSERT_X(!object.isNull(), "testFont", qPrintable(component.errorString())); + + QVariant var = object->property("font"); + Q_ASSERT_X(var.isValid(), "testFont", var.typeName()); + return var.value(); +} + +void tst_font::systemFont() +{ + const QFont *originalSystemFont = QGuiApplicationPrivate::platformTheme()->font(QPlatformTheme::SystemFont); + if (!originalSystemFont) + QSKIP("Cannot test the system font on a minimal platform"); + + const QFont fontBefore = testFont(); + QCOMPARE(fontBefore, *originalSystemFont); + + qmlClearTypeRegistrations(); + delete QGuiApplicationPrivate::app_font; + QGuiApplicationPrivate::app_font = nullptr; + + const QFont appFont = QGuiApplication::font(); + QCOMPARE(appFont, *originalSystemFont); + + const QFont fontAfter = testFont(); + QCOMPARE(fontAfter, *originalSystemFont); +} + void tst_font::font_data() { QTest::addColumn("testFile"); -- cgit v1.2.3