diff options
author | J-P Nurmi <jpnurmi@digia.com> | 2014-06-18 21:28:33 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@digia.com> | 2014-06-23 09:14:24 +0200 |
commit | 266fab2a8920dc79e52555b81cf1708233c1b60f (patch) | |
tree | 4829c6903c95f7582abdfbb1265cf50c98381e35 /src/controls | |
parent | 9578edd239f4f1e33d2bf5c044b1bf80ab2c595d (diff) | |
download | qtquickcontrols-266fab2a8920dc79e52555b81cf1708233c1b60f.tar.gz |
Singleton SystemPalette
Each SystemPalette instance installs an event filter on the
application object. Avoid this by sharing a single SystemPalette
instance.
Change-Id: Ica9f8979b33e511c1238add3d689f380d0daa93c
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
Reviewed-by: Caroline Chao <caroline.chao@digia.com>
Diffstat (limited to 'src/controls')
26 files changed, 111 insertions, 55 deletions
diff --git a/src/controls/ApplicationWindow.qml b/src/controls/ApplicationWindow.qml index fa9225be..240965c4 100644 --- a/src/controls/ApplicationWindow.qml +++ b/src/controls/ApplicationWindow.qml @@ -182,7 +182,7 @@ Window { /*! \internal */ default property alias data: contentArea.data - color: syspal.window + color: SystemPaletteSingleton.window(true) flags: Qt.Window | Qt.WindowFullscreenButtonHint | Qt.WindowTitleHint | Qt.WindowSystemMenuHint | Qt.WindowMinMaxButtonsHint | @@ -190,8 +190,6 @@ Window { // QTBUG-35049: Windows is removing features we didn't ask for, even though Qt::CustomizeWindowHint is not set // Otherwise Qt.Window | Qt.WindowFullscreenButtonHint would be enough - SystemPalette {id: syspal} - Item { id: backgroundItem anchors.fill: parent diff --git a/src/controls/ComboBox.qml b/src/controls/ComboBox.qml index 07d98876..9cb2a9f4 100644 --- a/src/controls/ComboBox.qml +++ b/src/controls/ComboBox.qml @@ -360,9 +360,9 @@ Control { renderType: __style ? __style.renderType : Text.NativeRendering selectByMouse: true - color: __style.__syspal.text - selectionColor: __style.__syspal.highlight - selectedTextColor: __style.__syspal.highlightedText + color: SystemPaletteSingleton.text(enabled) + selectionColor: SystemPaletteSingleton.highlight(enabled) + selectedTextColor: SystemPaletteSingleton.highlightedText(enabled) onAccepted: { var idx = input.find(editText, Qt.MatchFixedString) if (idx > -1) { diff --git a/src/controls/Private/Style.qml b/src/controls/Private/Style.qml index e99db169..53497517 100644 --- a/src/controls/Private/Style.qml +++ b/src/controls/Private/Style.qml @@ -50,10 +50,4 @@ import QtQuick.Controls.Private 1.0 AbstractStyle { /*! The control attached to this style */ readonly property Item control: __control - - /*! \internal */ - property var __syspal: SystemPalette { - colorGroup: control.enabled ? - SystemPalette.Active : SystemPalette.Disabled - } } diff --git a/src/controls/Private/SystemPaletteSingleton.qml b/src/controls/Private/SystemPaletteSingleton.qml new file mode 100644 index 00000000..9354af03 --- /dev/null +++ b/src/controls/Private/SystemPaletteSingleton.qml @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 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 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +pragma Singleton +import QtQuick 2.2 + +QtObject { + property SystemPalette active: SystemPalette { colorGroup: SystemPalette.Active } + property SystemPalette disabled: SystemPalette { colorGroup: SystemPalette.Disabled } + + function alternateBase(enabled) { return enabled ? active.alternateBase : disabled.alternateBase } + function base(enabled) { return enabled ? active.base : disabled.base } + function button(enabled) { return enabled ? active.button : disabled.button } + function buttonText(enabled) { return enabled ? active.buttonText : disabled.buttonText } + function dark(enabled) { return enabled ? active.dark : disabled.dark } + function highlight(enabled) { return enabled ? active.highlight : disabled.highlight } + function highlightedText(enabled) { return enabled ? active.highlightedText : disabled.highlightedText } + function light(enabled) { return enabled ? active.light : disabled.light } + function mid(enabled) { return enabled ? active.mid : disabled.mid } + function midlight(enabled) { return enabled ? active.midlight : disabled.midlight } + function shadow(enabled) { return enabled ? active.shadow : disabled.shadow } + function text(enabled) { return enabled ? active.text : disabled.text } + function window(enabled) { return enabled ? active.window : disabled.window } + function windowText(enabled) { return enabled ? active.windowText : disabled.windowText } +} diff --git a/src/controls/Private/private.pri b/src/controls/Private/private.pri index f9446854..b530a229 100644 --- a/src/controls/Private/private.pri +++ b/src/controls/Private/private.pri @@ -46,6 +46,7 @@ PRIVATE_QML_FILES += \ $$PWD/StackView.js \ $$PWD/ScrollViewHelper.qml \ $$PWD/ScrollBar.qml \ + $$PWD/SystemPaletteSingleton.qml \ $$PWD/TableViewSelection.qml \ $$PWD/TextSingleton.qml \ $$PWD/FocusFrame.qml \ diff --git a/src/controls/Private/qmldir b/src/controls/Private/qmldir index d31483e3..f2c572f2 100644 --- a/src/controls/Private/qmldir +++ b/src/controls/Private/qmldir @@ -24,4 +24,5 @@ MenuContentScroller 1.0 MenuContentScroller.qml ColumnMenuContent 1.0 ColumnMenuContent.qml ContentItem 1.0 ContentItem.qml HoverButton 1.0 HoverButton.qml +singleton SystemPaletteSingleton 1.0 SystemPaletteSingleton.qml singleton TextSingleton 1.0 TextSingleton.qml diff --git a/src/controls/Styles/Base/ButtonStyle.qml b/src/controls/Styles/Base/ButtonStyle.qml index 98336964..566f93e5 100644 --- a/src/controls/Styles/Base/ButtonStyle.qml +++ b/src/controls/Styles/Base/ButtonStyle.qml @@ -144,7 +144,7 @@ Style { renderType: Text.NativeRendering anchors.verticalCenter: parent.verticalCenter text: control.text - color: __syspal.buttonText + color: SystemPaletteSingleton.buttonText(control.enabled) } } } diff --git a/src/controls/Styles/Base/CalendarStyle.qml b/src/controls/Styles/Base/CalendarStyle.qml index db007812..56978ded 100644 --- a/src/controls/Styles/Base/CalendarStyle.qml +++ b/src/controls/Styles/Base/CalendarStyle.qml @@ -266,7 +266,7 @@ Style { readonly property bool addExtraMargin: control.frameVisible && styleData.selected readonly property color sameMonthDateTextColor: "#444" - readonly property color selectedDateColor: Qt.platform.os === "osx" ? "#3778d0" : __syspal.highlight + readonly property color selectedDateColor: Qt.platform.os === "osx" ? "#3778d0" : SystemPaletteSingleton.highlight(control.enabled) readonly property color selectedDateTextColor: "white" readonly property color differentMonthDateTextColor: "#bbb" readonly property color invalidDateColor: "#dddddd" diff --git a/src/controls/Styles/Base/CheckBoxStyle.qml b/src/controls/Styles/Base/CheckBoxStyle.qml index 36eeb78f..c8592b76 100644 --- a/src/controls/Styles/Base/CheckBoxStyle.qml +++ b/src/controls/Styles/Base/CheckBoxStyle.qml @@ -100,7 +100,7 @@ Style { id: text text: control.text anchors.centerIn: parent - color: __syspal.text + color: SystemPaletteSingleton.text(control.enabled) renderType: Text.NativeRendering } } diff --git a/src/controls/Styles/Base/ComboBoxStyle.qml b/src/controls/Styles/Base/ComboBoxStyle.qml index 6bf8a391..de78dc02 100644 --- a/src/controls/Styles/Base/ComboBoxStyle.qml +++ b/src/controls/Styles/Base/ComboBoxStyle.qml @@ -168,7 +168,7 @@ Style { anchors.verticalCenter: parent.verticalCenter text: control.currentText renderType: cbStyle.renderType - color: __syspal.text + color: SystemPaletteSingleton.text(control.enabled) elide: Text.ElideRight } } diff --git a/src/controls/Styles/Base/GroupBoxStyle.qml b/src/controls/Styles/Base/GroupBoxStyle.qml index e001fb26..545ca07b 100644 --- a/src/controls/Styles/Base/GroupBoxStyle.qml +++ b/src/controls/Styles/Base/GroupBoxStyle.qml @@ -62,7 +62,7 @@ Style { } /*! The title text color. */ - property color textColor: __syspal.text + property color textColor: SystemPaletteSingleton.text(control.enabled) /*! The check box. */ property Component checkbox: Item { diff --git a/src/controls/Styles/Base/MenuBarStyle.qml b/src/controls/Styles/Base/MenuBarStyle.qml index 5c566b3a..cff2b095 100644 --- a/src/controls/Styles/Base/MenuBarStyle.qml +++ b/src/controls/Styles/Base/MenuBarStyle.qml @@ -105,7 +105,7 @@ Style { text: formatMnemonic(styleData.text, styleData.underlineMnemonic) anchors.centerIn: parent renderType: Text.NativeRendering - color: styleData.open ? "white" : __syspal.windowText + color: styleData.open ? "white" : SystemPaletteSingleton.windowText(control.enabled) } } diff --git a/src/controls/Styles/Base/RadioButtonStyle.qml b/src/controls/Styles/Base/RadioButtonStyle.qml index bedd3dca..86b7c816 100644 --- a/src/controls/Styles/Base/RadioButtonStyle.qml +++ b/src/controls/Styles/Base/RadioButtonStyle.qml @@ -99,7 +99,7 @@ Style { id: text text: control.text anchors.centerIn: parent - color: __syspal.text + color: SystemPaletteSingleton.text(control.enabled) renderType: Text.NativeRendering } } diff --git a/src/controls/Styles/Base/SpinBoxStyle.qml b/src/controls/Styles/Base/SpinBoxStyle.qml index c9df4471..ffd30a58 100644 --- a/src/controls/Styles/Base/SpinBoxStyle.qml +++ b/src/controls/Styles/Base/SpinBoxStyle.qml @@ -87,13 +87,13 @@ Style { property int horizontalAlignment: Qt.AlignRight /*! The text color. */ - property color textColor: __syspal.text + property color textColor: SystemPaletteSingleton.text(control.enabled) /*! The text highlight color, used behind selections. */ - property color selectionColor: __syspal.highlight + property color selectionColor: SystemPaletteSingleton.highlight(control.enabled) /*! The highlighted text color, used in selections. */ - property color selectedTextColor: __syspal.highlightedText + property color selectedTextColor: SystemPaletteSingleton.highlightedText(control.enabled) /*! \qmlproperty enumeration renderType diff --git a/src/controls/Styles/Base/SwitchStyle.qml b/src/controls/Styles/Base/SwitchStyle.qml index 01779582..d5c5cf07 100644 --- a/src/controls/Styles/Base/SwitchStyle.qml +++ b/src/controls/Styles/Base/SwitchStyle.qml @@ -80,8 +80,10 @@ Style { implicitWidth: Math.round((parent.parent.width - padding.left - padding.right)/2) implicitHeight: control.height - padding.top - padding.bottom - border.color: control.activeFocus ? Qt.darker(__syspal.highlight, 2) : Qt.darker(__syspal.button, 2) - property color bg: control.activeFocus ? Qt.darker(__syspal.highlight, 1.2) : __syspal.button + border.color: control.activeFocus ? Qt.darker(highlight, 2) : Qt.darker(button, 2) + property color bg: control.activeFocus ? Qt.darker(highlight, 1.2) : button + property color highlight: SystemPaletteSingleton.highlight(control.enabled) + property color button: SystemPaletteSingleton.button(control.enabled) gradient: Gradient { GradientStop {color: Qt.lighter(bg, 1.4) ; position: 0} GradientStop {color: bg ; position: 1} @@ -92,8 +94,9 @@ Style { /*! This property holds the background groove of the switch. */ property Component groove: Rectangle { - property color shadow: control.checked ? Qt.darker(__syspal.highlight, 1.2): "#999" - property color bg: control.checked ? __syspal.highlight:"#bbb" + property color shadow: control.checked ? Qt.darker(highlight, 1.2): "#999" + property color bg: control.checked ? highlight:"#bbb" + property color highlight: SystemPaletteSingleton.highlight(control.enabled) implicitWidth: Math.round(implicitHeight * 3) implicitHeight: Math.max(16, Math.round(TextSingleton.implicitHeight)) diff --git a/src/controls/Styles/Base/TabViewStyle.qml b/src/controls/Styles/Base/TabViewStyle.qml index 42fabfe4..ad1d3856 100644 --- a/src/controls/Styles/Base/TabViewStyle.qml +++ b/src/controls/Styles/Base/TabViewStyle.qml @@ -168,11 +168,7 @@ Style { elide: Text.ElideMiddle renderType: Text.NativeRendering scale: control.tabPosition === Qt.TopEdge ? 1 : -1 - property var __syspal: SystemPalette { - colorGroup: styleData.enabled ? - SystemPalette.Active : SystemPalette.Disabled - } - color: __syspal.text + color: SystemPaletteSingleton.text(styleData.enabled) Rectangle { anchors.centerIn: parent width: textitem.paintedWidth + 6 diff --git a/src/controls/Styles/Base/TableViewStyle.qml b/src/controls/Styles/Base/TableViewStyle.qml index 5dca6631..b59a38ca 100644 --- a/src/controls/Styles/Base/TableViewStyle.qml +++ b/src/controls/Styles/Base/TableViewStyle.qml @@ -58,10 +58,10 @@ ScrollViewStyle { readonly property TableView control: __control /*! The text color. */ - property color textColor: __syspal.text + property color textColor: SystemPaletteSingleton.text(control.enabled) /*! The background color. */ - property color backgroundColor: control.backgroundVisible ? __syspal.base : "transparent" + property color backgroundColor: control.backgroundVisible ? SystemPaletteSingleton.base(control.enabled) : "transparent" /*! The alternate background color. */ property color alternateBackgroundColor: "#f5f5f5" diff --git a/src/controls/Styles/Base/TextAreaStyle.qml b/src/controls/Styles/Base/TextAreaStyle.qml index 7ad5686f..774f5cc6 100644 --- a/src/controls/Styles/Base/TextAreaStyle.qml +++ b/src/controls/Styles/Base/TextAreaStyle.qml @@ -71,16 +71,16 @@ ScrollViewStyle { property font font /*! The text color. */ - property color textColor: __syspal.text + property color textColor: SystemPaletteSingleton.text(control.enabled) /*! The text highlight color, used behind selections. */ - property color selectionColor: __syspal.highlight + property color selectionColor: SystemPaletteSingleton.highlight(control.enabled) /*! The highlighted text color, used in selections. */ - property color selectedTextColor: __syspal.highlightedText + property color selectedTextColor: SystemPaletteSingleton.highlightedText(control.enabled) /*! The background color. */ - property color backgroundColor: control.backgroundVisible ? __syspal.base : "transparent" + property color backgroundColor: control.backgroundVisible ? SystemPaletteSingleton.base(control.enabled) : "transparent" /*! \qmlproperty enumeration renderType diff --git a/src/controls/Styles/Base/TextFieldStyle.qml b/src/controls/Styles/Base/TextFieldStyle.qml index a0bed38d..4fe0d0a9 100644 --- a/src/controls/Styles/Base/TextFieldStyle.qml +++ b/src/controls/Styles/Base/TextFieldStyle.qml @@ -78,13 +78,13 @@ Style { property font font /*! The text color. */ - property color textColor: __syspal.text + property color textColor: SystemPaletteSingleton.text(control.enabled) /*! The text highlight color, used behind selections. */ - property color selectionColor: __syspal.highlight + property color selectionColor: SystemPaletteSingleton.highlight(control.enabled) /*! The highlighted text color, used in selections. */ - property color selectedTextColor: __syspal.highlightedText + property color selectedTextColor: SystemPaletteSingleton.highlightedText(control.enabled) /*! \qmlproperty enumeration renderType diff --git a/src/controls/Styles/Desktop/CheckBoxStyle.qml b/src/controls/Styles/Desktop/CheckBoxStyle.qml index 6bb33663..456e7e4b 100644 --- a/src/controls/Styles/Desktop/CheckBoxStyle.qml +++ b/src/controls/Styles/Desktop/CheckBoxStyle.qml @@ -74,7 +74,7 @@ Style { renderType: Text.NativeRendering elide: Text.ElideRight enabled: control.enabled - color: __syspal.windowText + color: SystemPaletteSingleton.windowText(control.enabled) StyleItem { elementType: "focusrect" anchors.margins: -1 diff --git a/src/controls/Styles/Desktop/MenuStyle.qml b/src/controls/Styles/Desktop/MenuStyle.qml index 4a0d5894..ecd898cf 100644 --- a/src/controls/Styles/Desktop/MenuStyle.qml +++ b/src/controls/Styles/Desktop/MenuStyle.qml @@ -61,7 +61,7 @@ Style { fill: parent margins: pixelMetric("menupanelwidth") } - color: __syspal.window + color: SystemPaletteSingleton.window(control.enabled) } Accessible.role: Accessible.PopupMenu diff --git a/src/controls/Styles/Desktop/RadioButtonStyle.qml b/src/controls/Styles/Desktop/RadioButtonStyle.qml index 49e3cace..cf1d4091 100644 --- a/src/controls/Styles/Desktop/RadioButtonStyle.qml +++ b/src/controls/Styles/Desktop/RadioButtonStyle.qml @@ -77,7 +77,7 @@ Style { renderType: Text.NativeRendering elide: Text.ElideRight enabled: control.enabled - color: __syspal.windowText + color: SystemPaletteSingleton.windowText(control.enabled) StyleItem { elementType: "focusrect" anchors.margins: -1 diff --git a/src/controls/Styles/Desktop/SpinBoxStyle.qml b/src/controls/Styles/Desktop/SpinBoxStyle.qml index 7896c234..36e84cd4 100644 --- a/src/controls/Styles/Desktop/SpinBoxStyle.qml +++ b/src/controls/Styles/Desktop/SpinBoxStyle.qml @@ -63,10 +63,10 @@ Style { property int horizontalAlignment: Qt.platform.os === "osx" ? Qt.AlignRight : Qt.AlignLeft property int verticalAlignment: Qt.AlignVCenter - property color foregroundColor: __syspal.text - property color backgroundColor: __syspal.base - property color selectionColor: __syspal.highlight - property color selectedTextColor: __syspal.highlightedText + property color foregroundColor: SystemPaletteSingleton.text(control.enabled) + property color backgroundColor: SystemPaletteSingleton.base(control.enabled) + property color selectionColor: SystemPaletteSingleton.highlight(control.enabled) + property color selectedTextColor: SystemPaletteSingleton.highlightedText(control.enabled) property int topPadding: edit.anchors.topMargin property int leftPadding: 3 + edit.anchors.leftMargin diff --git a/src/controls/Styles/Desktop/TableViewStyle.qml b/src/controls/Styles/Desktop/TableViewStyle.qml index 60589e5e..605c62d6 100644 --- a/src/controls/Styles/Desktop/TableViewStyle.qml +++ b/src/controls/Styles/Desktop/TableViewStyle.qml @@ -48,7 +48,7 @@ ScrollViewStyle { readonly property TableView control: __control property bool activateItemOnSingleClick: __styleitem.styleHint("activateItemOnSingleClick") property color textColor: __styleitem.textColor - property color backgroundColor: __syspal.base + property color backgroundColor: SystemPaletteSingleton.base(control.enabled) property color highlightedTextColor: __styleitem.highlightedTextColor property StyleItem __styleitem: StyleItem{ diff --git a/src/controls/Styles/Desktop/TextAreaStyle.qml b/src/controls/Styles/Desktop/TextAreaStyle.qml index 46750c1a..9a177303 100644 --- a/src/controls/Styles/Desktop/TextAreaStyle.qml +++ b/src/controls/Styles/Desktop/TextAreaStyle.qml @@ -43,10 +43,10 @@ import QtQuick.Controls.Private 1.0 ScrollViewStyle { property font font: __styleitem.font - property color textColor: __syspal.text - property color selectionColor: __syspal.highlight - property color selectedTextColor: __syspal.highlightedText - property color backgroundColor: control.backgroundVisible ? __syspal.base : "transparent" + property color textColor: SystemPaletteSingleton.text(control.enabled) + property color selectionColor: SystemPaletteSingleton.highlight(control.enabled) + property color selectedTextColor: SystemPaletteSingleton.highlightedText(control.enabled) + property color backgroundColor: control.backgroundVisible ? SystemPaletteSingleton.base(control.enabled) : "transparent" property StyleItem __styleitem: StyleItem{ elementType: "edit" diff --git a/src/controls/Styles/Desktop/TextFieldStyle.qml b/src/controls/Styles/Desktop/TextFieldStyle.qml index 5c623b80..585df03d 100644 --- a/src/controls/Styles/Desktop/TextFieldStyle.qml +++ b/src/controls/Styles/Desktop/TextFieldStyle.qml @@ -54,10 +54,10 @@ Style { hover: hovered hints: control.styleHints - property color textColor: __syspal.text + property color textColor: SystemPaletteSingleton.text(control.enabled) property color placeholderTextColor: "darkGray" - property color selectionColor: __syspal.highlight - property color selectedTextColor: __syspal.highlightedText + property color selectionColor: SystemPaletteSingleton.highlight(control.enabled) + property color selectedTextColor: SystemPaletteSingleton.highlightedText(control.enabled) property bool rounded: !!hints["rounded"] |