diff options
| author | Crystalwarrior <varsash@gmail.com> | 2020-08-25 12:48:09 +0300 |
|---|---|---|
| committer | Crystalwarrior <varsash@gmail.com> | 2020-08-25 12:48:09 +0300 |
| commit | ee3bad44c72329d61a2cb0c4064c22512451372d (patch) | |
| tree | 421e95752a4580b30dc097f4c5b72d7e2c7493fe /src/aoclocklabel.cpp | |
| parent | 7e9c5726e02a65023d9563f49e833525bf8f4bae (diff) | |
Implement clock pausing
Implement clock setting w/o starting or stopping
Both of these should make it possible for the server to start/stop/pause/resume the clock with perfect synchronization to the true time.
Diffstat (limited to 'src/aoclocklabel.cpp')
| -rw-r--r-- | src/aoclocklabel.cpp | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/src/aoclocklabel.cpp b/src/aoclocklabel.cpp index 783fcc51..7bbf48c7 100644 --- a/src/aoclocklabel.cpp +++ b/src/aoclocklabel.cpp @@ -4,27 +4,35 @@ AOClockLabel::AOClockLabel(QWidget *parent) : QLabel(parent) {} void AOClockLabel::start() { - this->resume(); + timer.start(100, this); } void AOClockLabel::start(int msecs) { + this->set(msecs); + this->start(); +} + +void AOClockLabel::set(int msecs, bool update_text) +{ QTime time = QTime::currentTime(); if (msecs > time.msec()) { target_time = time.addMSecs(msecs); - timer.start(100, this); } -} - -void AOClockLabel::pause() -{ - timer.stop(); -} - -void AOClockLabel::resume() -{ - timer.start(100, this); + 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::stop() @@ -35,16 +43,16 @@ void AOClockLabel::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); + 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); + } } |
