-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtimer.cpp
84 lines (74 loc) · 1.28 KB
/
timer.cpp
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
#include "timer.h"
#include <QDebug>
Timer::Timer(qreal time, QObject *parent) :
inteval(time*100),QObject(parent)
{
timer = new QTimer();
timer->setInterval(10);
active = false;
singleShot = false;
paused = false;
havingDeleted = false;
connect(timer,SIGNAL(timeout()),this,SLOT(countDown()));
}
Timer::~Timer()
{
if (!havingDeleted)
timer->deleteLater();
}
void Timer::start()
{
active = true;
waiting = inteval;
timer->start();
}
void Timer::start(qreal time)
{
// qDebug()<<"in timer";
// qDebug()<<time;
active = true;
inteval = time*100;
waiting = inteval-1;
timer->start();
}
void Timer::stop()
{
active = false;
timer->stop();
}
void Timer::pause()
{
paused = true;
if (active)
timer->stop();
}
void Timer::restore()
{
paused = false;
if (active)
timer->start();
}
void Timer::countDown()
{
if (waiting == 0){
emit timeout();
if (singleShot){
havingDeleted = true;
delete(timer);
// deleteLater();
}
else
waiting = inteval-1;
}
else {
waiting--;
}
}
bool Timer::isSingleShot()
{
return singleShot;
}
void Timer::setSingleShot(bool value)
{
singleShot = value;
}