blob: 783fcc51426e8ca5fdbdff5444c3f8601182a781 (
plain)
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
|
#include "aoclocklabel.h"
AOClockLabel::AOClockLabel(QWidget *parent) : QLabel(parent) {}
void AOClockLabel::start()
{
this->resume();
}
void AOClockLabel::start(int msecs)
{
QTime time = QTime::currentTime();
if (msecs > time.msec())
{
target_time = time.addMSecs(msecs);
timer.start(100, this);
}
}
void AOClockLabel::pause()
{
timer.stop();
}
void AOClockLabel::resume()
{
timer.start(100, this);
}
void AOClockLabel::stop()
{
this->setText("00:00:00.000");
timer.stop();
}
void AOClockLabel::timerEvent(QTimerEvent *event)
{
if (event->timerId() == timer.timerId()) {
if (QTime::currentTime() >= target_time)
{
this->stop();
return;
}
QTime timeleft = QTime(0,0).addMSecs(QTime::currentTime().msecsTo(target_time));
QString timestring = timeleft.toString("hh:mm:ss.zzz");
this->setText(timestring);
} else {
QWidget::timerEvent(event);
}
}
|