@@ -4,27 +4,35 @@ AOClockLabel::AOClockLabel(QWidget *parent) : QLabel(parent) {}
44
55void AOClockLabel::start ()
66{
7- this -> resume ( );
7+ timer. start ( 100 , this );
88}
99
1010void AOClockLabel::start (int msecs)
11+ {
12+ this ->set (msecs);
13+ this ->start ();
14+ }
15+
16+ void AOClockLabel::set (int msecs, bool update_text)
1117{
1218 QTime time = QTime::currentTime ();
1319 if (msecs > time.msec ())
1420 {
1521 target_time = time.addMSecs (msecs);
16- timer.start (100 , this );
1722 }
18- }
19-
20- void AOClockLabel::pause ()
21- {
22- timer.stop ();
23- }
24-
25- void AOClockLabel::resume ()
26- {
27- timer.start (100 , this );
23+ if (update_text)
24+ {
25+ if (QTime::currentTime () >= target_time)
26+ {
27+ this ->setText (" 00:00:00.000" );
28+ }
29+ else
30+ {
31+ QTime timeleft = QTime (0 ,0 ).addMSecs (QTime::currentTime ().msecsTo (target_time));
32+ QString timestring = timeleft.toString (" hh:mm:ss.zzz" );
33+ this ->setText (timestring);
34+ }
35+ }
2836}
2937
3038void AOClockLabel::stop ()
@@ -35,16 +43,16 @@ void AOClockLabel::stop()
3543
3644void AOClockLabel::timerEvent (QTimerEvent *event)
3745{
38- if (event->timerId () == timer.timerId ()) {
39- if (QTime::currentTime () >= target_time)
40- {
41- this ->stop ();
42- return ;
43- }
44- QTime timeleft = QTime (0 ,0 ).addMSecs (QTime::currentTime ().msecsTo (target_time));
45- QString timestring = timeleft.toString (" hh:mm:ss.zzz" );
46- this ->setText (timestring);
47- } else {
48- QWidget::timerEvent (event);
46+ if (event->timerId () == timer.timerId ()) {
47+ if (QTime::currentTime () >= target_time)
48+ {
49+ this ->stop ();
50+ return ;
4951 }
52+ QTime timeleft = QTime (0 ,0 ).addMSecs (QTime::currentTime ().msecsTo (target_time));
53+ QString timestring = timeleft.toString (" hh:mm:ss.zzz" );
54+ this ->setText (timestring);
55+ } else {
56+ QWidget::timerEvent (event);
57+ }
5058}
0 commit comments