2020-04-11 23:41:34 +02:00
|
|
|
#ifndef SCSTWRACE_H
|
|
|
|
#define SCSTWRACE_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QEventLoop>
|
|
|
|
#include "scstwtimer.h"
|
|
|
|
#include "scstwsoundplayer.h"
|
|
|
|
|
|
|
|
class ScStwRace : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2020-04-15 21:47:04 +02:00
|
|
|
Q_PROPERTY(RaceState state READ getState NOTIFY stateChanged)
|
2020-04-11 23:41:34 +02:00
|
|
|
public:
|
|
|
|
explicit ScStwRace(QObject *parent = nullptr);
|
|
|
|
|
|
|
|
enum RaceState { IDLE, STARTING, WAITING, RUNNING, STOPPED };
|
|
|
|
Q_ENUM(RaceState)
|
|
|
|
|
|
|
|
enum StartAction { None = -1, AtYourMarks, Ready, Start };
|
|
|
|
Q_ENUM(StartAction)
|
|
|
|
|
|
|
|
private:
|
|
|
|
RaceState state;
|
|
|
|
|
|
|
|
QList<ScStwTimer *> timers;
|
|
|
|
QList<ScStwTimer*> timerEnableQueque;
|
|
|
|
|
|
|
|
QTimer *nextActionTimer;
|
|
|
|
QEventLoop *nextActionLoop;
|
|
|
|
|
|
|
|
// sounds
|
|
|
|
ScStwSoundPlayer * soundPlayer;
|
|
|
|
|
|
|
|
StartAction nextStartAction;
|
|
|
|
|
|
|
|
// some settings
|
|
|
|
double soundVolume;
|
|
|
|
|
2020-04-15 19:21:32 +02:00
|
|
|
/*!
|
|
|
|
* \brief stores the start action settings
|
2020-04-11 23:41:34 +02:00
|
|
|
*
|
2020-04-15 19:21:32 +02:00
|
|
|
* \details Stores the settings for the action ScStwRace::AtYourMarks and ScStwRace::Ready. The settings keys are: "Enabled" and "Delay"
|
2020-04-11 23:41:34 +02:00
|
|
|
*/
|
|
|
|
QMap<StartAction, QVariantMap> startActionSettings;
|
|
|
|
|
|
|
|
void setState(RaceState newState);
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
int start();
|
|
|
|
int stop();
|
|
|
|
void handleTimerStop();
|
|
|
|
int reset();
|
|
|
|
void cancelStart(bool falseStart);
|
|
|
|
QVariantMap getNextStartActionDetails();
|
|
|
|
bool writeStartActionSetting(StartAction action, bool enabled, int delay);
|
|
|
|
bool setSoundVolume(double volume);
|
|
|
|
bool addTimer(ScStwTimer *timer);
|
|
|
|
RaceState getState();
|
|
|
|
StartAction getNextStartAction();
|
|
|
|
QVariantList getTimerDetailList();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void refreshTimerStates();
|
|
|
|
void handleTimerEnable(ScStwTimer* timer);
|
|
|
|
bool playSoundsAndStartTimers(StartAction thisAction);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void startTimers();
|
|
|
|
void stopTimers(int type);
|
|
|
|
void resetTimers();
|
|
|
|
void stateChanged(RaceState state);
|
|
|
|
void nextStartActionChanged();
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SCSTWRACE_H
|