diff options
| author | Crystalwarrior <varsash@gmail.com> | 2020-08-21 18:01:24 +0300 |
|---|---|---|
| committer | Crystalwarrior <varsash@gmail.com> | 2020-08-21 18:01:24 +0300 |
| commit | f27f210efeb13a5ac29727fef271f8249e3e8c5d (patch) | |
| tree | 50051262a3982f4a6a0cb95847b233b498cf2282 /src | |
| parent | edf3d463e990ff8573bb6655c793490e6b1ea82c (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')
| -rw-r--r-- | src/aoclocklabel.cpp | 33 | ||||
| -rw-r--r-- | src/courtroom.cpp | 7 |
2 files changed, 31 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); } diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 2484bcb0..e2b372c5 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -112,6 +112,9 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_music_name->setText(tr("None")); ui_music_name->setAttribute(Qt::WA_TransparentForMouseEvents); + ui_clock = new AOClockLabel(this); + ui_clock->setAttribute(Qt::WA_TransparentForMouseEvents); + ui_ic_chat_name = new QLineEdit(this); ui_ic_chat_name->setFrame(false); ui_ic_chat_name->setPlaceholderText(tr("Showname")); @@ -619,6 +622,9 @@ void Courtroom::set_widgets() ui_music_display->play("music_display"); ui_music_display->set_play_once(false); + set_size_and_pos(ui_clock, "clock"); + ui_clock->start(30000); + if (is_ao2_bg) { set_size_and_pos(ui_ic_chat_message, "ao2_ic_chat_message"); set_size_and_pos(ui_vp_chatbox, "ao2_chatbox"); @@ -943,6 +949,7 @@ void Courtroom::set_fonts(QString p_char) set_font(ui_music_list, "", "music_list", p_char); set_font(ui_area_list, "", "area_list", p_char); set_font(ui_music_name, "", "music_name", p_char); + set_font(ui_clock, "", "clock", p_char); set_dropdowns(); } |
