From f7f28017634f21beb1b4120c74832ddddb9f4518 Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig <jens.bache-wiig@digia.com> Date: Sun, 10 Feb 2013 16:10:43 +0100 Subject: [PATCH] Style cleanups Introducing new Control and Style items to share some code and making sure no styles are Items. Change-Id: Iced031dc03803c381a39d6b4d1987ba4890ec2ef Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com> --- examples/gallery/content/Controls.qml | 3 + examples/gallery/content/Styles.qml | 29 ++++-- src/private/BasicButton.qml | 19 +--- src/private/Control.qml | 78 +++++++++++++++ src/private/ScrollBar.qml | 53 +++++----- src/private/private.pro | 4 + src/private/qmldir | 1 + src/qtdesktop/Button.qml | 7 +- src/qtdesktop/CheckBox.qml | 21 +--- src/qtdesktop/ComboBox.qml | 3 - src/qtdesktop/ProgressBar.qml | 24 ++--- src/qtdesktop/Slider.qml | 21 +--- src/qtdesktop/SpinBox.qml | 46 +++------ src/qtdesktop/TextField.qml | 38 +++----- src/qtdesktop/ToolButton.qml | 7 +- src/styles/ButtonStyle.qml | 59 ++++++++---- src/styles/CheckBoxStyle.qml | 57 ++++++----- src/styles/ComboBoxStyle.qml | 3 +- src/styles/Desktop/ButtonStyle.qml | 14 +-- src/styles/Desktop/CheckBoxStyle.qml | 56 ++++++----- src/styles/Desktop/ComboBoxStyle.qml | 44 +++++---- src/styles/Desktop/ProgressBarStyle.qml | 32 +++--- src/styles/Desktop/RadioButtonStyle.qml | 55 ++++++----- src/styles/Desktop/SliderStyle.qml | 34 ++++--- src/styles/Desktop/SpinBoxStyle.qml | 123 ++++++++++++------------ src/styles/Desktop/TabFrameStyle.qml | 5 +- src/styles/Desktop/TextFieldStyle.qml | 63 ++++++------ src/styles/Desktop/ToolButtonStyle.qml | 49 ++++++---- src/styles/ProgressBarStyle.qml | 24 +++-- src/styles/RadioButtonStyle.qml | 73 ++++++++------ src/styles/ScrollBarStyle.qml | 2 +- src/styles/SliderStyle.qml | 40 ++++---- src/styles/SpinBoxStyle.qml | 90 ++++++++++------- src/styles/Style.qml | 42 ++++++++ src/styles/TabFrameStyle.qml | 5 +- src/styles/TextFieldStyle.qml | 51 ++++++---- src/styles/qmldir | 2 +- src/styles/styles.pro | 1 + 38 files changed, 739 insertions(+), 539 deletions(-) create mode 100644 src/private/Control.qml create mode 100644 src/styles/Style.qml diff --git a/examples/gallery/content/Controls.qml b/examples/gallery/content/Controls.qml index 10a916c6c..844e39424 100644 --- a/examples/gallery/content/Controls.qml +++ b/examples/gallery/content/Controls.qml @@ -99,6 +99,7 @@ Item { id: t3 KeyNavigation.tab: slider placeholderText: "This is a placeholder for a TextField" + width: 200 } ProgressBar { // normalize value [0.0 .. 1.0] @@ -128,6 +129,7 @@ Item { text: "Text frame" checked: true KeyNavigation.tab: tickmarkCheck + width: 100 } CheckBox { id: tickmarkCheck @@ -150,6 +152,7 @@ Item { KeyNavigation.tab: r2 checked: true exclusiveGroup: tabPositionGroup + width: 100 } RadioButton { id: r2 diff --git a/examples/gallery/content/Styles.qml b/examples/gallery/content/Styles.qml index 3f3ea1fec..cf7813fdb 100644 --- a/examples/gallery/content/Styles.qml +++ b/examples/gallery/content/Styles.qml @@ -137,6 +137,18 @@ Item { } } + Row { + spacing: 8 + CheckBox { + text: "CheckBox" + style: CheckBoxStyle{} + } + RadioButton { + style: RadioButtonStyle{} + text: "RadioButton" + } + } + Row { TabFrame { width: 400 @@ -153,9 +165,9 @@ Item { // Style delegates: property Component buttonStyle: ButtonStyle { - implicitHeight: 20 - implicitWidth: 100 background: Rectangle { + implicitHeight: 20 + implicitWidth: 100 color: control.pressed ? "darkGray" : "lightGray" antialiasing: true border.color: "gray" @@ -164,9 +176,9 @@ Item { } property Component textfieldStyle: TextFieldStyle { - implicitWidth: 100 - implicitHeight: 20 background: Rectangle { + implicitWidth: 100 + implicitHeight: 20 color: "#f0f0f0" antialiasing: true border.color: "gray" @@ -175,9 +187,6 @@ Item { } property Component sliderStyle: SliderStyle { - implicitWidth: 100 - implicitHeight: 20 - handle: Rectangle { width: 14 height: 14 @@ -189,6 +198,9 @@ Item { background: Rectangle { height: 8 + implicitWidth: 100 + implicitHeight: 20 + antialiasing: true color: "darkGray" border.color: "gray" @@ -219,6 +231,7 @@ Item { radius: height/2 } } + property Component tabFrameStyle: TabFrameStyle { tabOverlap: 16 leftMargin: 12 @@ -232,7 +245,7 @@ Item { anchors.fill: parent anchors.topMargin: -4 border.color: "#898989" - Rectangle { anchors.fill: parent ; anchors.margins: 1 ; border.color: "white" ; color: "transparent" } + Rectangle { anchors.fill: parent ; anchors.margins: 1 ; border.color: "white" ; color: "transparent" } } } tab: Item { diff --git a/src/private/BasicButton.qml b/src/private/BasicButton.qml index d848ebbd6..db2229c35 100644 --- a/src/private/BasicButton.qml +++ b/src/private/BasicButton.qml @@ -40,6 +40,7 @@ import QtQuick 2.0 import QtDesktop.Private 1.0 +import QtDesktop.Styles 1.0 /*! \qmltype BasicButton @@ -47,7 +48,8 @@ import QtDesktop.Private 1.0 \qmlabstract \inqmlmodule QtDesktop.Private 1.0 */ -Item { + +Control { id: button signal clicked @@ -56,8 +58,6 @@ Item { property alias checkable: behavior.checkable // button toggles between checked and !checked property alias checked: behavior.checked property bool activeFocusOnPress: false - property alias style: loader.sourceComponent - property var styleHints: [] property color textColor: syspal.text property string tooltip @@ -68,10 +68,7 @@ Item { signal toolTipTriggered // implementation - property string __position: "only" - implicitWidth: loader.implicitWidth - implicitHeight: loader.implicitHeight Keys.onPressed: { if (event.key === Qt.Key_Space && !event.isAutoRepeat && !behavior.pressed) @@ -87,16 +84,6 @@ Item { } } - Loader { - id: loader - anchors.fill: parent - sourceComponent: style - property alias control: button - property alias position: button.__position - height: item ? item.implicitHeight : 0 - width: item ? item.implicitWidth : 0 - } - ButtonBehavior { id: behavior anchors.fill: parent diff --git a/src/private/Control.qml b/src/private/Control.qml new file mode 100644 index 000000000..1cf753826 --- /dev/null +++ b/src/private/Control.qml @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Components project. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.0 +import QtDesktop.Styles 1.0 + +FocusScope { + id: root + + property Component style + + /* \internal */ + property Style __style: styleLoader.item + + /* \internal */ + property Item __panel: panelLoader.item + + /* \internal */ + property var styleHints: [] + + /* \internal */ + implicitWidth: __panel ? __panel.implicitWidth: 0 + + /* \internal */ + implicitHeight: __panel ? __panel.implicitHeight: 0 + + Loader { + id: panelLoader + anchors.fill: parent + sourceComponent: __style ? __style.panel : null + property alias control: root + onStatusChanged: if (status === Loader.Error) print("Failed to load panel for " + root) + Loader { + id: styleLoader + sourceComponent: style + onStatusChanged: { + if (status === Loader.Error) + print("Failed to load Style for " + root) + } + } + } +} diff --git a/src/private/ScrollBar.qml b/src/private/ScrollBar.qml index 84cf1fd4f..9d48a6022 100644 --- a/src/private/ScrollBar.qml +++ b/src/private/ScrollBar.qml @@ -54,29 +54,33 @@ Item { property int orientation: Qt.Horizontal property alias minimumValue: slider.minimumValue property alias maximumValue: slider.maximumValue - property int pageStep: internal.horizontal ? width : height - property int singleStep: 20 property alias value: slider.value - property bool scrollToClickposition: internal.scrollToClickPosition - - Accessible.role: Accessible.ScrollBar - implicitWidth: loader.implicitWidth - implicitHeight: loader.implicitHeight property Component style: Qt.createComponent("../" + Settings.THEME_PATH + "/ScrollBarStyle.qml", scrollbar) property alias styleItem: loader.item - property bool upPressed - property bool downPressed - property bool handlePressed + Accessible.role: Accessible.ScrollBar + implicitWidth: loader.implicitWidth + implicitHeight: loader.implicitHeight - property bool pageUpPressed - property bool pageDownPressed + readonly property alias upPressed: internal.upPressed + readonly property alias downPressed: internal.downPressed + readonly property alias pageUpPressed: internal.pageUpPressed + readonly property alias pageDownPressed: internal.pageDownPressed MouseArea { id: internal + property bool upPressed + property bool downPressed + property bool pageUpPressed + property bool pageDownPressed + property bool handlePressed + property bool horizontal: orientation === Qt.Horizontal + property int pageStep: internal.horizontal ? width : height + property int singleStep: 20 + property bool scrollToClickposition: internal.scrollToClickPosition anchors.fill: parent @@ -123,42 +127,43 @@ Item { onPressed: { control = styleItem.hitTest(mouseX, mouseY) scrollToClickposition = scrollToClickPosition + var handleRect = styleItem.subControlRect("handle") grooveSize = horizontal ? styleItem.subControlRect("groove").width - - styleItem.subControlRect("handle").width: + handleRect.width: styleItem.subControlRect("groove").height - - styleItem.subControlRect("handle").height; + handleRect.height; if (control == "handle") { pressedX = mouseX pressedY = mouseY - handlePressed = true + internal.handlePressed = true oldPosition = slider.position } else if (control == "up") { decrement(); - upPressed = true + internal.upPressed = true } else if (control == "down") { increment(); - downPressed = true + internal.downPressed = true } else if (!scrollToClickposition){ if (control == "upPage") { decrementPage(); - pageUpPressed = true + internal.pageUpPressed = true } else if (control == "downPage") { incrementPage(); - pageDownPressed = true + internal.pageDownPressed = true } } else { - slider.position = horizontal ? mouseX - handleRect.width/2 + slider.position = horizontal ? mouseX - handleRect.width/2 : mouseY - handleRect.height/2 } } onReleased: { autoincrement = false; - upPressed = false; - downPressed = false; + internal.upPressed = false; + internal.downPressed = false; handlePressed = false - pageUpPressed = false - pageDownPressed = false + internal.pageUpPressed = false + internal.pageDownPressed = false control = "" } diff --git a/src/private/private.pro b/src/private/private.pro index 23204d6a9..2659e94d8 100644 --- a/src/private/private.pro +++ b/src/private/private.pro @@ -27,6 +27,7 @@ QML_FILES += \ TabBar.qml \ BasicButton.qml \ ButtonBehavior.qml \ + Control.qml \ ModalPopupBehavior.qml \ PageSlideTransition.qml \ PageStack.js \ @@ -40,3 +41,6 @@ mac { load(qml_plugin) +OTHER_FILES += \ + Control.qml + diff --git a/src/private/qmldir b/src/private/qmldir index a9046611c..0ed608c78 100644 --- a/src/private/qmldir +++ b/src/private/qmldir @@ -1,6 +1,7 @@ module QtDesktop.Private plugin privateplugin ButtonBehavior 1.0 ButtonBehavior.qml +Control 1.0 Control.qml FocusFrame 1.0 FocusFrame.qml BasicButton 1.0 BasicButton.qml ScrollBar 1.0 ScrollBar.qml diff --git a/src/qtdesktop/Button.qml b/src/qtdesktop/Button.qml index 3da0597da..37d715668 100644 --- a/src/qtdesktop/Button.qml +++ b/src/qtdesktop/Button.qml @@ -58,16 +58,13 @@ import "Styles/Settings.js" as Settings */ BasicButton { id: button + /*! This property holds whether the push button is the default button. Default buttons decide what happens when the user presses enter in a dialog without giving a button explicit focus. Note : This property is currently ignored by Dialog */ property bool defaultbutton: false - /*! This property holds the style hints. Style hints are special properties that only affect specific themes or styles - An example of a styleHint can be: styleHints: "small" */ - property var styleHints: [] - /*! This property holds the text shown on the button. If the button has no text, the \l text property will be an empty string. */ property string text @@ -77,6 +74,6 @@ BasicButton { property url iconSource Accessible.name: text - style: Qt.createComponent(Settings.THEME_PATH + "/ButtonStyle.qml", button) + style: Qt.createComponent(Settings.THEME_PATH + "/ButtonStyle.qml", button) } diff --git a/src/qtdesktop/CheckBox.qml b/src/qtdesktop/CheckBox.qml index 54941687f..d9465eccc 100644 --- a/src/qtdesktop/CheckBox.qml +++ b/src/qtdesktop/CheckBox.qml @@ -61,7 +61,7 @@ import QtDesktop.Private 1.0 Whenever a CheckBox is clicked, it emits the clicked() signal. */ -FocusScope { +Control { id: checkBox /*! @@ -115,23 +115,8 @@ FocusScope { Accessible.role: Accessible.CheckBox Accessible.name: text - implicitWidth: Math.max(120, loader.item ? loader.item.implicitWidth : 0) - implicitHeight: loader.item ? loader.item.implicitHeight : 0 - - /*! - The style that should be applied to the checkbox. Custom style - components can be created with: - - \codeline Qt.createComponent("path/to/style.qml", checkBoxId); - */ - property Component style: Qt.createComponent(Settings.THEME_PATH + "/CheckBoxStyle.qml", checkBox) - - Loader { - id: loader - anchors.fill: parent - property alias control: checkBox - sourceComponent: style - } + /*! The style that should be applied to the checkbox. */ + style: Qt.createComponent(Settings.THEME_PATH + "/CheckBoxStyle.qml", checkBox) ButtonBehavior { id: behavior diff --git a/src/qtdesktop/ComboBox.qml b/src/qtdesktop/ComboBox.qml index 22f9d6984..4af1c760d 100644 --- a/src/qtdesktop/ComboBox.qml +++ b/src/qtdesktop/ComboBox.qml @@ -103,7 +103,6 @@ BasicButton { property alias selectedIndex: popup.selectedIndex property alias selectedText: popup.selectedText - property var styleHints:[] style: Qt.createComponent(Settings.THEME_PATH + "/ComboBoxStyle.qml", comboBox) @@ -111,8 +110,6 @@ BasicButton { // centers directly above button label when // popup.centerOnSelectedText === true - width: implicitWidth - height: implicitHeight checkable: false onPressedChanged: { if (pressed) popup.show() } diff --git a/src/qtdesktop/ProgressBar.qml b/src/qtdesktop/ProgressBar.qml index afad68f81..6b3127f64 100644 --- a/src/qtdesktop/ProgressBar.qml +++ b/src/qtdesktop/ProgressBar.qml @@ -40,6 +40,7 @@ import QtQuick 2.0 import QtDesktop 1.0 +import QtDesktop.Private 1.0 import "Styles/Settings.js" as Settings /*! @@ -53,7 +54,7 @@ import "Styles/Settings.js" as Settings */ -Item { +Control { id: progressbar /*! This property is @@ -73,26 +74,13 @@ Item { It must be either Qt.Horizontal or Qt.Vertical. */ property int orientation: Qt.Horizontal + /*! \internal */ - property Component style: Qt.createComponent(Settings.THEME_PATH + "/ProgressBarStyle.qml", progressbar) - /*! \internal */ - property var styleHints:[] + style: Qt.createComponent(Settings.THEME_PATH + "/ProgressBarStyle.qml", progressbar) Accessible.role: Accessible.ProgressBar Accessible.name: value - implicitWidth: orientation === Qt.Horizontal ? 200 : (loader.item ? loader.item.implicitHeight : 0) - implicitHeight: orientation === Qt.Horizontal ? (loader.item ? loader.item.implicitHeight : 0) : 200 - - Loader { - id: loader - property alias indeterminate: progressbar.indeterminate - property alias value: progressbar.value - property alias maximumValue: progressbar.maximumValue - property alias minimumValue: progressbar.minimumValue - - property alias control: progressbar - sourceComponent: style - anchors.fill: parent - } + implicitWidth: orientation === Qt.Horizontal ? 200 : (__panel ? __panel.implicitHeight : 0) + implicitHeight: orientation === Qt.Horizontal ? (__panel ? __panel.implicitHeight : 0) : 200 } diff --git a/src/qtdesktop/Slider.qml b/src/qtdesktop/Slider.qml index 3e380ffab..7def55d49 100644 --- a/src/qtdesktop/Slider.qml +++ b/src/qtdesktop/Slider.qml @@ -63,7 +63,7 @@ import "Styles/Settings.js" as Settings needed, you can set the \l stepSize. */ -Item { +Control { id: slider /*! @@ -135,7 +135,6 @@ Item { */ property alias stepSize: range.stepSize - /*! \qmlproperty double Slider::value @@ -184,18 +183,12 @@ Item { return Math.round(v); } - /*! \internal */ - property var styleHints:[] - - /*! \internal */ - property Component style: Qt.createComponent(Settings.THEME_PATH + "/SliderStyle.qml", slider) + /* \internal */ + style: Qt.createComponent(Settings.THEME_PATH + "/SliderStyle.qml", slider) Keys.onRightPressed: value += (maximumValue - minimumValue)/10.0 Keys.onLeftPressed: value -= (maximumValue - minimumValue)/10.0 - implicitWidth: loader.item ? loader.item.implicitWidth : 0 - implicitHeight: loader.item ? loader.item.implicitHeight : 0 - RangeModel { id: range minimumValue: 0.0 @@ -208,14 +201,6 @@ Item { positionAtMaximum: slider.width } - Loader { - id: loader - sourceComponent: style - anchors.fill: parent - property var control: slider - function positionForValue(value) { return range.positionForValue(value) } - } - Item { id: fakeHandle } MouseArea { diff --git a/src/qtdesktop/SpinBox.qml b/src/qtdesktop/SpinBox.qml index ea48c544d..9bc15b957 100644 --- a/src/qtdesktop/SpinBox.qml +++ b/src/qtdesktop/SpinBox.qml @@ -40,6 +40,7 @@ import QtQuick 2.0 import QtDesktop 1.0 +import QtDesktop.Private 1.0 import "Styles/Settings.js" as Settings /*! @@ -70,7 +71,7 @@ import "Styles/Settings.js" as Settings */ -FocusScope { +Control { id: spinbox /*! @@ -131,7 +132,7 @@ FocusScope { property bool activeFocusOnPress: true /*! \internal */ - property Component style: Qt.createComponent(Settings.THEME_PATH + "/SpinBoxStyle.qml", spinbox) + style: Qt.createComponent(Settings.THEME_PATH + "/SpinBoxStyle.qml", spinbox) /*! \internal */ function __increment() { @@ -160,8 +161,6 @@ FocusScope { /*! \internal */ readonly property alias __downPressed: mouseDown.pressed /*! \internal */ - property var styleHints:[] - /*! \internal */ property alias __upHovered: mouseUp.containsMouse /*! \internal */ property alias __downHovered: mouseDown.containsMouse @@ -204,19 +203,6 @@ FocusScope { Accessible.name: input.text Accessible.role: Accessible.SpinBox - width: implicitWidth - height: implicitHeight - - implicitWidth: loader.item ? loader.item.implicitWidth : 0 - implicitHeight: loader.item ? loader.item.implicitHeight : 0 - - Loader { - id: loader - property alias control: spinbox - sourceComponent: style - anchors.fill: parent - } - MouseArea { id: mouseArea anchors.fill: parent @@ -229,15 +215,15 @@ FocusScope { anchors.fill: parent spacing: 1 clip: true - anchors.leftMargin: loader.item ? loader.item.leftMargin : 0 - anchors.topMargin: loader.item ? loader.item.topMargin : 0 - anchors.rightMargin: loader.item ? loader.item.rightMargin: 0 - anchors.bottomMargin: loader.item ? loader.item.bottomMargin: 0 + anchors.leftMargin: __panel ? __panel.leftMargin : 0 + anchors.topMargin: __panel ? __panel.topMargin : 0 + anchors.rightMargin: __panel ? __panel.rightMargin: 0 + anchors.bottomMargin: __panel ? __panel.bottomMargin: 0 Text { id: prefixItem text: prefix - color: loader.item ? loader.item.foregroundColor : "black" + color: __panel ? __panel.foregroundColor : "black" anchors.verticalCenter: parent.verticalCenter renderType: Text.NativeRendering } @@ -263,15 +249,15 @@ FocusScope { } } - horizontalAlignment: loader.item ? loader.item.horizontalTextAlignment : Qt.AlignLeft - verticalAlignment: loader.item ? loader.item.verticalTextAlignment : Qt.AlignVCenter + horizontalAlignment: __panel ? __panel.horizontalTextAlignment : Qt.AlignLeft + verticalAlignment: __panel ? __panel.verticalTextAlignment : Qt.AlignVCenter selectByMouse: true validator: DoubleValidator { bottom: minimumValue; top: maximumValue; } onAccepted: setValue(input.text) - color: loader.item ? loader.item.foregroundColor : "black" - selectionColor: loader.item ? loader.item.selectionColor : "black" - selectedTextColor: loader.item ? loader.item.selectedTextColor : "black" + color: __panel ? __panel.foregroundColor : "black" + selectionColor: __panel ? __panel.selectionColor : "black" + selectedTextColor: __panel ? __panel.selectedTextColor : "black" opacity: parent.enabled ? 1 : 0.5 renderType: Text.NativeRendering @@ -279,7 +265,7 @@ FocusScope { Text { id: suffixItem text: suffix - color: loader.item ? loader.item.foregroundColor : "black" + color: __panel ? __panel.foregroundColor : "black" anchors.verticalCenter: parent.verticalCenter renderType: Text.NativeRendering } @@ -291,7 +277,7 @@ FocusScope { id: mouseUp hoverEnabled: true - property var upRect: loader.item ? loader.item.upRect : null + property var upRect: __panel ? __panel.upRect : null anchors.left: parent.left anchors.top: parent.top @@ -317,7 +303,7 @@ FocusScope { hoverEnabled: true onClicked: __decrement() - property var downRect: loader.item ? loader.item.downRect : null + property var downRect: __panel ? __panel.downRect : null anchors.left: parent.left anchors.top: parent.top diff --git a/src/qtdesktop/TextField.qml b/src/qtdesktop/TextField.qml index 4332f51c0..ba185f0cd 100644 --- a/src/qtdesktop/TextField.qml +++ b/src/qtdesktop/TextField.qml @@ -40,6 +40,7 @@ import QtQuick 2.0 import QtDesktop 1.0 +import QtDesktop.Private 1.0 import "Styles" import "Styles/Settings.js" as Settings @@ -57,7 +58,7 @@ import "Styles/Settings.js" as Settings \sa TextArea, TextInput */ -FocusScope { +Control { id: textfield /*! @@ -501,10 +502,7 @@ FocusScope { property alias __contentWidth: textInput.contentWidth /*! \internal */ - property Component style: Qt.createComponent(Settings.THEME_PATH + "/TextFieldStyle.qml", textInput) - - /*! \internal */ - property var styleHints:[] + style: Qt.createComponent(Settings.THEME_PATH + "/TextFieldStyle.qml", textInput) /*! \internal */ onFocusChanged: { @@ -512,21 +510,10 @@ FocusScope { textInput.forceActiveFocus(); } - // Implementation - implicitWidth: loader.implicitWidth - implicitHeight: loader.implicitHeight - Accessible.name: text Accessible.role: Accessible.EditableText Accessible.description: placeholderText - Loader { - id: loader - sourceComponent: style - anchors.fill: parent - property Item control: textfield - } - MouseArea { id: mouseArea anchors.fill: parent @@ -537,20 +524,19 @@ FocusScope { TextInput { id: textInput selectByMouse: true - selectionColor: loader.item ? loader.item.selectionColor : "darkred" - selectedTextColor: loader.item ? loader.item.selectedTextColor : "white" + selectionColor: __panel ? __panel.selectionColor : "darkred" + selectedTextColor: __panel ? __panel.selectedTextColor : "white" - property Item styleItem: loader.item - font: styleItem ? styleItem.font : font - anchors.leftMargin: styleItem ? styleItem.leftMargin : 0 - anchors.topMargin: styleItem ? styleItem.topMargin : 0 - anchors.rightMargin: styleItem ? styleItem.rightMargin : 0 - anchors.bottomMargin: styleItem ? styleItem.bottomMargin : 0 + font: __panel ? __panel.font : font + anchors.leftMargin: __panel ? __panel.leftMargin : 0 + anchors.topMargin: __panel ? __panel.topMargin : 0 + anchors.rightMargin: __panel ? __panel.rightMargin : 0 + anchors.bottomMargin: __panel ? __panel.bottomMargin : 0 anchors.fill: parent verticalAlignment: Text.AlignVCenter - color: loader.item ? loader.item.foregroundColor : "darkgray" + color: __panel ? __panel.foregroundColor : "darkgray" clip: true renderType: Text.NativeRendering @@ -564,7 +550,7 @@ FocusScope { horizontalAlignment: textInput.horizontalAlignment verticalAlignment: textInput.verticalAlignment opacity: !textInput.text.length && !textInput.activeFocus ? 1 : 0 - color: loader.item ? loader.item.placeholderTextColor : "darkgray" + color: __panel ? __panel.placeholderTextColor : "darkgray" clip: true elide: Text.ElideRight renderType: Text.NativeRendering diff --git a/src/qtdesktop/ToolButton.qml b/src/qtdesktop/ToolButton.qml index c4e1a8b05..722e79f85 100644 --- a/src/qtdesktop/ToolButton.qml +++ b/src/qtdesktop/ToolButton.qml @@ -62,10 +62,11 @@ import "Styles/Settings.js" as Settings Private.BasicButton { id: button + /*! The image label source. */ property url iconSource - property string text - style: Qt.createComponent(Settings.THEME_PATH + "/ToolButtonStyle.qml", button) + /*! The label text. */ + property string text Image { id: image @@ -76,4 +77,6 @@ Private.BasicButton { fillMode: Image.PreserveAspectFit } Accessible.name: text + + style: Qt.createComponent(Settings.THEME_PATH + "/ToolButtonStyle.qml", button) } diff --git a/src/styles/ButtonStyle.qml b/src/styles/ButtonStyle.qml index 0dc420ee9..a94ef7506 100644 --- a/src/styles/ButtonStyle.qml +++ b/src/styles/ButtonStyle.qml @@ -44,38 +44,61 @@ import QtDesktop 1.0 \qmltype ButtonStyle \internal \inqmlmodule QtDesktop.Styles 1.0 + \brief provides custom styling for Button */ -Item { - implicitWidth: backgroundLoader.implicitWidth - implicitHeight: backgroundLoader.implicitHeight +Style { + id: buttonstyle + property font font property color backgroundColor: "lightGray" property color foregroundColor: "black" - property alias font: textitem.font + + property Component label: Item { + Text { + id: textitem + anchors.centerIn: parent + renderType: Text.NativeRendering + text: control.text + color: buttonstyle.foregroundColor + font: buttonstyle.font + } + } property Component background: Rectangle { - implicitWidth: 100 + implicitWidth: 80 implicitHeight: 21 gradient: Gradient { - GradientStop {color: control.pressed ? Qt.lighter(backgroundColor, 1.1) : Qt.lighter(backgroundColor, 1.8) ; position: 0} - GradientStop {color: control.pressed ? Qt.lighter(backgroundColor, 1.1) : backgroundColor ; position: 1.4} + GradientStop {color: control.pressed ? Qt.lighter(buttonstyle.backgroundColor, 1.1) : + Qt.lighter(buttonstyle.backgroundColor, 1.8) ; position: 0} + GradientStop {color: control.pressed ? Qt.lighter(buttonstyle.backgroundColor, 1.1) : + buttonstyle.backgroundColor ; position: 1.4} } - border.color: Qt.darker(backgroundColor, 1.4) + border.color: Qt.darker(buttonstyle.backgroundColor, 1.4) radius: 3 antialiasing: true } - Loader { - id: backgroundLoader - sourceComponent: background + property Component panel: Item { + property Item controlref: control anchors.fill: parent - } - Text { - id: textitem - anchors.centerIn: backgroundLoader - renderType: Text.NativeRendering - text: control.text - color: foregroundColor + implicitWidth: backgroundLoader.implicitWidth + implicitHeight: backgroundLoader.implicitHeight + + Loader { + id: backgroundLoader + anchors.fill: parent + sourceComponent: background + property Item control: controlref + property Item label: labelLoader.item + } + + Loader { + id: labelLoader + sourceComponent: label + anchors.fill: parent + property Item control: controlref + } } } + diff --git a/src/styles/CheckBoxStyle.qml b/src/styles/CheckBoxStyle.qml index d88974c4f..68f4c422a 100644 --- a/src/styles/CheckBoxStyle.qml +++ b/src/styles/CheckBoxStyle.qml @@ -44,47 +44,60 @@ import QtDesktop 1.0 \qmltype CheckBoxStyle \internal \inqmlmodule QtDesktop.Styles 1.0 + \brief provides custom styling for CheckBox */ -Item { - implicitWidth: 100 - implicitHeight: 20 +Style { + + property int labelSpacing: 6 property Component indicator: Rectangle { - height:20 + height: 20 width: 20 antialiasing: true - gradient: Gradient{ + gradient: Gradient { GradientStop{color: control.pressed ? "lightgray" : "white" ; position: 0} GradientStop{color: control.pressed ? "lightgray" : "lightgray" ; position: 1} } - radius:4 + radius: 2 border.color: "#aaa" Rectangle { - height:20 + height: 20 width: 20 antialiasing: true visible: control.checked - gradient: Gradient{ - GradientStop{color: "darkgray" ; position: 1} - GradientStop{color: "lightgray" ; position: 0} - } - radius:2 + color: "#444" + radius: 1 anchors.margins: 5 anchors.fill: parent - border.color: "gray" + border.color: "black" } } - Loader { - id: indicatorLoader - sourceComponent: indicator - } - - Text { - anchors.left: parent.left - anchors.leftMargin: 24 - anchors.verticalCenter: parent.verticalCenter + property Component label: Text { text: control.text renderType: Text.NativeRendering } + + property Component panel: Item { + implicitWidth: row.width + implicitHeight: row.height + property var _cref: control + + Row { + id: row + spacing: labelSpacing + Loader { + id: indicatorLoader + sourceComponent: indicator + anchors.verticalCenter: parent.verticalCenter + property CheckBox control: _cref + } + Loader { + id: labelLoader + sourceComponent: label + anchors.verticalCenter: parent.verticalCenter + property CheckBox control: _cref + } + } + } } diff --git a/src/styles/ComboBoxStyle.qml b/src/styles/ComboBoxStyle.qml index 21b9eaeb2..dd31c7f84 100644 --- a/src/styles/ComboBoxStyle.qml +++ b/src/styles/ComboBoxStyle.qml @@ -37,8 +37,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -import QtQuick 2.0 -import QtDesktop 1.0 +import QtDesktop.Styles 1.0 /*! \qmltype ComboBoxStyle diff --git a/src/styles/Desktop/ButtonStyle.qml b/src/styles/Desktop/ButtonStyle.qml index 6abee4389..b83eac3ab 100644 --- a/src/styles/Desktop/ButtonStyle.qml +++ b/src/styles/Desktop/ButtonStyle.qml @@ -38,18 +38,12 @@ ** ****************************************************************************/ import QtQuick 2.0 -import QtDesktop 1.0 +import QtDesktop.Styles 1.0 import QtDesktop.Private 1.0 -Item { - width: implicitWidth - height: implicitHeight - implicitWidth: styleitem.implicitWidth - implicitHeight: styleitem.implicitHeight - StyleItem { +Style { + property Component panel: StyleItem { id: styleitem - width: parent.width - anchors.verticalCenter: parent.verticalCenter elementType: "button" sunken: control.pressed || control.checked raised: !(control.pressed || control.checked) @@ -58,6 +52,6 @@ Item { hasFocus: control.focus hints: control.styleHints // If no icon, let the style do the drawing - activeControl: defaultbutton ? "default" : "f" + activeControl: control.defaultbutton ? "default" : "f" } } diff --git a/src/styles/Desktop/CheckBoxStyle.qml b/src/styles/Desktop/CheckBoxStyle.qml index 61daa1a68..ca3735239 100644 --- a/src/styles/Desktop/CheckBoxStyle.qml +++ b/src/styles/Desktop/CheckBoxStyle.qml @@ -38,29 +38,41 @@ ** ****************************************************************************/ import QtQuick 2.0 -import QtDesktop 1.0 +import QtDesktop.Styles 1.0 import QtDesktop.Private 1.0 -StyleItem { - elementType: "checkbox" - sunken: pressed - on: checked || pressed - hover: containsMouse - enabled: control.enabled - hasFocus: control.activeFocus - hints: control.styleHints - contentHeight: textitem.implicitHeight - contentWidth: textitem.implicitWidth + indicatorWidth - Text { - id: textitem - text: control.text - anchors.left: parent.left - anchors.leftMargin: parent.indicatorWidth - anchors.verticalCenter: parent.verticalCenter - anchors.right: parent.right - elide: Text.ElideRight - color: syspal.windowText - SystemPalette { id: syspal } +Style { + property Component panel: Item { + anchors.fill: parent + + implicitWidth: styleitem.implicitWidth + implicitHeight: styleitem.implicitHeight + + StyleItem { + id: styleitem + elementType: "checkbox" + sunken: control.pressed + on: control.checked || control.pressed + hover: control.containsMouse + enabled: control.enabled + hasFocus: control.activeFocus + hints: control.styleHints + contentHeight: textitem.implicitHeight + contentWidth: textitem.implicitWidth + indicatorWidth + property int indicatorWidth: pixelMetric("indicatorwidth") + 2 + + Text { + id: textitem + text: control.text + anchors.left: parent.left + anchors.leftMargin: parent.indicatorWidth + anchors.verticalCenter: parent.verticalCenter + anchors.right: parent.right + renderType: Text.NativeRendering + elide: Text.ElideRight + color: syspal.windowText + SystemPalette { id: syspal } + } + } } - property int indicatorWidth: pixelMetric("indicatorwidth") + 2 } diff --git a/src/styles/Desktop/ComboBoxStyle.qml b/src/styles/Desktop/ComboBoxStyle.qml index 7a3818bba..cd431cca2 100644 --- a/src/styles/Desktop/ComboBoxStyle.qml +++ b/src/styles/Desktop/ComboBoxStyle.qml @@ -38,27 +38,31 @@ ** ****************************************************************************/ import QtQuick 2.0 -import QtDesktop 1.0 +import QtDesktop.Styles 1.0 import QtDesktop.Private 1.0 -Item { - width: implicitWidth - height: implicitHeight - implicitWidth: styleitem.implicitWidth - implicitHeight: styleitem.implicitHeight - StyleItem { - id: styleitem - width: parent.width - anchors.verticalCenter: parent.verticalCenter - elementType: "combobox" - sunken: comboBox.pressed || comboBox.popupOpen - raised: !sunken - hover: comboBox.containsMouse - enabled: comboBox.enabled - text: comboBox.selectedText - hasFocus: comboBox.focus - contentHeight: 18 - contentWidth: 80 - Component.onCompleted: popup.centerSelectedText = styleHint("comboboxpopup"); +Style { + property Component panel: Item { + width: implicitWidth + height: implicitHeight + implicitWidth: styleitem.implicitWidth + implicitHeight: styleitem.implicitHeight + + property int popup: styleitem.styleHint("comboboxpopup"); + + StyleItem { + id: styleitem + width: parent.width + anchors.verticalCenter: parent.verticalCenter + elementType: "combobox" + sunken: control.pressed + raised: !sunken + hover: control.containsMouse + enabled: control.enabled + text: control.selectedText + hasFocus: control.focus + contentHeight: 18 + contentWidth: 80 + } } } diff --git a/src/styles/Desktop/ProgressBarStyle.qml b/src/styles/Desktop/ProgressBarStyle.qml index fcd85401c..5602c2af8 100644 --- a/src/styles/Desktop/ProgressBarStyle.qml +++ b/src/styles/Desktop/ProgressBarStyle.qml @@ -38,21 +38,23 @@ ** ****************************************************************************/ import QtQuick 2.0 -import QtDesktop 1.0 +import QtDesktop.Styles 1.0 import QtDesktop.Private 1.0 -StyleItem { - anchors.fill: parent - elementType: "progressbar" - // XXX: since desktop uses int instead of real, the progressbar - // range [0..1] must be stretched to a good precision - property int factor : 1000 - value: indeterminate ? 0 : progressbar.value * factor // does indeterminate value need to be 1 on windows? - minimum: indeterminate ? 0 : progressbar.minimumValue * factor - maximum: indeterminate ? 0 : progressbar.maximumValue * factor - enabled: progressbar.enabled - horizontal: progressbar.orientation == Qt.Horizontal - hints: progressbar.styleHints - contentWidth: 23 - contentHeight: 23 +Style { + property Component panel: StyleItem { + anchors.fill: parent + elementType: "progressbar" + // XXX: since desktop uses int instead of real, the progressbar + // range [0..1] must be stretched to a good precision + property int factor : 1000 + value: indeterminate ? 0 : control.value * factor // does indeterminate value need to be 1 on windows? + minimum: indeterminate ? 0 : control.minimumValue * factor + maximum: indeterminate ? 0 : control.maximumValue * factor + enabled: control.enabled + horizontal: control.orientation == Qt.Horizontal + hints: control.styleHints + contentWidth: 23 + contentHeight: 23 + } } diff --git a/src/styles/Desktop/RadioButtonStyle.qml b/src/styles/Desktop/RadioButtonStyle.qml index 255411458..2330e9bd3 100644 --- a/src/styles/Desktop/RadioButtonStyle.qml +++ b/src/styles/Desktop/RadioButtonStyle.qml @@ -38,30 +38,41 @@ ** ****************************************************************************/ import QtQuick 2.0 -import QtDesktop 1.0 +import QtDesktop.Styles 1.0 import QtDesktop.Private 1.0 -StyleItem { - elementType: "radiobutton" - sunken: pressed - on: checked || pressed - hover: containsMouse - enabled: radiobutton.enabled - hasFocus: radiobutton.activeFocus - hints: radiobutton.styleHints - contentHeight: textitem.implicitHeight - contentWidth: textitem.implicitWidth + indicatorWidth - property int indicatorWidth: pixelMetric("indicatorwidth") + 2 +Style { + property Component panel: Item { + anchors.fill: parent - Text { - id: textitem - text: radiobutton.text - anchors.left: parent.left - anchors.leftMargin: parent.indicatorWidth - anchors.verticalCenter: parent.verticalCenter - anchors.right: parent.right - elide: Text.ElideRight - color: syspal.windowText - SystemPalette { id: syspal } + implicitWidth: styleitem.implicitWidth + implicitHeight: styleitem.implicitHeight + + StyleItem { + id: styleitem + elementType: "radiobutton" + sunken: control.pressed + on: control.checked || control.pressed + hover: control.containsMouse + enabled: control.enabled + hasFocus: control.activeFocus + hints: control.styleHints + contentHeight: textitem.implicitHeight + contentWidth: textitem.implicitWidth + indicatorWidth + property int indicatorWidth: pixelMetric("indicatorwidth") + 2 + + Text { + id: textitem + text: control.text + anchors.left: parent.left + anchors.leftMargin: parent.indicatorWidth + anchors.verticalCenter: parent.verticalCenter + anchors.right: parent.right + renderType: Text.NativeRendering + elide: Text.ElideRight + color: syspal.windowText + SystemPalette { id: syspal } + } + } } } diff --git a/src/styles/Desktop/SliderStyle.qml b/src/styles/Desktop/SliderStyle.qml index 7f551a3b7..13adde3cc 100644 --- a/src/styles/Desktop/SliderStyle.qml +++ b/src/styles/Desktop/SliderStyle.qml @@ -38,23 +38,25 @@ ** ****************************************************************************/ import QtQuick 2.0 -import QtDesktop 1.0 +import QtDesktop.Styles 1.0 import QtDesktop.Private 1.0 -StyleItem { - elementType: "slider" - sunken: pressed +Style { + property Component panel: StyleItem { + elementType: "slider" + sunken: control.pressed + implicitWidth: 200 + contentHeight: horizontal ? 20 : 200 + contentWidth: horizontal ? 200 : 20 - contentHeight: horizontal ? 20 : 200 - contentWidth: horizontal ? 200 : 20 - - maximum: control.maximumValue*100 - minimum: control.minimumValue*100 - step: control.stepSize*100 - value: control.value*100 - horizontal: control.orientation === Qt.Horizontal - enabled: control.enabled - hasFocus: control.focus - hints: control.styleHints - activeControl: control.tickmarksEnabled ? "ticks" : "" + maximum: control.maximumValue*100 + minimum: control.minimumValue*100 + step: control.stepSize*100 + value: control.value*100 + horizontal: control.orientation === Qt.Horizontal + enabled: control.enabled + hasFocus: control.focus + hints: control.styleHints + activeControl: control.tickmarksEnabled ? "ticks" : "" + } } diff --git a/src/styles/Desktop/SpinBoxStyle.qml b/src/styles/Desktop/SpinBoxStyle.qml index d430dcec7..34502921a 100644 --- a/src/styles/Desktop/SpinBoxStyle.qml +++ b/src/styles/Desktop/SpinBoxStyle.qml @@ -39,79 +39,82 @@ ****************************************************************************/ import QtQuick 2.0 import QtDesktop 1.0 +import QtDesktop.Styles 1.0 import QtDesktop.Private 1.0 -Item { - id: style +Style { + property Component panel: Item { + id: style - property rect upRect - property rect downRect + property rect upRect + property rect downRect - property int topMargin: edit.anchors.topMargin - property int leftMargin: 2 + edit.anchors.leftMargin - property int rightMargin: 2 + edit.anchors.rightMargin - property int bottomMargin: edit.anchors.bottomMargin - property int horizontalTextAlignment: Qt.AlignLeft - property int verticalTextAlignment: Qt.AlignVCenter + property int topMargin: edit.anchors.topMargin + property int leftMargin: 2 + edit.anchors.leftMargin + property int rightMargin: 2 + edit.anchors.rightMargin + property int bottomMargin: edit.anchors.bottomMargin + property int horizontalTextAlignment: Qt.AlignLeft + property int verticalTextAlignment: 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: syspal.text + property color backgroundColor: syspal.base + property color selectionColor: syspal.highlight + property color selectedTextColor: syspal.highlightedText - SystemPalette { - id: syspal - colorGroup: control.enabled ? SystemPalette.Active : SystemPalette.Disabled - } + SystemPalette { + id: syspal + colorGroup: control.enabled ? SystemPalette.Active : SystemPalette.Disabled + } - width: 100 - height: styleitem.implicitHeight + width: 100 + height: styleitem.implicitHeight - implicitWidth: styleitem.implicitWidth - implicitHeight: styleitem.implicitHeight + implicitWidth: styleitem.implicitWidth + implicitHeight: styleitem.implicitHeight - Item { - id: edit - anchors.fill: parent - Rectangle { - color: "white" + Item { + id: edit anchors.fill: parent - anchors.margins: -1 + Rectangle { + color: "white" + anchors.fill: parent + anchors.margins: -1 + } + FocusFrame { + focusMargin:-6 + visible: spinbox.activeFocus && styleitem.styleHint("focuswidget") + } } - FocusFrame { - focusMargin:-6 - visible: spinbox.activeFocus && styleitem.styleHint("focuswidget") - } - } - function updateRect() { - style.upRect = styleitem.subControlRect("up"); - style.downRect = styleitem.subControlRect("down"); - var inputRect = styleitem.subControlRect("edit"); - edit.anchors.topMargin = inputRect.y - edit.anchors.leftMargin = inputRect.x - edit.anchors.rightMargin = style.width - inputRect.width - edit.anchors.leftMargin - edit.anchors.bottomMargin = style.height - inputRect.height - edit.anchors.topMargin - } + function updateRect() { + style.upRect = styleitem.subControlRect("up"); + style.downRect = styleitem.subControlRect("down"); + var inputRect = styleitem.subControlRect("edit"); + edit.anchors.topMargin = inputRect.y + edit.anchors.leftMargin = inputRect.x + edit.anchors.rightMargin = style.width - inputRect.width - edit.anchors.leftMargin + edit.anchors.bottomMargin = style.height - inputRect.height - edit.anchors.topMargin + } - Component.onCompleted: updateRect() - onWidthChanged: updateRect() - onHeightChanged: updateRect() + Component.onCompleted: updateRect() + onWidthChanged: updateRect() + onHeightChanged: updateRect() - StyleItem { - id: styleitem - elementType: "spinbox" - anchors.fill: parent - sunken: (control.__downEnabled && control.__downPressed) || (control.__upEnabled && control.__upPressed) - hover: __containsMouse - hints: control.styleHints - hasFocus: control.focus - enabled: control.enabled - value: (control.__upPressed ? 1 : 0) | - (control.__downPressed ? 1<<1 : 0) | - (control.__upEnabled ? (1<<2) : 0) | - (control.__downEnabled ? (1<<3) : 0) - contentWidth: control.__contentWidth - contentHeight: control.__contentHeight + StyleItem { + id: styleitem + elementType: "spinbox" + anchors.fill: parent + sunken: (control.__downEnabled && control.__downPressed) || (control.__upEnabled && control.__upPressed) + hover: __containsMouse + hints: control.styleHints + hasFocus: control.focus + enabled: control.enabled + value: (control.__upPressed ? 1 : 0) | + (control.__downPressed ? 1<<1 : 0) | + (control.__upEnabled ? (1<<2) : 0) | + (control.__downEnabled ? (1<<3) : 0) + contentWidth: control.__contentWidth + contentHeight: control.__contentHeight + } } } diff --git a/src/styles/Desktop/TabFrameStyle.qml b/src/styles/Desktop/TabFrameStyle.qml index 56b51db60..7c5f7531b 100644 --- a/src/styles/Desktop/TabFrameStyle.qml +++ b/src/styles/Desktop/TabFrameStyle.qml @@ -40,15 +40,14 @@ import QtQuick 2.0 import QtDesktop 1.0 import QtDesktop.Private 1.0 +import QtDesktop.Styles 1.0 -QtObject { +Style { id: root property int leftMargin: 0 property int rightMargin: 0 - property StyleItem __barstyle: StyleItem { elementType: "tabbar" ; visible: false } - property string tabBarAlignment: __barstyle.styleHint("tabbaralignment"); property int tabOverlap: __barstyle.pixelMetric("taboverlap"); property int tabBaseOverlap: __barstyle.pixelMetric("tabbaseoverlap"); diff --git a/src/styles/Desktop/TextFieldStyle.qml b/src/styles/Desktop/TextFieldStyle.qml index 31fc79ea2..529f09bfd 100644 --- a/src/styles/Desktop/TextFieldStyle.qml +++ b/src/styles/Desktop/TextFieldStyle.qml @@ -38,43 +38,46 @@ ** ****************************************************************************/ import QtQuick 2.0 -import QtDesktop 1.0 +import QtDesktop.Styles 1.0 import QtDesktop.Private 1.0 -StyleItem { - id: textfieldstyle - anchors.fill: parent - elementType: "edit" - sunken: true - hasFocus: textfield.activeFocus - hover: __containsMouse +Style { + property Component panel: StyleItem { + id: textfieldstyle + elementType: "edit" + anchors.fill: parent - SystemPalette { - id: syspal - colorGroup: control.enabled ? - SystemPalette.Active : - SystemPalette.Disabled - } + sunken: true + hasFocus: control.activeFocus + hover: __containsMouse + hints: control.styleHints - contentWidth: 200 - contentHeight: 18 + SystemPalette { + id: syspal + colorGroup: control.enabled ? + SystemPalette.Active : + SystemPalette.Disabled + } - property bool rounded: hints.indexOf("rounded") > -1 - property int topMargin: 1 - property int leftMargin: rounded ? 8 : 4 - property int rightMargin: 4 - property int bottomMargin: 1 + property color foregroundColor: syspal.text + property color backgroundColor: syspal.base + property color placeholderTextColor: "darkGray" + property color selectionColor: syspal.highlight + property color selectedTextColor: syspal.highlightedText - property color foregroundColor: syspal.text - property color backgroundColor: syspal.base - property color placeholderTextColor: "darkGray" - property color selectionColor: syspal.highlight - property color selectedTextColor: syspal.highlightedText - hints: control.styleHints + property bool rounded: hints.indexOf("rounded") > -1 + property int topMargin: 1 + property int leftMargin: rounded ? 8 : 4 + property int rightMargin: 4 + property int bottomMargin: 1 - FocusFrame { - anchors.fill: parent - visible: textfield.activeFocus && textfieldstyle.styleHint("focuswidget") + contentWidth: 100 + contentHeight: 18 + + FocusFrame { + anchors.fill: parent + visible: textfield.activeFocus && textfieldstyle.styleHint("focuswidget") + } } } diff --git a/src/styles/Desktop/ToolButtonStyle.qml b/src/styles/Desktop/ToolButtonStyle.qml index 645cbd6fd..faf0258ec 100644 --- a/src/styles/Desktop/ToolButtonStyle.qml +++ b/src/styles/Desktop/ToolButtonStyle.qml @@ -38,25 +38,38 @@ ** ****************************************************************************/ import QtQuick 2.0 -import QtDesktop 1.0 +import QtDesktop.Styles 1.0 import QtDesktop.Private 1.0 -StyleItem { - id: styleitem - anchors.fill: parent - elementType: "toolbutton" - on: pressed | checked - sunken: pressed - raised: containsMouse - hover: containsMouse - hasFocus: control.focus - hints: control.styleHints.concat([__position]) - contentWidth: Math.max(textitem.paintedWidth, 32) - contentHeight: 30 - Text { - id: textitem - text: control.text - anchors.centerIn: parent - visible: control.iconSource == "" +Style { + property Component panel: StyleItem { + id: styleitem + + anchors.fill: parent + elementType: "toolbutton" + on: control.pressed | control.checked + sunken: control.pressed + raised: control.containsMouse + hover: control.containsMouse + hasFocus: control.focus + hints: control.styleHints.concat([control.__position]) + + contentWidth: Math.max(textitem.paintedWidth, 32) + contentHeight: 30 + + Image { + id: image + anchors.centerIn: parent + source: button.iconSource + sourceSize.width: Math.min(control.width, image.implicitWidth) + sourceSize.height: Math.min(control.height, image.implicitHeight) + } + + Text { + id: textitem + text: control.text + anchors.centerIn: parent + visible: control.iconSource === "" + } } } diff --git a/src/styles/ProgressBarStyle.qml b/src/styles/ProgressBarStyle.qml index d599507d2..7eebf9d80 100644 --- a/src/styles/ProgressBarStyle.qml +++ b/src/styles/ProgressBarStyle.qml @@ -45,17 +45,18 @@ import QtDesktop 1.0 \qmltype ProgressBarStyle \internal \inqmlmodule QtDesktop.Styles 1.0 + \brief provides custom styling for ProgressBar */ -Item { - anchors.fill: parent - implicitWidth: 200 - implicitHeight: 20 +Style { property color backgroundColor: "darkgrey" property color progressColor: "#47f" property Component background: Rectangle { id: styleitem + anchors.fill: parent + implicitWidth: 200 + implicitHeight: 20 clip: true radius: 2 antialiasing: true @@ -89,9 +90,18 @@ Item { } } - Loader { - id: backgroundLoader + property Component panel: Item { + property Item controlref: control anchors.fill: parent - sourceComponent: background + + implicitWidth: backgroundLoader.implicitWidth + implicitHeight: backgroundLoader.implicitHeight + + Loader { + id: backgroundLoader + anchors.fill: parent + sourceComponent: background + property Item control: controlref + } } } diff --git a/src/styles/RadioButtonStyle.qml b/src/styles/RadioButtonStyle.qml index 0b8c760af..46a625bb9 100644 --- a/src/styles/RadioButtonStyle.qml +++ b/src/styles/RadioButtonStyle.qml @@ -44,47 +44,56 @@ import QtDesktop 1.0 \qmltype RadioButtonStyle \internal \inqmlmodule QtDesktop.Styles 1.0 + \brief provides custom styling for RadioButton */ -Item { - implicitWidth: 100 - implicitHeight: 20 +Style { - property Component indicator: Rectangle { - id: styleitem - height:20 + property int labelSpacing: 6 + + property Component indicator: Rectangle { width: 20 - gradient: Gradient{ - GradientStop{color: control.pressed ? "lightgray" : "white" ; position: 0} - GradientStop{color: control.pressed ? "lightgray" : "lightgray" ; position: 1} - } - radius: width/2 - border.color: "#aaa" + height: 20 + color: "#f0f0f0" + border.color: "gray" antialiasing: true + radius: height/2 + Rectangle { - height:20 - width: 20 - antialiasing: true + anchors.centerIn: parent visible: control.checked - gradient: Gradient{ - GradientStop{color: "darkgray" ; position: 1} - GradientStop{color: "lightgray" ; position: 0} - } - radius: width/2 - anchors.margins: 5 - anchors.fill: parent - border.color: "gray" + width: 10 + height: 10 + color: "#444" + border.color: "black" + antialiasing: true + radius: height/2 } } - - Loader { - id: indicatorLoader - sourceComponent: indicator + property Component label: Text { + text: control.text + renderType: Text.NativeRendering } - Text { - anchors.left: parent.left - anchors.leftMargin: 24 - anchors.verticalCenter: parent.verticalCenter - text: control.text + property Component panel: Item { + implicitWidth: row.width + implicitHeight: row.height + property var _cref: control + + Row { + id: row + spacing: labelSpacing + Loader { + id: indicatorLoader + sourceComponent: indicator + anchors.verticalCenter: parent.verticalCenter + property CheckBox control: _cref + } + Loader { + id: labelLoader + sourceComponent: label + anchors.verticalCenter: parent.verticalCenter + property CheckBox control: _cref + } + } } } diff --git a/src/styles/ScrollBarStyle.qml b/src/styles/ScrollBarStyle.qml index 8386be712..d5477ff70 100644 --- a/src/styles/ScrollBarStyle.qml +++ b/src/styles/ScrollBarStyle.qml @@ -175,7 +175,7 @@ Rectangle { Loader{ id: handleControl property int totalextent: horizontal ? bg.width : bg.height - property int extent: Math.max(minimumHandleLength, totalextent - control.maximumValue + 2 * handleOverlap) + property int extent: Math.max(minimumHandleLength, 100 * totalextent / (control.maximumValue - control.minimumValue) + 2 * handleOverlap) property bool mouseOver: activeControl === "handle" height: horizontal ? implicitHeight : extent diff --git a/src/styles/SliderStyle.qml b/src/styles/SliderStyle.qml index 65b05209b..e376fce4d 100644 --- a/src/styles/SliderStyle.qml +++ b/src/styles/SliderStyle.qml @@ -39,18 +39,16 @@ ****************************************************************************/ import QtQuick 2.0 import QtDesktop 1.0 +import QtDesktop.Private 1.0 /*! \qmltype SliderStyle \internal \inqmlmodule QtDesktop.Styles 1.0 */ -Item { +Style { id: styleitem - implicitWidth: 200 - implicitHeight: 20 - property int leftMargin property int rightMargin @@ -68,8 +66,7 @@ Item { border.color: Qt.darker(backgroundColor, 1.8) } - property Component background: Item { - Rectangle { + property Component background: Rectangle { anchors.verticalCenter: parent.verticalCenter width: parent.width @@ -82,19 +79,28 @@ Item { antialiasing: true radius: height / 2.0 border.color: Qt.darker(backgroundColor, 1.8) - } } - Loader { - id: backgroundControl - sourceComponent: background - width: parent.width - anchors.verticalCenter: parent.verticalCenter - } + property Component panel: Item { + implicitWidth: 200 + implicitHeight: 20 + + property Control __cref: control + Loader { + id: backgroundControl + sourceComponent: background + width: parent.width + anchors.verticalCenter: parent.verticalCenter + property Control control: __cref + property Item handle: handleLoader.item + } - Loader { - sourceComponent: handle - anchors.verticalCenter: backgroundControl.verticalCenter - x: leftMargin + control.value / control.maximumValue * (parent.width - leftMargin - rightMargin - width) + Loader { + id: handleLoader + sourceComponent: handle + anchors.verticalCenter: backgroundControl.verticalCenter + x: leftMargin + control.value / control.maximumValue * (parent.width - leftMargin - rightMargin - width) + property Control control: __cref + } } } diff --git a/src/styles/SpinBoxStyle.qml b/src/styles/SpinBoxStyle.qml index 26138d83b..1e1385982 100644 --- a/src/styles/SpinBoxStyle.qml +++ b/src/styles/SpinBoxStyle.qml @@ -44,32 +44,22 @@ import QtDesktop 1.0 \qmltype SpinBoxStyle \internal \inqmlmodule QtDesktop.Styles 1.0 + \brief provides custom styling for SpinBox */ -Item { - id: styleitem - implicitWidth: 100 - implicitHeight: 21 - property rect upRect: Qt.rect(width - upControlLoader.implicitWidth, 0, upControlLoader.implicitWidth, height / 2 + 1) - property rect downRect: Qt.rect(width - downControlLoader.implicitWidth, height / 2, downControlLoader.implicitWidth, height / 2) +Style { + id: spinboxStyle property int topMargin: 0 property int leftMargin: 4 property int rightMargin: 12 property int bottomMargin: 0 - property int horizontalTextAlignment: Qt.AlignLeft - property int verticalTextAlignment: Qt.AlignVCenter property color foregroundColor: syspal.text property color backgroundColor: syspal.base property color selectionColor: syspal.highlight property color selectedTextColor: syspal.highlightedText - SystemPalette { - id: syspal - colorGroup: control.enabled ? SystemPalette.Active : SystemPalette.Disabled - } - property Component upControl: Rectangle { anchors.centerIn: parent implicitWidth: 12 @@ -108,28 +98,60 @@ Item { border.color: Qt.darker(backgroundColor, 2) } - Loader { - id: backgroundLoader - anchors.fill: parent - sourceComponent: background - } - Loader { - id: upControlLoader - x: upRect.x - y: upRect.y - width: upRect.width - height: upRect.height - sourceComponent: upControl - } + property Component panel: Item { + id: styleitem + implicitWidth: 100 + implicitHeight: 21 - Loader { - id: downControlLoader - x: downRect.x - y: downRect.y - width: downRect.width - height: downRect.height - sourceComponent: downControl - } + property color foregroundColor: spinboxStyle.foregroundColor + property color backgroundColor: spinboxStyle.backgroundColor + property color selectionColor: spinboxStyle.selectionColor + property color selectedTextColor: spinboxStyle.selectedTextColor + + property int leftMargin: spinboxStyle.leftMargin + property int rightMargin: spinboxStyle.rightMargin + property int topMargin: spinboxStyle.topMargin + property int bottomMargin: spinboxStyle.bottomMargin + + property rect upRect: Qt.rect(width - upControlLoader.implicitWidth, 0, upControlLoader.implicitWidth, height / 2 + 1) + property rect downRect: Qt.rect(width - downControlLoader.implicitWidth, height / 2, downControlLoader.implicitWidth, height / 2) + + property int horizontalTextAlignment: Qt.AlignLeft + property int verticalTextAlignment: Qt.AlignVCenter + property SpinBox cref: control + + SystemPalette { + id: syspal + colorGroup: control.enabled ? SystemPalette.Active : SystemPalette.Disabled + } + + Loader { + id: backgroundLoader + anchors.fill: parent + sourceComponent: background + property SpinBox control: cref + } + + Loader { + id: upControlLoader + x: upRect.x + y: upRect.y + width: upRect.width + height: upRect.height + sourceComponent: upControl + property SpinBox control: cref + } + + Loader { + id: downControlLoader + x: downRect.x + y: downRect.y + width: downRect.width + height: downRect.height + sourceComponent: downControl + property SpinBox control: cref + } + } } diff --git a/src/styles/Style.qml b/src/styles/Style.qml new file mode 100644 index 000000000..859b32371 --- /dev/null +++ b/src/styles/Style.qml @@ -0,0 +1,42 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Components project. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.0 + +QtObject { } diff --git a/src/styles/TabFrameStyle.qml b/src/styles/TabFrameStyle.qml index 2d23c6ffd..4d156d618 100644 --- a/src/styles/TabFrameStyle.qml +++ b/src/styles/TabFrameStyle.qml @@ -38,13 +38,16 @@ ** ****************************************************************************/ import QtQuick 2.0 +import QtDesktop.Styles 1.0 /*! \qmltype TabFrameStyle \internal \inqmlmodule QtDesktop.Styles 1.0 + \brief provides custom styling for TabFrame */ -QtObject { + +Style { /*! This property holds the base alignment of the tab bar. The default value is "left". Supporeted alignments are diff --git a/src/styles/TextFieldStyle.qml b/src/styles/TextFieldStyle.qml index 71c2f04ff..30a224672 100644 --- a/src/styles/TextFieldStyle.qml +++ b/src/styles/TextFieldStyle.qml @@ -44,32 +44,23 @@ import QtDesktop 1.0 \qmltype TextFieldStyle \internal \inqmlmodule QtDesktop.Styles 1.0 + \brief provides custom styling for TextField. */ -Item { - id: style - anchors.fill: parent - implicitWidth: backgroundLoader.implicitWidth ? backgroundLoader.implicitWidth : 100 - implicitHeight: backgroundLoader.implicitHeight ? backgroundLoader.implicitHeight : 20 +Style { + id: style property int topMargin: 4 property int leftMargin: 8 property int rightMargin: 8 property int bottomMargin: 4 - property color foregroundColor: syspal.text - property color backgroundColor: syspal.base - property color placeholderTextColor: Qt.rgba(0, 0, 0, 0.5) - property color selectionColor: syspal.highlight - property color selectedTextColor: syspal.highlightedText - property font font + property color foregroundColor: "black" + property color backgroundColor: "white" + property color selectionColor: "blue" + property color selectedTextColor: "white" - SystemPalette { - id: syspal - colorGroup: control.enabled ? - SystemPalette.Active : - SystemPalette.Disabled - } + property font font property Component background: Rectangle { id: styleitem @@ -82,9 +73,29 @@ Item { antialiasing: true } - Loader { - id: backgroundLoader - sourceComponent: background + property Component panel: Item { anchors.fill: parent + + property int topMargin: style.topMargin + property int leftMargin: style.leftMargin + property int rightMargin: style.rightMargin + property int bottomMargin: style.bottomMargin + + property color foregroundColor: style.foregroundColor + property color backgroundColor: style.backgroundColor + property color selectionColor: style.selectionColor + property color selectedTextColor: style.selectedTextColor + + implicitWidth: backgroundLoader.implicitWidth ? backgroundLoader.implicitWidth : 100 + implicitHeight: backgroundLoader.implicitHeight ? backgroundLoader.implicitHeight : 20 + + property color placeholderTextColor: Qt.rgba(0, 0, 0, 0.5) + property font font: style.font + + Loader { + id: backgroundLoader + sourceComponent: background + anchors.fill: parent + } } } diff --git a/src/styles/qmldir b/src/styles/qmldir index 999aaf46a..c645ca534 100644 --- a/src/styles/qmldir +++ b/src/styles/qmldir @@ -14,4 +14,4 @@ TextAreaStyle 1.0 TextAreaStyle.qml TextFieldStyle 1.0 TextFieldStyle.qml ToolBarStyle 1.0 ToolBarStyle.qml ToolButtonStyle 1.0 ToolButtonStyle.qml - +Style 1.0 Style.qml diff --git a/src/styles/styles.pro b/src/styles/styles.pro index 7da032e0a..bf26dc512 100644 --- a/src/styles/styles.pro +++ b/src/styles/styles.pro @@ -16,6 +16,7 @@ QML_FILES = \ Settings.js \ SliderStyle.qml \ SpinBoxStyle.qml \ + Style.qml \ TabFrameStyle.qml \ TextFieldStyle.qml \ ToolBarStyle.qml \ -- GitLab