-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclock.cpp
More file actions
39 lines (33 loc) · 680 Bytes
/
clock.cpp
File metadata and controls
39 lines (33 loc) · 680 Bytes
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
#include "clock.h"
#define CLOCK_TICK_MILIS 1000
Clock::Clock(QObject *parent) :
QObject(parent),
seconds(0)
{
}
void Clock::timerEvent(QTimerEvent *)
{
seconds++;
emit ticked();
}
void Clock::start()
{
timerId = startTimer(CLOCK_TICK_MILIS);
}
void Clock::stop()
{
killTimer(timerId);
}
void Clock::reset()
{
seconds = 0;
}
QString Clock::getFormatted()
{
int hours = seconds/3600;
int minutes = (seconds/60) % 60;
int secs = seconds % 60;
return QString::number(hours).rightJustified(2, '0') + ":" +
QString::number(minutes).rightJustified(2, '0') + ":" +
QString::number(secs).rightJustified(2, '0');
}