-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdigitalclock.cpp
68 lines (45 loc) · 938 Bytes
/
digitalclock.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
//#include <QtWidgets>
#include "digitalclock.h"
#include <QTimer>
#include <QTime>
DigitalClock::DigitalClock(QWidget *parent)
: QLCDNumber(parent), stop_time_(0)
{
setSegmentStyle(Filled);
timer_.setSingleShot(false);
connect(&timer_, SIGNAL(timeout()), this, SLOT(showTime()));
start();
}
DigitalClock::~DigitalClock()
{
timer_.stop();
}
void DigitalClock::start(int time)
{
stop_time_ = time;
time_.start();
showTime();
timer_.start(1000);
}
void DigitalClock::stop()
{
timer_.stop();
if (stop_time_ == 0)
stop_time_ = time_.elapsed();
}
int DigitalClock::getTime()
{
return time_.elapsed();
}
void DigitalClock::showTime()
{
QTime t(0, 0);
int diff = abs(stop_time_ - time_.elapsed());
if ( diff <= 0 && stop_time_ != 0)
{
stop();
}
t = t.addMSecs( diff );
QString text = t.toString("mm:ss");
display(text);
}