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 --- 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 + 34 files changed, 1375 insertions(+), 1375 deletions(-) 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 (limited to 'src/imports/controls') 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 +} -- cgit v1.2.3