From f76576b9eae175c99d405e8c57a35c214b5f25b1 Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig <jens.bache-wiig@nokia.com> Date: Sun, 13 Mar 2011 11:01:17 +0100 Subject: [PATCH] Unify StyleItem and StyleBackground --- components/Button.qml | 6 ++--- components/ChoiceList.qml | 36 +++++++++++++---------------- components/Dial.qml | 30 +++++++++++------------- components/GroupBox.qml | 8 +++---- components/ProgressBar.qml | 23 +++++++++--------- components/ScrollArea.qml | 18 ++++++--------- components/ScrollBar.qml | 25 +++++++++----------- components/Slider.qml | 23 +++++++++--------- components/SpinBox.qml | 34 +++++++++++---------------- components/TabBar.qml | 19 ++++++++------- components/TabFrame.qml | 21 ++++++++--------- components/TextField.qml | 20 +++++++--------- components/ToolBar.qml | 8 +++---- components/ToolButton.qml | 22 ++++++++---------- components/custom/BasicButton.qml | 1 + components/custom/Button.qml | 1 + components/custom/ChoiceList.qml | 2 ++ components/styleitem/qstyleitem.cpp | 2 ++ 18 files changed, 136 insertions(+), 163 deletions(-) diff --git a/components/Button.qml b/components/Button.qml index 78bd63ee0..61a4c882c 100644 --- a/components/Button.qml +++ b/components/Button.qml @@ -7,13 +7,13 @@ Components.Button { width: 100 height: Math.max(22, sizehint.height) - property variant sizehint: styleitem.sizeFromContents(80, 6) + property variant sizehint: backgroundItem.sizeFromContents(80, 6) property bool defaultbutton background: QStyleItem { id: styleitem - anchors.fill:parent + anchors.fill: parent elementType: "button" sunken: pressed @@ -50,7 +50,7 @@ Components.Button { id:text color: textColor anchors.verticalCenter: parent.verticalCenter - text: styleitem.text + text: button.text horizontalAlignment: Text.Center } } diff --git a/components/ChoiceList.qml b/components/ChoiceList.qml index 8c5f0d531..824da6b7f 100644 --- a/components/ChoiceList.qml +++ b/components/ChoiceList.qml @@ -5,16 +5,18 @@ import "plugin" Components.ChoiceList { id:choicelist - property int buttonHeight: buttonitem.sizeFromContents(100, 18).height - property int buttonWidth: buttonitem.sizeFromContents(100, 18).width - QStyleItem { id:buttonitem; elementType:"combobox" } + property int buttonHeight: backgroundItem.sizeFromContents(100, 18).height + property int buttonWidth: backgroundItem.sizeFromContents(100, 18).width + QStyleItem { id:buttonitem ; elementType:"combobox" } height: buttonHeight width: buttonWidth - topMargin:4 - bottomMargin:4 + topMargin: 4 + bottomMargin: 4 - QStyleItem { - id:styleitem + + background: QStyleItem { + id: styleitem + anchors.fill:parent elementType: "combobox" sunken: pressed raised: !pressed @@ -24,33 +26,27 @@ Components.ChoiceList { focus:choicelist.focus } - background: QStyleBackground { - anchors.fill:parent - style: styleitem - } - listItem: Item { id:item height:22 anchors.left:parent.left width:choicelist.width - QStyleBackground { + QStyleItem { anchors.fill:parent - style: QStyleItem { - elementType: "comboboxitem" - text: choicelist.model.get(index).text - selected: highlighted - } + elementType: "comboboxitem" + text: choicelist.model.get(index).text + selected: highlighted + } } - popupFrame: QStyleBackground { + popupFrame: QStyleItem { property string behavior: styleitem.styleHint("comboboxpopup") ? "MacOS" : "Windows" property int fw: styleitem.pixelMetric("menupanelwidth"); anchors.leftMargin: styleitem.pixelMetric("menuhmargin") + fw anchors.rightMargin: styleitem.pixelMetric("menuhmargin") + fw anchors.topMargin: styleitem.pixelMetric("menuvmargin") + fw anchors.bottomMargin: styleitem.pixelMetric("menuvmargin") + fw - style:QStyleItem{elementType:"menu"} + elementType: "menu" } } diff --git a/components/Dial.qml b/components/Dial.qml index 16bb224be..6173774a4 100644 --- a/components/Dial.qml +++ b/components/Dial.qml @@ -4,7 +4,7 @@ import "plugin" // jens: ContainsMouse breaks drag functionality -QStyleBackground { +QStyleItem { id: dial width:100 @@ -77,21 +77,19 @@ QStyleBackground { } } - style: QStyleItem{ - elementType:"dial" - sunken: mouseArea.pressed - maximum: range.maximumValue*90 - minimum: range.minimumValue*90 - focus:dial.focus - value: visualPos*90 - enabled: dial.enabled - property double visualPos : range.value - Behavior on visualPos { - enabled: !mouseArea.inDrag - NumberAnimation { - duration: 300 - easing.type: Easing.OutSine - } + elementType:"dial" + sunken: mouseArea.pressed + maximum: range.maximumValue*90 + minimum: range.minimumValue*90 + focus:dial.focus + value: visualPos*90 + enabled: dial.enabled + property double visualPos : range.value + Behavior on visualPos { + enabled: !mouseArea.inDrag + NumberAnimation { + duration: 300 + easing.type: Easing.OutSine } } } diff --git a/components/GroupBox.qml b/components/GroupBox.qml index 9a5a5bdea..e65495bc8 100644 --- a/components/GroupBox.qml +++ b/components/GroupBox.qml @@ -10,12 +10,10 @@ Item { default property alias children: content.children property bool checkable: false - QStyleBackground { + QStyleItem { + id:styleitem + elementType:"groupbox" anchors.fill:parent - style: QStyleItem{ - id:styleitem - elementType:"groupbox" - } Item { id:content diff --git a/components/ProgressBar.qml b/components/ProgressBar.qml index 6b1164b40..a50b87028 100644 --- a/components/ProgressBar.qml +++ b/components/ProgressBar.qml @@ -12,19 +12,18 @@ Components.ProgressBar { height: orientation === Qt.Horizontal ? sizehint.height : 200 width: orientation === Qt.Horizontal ? 200 : sizehint.height - background: QStyleBackground{ + background: QStyleItem { anchors.fill:parent - style: QStyleItem { - 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 : 1000000 - value: indeterminate ? 1 : progressbar.value * factor - minimum: indeterminate ? 0 : progressbar.minimumValue * factor - maximum: indeterminate ? 0 : progressbar.maximumValue * factor - enabled: progressbar.enabled - horizontal: progressbar.orientation == Qt.Horizontal - } + 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 : 1000000 + value: indeterminate ? 1 : progressbar.value * factor + minimum: indeterminate ? 0 : progressbar.minimumValue * factor + maximum: indeterminate ? 0 : progressbar.maximumValue * factor + enabled: progressbar.enabled + horizontal: progressbar.orientation == Qt.Horizontal + } } diff --git a/components/ScrollArea.qml b/components/ScrollArea.qml index 169a972dd..c7f8473e0 100644 --- a/components/ScrollArea.qml +++ b/components/ScrollArea.qml @@ -27,12 +27,11 @@ FocusScope { property int frameMargins : frame ? frameWidth : 0 - QStyleBackground { - style: QStyleItem{ - id:styleitem - elementType: frame ? "frame" : "" - sunken: true - } + QStyleItem { + id:styleitem + elementType: frame ? "frame" : "" + sunken: true + anchors.fill: parent anchors.rightMargin: frame ? (frameAroundContents ? (vscrollbar.visible ? vscrollbar.width + 2 * frameMargins : 0) : -frameWidth) : 0 anchors.bottomMargin: frame ? (frameAroundContents ? (hscrollbar.visible ? hscrollbar.height + 2 * frameMargins : 0) : -frameWidth) : 0 @@ -87,14 +86,11 @@ FocusScope { anchors.bottomMargin: (frameAroundContents && hscrollbar.visible) ? hscrollbar.height : 0 } - QStyleBackground { + QStyleItem { z: 2 anchors.fill: parent anchors.margins: -4 visible: highlightOnFocus && parent.activeFocus && styleitem.styleHint("focuswidget") - style: QStyleItem { - id:framestyle - elementType: "focusframe" - } + elementType: "focusframe" } } diff --git a/components/ScrollBar.qml b/components/ScrollBar.qml index 8032de9fd..5eb65d8fd 100644 --- a/components/ScrollBar.qml +++ b/components/ScrollBar.qml @@ -60,21 +60,18 @@ MouseArea { value = minimumValue } - QStyleBackground { - id:bgitem + QStyleItem { + id: styleitem anchors.fill:parent - style: QStyleItem { - id:styleitem - elementType: "scrollbar" - hover: activeControl != "none" - activeControl: "none" - sunken: upPressed | downPressed - minimum: slider.minimumValue - maximum: slider.maximumValue - value: slider.value - horizontal: orientation == Qt.Horizontal - enabled: parent.enabled - } + elementType: "scrollbar" + hover: activeControl != "none" + activeControl: "none" + sunken: upPressed | downPressed + minimum: slider.minimumValue + maximum: slider.maximumValue + value: slider.value + horizontal: orientation == Qt.Horizontal + enabled: parent.enabled } property variant handleRect diff --git a/components/Slider.qml b/components/Slider.qml index 9175f9f3e..694d2305a 100644 --- a/components/Slider.qml +++ b/components/Slider.qml @@ -15,19 +15,18 @@ Components.Slider{ height: orientation === Qt.Horizontal ? sizehint.height : 200 width: orientation === Qt.Horizontal ? 200 : sizehint.height - groove: QStyleBackground { + groove: QStyleItem { anchors.fill:parent - style: QStyleItem { - elementType: "slider" - sunken: pressed - maximum: slider.maximumValue*100 - minimum: slider.minimumValue*100 - value: slider.value*100 - horizontal: slider.orientation == Qt.Horizontal - enabled: slider.enabled - focus: slider.focus - activeControl: tickmarksEnabled ? "ticks" : "" - } + elementType: "slider" + sunken: pressed + maximum: slider.maximumValue*100 + minimum: slider.minimumValue*100 + value: slider.value*100 + horizontal: slider.orientation == Qt.Horizontal + enabled: slider.enabled + focus: slider.focus + activeControl: tickmarksEnabled ? "ticks" : "" + } handle: null diff --git a/components/SpinBox.qml b/components/SpinBox.qml index 030315c47..26a2bd21a 100644 --- a/components/SpinBox.qml +++ b/components/SpinBox.qml @@ -25,7 +25,7 @@ Components.SpinBox { clip:false background: - Item { + Item { anchors.fill: parent property variant __editRect @@ -41,16 +41,13 @@ Components.SpinBox { id:focusFrame anchors.fill: editBackground visible:framestyle.styleHint("focuswidget") - QStyleBackground{ + QStyleItem { anchors.margins: -6 anchors.leftMargin: -5 anchors.rightMargin: -7 anchors.fill: parent visible: spinbox.focus || spinbox.activeFocus - style: QStyleItem { - id:framestyle - elementType:"focusframe" - } + elementType:"focusframe" } } @@ -64,21 +61,18 @@ Components.SpinBox { onWidthChanged:updateRect() onHeightChanged:updateRect() - QStyleBackground { - id:spinboxbg + QStyleItem { + id: styleitem anchors.fill:parent - style: QStyleItem { - id: styleitem - elementType: "spinbox" - sunken: downPressed | upPressed - hover: containsMouse - focus: spinbox.focus || spinbox.activeFocus - enabled: spinbox.enabled - value: (upPressed? 1 : 0) | - (downPressed== 1 ? 1<<1 : 0) | - (upEnabled? (1<<2) : 0) | - (downEnabled == 1 ? (1<<3) : 0) - } + elementType: "spinbox" + sunken: downPressed | upPressed + hover: containsMouse + focus: spinbox.focus || spinbox.activeFocus + enabled: spinbox.enabled + value: (upPressed? 1 : 0) | + (downPressed== 1 ? 1<<1 : 0) | + (upEnabled? (1<<2) : 0) | + (downEnabled == 1 ? (1<<3) : 0) } } diff --git a/components/TabBar.qml b/components/TabBar.qml index ee3780a78..bb5a6e8ec 100644 --- a/components/TabBar.qml +++ b/components/TabBar.qml @@ -26,6 +26,7 @@ Item { } QStyleItem { + visible:false id:styleitem elementType: "tab" text: "generic" @@ -53,16 +54,14 @@ Item { height: tabHeight z: selected ? 1 : -1 - QStyleBackground { - style: QStyleItem { - id:style - elementType: "tab" - selected: tab.selected - info: tabbar.position - text: tabFrame.tabs[index].title - activeControl: tabFrame.count == 1 ? "only" : index == 0 ? "beginning" : - index == tabFrame.count-1 ? "end" : "middle" - } + QStyleItem { + id:style + elementType: "tab" + selected: tab.selected + info: tabbar.position + text: tabFrame.tabs[index].title + activeControl: tabFrame.count == 1 ? "only" : index == 0 ? "beginning" : + index == tabFrame.count-1 ? "end" : "middle" anchors.leftMargin: -tabOverlap + (style.text == "North" && (style.activeControl == "middle" || style.activeControl == "end") && tab.selected ? -__overlap : 0) diff --git a/components/TabFrame.qml b/components/TabFrame.qml index 91c025b31..1a3a29965 100644 --- a/components/TabFrame.qml +++ b/components/TabFrame.qml @@ -30,20 +30,17 @@ Item{ } } - QStyleBackground { + QStyleItem { id: frame - z:-1 - style: QStyleItem { - id:style - elementType: "tabframe" - info: position - value: tabbar && tabsVisible && tabbar.tab(current) ? tabbar.tab(current).x : 0 - minimum: tabbar && tabsVisible && tabbar.tab(current) ? tabbar.tab(current).width : 0 - } - anchors.fill:parent + z: -1 + elementType: "tabframe" + info: position + value: tabbar && tabsVisible && tabbar.tab(current) ? tabbar.tab(current).x : 0 + minimum: tabbar && tabsVisible && tabbar.tab(current) ? tabbar.tab(current).width : 0 + anchors.fill: parent Item { - id:stack - anchors.fill:parent + id: stack + anchors.fill: parent anchors.margins: frame ? 2 : 0 } anchors.topMargin: tabbar && tabsVisible && position == "North" ? tabbar.height - __baseOverlap : 0 diff --git a/components/TextField.qml b/components/TextField.qml index 8ec58ca8f..d993ec452 100644 --- a/components/TextField.qml +++ b/components/TextField.qml @@ -23,13 +23,11 @@ Components.TextField { hover:containsMouse } - background: QStyleBackground { - anchors.fill:parent - style: QStyleItem{ - elementType:"edit" - sunken:true - focus:textfield.activeFocus - } + background: QStyleItem { + anchors.fill: parent + elementType: "edit" + sunken: true + focus: textfield.activeFocus } Item{ @@ -37,16 +35,14 @@ Components.TextField { anchors.fill: textfield parent:textfield visible:framestyle.styleHint("focuswidget") - QStyleBackground{ + QStyleItem { + id:framestyle anchors.margins: -2 anchors.rightMargin:-4 anchors.bottomMargin:-4 anchors.fill: parent visible:textfield.activeFocus - style: QStyleItem { - id:framestyle - elementType:"focusframe" - } + elementType:"focusframe" } } } diff --git a/components/ToolBar.qml b/components/ToolBar.qml index f91b72fb9..a63b6ccb4 100644 --- a/components/ToolBar.qml +++ b/components/ToolBar.qml @@ -2,10 +2,10 @@ import QtQuick 1.0 import "custom" as Components import "plugin" -QStyleBackground { +QStyleItem{ id:toolbar - width:200 - height: styleitem.sizeFromContents(32, 32).height - style: QStyleItem{id:styleitem; elementType:"toolbar"} + width: 200 + height: sizeFromContents(32, 32).height + elementType: "toolbar" } diff --git a/components/ToolButton.qml b/components/ToolButton.qml index 7cabb3d70..636a11db5 100644 --- a/components/ToolButton.qml +++ b/components/ToolButton.qml @@ -10,20 +10,18 @@ Components.Button { QStyleItem {elementType: "toolbutton"; id:styleitem } - background: QStyleBackground { - anchors.fill:parent - style: QStyleItem { - id:styleitem - elementType: "toolbutton" - on: pressed | checked - sunken: pressed - raised: containsMouse - hover: containsMouse + background: QStyleItem { + anchors.fill: parent + id: styleitem + elementType: "toolbutton" + on: pressed | checked + sunken: pressed + raised: containsMouse + hover: containsMouse - } Image{ - source:button.iconSource - anchors.centerIn:parent + source: button.iconSource + anchors.centerIn: parent } } } diff --git a/components/custom/BasicButton.qml b/components/custom/BasicButton.qml index ee4b34118..14c929b1c 100644 --- a/components/custom/BasicButton.qml +++ b/components/custom/BasicButton.qml @@ -11,6 +11,7 @@ Item { property alias checked: behavior.checked property Component background: null + property Item backgroundItem: backgroundLoader.item property color textColor: syspal.text; property bool activeFocusOnPress: true diff --git a/components/custom/Button.qml b/components/custom/Button.qml index d0ba44c62..45abc83f6 100644 --- a/components/custom/Button.qml +++ b/components/custom/Button.qml @@ -10,6 +10,7 @@ BasicButton { // implementation background: defaultStyle.background + property Item labelItem: labelLoader.item Loader { id: labelLoader diff --git a/components/custom/ChoiceList.qml b/components/custom/ChoiceList.qml index 5e288b42d..892a297eb 100644 --- a/components/custom/ChoiceList.qml +++ b/components/custom/ChoiceList.qml @@ -17,6 +17,7 @@ Item { property bool pressed: false //mm needed? property Component background: null + property Item backgroundItem: backgroundLoader.item property Component listItem: null property Component popupFrame: null @@ -35,6 +36,7 @@ Item { SystemPalette { id: syspal } Loader { + id: backgroundLoader property alias styledItem: choiceList sourceComponent: background anchors.fill: parent diff --git a/components/styleitem/qstyleitem.cpp b/components/styleitem/qstyleitem.cpp index b4027d2be..297609e9d 100644 --- a/components/styleitem/qstyleitem.cpp +++ b/components/styleitem/qstyleitem.cpp @@ -312,6 +312,8 @@ void QStyleItem::initStyleOption() opt->sliderValue = value(); opt->subControls = QStyle::SC_All; } + if (!m_styleoption) + m_styleoption = new QStyleOption(); if (!m_styleoption->rect.isValid()) m_styleoption->rect = QRect(0, 0, width(), height()); -- GitLab