diff options
author | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-04-10 15:33:05 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-04-11 09:00:18 +0000 |
commit | 7172c212faf73b6f4ab80b025e4cd45ecc7d6a86 (patch) | |
tree | e70286def8ffcb04e9a179c2bde7977f4f468749 /src | |
parent | 7946ce46e5ec42b4a1510b9dc6a33a28d8febe4e (diff) |
Add internal QQuickStylePlugin
This is a common base class for QtQuickMaterialStylePlugin and
QtQuickUniversalStylePlugin that takes care of the proxy theme
installation and manages its life time by using a scoped pointer.
Change-Id: I2cbe38287565d284b18fab4265456a41a2dbd8d4
Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/controls/controls.pri | 2 | ||||
-rw-r--r-- | src/controls/qquickstyleplugin.cpp | 81 | ||||
-rw-r--r-- | src/controls/qquickstyleplugin_p.h | 79 | ||||
-rw-r--r-- | src/imports/controls/material/qtquickmaterialstyleplugin.cpp | 29 | ||||
-rw-r--r-- | src/imports/controls/universal/qtquickuniversalstyleplugin.cpp | 30 |
5 files changed, 196 insertions, 25 deletions
diff --git a/src/controls/controls.pri b/src/controls/controls.pri index dc1920fb..5424c5c7 100644 --- a/src/controls/controls.pri +++ b/src/controls/controls.pri @@ -4,6 +4,7 @@ HEADERS += \ $$PWD/qquickproxytheme_p.h \ $$PWD/qquickstyle.h \ $$PWD/qquickstyleattached_p.h \ + $$PWD/qquickstyleplugin_p.h \ $$PWD/qquickstyleselector_p.h \ $$PWD/qquickstyleselector_p_p.h \ $$PWD/qquickpaddedrectangle_p.h @@ -14,5 +15,6 @@ SOURCES += \ $$PWD/qquickproxytheme.cpp \ $$PWD/qquickstyle.cpp \ $$PWD/qquickstyleattached.cpp \ + $$PWD/qquickstyleplugin.cpp \ $$PWD/qquickstyleselector.cpp \ $$PWD/qquickpaddedrectangle.cpp diff --git a/src/controls/qquickstyleplugin.cpp b/src/controls/qquickstyleplugin.cpp new file mode 100644 index 00000000..ceb6531e --- /dev/null +++ b/src/controls/qquickstyleplugin.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Labs Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickstyleplugin_p.h" +#include "qquickproxytheme_p.h" +#include "qquickstyle.h" + +#include <QtGui/private/qguiapplication_p.h> + +QT_BEGIN_NAMESPACE + +QQuickStylePlugin::QQuickStylePlugin(QObject *parent) : QQmlExtensionPlugin(parent) +{ +} + +QQuickStylePlugin::~QQuickStylePlugin() +{ +} + +void QQuickStylePlugin::registerTypes(const char *uri) +{ + Q_UNUSED(uri); +} + +void QQuickStylePlugin::initializeEngine(QQmlEngine *engine, const char *uri) +{ + Q_UNUSED(engine); + Q_UNUSED(uri); + + const QString style = name(); + if (!style.isEmpty() && style.compare(QQuickStyle::name(), Qt::CaseInsensitive) == 0) { + m_theme.reset(createTheme()); + if (m_theme) + QGuiApplicationPrivate::platform_theme = m_theme.data(); + } +} + +QString QQuickStylePlugin::name() const +{ + return QString(); +} + +QQuickProxyTheme *QQuickStylePlugin::createTheme() const +{ + return nullptr; +} + +QT_END_NAMESPACE diff --git a/src/controls/qquickstyleplugin_p.h b/src/controls/qquickstyleplugin_p.h new file mode 100644 index 00000000..93be0aa8 --- /dev/null +++ b/src/controls/qquickstyleplugin_p.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Labs Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKSTYLEPLUGIN_P_H +#define QQUICKSTYLEPLUGIN_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtCore/qscopedpointer.h> +#include <QtQml/qqmlextensionplugin.h> +#include <QtQuickControls/private/qtquickcontrolsglobal_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickProxyTheme; + +class Q_QUICKCONTROLS_PRIVATE_EXPORT QQuickStylePlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + +public: + explicit QQuickStylePlugin(QObject *parent = nullptr); + ~QQuickStylePlugin(); + + void registerTypes(const char *uri) override; + void initializeEngine(QQmlEngine *engine, const char *uri) override; + + virtual QString name() const; + virtual QQuickProxyTheme *createTheme() const; + +private: + QScopedPointer<QQuickProxyTheme> m_theme; +}; + +QT_END_NAMESPACE + +#endif // QQUICKSTYLEPLUGIN_P_H diff --git a/src/imports/controls/material/qtquickmaterialstyleplugin.cpp b/src/imports/controls/material/qtquickmaterialstyleplugin.cpp index 8b5f8dc4..a0336226 100644 --- a/src/imports/controls/material/qtquickmaterialstyleplugin.cpp +++ b/src/imports/controls/material/qtquickmaterialstyleplugin.cpp @@ -34,15 +34,13 @@ ** ****************************************************************************/ -#include <QtQml/qqmlextensionplugin.h> +#include <QtQuickControls/private/qquickstyleplugin_p.h> #include "qquickmaterialstyle_p.h" #include "qquickmaterialtheme_p.h" #include "qquickmaterialprogressring_p.h" #include "qquickmaterialprogressstrip_p.h" -#include <QtGui/private/qguiapplication_p.h> -#include <QtQuickControls/qquickstyle.h> #include <QtQuickControls/private/qquickstyleselector_p.h> static inline void initResources() @@ -55,7 +53,7 @@ static inline void initResources() QT_BEGIN_NAMESPACE -class QtQuickMaterialStylePlugin : public QQmlExtensionPlugin +class QtQuickMaterialStylePlugin : public QQuickStylePlugin { Q_OBJECT Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface/1.0") @@ -66,11 +64,11 @@ public: void registerTypes(const char *uri) override; void initializeEngine(QQmlEngine *engine, const char *uri) override; -private: - QScopedPointer<QQuickProxyTheme> theme; + QString name() const override; + QQuickProxyTheme *createTheme() const override; }; -QtQuickMaterialStylePlugin::QtQuickMaterialStylePlugin(QObject *parent) : QQmlExtensionPlugin(parent) +QtQuickMaterialStylePlugin::QtQuickMaterialStylePlugin(QObject *parent) : QQuickStylePlugin(parent) { initResources(); } @@ -82,12 +80,7 @@ void QtQuickMaterialStylePlugin::registerTypes(const char *uri) void QtQuickMaterialStylePlugin::initializeEngine(QQmlEngine *engine, const char *uri) { - Q_UNUSED(engine); - - if (QQuickStyle::name().compare(QLatin1String("material"), Qt::CaseInsensitive) == 0) { - theme.reset(new QQuickMaterialTheme); - QGuiApplicationPrivate::platform_theme = theme.data(); - } + QQuickStylePlugin::initializeEngine(engine, uri); QByteArray import = QByteArray(uri) + ".impl"; qmlRegisterType<QQuickMaterialProgressRing>(import, 1, 0, "ProgressRing"); @@ -98,6 +91,16 @@ void QtQuickMaterialStylePlugin::initializeEngine(QQmlEngine *engine, const char qmlRegisterType(QUrl(baseUrl().toString() + QStringLiteral("/SliderHandle.qml")), import, 1, 0, "SliderHandle"); } +QString QtQuickMaterialStylePlugin::name() const +{ + return QStringLiteral("material"); +} + +QQuickProxyTheme *QtQuickMaterialStylePlugin::createTheme() const +{ + return new QQuickMaterialTheme; +} + QT_END_NAMESPACE #include "qtquickmaterialstyleplugin.moc" diff --git a/src/imports/controls/universal/qtquickuniversalstyleplugin.cpp b/src/imports/controls/universal/qtquickuniversalstyleplugin.cpp index 371b94ed..d940b0e6 100644 --- a/src/imports/controls/universal/qtquickuniversalstyleplugin.cpp +++ b/src/imports/controls/universal/qtquickuniversalstyleplugin.cpp @@ -34,16 +34,15 @@ ** ****************************************************************************/ -#include <QtQml/qqmlextensionplugin.h> +#include <QtQuickControls/private/qquickstyleplugin_p.h> + #include "qquickuniversalfocusrectangle_p.h" #include "qquickuniversalprogressring_p.h" #include "qquickuniversalprogressstrip_p.h" #include "qquickuniversalstyle_p.h" #include "qquickuniversaltheme_p.h" -#include <QtGui/private/qguiapplication_p.h> #include <QtQuickControls/private/qquickcolorimageprovider_p.h> -#include <QtQuickControls/qquickstyle.h> static inline void initResources() { @@ -55,7 +54,7 @@ static inline void initResources() QT_BEGIN_NAMESPACE -class QtQuickUniversalStylePlugin: public QQmlExtensionPlugin +class QtQuickUniversalStylePlugin: public QQuickStylePlugin { Q_OBJECT Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface/1.0") @@ -66,11 +65,11 @@ public: void registerTypes(const char *uri) override; void initializeEngine(QQmlEngine *engine, const char *uri) override; -private: - QScopedPointer<QQuickProxyTheme> theme; + QString name() const override; + QQuickProxyTheme *createTheme() const override; }; -QtQuickUniversalStylePlugin::QtQuickUniversalStylePlugin(QObject *parent) : QQmlExtensionPlugin(parent) +QtQuickUniversalStylePlugin::QtQuickUniversalStylePlugin(QObject *parent) : QQuickStylePlugin(parent) { initResources(); } @@ -82,12 +81,9 @@ void QtQuickUniversalStylePlugin::registerTypes(const char *uri) void QtQuickUniversalStylePlugin::initializeEngine(QQmlEngine *engine, const char *uri) { - if (QQuickStyle::name().compare(QLatin1String("universal"), Qt::CaseInsensitive) == 0) { - theme.reset(new QQuickUniversalTheme); - QGuiApplicationPrivate::platform_theme = theme.data(); - } + QQuickStylePlugin::initializeEngine(engine, uri); - engine->addImageProvider(QStringLiteral("universal"), new QQuickColorImageProvider(QStringLiteral(":/qt-project.org/imports/Qt/labs/controls/universal/images"))); + engine->addImageProvider(name(), new QQuickColorImageProvider(QStringLiteral(":/qt-project.org/imports/Qt/labs/controls/universal/images"))); QByteArray import = QByteArray(uri) + ".impl"; qmlRegisterType<QQuickUniversalFocusRectangle>(import, 1, 0, "FocusRectangle"); @@ -97,6 +93,16 @@ void QtQuickUniversalStylePlugin::initializeEngine(QQmlEngine *engine, const cha qmlRegisterType<QQuickUniversalProgressStripAnimator>(import, 1, 0, "ProgressStripAnimator"); } +QString QtQuickUniversalStylePlugin::name() const +{ + return QStringLiteral("universal"); +} + +QQuickProxyTheme *QtQuickUniversalStylePlugin::createTheme() const +{ + return new QQuickUniversalTheme; +} + QT_END_NAMESPACE #include "qtquickuniversalstyleplugin.moc" |