Skip to content

Commit

Permalink
Timer interval (#15)
Browse files Browse the repository at this point in the history
Adding a new packet called TIN ("Timer Interval") to set after how much
time timer should update.
Example of the packet; ["TIN", TimerID, TimerInterval]
  • Loading branch information
EstatoDeviato authored Jul 29, 2024
1 parent d8ef822 commit 21e47ee
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/aoclocklabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class AOClockLabel : public QLabel {
void pause();
void stop();
void set_format(QString formatting, qint64 timer_value);
void set_interval(qint64 timer_interval);
void skip(qint64 msecs);
bool active();

Expand All @@ -28,6 +29,7 @@ class AOClockLabel : public QLabel {
QBasicTimer timer;
QDateTime target_time;
QString time_format = "hh:mm:ss";
qint64 p_time_interval = 1000 / 60;
};

#endif // AOCLOCKLABEL_H
1 change: 1 addition & 0 deletions include/courtroom.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ class Courtroom : public QMainWindow {
void set_clock_visibility(int id, bool visible);
void skip_clocks(qint64 msecs);
void format_clock(int id, QString timer_format, qint64 msecs);
void interval_clock(int id, qint64 timer_interval);

qint64 pong();
// Truncates text so it fits within theme-specified boundaries and sets the tooltip to the full string
Expand Down
11 changes: 10 additions & 1 deletion src/aoclocklabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ AOClockLabel::AOClockLabel(QWidget *parent) : QLabel(parent) {}

void AOClockLabel::start()
{
timer.start(1000 / 60, this);
timer.start(p_time_interval, this);
}

void AOClockLabel::start(qint64 msecs)
Expand Down Expand Up @@ -82,3 +82,12 @@ void AOClockLabel::set_format(QString formatting, qint64 timer_value)
this->set(timer_value, true);
}
}

void AOClockLabel::set_interval(qint64 timer_interval)
{
p_time_interval = timer_interval;
if (this->active()) {
this->stop();
this->start();
}
}
7 changes: 7 additions & 0 deletions src/courtroom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6779,6 +6779,13 @@ void Courtroom::format_clock(int id, QString time_format, qint64 msecs) {
}
}

void Courtroom::interval_clock(int id, qint64 timer_interval)
{
if (id >= 0 && id < max_clocks && ui_clock[id] != nullptr) {
ui_clock[id]->set_interval(timer_interval);
}
}

void Courtroom::truncate_label_text(QWidget *p_widget, QString p_identifier)
{
QString filename = "courtroom_design.ini";
Expand Down
7 changes: 7 additions & 0 deletions src/packet_distribution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,13 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
w_courtroom->format_clock(id, time_format, timer_value);
}
}
else if (header == "TIN") {
if (courtroom_constructed && f_contents.size() == 2) {
int id = f_contents.at(0).toInt();
qint64 timer_interval = f_contents.at(1).toLongLong();
w_courtroom->interval_clock(id, timer_interval);
}
}
else if (header == "CHECK") {
if (!courtroom_constructed)
goto end;
Expand Down

0 comments on commit 21e47ee

Please sign in to comment.