aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCrystalwarrior <varsash@gmail.com>2020-08-21 17:17:49 +0300
committerCrystalwarrior <varsash@gmail.com>2020-08-21 17:17:49 +0300
commitedf3d463e990ff8573bb6655c793490e6b1ea82c (patch)
tree7d85a18f2ca7b6fb8f434017b700ef18090c834f
parentaf1e76022568af1f146e2b49e96af85eb06521b9 (diff)
add a new aoclocklabel class that is a QLabel with fancy DR-Style timing features
WIP
-rw-r--r--include/aoclocklabel.h29
-rw-r--r--src/aoclocklabel.cpp35
2 files changed, 64 insertions, 0 deletions
diff --git a/include/aoclocklabel.h b/include/aoclocklabel.h
new file mode 100644
index 00000000..518cae7b
--- /dev/null
+++ b/include/aoclocklabel.h
@@ -0,0 +1,29 @@
+#ifndef AOCLOCKLABEL_H
+#define AOCLOCKLABEL_H
+
+#include <QLabel>
+#include <QBasicTimer>
+#include <QTimerEvent>
+#include <QTime>
+
+class AOClockLabel : public QLabel {
+ Q_OBJECT
+
+public:
+ AOClockLabel(QWidget *parent);
+ void start();
+ void start(QTime p_time);
+ void pause();
+ void resume();
+ void stop();
+
+protected:
+ void timerEvent(QTimerEvent *event) override;
+
+private:
+ QBasicTimer timer;
+ QTime starting_time;
+ QTime target_time;
+};
+
+#endif // AOCLOCKLABEL_H
diff --git a/src/aoclocklabel.cpp b/src/aoclocklabel.cpp
new file mode 100644
index 00000000..fad21f4e
--- /dev/null
+++ b/src/aoclocklabel.cpp
@@ -0,0 +1,35 @@
+#include "aoclocklabel.h"
+
+AOClockLabel::AOClockLabel(QWidget *parent) : QLabel(parent) {}
+
+void AOClockLabel::start()
+{
+ this->resume();
+}
+
+void AOClockLabel::start(QTime p_time)
+{
+ QTime time = QTime::currentTime();
+ if (p_time > time)
+ {
+ target_time = p_time;
+ starting_time = time;
+ timer.start(100, this);
+ }
+}
+
+void AOClockLabel::pause() {}
+
+void AOClockLabel::resume() {}
+
+void AOClockLabel::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"));
+ } else {
+ QWidget::timerEvent(event);
+ }
+}