summaryrefslogtreecommitdiffstats
path: root/demos/declarative/flickr/content/Slider.qml
blob: 92f499361c5aeb8c2d284735ab89a462dad26986 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Item {
    id: Slider; width: 400; height: 16

    // value is read/write.
    property real value
    onValueChanged: { Handle.x = (value - minimum) * Slider.xMax / (maximum - minimum); }
    property real maximum: 1
    property real minimum: 1
    property int xMax: Slider.width - Handle.width - 2

    Rect {
        id: Container; anchors.fill: parent; gradientColor: "#66000000";
        pen.color: "white"; pen.width: 1;  color: "#66343434"; radius: 8
    }

    Rect {
        id: Handle
        x: Slider.width / 2 - Handle.width / 2; y: 2; width: 30; height: 12
        color: "lightgray"; gradientColor: "gray"; radius: 6

        MouseRegion {
            anchors.fill: parent; drag.target: parent
            drag.axis: "x"; drag.xmin: 2; drag.xmax: Slider.xMax
            onPositionChanged: { value = (maximum - minimum) * Handle.x / Slider.xMax + minimum; }
        }
    }
}