diff --git a/headers/speedtimer.h b/headers/speedtimer.h index a4061da..1beca26 100644 --- a/headers/speedtimer.h +++ b/headers/speedtimer.h @@ -13,7 +13,7 @@ class SpeedTimer : public QObject public: explicit SpeedTimer(QObject *parent = nullptr); - enum timerState { IDLE, STARTING, WAITING, RUNNING, STOPPED, FAILED, CANCELLED }; + enum timerState { IDLE, STARTING, WAITING, RUNNING, WON, LOST, FAILED, CANCELLED, DISABLED }; timerState state; // variables for capturing the time diff --git a/qml/main.qml b/qml/main.qml index efc96e9..170ae86 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -187,7 +187,11 @@ Window { height: parent.height elide: "ElideRight" - color: appTheme.style.textColor + color: speedBackend.timers[index]["state"] === "WON" ? "green" : + speedBackend.timers[index]["state"] === "LOST" ? "red": + appTheme.style.textColor + + enabled: speedBackend.timers[index]["state"] !== "DISABLED" text: speedBackend.timers[index]["text"] diff --git a/sources/climbingrace.cpp b/sources/climbingrace.cpp index 07f61fc..d5360a8 100644 --- a/sources/climbingrace.cpp +++ b/sources/climbingrace.cpp @@ -394,7 +394,7 @@ void ClimbingRace::refreshTimerText() { QVariantList newTimerTextList; foreach(SpeedTimer * timer, this->speedTimers){ - QVariantMap timerMap = {{"text",timer->getText()}, {"reacttime", timer->reactionTime}}; + QVariantMap timerMap = {{"text",timer->getText()}, {"reacttime", timer->reactionTime}, {"state", timer->getState()}}; newTimerTextList.append(timerMap); } diff --git a/sources/speedtimer.cpp b/sources/speedtimer.cpp index ead2087..ce6a5b1 100644 --- a/sources/speedtimer.cpp +++ b/sources/speedtimer.cpp @@ -47,7 +47,7 @@ bool SpeedTimer::stop(int type, bool force) { { this->stopTime = this->date->currentMSecsSinceEpoch(); this->stoppedTime = this->stopTime - this->startTime; - this->setState(STOPPED); + this->setState(WON); break; } case 1: @@ -71,7 +71,7 @@ bool SpeedTimer::stop(int type, bool force) { } bool SpeedTimer::reset(bool force){ - if( ( this->state != STOPPED && this->state != FAILED && this->state != CANCELLED ) && !force){ + if( ( this->state < WON ) && !force){ return false; } @@ -103,12 +103,16 @@ QString SpeedTimer::getState(){ return ("WAITING"); case RUNNING: return("RUNNING"); - case STOPPED: - return("STOPPED"); + case WON: + return "WON"; + case LOST: + return "LOST"; case FAILED: return("FAILED"); case CANCELLED: return("CANCELLED"); + case DISABLED: + return "DISABLED"; } return "ERROR"; } @@ -141,7 +145,10 @@ QString SpeedTimer::getText() { case SpeedTimer::RUNNING: newText = QString::number( this->getCurrTime() / 1000.0, 'f', 3 ) + " sec"; break; - case SpeedTimer::STOPPED: + case SpeedTimer::WON: + newText = QString::number( this->stoppedTime / 1000.0, 'f', 3 ) + " sec"; + break; + case SpeedTimer::LOST: newText = QString::number( this->stoppedTime / 1000.0, 'f', 3 ) + " sec"; break; case SpeedTimer::FAILED: @@ -150,6 +157,9 @@ QString SpeedTimer::getText() { case SpeedTimer::CANCELLED: newText = tr("Cancelled"); break; + case SpeedTimer::DISABLED: + newText = "---"; + break; } return newText; @@ -182,12 +192,18 @@ SpeedTimer::timerState SpeedTimer::stateFromString(QString state){ else if (state == "RUNNING") { return RUNNING; } - else if (state == "STOPPED") { - return STOPPED; + else if (state == "WON") { + return WON; + } + else if (state == "LOST") { + return LOST; } else if (state == "FAILED") { return FAILED; } + else if(state == "DISABLED") { + return DISABLED; + } else { return CANCELLED; }