aboutsummaryrefslogtreecommitdiff
path: root/src/aoclocklabel.cpp
diff options
context:
space:
mode:
authorCrystalwarrior <varsash@gmail.com>2020-08-21 18:01:24 +0300
committerCrystalwarrior <varsash@gmail.com>2020-08-21 18:01:24 +0300
commitf27f210efeb13a5ac29727fef271f8249e3e8c5d (patch)
tree50051262a3982f4a6a0cb95847b233b498cf2282 /src/aoclocklabel.cpp
parentedf3d463e990ff8573bb6655c793490e6b1ea82c (diff)
Proof of concept complete. The timer will now take int msecs to start, and will properly display the time remaining until target time in hh:mm:ss.zzz
Clock can be defined in courtroom_config.ini and its font set in courtroom_fonts.ini Pause and resume functions will not work as expected atm.
Diffstat (limited to 'src/aoclocklabel.cpp')
-rw-r--r--src/aoclocklabel.cpp33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/aoclocklabel.cpp b/src/aoclocklabel.cpp
index fad21f4e..783fcc51 100644
--- a/src/aoclocklabel.cpp
+++ b/src/aoclocklabel.cpp
@@ -7,28 +7,43 @@ void AOClockLabel::start()
this->resume();
}
-void AOClockLabel::start(QTime p_time)
+void AOClockLabel::start(int msecs)
{
QTime time = QTime::currentTime();
- if (p_time > time)
+ if (msecs > time.msec())
{
- target_time = p_time;
- starting_time = time;
+ target_time = time.addMSecs(msecs);
timer.start(100, this);
}
}
-void AOClockLabel::pause() {}
+void AOClockLabel::pause()
+{
+ timer.stop();
+}
-void AOClockLabel::resume() {}
+void AOClockLabel::resume()
+{
+ timer.start(100, this);
+}
-void AOClockLabel::stop() {}
+void AOClockLabel::stop()
+{
+ this->setText("00:00:00.000");
+ timer.stop();
+}
void AOClockLabel::timerEvent(QTimerEvent *event)
{
if (event->timerId() == timer.timerId()) {
- QTime elapsed = QTime(0,0).addSecs(starting_time.secsTo(starting_time));
- this->setText(elapsed.toString("hh:mm:ss.zzz"));
+ 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);
}