summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Bache-Wiig <jens.bache-wiig@digia.com>2014-02-24 18:55:52 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-25 16:09:44 +0100
commit5c8e205c5f4f4a0d131cb1f2511ca0b91923c0f2 (patch)
tree053ab9da0ecbf135726594b5a6d3a3d23cc79cf9
parent784d8982d3293e4632f0a19d61a16372c0d279df (diff)
downloadqtquickcontrols-5c8e205c5f4f4a0d131cb1f2511ca0b91923c0f2.tar.gz
Fix initial incorrect value for Switch
Task-number: QTBUG-36910 We would sometimes get the incorrect value for switch. This patch doesn't radically change the logic but it makes the initial value assignment a binding rather than depend on oncompleted. I also slightly cleaned up and simplified the logic. Change-Id: I001494a5f9f3a421a5c755a7fed1f9be09d918bd Reviewed-by: J-P Nurmi <jpnurmi@digia.com> Reviewed-by: Caroline Chao <caroline.chao@digia.com>
-rw-r--r--src/controls/Styles/Base/SwitchStyle.qml9
-rw-r--r--src/controls/Switch.qml12
2 files changed, 9 insertions, 12 deletions
diff --git a/src/controls/Styles/Base/SwitchStyle.qml b/src/controls/Styles/Base/SwitchStyle.qml
index 68796645..94e86270 100644
--- a/src/controls/Styles/Base/SwitchStyle.qml
+++ b/src/controls/Styles/Base/SwitchStyle.qml
@@ -125,9 +125,9 @@ Style {
implicitWidth: Math.round(grooveLoader.width + padding.left + padding.right)
implicitHeight: grooveLoader.implicitHeight + padding.top + padding.bottom
- property var __groove: grooveLoader
property var __handle: handleLoader
- property bool enableAnimation: false
+ property int min: padding.left
+ property int max: grooveLoader.width - handleLoader.width - padding.right
Loader {
id: grooveLoader
@@ -142,6 +142,9 @@ Style {
id: handleLoader
z:1
+
+ x: control.checked ? max : min
+
anchors.top: grooveLoader.top
anchors.bottom: grooveLoader.bottom
anchors.topMargin: padding.top
@@ -149,7 +152,7 @@ Style {
Behavior on x {
id: behavior
- enabled: enableAnimation
+ enabled: handleLoader.status === Loader.Ready
NumberAnimation {
duration: 150
easing.type: Easing.OutCubic
diff --git a/src/controls/Switch.qml b/src/controls/Switch.qml
index bed46a84..668ee22f 100644
--- a/src/controls/Switch.qml
+++ b/src/controls/Switch.qml
@@ -102,10 +102,9 @@ Control {
MouseArea {
id: internal
- property Item handle: __panel ? __panel.__handle : null
- property int min: __style ? __style.padding.left : 0
- property int max: handle.parent.width - (handle ? handle.width : 0) -
- ( __style ? __style.padding.right : 0)
+ property Item handle: __panel.__handle
+ property int min: __panel.min
+ property int max: __panel.max
focus: true
anchors.fill: parent
drag.threshold: 0
@@ -129,11 +128,6 @@ Control {
}
}
- Component.onCompleted: {
- internal.handle.x = checked ? internal.max : internal.min
- __panel.enableAnimation = true
- }
-
onCheckedChanged: {
if (internal.handle)
internal.handle.x = checked ? internal.max : internal.min