-
Notifications
You must be signed in to change notification settings - Fork 0
/
Countdown.qml
62 lines (54 loc) · 1.33 KB
/
Countdown.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
import QtQuick 2.0
Item {
id: countdown
property int length: 5
property int tempLength: 0
property int current: 0
property bool running: false
Rectangle {
visible: timer.running
anchors.fill: parent
color: Qt.rgba(255,255,255,0.3)
Text {
text: length - current
font.pixelSize: countdown.height * 0.5
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
anchors.fill: parent
}
}
Timer {
id: timer
interval: 1000
repeat: true
onTriggered: (length - 1) == current ? finish() : countUp()
}
function finish()
{
timer.stop();
current = 0;
countdown.running = false;
if(countdown.tempLength != 0)
{
countdown.length = countdown.tempLength;
countdown.tempLength = 0;
}
finished();
}
signal finished()
function start() {
countdown.running = true;
console.log('Starting countdown timer.');
timer.start();
}
function startWithLength(len)
{
countdown.tempLength = countdown.length;
countdown.length = len;
start();
}
function countUp() {
current++;
console.log('Countdown', current);
}
}