From 1fd4797816f92ec1be3c80c7572d909bcee08c1e Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Thu, 28 Jan 2016 11:13:46 +0100 Subject: QQuickApplicationWindow: resolve the default system theme font Change-Id: I6927ee293e5126abc037a3eb9f86a67825732679 Reviewed-by: Liang Qi --- tests/auto/applicationwindow/applicationwindow.pro | 2 +- .../applicationwindow/tst_applicationwindow.cpp | 33 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) (limited to 'tests/auto/applicationwindow') diff --git a/tests/auto/applicationwindow/applicationwindow.pro b/tests/auto/applicationwindow/applicationwindow.pro index 5a664b63..eabe81bf 100644 --- a/tests/auto/applicationwindow/applicationwindow.pro +++ b/tests/auto/applicationwindow/applicationwindow.pro @@ -4,7 +4,7 @@ SOURCES += tst_applicationwindow.cpp osx:CONFIG -= app_bundle -QT += core-private gui-private qml-private quick-private labstemplates-private testlib +QT += core-private gui-private qml-private quick-private labstemplates-private labscontrols-private testlib include (../shared/util.pri) diff --git a/tests/auto/applicationwindow/tst_applicationwindow.cpp b/tests/auto/applicationwindow/tst_applicationwindow.cpp index 8256f16b..34493ea0 100644 --- a/tests/auto/applicationwindow/tst_applicationwindow.cpp +++ b/tests/auto/applicationwindow/tst_applicationwindow.cpp @@ -41,12 +41,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include "../shared/util.h" #include "../shared/visualtestutil.h" @@ -65,6 +67,7 @@ private slots: void implicitFill(); void attachedProperties(); void font(); + void defaultFont(); void locale(); void activeFocusControl_data(); void activeFocusControl(); @@ -492,6 +495,36 @@ void tst_applicationwindow::font() QCOMPARE(item6->font(), font); } +class TestTheme : public QQuickProxyTheme +{ +public: + TestTheme(QPlatformTheme *theme) : QQuickProxyTheme(theme), m_font("Courier") + { QGuiApplicationPrivate::platform_theme = this; } + ~TestTheme() { QGuiApplicationPrivate::platform_theme = theme(); } + + const QFont *font(Font type = SystemFont) const Q_DECL_OVERRIDE + { + Q_UNUSED(type); + return &m_font; + } + + QFont m_font; +}; + +void tst_applicationwindow::defaultFont() +{ + TestTheme theme(QGuiApplicationPrivate::platform_theme); + + QQmlEngine engine; + QQmlComponent component(&engine); + component.setData("import Qt.labs.controls 1.0; ApplicationWindow { }", QUrl()); + + QScopedPointer window; + window.reset(static_cast(component.create())); + QVERIFY(!window.isNull()); + QCOMPARE(window->font(), *theme.font()); +} + void tst_applicationwindow::locale() { QQmlEngine engine; -- cgit v1.2.3