summaryrefslogtreecommitdiffstats
path: root/demos/declarative/flickr/common/Slider.qml
diff options
context:
space:
mode:
authorDavid Boddie <david.boddie@nokia.com>2010-09-07 16:35:56 (GMT)
committerDavid Boddie <david.boddie@nokia.com>2010-09-07 16:35:56 (GMT)
commit703d85e8991e2061062f6d7c695cdeb45d9661fd (patch)
tree12548ba44aec50979cc116ffba392b8dcd166b58 /demos/declarative/flickr/common/Slider.qml
parentb3de9c2ee4c9f36a6133fc78109909c3ee6317fd (diff)
parenta93243ce81fdc71842bb133e7eadb9476e4648e4 (diff)
downloadQt-703d85e8991e2061062f6d7c695cdeb45d9661fd.zip
Qt-703d85e8991e2061062f6d7c695cdeb45d9661fd.tar.gz
Qt-703d85e8991e2061062f6d7c695cdeb45d9661fd.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-2 into 4.7
Diffstat (limited to 'demos/declarative/flickr/common/Slider.qml')
-rw-r--r--demos/declarative/flickr/common/Slider.qml22
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; }