diff options
author | Liang Qi <liang.qi@theqtcompany.com> | 2015-12-01 09:27:28 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@theqtcompany.com> | 2015-12-01 15:04:23 +0000 |
commit | adcc76a84d3751e800c763a924bebeeda8e4001f (patch) | |
tree | a2a1c8817818ee0e31359ac6bd21ba15804a4af5 /src/imports/controls/universal | |
parent | 209fea864e823323af3cd43456737e08168d4a9d (diff) |
Universal: move to QQuickProxyTheme way for font settings
Change-Id: I90d91ceaea245dc19d2c0de683cb7c1172e1042e
Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Diffstat (limited to 'src/imports/controls/universal')
20 files changed, 178 insertions, 65 deletions
diff --git a/src/imports/controls/universal/Button.qml b/src/imports/controls/universal/Button.qml index d8e988a7..41198f89 100644 --- a/src/imports/controls/universal/Button.qml +++ b/src/imports/controls/universal/Button.qml @@ -52,9 +52,6 @@ T.Button { rightPadding: 8 bottomPadding: 4 - font.pixelSize: Universal.fontSize - font.family: Universal.fontFamily - //! [label] label: Text { x: control.leftPadding diff --git a/src/imports/controls/universal/CheckBox.qml b/src/imports/controls/universal/CheckBox.qml index 325b9872..52523ffd 100644 --- a/src/imports/controls/universal/CheckBox.qml +++ b/src/imports/controls/universal/CheckBox.qml @@ -53,9 +53,6 @@ T.CheckBox { padding: 6 spacing: 8 - font.pixelSize: Universal.fontSize - font.family: Universal.fontFamily - //! [indicator] indicator: Rectangle { id: normalRectangle diff --git a/src/imports/controls/universal/GroupBox.qml b/src/imports/controls/universal/GroupBox.qml index 7f61f438..cf7b7405 100644 --- a/src/imports/controls/universal/GroupBox.qml +++ b/src/imports/controls/universal/GroupBox.qml @@ -51,10 +51,6 @@ T.GroupBox { padding: 12 topPadding: 12 + (label && title ? label.implicitHeight + spacing : 0) - font.pixelSize: Universal.fontSize - font.family: Universal.fontFamily -// font.weight: Font.DemiBold (TODO: don't want this to inherit...) - //! [contentItem] contentItem: Item { } //! [contentItem] diff --git a/src/imports/controls/universal/ItemDelegate.qml b/src/imports/controls/universal/ItemDelegate.qml index bb1f6672..d9156177 100644 --- a/src/imports/controls/universal/ItemDelegate.qml +++ b/src/imports/controls/universal/ItemDelegate.qml @@ -56,9 +56,6 @@ T.ItemDelegate { rightPadding: 12 bottomPadding: 13 - font.pixelSize: Universal.fontSize - font.family: Universal.fontFamily - //! [indicator] indicator: Image { x: text ? (control.mirrored ? control.width - width - control.rightPadding : control.leftPadding) : control.leftPadding + (control.availableWidth - width) / 2 diff --git a/src/imports/controls/universal/Label.qml b/src/imports/controls/universal/Label.qml index 490a55c0..ee51c8cd 100644 --- a/src/imports/controls/universal/Label.qml +++ b/src/imports/controls/universal/Label.qml @@ -41,9 +41,6 @@ import Qt.labs.controls.universal 1.0 T.Label { id: control - font.pixelSize: Universal.fontSize - font.family: Universal.fontFamily - color: !control.enabled ? Universal.baseLowColor : Universal.baseHighColor linkColor: Universal.accentColor renderType: Text.NativeRendering diff --git a/src/imports/controls/universal/RadioButton.qml b/src/imports/controls/universal/RadioButton.qml index e09f0079..02212c4f 100644 --- a/src/imports/controls/universal/RadioButton.qml +++ b/src/imports/controls/universal/RadioButton.qml @@ -53,9 +53,6 @@ T.RadioButton { padding: 6 spacing: 8 - font.pixelSize: Universal.fontSize - font.family: Universal.fontFamily - //! [indicator] indicator: Rectangle { id: outerEllipse diff --git a/src/imports/controls/universal/SpinBox.qml b/src/imports/controls/universal/SpinBox.qml index 75298895..97ea6c57 100644 --- a/src/imports/controls/universal/SpinBox.qml +++ b/src/imports/controls/universal/SpinBox.qml @@ -58,9 +58,6 @@ T.SpinBox { Universal.theme: activeFocus ? Universal.Light : undefined - font.pixelSize: Universal.fontSize - font.family: Universal.fontFamily - //! [validator] validator: IntValidator { locale: control.locale.name diff --git a/src/imports/controls/universal/Switch.qml b/src/imports/controls/universal/Switch.qml index f8d03333..8b7c73f3 100644 --- a/src/imports/controls/universal/Switch.qml +++ b/src/imports/controls/universal/Switch.qml @@ -53,9 +53,6 @@ T.Switch { padding: 5 spacing: 8 - font.pixelSize: Universal.fontSize - font.family: Universal.fontFamily - //! [indicator] indicator: Rectangle { implicitWidth: 44 diff --git a/src/imports/controls/universal/TabButton.qml b/src/imports/controls/universal/TabButton.qml index a750db22..3b9fc60c 100644 --- a/src/imports/controls/universal/TabButton.qml +++ b/src/imports/controls/universal/TabButton.qml @@ -49,10 +49,6 @@ T.TabButton { padding: 12 // PivotItemMargin - font.pixelSize: 24 // PivotHeaderItemFontSize - font.family: Universal.fontFamily - font.weight: Font.Light - //! [label] label: Text { x: control.leftPadding diff --git a/src/imports/controls/universal/TextArea.qml b/src/imports/controls/universal/TextArea.qml index 0fb88c78..ec319b86 100644 --- a/src/imports/controls/universal/TextArea.qml +++ b/src/imports/controls/universal/TextArea.qml @@ -56,9 +56,6 @@ T.TextArea { Universal.theme: activeFocus ? Universal.Light : undefined - font.pixelSize: Universal.fontSize - font.family: Universal.fontFamily - color: !enabled ? Universal.chromeDisabledLowColor : activeFocus ? Universal.chromeBlackHighColor : Universal.baseHighColor selectionColor: Universal.accentColor diff --git a/src/imports/controls/universal/TextField.qml b/src/imports/controls/universal/TextField.qml index 56601660..b4e217d2 100644 --- a/src/imports/controls/universal/TextField.qml +++ b/src/imports/controls/universal/TextField.qml @@ -56,9 +56,6 @@ T.TextField { Universal.theme: activeFocus ? Universal.Light : undefined - font.pixelSize: Universal.fontSize - font.family: Universal.fontFamily - color: !enabled ? Universal.chromeDisabledLowColor : activeFocus ? Universal.chromeBlackHighColor : Universal.baseHighColor selectionColor: Universal.accentColor diff --git a/src/imports/controls/universal/ToolButton.qml b/src/imports/controls/universal/ToolButton.qml index 369caa90..6488044b 100644 --- a/src/imports/controls/universal/ToolButton.qml +++ b/src/imports/controls/universal/ToolButton.qml @@ -49,9 +49,6 @@ T.ToolButton { padding: 6 - font.pixelSize: Universal.fontSize - font.family: Universal.fontFamily - //! [label] label: Text { x: control.leftPadding diff --git a/src/imports/controls/universal/Tumbler.qml b/src/imports/controls/universal/Tumbler.qml index 3fded6db..d327733c 100644 --- a/src/imports/controls/universal/Tumbler.qml +++ b/src/imports/controls/universal/Tumbler.qml @@ -45,9 +45,6 @@ T.Tumbler { implicitWidth: 60 implicitHeight: 200 - font.pixelSize: Universal.fontSize - font.family: Universal.fontFamily - //! [delegate] delegate: Text { text: modelData diff --git a/src/imports/controls/universal/qquickuniversalstyle.cpp b/src/imports/controls/universal/qquickuniversalstyle.cpp index 7f8d4be9..10c4e812 100644 --- a/src/imports/controls/universal/qquickuniversalstyle.cpp +++ b/src/imports/controls/universal/qquickuniversalstyle.cpp @@ -37,7 +37,6 @@ #include "qquickuniversalstyle_p.h" #include "qquickstyle_p.h" -#include <QtGui/qfont.h> #include <QtGui/qguiapplication.h> #include <QtQuick/private/qquickitem_p.h> @@ -371,20 +370,6 @@ QColor QQuickUniversalStyle::getColor(SystemColor role) const return m_theme == QQuickUniversalStyle::Dark ? qquickuniversal_dark_color(role) : qquickuniversal_light_color(role); } -int QQuickUniversalStyle::fontSize() const -{ - return 15; // ControlContentThemeFontSize -} - -QString QQuickUniversalStyle::fontFamily() const -{ -#ifdef Q_OS_WIN - return QStringLiteral("Segoe UI"); // ContentControlThemeFontFamily -#else - return QGuiApplication::font().family(); -#endif -} - void QQuickUniversalStyle::reparent(QQuickUniversalStyle *style) { if (m_parentStyle != style) { diff --git a/src/imports/controls/universal/qquickuniversalstyle_p.h b/src/imports/controls/universal/qquickuniversalstyle_p.h index 60572252..e8e9eafb 100644 --- a/src/imports/controls/universal/qquickuniversalstyle_p.h +++ b/src/imports/controls/universal/qquickuniversalstyle_p.h @@ -91,9 +91,6 @@ class QQuickUniversalStyle : public QObject, public QQuickItemChangeListener Q_PROPERTY(QColor listLowColor READ listLowColor NOTIFY paletteChanged FINAL) Q_PROPERTY(QColor listMediumColor READ listMediumColor NOTIFY paletteChanged FINAL) - Q_PROPERTY(int fontSize READ fontSize CONSTANT FINAL) - Q_PROPERTY(QString fontFamily READ fontFamily CONSTANT FINAL) - public: explicit QQuickUniversalStyle(QObject *parent = Q_NULLPTR); ~QQuickUniversalStyle(); @@ -193,9 +190,6 @@ public: QColor getColor(SystemColor role) const; - int fontSize() const; - QString fontFamily() const; - Q_SIGNALS: void themeChanged(); void accentChanged(); diff --git a/src/imports/controls/universal/qquickuniversaltheme.cpp b/src/imports/controls/universal/qquickuniversaltheme.cpp new file mode 100644 index 00000000..fd470ba6 --- /dev/null +++ b/src/imports/controls/universal/qquickuniversaltheme.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2015 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 "qquickuniversaltheme_p.h" + +#include <QtGui/qfont.h> + +QT_BEGIN_NAMESPACE + +QQuickUniversalTheme::QQuickUniversalTheme(QPlatformTheme *theme) + : QQuickProxyTheme(theme) +{ + systemFont = QFont(QLatin1Literal("Sege UI")); + systemFont.setPixelSize(15); + mdiSubWindowTitleFont = systemFont; + mdiSubWindowTitleFont.setWeight(QFont::DemiBold); + dockWidgetTitleFont = QFont(QLatin1Literal("Sege UI")); + dockWidgetTitleFont.setPixelSize(24); + dockWidgetTitleFont.setWeight(QFont::Light); +} + +QQuickUniversalTheme::~QQuickUniversalTheme() +{ +} + +const QFont *QQuickUniversalTheme::font(QPlatformTheme::Font type) const +{ + switch (type) { + case QPlatformTheme::MdiSubWindowTitleFont: + return &mdiSubWindowTitleFont; + case QPlatformTheme::DockWidgetTitleFont: + return &dockWidgetTitleFont; + default: + return &systemFont; + } +} + +QT_END_NAMESPACE diff --git a/src/imports/controls/universal/qquickuniversaltheme_p.h b/src/imports/controls/universal/qquickuniversaltheme_p.h new file mode 100644 index 00000000..c014ead2 --- /dev/null +++ b/src/imports/controls/universal/qquickuniversaltheme_p.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2015 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 QQUICKUNIVERSALTHEME_H +#define QQUICKUNIVERSALTHEME_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 <QtGui/qpa/qplatformtheme.h> +#include <QtGui/qfont.h> +#include <QtLabsControls/private/qquickproxytheme_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickUniversalTheme : public QQuickProxyTheme +{ +public: + QQuickUniversalTheme(QPlatformTheme *theme); + + ~QQuickUniversalTheme(); + + const QFont *font(Font type = SystemFont) const Q_DECL_OVERRIDE; + +private: + QFont systemFont; + QFont mdiSubWindowTitleFont; // QQuickGroupBox + QFont dockWidgetTitleFont; // QQuickTabButton +}; + +QT_END_NAMESPACE + +#endif // QQUICKUNIVERSALTHEME_H diff --git a/src/imports/controls/universal/qtlabsuniversalstyleplugin.cpp b/src/imports/controls/universal/qtlabsuniversalstyleplugin.cpp index 9b760250..e2d52f2f 100644 --- a/src/imports/controls/universal/qtlabsuniversalstyleplugin.cpp +++ b/src/imports/controls/universal/qtlabsuniversalstyleplugin.cpp @@ -39,6 +39,10 @@ #include "qquickuniversalprogressring_p.h" #include "qquickuniversalprogressstrip_p.h" #include "qquickuniversalstyle_p.h" +#include "qquickuniversaltheme_p.h" + +#include <QtGui/private/qguiapplication_p.h> +#include <QtLabsControls/private/qquickstyleselector_p.h> static inline void initResources() { @@ -53,10 +57,23 @@ class QtLabsUniversalStylePlugin: public QQmlExtensionPlugin Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface/1.0") public: + ~QtLabsUniversalStylePlugin(); void registerTypes(const char *uri) Q_DECL_OVERRIDE; void initializeEngine(QQmlEngine *engine, const char *uri) Q_DECL_OVERRIDE; + +private: + QQuickProxyTheme *theme; }; +QtLabsUniversalStylePlugin::~QtLabsUniversalStylePlugin() +{ + if (theme) { + QPlatformTheme *old = theme->theme(); + QGuiApplicationPrivate::platform_theme = old; + delete theme; + } +} + void QtLabsUniversalStylePlugin::registerTypes(const char *uri) { qmlRegisterUncreatableType<QQuickUniversalStyle>(uri, 1, 0, "Universal", tr("Universal is an attached property")); @@ -64,6 +81,17 @@ void QtLabsUniversalStylePlugin::registerTypes(const char *uri) void QtLabsUniversalStylePlugin::initializeEngine(QQmlEngine *engine, const char *uri) { + QQuickStyleSelector *selector = QQuickStyleSelector::instance(this); + if (selector && selector->style() == QStringLiteral("universal")) { + if (QFont(QStringLiteral("Segoe UI")).family() == QStringLiteral("Segoe UI")) { + QPlatformTheme *old = QGuiApplicationPrivate::platform_theme; + if (old) { + QQuickProxyTheme *theme = new QQuickUniversalTheme(old); + QGuiApplicationPrivate::platform_theme = theme; + } + } + } + initResources(); engine->addImageProvider(QStringLiteral("universal"), new QQuickUniversalImageProvider); diff --git a/src/imports/controls/universal/universal.pri b/src/imports/controls/universal/universal.pri index 16e52d17..4865e499 100644 --- a/src/imports/controls/universal/universal.pri +++ b/src/imports/controls/universal/universal.pri @@ -30,10 +30,12 @@ HEADERS += \ $$PWD/qquickuniversalimageprovider_p.h \ $$PWD/qquickuniversalprogressring_p.h \ $$PWD/qquickuniversalprogressstrip_p.h \ - $$PWD/qquickuniversalstyle_p.h + $$PWD/qquickuniversalstyle_p.h \ + $$PWD/qquickuniversaltheme_p.h SOURCES += \ $$PWD/qquickuniversalimageprovider.cpp \ $$PWD/qquickuniversalprogressring.cpp \ $$PWD/qquickuniversalprogressstrip.cpp \ - $$PWD/qquickuniversalstyle.cpp + $$PWD/qquickuniversalstyle.cpp \ + $$PWD/qquickuniversaltheme.cpp diff --git a/src/imports/controls/universal/universal.pro b/src/imports/controls/universal/universal.pro index 99794dce..4e96256b 100644 --- a/src/imports/controls/universal/universal.pro +++ b/src/imports/controls/universal/universal.pro @@ -3,7 +3,7 @@ TARGETPATH = Qt/labs/controls/universal IMPORT_VERSION = 1.0 QT += qml quick -QT_PRIVATE += core-private gui-private qml-private quick-private +QT_PRIVATE += core-private gui-private qml-private quick-private labscontrols-private DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII |