diff --git a/ScStwLibraries/headers/scstwtimer.h b/ScStwLibraries/headers/scstwtimer.h index f8f6d00..e1aac72 100644 --- a/ScStwLibraries/headers/scstwtimer.h +++ b/ScStwLibraries/headers/scstwtimer.h @@ -284,6 +284,16 @@ public slots: */ bool setReactionTime(double rectionTime); + /*! + * \brief Function to dircetly change the letter + * + * Only works when directControlEnabled is set to true! + * + * \param newLetter the letter to change to + * \return false when directControlEnabled is set to false and the letter was therefore not modified, true otherwise + */ + bool setLetter(QString newLetter); + protected slots: /*! diff --git a/ScStwLibraries/sources/scstwremotemonitorrace.cpp b/ScStwLibraries/sources/scstwremotemonitorrace.cpp index d80d8ba..56d6f4e 100644 --- a/ScStwLibraries/sources/scstwremotemonitorrace.cpp +++ b/ScStwLibraries/sources/scstwremotemonitorrace.cpp @@ -207,6 +207,8 @@ bool ScStwRemoteMonitorRace::refreshRemoteTimers(QVariantList remoteTimers) { this->timers[currId]->setReactionTime(remoteTimer.toMap()["reactionTime"].toDouble()); this->timers[currId]->setState(newState, true); + + this->timers[currId]->setLetter(remoteTimer.toMap()["letter"].toString()); } return true; diff --git a/ScStwLibraries/sources/scstwtimer.cpp b/ScStwLibraries/sources/scstwtimer.cpp index d9b0efc..0adf62d 100644 --- a/ScStwLibraries/sources/scstwtimer.cpp +++ b/ScStwLibraries/sources/scstwtimer.cpp @@ -21,7 +21,12 @@ ScStwTimer::ScStwTimer(QObject *parent, bool directControlEnabled, QString letter) : QObject(parent) { this->directControlEnabled = directControlEnabled; - this->letter = letter; + + if(letter.length() > 1) + this->letter = letter[0]; + else + this->letter = letter; + this->startTime = 0; this->stopTime = 0; this->reactionTime = 0; @@ -199,6 +204,14 @@ void ScStwTimer::setState(TimerState newState){ } } +bool ScStwTimer::setLetter(QString newLetter) { + if(!this->directControlEnabled) + return false; + + this->letter = newLetter; + return true; +} + ScStwTimer::TimerState ScStwTimer::getState() { return this->state; } @@ -225,26 +238,27 @@ QString ScStwTimer::getLetter() { } QString ScStwTimer::getText() { - //qDebug() << this->getState(); - QString newText; + + QString newText = ""; + int newTime = 0; switch (this->state) { case ScStwTimer::IDLE: - newText = "0.000 sec"; + newTime = 0; break; case ScStwTimer::STARTING: - newText = "0.000 sec"; + newTime = 0; break; case ScStwTimer::WAITING: newText = "please wait..."; break; case ScStwTimer::RUNNING: - newText = QString::number( this->getCurrentTime() / 1000.0, 'f', 3 ) + " sec"; + newTime = this->getCurrentTime(); break; case ScStwTimer::WON: - newText = QString::number( this->getCurrentTime() / 1000.0, 'f', 3 ) + " sec"; + newTime = this->getCurrentTime(); break; case ScStwTimer::LOST: - newText = QString::number( this->getCurrentTime() / 1000.0, 'f', 3 ) + " sec"; + newTime = this->getCurrentTime(); break; case ScStwTimer::FAILED: newText = "false start"; @@ -257,6 +271,9 @@ QString ScStwTimer::getText() { break; } + if(newText == "") + newText = QString::number( newTime / 1000.0, 'f', 3 ).rightJustified(6, '0'); + return newText; }