aboutsummaryrefslogtreecommitdiff
path: root/src/aoclocklabel.cpp
diff options
context:
space:
mode:
authoroldmud0 <oldmud0@users.noreply.github.com>2021-01-19 10:02:31 -0600
committerGitHub <noreply@github.com>2021-01-19 10:02:31 -0600
commite097df09adc365db948858d2ab3bfff0f07e1143 (patch)
tree39ea2ed35b536bdd5a06141398eb3bc379fccd09 /src/aoclocklabel.cpp
parent0926f3c15842a71002c0ec374fd54832469036d8 (diff)
parent1b016ddf91cb8b065215d046e7e0b4064b5d8633 (diff)
Merge pull request #384 from AttorneyOnline/feature/timerclock
Countdown timer
Diffstat (limited to 'src/aoclocklabel.cpp')
-rw-r--r--src/aoclocklabel.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/aoclocklabel.cpp b/src/aoclocklabel.cpp
new file mode 100644
index 00000000..4c9c4819
--- /dev/null
+++ b/src/aoclocklabel.cpp
@@ -0,0 +1,59 @@
+#include "aoclocklabel.h"
+
+AOClockLabel::AOClockLabel(QWidget *parent) : QLabel(parent) {}
+
+void AOClockLabel::start()
+{
+ timer.start(1000 / 60, this);
+}
+
+void AOClockLabel::start(int msecs)
+{
+ this->set(msecs);
+ this->start();
+}
+
+void AOClockLabel::set(int msecs, bool update_text)
+{
+ target_time = QTime::currentTime().addMSecs(msecs);
+ if (update_text)
+ {
+ if (QTime::currentTime() >= target_time)
+ {
+ this->setText("00:00:00.000");
+ }
+ else
+ {
+ QTime timeleft = QTime(0,0).addMSecs(QTime::currentTime().msecsTo(target_time));
+ QString timestring = timeleft.toString("hh:mm:ss.zzz");
+ this->setText(timestring);
+ }
+ }
+}
+
+void AOClockLabel::pause()
+{
+ timer.stop();
+}
+
+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);
+ }
+}