diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2018-05-13 19:34:29 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2018-05-22 14:20:58 +0000 |
commit | 9478053838ae2d950b162c2b93a2a400c82d9bf7 (patch) | |
tree | 317481f78a4c02e6c03ee6be50ac12df205e5b75 /src/imports/controls/material | |
parent | 1a3c1a089ff088482c9d093f4fa002e2d47cc103 (diff) |
Create and init QQuickTheme from QtQuickControls2Plugin
Instead of creating and setting the QQuickTheme instance from each
style plugin (e.g. QtQuickControls2MaterialStylePlugin), create the
QQuickTheme instance in QtQuickControls2Plugin when the style is
being resolved, and just pass the instance to be initialized by the
style plugin(s). This avoids the problem that QQuickTheme API was
virtual, and sub-classes created from plugins would have vtables
destroyed before the QQuickTheme was destroyed.
Task-number: QTBUG-67062
Task-number: QTBUG-68087
Change-Id: I19e9ced5296b708c2668c30163389cb3da6be7cf
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/imports/controls/material')
3 files changed, 23 insertions, 29 deletions
diff --git a/src/imports/controls/material/qquickmaterialtheme.cpp b/src/imports/controls/material/qquickmaterialtheme.cpp index 3ab07f6b..f42c0a03 100644 --- a/src/imports/controls/material/qquickmaterialtheme.cpp +++ b/src/imports/controls/material/qquickmaterialtheme.cpp @@ -40,14 +40,11 @@ #include <QtGui/qpa/qplatformdialoghelper.h> #include <QtGui/qfont.h> #include <QtGui/qfontinfo.h> +#include <QtQuickTemplates2/private/qquicktheme_p.h> QT_BEGIN_NAMESPACE -QQuickMaterialTheme::QQuickMaterialTheme() -{ -} - -void QQuickMaterialTheme::resolve() +void QQuickMaterialTheme::initialize(QQuickTheme *theme) { QFont systemFont; QFont buttonFont; @@ -78,38 +75,38 @@ void QQuickMaterialTheme::resolve() const bool dense = QQuickMaterialStyle::variant() == QQuickMaterialStyle::Dense; systemFont.setPixelSize(dense ? 13 : 14); - setFont(System, systemFont); + theme->setFont(QQuickTheme::System, systemFont); // https://material.io/guidelines/components/buttons.html#buttons-style buttonFont.setPixelSize(dense ? 13 : 14); buttonFont.setCapitalization(QFont::AllUppercase); buttonFont.setWeight(QFont::Medium); - setFont(Button, buttonFont); - setFont(TabBar, buttonFont); - setFont(ToolBar, buttonFont); + theme->setFont(QQuickTheme::Button, buttonFont); + theme->setFont(QQuickTheme::TabBar, buttonFont); + theme->setFont(QQuickTheme::ToolBar, buttonFont); // https://material.io/guidelines/components/tooltips.html toolTipFont.setPixelSize(dense ? 10 : 14); toolTipFont.setWeight(QFont::Medium); - setFont(ToolTip, toolTipFont); + theme->setFont(QQuickTheme::ToolTip, toolTipFont); itemViewFont.setPixelSize(dense ? 13 : 14); itemViewFont.setWeight(QFont::Medium); - setFont(ItemView, itemViewFont); + theme->setFont(QQuickTheme::ItemView, itemViewFont); // https://material.io/guidelines/components/lists.html#lists-specs listViewFont.setPixelSize(dense ? 13 : 16); - setFont(ListView, listViewFont); + theme->setFont(QQuickTheme::ListView, listViewFont); menuItemFont.setPixelSize(dense ? 13 : 16); - setFont(Menu, menuItemFont); - setFont(MenuBar, menuItemFont); - setFont(ComboBox, menuItemFont); + theme->setFont(QQuickTheme::Menu, menuItemFont); + theme->setFont(QQuickTheme::MenuBar, menuItemFont); + theme->setFont(QQuickTheme::ComboBox, menuItemFont); editorFont.setPixelSize(dense ? 13 : 16); - setFont(TextArea, editorFont); - setFont(TextField, editorFont); - setFont(SpinBox, editorFont); + theme->setFont(QQuickTheme::TextArea, editorFont); + theme->setFont(QQuickTheme::TextField, editorFont); + theme->setFont(QQuickTheme::SpinBox, editorFont); } QT_END_NAMESPACE diff --git a/src/imports/controls/material/qquickmaterialtheme_p.h b/src/imports/controls/material/qquickmaterialtheme_p.h index aa50887b..9a1362b8 100644 --- a/src/imports/controls/material/qquickmaterialtheme_p.h +++ b/src/imports/controls/material/qquickmaterialtheme_p.h @@ -48,19 +48,16 @@ // We mean it. // -#include <QtCore/qvariant.h> -#include <QtGui/qfont.h> -#include <QtQuickTemplates2/private/qquicktheme_p.h> +#include <QtCore/qglobal.h> QT_BEGIN_NAMESPACE -class QQuickMaterialTheme : public QQuickTheme +class QQuickTheme; + +class QQuickMaterialTheme { public: - explicit QQuickMaterialTheme(); - -protected: - void resolve() override; + static void initialize(QQuickTheme *theme); }; QT_END_NAMESPACE diff --git a/src/imports/controls/material/qtquickcontrols2materialstyleplugin.cpp b/src/imports/controls/material/qtquickcontrols2materialstyleplugin.cpp index 09dda329..d407af94 100644 --- a/src/imports/controls/material/qtquickcontrols2materialstyleplugin.cpp +++ b/src/imports/controls/material/qtquickcontrols2materialstyleplugin.cpp @@ -58,7 +58,7 @@ public: void registerTypes(const char *uri) override; QString name() const override; - QQuickTheme *createTheme() const override; + void initializeTheme(QQuickTheme *theme) override; }; QtQuickControls2MaterialStylePlugin::QtQuickControls2MaterialStylePlugin(QObject *parent) : QQuickStylePlugin(parent) @@ -92,9 +92,9 @@ QString QtQuickControls2MaterialStylePlugin::name() const return QStringLiteral("Material"); } -QQuickTheme *QtQuickControls2MaterialStylePlugin::createTheme() const +void QtQuickControls2MaterialStylePlugin::initializeTheme(QQuickTheme *theme) { - return new QQuickMaterialTheme; + QQuickMaterialTheme::initialize(theme); } QT_END_NAMESPACE |