-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CircularProgressButton.qml
205 lines (187 loc) · 6.29 KB
/
CircularProgressButton.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import QtQuick 2.15
import QtQuick.Shapes 2.15
import Qt5Compat.GraphicalEffects
Item {
id: progress
implicitHeight: buttonSize
implicitWidth: buttonSize
// Signals
signal pressAndHold
signal pressAndHoldCustom
signal pressEnd
signal released
// Properties
// General
property int buttonSize: 250
property int circleSize: 10
property bool roundCap: true
property bool status: false
property int startAngle: -90
property real maxValue: 100
property real value: 0
property url iconSource: ""
// Drop Shadow
property bool enableDropShadow: true
property color dropShadowColor: "#20000000"
property int dropShadowRadius: circleSize
// Bg Circle
property color bgStorkeColor: "#7e7e7e"
property int strokeBgWidth: circleSize
property color bgColor: "transparent"
property color innerCircleColor: "white"
// Progress Circle
property color progressColor: "#399fff"
property int progressWidth: circleSize
QtObject {
id: internal
property Component dropShadow: DropShadow {
color: progress.dropShadowColor
fast: true
verticalOffset: 0
horizontalOffset: 0
samples: 12
radius: progress.dropShadowRadius
}
}
Shape {
id: shape
anchors.fill: parent
antialiasing: true
layer.enabled: true
layer.samples: 4
asynchronous: true
layer.effect: progress.enableDropShadow ? internal.dropShadow : null
ShapePath {
id: pathBg
strokeColor: progress.bgStorkeColor
fillColor: progress.bgColor
strokeWidth: progress.strokeBgWidth
capStyle: progress.roundCap ? ShapePath.RoundCap : ShapePath.FlatCap
joinStyle: ShapePath.RoundJoin
PathAngleArc {
radiusX: (progress.width / 2) - (pathBg.strokeWidth / 2)
radiusY: (progress.height / 2) - (pathBg.strokeWidth / 2)
centerX: progress.width / 2
centerY: progress.height / 2
startAngle: progress.startAngle
sweepAngle: 360
}
}
ShapePath {
id: path
strokeColor: progressColor
fillColor: progress.bgColor
strokeWidth: progress.progressWidth
capStyle: progress.roundCap ? ShapePath.RoundCap : ShapePath.FlatCap
joinStyle: ShapePath.RoundJoin
PathAngleArc {
radiusX: (progress.width / 2) - (progress.progressWidth / 2)
radiusY: (progress.height / 2) - (progress.progressWidth / 2)
centerX: progress.width / 2
centerY: progress.height / 2
startAngle: progress.startAngle
sweepAngle: (360 / progress.maxValue * progress.value)
}
}
ShapePath {
id: pathInner
strokeColor: progress.innerCircleColor
fillColor: progress.bgColor
strokeWidth: progress.progressWidth / 3
capStyle: progress.roundCap ? ShapePath.RoundCap : ShapePath.FlatCap
joinStyle: ShapePath.RoundJoin
PathAngleArc {
radiusX: (progress.width / 2) - (progress.progressWidth / 2) - 10
radiusY: (progress.height / 2) - (progress.progressWidth / 2) - 10
centerX: progress.width / 2
centerY: progress.height / 2
startAngle: 0
sweepAngle: 360
}
}
Image {
id: icon
anchors.fill: parent
source: progress.iconSource
fillMode: Image.PreserveAspectFit
}
MouseArea {
id: mouseArea
property int pressAndHoldDuration: 10
anchors.verticalCenter: parent.verticalCenter
pressAndHoldInterval: 1005
z: 3
anchors.horizontalCenter: parent.horizontalCenter
width: progress.implicitHeight
height: progress.implicitHeight
propagateComposedEvents: true
onPressAndHold: progress.pressAndHold()
onPressed: pressAndHoldTimer.restart()
onReleased: relasedTimer.restart()
Timer {
id: pressAndHoldTimer
interval: parent.pressAndHoldDuration
running: false
repeat: true
onTriggered: {
progress.pressAndHoldCustom()
}
}
Timer {
id: relasedTimer
interval: parent.pressAndHoldDuration
running: false
repeat: true
onTriggered: {
progress.released()
}
}
}
}
onPressAndHoldCustom: {
if (progress.status == true) {
progress.value -= 1
if (progress.value <= 0) {
pressAndHoldTimer.stop()
progress.status = false
progress.pressEnd()
}
} else {
progress.value += 1
if (progress.value >= 100) {
pressAndHoldTimer.stop()
progress.status = true
progress.pressEnd()
}
}
}
onReleased: {
pressAndHoldTimer.stop()
relasedTimer.restart()
if (!progress.status) {
if (progress.value == 100) {
console.log("released and mode on", progress.status)
relasedTimer.stop()
} else {
progress.value -= 1
if (progress.value <= 0) {
relasedTimer.stop()
progress.value = 0
console.log("released and mode on", progress.status)
}
}
} else {
if (progress.value == 0) {
relasedTimer.stop()
console.log("released1 and mode on", progress.status)
} else {
progress.value += 1
if (progress.value >= 100) {
relasedTimer.stop()
progress.value = 100
console.log("released and mode on", progress.status)
}
}
}
}
}