diff --git a/include/aoclocklabel.h b/include/aoclocklabel.h index 518cae7..806ed18 100644 --- a/include/aoclocklabel.h +++ b/include/aoclocklabel.h @@ -5,6 +5,7 @@ #include #include #include +#include class AOClockLabel : public QLabel { Q_OBJECT @@ -12,7 +13,7 @@ class AOClockLabel : public QLabel { public: AOClockLabel(QWidget *parent); void start(); - void start(QTime p_time); + void start(int msecs); void pause(); void resume(); void stop(); @@ -22,7 +23,6 @@ protected: private: QBasicTimer timer; - QTime starting_time; QTime target_time; }; diff --git a/include/courtroom.h b/include/courtroom.h index 5b5ff6c..1ff74f5 100644 --- a/include/courtroom.h +++ b/include/courtroom.h @@ -6,6 +6,7 @@ #include "aobutton.h" #include "aocharbutton.h" #include "aocharmovie.h" +#include "aoclocklabel.h" #include "aoemotebutton.h" #include "aoevidencebutton.h" #include "aoevidencedisplay.h" @@ -517,6 +518,8 @@ private: ScrollText *ui_music_name; AOMovie *ui_music_display; + AOClockLabel *ui_clock; + AOButton *ui_pair_button; QListWidget *ui_pair_list; QSpinBox *ui_pair_offset_spinbox; diff --git a/src/aoclocklabel.cpp b/src/aoclocklabel.cpp index fad21f4..783fcc5 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 2484bcb..e2b372c 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(); }