Merge branch 'qml'
[mdictionary] / src / mdictionary / qml / ScrollBar.qml
1 import Qt 4.7
2
3 Item {
4     id: container
5
6     property variant scrollArea
7     property variant orientation: Qt.Vertical
8
9     opacity: 0
10
11     function position()
12     {
13         var ny = 0;
14         if (container.orientation == Qt.Vertical)
15             ny = scrollArea.visibleArea.yPosition * container.height;
16         else
17             ny = scrollArea.visibleArea.xPosition * container.width;
18         if (ny > 2)
19             return ny;
20         else
21             return 2;
22     }
23
24     function size()
25     {
26         var nh, ny;
27
28         if (container.orientation == Qt.Vertical)
29             nh = scrollArea.visibleArea.heightRatio * container.height;
30         else
31             nh = scrollArea.visibleArea.widthRatio * container.width;
32
33         if (container.orientation == Qt.Vertical)
34             ny = scrollArea.visibleArea.yPosition * container.height;
35         else
36             ny = scrollArea.visibleArea.xPosition * container.width;
37
38         if (ny > 3) {
39             var t;
40             if (container.orientation == Qt.Vertical)
41                 t = Math.ceil(container.height - 3 - ny);
42             else
43                 t = Math.ceil(container.width - 3 - ny);
44             if (nh > t) return t; else return nh;
45         } else
46             return nh + ny;
47     }
48
49  //Rectangle { anchors.fill: parent; color: "Black"; opacity: 0.5 }
50
51  /*   BorderImage {
52         source: "pics/scrollbar.png"
53         border { left: 1; right: 1; top: 1; bottom: 1 }
54         x: container.orientation == Qt.Vertical ? 2 : position()
55         width: container.orientation == Qt.Vertical ? container.width - 4 : size()
56         y: container.orientation == Qt.Vertical ? position() : 2
57         height: container.orientation == Qt.Vertical ? size() : container.height - 4
58     } */
59
60     states: State {
61         name: "visible"
62         when: container.orientation == Qt.Vertical ? scrollArea.movingVertically : scrollArea.movingHorizontally
63         PropertyChanges { target: container; opacity: 1.0 }
64     }
65
66     transitions: Transition {
67         from: "visible"; to: ""
68         NumberAnimation { properties: "opacity"; duration: 600 }
69     }
70 }