QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
TimedProgressTracker.qml
Go to the documentation of this file.
1import QtQuick
2
3Item {
4 id: root
5 // Setable propterties
6 property real timeoutSeconds: 0
7 property string progressLabel: ""
8 property bool running: false
9
10 // Do not set these properties
11 property real progress: 0
12
13 signal timeout()
14
15 property double _lastUpdateTime: 0
16
17 Timer {
18 id: timeoutTimer
19 interval: timeoutSeconds * 1000
20 repeat: false
21 running: running
22
23 onTriggered: {
24 root.running = false
25 root.progress = 0
26 root.progressLabel = ""
27 root.timeout()
28 }
29 }
30
31 SequentialAnimation on progress {
32 id: progressAnimation
33 running: root.running
34 loops: 1
35
36 NumberAnimation {
37 target: root
38 property: "progress"
39 to: 1
40 duration: timeoutSeconds * 1000
41 }
42 }
43
44 onProgressChanged: {
45 const currentTime = Date.now() * 0.001
46 if (currentTime - _lastUpdateTime < 0.1) {
47 return
48 }
49
50 if (running) {
51 var currentCount = (progress * timeoutSeconds)
52 progressLabel = (timeoutSeconds - currentCount).toFixed(1)
53 } else {
54 progressLabel = ""
55 }
56
57 _lastUpdateTime = currentTime
58 }
59
60 function start() {
61 running = true
62 progress = 0
63 timeoutTimer.restart()
64 progressAnimation.restart()
65 }
66
67 function stop() {
68 running = false
69 progress = 0
70 timeoutTimer.stop()
71 progressAnimation.stop()
72 progressLabel = ""
73 }
74}