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.
This commit is contained in:
parent
7e9c5726e0
commit
ee3bad44c7
@ -14,8 +14,8 @@ public:
|
||||
AOClockLabel(QWidget *parent);
|
||||
void start();
|
||||
void start(int msecs);
|
||||
void set(int msecs, bool update_text=false);
|
||||
void pause();
|
||||
void resume();
|
||||
void stop();
|
||||
|
||||
protected:
|
||||
|
@ -251,8 +251,11 @@ public:
|
||||
|
||||
void check_connection_received();
|
||||
|
||||
void start_clock();
|
||||
void start_clock(qint64 msecs);
|
||||
|
||||
void set_clock(qint64 msecs);
|
||||
|
||||
void stop_clock();
|
||||
|
||||
qint64 get_ping() { return ping_timer.elapsed(); }
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -4715,11 +4715,26 @@ void Courtroom::announce_case(QString title, bool def, bool pro, bool jud,
|
||||
}
|
||||
}
|
||||
|
||||
void Courtroom::start_clock()
|
||||
{
|
||||
ui_clock->start();
|
||||
}
|
||||
|
||||
void Courtroom::start_clock(qint64 msecs)
|
||||
{
|
||||
ui_clock->start(static_cast<int>(msecs));
|
||||
}
|
||||
|
||||
void Courtroom::set_clock(qint64 msecs)
|
||||
{
|
||||
ui_clock->set(static_cast<int>(msecs), true);
|
||||
}
|
||||
|
||||
void Courtroom::pause_clock()
|
||||
{
|
||||
ui_clock->pause();
|
||||
}
|
||||
|
||||
void Courtroom::stop_clock()
|
||||
{
|
||||
ui_clock->stop();
|
||||
|
@ -729,12 +729,25 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
|
||||
f_contents.at(5) == "1");
|
||||
}
|
||||
else if (header == "TI") { // Timer packet
|
||||
if (courtroom_constructed && f_contents.size() >= 1) {
|
||||
if (courtroom_constructed && f_contents.size() > 0) {
|
||||
qint64 resolution = f_contents.at(0).toInt();
|
||||
//Type 0 = start/stop timer
|
||||
//Type 1 = pause timer
|
||||
int type = 0;
|
||||
if (f_contents.size() > 1)
|
||||
type = f_contents.at(1).toInt();
|
||||
qDebug() << "timer" << resolution << last_ping << resolution - last_ping;
|
||||
resolution = resolution - last_ping;
|
||||
if (resolution > 0)
|
||||
w_courtroom->start_clock(resolution);
|
||||
{
|
||||
if (type == 1)
|
||||
{
|
||||
w_courtroom->pause_clock();
|
||||
w_courtroom->set_clock(resolution);
|
||||
}
|
||||
else
|
||||
w_courtroom->start_clock(resolution);
|
||||
}
|
||||
else
|
||||
w_courtroom->stop_clock();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user