diff options
author | David Boddie <david.boddie@nokia.com> | 2010-09-07 16:36:49 (GMT) |
---|---|---|
committer | David Boddie <david.boddie@nokia.com> | 2010-09-07 16:36:49 (GMT) |
commit | 415ad7b69d364c41156d35b98790b02667a6671b (patch) | |
tree | 759b02134da808773a1d68eecf2eb5c0ff12167c /demos/declarative/flickr/common/Slider.qml | |
parent | 3c18c2a43260a271f8a13e89053eede15d399005 (diff) | |
parent | 703d85e8991e2061062f6d7c695cdeb45d9661fd (diff) | |
download | Qt-415ad7b69d364c41156d35b98790b02667a6671b.zip Qt-415ad7b69d364c41156d35b98790b02667a6671b.tar.gz Qt-415ad7b69d364c41156d35b98790b02667a6671b.tar.bz2 |
Merge branch '4.7' into qmldocs
Diffstat (limited to 'demos/declarative/flickr/common/Slider.qml')
-rw-r--r-- | demos/declarative/flickr/common/Slider.qml | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/demos/declarative/flickr/common/Slider.qml b/demos/declarative/flickr/common/Slider.qml index 4353f8d..faa2e5f 100644 --- a/demos/declarative/flickr/common/Slider.qml +++ b/demos/declarative/flickr/common/Slider.qml @@ -45,11 +45,24 @@ Item { id: slider; width: 400; height: 16 // value is read/write. - property real value - onValueChanged: { handle.x = 2 + (value - minimum) * slider.xMax / (maximum - minimum); } + property real value: 1 + onValueChanged: updatePos(); property real maximum: 1 property real minimum: 1 - property int xMax: slider.width - handle.width - 4 + property int xMax: width - handle.width - 4 + onXMaxChanged: updatePos(); + onMinimumChanged: updatePos(); + + function updatePos() { + if (maximum > minimum) { + var pos = 2 + (value - minimum) * slider.xMax / (maximum - minimum); + pos = Math.min(pos, width - handle.width - 2); + pos = Math.max(pos, 2); + handle.x = pos; + } else { + handle.x = 2; + } + } Rectangle { anchors.fill: parent @@ -62,13 +75,14 @@ Item { Rectangle { id: handle; smooth: true - x: slider.width / 2 - handle.width / 2; y: 2; width: 30; height: slider.height-4; radius: 6 + y: 2; width: 30; height: slider.height-4; radius: 6 gradient: Gradient { GradientStop { position: 0.0; color: "lightgray" } GradientStop { position: 1.0; color: "gray" } } MouseArea { + id: mouse anchors.fill: parent; drag.target: parent drag.axis: Drag.XAxis; drag.minimumX: 2; drag.maximumX: slider.xMax+2 onPositionChanged: { value = (maximum - minimum) * (handle.x-2) / slider.xMax + minimum; } |