4 #include "boxingtimer.h" 5 #include "boxingsettings.h" 10 mOldStatus(Status::Default) {
11 this->setTimerType(Qt::VeryCoarseTimer);
15 mRemainingMilliseconds = settings->getRoundMilliseconds();
17 QObject::connect(
this, SIGNAL(statusChanged()),
this, SLOT(applyStatus()));
18 QObject::connect(
this, SIGNAL(timeout()),
this, SLOT(updateRemainingMilliseconds()));
21 const QString BoxingTimer::getPreset() {
22 return this->settings->getPreset();
25 void BoxingTimer::setRound(
const int &round) {
28 emit roundsToStringChanged();
31 void BoxingTimer::setRemainingMilliseconds(
const int &milliseconds) {
32 this->mRemainingMilliseconds = milliseconds;
34 emit remainingTimeToStringChanged();
37 void BoxingTimer::setStatus(
const Status &status) {
38 if (this->mStatus == Status::Start || this->mStatus == Status::Rest) {
39 this->mOldStatus = this->mStatus;
42 this->mStatus = status;
47 void BoxingTimer::stop() {
53 void BoxingTimer::start(
const int &milliseconds) {
54 QTimer::start(milliseconds);
59 void BoxingTimer::applyStatus() {
60 switch (this->mStatus) {
62 if (this->mOldStatus == Status::Start) {
63 this->setRemainingMilliseconds(this->settings->getRoundMilliseconds());
64 }
else if (this->mOldStatus == Status::Rest) {
65 this->setRemainingMilliseconds(this->settings->getRestMilliseconds());
68 if (this->isActive()) {
69 this->setStatus(this->mOldStatus);
77 if (this->mRound == 0) {
83 this->setRemainingMilliseconds(this->settings->getRoundMilliseconds());
94 void BoxingTimer::updateRemainingMilliseconds() {
95 this->setRemainingMilliseconds(this->mRemainingMilliseconds - 1000);
97 if (this->mRemainingMilliseconds < 0) {
98 if (this->mStatus == Status::Start) {
99 this->mStatus = Status::Rest;
100 this->setRemainingMilliseconds(this->settings->getRestMilliseconds());
101 }
else if(this->mStatus == Status::Rest) {
102 this->mStatus = Status::Start;
103 this->setRemainingMilliseconds(this->settings->getRoundMilliseconds());
110 void BoxingTimer::nextRound() {
111 int newRound = this->mRound + 1;
112 if (newRound > this->settings->getRounds()) {
113 this->setStatus(Status::Stop);
115 this->setRound(newRound);
120 return QString::number(this->mRound) +
"/" + QString::number(this->settings->getRounds());
123 const QString BoxingTimer::remainingTimeToString() {
124 return QTime::fromMSecsSinceStartOfDay(this->mRemainingMilliseconds).toString(QString(
"mm:ss"));
BoxingTimer()
Default constructor.
const QString roundsToString()
Convert round and total rounds for view.