This repository has been archived by the owner on Oct 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ScrollBar.qml
executable file
·158 lines (145 loc) · 5.13 KB
/
ScrollBar.qml
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
* Copyright 2017 Marco Martin <mart@kde.org>
* Copyright 2017 The Qt Company Ltd.
*
* GNU Lesser General Public License Usage
* Alternatively, this file may be used under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software
* Foundation and appearing in the file LICENSE.LGPLv3 included in the
* packaging of this file. Please review the following information to
* ensure the GNU Lesser General Public License version 3 requirements
* will be met: https://www.gnu.org/licenses/lgpl.html.
*
* GNU General Public License Usage
* Alternatively, this file may be used under the terms of the GNU
* General Public License version 2.0 or later as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included in
* the packaging of this file. Please review the following information to
* ensure the GNU General Public License version 2.0 requirements will be
* met: http://www.gnu.org/licenses/gpl-2.0.html.
*/
import QtQuick 2.6
import org.kde.qqc2desktopstyle.private 1.0 as StylePrivate
import QtQuick.Templates 2.3 as T
import org.kde.kirigami 2.2 as Kirigami
T.ScrollBar {
id: controlRoot
implicitWidth: background.implicitWidth
implicitHeight: background.implicitHeight
hoverEnabled: true
visible: controlRoot.size < 1.0
background: MouseArea {
id: mouseArea
anchors.fill: parent
visible: controlRoot.size < 1.0
hoverEnabled: true
state: "inactive"
onPositionChanged: style.activeControl = style.hitTest(mouse.x, mouse.y)
onExited: style.activeControl = "groove";
onPressed: {
if (style.activeControl == "down") {
buttonTimer.increment = 0.02;
buttonTimer.running = true;
mouse.accepted = true
} else if (style.activeControl == "up") {
buttonTimer.increment = -0.02;
buttonTimer.running = true;
mouse.accepted = true
} else {
mouse.accepted = false
}
}
onReleased: {
buttonTimer.running = false;
mouse.accepted = false
}
onCanceled: buttonTimer.running = false;
implicitWidth: style.horizontal ? 200 : style.pixelMetric("scrollbarExtent")
implicitHeight: style.horizontal ? style.pixelMetric("scrollbarExtent") : 200
StylePrivate.StyleItem {
id: style
control: controlRoot
anchors.fill: parent
elementType: "scrollbar"
hover: activeControl != "none"
activeControl: "none"
sunken: controlRoot.pressed
minimum: 0
maximum: (controlRoot.height/controlRoot.size - controlRoot.height)
value: controlRoot.position * (controlRoot.height/controlRoot.size)
horizontal: controlRoot.orientation == Qt.Horizontal
enabled: controlRoot.enabled
visible: controlRoot.size < 1.0
opacity: 1
Timer {
id: buttonTimer
property real increment
repeat: true
interval: 150
onTriggered: {
controlRoot.position += increment;
}
}
}
StylePrivate.StyleItem {
id: inactiveStyle
anchors.fill: parent
control: controlRoot
elementType: "scrollbar"
activeControl: "none"
sunken: false
minimum: 0
maximum: style.maximum
value: style.value
horizontal: style.horizontal
enabled: controlRoot.enabled
visible: controlRoot.size < 1.0
opacity: 1
}
states: [
State {
name: "hover"
when: mouseArea.containsMouse
PropertyChanges {
target: style
opacity: 1
}
PropertyChanges {
target: inactiveStyle
opacity: 0
}
},
State {
name: "inactive"
when: !mouseArea.containsMouse
PropertyChanges {
target: style
opacity: 0
}
PropertyChanges {
target: inactiveStyle
opacity: 1
}
}
]
transitions: [
Transition {
ParallelAnimation {
NumberAnimation {
target: style
property: "opacity"
duration: Kirigami.Units.shortDuration
easing.type: Easing.InOutQuad
}
NumberAnimation {
target: inactiveStyle
property: "opacity"
duration: Kirigami.Units.shortDuration
easing.type: Easing.InOutQuad
}
}
}
]
}
contentItem: Item {}
}