summaryrefslogtreecommitdiff
path: root/SDL_Core/src/components/qt_hmi/References/Look/plugins/com/ford/hmiframework/qml/BaseWidgets/FWdgtScrollbar.qml
blob: 74c1e27e9bb18f5ed4d5987ebd4ec5acdaf512ca (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 2.0

BorderImage {
        property variant target

        source: "../Resources/scrollbar.png"
        border {left: 0; top: 3; right: 0; bottom: 3}
        width: 17

        //anchors {top: target.top; bottom: target.bottom; right: target.right }
        visible: (track.height == slider.height) ? false : true //TODO: !visible -> width: 0 (but creates a binding loop)

        Item {
                anchors {fill: parent; margins: 1; rightMargin: 2; bottomMargin: 2}

                Image {
                        id: upArrow
                        source: "../Resources/up-arrow.png"
                        anchors.top: parent.top
                        MouseArea {
                                anchors.fill: parent
                                onPressed: {
                                        timer.scrollAmount = -10
                                        timer.running = true;
                                }
                                onReleased: {
                                        timer.running = false;
                                }
                        }
                }

                Timer {
                        property int scrollAmount

                        id: timer
                        repeat: true
                        interval: 20
                        onTriggered: {
                                target.contentY = Math.max(
                                                0, Math.min(
                                                target.contentY + scrollAmount,
                                                target.contentHeight - target.height));
                        }
                }

                Item {
                        id: track
                        anchors {top: upArrow.bottom; topMargin: 1; bottom: dnArrow.top;}
                        width: parent.width

                        MouseArea {
                                anchors.fill: parent
                                onPressed: {
                                        timer.scrollAmount = target.height * (mouseY < slider.y ? -1 : 1)       // scroll by a page
                                        timer.running = true;
                                }
                                onReleased: {
                                        timer.running = false;
                                }
                        }

                        BorderImage {
                                id:slider

                                source: "../Resources/slider.png"
                                border {left: 0; top: 3; right: 0; bottom: 3}
                                width: parent.width

                                height: Math.min(target.height / target.contentHeight * track.height, track.height)
                                y: target.visibleArea.yPosition * track.height

                                MouseArea {
                                        anchors.fill: parent
                                        drag.target: parent
                                        drag.axis: Drag.YAxis
                                        drag.minimumY: 0
                                        drag.maximumY: track.height - height

                                        onPositionChanged: {
                                                if (pressedButtons == Qt.LeftButton) {
                                                        target.contentY = slider.y * target.contentHeight / track.height
                                                }
                                        }
                                }
                        }
                }
                Image {
                        id: dnArrow
                        source: "../Resources/dn-arrow.png"
                        anchors.bottom: parent.bottom
                        MouseArea {
                                anchors.fill: parent
                                onPressed: {
                                        timer.scrollAmount = 10
                                        timer.running = true;
                                }
                                onReleased: {
                                        timer.running = false;
                                }
                        }
                }
        }
}