diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2018-02-22 23:29:44 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2018-02-27 11:19:37 +0000 |
commit | cf0905a25cc02a1ad2a242319e7ad9748c0a64f3 (patch) | |
tree | ca40c76cc7974de2d5cbf00bd9c7c7cfe2268899 /src/quicktemplates2/qquicktheme.cpp | |
parent | 0836a69bdf84c7f0d63ef081c838b98bb38de41e (diff) |
QQuickTheme: don't inherit QPlatformTheme
Use QPlatformTheme as a fallback instead of inheriting from it. This
way, Qt Quick Controls 2 themes don't mess up the fonts and palettes
of Qt Quick Controls 1 and Qt Widgets applications.
Note: QQuickTheme::Font and QQuickTheme::Palette enums are copies of
the respective enums in QPlatformTheme, for now. This is the simplest
first step, but later on, we can have our own set of enums that cover
controls, such as Switch, that were previously entirely missing from
QPlatformTheme.
Task-number: QTBUG-51921
Change-Id: I8efe0ba2d03d65bc12b55b533ba9f2fab5320348
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquicktheme.cpp')
-rw-r--r-- | src/quicktemplates2/qquicktheme.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/quicktemplates2/qquicktheme.cpp b/src/quicktemplates2/qquicktheme.cpp index 0f9bc5de..02389ed0 100644 --- a/src/quicktemplates2/qquicktheme.cpp +++ b/src/quicktemplates2/qquicktheme.cpp @@ -37,10 +37,13 @@ #include "qquicktheme_p.h" #include "qquicktheme_p_p.h" +#include <QtGui/qpa/qplatformtheme.h> #include <QtGui/private/qguiapplication_p.h> QT_BEGIN_NAMESPACE +QScopedPointer<QQuickTheme> QQuickThemePrivate::current; + QQuickTheme::QQuickTheme() : d_ptr(new QQuickThemePrivate) { @@ -50,15 +53,27 @@ QQuickTheme::~QQuickTheme() { } +QQuickTheme *QQuickTheme::current() +{ + return QQuickThemePrivate::current.data(); +} + +void QQuickTheme::setCurrent(QQuickTheme *theme) +{ + QQuickThemePrivate::current.reset(theme); +} + QFont QQuickTheme::themeFont(Font type) { const QFont *font = nullptr; - if (QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) + if (QQuickTheme *theme = current()) font = theme->font(type); + else if (QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) + font = theme->font(static_cast<QPlatformTheme::Font>(type)); if (font) { QFont f = *font; - if (type == QPlatformTheme::SystemFont) + if (type == SystemFont) f.resolve(0); return f; } @@ -69,12 +84,14 @@ QFont QQuickTheme::themeFont(Font type) QPalette QQuickTheme::themePalette(Palette type) { const QPalette *palette = nullptr; - if (QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) + if (QQuickTheme *theme = current()) palette = theme->palette(type); + else if (QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) + palette = theme->palette(static_cast<QPlatformTheme::Palette>(type)); if (palette) { QPalette f = *palette; - if (type == QPlatformTheme::SystemPalette) + if (type == SystemPalette) f.resolve(0); return f; } |