implemented boundary checking for stroke list
[stuff:qml-dashboard.git] / multilayer-dashboard / StrokeList.qml
1 import Qt 4.7
2 import Qt.labs.gestures 1.0
3
4 Rectangle {
5     id: borderWidget
6     anchors.fill: parent
7     radius: 10
8     color: "red"
9
10     Rectangle {
11
12         id: mainrect
13
14         anchors.fill: parent
15         anchors.margins: 10
16         radius: 10
17         clip: true
18
19         function foo(index) {
20             var colors = ["blue", "green", "grey", "red", "lightgreen"];
21             return colors[index % colors.length]
22         }
23
24         Rectangle {
25             id: list
26             radius: 10
27             anchors.left: parent.left
28             anchors.right: parent.right
29             height: parent.height
30
31             onHeightChanged: y = 0
32
33             Repeater {
34                 model: [ "apple", "orange", "pineapple", "coconut", "foo", "bar", "baz", "zealot" ]
35
36                 Button {
37                     x: 0
38                     y: 0 + (height + 2) * index
39                     bgColor: mainrect.foo(index)
40                     text: modelData
41                 }
42             }
43
44             property int maxY : (mainrect.height < list.childrenRect.height) ?
45                     0 :
46                     (mainrect.height - list.childrenRect.height)
47             property int minY : (mainrect.height < list.childrenRect.height) ?
48                     -(list.childrenRect.height - mainrect.height) :
49                     0
50         }
51         GestureArea {
52             anchors.fill: parent
53             property bool panEnabled : false
54
55             Pan {
56                 onUpdated: {
57                     if (parent.panEnabled)
58                         list.y += gesture.delta.y
59                     else if (Math.abs(gesture.offset.y) >= 10 && Math.abs(gesture.offset.x) < 10)
60                         parent.panEnabled = true
61
62                     if(list.y > list.maxY)
63                         list.y = list.maxY
64                     else if(list.y < list.minY)
65                         list.y = list.minY
66                 }
67                 onFinished: {
68                     parent.panEnabled = false
69                 }
70             }
71         }
72     }
73 }