Skip to content

Commit

Permalink
Pluginize the platform styles
Browse files Browse the repository at this point in the history
This enforces decoupling and in the case of QMacStyle, isolates
QtWidgets and therefore end user applications, from Carbon/HITheme.

Windows and Fusion are platform independent, so they remain built-in
(but mostly because the Windows style is tightly coupled to other styles
like QStylesheetStyle).

Task-number: QTBUG-59428
Change-Id: Id6519fe0c5269c1bce5b5921f9db06257032a1c9
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@qt.io>
  • Loading branch information
jakepetroules committed Apr 14, 2017
1 parent 571eb37 commit 4f3249f
Show file tree
Hide file tree
Showing 38 changed files with 297 additions and 138 deletions.
1 change: 1 addition & 0 deletions src/plugins/plugins.pro
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ qtHaveModule(gui) {
qtConfig(imageformatplugin): SUBDIRS *= imageformats
!android:qtConfig(library): SUBDIRS *= generic
}
qtHaveModule(widgets): SUBDIRS += styles

!winrt:!wince:qtHaveModule(printsupport): \
SUBDIRS += printsupport
16 changes: 16 additions & 0 deletions src/plugins/styles/android/android.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
TARGET = qandroidstyle

QT += widgets-private

SOURCES += \
main.cpp \
qandroidstyle.cpp

HEADERS += \
qandroidstyle_p.h

DISTFILES += androidstyle.json

PLUGIN_TYPE = styles
PLUGIN_CLASS_NAME = QAndroidStylePlugin
load(qt_plugin)
3 changes: 3 additions & 0 deletions src/plugins/styles/android/androidstyle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Keys": [ "android" ]
}
64 changes: 64 additions & 0 deletions src/plugins/styles/android/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** 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 https://www.qt.io/terms-conditions. For further
** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include <QtWidgets/qstyleplugin.h>
#include "qandroidstyle_p.h"

QT_BEGIN_NAMESPACE

class QAndroidStylePlugin : public QStylePlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QStyleFactoryInterface" FILE "androidstyle.json")
public:
QStyle *create(const QString &key);
};

QStyle *QAndroidStylePlugin::create(const QString &key)
{
if (key.compare(QLatin1String("android"), Qt::CaseInsensitive) == 0)
return new QAndroidStyle();

return 0;
}

QT_END_NAMESPACE

#include "main.moc"

Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@

#include "qandroidstyle_p.h"

#if QT_CONFIG(style_android) || defined(QT_PLUGIN)

#include <QFile>
#include <QFont>
#include <QApplication>
Expand Down Expand Up @@ -1805,5 +1803,3 @@ QRect QAndroidStyle::AndroidSpinnerControl::subControlRect(const QStyleOptionCom
}

QT_END_NAMESPACE

#endif // QT_CONFIG(style_android) || defined(QT_PLUGIN)
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,14 @@
//

#include <QtWidgets/private/qtwidgetsglobal_p.h>
#include <QtWidgets/private/qfusionstyle_p.h>
#include <QtCore/QList>
#include <QtCore/QMargins>
#include <QtCore/QHash>
#include <QtCore/QVariantMap>
#include "qfusionstyle_p.h"

QT_BEGIN_NAMESPACE

#if QT_CONFIG(style_android)

class Q_WIDGETS_EXPORT QAndroidStyle : public QFusionStyle
{
Q_OBJECT
Expand Down Expand Up @@ -388,8 +386,6 @@ class Q_WIDGETS_EXPORT QAndroidStyle : public QFusionStyle
AndroidCompoundButtonControl *checkBoxControl;
};

#endif // style_android

QT_END_NAMESPACE

#endif // QANDROIDSTYLE_P_H
19 changes: 19 additions & 0 deletions src/plugins/styles/mac/mac.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
TARGET = qmacstyle

QT += widgets-private

SOURCES += \
main.mm \
qmacstyle_mac.mm

HEADERS += \
qmacstyle_mac_p.h \
qmacstyle_mac_p_p.h

LIBS_PRIVATE += -framework AppKit -framework Carbon

DISTFILES += macstyle.json

PLUGIN_TYPE = styles
PLUGIN_CLASS_NAME = QMacStylePlugin
load(qt_plugin)
3 changes: 3 additions & 0 deletions src/plugins/styles/mac/macstyle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Keys": [ "macintosh" ]
}
65 changes: 65 additions & 0 deletions src/plugins/styles/mac/main.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** 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 https://www.qt.io/terms-conditions. For further
** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include <QtWidgets/qstyleplugin.h>
#include "qmacstyle_mac_p.h"

QT_BEGIN_NAMESPACE

class QMacStylePlugin : public QStylePlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QStyleFactoryInterface" FILE "macstyle.json")
public:
QStyle *create(const QString &key);
};

QStyle *QMacStylePlugin::create(const QString &key)
{
QMacAutoReleasePool pool;
if (key.compare(QLatin1String("macintosh"), Qt::CaseInsensitive) == 0)
return new QMacStyle();

return 0;
}

QT_END_NAMESPACE

#include "main.moc"

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@

QT_BEGIN_NAMESPACE


#if QT_CONFIG(style_mac)

class QPalette;

class QPushButton;
Expand Down Expand Up @@ -126,8 +123,6 @@ class QMacStyle : public QCommonStyle
#endif
};

#endif

QT_END_NAMESPACE

#endif // QMACSTYLE_MAC_P_H
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
#undef check

#include <QtWidgets/private/qtwidgetsglobal_p.h>
#include <QtWidgets/private/qcommonstyle_p.h>
#include "qmacstyle_mac_p.h"
#include "qcommonstyle_p.h"
#include <private/qapplication_p.h>
#include <private/qcombobox_p.h>
#include <private/qpainter_p.h>
Expand Down
8 changes: 8 additions & 0 deletions src/plugins/styles/styles.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
TEMPLATE = subdirs
QT_FOR_CONFIG += widgets-private

qtConfig(style-android): SUBDIRS += android

qtConfig(style-mac): SUBDIRS += mac

qtConfig(style-windowsvista): SUBDIRS += windowsvista
64 changes: 64 additions & 0 deletions src/plugins/styles/windowsvista/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** 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 https://www.qt.io/terms-conditions. For further
** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include <QtWidgets/private/qtwidgetsglobal_p.h>
#include <QtWidgets/qstyleplugin.h>
#include "qwindowsvistastyle_p.h"

QT_BEGIN_NAMESPACE

class QWindowsVistaStylePlugin : public QStylePlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QStyleFactoryInterface" FILE "windowsvistastyle.json")
public:
QStyle *create(const QString &key);
};

QStyle *QWindowsVistaStylePlugin::create(const QString &key)
{
if (key.compare(QLatin1String("windowsvista"), Qt::CaseInsensitive) == 0)
return new QWindowsVistaStyle();

return 0;
}

QT_END_NAMESPACE

#include "main.moc"
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
#include <private/qapplication_p.h>
#include <qpa/qplatformnativeinterface.h>

#if QT_CONFIG(style_windowsvista) || defined(QT_PLUGIN)

QT_BEGIN_NAMESPACE

static const int windowsItemFrame = 2; // menu item frame width
Expand Down Expand Up @@ -2487,5 +2485,3 @@ QIcon QWindowsVistaStyle::standardIcon(StandardPixmap standardIcon,
}

QT_END_NAMESPACE

#endif //QT_NO_WINDOWSVISTA
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,10 @@
//

#include <QtWidgets/private/qtwidgetsglobal_p.h>
#include <private/qwindowsxpstyle_p.h>
#include "qwindowsxpstyle_p.h"

QT_BEGIN_NAMESPACE


#if QT_CONFIG(style_windowsvista)

class QWindowsVistaStylePrivate;
class QWindowsVistaStyle : public QWindowsXPStyle
{
Expand Down Expand Up @@ -103,7 +100,6 @@ class QWindowsVistaStyle : public QWindowsXPStyle
Q_DECLARE_PRIVATE(QWindowsVistaStyle)
friend class QStyleFactory;
};
#endif // style_windowsvista

QT_END_NAMESPACE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@

#include <QtWidgets/private/qtwidgetsglobal_p.h>
#include "qwindowsvistastyle_p.h"

#if QT_CONFIG(style_windowsvista)
#include <private/qwindowsxpstyle_p_p.h>
#include "qwindowsxpstyle_p_p.h"
#include <private/qstyleanimation_p.h>
#include <private/qpaintengine_raster_p.h>
#include <qpaintengine.h>
Expand Down Expand Up @@ -179,6 +177,4 @@ class QWindowsVistaStylePrivate : public QWindowsXPStylePrivate

QT_END_NAMESPACE

#endif // style_windowsvista

#endif // QWINDOWSVISTASTYLE_P_P_H
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
#include "qwindowsxpstyle_p.h"
#include "qwindowsxpstyle_p_p.h"

#if QT_CONFIG(style_windowsvista) || defined(QT_PLUGIN)

#include <private/qobject_p.h>
#include <private/qpaintengine_raster_p.h>
#include <private/qapplication_p.h>
Expand Down Expand Up @@ -4223,5 +4221,3 @@ void QWindowsXPStylePrivate::showProperties(XPThemeData &themeData)


QT_END_NAMESPACE

#endif //QT_NO_WINDOWSXP
Loading

0 comments on commit 4f3249f

Please sign in to comment.