From 7b971c28e6098b629b8e9e3e38a9465a3f1bd459 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Wed, 8 Apr 2015 18:16:13 +0200 Subject: Rename Style to Theme Change-Id: I0186cd36f0b42ca015b70a09af27f8a3517d4a60 Reviewed-by: Jari-Pekka Nurmi --- .gitignore | 2 +- examples/quick/calendar/main.qml | 12 +- examples/quick/controls/controls.pro | 2 +- examples/quick/controls/drawer/main.qml | 16 +- examples/quick/controls/mirroring/main.qml | 10 +- examples/quick/controls/styles/main.cpp | 50 -- examples/quick/controls/styles/main.qml | 188 ------ examples/quick/controls/styles/styles.pro | 12 - examples/quick/controls/styles/styles.qrc | 5 - examples/quick/controls/tabs/main.qml | 62 +- examples/quick/controls/theme/main.cpp | 50 ++ examples/quick/controls/theme/main.qml | 188 ++++++ examples/quick/controls/theme/theme.pro | 12 + examples/quick/controls/theme/theme.qrc | 5 + src/imports/calendar/CalendarView.qml | 4 +- src/imports/calendar/DayOfWeekRow.qml | 6 +- src/imports/calendar/WeekNumberColumn.qml | 6 +- src/imports/controls/ApplicationWindow.qml | 2 +- src/imports/controls/BusyIndicator.qml | 2 +- src/imports/controls/Button.qml | 16 +- src/imports/controls/CheckBox.qml | 28 +- src/imports/controls/Frame.qml | 6 +- src/imports/controls/GroupBox.qml | 16 +- src/imports/controls/Label.qml | 4 +- src/imports/controls/PageIndicator.qml | 6 +- src/imports/controls/ProgressBar.qml | 10 +- src/imports/controls/RadioButton.qml | 26 +- src/imports/controls/ScrollBar.qml | 4 +- src/imports/controls/ScrollIndicator.qml | 4 +- src/imports/controls/Slider.qml | 22 +- src/imports/controls/Switch.qml | 26 +- src/imports/controls/TabBar.qml | 8 +- src/imports/controls/TabButton.qml | 8 +- src/imports/controls/TextArea.qml | 10 +- src/imports/controls/TextField.qml | 18 +- src/imports/controls/ToggleButton.qml | 28 +- src/imports/controls/ToolBar.qml | 2 +- src/imports/controls/ToolButton.qml | 10 +- src/imports/controls/controls.pro | 10 +- src/imports/controls/qquickstyle.cpp | 826 ------------------------ src/imports/controls/qquickstyle_p.h | 168 ----- src/imports/controls/qquickstyledata.cpp | 101 --- src/imports/controls/qquickstyledata_p.h | 128 ---- src/imports/controls/qquicktheme.cpp | 826 ++++++++++++++++++++++++ src/imports/controls/qquicktheme_p.h | 168 +++++ src/imports/controls/qquickthemedata.cpp | 101 +++ src/imports/controls/qquickthemedata_p.h | 128 ++++ src/imports/controls/qtquickcontrols2plugin.cpp | 4 +- src/imports/controls/qtquickcontrols2plugin.qrc | 2 +- src/imports/controls/style.json | 16 - src/imports/controls/theme.json | 16 + src/imports/extras/Drawer.qml | 4 +- tests/auto/controls/data/tst_style.qml | 304 --------- tests/auto/controls/data/tst_theme.qml | 304 +++++++++ 54 files changed, 1996 insertions(+), 1996 deletions(-) delete mode 100644 examples/quick/controls/styles/main.cpp delete mode 100644 examples/quick/controls/styles/main.qml delete mode 100644 examples/quick/controls/styles/styles.pro delete mode 100644 examples/quick/controls/styles/styles.qrc create mode 100644 examples/quick/controls/theme/main.cpp create mode 100644 examples/quick/controls/theme/main.qml create mode 100644 examples/quick/controls/theme/theme.pro create mode 100644 examples/quick/controls/theme/theme.qrc delete mode 100644 src/imports/controls/qquickstyle.cpp delete mode 100644 src/imports/controls/qquickstyle_p.h delete mode 100644 src/imports/controls/qquickstyledata.cpp delete mode 100644 src/imports/controls/qquickstyledata_p.h create mode 100644 src/imports/controls/qquicktheme.cpp create mode 100644 src/imports/controls/qquicktheme_p.h create mode 100644 src/imports/controls/qquickthemedata.cpp create mode 100644 src/imports/controls/qquickthemedata_p.h delete mode 100644 src/imports/controls/style.json create mode 100644 src/imports/controls/theme.json delete mode 100644 tests/auto/controls/data/tst_style.qml create mode 100644 tests/auto/controls/data/tst_theme.qml diff --git a/.gitignore b/.gitignore index d14ff93e..c18716e4 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ /examples/quick/calendar/calendar /examples/quick/controls/drawer/drawer /examples/quick/controls/mirroring/mirroring -/examples/quick/controls/styles/styles +/examples/quick/controls/theme/theme /examples/quick/controls/tabs/tabs /tests/auto/controls/tst_controls diff --git a/examples/quick/calendar/main.qml b/examples/quick/calendar/main.qml index 645b05dd..82d71ecb 100644 --- a/examples/quick/calendar/main.qml +++ b/examples/quick/calendar/main.qml @@ -99,7 +99,7 @@ ApplicationWindow { id: title x: delegate.contentItem.x width: delegate.contentItem.width - spacing: Style.spacing + spacing: Theme.spacing Text { width: parent.width height: implicitHeight * 2 @@ -129,7 +129,7 @@ ApplicationWindow { width: delegate.contentItem.width / 7 height: delegate.contentItem.height / 6 opacity: model.month === delegate.month ? 1 : 0 - color: model.today ? Style.accentColor : Style.textColor + color: model.today ? Theme.accentColor : Theme.textColor Rectangle { z: -1 anchors.centerIn: parent @@ -137,8 +137,8 @@ ApplicationWindow { height: width radius: width / 2 opacity: 0.5 - color: pressed ? Style.pressColor : "transparent" - border.color: eventModel.eventsForDate(model.date).length > 0 ? Style.accentColor : "transparent" + color: pressed ? Theme.pressColor : "transparent" + border.color: eventModel.eventsForDate(model.date).length > 0 ? Theme.accentColor : "transparent" } } } @@ -146,7 +146,7 @@ ApplicationWindow { z: -1 parent: calendar anchors.fill: parent - border.color: Style.frameColor + border.color: Theme.frameColor } } @@ -185,7 +185,7 @@ ApplicationWindow { Rectangle { width: (parent.width > parent.height ? (parent.width - parent.spacing) * 0.4 : parent.width) height: (parent.height > parent.width ? (parent.height - parent.spacing) * 0.4 : parent.height) - border.color: Style.frameColor + border.color: Theme.frameColor ListView { id: eventsListView diff --git a/examples/quick/controls/controls.pro b/examples/quick/controls/controls.pro index b39b9aea..37087c42 100644 --- a/examples/quick/controls/controls.pro +++ b/examples/quick/controls/controls.pro @@ -2,5 +2,5 @@ TEMPLATE = subdirs SUBDIRS += \ drawer \ mirroring \ - styles \ + theme \ tabs diff --git a/examples/quick/controls/drawer/main.qml b/examples/quick/controls/drawer/main.qml index 8ab67829..55385a6a 100644 --- a/examples/quick/controls/drawer/main.qml +++ b/examples/quick/controls/drawer/main.qml @@ -53,7 +53,7 @@ ApplicationWindow { id: content anchors.fill: parent anchors.margins: -1 - border.color: Style.frameColor + border.color: Theme.frameColor Image { width: window.width / 2 @@ -98,13 +98,13 @@ ApplicationWindow { model: VisualItemModel { Label { text: "Settings" - x: Style.padding - width: parent.width - Style.padding * 2 + x: Theme.padding + width: parent.width - Theme.padding * 2 lineHeight: 2.0 - color: Style.accentColor + color: Theme.accentColor verticalAlignment: Text.AlignVCenter } - Rectangle { width: parent.width; height: 1; color: Style.frameColor } + Rectangle { width: parent.width; height: 1; color: Theme.frameColor } Switch { id: dim text: "Dim" @@ -113,7 +113,7 @@ ApplicationWindow { layoutDirection: Qt.RightToLeft enabled: effect.current != uncover } - Rectangle { width: parent.width; height: 1; color: Style.frameColor } + Rectangle { width: parent.width; height: 1; color: Theme.frameColor } RadioButton { id: overlay text: "Overlay" @@ -136,14 +136,14 @@ ApplicationWindow { Exclusive.group: effect layoutDirection: Qt.RightToLeft } - Rectangle { width: parent.width; height: 1; color: Style.frameColor } + Rectangle { width: parent.width; height: 1; color: Theme.frameColor } } Rectangle { z: -1 anchors.fill: parent anchors.topMargin: -1 anchors.bottomMargin: -1 - border.color: Style.frameColor + border.color: Theme.frameColor } transform: Translate { diff --git a/examples/quick/controls/mirroring/main.qml b/examples/quick/controls/mirroring/main.qml index 1bdf8cb2..3deb3cae 100644 --- a/examples/quick/controls/mirroring/main.qml +++ b/examples/quick/controls/mirroring/main.qml @@ -67,7 +67,7 @@ ApplicationWindow { Label { id: label text: "Beyond the essentials." - color: Style.accentColor + color: Theme.accentColor anchors.fill: parent anchors.margins: 48 horizontalAlignment: Text.AlignHCenter @@ -89,7 +89,7 @@ ApplicationWindow { width: parent.width height: 1 anchors.bottom: parent.bottom - color: Style.frameColor + color: Theme.frameColor } } @@ -157,7 +157,7 @@ ApplicationWindow { width: flow.width Row { width: parent.width - spacing: Style.spacing + spacing: Theme.spacing readonly property real availableWidth: (flow.width - 12) / 2 readonly property real contentWidth: okButton.implicitWidth + cancelButton.implicitWidth + 12 readonly property real buttonWidth: contentWidth > availableWidth ? (width / 2 - spacing) : (width / 2 - 2 * spacing) / 2 @@ -196,7 +196,7 @@ ApplicationWindow { width: flow.width Column { width: parent.width - spacing: Style.spacing + spacing: Theme.spacing ProgressBar { width: parent.width indeterminate: true @@ -213,7 +213,7 @@ ApplicationWindow { width: flow.width Column { width: parent.width - spacing: Style.spacing + spacing: Theme.spacing Slider { id: slider value: 0.4 diff --git a/examples/quick/controls/styles/main.cpp b/examples/quick/controls/styles/main.cpp deleted file mode 100644 index 92844360..00000000 --- a/examples/quick/controls/styles/main.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include - -int main(int argc, char *argv[]) -{ - QGuiApplication app(argc, argv); - QQmlApplicationEngine engine; - engine.load(QUrl("qrc:/main.qml")); - return app.exec(); -} diff --git a/examples/quick/controls/styles/main.qml b/examples/quick/controls/styles/main.qml deleted file mode 100644 index c614320d..00000000 --- a/examples/quick/controls/styles/main.qml +++ /dev/null @@ -1,188 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.6 -import QtQuick.Controls 2.0 - -ApplicationWindow { - id: window - width: 360 - height: 520 - visible: true - title: "Qt Quick Controls - Styles Example" - - header: ToolBar { - ToolButton { - label: Text { - text: "\u25C0" - color: enabled ? Style.accentColor : Style.frameColor - anchors.centerIn: parent - } - enabled: stackview.depth > 1 - onClicked: stackview.pop() - } - } - - StackView { - id: stackview - anchors.fill: parent - initialItem: pageComponent - } - - Component { - id: pageComponent - Control { - id: page - Style.roundness: roundedToggle.checked ? 3 : 0 - Style.accentColor: Qt.hsla(colorSlider.position, 0.5, 0.5, 1.0) - Style.backgroundColor: darkButton.checked ? "#444" : "#fff" - Style.frameColor: darkButton.checked ? "#666" : "#ccc" - Style.textColor: darkButton.checked ? "#eee" : "#111" - Style.pressColor: darkButton.checked ? "#33ffffff" : "#33333333" - Style.baseColor: darkButton.checked ? "#444" : "#eee" - background: Rectangle { - color: Style.backgroundColor - } - Flickable { - anchors.fill: parent - contentHeight: column.height + 48 - - Column { - id: column - - x: (window.width - width) / 2 - y: 24 - width: window.width / 2 - spacing: 12 - - Label { - text: "Code less. Create more." - color: Style.accentColor - width: parent.width - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - wrapMode: Text.WordWrap - font.pointSize: 26 - } - - Item { width: 1; height: 48 } - - Rectangle { - width: parent.width - height: 1 - color: Style.frameColor - } - - Column { - spacing: 6 - width: parent.width - Label { - text: "Accent color" - color: Style.textColor - } - Slider { - id: colorSlider - width: parent.width - value: 0.275 - } - } - - Rectangle { - width: parent.width - height: 1 - color: Style.frameColor - } - - ExclusiveGroup { - id: styleGroup - } - - Column { - width: parent.width - spacing: 6 - RadioButton { - id: lightButton - text: "Light" - width: parent.width - checked: true - layoutDirection: Qt.RightToLeft - Exclusive.group: styleGroup - } - RadioButton { - id: darkButton - text: "Dark" - width: parent.width - layoutDirection: Qt.RightToLeft - Exclusive.group: styleGroup - } - } - - Rectangle { - width: parent.width - height: 1 - color: Style.frameColor - } - - ToggleButton { - id: roundedToggle - width: parent.width - text: "Rounded corners" - layoutDirection: Qt.RightToLeft - checked: true - } - - Rectangle { - width: parent.width - height: 1 - color: Style.frameColor - } - - Button { - text: "Push" - anchors.right: parent.right - onClicked: stackview.push(pageComponent) - } - } - - AbstractScrollIndicator.vertical: ScrollIndicator { } - } - } - } -} diff --git a/examples/quick/controls/styles/styles.pro b/examples/quick/controls/styles/styles.pro deleted file mode 100644 index f8fdec46..00000000 --- a/examples/quick/controls/styles/styles.pro +++ /dev/null @@ -1,12 +0,0 @@ -TEMPLATE = app -TARGET = styles -QT += quick - -SOURCES += \ - main.cpp - -OTHER_FILES += \ - main.qml - -RESOURCES += \ - styles.qrc diff --git a/examples/quick/controls/styles/styles.qrc b/examples/quick/controls/styles/styles.qrc deleted file mode 100644 index 5f6483ac..00000000 --- a/examples/quick/controls/styles/styles.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - main.qml - - diff --git a/examples/quick/controls/tabs/main.qml b/examples/quick/controls/tabs/main.qml index 38db6e87..5e68d79b 100644 --- a/examples/quick/controls/tabs/main.qml +++ b/examples/quick/controls/tabs/main.qml @@ -55,7 +55,7 @@ ApplicationWindow { spacing: 1 anchors.fill: parent - background: Rectangle { color: Style.frameColor } + background: Rectangle { color: Theme.frameColor } Rectangle { Tab.title: "Home" @@ -72,7 +72,7 @@ ApplicationWindow { Label { text: "Things just got better" - color: Style.accentColor + color: Theme.accentColor anchors.margins: 40 anchors.top: logo.bottom anchors.left: parent.left @@ -110,46 +110,46 @@ ApplicationWindow { Column { id: feedItem width: parent.width - spacing: Style.spacing + spacing: Theme.spacing Rectangle { width: parent.width height: 1 - color: Style.frameColor + color: Theme.frameColor visible: index == 0 } - Item { width: 1; height: Style.spacing } + Item { width: 1; height: Theme.spacing } Label { text: model.title - x: Style.padding - width: parent.width - 2 * Style.padding + x: Theme.padding + width: parent.width - 2 * Theme.padding elide: Text.ElideRight - color: Style.accentColor + color: Theme.accentColor font.pointSize: 20 lineHeight: 0.75 } Label { text: model.description textFormat: Text.StyledText - x: Style.padding - width: parent.width - 2 * Style.padding + x: Theme.padding + width: parent.width - 2 * Theme.padding wrapMode: Text.WordWrap } RowLayout { - x: Style.padding - width: parent.width - 2 * Style.padding - spacing: Style.spacing + x: Theme.padding + width: parent.width - 2 * Theme.padding + spacing: Theme.spacing Label { text: model.creator height: parent.height verticalAlignment: Text.AlignVCenter - color: Style.focusColor + color: Theme.focusColor font.pointSize: 8 } Label { text: model.pubDate height: parent.height verticalAlignment: Text.AlignVCenter - opacity: Style.disabledOpacity + opacity: Theme.disabledOpacity font.pointSize: 8 } Item { Layout.fillWidth: true } @@ -161,7 +161,7 @@ ApplicationWindow { Rectangle { width: parent.width height: 1 - color: Style.frameColor + color: Theme.frameColor } } } @@ -200,47 +200,47 @@ ApplicationWindow { Column { id: commentItem width: parent.width - spacing: Style.spacing + spacing: Theme.spacing Rectangle { width: parent.width height: 1 - color: Style.frameColor + color: Theme.frameColor visible: index == 0 } - Item { width: 1; height: Style.spacing } + Item { width: 1; height: Theme.spacing } Label { text: model.title - x: Style.padding - width: parent.width - 2 * Style.padding + x: Theme.padding + width: parent.width - 2 * Theme.padding elide: Text.ElideRight - color: Style.accentColor + color: Theme.accentColor font.pointSize: 14 lineHeight: 0.75 } - Item { width: 1; height: Style.spacing } + Item { width: 1; height: Theme.spacing } Label { text: model.description textFormat: Text.StyledText - x: Style.padding - width: parent.width - 2 * Style.padding + x: Theme.padding + width: parent.width - 2 * Theme.padding wrapMode: Text.WordWrap } RowLayout { - x: Style.padding - width: parent.width - 2 * Style.padding - spacing: Style.spacing + x: Theme.padding + width: parent.width - 2 * Theme.padding + spacing: Theme.spacing Label { text: model.creator height: parent.height verticalAlignment: Text.AlignVCenter - color: Style.focusColor + color: Theme.focusColor font.pointSize: 8 } Label { text: model.pubDate height: parent.height verticalAlignment: Text.AlignVCenter - opacity: Style.disabledOpacity + opacity: Theme.disabledOpacity font.pointSize: 8 } Item { Layout.fillWidth: true } @@ -252,7 +252,7 @@ ApplicationWindow { Rectangle { width: parent.width height: 1 - color: Style.frameColor + color: Theme.frameColor } } } diff --git a/examples/quick/controls/theme/main.cpp b/examples/quick/controls/theme/main.cpp new file mode 100644 index 00000000..92844360 --- /dev/null +++ b/examples/quick/controls/theme/main.cpp @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + QQmlApplicationEngine engine; + engine.load(QUrl("qrc:/main.qml")); + return app.exec(); +} diff --git a/examples/quick/controls/theme/main.qml b/examples/quick/controls/theme/main.qml new file mode 100644 index 00000000..58f5b5f9 --- /dev/null +++ b/examples/quick/controls/theme/main.qml @@ -0,0 +1,188 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.6 +import QtQuick.Controls 2.0 + +ApplicationWindow { + id: window + width: 360 + height: 520 + visible: true + title: "Qt Quick Controls - Theme Example" + + header: ToolBar { + ToolButton { + label: Text { + text: "\u25C0" + color: enabled ? Theme.accentColor : Theme.frameColor + anchors.centerIn: parent + } + enabled: stackview.depth > 1 + onClicked: stackview.pop() + } + } + + StackView { + id: stackview + anchors.fill: parent + initialItem: pageComponent + } + + Component { + id: pageComponent + Control { + id: page + Theme.roundness: roundedToggle.checked ? 3 : 0 + Theme.accentColor: Qt.hsla(colorSlider.position, 0.5, 0.5, 1.0) + Theme.backgroundColor: darkButton.checked ? "#444" : "#fff" + Theme.frameColor: darkButton.checked ? "#666" : "#ccc" + Theme.textColor: darkButton.checked ? "#eee" : "#111" + Theme.pressColor: darkButton.checked ? "#33ffffff" : "#33333333" + Theme.baseColor: darkButton.checked ? "#444" : "#eee" + background: Rectangle { + color: Theme.backgroundColor + } + Flickable { + anchors.fill: parent + contentHeight: column.height + 48 + + Column { + id: column + + x: (window.width - width) / 2 + y: 24 + width: window.width / 2 + spacing: 12 + + Label { + text: "Code less. Create more." + color: Theme.accentColor + width: parent.width + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + wrapMode: Text.WordWrap + font.pointSize: 26 + } + + Item { width: 1; height: 48 } + + Rectangle { + width: parent.width + height: 1 + color: Theme.frameColor + } + + Column { + spacing: 6 + width: parent.width + Label { + text: "Accent color" + color: Theme.textColor + } + Slider { + id: colorSlider + width: parent.width + value: 0.275 + } + } + + Rectangle { + width: parent.width + height: 1 + color: Theme.frameColor + } + + ExclusiveGroup { + id: themeGroup + } + + Column { + width: parent.width + spacing: 6 + RadioButton { + id: lightButton + text: "Light" + width: parent.width + checked: true + layoutDirection: Qt.RightToLeft + Exclusive.group: themeGroup + } + RadioButton { + id: darkButton + text: "Dark" + width: parent.width + layoutDirection: Qt.RightToLeft + Exclusive.group: themeGroup + } + } + + Rectangle { + width: parent.width + height: 1 + color: Theme.frameColor + } + + ToggleButton { + id: roundedToggle + width: parent.width + text: "Rounded corners" + layoutDirection: Qt.RightToLeft + checked: true + } + + Rectangle { + width: parent.width + height: 1 + color: Theme.frameColor + } + + Button { + text: "Push" + anchors.right: parent.right + onClicked: stackview.push(pageComponent) + } + } + + AbstractScrollIndicator.vertical: ScrollIndicator { } + } + } + } +} diff --git a/examples/quick/controls/theme/theme.pro b/examples/quick/controls/theme/theme.pro new file mode 100644 index 00000000..0208bd4f --- /dev/null +++ b/examples/quick/controls/theme/theme.pro @@ -0,0 +1,12 @@ +TEMPLATE = app +TARGET = theme +QT += quick + +SOURCES += \ + main.cpp + +OTHER_FILES += \ + main.qml + +RESOURCES += \ + theme.qrc diff --git a/examples/quick/controls/theme/theme.qrc b/examples/quick/controls/theme/theme.qrc new file mode 100644 index 00000000..5f6483ac --- /dev/null +++ b/examples/quick/controls/theme/theme.qrc @@ -0,0 +1,5 @@ + + + main.qml + + diff --git a/src/imports/calendar/CalendarView.qml b/src/imports/calendar/CalendarView.qml index 541c7d6b..f70f063b 100644 --- a/src/imports/calendar/CalendarView.qml +++ b/src/imports/calendar/CalendarView.qml @@ -45,9 +45,9 @@ AbstractCalendarView { width: grid.width ? grid.width / 7 : implicitWidth height: grid.height ? grid.height / 6 : implicitHeight opacity: model.month === control.month ? 1 : 0 - color: model.today ? control.Style.accentColor : control.Style.textColor + color: model.today ? control.Theme.accentColor : control.Theme.textColor text: model.day - padding: control.Style.padding + padding: control.Theme.padding } contentWidth: grid.implicitWidth diff --git a/src/imports/calendar/DayOfWeekRow.qml b/src/imports/calendar/DayOfWeekRow.qml index ef59ec5f..b6404c05 100644 --- a/src/imports/calendar/DayOfWeekRow.qml +++ b/src/imports/calendar/DayOfWeekRow.qml @@ -44,7 +44,7 @@ AbstractDayOfWeekRow { property Component delegate: Text { text: model.shortName font.bold: true - color: control.Style.textColor + color: control.Theme.textColor width: row.width ? row.width / 7 : implicitWidth height: row.height ? row.height : implicitHeight horizontalAlignment: Text.AlignHCenter @@ -57,8 +57,8 @@ AbstractDayOfWeekRow { implicitWidth: Math.max(background ? background.implicitWidth : 0, contentWidth + leftPadding + rightPadding) implicitHeight: Math.max(background ? background.implicitHeight : 0, contentHeight + topPadding + bottomPadding) - topPadding: Style.padding - bottomPadding: Style.padding + topPadding: Theme.padding + bottomPadding: Theme.padding contentItem: Row { id: row diff --git a/src/imports/calendar/WeekNumberColumn.qml b/src/imports/calendar/WeekNumberColumn.qml index 732a914a..3d3092fe 100644 --- a/src/imports/calendar/WeekNumberColumn.qml +++ b/src/imports/calendar/WeekNumberColumn.qml @@ -44,7 +44,7 @@ AbstractWeekNumberColumn { property Component delegate: Text { text: model.weekNumber font.bold: true - color: control.Style.textColor + color: control.Theme.textColor width: column.width ? column.width : implicitWidth height: column.height ? column.height / 6 : implicitHeight horizontalAlignment: Text.AlignHCenter @@ -57,8 +57,8 @@ AbstractWeekNumberColumn { implicitWidth: Math.max(background ? background.implicitWidth : 0, contentWidth + leftPadding + rightPadding) implicitHeight: Math.max(background ? background.implicitHeight : 0, contentHeight + topPadding + bottomPadding) - leftPadding: Style.padding - rightPadding: Style.padding + leftPadding: Theme.padding + rightPadding: Theme.padding contentItem: Column { id: column diff --git a/src/imports/controls/ApplicationWindow.qml b/src/imports/controls/ApplicationWindow.qml index 551598c6..bb937e50 100644 --- a/src/imports/controls/ApplicationWindow.qml +++ b/src/imports/controls/ApplicationWindow.qml @@ -41,7 +41,7 @@ import QtQuick.Controls 2.0 AbstractApplicationWindow { id: window - color: Style.backgroundColor + color: Theme.backgroundColor flags: Qt.Window | Qt.WindowFullscreenButtonHint contentWidth: contentItem.children.length === 1 ? contentItem.children[0].implicitWidth : 0 diff --git a/src/imports/controls/BusyIndicator.qml b/src/imports/controls/BusyIndicator.qml index dcaa0ff7..cf92809f 100644 --- a/src/imports/controls/BusyIndicator.qml +++ b/src/imports/controls/BusyIndicator.qml @@ -45,7 +45,7 @@ AbstractBusyIndicator { Accessible.role: Accessible.Indicator - padding: Style.padding + padding: Theme.padding indicator: Item { id: delegate diff --git a/src/imports/controls/Button.qml b/src/imports/controls/Button.qml index e78aa731..0dd9b6ee 100644 --- a/src/imports/controls/Button.qml +++ b/src/imports/controls/Button.qml @@ -49,7 +49,7 @@ AbstractButton { Accessible.pressed: pressed Accessible.role: Accessible.Button - padding: Style.padding + padding: Theme.padding label: Text { x: control.leftPadding @@ -58,9 +58,9 @@ AbstractButton { height: parent.height - control.topPadding - control.bottomPadding text: control.text - color: control.Style.selectedTextColor + color: control.Theme.selectedTextColor elide: Text.ElideRight - opacity: enabled ? 1.0 : control.Style.disabledOpacity + opacity: enabled ? 1.0 : control.Theme.disabledOpacity horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter } @@ -69,10 +69,10 @@ AbstractButton { implicitWidth: 26 implicitHeight: 26 - radius: control.Style.roundness - opacity: control.enabled ? 1.0 : control.Style.disabledOpacity - color: Qt.tint(Qt.tint(control.Style.accentColor, - control.activeFocus ? control.Style.focusColor : "transparent"), - control.pressed ? control.Style.pressColor : "transparent") + radius: control.Theme.roundness + opacity: control.enabled ? 1.0 : control.Theme.disabledOpacity + color: Qt.tint(Qt.tint(control.Theme.accentColor, + control.activeFocus ? control.Theme.focusColor : "transparent"), + control.pressed ? control.Theme.pressColor : "transparent") } } diff --git a/src/imports/controls/CheckBox.qml b/src/imports/controls/CheckBox.qml index ed1eea0f..0a8facf1 100644 --- a/src/imports/controls/CheckBox.qml +++ b/src/imports/controls/CheckBox.qml @@ -43,7 +43,7 @@ AbstractCheckBox { implicitWidth: Math.max(background ? background.implicitWidth : 0, (label ? label.implicitWidth : 0) + (indicator ? indicator.implicitWidth : 0) + - (label && indicator ? Style.spacing : 0) + leftPadding + rightPadding) + (label && indicator ? Theme.spacing : 0) + leftPadding + rightPadding) implicitHeight: Math.max(background ? background.implicitHeight : 0, Math.max(label ? label.implicitHeight : 0, indicator ? indicator.implicitHeight : 0) + topPadding + bottomPadding) @@ -53,7 +53,7 @@ AbstractCheckBox { Accessible.pressed: pressed Accessible.role: Accessible.CheckBox - padding: Style.padding + padding: Theme.padding indicator: Rectangle { readonly property bool mirror: control.effectiveLayoutDirection == Qt.RightToLeft @@ -63,38 +63,38 @@ AbstractCheckBox { x: text ? (mirror ? parent.width - width - control.rightPadding : control.leftPadding) : (parent.width - width) / 2 y: (parent.height - height) / 2 - radius: control.Style.roundness + radius: control.Theme.roundness border.width: control.activeFocus ? 2 : 1 - border.color: control.activeFocus ? control.Style.focusColor : control.Style.frameColor - opacity: enabled ? 1.0 : control.Style.disabledOpacity - color: control.Style.backgroundColor + border.color: control.activeFocus ? control.Theme.focusColor : control.Theme.frameColor + opacity: enabled ? 1.0 : control.Theme.disabledOpacity + color: control.Theme.backgroundColor Rectangle { x: (parent.width - width) / 2 y: (parent.height - height) / 2 width: 12 height: 12 - color: Qt.tint(Qt.tint(control.checked ? control.Style.accentColor : control.Style.baseColor, - control.checked && control.activeFocus ? control.Style.focusColor : "transparent"), - control.pressed ? control.Style.pressColor : "transparent") + color: Qt.tint(Qt.tint(control.checked ? control.Theme.accentColor : control.Theme.baseColor, + control.checked && control.activeFocus ? control.Theme.focusColor : "transparent"), + control.pressed ? control.Theme.pressColor : "transparent") border.width: control.checked || control.pressed ? 0 : 1 - border.color: control.Style.frameColor + border.color: control.Theme.frameColor } } label: Text { readonly property bool mirror: control.effectiveLayoutDirection == Qt.RightToLeft - x: mirror ? control.leftPadding : (indicator.x + indicator.width + control.Style.spacing) + x: mirror ? control.leftPadding : (indicator.x + indicator.width + control.Theme.spacing) y: control.topPadding - width: parent.width - indicator.width - control.Style.spacing - control.leftPadding - control.rightPadding + width: parent.width - indicator.width - control.Theme.spacing - control.leftPadding - control.rightPadding height: parent.height - control.topPadding - control.bottomPadding text: control.text - color: control.Style.textColor + color: control.Theme.textColor elide: Text.ElideRight visible: control.text - opacity: enabled ? 1.0 : control.Style.disabledOpacity + opacity: enabled ? 1.0 : control.Theme.disabledOpacity horizontalAlignment: Text.AlignLeft verticalAlignment: Text.AlignVCenter } diff --git a/src/imports/controls/Frame.qml b/src/imports/controls/Frame.qml index 8c73f6ba..dc773e95 100644 --- a/src/imports/controls/Frame.qml +++ b/src/imports/controls/Frame.qml @@ -50,7 +50,7 @@ AbstractFrame { contentWidth: content.children.length === 1 ? content.children[0].implicitWidth : 0 contentHeight: content.children.length === 1 ? content.children[0].implicitHeight : 0 - padding: Style.padding + padding: Theme.padding contentItem: Item { id: content @@ -62,7 +62,7 @@ AbstractFrame { background: Rectangle { color: "transparent" - radius: control.Style.roundness - border.color: control.Style.frameColor + radius: control.Theme.roundness + border.color: control.Theme.frameColor } } diff --git a/src/imports/controls/GroupBox.qml b/src/imports/controls/GroupBox.qml index acd6f7ac..0a78011e 100644 --- a/src/imports/controls/GroupBox.qml +++ b/src/imports/controls/GroupBox.qml @@ -50,8 +50,8 @@ AbstractGroupBox { contentWidth: content.children.length === 1 ? content.children[0].implicitWidth : 0 contentHeight: content.children.length === 1 ? content.children[0].implicitHeight : 0 - padding: Style.padding - topPadding: Style.padding + (label && title ? label.implicitHeight + Style.spacing : 0) + padding: Theme.padding + topPadding: Theme.padding + (label && title ? label.implicitHeight + Theme.spacing : 0) contentItem: Item { id: content @@ -66,20 +66,20 @@ AbstractGroupBox { width: parent.width - control.leftPadding - control.rightPadding text: control.title - color: control.Style.textColor + color: control.Theme.textColor elide: Text.ElideRight - opacity: enabled ? 1.0 : control.Style.disabledOpacity + opacity: enabled ? 1.0 : control.Theme.disabledOpacity horizontalAlignment: Text.AlignLeft verticalAlignment: Text.AlignVCenter } frame: Rectangle { - y: control.topPadding - control.Style.padding + y: control.topPadding - control.Theme.padding width: parent.width - height: parent.height - control.topPadding + control.Style.padding + height: parent.height - control.topPadding + control.Theme.padding color: "transparent" - radius: control.Style.roundness - border.color: control.Style.frameColor + radius: control.Theme.roundness + border.color: control.Theme.frameColor } } diff --git a/src/imports/controls/Label.qml b/src/imports/controls/Label.qml index 2f5868b5..05eee695 100644 --- a/src/imports/controls/Label.qml +++ b/src/imports/controls/Label.qml @@ -43,6 +43,6 @@ AbstractLabel { Accessible.name: text Accessible.role: Accessible.StaticText - color: Style.textColor - linkColor: Style.focusColor // TODO + color: Theme.textColor + linkColor: Theme.focusColor // TODO } diff --git a/src/imports/controls/PageIndicator.qml b/src/imports/controls/PageIndicator.qml index fb0faeef..c656aca9 100644 --- a/src/imports/controls/PageIndicator.qml +++ b/src/imports/controls/PageIndicator.qml @@ -47,7 +47,7 @@ AbstractPageIndicator { implicitHeight: 8 radius: width / 2 - color: control.Style.shadowColor // TODO + color: control.Theme.shadowColor // TODO opacity: index === currentIndex ? 0.75 : 0.25 Behavior on opacity { OpacityAnimator { duration: 100 } } @@ -61,7 +61,7 @@ AbstractPageIndicator { implicitWidth: Math.max(background ? background.implicitWidth : 0, contentWidth + leftPadding + rightPadding) implicitHeight: Math.max(background ? background.implicitHeight : 0, contentHeight + topPadding + bottomPadding) - padding: Style.padding + padding: Theme.padding contentItem: Row { id: row @@ -71,7 +71,7 @@ AbstractPageIndicator { width: parent.width - control.leftPadding - control.rightPadding height: parent.height - control.topPadding - control.bottomPadding - spacing: control.Style.spacing + spacing: control.Theme.spacing Repeater { model: control.count diff --git a/src/imports/controls/ProgressBar.qml b/src/imports/controls/ProgressBar.qml index 0ebaa994..b8d1dbf8 100644 --- a/src/imports/controls/ProgressBar.qml +++ b/src/imports/controls/ProgressBar.qml @@ -47,7 +47,7 @@ AbstractProgressBar { Accessible.role: Accessible.ProgressBar - padding: Style.padding + padding: Theme.padding indicator: Item { x: control.leftPadding @@ -68,8 +68,8 @@ AbstractProgressBar { width: offset * (parent.width - x) - 2 height: 2 - color: control.Style.accentColor - radius: control.Style.roundness + color: control.Theme.accentColor + radius: control.Theme.roundness SequentialAnimation on offset { loops: Animation.Infinite @@ -95,8 +95,8 @@ AbstractProgressBar { width: parent.width - control.leftPadding - control.rightPadding height: 6 - radius: control.Style.roundness - border.color: control.Style.frameColor + radius: control.Theme.roundness + border.color: control.Theme.frameColor color: "transparent" } } diff --git a/src/imports/controls/RadioButton.qml b/src/imports/controls/RadioButton.qml index af6cc1fc..92890ed0 100644 --- a/src/imports/controls/RadioButton.qml +++ b/src/imports/controls/RadioButton.qml @@ -43,7 +43,7 @@ AbstractRadioButton { implicitWidth: Math.max(background ? background.implicitWidth : 0, (label ? label.implicitWidth : 0) + (indicator ? indicator.implicitWidth : 0) + - (label && indicator ? Style.spacing : 0) + leftPadding + rightPadding) + (label && indicator ? Theme.spacing : 0) + leftPadding + rightPadding) implicitHeight: Math.max(background ? background.implicitHeight : 0, Math.max(label ? label.implicitHeight : 0, indicator ? indicator.implicitHeight : 0) + topPadding + bottomPadding) @@ -53,7 +53,7 @@ AbstractRadioButton { Accessible.pressed: pressed Accessible.role: Accessible.RadioButton - padding: Style.padding + padding: Theme.padding indicator: Rectangle { readonly property bool mirror: control.effectiveLayoutDirection == Qt.RightToLeft @@ -65,9 +65,9 @@ AbstractRadioButton { radius: width / 2 border.width: control.activeFocus ? 2 : 1 - border.color: control.activeFocus ? control.Style.focusColor : control.Style.frameColor - opacity: enabled ? 1.0 : control.Style.disabledOpacity - color: control.Style.backgroundColor + border.color: control.activeFocus ? control.Theme.focusColor : control.Theme.frameColor + opacity: enabled ? 1.0 : control.Theme.disabledOpacity + color: control.Theme.backgroundColor Rectangle { x: (parent.width - width) / 2 @@ -75,27 +75,27 @@ AbstractRadioButton { width: 12 height: 12 radius: width / 2 - color: Qt.tint(Qt.tint(control.checked ? control.Style.accentColor : control.Style.baseColor, - control.checked && control.activeFocus ? control.Style.focusColor : "transparent"), - control.pressed ? control.Style.pressColor : "transparent") + color: Qt.tint(Qt.tint(control.checked ? control.Theme.accentColor : control.Theme.baseColor, + control.checked && control.activeFocus ? control.Theme.focusColor : "transparent"), + control.pressed ? control.Theme.pressColor : "transparent") border.width: control.checked || control.pressed ? 0 : 1 - border.color: control.Style.frameColor + border.color: control.Theme.frameColor } } label: Text { readonly property bool mirror: control.effectiveLayoutDirection == Qt.RightToLeft - x: mirror ? control.leftPadding : (indicator.x + indicator.width + control.Style.spacing) + x: mirror ? control.leftPadding : (indicator.x + indicator.width + control.Theme.spacing) y: control.topPadding - width: parent.width - indicator.width - control.Style.spacing - control.leftPadding - control.rightPadding + width: parent.width - indicator.width - control.Theme.spacing - control.leftPadding - control.rightPadding height: parent.height - control.topPadding - control.bottomPadding text: control.text - color: control.Style.textColor + color: control.Theme.textColor elide: Text.ElideRight visible: control.text - opacity: enabled ? 1.0 : control.Style.disabledOpacity + opacity: enabled ? 1.0 : control.Theme.disabledOpacity horizontalAlignment: Text.AlignLeft verticalAlignment: Text.AlignVCenter } diff --git a/src/imports/controls/ScrollBar.qml b/src/imports/controls/ScrollBar.qml index ed79c8db..a9302231 100644 --- a/src/imports/controls/ScrollBar.qml +++ b/src/imports/controls/ScrollBar.qml @@ -57,7 +57,7 @@ AbstractScrollBar { implicitHeight: 6 radius: width / 2 - color: control.pressed ? control.Style.shadowColor : control.Style.frameColor + color: control.pressed ? control.Theme.shadowColor : control.Theme.frameColor visible: control.size < 1.0 opacity: 0.0 @@ -70,7 +70,7 @@ AbstractScrollBar { states: State { name: "active" when: control.active - PropertyChanges { target: handle; opacity: 1.0 - control.Style.disabledOpacity } + PropertyChanges { target: handle; opacity: 1.0 - control.Theme.disabledOpacity } } transitions: Transition { diff --git a/src/imports/controls/ScrollIndicator.qml b/src/imports/controls/ScrollIndicator.qml index b253ca03..9a525f51 100644 --- a/src/imports/controls/ScrollIndicator.qml +++ b/src/imports/controls/ScrollIndicator.qml @@ -55,7 +55,7 @@ AbstractScrollIndicator { implicitWidth: 2 implicitHeight: 2 - color: control.Style.frameColor + color: control.Theme.frameColor visible: control.size < 1.0 opacity: 0.0 @@ -68,7 +68,7 @@ AbstractScrollIndicator { states: State { name: "active" when: control.active - PropertyChanges { target: indicator; opacity: 1.0 - control.Style.disabledOpacity } + PropertyChanges { target: indicator; opacity: 1.0 - control.Theme.disabledOpacity } } transitions: [ diff --git a/src/imports/controls/Slider.qml b/src/imports/controls/Slider.qml index 83e9d00b..16d33613 100644 --- a/src/imports/controls/Slider.qml +++ b/src/imports/controls/Slider.qml @@ -50,15 +50,15 @@ AbstractSlider { Accessible.pressed: pressed Accessible.role: Accessible.Slider - padding: Style.padding + padding: Theme.padding handle: Rectangle { implicitWidth: 20 implicitHeight: 20 radius: width / 2 border.width: control.activeFocus ? 2 : 1 - border.color: control.activeFocus ? control.Style.focusColor : control.Style.frameColor - color: control.Style.backgroundColor + border.color: control.activeFocus ? control.Theme.focusColor : control.Theme.frameColor + color: control.Theme.backgroundColor readonly property bool horizontal: control.orientation === Qt.Horizontal x: horizontal ? control.visualPosition * (control.width - width) : (control.width - width) / 2 @@ -71,9 +71,9 @@ AbstractSlider { height: 12 radius: width / 2 - color: Qt.tint(Qt.tint(control.Style.accentColor, - control.activeFocus ? control.Style.focusColor : "transparent"), - control.pressed ? control.Style.pressColor : "transparent") + color: Qt.tint(Qt.tint(control.Theme.accentColor, + control.activeFocus ? control.Theme.focusColor : "transparent"), + control.pressed ? control.Theme.pressColor : "transparent") } } @@ -86,9 +86,9 @@ AbstractSlider { width: horizontal ? parent.width - control.leftPadding - control.rightPadding : implicitWidth height: horizontal ? implicitHeight : parent.height - control.topPadding - control.bottomPadding - radius: control.Style.roundness - border.color: control.Style.frameColor - color: control.Style.backgroundColor + radius: control.Theme.roundness + border.color: control.Theme.frameColor + color: control.Theme.backgroundColor scale: control.effectiveLayoutDirection === Qt.RightToLeft ? -1 : 1 Rectangle { @@ -97,8 +97,8 @@ AbstractSlider { width: control.position * parent.width - 4 height: 2 - color: control.Style.accentColor - radius: control.Style.roundness + color: control.Theme.accentColor + radius: control.Theme.roundness } } } diff --git a/src/imports/controls/Switch.qml b/src/imports/controls/Switch.qml index 58b4b9c1..ccfdaa3c 100644 --- a/src/imports/controls/Switch.qml +++ b/src/imports/controls/Switch.qml @@ -43,7 +43,7 @@ AbstractSwitch { implicitWidth: Math.max(background ? background.implicitWidth : 0, (label ? label.implicitWidth : 0) + (indicator ? indicator.implicitWidth : 0) + - (label && indicator ? Style.spacing : 0) + leftPadding + rightPadding) + (label && indicator ? Theme.spacing : 0) + leftPadding + rightPadding) implicitHeight: Math.max(background ? background.implicitHeight : 0, Math.max(label ? label.implicitHeight : 0, indicator ? indicator.implicitHeight : 0) + topPadding + bottomPadding) @@ -54,7 +54,7 @@ AbstractSwitch { Accessible.pressed: pressed Accessible.role: Accessible.Button // TODO: Switch? - padding: Style.padding + padding: Theme.padding indicator: Rectangle { readonly property bool mirror: control.effectiveLayoutDirection == Qt.RightToLeft @@ -66,20 +66,20 @@ AbstractSwitch { radius: 10 border.width: control.activeFocus ? 2 : 1 - border.color: control.activeFocus ? control.Style.focusColor : control.Style.frameColor - opacity: enabled ? 1.0 : control.Style.disabledOpacity - color: control.Style.backgroundColor + border.color: control.activeFocus ? control.Theme.focusColor : control.Theme.frameColor + opacity: enabled ? 1.0 : control.Theme.disabledOpacity + color: control.Theme.backgroundColor Rectangle { width: 12 height: 12 radius: 6 - color: Qt.tint(Qt.tint(control.checked ? control.Style.accentColor : control.Style.baseColor, - control.checked && control.activeFocus ? control.Style.focusColor : "transparent"), - control.pressed ? control.Style.pressColor : "transparent") + color: Qt.tint(Qt.tint(control.checked ? control.Theme.accentColor : control.Theme.baseColor, + control.checked && control.activeFocus ? control.Theme.focusColor : "transparent"), + control.pressed ? control.Theme.pressColor : "transparent") border.width: control.checked || control.pressed ? 0 : 1 - border.color: control.Style.frameColor + border.color: control.Theme.frameColor x: Math.max(4, Math.min(parent.width - width - 4, control.visualPosition * parent.width - (width / 2))) @@ -95,16 +95,16 @@ AbstractSwitch { label: Text { readonly property bool mirror: control.effectiveLayoutDirection == Qt.RightToLeft - x: mirror ? control.leftPadding : (indicator.x + indicator.width + control.Style.spacing) + x: mirror ? control.leftPadding : (indicator.x + indicator.width + control.Theme.spacing) y: control.topPadding - width: parent.width - indicator.width - control.Style.spacing - control.leftPadding - control.rightPadding + width: parent.width - indicator.width - control.Theme.spacing - control.leftPadding - control.rightPadding height: parent.height - control.topPadding - control.bottomPadding text: control.text - color: control.Style.textColor + color: control.Theme.textColor elide: Text.ElideRight visible: control.text - opacity: enabled ? 1.0 : control.Style.disabledOpacity + opacity: enabled ? 1.0 : control.Theme.disabledOpacity horizontalAlignment: Text.AlignLeft verticalAlignment: Text.AlignVCenter } diff --git a/src/imports/controls/TabBar.qml b/src/imports/controls/TabBar.qml index 6d833485..0bf99508 100644 --- a/src/imports/controls/TabBar.qml +++ b/src/imports/controls/TabBar.qml @@ -98,7 +98,7 @@ AbstractTabBar { height: 4 width: parent.width y: parent.height - height - color: control.Style.accentColor + color: control.Theme.accentColor } } } @@ -107,14 +107,14 @@ AbstractTabBar { implicitWidth: 26 implicitHeight: 26 width: listView.width - border.color: control.Style.backgroundColor + border.color: control.Theme.backgroundColor border.width: 8 - color: listView.count > 1 ? control.Style.frameColor : control.Style.backgroundColor + color: listView.count > 1 ? control.Theme.frameColor : control.Theme.backgroundColor Rectangle { y: parent.height - height width: parent.width height: 1 - color: control.Style.frameColor + color: control.Theme.frameColor } } } diff --git a/src/imports/controls/TabButton.qml b/src/imports/controls/TabButton.qml index b70bd83c..881b18fe 100644 --- a/src/imports/controls/TabButton.qml +++ b/src/imports/controls/TabButton.qml @@ -50,7 +50,7 @@ AbstractTabButton { Accessible.selected: checked Accessible.role: Accessible.PageTab - padding: Style.padding + padding: Theme.padding label: Text { x: control.leftPadding @@ -61,8 +61,8 @@ AbstractTabButton { text: control.text font.pointSize: 10 elide: Text.ElideRight - color: control.pressed ? control.Style.accentColor : control.Style.textColor - opacity: enabled ? 1.0 : control.Style.disabledOpacity + color: control.pressed ? control.Theme.accentColor : control.Theme.textColor + opacity: enabled ? 1.0 : control.Theme.disabledOpacity horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter } @@ -70,6 +70,6 @@ AbstractTabButton { background: Rectangle { height: parent.height - 1 implicitHeight: 26 - color: Style.backgroundColor + color: Theme.backgroundColor } } diff --git a/src/imports/controls/TextArea.qml b/src/imports/controls/TextArea.qml index d1895a9e..4e1199e8 100644 --- a/src/imports/controls/TextArea.qml +++ b/src/imports/controls/TextArea.qml @@ -46,9 +46,9 @@ AbstractTextArea { Accessible.readOnly: readOnly Accessible.description: placeholder ? placeholder.text : "" - color: Style.textColor - selectionColor: Style.selectionColor - selectedTextColor: Style.selectedTextColor + color: Theme.textColor + selectionColor: Theme.selectionColor + selectedTextColor: Theme.selectedTextColor placeholder: Text { x: control.leftPadding @@ -56,8 +56,8 @@ AbstractTextArea { width: parent.width - control.leftPadding - control.rightPadding height: parent.height - control.topPadding - control.bottomPadding - color: control.Style.textColor - opacity: control.Style.disabledOpacity + color: control.Theme.textColor + opacity: control.Theme.disabledOpacity visible: !control.length } } diff --git a/src/imports/controls/TextField.qml b/src/imports/controls/TextField.qml index a8e13f57..5d623b2f 100644 --- a/src/imports/controls/TextField.qml +++ b/src/imports/controls/TextField.qml @@ -46,11 +46,11 @@ AbstractTextField { Accessible.description: placeholder ? placeholder.text : "" Accessible.passwordEdit: echoMode === TextInput.Password || echoMode === TextInput.PasswordEchoOnEdit - padding: Style.padding + padding: Theme.padding - color: Style.textColor - selectionColor: Style.selectionColor - selectedTextColor: Style.selectedTextColor + color: Theme.textColor + selectionColor: Theme.selectionColor + selectedTextColor: Theme.selectedTextColor verticalAlignment: TextInput.AlignVCenter placeholder: Text { @@ -59,16 +59,16 @@ AbstractTextField { width: parent.width - control.leftPadding - control.rightPadding height: parent.height - control.topPadding - control.bottomPadding - color: control.Style.textColor - opacity: control.Style.disabledOpacity + color: control.Theme.textColor + opacity: control.Theme.disabledOpacity visible: !control.displayText } background: Rectangle { implicitWidth: 120 // TODO - radius: control.Style.roundness + radius: control.Theme.roundness border.width: control.activeFocus ? 2 : 1 - border.color: control.activeFocus ? control.Style.focusColor : control.Style.frameColor - opacity: enabled ? 1.0 : control.Style.disabledOpacity + border.color: control.activeFocus ? control.Theme.focusColor : control.Theme.frameColor + opacity: enabled ? 1.0 : control.Theme.disabledOpacity } } diff --git a/src/imports/controls/ToggleButton.qml b/src/imports/controls/ToggleButton.qml index 7ab30bd3..fec1c889 100644 --- a/src/imports/controls/ToggleButton.qml +++ b/src/imports/controls/ToggleButton.qml @@ -43,7 +43,7 @@ AbstractToggleButton { implicitWidth: Math.max(background ? background.implicitWidth : 0, (label ? label.implicitWidth : 0) + (indicator ? indicator.implicitWidth : 0) + - (label && indicator ? Style.spacing : 0) + leftPadding + rightPadding) + (label && indicator ? Theme.spacing : 0) + leftPadding + rightPadding) implicitHeight: Math.max(background ? background.implicitHeight : 0, Math.max(label ? label.implicitHeight : 0, indicator ? indicator.implicitHeight : 0) + topPadding + bottomPadding) @@ -54,7 +54,7 @@ AbstractToggleButton { Accessible.pressed: pressed Accessible.role: Accessible.Button - padding: Style.padding + padding: Theme.padding indicator: Rectangle { readonly property bool mirror: control.effectiveLayoutDirection == Qt.RightToLeft @@ -64,21 +64,21 @@ AbstractToggleButton { x: text ? (mirror ? parent.width - width - control.rightPadding : control.leftPadding) : (parent.width - width) / 2 y: (parent.height - height) / 2 - radius: control.Style.roundness + radius: control.Theme.roundness border.width: control.activeFocus ? 2 : 1 - border.color: control.activeFocus ? control.Style.focusColor : control.Style.frameColor - opacity: enabled ? 1.0 : control.Style.disabledOpacity - color: control.Style.backgroundColor + border.color: control.activeFocus ? control.Theme.focusColor : control.Theme.frameColor + opacity: enabled ? 1.0 : control.Theme.disabledOpacity + color: control.Theme.backgroundColor Rectangle { width: 12 height: 12 - color: Qt.tint(Qt.tint(control.checked ? control.Style.accentColor : control.Style.baseColor, - control.checked && control.activeFocus ? control.Style.focusColor : "transparent"), - control.pressed ? control.Style.pressColor : "transparent") + color: Qt.tint(Qt.tint(control.checked ? control.Theme.accentColor : control.Theme.baseColor, + control.checked && control.activeFocus ? control.Theme.focusColor : "transparent"), + control.pressed ? control.Theme.pressColor : "transparent") border.width: control.checked || control.pressed ? 0 : 1 - border.color: control.Style.frameColor + border.color: control.Theme.frameColor x: Math.max(4, Math.min(parent.width - width - 4, control.visualPosition * parent.width - (width / 2))) @@ -94,16 +94,16 @@ AbstractToggleButton { label: Text { readonly property bool mirror: control.effectiveLayoutDirection == Qt.RightToLeft - x: mirror ? control.leftPadding : (indicator.x + indicator.width + control.Style.spacing) + x: mirror ? control.leftPadding : (indicator.x + indicator.width + control.Theme.spacing) y: control.topPadding - width: parent.width - indicator.width - control.Style.spacing - control.leftPadding - control.rightPadding + width: parent.width - indicator.width - control.Theme.spacing - control.leftPadding - control.rightPadding height: parent.height - control.topPadding - control.bottomPadding text: control.text - color: control.Style.textColor + color: control.Theme.textColor elide: Text.ElideRight visible: control.text - opacity: enabled ? 1.0 : control.Style.disabledOpacity + opacity: enabled ? 1.0 : control.Theme.disabledOpacity horizontalAlignment: Text.AlignLeft verticalAlignment: Text.AlignVCenter } diff --git a/src/imports/controls/ToolBar.qml b/src/imports/controls/ToolBar.qml index 8bdedd82..2d893264 100644 --- a/src/imports/controls/ToolBar.qml +++ b/src/imports/controls/ToolBar.qml @@ -62,6 +62,6 @@ AbstractToolBar { background: Rectangle { implicitHeight: 26 - color: control.Style.baseColor + color: control.Theme.baseColor } } diff --git a/src/imports/controls/ToolButton.qml b/src/imports/controls/ToolButton.qml index ade1c72a..b185dc79 100644 --- a/src/imports/controls/ToolButton.qml +++ b/src/imports/controls/ToolButton.qml @@ -49,7 +49,7 @@ AbstractButton { Accessible.pressed: pressed Accessible.role: Accessible.Button - padding: Style.padding + padding: Theme.padding label: Text { x: control.leftPadding @@ -58,9 +58,9 @@ AbstractButton { height: parent.height - control.topPadding - control.bottomPadding text: control.text - color: control.Style.textColor + color: control.Theme.textColor elide: Text.ElideRight - opacity: enabled ? 1.0 : control.Style.disabledOpacity + opacity: enabled ? 1.0 : control.Theme.disabledOpacity horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter } @@ -69,8 +69,8 @@ AbstractButton { implicitWidth: 26 implicitHeight: 26 - opacity: control.Style.disabledOpacity - color: control.Style.frameColor + opacity: control.Theme.disabledOpacity + color: control.Theme.frameColor visible: control.pressed } } diff --git a/src/imports/controls/controls.pro b/src/imports/controls/controls.pro index 06a947dd..44e2a5e6 100644 --- a/src/imports/controls/controls.pro +++ b/src/imports/controls/controls.pro @@ -37,19 +37,19 @@ QML_FILES = \ ToolButton.qml HEADERS += \ - $$PWD/qquickstyle_p.h \ - $$PWD/qquickstyledata_p.h + $$PWD/qquicktheme_p.h \ + $$PWD/qquickthemedata_p.h SOURCES += \ - $$PWD/qquickstyle.cpp \ - $$PWD/qquickstyledata.cpp \ + $$PWD/qquicktheme.cpp \ + $$PWD/qquickthemedata.cpp \ $$PWD/qtquickcontrols2plugin.cpp RESOURCES += \ $$PWD/qtquickcontrols2plugin.qrc OTHER_FILES += \ - $$PWD/style.json + $$PWD/theme.json CONFIG += no_cxx_module load(qml_plugin) diff --git a/src/imports/controls/qquickstyle.cpp b/src/imports/controls/qquickstyle.cpp deleted file mode 100644 index 91c1e2da..00000000 --- a/src/imports/controls/qquickstyle.cpp +++ /dev/null @@ -1,826 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick 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 "qquickstyle_p.h" -#include "qquickstyledata_p.h" - -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -/*! - \qmltype Style - \inherits QtObject - \instantiates QQuickStyle - \inqmlmodule QtQuick.Controls - \ingroup utilities - \brief A style interface. - - TODO -*/ - -/*! - \qmlattachedproperty color QtQuickControls2::Style::accentColor -*/ - -/*! - \qmlattachedproperty color QtQuickControls2::Style::backgroundColor -*/ - -/*! - \qmlattachedproperty color QtQuickControls2::Style::focusColor -*/ - -/*! - \qmlattachedproperty color QtQuickControls2::Style::frameColor -*/ - -/*! - \qmlattachedproperty color QtQuickControls2::Style::pressColor -*/ - -/*! - \qmlattachedproperty color QtQuickControls2::Style::selectedTextColor -*/ - -/*! - \qmlattachedproperty color QtQuickControls2::Style::selectionColor -*/ - -/*! - \qmlattachedproperty color QtQuickControls2::Style::shadowColor -*/ - -/*! - \qmlattachedproperty color QtQuickControls2::Style::textColor -*/ - -/*! - \qmlattachedproperty int QtQuickControls2::Style::padding -*/ - -/*! - \qmlattachedproperty int QtQuickControls2::Style::roundness -*/ - -/*! - \qmlattachedproperty int QtQuickControls2::Style::spacing -*/ - -/*! - \qmlattachedproperty real QtQuickControls2::Style::disabledOpacity -*/ - -Q_GLOBAL_STATIC_WITH_ARGS(QQuickStyleData, globalStyleData, (QString::fromLatin1(":/qtquickcontrols/style.json"))) - -static QQuickStyle *styleInstance(QQmlEngine *engine) -{ - static QHash styles; - QHash::iterator it = styles.find(engine); - if (it == styles.end()) - it = styles.insert(engine, new QQuickStyle(*globalStyleData(), engine)); - return it.value(); -} - -static QQuickStyle *attachedStyle(QObject *object) -{ - if (object) - return qobject_cast(qmlAttachedPropertiesObject(object, false)); - return Q_NULLPTR; -} - -static QQuickStyle *findParentStyle(QObject *object) -{ - QQuickItem *item = qobject_cast(object); - if (item) { - // lookup parent items - QQuickItem *parent = item->parentItem(); - while (parent) { - QQuickStyle *attached = attachedStyle(parent); - if (attached) - return attached; - parent = parent->parentItem(); - } - - // fallback to item's window style - QQuickWindow *window = item->window(); - if (window) { - QQuickStyle *attached = attachedStyle(window); - if (attached) - return attached; - } - } - - // lookup parent window style - QQuickWindow *window = qobject_cast(object); - if (window) { - QQuickWindow *parentWindow = qobject_cast(window->parent()); - if (parentWindow) { - QQuickStyle *attached = attachedStyle(window); - if (attached) - return attached; - } - } - - // fallback to global style - if (object) { - QQmlEngine *engine = qmlEngine(object); - if (engine) - return styleInstance(engine); - } - - return Q_NULLPTR; -} - -static QList findChildStyles(QObject *object) -{ - QList styles; - - QQuickItem *item = qobject_cast(object); - if (!item) { - QQuickWindow *window = qobject_cast(object); - if (window) { - item = window->contentItem(); - - foreach (QObject *child, window->children()) { - QQuickWindow *childWindow = qobject_cast(child); - if (childWindow) { - QQuickStyle *style = attachedStyle(childWindow); - if (style) - styles += style; - } - } - } - } - - if (item) { - foreach (QQuickItem *child, item->childItems()) { - QQuickStyle *style = attachedStyle(child); - if (style) - styles += style; - else - styles += findChildStyles(child); - } - } - - return styles; -} - -class QQuickStylePrivate : public QObjectPrivate, public QQuickItemChangeListener -{ - Q_DECLARE_PUBLIC(QQuickStyle) - -public: - QQuickStylePrivate(const QQuickStyleData &data) : data(data), - explicitAccentColor(false), - explicitBackgroundColor(false), - explicitBaseColor(false), - explicitFocusColor(false), - explicitFrameColor(false), - explicitPressColor(false), - explicitSelectedTextColor(false), - explicitSelectionColor(false), - explicitShadowColor(false), - explicitTextColor(false), - explicitPadding(false), - explicitSpacing(false), - explicitRoundness(false), - explicitDisabledOpacity(false) { } - - enum Method { Implicit, Explicit, Inherit }; - - void setAccentColor(const QColor &color, Method method); - void setBackgroundColor(const QColor &color, Method method); - void setBaseColor(const QColor &color, Method method); - void setFocusColor(const QColor &color, Method method); - void setFrameColor(const QColor &color, Method method); - void setPressColor(const QColor &color, Method method); - void setSelectedTextColor(const QColor &color, Method method); - void setSelectionColor(const QColor &color, Method method); - void setShadowColor(const QColor &color, Method method); - void setTextColor(const QColor &color, Method method); - void setPadding(int padding, Method method); - void setRoundness(int roundness, Method method); - void setSpacing(int spacing, Method method); - void setDisabledOpacity(qreal opacity, Method method); - - void inherit(QQuickStyle *style); - - const QQuickStyleData &resolve() const; - - // TODO: add QQuickItemChangeListener::itemSceneChanged() - void itemParentChanged(QQuickItem *item, QQuickItem *parent) Q_DECL_OVERRIDE; - - QQuickStyleData data; - QPointer parentStyle; - QSet childStyles; - - bool explicitAccentColor; - bool explicitBackgroundColor; - bool explicitBaseColor; - bool explicitFocusColor; - bool explicitFrameColor; - bool explicitPressColor; - bool explicitSelectedTextColor; - bool explicitSelectionColor; - bool explicitShadowColor; - bool explicitTextColor; - bool explicitPadding; - bool explicitSpacing; - bool explicitRoundness; - bool explicitDisabledOpacity; -}; - -void QQuickStylePrivate::setAccentColor(const QColor &color, Method method) -{ - Q_Q(QQuickStyle); - if (!explicitAccentColor || method != Inherit) { - explicitAccentColor = method == Explicit; - if (data.accentColor() != color) { - data.setAccentColor(color); - emit q->accentColorChanged(); - - foreach (QQuickStyle *child, childStyles) - child->d_func()->setAccentColor(color, Inherit); - } - } -} - -void QQuickStylePrivate::setBackgroundColor(const QColor &color, Method method) -{ - Q_Q(QQuickStyle); - if (!explicitBackgroundColor || method != Inherit) { - explicitBackgroundColor = method == Explicit; - if (data.backgroundColor() != color) { - data.setBackgroundColor(color); - emit q->backgroundColorChanged(); - - foreach (QQuickStyle *child, childStyles) - child->d_func()->setBackgroundColor(color, Inherit); - } - } -} - -void QQuickStylePrivate::setBaseColor(const QColor &color, Method method) -{ - Q_Q(QQuickStyle); - if (!explicitBaseColor || method != Inherit) { - explicitBaseColor = method == Explicit; - if (data.baseColor() != color) { - data.setBaseColor(color); - emit q->baseColorChanged(); - - foreach (QQuickStyle *child, childStyles) - child->d_func()->setBaseColor(color, Inherit); - } - } -} - -void QQuickStylePrivate::setFocusColor(const QColor &color, Method method) -{ - Q_Q(QQuickStyle); - if (!explicitFocusColor || method != Inherit) { - explicitFocusColor = method == Explicit; - if (data.focusColor() != color) { - data.setFocusColor(color); - emit q->focusColorChanged(); - - foreach (QQuickStyle *child, childStyles) - child->d_func()->setFocusColor(color, Inherit); - } - } -} - -void QQuickStylePrivate::setFrameColor(const QColor &color, Method method) -{ - Q_Q(QQuickStyle); - if (!explicitFrameColor || method != Inherit) { - explicitFrameColor = method == Explicit; - if (data.frameColor() != color) { - data.setFrameColor(color); - emit q->frameColorChanged(); - - foreach (QQuickStyle *child, childStyles) - child->d_func()->setFrameColor(color, Inherit); - } - } -} - -void QQuickStylePrivate::setPressColor(const QColor &color, Method method) -{ - Q_Q(QQuickStyle); - if (!explicitPressColor || method != Inherit) { - explicitPressColor = method == Explicit; - if (data.pressColor() != color) { - data.setPressColor(color); - emit q->pressColorChanged(); - - foreach (QQuickStyle *child, childStyles) - child->d_func()->setPressColor(color, Inherit); - } - } -} - -void QQuickStylePrivate::setSelectedTextColor(const QColor &color, Method method) -{ - Q_Q(QQuickStyle); - if (!explicitSelectedTextColor || method != Inherit) { - explicitSelectedTextColor = method == Explicit; - if (data.selectedTextColor() != color) { - data.setSelectedTextColor(color); - q->selectedTextColorChanged(); - - foreach (QQuickStyle *child, childStyles) - child->d_func()->setSelectedTextColor(color, Inherit); - } - } -} - -void QQuickStylePrivate::setSelectionColor(const QColor &color, Method method) -{ - Q_Q(QQuickStyle); - if (!explicitSelectionColor || method != Inherit) { - explicitSelectionColor = method == Explicit; - if (data.selectionColor() != color) { - data.setSelectionColor(color); - emit q->selectionColorChanged(); - - foreach (QQuickStyle *child, childStyles) - child->d_func()->setSelectionColor(color, Inherit); - } - } -} - -void QQuickStylePrivate::setShadowColor(const QColor &color, Method method) -{ - Q_Q(QQuickStyle); - if (!explicitShadowColor || method != Inherit) { - explicitShadowColor = method == Explicit; - if (data.shadowColor() != color) { - data.setShadowColor(color); - emit q->shadowColorChanged(); - - foreach (QQuickStyle *child, childStyles) - child->d_func()->setShadowColor(color, Inherit); - } - } -} - -void QQuickStylePrivate::setTextColor(const QColor &color, Method method) -{ - Q_Q(QQuickStyle); - if (!explicitTextColor || method != Inherit) { - explicitTextColor = method == Explicit; - if (data.textColor() != color) { - data.setTextColor(color); - emit q->textColorChanged(); - - foreach (QQuickStyle *child, childStyles) - child->d_func()->setTextColor(color, Inherit); - } - } -} - -void QQuickStylePrivate::setPadding(int padding, Method method) -{ - Q_Q(QQuickStyle); - if (!explicitPadding || method != Inherit) { - explicitPadding = method == Explicit; - if (data.padding() != padding) { - data.setPadding(padding); - emit q->paddingChanged(); - - foreach (QQuickStyle *child, childStyles) - child->d_func()->setPadding(padding, Inherit); - } - } -} - -void QQuickStylePrivate::setRoundness(int roundness, Method method) -{ - Q_Q(QQuickStyle); - if (!explicitRoundness || method != Inherit) { - explicitRoundness = method == Explicit; - if (data.roundness() != roundness) { - data.setRoundness(roundness); - emit q->roundnessChanged(); - - foreach (QQuickStyle *child, childStyles) - child->d_func()->setRoundness(roundness, Inherit); - } - } -} - -void QQuickStylePrivate::setSpacing(int spacing, Method method) -{ - Q_Q(QQuickStyle); - if (!explicitSpacing || method != Inherit) { - explicitSpacing = method == Explicit; - if (data.spacing() != spacing) { - data.setSpacing(spacing); - emit q->spacingChanged(); - - foreach (QQuickStyle *child, childStyles) - child->d_func()->setSpacing(spacing, Inherit); - } - } -} - -void QQuickStylePrivate::setDisabledOpacity(qreal opacity, Method method) -{ - Q_Q(QQuickStyle); - if (!explicitDisabledOpacity || method != Inherit) { - explicitDisabledOpacity = method == Explicit; - if (data.disabledOpacity() != opacity) { - data.setDisabledOpacity(opacity); - emit q->disabledOpacityChanged(); - - foreach (QQuickStyle *child, childStyles) - child->d_func()->setDisabledOpacity(opacity, Inherit); - } - } -} - -void QQuickStylePrivate::inherit(QQuickStyle *style) -{ - setAccentColor(style->accentColor(), Inherit); - setBackgroundColor(style->backgroundColor(), Inherit); - setBaseColor(style->baseColor(), QQuickStylePrivate::Inherit); - setFocusColor(style->focusColor(), Inherit); - setFrameColor(style->frameColor(), Inherit); - setPressColor(style->pressColor(), Inherit); - setSelectedTextColor(style->selectedTextColor(), Inherit); - setSelectionColor(style->selectionColor(), Inherit); - setShadowColor(style->shadowColor(), Inherit); - setTextColor(style->textColor(), Inherit); - setPadding(style->padding(), Inherit); - setRoundness(style->roundness(), Inherit); - setSpacing(style->spacing(), Inherit); - setDisabledOpacity(style->disabledOpacity(), Inherit); -} - -const QQuickStyleData &QQuickStylePrivate::resolve() const -{ - Q_Q(const QQuickStyle); - QQuickStyle *style = findParentStyle(const_cast(q)); - return style ? style->d_func()->data : *globalStyleData(); -} - -void QQuickStylePrivate::itemParentChanged(QQuickItem *item, QQuickItem *) -{ - QQuickStyle *style = attachedStyle(item); - if (style) { - QQuickStyle *parent = findParentStyle(style); - if (parent) - style->setParentStyle(parent); - } -} - -QQuickStyle::QQuickStyle(const QQuickStyleData &data, QObject *parent) : - QObject(*(new QQuickStylePrivate(data)), parent) -{ - Q_D(QQuickStyle); - QQuickItem *item = qobject_cast(parent); - if (item) - QQuickItemPrivate::get(item)->addItemChangeListener(d, QQuickItemPrivate::Parent); -} - -QQuickStyle::~QQuickStyle() -{ - Q_D(QQuickStyle); - QQuickItem *item = qobject_cast(parent()); - if (item) - QQuickItemPrivate::get(item)->removeItemChangeListener(d, QQuickItemPrivate::Parent); - - setParentStyle(Q_NULLPTR); -} - -QQuickStyle *QQuickStyle::qmlAttachedProperties(QObject *object) -{ - QQuickStyle *style = Q_NULLPTR; - QQuickStyle *parent = findParentStyle(object); - if (parent) { - style = new QQuickStyle(parent->d_func()->data, object); - style->setParentStyle(parent); - } else { - style = new QQuickStyle(*globalStyleData(), object); - } - - QList childStyles = findChildStyles(object); - foreach (QQuickStyle *child, childStyles) - child->setParentStyle(style); - return style; -} - -QQuickStyle *QQuickStyle::parentStyle() const -{ - Q_D(const QQuickStyle); - return d->parentStyle; -} - -void QQuickStyle::setParentStyle(QQuickStyle *style) -{ - Q_D(QQuickStyle); - if (d->parentStyle != style) { - if (d->parentStyle) - d->parentStyle->d_func()->childStyles.remove(this); - d->parentStyle = style; - if (style) { - style->d_func()->childStyles.insert(this); - d->inherit(style); - } - } -} - -QColor QQuickStyle::accentColor() const -{ - Q_D(const QQuickStyle); - return d->data.accentColor(); -} - -void QQuickStyle::setAccentColor(const QColor &color) -{ - Q_D(QQuickStyle); - d->setAccentColor(color, QQuickStylePrivate::Explicit); -} - -void QQuickStyle::resetAccentColor() -{ - Q_D(QQuickStyle); - d->setAccentColor(d->resolve().accentColor(), QQuickStylePrivate::Implicit); -} - -QColor QQuickStyle::backgroundColor() const -{ - Q_D(const QQuickStyle); - return d->data.backgroundColor(); -} - -void QQuickStyle::setBackgroundColor(const QColor &color) -{ - Q_D(QQuickStyle); - d->setBackgroundColor(color, QQuickStylePrivate::Explicit); -} - -void QQuickStyle::resetBackgroundColor() -{ - Q_D(QQuickStyle); - d->setBackgroundColor(d->resolve().backgroundColor(), QQuickStylePrivate::Implicit); -} - -QColor QQuickStyle::baseColor() const -{ - Q_D(const QQuickStyle); - return d->data.baseColor(); -} - -void QQuickStyle::setBaseColor(const QColor &color) -{ - Q_D(QQuickStyle); - d->setBaseColor(color, QQuickStylePrivate::Explicit); -} - -void QQuickStyle::resetBaseColor() -{ - Q_D(QQuickStyle); - d->setBaseColor(d->resolve().baseColor(), QQuickStylePrivate::Implicit); -} - -QColor QQuickStyle::focusColor() const -{ - Q_D(const QQuickStyle); - return d->data.focusColor(); -} - -void QQuickStyle::setFocusColor(const QColor &color) -{ - Q_D(QQuickStyle); - d->setFocusColor(color, QQuickStylePrivate::Explicit); -} - -void QQuickStyle::resetFocusColor() -{ - Q_D(QQuickStyle); - d->setFocusColor(d->resolve().focusColor(), QQuickStylePrivate::Implicit); -} - -QColor QQuickStyle::frameColor() const -{ - Q_D(const QQuickStyle); - return d->data.frameColor(); -} - -void QQuickStyle::setFrameColor(const QColor &color) -{ - Q_D(QQuickStyle); - d->setFrameColor(color, QQuickStylePrivate::Explicit); -} - -void QQuickStyle::resetFrameColor() -{ - Q_D(QQuickStyle); - d->setFrameColor(d->resolve().frameColor(), QQuickStylePrivate::Implicit); -} - -QColor QQuickStyle::pressColor() const -{ - Q_D(const QQuickStyle); - return d->data.pressColor(); -} - -void QQuickStyle::setPressColor(const QColor &color) -{ - Q_D(QQuickStyle); - d->setPressColor(color, QQuickStylePrivate::Explicit); -} - -void QQuickStyle::resetPressColor() -{ - Q_D(QQuickStyle); - d->setPressColor(d->resolve().pressColor(), QQuickStylePrivate::Implicit); -} - -QColor QQuickStyle::selectedTextColor() const -{ - Q_D(const QQuickStyle); - return d->data.selectedTextColor(); -} - -void QQuickStyle::setSelectedTextColor(const QColor &color) -{ - Q_D(QQuickStyle); - d->setSelectedTextColor(color, QQuickStylePrivate::Explicit); -} - -void QQuickStyle::resetSelectedTextColor() -{ - Q_D(QQuickStyle); - d->setSelectedTextColor(d->resolve().selectedTextColor(), QQuickStylePrivate::Implicit); -} - -QColor QQuickStyle::selectionColor() const -{ - Q_D(const QQuickStyle); - return d->data.selectionColor(); -} - -void QQuickStyle::setSelectionColor(const QColor &color) -{ - Q_D(QQuickStyle); - d->setSelectionColor(color, QQuickStylePrivate::Explicit); -} - -void QQuickStyle::resetSelectionColor() -{ - Q_D(QQuickStyle); - d->setSelectionColor(d->resolve().selectionColor(), QQuickStylePrivate::Implicit); -} - -QColor QQuickStyle::shadowColor() const -{ - Q_D(const QQuickStyle); - return d->data.shadowColor(); -} - -void QQuickStyle::setShadowColor(const QColor &color) -{ - Q_D(QQuickStyle); - d->setShadowColor(color, QQuickStylePrivate::Explicit); -} - -void QQuickStyle::resetShadowColor() -{ - Q_D(QQuickStyle); - d->setShadowColor(d->resolve().shadowColor(), QQuickStylePrivate::Implicit); -} - -QColor QQuickStyle::textColor() const -{ - Q_D(const QQuickStyle); - return d->data.textColor(); -} - -void QQuickStyle::setTextColor(const QColor &color) -{ - Q_D(QQuickStyle); - d->setTextColor(color, QQuickStylePrivate::Explicit); -} - -void QQuickStyle::resetTextColor() -{ - Q_D(QQuickStyle); - d->setTextColor(d->resolve().textColor(), QQuickStylePrivate::Implicit); -} - -int QQuickStyle::padding() const -{ - Q_D(const QQuickStyle); - return d->data.padding(); -} - -void QQuickStyle::setPadding(int padding) -{ - Q_D(QQuickStyle); - d->setPadding(padding, QQuickStylePrivate::Explicit); -} - -void QQuickStyle::resetPadding() -{ - Q_D(QQuickStyle); - d->setPadding(d->resolve().padding(), QQuickStylePrivate::Implicit); -} - -int QQuickStyle::roundness() const -{ - Q_D(const QQuickStyle); - return d->data.roundness(); -} - -void QQuickStyle::setRoundness(int roundness) -{ - Q_D(QQuickStyle); - d->setRoundness(roundness, QQuickStylePrivate::Explicit); -} - -void QQuickStyle::resetRoundness() -{ - Q_D(QQuickStyle); - d->setRoundness(d->resolve().roundness(), QQuickStylePrivate::Implicit); -} - -int QQuickStyle::spacing() const -{ - Q_D(const QQuickStyle); - return d->data.spacing(); -} - -void QQuickStyle::setSpacing(int spacing) -{ - Q_D(QQuickStyle); - d->setSpacing(spacing, QQuickStylePrivate::Explicit); -} - -void QQuickStyle::resetSpacing() -{ - Q_D(QQuickStyle); - d->setSpacing(d->resolve().spacing(), QQuickStylePrivate::Implicit); -} - -qreal QQuickStyle::disabledOpacity() const -{ - Q_D(const QQuickStyle); - return d->data.disabledOpacity(); -} - -void QQuickStyle::setDisabledOpacity(qreal opacity) -{ - Q_D(QQuickStyle); - d->setDisabledOpacity(opacity, QQuickStylePrivate::Explicit); -} - -void QQuickStyle::resetDisabledOpacity() -{ - Q_D(QQuickStyle); - d->setDisabledOpacity(d->resolve().disabledOpacity(), QQuickStylePrivate::Implicit); -} - -QT_END_NAMESPACE diff --git a/src/imports/controls/qquickstyle_p.h b/src/imports/controls/qquickstyle_p.h deleted file mode 100644 index 38ffe5df..00000000 --- a/src/imports/controls/qquickstyle_p.h +++ /dev/null @@ -1,168 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick 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 QQUICKSTYLE_P_H -#define QQUICKSTYLE_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 -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickStyleData; -class QQuickStylePrivate; - -class QQuickStyle : public QObject -{ - Q_OBJECT - Q_PROPERTY(QColor accentColor READ accentColor WRITE setAccentColor RESET resetAccentColor NOTIFY accentColorChanged FINAL) - Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor RESET resetBackgroundColor NOTIFY backgroundColorChanged FINAL) - Q_PROPERTY(QColor baseColor READ baseColor WRITE setBaseColor RESET resetBaseColor NOTIFY baseColorChanged FINAL) - Q_PROPERTY(QColor focusColor READ focusColor WRITE setFocusColor RESET resetFocusColor NOTIFY focusColorChanged FINAL) - Q_PROPERTY(QColor frameColor READ frameColor WRITE setFrameColor RESET resetFrameColor NOTIFY frameColorChanged FINAL) - Q_PROPERTY(QColor pressColor READ pressColor WRITE setPressColor RESET resetPressColor NOTIFY pressColorChanged FINAL) - Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor RESET resetSelectedTextColor NOTIFY selectedTextColorChanged FINAL) - Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor RESET resetSelectionColor NOTIFY selectionColorChanged FINAL) - Q_PROPERTY(QColor shadowColor READ shadowColor WRITE setShadowColor RESET resetShadowColor NOTIFY shadowColorChanged FINAL) - Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor RESET resetTextColor NOTIFY textColorChanged FINAL) - Q_PROPERTY(int padding READ padding WRITE setPadding RESET resetPadding NOTIFY paddingChanged FINAL) - Q_PROPERTY(int roundness READ roundness WRITE setRoundness RESET resetRoundness NOTIFY roundnessChanged FINAL) - Q_PROPERTY(int spacing READ spacing WRITE setSpacing RESET resetSpacing NOTIFY spacingChanged FINAL) - Q_PROPERTY(qreal disabledOpacity READ disabledOpacity WRITE setDisabledOpacity RESET resetDisabledOpacity NOTIFY disabledOpacityChanged FINAL) - -public: - explicit QQuickStyle(const QQuickStyleData &data, QObject *parent = Q_NULLPTR); - ~QQuickStyle(); - - static QQuickStyle *qmlAttachedProperties(QObject *object); - - QQuickStyle *parentStyle() const; - void setParentStyle(QQuickStyle *style); - - QColor accentColor() const; - void setAccentColor(const QColor &color); - void resetAccentColor(); - - QColor backgroundColor() const; - void setBackgroundColor(const QColor &color); - void resetBackgroundColor(); - - QColor baseColor() const; - void setBaseColor(const QColor &color); - void resetBaseColor(); - - QColor focusColor() const; - void setFocusColor(const QColor &color); - void resetFocusColor(); - - QColor frameColor() const; - void setFrameColor(const QColor &color); - void resetFrameColor(); - - QColor pressColor() const; - void setPressColor(const QColor &color); - void resetPressColor(); - - QColor selectedTextColor() const; - void setSelectedTextColor(const QColor &color); - void resetSelectedTextColor(); - - QColor selectionColor() const; - void setSelectionColor(const QColor &color); - void resetSelectionColor(); - - QColor shadowColor() const; - void setShadowColor(const QColor &color); - void resetShadowColor(); - - QColor textColor() const; - void setTextColor(const QColor &color); - void resetTextColor(); - - int padding() const; - void setPadding(int padding); - void resetPadding(); - - int roundness() const; - void setRoundness(int roundness); - void resetRoundness(); - - int spacing() const; - void setSpacing(int spacing); - void resetSpacing(); - - qreal disabledOpacity() const; - void setDisabledOpacity(qreal opacity); - void resetDisabledOpacity(); - -Q_SIGNALS: - void accentColorChanged(); - void backgroundColorChanged(); - void baseColorChanged(); - void focusColorChanged(); - void frameColorChanged(); - void pressColorChanged(); - void selectedTextColorChanged(); - void selectionColorChanged(); - void shadowColorChanged(); - void textColorChanged(); - void paddingChanged(); - void roundnessChanged(); - void spacingChanged(); - void disabledOpacityChanged(); - -private: - Q_DISABLE_COPY(QQuickStyle) - Q_DECLARE_PRIVATE(QQuickStyle) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPEINFO(QQuickStyle, QML_HAS_ATTACHED_PROPERTIES) - -#endif // QQUICKSTYLE_P_H diff --git a/src/imports/controls/qquickstyledata.cpp b/src/imports/controls/qquickstyledata.cpp deleted file mode 100644 index 9e81e61b..00000000 --- a/src/imports/controls/qquickstyledata.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick 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 "qquickstyledata_p.h" - -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -QQuickStyleData::QQuickStyleData(const QString &filePath) : d(new Data) -{ - if (!filePath.isEmpty()) - load(filePath); -} - -static QColor readColorValue(const QJsonValue &value, const QColor &defaultValue) -{ - if (value.isString()) - return QColor(value.toString()); - return QColor::fromRgba(value.toInt(defaultValue.rgba())); -} - -static double readNumberValue(const QJsonValue &value, double defaultValue) -{ - return value.toDouble(defaultValue); -} - -bool QQuickStyleData::load(const QString &filePath) -{ - QJsonDocument doc; - - QFile file(filePath); - if (!file.open(QFile::ReadOnly | QFile::Text)) { - qDebug() << file.error(); - qWarning() << "QQuickStyle: failed to open ':/qtquickcontrols/style.json': " << qPrintable(file.errorString()); - return false; - } else { - QJsonParseError error; - doc = QJsonDocument::fromJson(file.readAll(), &error); - if (error.error != QJsonParseError::NoError) { - qWarning() << "QQuickStyle: failed to parse ':/qtquickcontrols/style.json': " << qPrintable(error.errorString()); - return false; - } - } - - QJsonObject style = doc.object(); - d->accentColor = readColorValue(style.value(QStringLiteral("accentColor")), QColor("#7bc258")); - d->backgroundColor = readColorValue(style.value(QStringLiteral("backgroundColor")), QColor("#ffffff")); - d->baseColor = readColorValue(style.value(QStringLiteral("baseColor")), QColor("#eeeeee")); - d->focusColor = readColorValue(style.value(QStringLiteral("focusColor")), QColor("#45a7d7")); - d->frameColor = readColorValue(style.value(QStringLiteral("frameColor")), QColor("#bdbebf")); - d->pressColor = readColorValue(style.value(QStringLiteral("pressColor")), QColor("#33333333")); - d->selectedTextColor = readColorValue(style.value(QStringLiteral("selectedTextColor")), QColor("#ffffff")); - d->selectionColor = readColorValue(style.value(QStringLiteral("selectionColor")), QColor("#45a7d7")); - d->shadowColor = readColorValue(style.value(QStringLiteral("shadowColor")), QColor("#28282a")); - d->textColor = readColorValue(style.value(QStringLiteral("textColor")), QColor("#26282a")); - d->padding = readNumberValue(style.value(QStringLiteral("padding")), 6); - d->roundness = readNumberValue(style.value(QStringLiteral("roundness")), 3); - d->spacing = readNumberValue(style.value(QStringLiteral("spacing")), 6); - d->disabledOpacity = readNumberValue(style.value(QStringLiteral("disabledOpacity")), 0.3); - return true; -} - -QT_END_NAMESPACE diff --git a/src/imports/controls/qquickstyledata_p.h b/src/imports/controls/qquickstyledata_p.h deleted file mode 100644 index 29938f7d..00000000 --- a/src/imports/controls/qquickstyledata_p.h +++ /dev/null @@ -1,128 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick 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 QQUICKSTYLEDATA_P_H -#define QQUICKSTYLEDATA_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 -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickStyleData -{ -public: - QQuickStyleData(const QString &filePath = QString()); - - bool load(const QString &filePath); - - QColor accentColor() const { return d->accentColor; } - void setAccentColor(const QColor &color) { d->accentColor = color; } - - QColor backgroundColor() const { return d->backgroundColor; } - void setBackgroundColor(const QColor &color) { d->backgroundColor = color; } - - QColor baseColor() const { return d->baseColor; } - void setBaseColor(const QColor &color) { d->baseColor = color; } - - QColor focusColor() const { return d->focusColor; } - void setFocusColor(const QColor &color) { d->focusColor = color; } - - QColor frameColor() const { return d->frameColor; } - void setFrameColor(const QColor &color) { d->frameColor = color; } - - QColor pressColor() const { return d->pressColor; } - void setPressColor(const QColor &color) { d->pressColor = color; } - - QColor selectedTextColor() const { return d->selectedTextColor; } - void setSelectedTextColor(const QColor &color) { d->selectedTextColor = color; } - - QColor selectionColor() const { return d->selectionColor; } - void setSelectionColor(const QColor &color) { d->selectionColor = color; } - - QColor shadowColor() const { return d->shadowColor; } - void setShadowColor(const QColor &color) { d->shadowColor = color; } - - QColor textColor() const { return d->textColor; } - void setTextColor(const QColor &color) { d->textColor = color; } - - int padding() const { return d->padding; } - void setPadding(int padding) { d->padding = padding; } - - int roundness() const { return d->roundness; } - void setRoundness(int roundness) { d->roundness = roundness; } - - int spacing() const { return d->spacing; } - void setSpacing(int spacing) { d->spacing = spacing; } - - qreal disabledOpacity() const { return d->disabledOpacity; } - void setDisabledOpacity(qreal opacity) { d->disabledOpacity = opacity; } - -private: - struct Data : public QSharedData { - QColor accentColor; - QColor baseColor; - QColor backgroundColor; - QColor focusColor; - QColor frameColor; - QColor pressColor; - QColor selectedTextColor; - QColor selectionColor; - QColor shadowColor; - QColor textColor; - int padding; - int spacing; - int roundness; - qreal disabledOpacity; - }; - QSharedDataPointer d; -}; - -QT_END_NAMESPACE - -#endif // QQUICKSTYLEDATA_P_H diff --git a/src/imports/controls/qquicktheme.cpp b/src/imports/controls/qquicktheme.cpp new file mode 100644 index 00000000..476379e3 --- /dev/null +++ b/src/imports/controls/qquicktheme.cpp @@ -0,0 +1,826 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick 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 "qquicktheme_p.h" +#include "qquickthemedata_p.h" + +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +/*! + \qmltype Theme + \inherits QtObject + \instantiates QQuickTheme + \inqmlmodule QtQuick.Controls + \ingroup utilities + \brief A theme interface. + + TODO +*/ + +/*! + \qmlattachedproperty color QtQuickControls2::Theme::accentColor +*/ + +/*! + \qmlattachedproperty color QtQuickControls2::Theme::backgroundColor +*/ + +/*! + \qmlattachedproperty color QtQuickControls2::Theme::focusColor +*/ + +/*! + \qmlattachedproperty color QtQuickControls2::Theme::frameColor +*/ + +/*! + \qmlattachedproperty color QtQuickControls2::Theme::pressColor +*/ + +/*! + \qmlattachedproperty color QtQuickControls2::Theme::selectedTextColor +*/ + +/*! + \qmlattachedproperty color QtQuickControls2::Theme::selectionColor +*/ + +/*! + \qmlattachedproperty color QtQuickControls2::Theme::shadowColor +*/ + +/*! + \qmlattachedproperty color QtQuickControls2::Theme::textColor +*/ + +/*! + \qmlattachedproperty int QtQuickControls2::Theme::padding +*/ + +/*! + \qmlattachedproperty int QtQuickControls2::Theme::roundness +*/ + +/*! + \qmlattachedproperty int QtQuickControls2::Theme::spacing +*/ + +/*! + \qmlattachedproperty real QtQuickControls2::Theme::disabledOpacity +*/ + +Q_GLOBAL_STATIC_WITH_ARGS(QQuickThemeData, globalThemeData, (QString::fromLatin1(":/qtquickcontrols/theme.json"))) + +static QQuickTheme *themeInstance(QQmlEngine *engine) +{ + static QHash themes; + QHash::iterator it = themes.find(engine); + if (it == themes.end()) + it = themes.insert(engine, new QQuickTheme(*globalThemeData(), engine)); + return it.value(); +} + +static QQuickTheme *attachedTheme(QObject *object) +{ + if (object) + return qobject_cast(qmlAttachedPropertiesObject(object, false)); + return Q_NULLPTR; +} + +static QQuickTheme *findParentTheme(QObject *object) +{ + QQuickItem *item = qobject_cast(object); + if (item) { + // lookup parent items + QQuickItem *parent = item->parentItem(); + while (parent) { + QQuickTheme *attached = attachedTheme(parent); + if (attached) + return attached; + parent = parent->parentItem(); + } + + // fallback to item's window theme + QQuickWindow *window = item->window(); + if (window) { + QQuickTheme *attached = attachedTheme(window); + if (attached) + return attached; + } + } + + // lookup parent window theme + QQuickWindow *window = qobject_cast(object); + if (window) { + QQuickWindow *parentWindow = qobject_cast(window->parent()); + if (parentWindow) { + QQuickTheme *attached = attachedTheme(window); + if (attached) + return attached; + } + } + + // fallback to global theme + if (object) { + QQmlEngine *engine = qmlEngine(object); + if (engine) + return themeInstance(engine); + } + + return Q_NULLPTR; +} + +static QList findChildThemes(QObject *object) +{ + QList themes; + + QQuickItem *item = qobject_cast(object); + if (!item) { + QQuickWindow *window = qobject_cast(object); + if (window) { + item = window->contentItem(); + + foreach (QObject *child, window->children()) { + QQuickWindow *childWindow = qobject_cast(child); + if (childWindow) { + QQuickTheme *theme = attachedTheme(childWindow); + if (theme) + themes += theme; + } + } + } + } + + if (item) { + foreach (QQuickItem *child, item->childItems()) { + QQuickTheme *theme = attachedTheme(child); + if (theme) + themes += theme; + else + themes += findChildThemes(child); + } + } + + return themes; +} + +class QQuickThemePrivate : public QObjectPrivate, public QQuickItemChangeListener +{ + Q_DECLARE_PUBLIC(QQuickTheme) + +public: + QQuickThemePrivate(const QQuickThemeData &data) : data(data), + explicitAccentColor(false), + explicitBackgroundColor(false), + explicitBaseColor(false), + explicitFocusColor(false), + explicitFrameColor(false), + explicitPressColor(false), + explicitSelectedTextColor(false), + explicitSelectionColor(false), + explicitShadowColor(false), + explicitTextColor(false), + explicitPadding(false), + explicitSpacing(false), + explicitRoundness(false), + explicitDisabledOpacity(false) { } + + enum Method { Implicit, Explicit, Inherit }; + + void setAccentColor(const QColor &color, Method method); + void setBackgroundColor(const QColor &color, Method method); + void setBaseColor(const QColor &color, Method method); + void setFocusColor(const QColor &color, Method method); + void setFrameColor(const QColor &color, Method method); + void setPressColor(const QColor &color, Method method); + void setSelectedTextColor(const QColor &color, Method method); + void setSelectionColor(const QColor &color, Method method); + void setShadowColor(const QColor &color, Method method); + void setTextColor(const QColor &color, Method method); + void setPadding(int padding, Method method); + void setRoundness(int roundness, Method method); + void setSpacing(int spacing, Method method); + void setDisabledOpacity(qreal opacity, Method method); + + void inherit(QQuickTheme *theme); + + const QQuickThemeData &resolve() const; + + // TODO: add QQuickItemChangeListener::itemSceneChanged() + void itemParentChanged(QQuickItem *item, QQuickItem *parent) Q_DECL_OVERRIDE; + + QQuickThemeData data; + QPointer parentTheme; + QSet childThemes; + + bool explicitAccentColor; + bool explicitBackgroundColor; + bool explicitBaseColor; + bool explicitFocusColor; + bool explicitFrameColor; + bool explicitPressColor; + bool explicitSelectedTextColor; + bool explicitSelectionColor; + bool explicitShadowColor; + bool explicitTextColor; + bool explicitPadding; + bool explicitSpacing; + bool explicitRoundness; + bool explicitDisabledOpacity; +}; + +void QQuickThemePrivate::setAccentColor(const QColor &color, Method method) +{ + Q_Q(QQuickTheme); + if (!explicitAccentColor || method != Inherit) { + explicitAccentColor = method == Explicit; + if (data.accentColor() != color) { + data.setAccentColor(color); + emit q->accentColorChanged(); + + foreach (QQuickTheme *child, childThemes) + child->d_func()->setAccentColor(color, Inherit); + } + } +} + +void QQuickThemePrivate::setBackgroundColor(const QColor &color, Method method) +{ + Q_Q(QQuickTheme); + if (!explicitBackgroundColor || method != Inherit) { + explicitBackgroundColor = method == Explicit; + if (data.backgroundColor() != color) { + data.setBackgroundColor(color); + emit q->backgroundColorChanged(); + + foreach (QQuickTheme *child, childThemes) + child->d_func()->setBackgroundColor(color, Inherit); + } + } +} + +void QQuickThemePrivate::setBaseColor(const QColor &color, Method method) +{ + Q_Q(QQuickTheme); + if (!explicitBaseColor || method != Inherit) { + explicitBaseColor = method == Explicit; + if (data.baseColor() != color) { + data.setBaseColor(color); + emit q->baseColorChanged(); + + foreach (QQuickTheme *child, childThemes) + child->d_func()->setBaseColor(color, Inherit); + } + } +} + +void QQuickThemePrivate::setFocusColor(const QColor &color, Method method) +{ + Q_Q(QQuickTheme); + if (!explicitFocusColor || method != Inherit) { + explicitFocusColor = method == Explicit; + if (data.focusColor() != color) { + data.setFocusColor(color); + emit q->focusColorChanged(); + + foreach (QQuickTheme *child, childThemes) + child->d_func()->setFocusColor(color, Inherit); + } + } +} + +void QQuickThemePrivate::setFrameColor(const QColor &color, Method method) +{ + Q_Q(QQuickTheme); + if (!explicitFrameColor || method != Inherit) { + explicitFrameColor = method == Explicit; + if (data.frameColor() != color) { + data.setFrameColor(color); + emit q->frameColorChanged(); + + foreach (QQuickTheme *child, childThemes) + child->d_func()->setFrameColor(color, Inherit); + } + } +} + +void QQuickThemePrivate::setPressColor(const QColor &color, Method method) +{ + Q_Q(QQuickTheme); + if (!explicitPressColor || method != Inherit) { + explicitPressColor = method == Explicit; + if (data.pressColor() != color) { + data.setPressColor(color); + emit q->pressColorChanged(); + + foreach (QQuickTheme *child, childThemes) + child->d_func()->setPressColor(color, Inherit); + } + } +} + +void QQuickThemePrivate::setSelectedTextColor(const QColor &color, Method method) +{ + Q_Q(QQuickTheme); + if (!explicitSelectedTextColor || method != Inherit) { + explicitSelectedTextColor = method == Explicit; + if (data.selectedTextColor() != color) { + data.setSelectedTextColor(color); + q->selectedTextColorChanged(); + + foreach (QQuickTheme *child, childThemes) + child->d_func()->setSelectedTextColor(color, Inherit); + } + } +} + +void QQuickThemePrivate::setSelectionColor(const QColor &color, Method method) +{ + Q_Q(QQuickTheme); + if (!explicitSelectionColor || method != Inherit) { + explicitSelectionColor = method == Explicit; + if (data.selectionColor() != color) { + data.setSelectionColor(color); + emit q->selectionColorChanged(); + + foreach (QQuickTheme *child, childThemes) + child->d_func()->setSelectionColor(color, Inherit); + } + } +} + +void QQuickThemePrivate::setShadowColor(const QColor &color, Method method) +{ + Q_Q(QQuickTheme); + if (!explicitShadowColor || method != Inherit) { + explicitShadowColor = method == Explicit; + if (data.shadowColor() != color) { + data.setShadowColor(color); + emit q->shadowColorChanged(); + + foreach (QQuickTheme *child, childThemes) + child->d_func()->setShadowColor(color, Inherit); + } + } +} + +void QQuickThemePrivate::setTextColor(const QColor &color, Method method) +{ + Q_Q(QQuickTheme); + if (!explicitTextColor || method != Inherit) { + explicitTextColor = method == Explicit; + if (data.textColor() != color) { + data.setTextColor(color); + emit q->textColorChanged(); + + foreach (QQuickTheme *child, childThemes) + child->d_func()->setTextColor(color, Inherit); + } + } +} + +void QQuickThemePrivate::setPadding(int padding, Method method) +{ + Q_Q(QQuickTheme); + if (!explicitPadding || method != Inherit) { + explicitPadding = method == Explicit; + if (data.padding() != padding) { + data.setPadding(padding); + emit q->paddingChanged(); + + foreach (QQuickTheme *child, childThemes) + child->d_func()->setPadding(padding, Inherit); + } + } +} + +void QQuickThemePrivate::setRoundness(int roundness, Method method) +{ + Q_Q(QQuickTheme); + if (!explicitRoundness || method != Inherit) { + explicitRoundness = method == Explicit; + if (data.roundness() != roundness) { + data.setRoundness(roundness); + emit q->roundnessChanged(); + + foreach (QQuickTheme *child, childThemes) + child->d_func()->setRoundness(roundness, Inherit); + } + } +} + +void QQuickThemePrivate::setSpacing(int spacing, Method method) +{ + Q_Q(QQuickTheme); + if (!explicitSpacing || method != Inherit) { + explicitSpacing = method == Explicit; + if (data.spacing() != spacing) { + data.setSpacing(spacing); + emit q->spacingChanged(); + + foreach (QQuickTheme *child, childThemes) + child->d_func()->setSpacing(spacing, Inherit); + } + } +} + +void QQuickThemePrivate::setDisabledOpacity(qreal opacity, Method method) +{ + Q_Q(QQuickTheme); + if (!explicitDisabledOpacity || method != Inherit) { + explicitDisabledOpacity = method == Explicit; + if (data.disabledOpacity() != opacity) { + data.setDisabledOpacity(opacity); + emit q->disabledOpacityChanged(); + + foreach (QQuickTheme *child, childThemes) + child->d_func()->setDisabledOpacity(opacity, Inherit); + } + } +} + +void QQuickThemePrivate::inherit(QQuickTheme *theme) +{ + setAccentColor(theme->accentColor(), Inherit); + setBackgroundColor(theme->backgroundColor(), Inherit); + setBaseColor(theme->baseColor(), QQuickThemePrivate::Inherit); + setFocusColor(theme->focusColor(), Inherit); + setFrameColor(theme->frameColor(), Inherit); + setPressColor(theme->pressColor(), Inherit); + setSelectedTextColor(theme->selectedTextColor(), Inherit); + setSelectionColor(theme->selectionColor(), Inherit); + setShadowColor(theme->shadowColor(), Inherit); + setTextColor(theme->textColor(), Inherit); + setPadding(theme->padding(), Inherit); + setRoundness(theme->roundness(), Inherit); + setSpacing(theme->spacing(), Inherit); + setDisabledOpacity(theme->disabledOpacity(), Inherit); +} + +const QQuickThemeData &QQuickThemePrivate::resolve() const +{ + Q_Q(const QQuickTheme); + QQuickTheme *theme = findParentTheme(const_cast(q)); + return theme ? theme->d_func()->data : *globalThemeData(); +} + +void QQuickThemePrivate::itemParentChanged(QQuickItem *item, QQuickItem *) +{ + QQuickTheme *theme = attachedTheme(item); + if (theme) { + QQuickTheme *parent = findParentTheme(theme); + if (parent) + theme->setParentTheme(parent); + } +} + +QQuickTheme::QQuickTheme(const QQuickThemeData &data, QObject *parent) : + QObject(*(new QQuickThemePrivate(data)), parent) +{ + Q_D(QQuickTheme); + QQuickItem *item = qobject_cast(parent); + if (item) + QQuickItemPrivate::get(item)->addItemChangeListener(d, QQuickItemPrivate::Parent); +} + +QQuickTheme::~QQuickTheme() +{ + Q_D(QQuickTheme); + QQuickItem *item = qobject_cast(parent()); + if (item) + QQuickItemPrivate::get(item)->removeItemChangeListener(d, QQuickItemPrivate::Parent); + + setParentTheme(Q_NULLPTR); +} + +QQuickTheme *QQuickTheme::qmlAttachedProperties(QObject *object) +{ + QQuickTheme *theme = Q_NULLPTR; + QQuickTheme *parent = findParentTheme(object); + if (parent) { + theme = new QQuickTheme(parent->d_func()->data, object); + theme->setParentTheme(parent); + } else { + theme = new QQuickTheme(*globalThemeData(), object); + } + + QList childThemes = findChildThemes(object); + foreach (QQuickTheme *child, childThemes) + child->setParentTheme(theme); + return theme; +} + +QQuickTheme *QQuickTheme::parentTheme() const +{ + Q_D(const QQuickTheme); + return d->parentTheme; +} + +void QQuickTheme::setParentTheme(QQuickTheme *theme) +{ + Q_D(QQuickTheme); + if (d->parentTheme != theme) { + if (d->parentTheme) + d->parentTheme->d_func()->childThemes.remove(this); + d->parentTheme = theme; + if (theme) { + theme->d_func()->childThemes.insert(this); + d->inherit(theme); + } + } +} + +QColor QQuickTheme::accentColor() const +{ + Q_D(const QQuickTheme); + return d->data.accentColor(); +} + +void QQuickTheme::setAccentColor(const QColor &color) +{ + Q_D(QQuickTheme); + d->setAccentColor(color, QQuickThemePrivate::Explicit); +} + +void QQuickTheme::resetAccentColor() +{ + Q_D(QQuickTheme); + d->setAccentColor(d->resolve().accentColor(), QQuickThemePrivate::Implicit); +} + +QColor QQuickTheme::backgroundColor() const +{ + Q_D(const QQuickTheme); + return d->data.backgroundColor(); +} + +void QQuickTheme::setBackgroundColor(const QColor &color) +{ + Q_D(QQuickTheme); + d->setBackgroundColor(color, QQuickThemePrivate::Explicit); +} + +void QQuickTheme::resetBackgroundColor() +{ + Q_D(QQuickTheme); + d->setBackgroundColor(d->resolve().backgroundColor(), QQuickThemePrivate::Implicit); +} + +QColor QQuickTheme::baseColor() const +{ + Q_D(const QQuickTheme); + return d->data.baseColor(); +} + +void QQuickTheme::setBaseColor(const QColor &color) +{ + Q_D(QQuickTheme); + d->setBaseColor(color, QQuickThemePrivate::Explicit); +} + +void QQuickTheme::resetBaseColor() +{ + Q_D(QQuickTheme); + d->setBaseColor(d->resolve().baseColor(), QQuickThemePrivate::Implicit); +} + +QColor QQuickTheme::focusColor() const +{ + Q_D(const QQuickTheme); + return d->data.focusColor(); +} + +void QQuickTheme::setFocusColor(const QColor &color) +{ + Q_D(QQuickTheme); + d->setFocusColor(color, QQuickThemePrivate::Explicit); +} + +void QQuickTheme::resetFocusColor() +{ + Q_D(QQuickTheme); + d->setFocusColor(d->resolve().focusColor(), QQuickThemePrivate::Implicit); +} + +QColor QQuickTheme::frameColor() const +{ + Q_D(const QQuickTheme); + return d->data.frameColor(); +} + +void QQuickTheme::setFrameColor(const QColor &color) +{ + Q_D(QQuickTheme); + d->setFrameColor(color, QQuickThemePrivate::Explicit); +} + +void QQuickTheme::resetFrameColor() +{ + Q_D(QQuickTheme); + d->setFrameColor(d->resolve().frameColor(), QQuickThemePrivate::Implicit); +} + +QColor QQuickTheme::pressColor() const +{ + Q_D(const QQuickTheme); + return d->data.pressColor(); +} + +void QQuickTheme::setPressColor(const QColor &color) +{ + Q_D(QQuickTheme); + d->setPressColor(color, QQuickThemePrivate::Explicit); +} + +void QQuickTheme::resetPressColor() +{ + Q_D(QQuickTheme); + d->setPressColor(d->resolve().pressColor(), QQuickThemePrivate::Implicit); +} + +QColor QQuickTheme::selectedTextColor() const +{ + Q_D(const QQuickTheme); + return d->data.selectedTextColor(); +} + +void QQuickTheme::setSelectedTextColor(const QColor &color) +{ + Q_D(QQuickTheme); + d->setSelectedTextColor(color, QQuickThemePrivate::Explicit); +} + +void QQuickTheme::resetSelectedTextColor() +{ + Q_D(QQuickTheme); + d->setSelectedTextColor(d->resolve().selectedTextColor(), QQuickThemePrivate::Implicit); +} + +QColor QQuickTheme::selectionColor() const +{ + Q_D(const QQuickTheme); + return d->data.selectionColor(); +} + +void QQuickTheme::setSelectionColor(const QColor &color) +{ + Q_D(QQuickTheme); + d->setSelectionColor(color, QQuickThemePrivate::Explicit); +} + +void QQuickTheme::resetSelectionColor() +{ + Q_D(QQuickTheme); + d->setSelectionColor(d->resolve().selectionColor(), QQuickThemePrivate::Implicit); +} + +QColor QQuickTheme::shadowColor() const +{ + Q_D(const QQuickTheme); + return d->data.shadowColor(); +} + +void QQuickTheme::setShadowColor(const QColor &color) +{ + Q_D(QQuickTheme); + d->setShadowColor(color, QQuickThemePrivate::Explicit); +} + +void QQuickTheme::resetShadowColor() +{ + Q_D(QQuickTheme); + d->setShadowColor(d->resolve().shadowColor(), QQuickThemePrivate::Implicit); +} + +QColor QQuickTheme::textColor() const +{ + Q_D(const QQuickTheme); + return d->data.textColor(); +} + +void QQuickTheme::setTextColor(const QColor &color) +{ + Q_D(QQuickTheme); + d->setTextColor(color, QQuickThemePrivate::Explicit); +} + +void QQuickTheme::resetTextColor() +{ + Q_D(QQuickTheme); + d->setTextColor(d->resolve().textColor(), QQuickThemePrivate::Implicit); +} + +int QQuickTheme::padding() const +{ + Q_D(const QQuickTheme); + return d->data.padding(); +} + +void QQuickTheme::setPadding(int padding) +{ + Q_D(QQuickTheme); + d->setPadding(padding, QQuickThemePrivate::Explicit); +} + +void QQuickTheme::resetPadding() +{ + Q_D(QQuickTheme); + d->setPadding(d->resolve().padding(), QQuickThemePrivate::Implicit); +} + +int QQuickTheme::roundness() const +{ + Q_D(const QQuickTheme); + return d->data.roundness(); +} + +void QQuickTheme::setRoundness(int roundness) +{ + Q_D(QQuickTheme); + d->setRoundness(roundness, QQuickThemePrivate::Explicit); +} + +void QQuickTheme::resetRoundness() +{ + Q_D(QQuickTheme); + d->setRoundness(d->resolve().roundness(), QQuickThemePrivate::Implicit); +} + +int QQuickTheme::spacing() const +{ + Q_D(const QQuickTheme); + return d->data.spacing(); +} + +void QQuickTheme::setSpacing(int spacing) +{ + Q_D(QQuickTheme); + d->setSpacing(spacing, QQuickThemePrivate::Explicit); +} + +void QQuickTheme::resetSpacing() +{ + Q_D(QQuickTheme); + d->setSpacing(d->resolve().spacing(), QQuickThemePrivate::Implicit); +} + +qreal QQuickTheme::disabledOpacity() const +{ + Q_D(const QQuickTheme); + return d->data.disabledOpacity(); +} + +void QQuickTheme::setDisabledOpacity(qreal opacity) +{ + Q_D(QQuickTheme); + d->setDisabledOpacity(opacity, QQuickThemePrivate::Explicit); +} + +void QQuickTheme::resetDisabledOpacity() +{ + Q_D(QQuickTheme); + d->setDisabledOpacity(d->resolve().disabledOpacity(), QQuickThemePrivate::Implicit); +} + +QT_END_NAMESPACE diff --git a/src/imports/controls/qquicktheme_p.h b/src/imports/controls/qquicktheme_p.h new file mode 100644 index 00000000..f443c311 --- /dev/null +++ b/src/imports/controls/qquicktheme_p.h @@ -0,0 +1,168 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick 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 QQUICKTHEME_P_H +#define QQUICKTHEME_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 +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickThemeData; +class QQuickThemePrivate; + +class QQuickTheme : public QObject +{ + Q_OBJECT + Q_PROPERTY(QColor accentColor READ accentColor WRITE setAccentColor RESET resetAccentColor NOTIFY accentColorChanged FINAL) + Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor RESET resetBackgroundColor NOTIFY backgroundColorChanged FINAL) + Q_PROPERTY(QColor baseColor READ baseColor WRITE setBaseColor RESET resetBaseColor NOTIFY baseColorChanged FINAL) + Q_PROPERTY(QColor focusColor READ focusColor WRITE setFocusColor RESET resetFocusColor NOTIFY focusColorChanged FINAL) + Q_PROPERTY(QColor frameColor READ frameColor WRITE setFrameColor RESET resetFrameColor NOTIFY frameColorChanged FINAL) + Q_PROPERTY(QColor pressColor READ pressColor WRITE setPressColor RESET resetPressColor NOTIFY pressColorChanged FINAL) + Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor RESET resetSelectedTextColor NOTIFY selectedTextColorChanged FINAL) + Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor RESET resetSelectionColor NOTIFY selectionColorChanged FINAL) + Q_PROPERTY(QColor shadowColor READ shadowColor WRITE setShadowColor RESET resetShadowColor NOTIFY shadowColorChanged FINAL) + Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor RESET resetTextColor NOTIFY textColorChanged FINAL) + Q_PROPERTY(int padding READ padding WRITE setPadding RESET resetPadding NOTIFY paddingChanged FINAL) + Q_PROPERTY(int roundness READ roundness WRITE setRoundness RESET resetRoundness NOTIFY roundnessChanged FINAL) + Q_PROPERTY(int spacing READ spacing WRITE setSpacing RESET resetSpacing NOTIFY spacingChanged FINAL) + Q_PROPERTY(qreal disabledOpacity READ disabledOpacity WRITE setDisabledOpacity RESET resetDisabledOpacity NOTIFY disabledOpacityChanged FINAL) + +public: + explicit QQuickTheme(const QQuickThemeData &data, QObject *parent = Q_NULLPTR); + ~QQuickTheme(); + + static QQuickTheme *qmlAttachedProperties(QObject *object); + + QQuickTheme *parentTheme() const; + void setParentTheme(QQuickTheme *theme); + + QColor accentColor() const; + void setAccentColor(const QColor &color); + void resetAccentColor(); + + QColor backgroundColor() const; + void setBackgroundColor(const QColor &color); + void resetBackgroundColor(); + + QColor baseColor() const; + void setBaseColor(const QColor &color); + void resetBaseColor(); + + QColor focusColor() const; + void setFocusColor(const QColor &color); + void resetFocusColor(); + + QColor frameColor() const; + void setFrameColor(const QColor &color); + void resetFrameColor(); + + QColor pressColor() const; + void setPressColor(const QColor &color); + void resetPressColor(); + + QColor selectedTextColor() const; + void setSelectedTextColor(const QColor &color); + void resetSelectedTextColor(); + + QColor selectionColor() const; + void setSelectionColor(const QColor &color); + void resetSelectionColor(); + + QColor shadowColor() const; + void setShadowColor(const QColor &color); + void resetShadowColor(); + + QColor textColor() const; + void setTextColor(const QColor &color); + void resetTextColor(); + + int padding() const; + void setPadding(int padding); + void resetPadding(); + + int roundness() const; + void setRoundness(int roundness); + void resetRoundness(); + + int spacing() const; + void setSpacing(int spacing); + void resetSpacing(); + + qreal disabledOpacity() const; + void setDisabledOpacity(qreal opacity); + void resetDisabledOpacity(); + +Q_SIGNALS: + void accentColorChanged(); + void backgroundColorChanged(); + void baseColorChanged(); + void focusColorChanged(); + void frameColorChanged(); + void pressColorChanged(); + void selectedTextColorChanged(); + void selectionColorChanged(); + void shadowColorChanged(); + void textColorChanged(); + void paddingChanged(); + void roundnessChanged(); + void spacingChanged(); + void disabledOpacityChanged(); + +private: + Q_DISABLE_COPY(QQuickTheme) + Q_DECLARE_PRIVATE(QQuickTheme) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPEINFO(QQuickTheme, QML_HAS_ATTACHED_PROPERTIES) + +#endif // QQUICKTHEME_P_H diff --git a/src/imports/controls/qquickthemedata.cpp b/src/imports/controls/qquickthemedata.cpp new file mode 100644 index 00000000..73070231 --- /dev/null +++ b/src/imports/controls/qquickthemedata.cpp @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick 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 "qquickthemedata_p.h" + +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +QQuickThemeData::QQuickThemeData(const QString &filePath) : d(new Data) +{ + if (!filePath.isEmpty()) + load(filePath); +} + +static QColor readColorValue(const QJsonValue &value, const QColor &defaultValue) +{ + if (value.isString()) + return QColor(value.toString()); + return QColor::fromRgba(value.toInt(defaultValue.rgba())); +} + +static double readNumberValue(const QJsonValue &value, double defaultValue) +{ + return value.toDouble(defaultValue); +} + +bool QQuickThemeData::load(const QString &filePath) +{ + QJsonDocument doc; + + QFile file(filePath); + if (!file.open(QFile::ReadOnly | QFile::Text)) { + qDebug() << file.error(); + qWarning() << "QQuickTheme: failed to open ':/qtquickcontrols/theme.json': " << qPrintable(file.errorString()); + return false; + } else { + QJsonParseError error; + doc = QJsonDocument::fromJson(file.readAll(), &error); + if (error.error != QJsonParseError::NoError) { + qWarning() << "QQuickTheme: failed to parse ':/qtquickcontrols/theme.json': " << qPrintable(error.errorString()); + return false; + } + } + + QJsonObject theme = doc.object(); + d->accentColor = readColorValue(theme.value(QStringLiteral("accentColor")), QColor("#7bc258")); + d->backgroundColor = readColorValue(theme.value(QStringLiteral("backgroundColor")), QColor("#ffffff")); + d->baseColor = readColorValue(theme.value(QStringLiteral("baseColor")), QColor("#eeeeee")); + d->focusColor = readColorValue(theme.value(QStringLiteral("focusColor")), QColor("#45a7d7")); + d->frameColor = readColorValue(theme.value(QStringLiteral("frameColor")), QColor("#bdbebf")); + d->pressColor = readColorValue(theme.value(QStringLiteral("pressColor")), QColor("#33333333")); + d->selectedTextColor = readColorValue(theme.value(QStringLiteral("selectedTextColor")), QColor("#ffffff")); + d->selectionColor = readColorValue(theme.value(QStringLiteral("selectionColor")), QColor("#45a7d7")); + d->shadowColor = readColorValue(theme.value(QStringLiteral("shadowColor")), QColor("#28282a")); + d->textColor = readColorValue(theme.value(QStringLiteral("textColor")), QColor("#26282a")); + d->padding = readNumberValue(theme.value(QStringLiteral("padding")), 6); + d->roundness = readNumberValue(theme.value(QStringLiteral("roundness")), 3); + d->spacing = readNumberValue(theme.value(QStringLiteral("spacing")), 6); + d->disabledOpacity = readNumberValue(theme.value(QStringLiteral("disabledOpacity")), 0.3); + return true; +} + +QT_END_NAMESPACE diff --git a/src/imports/controls/qquickthemedata_p.h b/src/imports/controls/qquickthemedata_p.h new file mode 100644 index 00000000..5b590735 --- /dev/null +++ b/src/imports/controls/qquickthemedata_p.h @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick 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 QQUICKTHEMEDATA_P_H +#define QQUICKTHEMEDATA_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 +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickThemeData +{ +public: + QQuickThemeData(const QString &filePath = QString()); + + bool load(const QString &filePath); + + QColor accentColor() const { return d->accentColor; } + void setAccentColor(const QColor &color) { d->accentColor = color; } + + QColor backgroundColor() const { return d->backgroundColor; } + void setBackgroundColor(const QColor &color) { d->backgroundColor = color; } + + QColor baseColor() const { return d->baseColor; } + void setBaseColor(const QColor &color) { d->baseColor = color; } + + QColor focusColor() const { return d->focusColor; } + void setFocusColor(const QColor &color) { d->focusColor = color; } + + QColor frameColor() const { return d->frameColor; } + void setFrameColor(const QColor &color) { d->frameColor = color; } + + QColor pressColor() const { return d->pressColor; } + void setPressColor(const QColor &color) { d->pressColor = color; } + + QColor selectedTextColor() const { return d->selectedTextColor; } + void setSelectedTextColor(const QColor &color) { d->selectedTextColor = color; } + + QColor selectionColor() const { return d->selectionColor; } + void setSelectionColor(const QColor &color) { d->selectionColor = color; } + + QColor shadowColor() const { return d->shadowColor; } + void setShadowColor(const QColor &color) { d->shadowColor = color; } + + QColor textColor() const { return d->textColor; } + void setTextColor(const QColor &color) { d->textColor = color; } + + int padding() const { return d->padding; } + void setPadding(int padding) { d->padding = padding; } + + int roundness() const { return d->roundness; } + void setRoundness(int roundness) { d->roundness = roundness; } + + int spacing() const { return d->spacing; } + void setSpacing(int spacing) { d->spacing = spacing; } + + qreal disabledOpacity() const { return d->disabledOpacity; } + void setDisabledOpacity(qreal opacity) { d->disabledOpacity = opacity; } + +private: + struct Data : public QSharedData { + QColor accentColor; + QColor baseColor; + QColor backgroundColor; + QColor focusColor; + QColor frameColor; + QColor pressColor; + QColor selectedTextColor; + QColor selectionColor; + QColor shadowColor; + QColor textColor; + int padding; + int spacing; + int roundness; + qreal disabledOpacity; + }; + QSharedDataPointer d; +}; + +QT_END_NAMESPACE + +#endif // QQUICKTHEMEDATA_P_H diff --git a/src/imports/controls/qtquickcontrols2plugin.cpp b/src/imports/controls/qtquickcontrols2plugin.cpp index 9f232c55..ace8455e 100644 --- a/src/imports/controls/qtquickcontrols2plugin.cpp +++ b/src/imports/controls/qtquickcontrols2plugin.cpp @@ -35,7 +35,7 @@ ****************************************************************************/ #include -#include "qquickstyle_p.h" +#include "qquicktheme_p.h" #include #include @@ -107,7 +107,7 @@ void QtQuickControls2Plugin::registerTypes(const char *uri) qmlRegisterUncreatableType(uri, 2, 0, "Exclusive", "Exclusive is an attached property"); qmlRegisterUncreatableType(uri, 2, 0, "Stack", "Stack is an attached property"); - qmlRegisterUncreatableType(uri, 2, 0, "Style", "Style is an attached property"); + qmlRegisterUncreatableType(uri, 2, 0, "Theme", "Theme is an attached property"); qmlRegisterUncreatableType(uri, 2, 0, "Tab", "Tab is an attached property"); qmlRegisterType(uri, 2, 0, "Control"); diff --git a/src/imports/controls/qtquickcontrols2plugin.qrc b/src/imports/controls/qtquickcontrols2plugin.qrc index 76d81809..64ba7018 100644 --- a/src/imports/controls/qtquickcontrols2plugin.qrc +++ b/src/imports/controls/qtquickcontrols2plugin.qrc @@ -1,6 +1,6 @@ - style.json + theme.json images/spinner_small.png diff --git a/src/imports/controls/style.json b/src/imports/controls/style.json deleted file mode 100644 index a1a79969..00000000 --- a/src/imports/controls/style.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "accentColor": "#7bc258", - "backgroundColor": "#ffffff", - "baseColor": "#eeeeee", - "focusColor": "#45a7d7", - "frameColor": "#bdbebf", - "pressColor": "#33333333", - "selectedTextColor": "#ffffff", - "selectionColor": "#45a7d7", - "shadowColor": "#28282a", - "textColor": "#26282a", - "padding": 6, - "roundness": 3, - "disabledOpacity": 0.3, - "spacing": 6 -} diff --git a/src/imports/controls/theme.json b/src/imports/controls/theme.json new file mode 100644 index 00000000..a1a79969 --- /dev/null +++ b/src/imports/controls/theme.json @@ -0,0 +1,16 @@ +{ + "accentColor": "#7bc258", + "backgroundColor": "#ffffff", + "baseColor": "#eeeeee", + "focusColor": "#45a7d7", + "frameColor": "#bdbebf", + "pressColor": "#33333333", + "selectedTextColor": "#ffffff", + "selectionColor": "#45a7d7", + "shadowColor": "#28282a", + "textColor": "#26282a", + "padding": 6, + "roundness": 3, + "disabledOpacity": 0.3, + "spacing": 6 +} diff --git a/src/imports/extras/Drawer.qml b/src/imports/extras/Drawer.qml index b1347142..a62a3d14 100644 --- a/src/imports/extras/Drawer.qml +++ b/src/imports/extras/Drawer.qml @@ -45,8 +45,8 @@ AbstractDrawer { height: parent.height // TODO: Window.height background: Rectangle { - color: control.Style.shadowColor - opacity: position * control.Style.disabledOpacity + color: control.Theme.shadowColor + opacity: position * control.Theme.disabledOpacity } // TODO: make this a proper transition diff --git a/tests/auto/controls/data/tst_style.qml b/tests/auto/controls/data/tst_style.qml deleted file mode 100644 index b6a6deec..00000000 --- a/tests/auto/controls/data/tst_style.qml +++ /dev/null @@ -1,304 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.2 -import QtQuick.Window 2.2 -import QtTest 1.0 -import QtQuick.Controls 2.0 - -TestCase { - id: testCase - width: 200 - height: 200 - visible: true - when: windowShown - name: "Style" - - Component { - id: button - Button { } - } - - Component { - id: styledButton - Button { - Style.accentColor: "#111111" - Style.backgroundColor: "#222222" - Style.baseColor: "#333333" - Style.focusColor: "#444444" - Style.frameColor: "#555555" - Style.pressColor: "#666666" - Style.selectedTextColor: "#777777" - Style.selectionColor: "#888888" - Style.textColor: "#999999" - Style.padding: 111 - Style.roundness: 222 - Style.spacing: 333 - Style.disabledOpacity: 0.123 - } - } - - Component { - id: window - Window { } - } - - Component { - id: styledWindow - Window { - Style.accentColor: "#111111" - Style.backgroundColor: "#222222" - Style.baseColor: "#333333" - Style.focusColor: "#444444" - Style.frameColor: "#555555" - Style.pressColor: "#666666" - Style.selectedTextColor: "#777777" - Style.selectionColor: "#888888" - Style.textColor: "#999999" - Style.padding: 111 - Style.roundness: 222 - Style.spacing: 333 - Style.disabledOpacity: 0.123 - } - } - - Component { - id: loader - Loader { - active: false - sourceComponent: Button { } - } - } - - function test_defaults() { - var control = button.createObject(testCase) - verify(control) - verify(control.Style) - verify(control.Style.accentColor !== undefined) - verify(control.Style.backgroundColor !== undefined) - verify(control.Style.baseColor !== undefined) - verify(control.Style.focusColor !== undefined) - verify(control.Style.frameColor !== undefined) - verify(control.Style.pressColor !== undefined) - verify(control.Style.selectedTextColor !== undefined) - verify(control.Style.selectionColor !== undefined) - verify(control.Style.textColor !== undefined) - verify(control.Style.padding !== undefined) - verify(control.Style.roundness !== undefined) - verify(control.Style.spacing !== undefined) - verify(control.Style.disabledOpacity !== undefined) - control.destroy() - } - - function test_set() { - var control = button.createObject(testCase) - verify(control) - control.Style.accentColor = "#111111" - control.Style.backgroundColor = "#222222" - control.Style.baseColor = "#333333" - control.Style.focusColor = "#444444" - control.Style.frameColor = "#555555" - control.Style.pressColor = "#666666" - control.Style.selectedTextColor = "#777777" - control.Style.selectionColor = "#888888" - control.Style.textColor = "#999999" - control.Style.padding = 111 - control.Style.roundness = 222 - control.Style.spacing = 333 - control.Style.disabledOpacity = 0.123 - compare(control.Style.accentColor, "#111111") - compare(control.Style.backgroundColor, "#222222") - compare(control.Style.baseColor, "#333333") - compare(control.Style.focusColor, "#444444") - compare(control.Style.frameColor, "#555555") - compare(control.Style.pressColor, "#666666") - compare(control.Style.selectedTextColor, "#777777") - compare(control.Style.selectionColor, "#888888") - compare(control.Style.textColor, "#999999") - compare(control.Style.padding, 111) - compare(control.Style.roundness, 222) - compare(control.Style.spacing, 333) - compare(control.Style.disabledOpacity, 0.123) - control.destroy() - } - - function test_reset() { - var control = styledButton.createObject(testCase) - verify(control) - compare(control.Style.accentColor, "#111111") - compare(control.Style.backgroundColor, "#222222") - compare(control.Style.baseColor, "#333333") - compare(control.Style.focusColor, "#444444") - compare(control.Style.frameColor, "#555555") - compare(control.Style.pressColor, "#666666") - compare(control.Style.selectedTextColor, "#777777") - compare(control.Style.selectionColor, "#888888") - compare(control.Style.textColor, "#999999") - compare(control.Style.padding, 111) - compare(control.Style.roundness, 222) - compare(control.Style.spacing, 333) - compare(control.Style.disabledOpacity, 0.123) - control.Style.accentColor = undefined - control.Style.backgroundColor = undefined - control.Style.baseColor = undefined - control.Style.focusColor = undefined - control.Style.frameColor = undefined - control.Style.pressColor = undefined - control.Style.selectedTextColor = undefined - control.Style.selectionColor = undefined - control.Style.textColor = undefined - control.Style.padding = undefined - control.Style.roundness = undefined - control.Style.spacing = undefined - control.Style.disabledOpacity = undefined - compare(control.Style.accentColor, testCase.Style.accentColor) - compare(control.Style.backgroundColor, testCase.Style.backgroundColor) - compare(control.Style.baseColor, testCase.Style.baseColor) - compare(control.Style.focusColor, testCase.Style.focusColor) - compare(control.Style.frameColor, testCase.Style.frameColor) - compare(control.Style.pressColor, testCase.Style.pressColor) - compare(control.Style.selectedTextColor, testCase.Style.selectedTextColor) - compare(control.Style.selectionColor, testCase.Style.selectionColor) - compare(control.Style.textColor, testCase.Style.textColor) - compare(control.Style.padding, testCase.Style.padding) - compare(control.Style.roundness, testCase.Style.roundness) - compare(control.Style.spacing, testCase.Style.spacing) - compare(control.Style.disabledOpacity, testCase.Style.disabledOpacity) - control.destroy() - } - - function test_inheritance_data() { - return [ - { tag: "accentColor", value1: "#111111", value2: "#101010" }, - { tag: "backgroundColor", value1: "#222222", value2: "#202020" }, - { tag: "baseColor", value1: "#333333", value2: "#303030" }, - { tag: "focusColor", value1: "#444444", value2: "#404040" }, - { tag: "frameColor", value1: "#555555", value2: "#505050" }, - { tag: "pressColor", value1: "#666666", value2: "#606060" }, - { tag: "selectedTextColor", value1: "#777777", value2: "#707070" }, - { tag: "selectionColor", value1: "#888888", value2: "#808080" }, - { tag: "textColor", value1: "#999999", value2: "#909090" }, - { tag: "padding", value1: 11, value2: 10 }, - { tag: "roundness", value1: 22, value2: 20 }, - { tag: "spacing", value1: 33, value2: 30 }, - { tag: "disabledOpacity", value1: 0.123, value2: 0.345 } - ] - } - - function test_inheritance(data) { - var prop = data.tag - var parent = button.createObject(testCase) - parent.Style[prop] = data.value1 - compare(parent.Style[prop], data.value1) - - var child1 = button.createObject(parent) - compare(child1.Style[prop], data.value1) - - parent.Style[prop] = data.value2 - compare(parent.Style[prop], data.value2) - compare(child1.Style[prop], data.value2) - - var child2 = button.createObject(parent) - compare(child2.Style[prop], data.value2) - - child2.Style[prop] = data.value1 - compare(child2.Style[prop], data.value1) - compare(child1.Style[prop], data.value2) - compare(parent.Style[prop], data.value2) - - parent.Style[prop] = undefined - verify(parent.Style[prop] !== data.value1) - verify(parent.Style[prop] !== data.value2) - verify(parent.Style[prop] !== undefined) - compare(child1.Style[prop], parent.Style[prop]) - verify(child2.Style[prop] !== parent.Style[prop]) - - var grandChild1 = button.createObject(child1) - var grandChild2 = button.createObject(child2) - compare(grandChild1.Style[prop], child1.Style[prop]) - compare(grandChild2.Style[prop], child2.Style[prop]) - - var stylelessGrandGrandChild = button.createObject(grandChild1) - var grandGrandGrandChild1 = button.createObject(stylelessGrandGrandChild) - compare(grandGrandGrandChild1.Style[prop], parent.Style[prop]) - - child1.Style[prop] = data.value2 - verify(parent.Style[prop] !== data.value2) - compare(child1.Style[prop], data.value2) - compare(grandChild1.Style[prop], data.value2) - compare(grandGrandGrandChild1.Style[prop], data.value2) - - parent.destroy() - } - - function test_window() { - var parent = window.createObject() - - var control = button.createObject(parent.contentItem) - compare(control.Style.backgroundColor, parent.Style.backgroundColor) - - var styledChild = styledWindow.createObject(window) - verify(styledChild.Style.backgroundColor !== parent.Style.backgroundColor) - - var unstyledChild = window.createObject(window) - compare(unstyledChild.Style.backgroundColor, parent.Style.backgroundColor) - - parent.Style.backgroundColor = "#123456" - compare(control.Style.backgroundColor, "#123456") - verify(styledChild.Style.backgroundColor !== "#123456") - // ### FIXME: compare(unstyledChild.Style.backgroundColor, "#123456") - - parent.destroy() - } - - function test_loader() { - var control = loader.createObject(testCase) - control.Style.accentColor = "#111111" - control.active = true - compare(control.item.Style.accentColor, "#111111") - control.Style.accentColor = "#222222" - compare(control.item.Style.accentColor, "#222222") - control.active = false - control.Style.accentColor = "#333333" - control.active = true - compare(control.item.Style.accentColor, "#333333") - control.destroy() - } -} diff --git a/tests/auto/controls/data/tst_theme.qml b/tests/auto/controls/data/tst_theme.qml new file mode 100644 index 00000000..239d4914 --- /dev/null +++ b/tests/auto/controls/data/tst_theme.qml @@ -0,0 +1,304 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtQuick.Window 2.2 +import QtTest 1.0 +import QtQuick.Controls 2.0 + +TestCase { + id: testCase + width: 200 + height: 200 + visible: true + when: windowShown + name: "Theme" + + Component { + id: button + Button { } + } + + Component { + id: themedButton + Button { + Theme.accentColor: "#111111" + Theme.backgroundColor: "#222222" + Theme.baseColor: "#333333" + Theme.focusColor: "#444444" + Theme.frameColor: "#555555" + Theme.pressColor: "#666666" + Theme.selectedTextColor: "#777777" + Theme.selectionColor: "#888888" + Theme.textColor: "#999999" + Theme.padding: 111 + Theme.roundness: 222 + Theme.spacing: 333 + Theme.disabledOpacity: 0.123 + } + } + + Component { + id: window + Window { } + } + + Component { + id: themedWindow + Window { + Theme.accentColor: "#111111" + Theme.backgroundColor: "#222222" + Theme.baseColor: "#333333" + Theme.focusColor: "#444444" + Theme.frameColor: "#555555" + Theme.pressColor: "#666666" + Theme.selectedTextColor: "#777777" + Theme.selectionColor: "#888888" + Theme.textColor: "#999999" + Theme.padding: 111 + Theme.roundness: 222 + Theme.spacing: 333 + Theme.disabledOpacity: 0.123 + } + } + + Component { + id: loader + Loader { + active: false + sourceComponent: Button { } + } + } + + function test_defaults() { + var control = button.createObject(testCase) + verify(control) + verify(control.Theme) + verify(control.Theme.accentColor !== undefined) + verify(control.Theme.backgroundColor !== undefined) + verify(control.Theme.baseColor !== undefined) + verify(control.Theme.focusColor !== undefined) + verify(control.Theme.frameColor !== undefined) + verify(control.Theme.pressColor !== undefined) + verify(control.Theme.selectedTextColor !== undefined) + verify(control.Theme.selectionColor !== undefined) + verify(control.Theme.textColor !== undefined) + verify(control.Theme.padding !== undefined) + verify(control.Theme.roundness !== undefined) + verify(control.Theme.spacing !== undefined) + verify(control.Theme.disabledOpacity !== undefined) + control.destroy() + } + + function test_set() { + var control = button.createObject(testCase) + verify(control) + control.Theme.accentColor = "#111111" + control.Theme.backgroundColor = "#222222" + control.Theme.baseColor = "#333333" + control.Theme.focusColor = "#444444" + control.Theme.frameColor = "#555555" + control.Theme.pressColor = "#666666" + control.Theme.selectedTextColor = "#777777" + control.Theme.selectionColor = "#888888" + control.Theme.textColor = "#999999" + control.Theme.padding = 111 + control.Theme.roundness = 222 + control.Theme.spacing = 333 + control.Theme.disabledOpacity = 0.123 + compare(control.Theme.accentColor, "#111111") + compare(control.Theme.backgroundColor, "#222222") + compare(control.Theme.baseColor, "#333333") + compare(control.Theme.focusColor, "#444444") + compare(control.Theme.frameColor, "#555555") + compare(control.Theme.pressColor, "#666666") + compare(control.Theme.selectedTextColor, "#777777") + compare(control.Theme.selectionColor, "#888888") + compare(control.Theme.textColor, "#999999") + compare(control.Theme.padding, 111) + compare(control.Theme.roundness, 222) + compare(control.Theme.spacing, 333) + compare(control.Theme.disabledOpacity, 0.123) + control.destroy() + } + + function test_reset() { + var control = themedButton.createObject(testCase) + verify(control) + compare(control.Theme.accentColor, "#111111") + compare(control.Theme.backgroundColor, "#222222") + compare(control.Theme.baseColor, "#333333") + compare(control.Theme.focusColor, "#444444") + compare(control.Theme.frameColor, "#555555") + compare(control.Theme.pressColor, "#666666") + compare(control.Theme.selectedTextColor, "#777777") + compare(control.Theme.selectionColor, "#888888") + compare(control.Theme.textColor, "#999999") + compare(control.Theme.padding, 111) + compare(control.Theme.roundness, 222) + compare(control.Theme.spacing, 333) + compare(control.Theme.disabledOpacity, 0.123) + control.Theme.accentColor = undefined + control.Theme.backgroundColor = undefined + control.Theme.baseColor = undefined + control.Theme.focusColor = undefined + control.Theme.frameColor = undefined + control.Theme.pressColor = undefined + control.Theme.selectedTextColor = undefined + control.Theme.selectionColor = undefined + control.Theme.textColor = undefined + control.Theme.padding = undefined + control.Theme.roundness = undefined + control.Theme.spacing = undefined + control.Theme.disabledOpacity = undefined + compare(control.Theme.accentColor, testCase.Theme.accentColor) + compare(control.Theme.backgroundColor, testCase.Theme.backgroundColor) + compare(control.Theme.baseColor, testCase.Theme.baseColor) + compare(control.Theme.focusColor, testCase.Theme.focusColor) + compare(control.Theme.frameColor, testCase.Theme.frameColor) + compare(control.Theme.pressColor, testCase.Theme.pressColor) + compare(control.Theme.selectedTextColor, testCase.Theme.selectedTextColor) + compare(control.Theme.selectionColor, testCase.Theme.selectionColor) + compare(control.Theme.textColor, testCase.Theme.textColor) + compare(control.Theme.padding, testCase.Theme.padding) + compare(control.Theme.roundness, testCase.Theme.roundness) + compare(control.Theme.spacing, testCase.Theme.spacing) + compare(control.Theme.disabledOpacity, testCase.Theme.disabledOpacity) + control.destroy() + } + + function test_inheritance_data() { + return [ + { tag: "accentColor", value1: "#111111", value2: "#101010" }, + { tag: "backgroundColor", value1: "#222222", value2: "#202020" }, + { tag: "baseColor", value1: "#333333", value2: "#303030" }, + { tag: "focusColor", value1: "#444444", value2: "#404040" }, + { tag: "frameColor", value1: "#555555", value2: "#505050" }, + { tag: "pressColor", value1: "#666666", value2: "#606060" }, + { tag: "selectedTextColor", value1: "#777777", value2: "#707070" }, + { tag: "selectionColor", value1: "#888888", value2: "#808080" }, + { tag: "textColor", value1: "#999999", value2: "#909090" }, + { tag: "padding", value1: 11, value2: 10 }, + { tag: "roundness", value1: 22, value2: 20 }, + { tag: "spacing", value1: 33, value2: 30 }, + { tag: "disabledOpacity", value1: 0.123, value2: 0.345 } + ] + } + + function test_inheritance(data) { + var prop = data.tag + var parent = button.createObject(testCase) + parent.Theme[prop] = data.value1 + compare(parent.Theme[prop], data.value1) + + var child1 = button.createObject(parent) + compare(child1.Theme[prop], data.value1) + + parent.Theme[prop] = data.value2 + compare(parent.Theme[prop], data.value2) + compare(child1.Theme[prop], data.value2) + + var child2 = button.createObject(parent) + compare(child2.Theme[prop], data.value2) + + child2.Theme[prop] = data.value1 + compare(child2.Theme[prop], data.value1) + compare(child1.Theme[prop], data.value2) + compare(parent.Theme[prop], data.value2) + + parent.Theme[prop] = undefined + verify(parent.Theme[prop] !== data.value1) + verify(parent.Theme[prop] !== data.value2) + verify(parent.Theme[prop] !== undefined) + compare(child1.Theme[prop], parent.Theme[prop]) + verify(child2.Theme[prop] !== parent.Theme[prop]) + + var grandChild1 = button.createObject(child1) + var grandChild2 = button.createObject(child2) + compare(grandChild1.Theme[prop], child1.Theme[prop]) + compare(grandChild2.Theme[prop], child2.Theme[prop]) + + var themelessGrandGrandChild = button.createObject(grandChild1) + var grandGrandGrandChild1 = button.createObject(themelessGrandGrandChild) + compare(grandGrandGrandChild1.Theme[prop], parent.Theme[prop]) + + child1.Theme[prop] = data.value2 + verify(parent.Theme[prop] !== data.value2) + compare(child1.Theme[prop], data.value2) + compare(grandChild1.Theme[prop], data.value2) + compare(grandGrandGrandChild1.Theme[prop], data.value2) + + parent.destroy() + } + + function test_window() { + var parent = window.createObject() + + var control = button.createObject(parent.contentItem) + compare(control.Theme.backgroundColor, parent.Theme.backgroundColor) + + var themedChild = themedWindow.createObject(window) + verify(themedChild.Theme.backgroundColor !== parent.Theme.backgroundColor) + + var unthemedChild = window.createObject(window) + compare(unthemedChild.Theme.backgroundColor, parent.Theme.backgroundColor) + + parent.Theme.backgroundColor = "#123456" + compare(control.Theme.backgroundColor, "#123456") + verify(themedChild.Theme.backgroundColor !== "#123456") + // ### FIXME: compare(unthemedChild.Theme.backgroundColor, "#123456") + + parent.destroy() + } + + function test_loader() { + var control = loader.createObject(testCase) + control.Theme.accentColor = "#111111" + control.active = true + compare(control.item.Theme.accentColor, "#111111") + control.Theme.accentColor = "#222222" + compare(control.item.Theme.accentColor, "#222222") + control.active = false + control.Theme.accentColor = "#333333" + control.active = true + compare(control.item.Theme.accentColor, "#333333") + control.destroy() + } +} -- cgit v1.2.3