#ifndef SCSTWRACE_H #define SCSTWRACE_H #include #include #include #include #include "scstwtimer.h" #include "scstwsoundplayer.h" class ScStwRace : public QObject { Q_OBJECT Q_PROPERTY(RaceState state READ getState NOTIFY stateChanged) Q_PROPERTY(QVariantList timers READ getTimerDetailList NOTIFY timersChanged) Q_PROPERTY(QVariantList nextStartActionDetails READ getNextStartActionDetails NOTIFY nextStartActionDetailsChanged) public: explicit ScStwRace(QObject *parent = nullptr); enum RaceState { IDLE, STARTING, WAITING, RUNNING, STOPPED }; Q_ENUM(RaceState) enum StartAction { None = -1, AtYourMarks = 0, Ready = 1, Start = 2 }; Q_ENUM(StartAction) enum NextStartActionDetailAttributes { NextStartAction = 0, NextStartActionTotalDelay = 1, NextStartActionDelayProgress = 2 }; Q_ENUM(NextStartActionDetailAttributes); protected: StartAction nextStartAction; QList timers; void setState(RaceState newState); private: RaceState state; QList timerEnableQueque; QTimer *nextActionTimer; QEventLoop *nextActionLoop; // sounds ScStwSoundPlayer * soundPlayer; // some settings double soundVolume; /*! * \brief stores the start action settings * * \details Stores the settings for the action ScStwRace::AtYourMarks and ScStwRace::Ready. The settings keys are: "Enabled" and "Delay" */ QMap startActionSettings; public slots: int start(); int stop(); int reset(); void cancelStart(bool falseStart); // setters bool writeStartActionSetting(StartAction action, bool enabled, int delay); bool setSoundVolume(double volume); bool addTimer(ScStwTimer *timer); // getters RaceState getState(); StartAction getNextStartAction(); QVariantList getNextStartActionDetails(); QVariantList getTimerDetailList(); protected slots: private slots: void refreshTimerStates(); void handleTimerEnable(ScStwTimer* timer); bool playSoundsAndStartTimers(StartAction thisAction); void handleTimerStop(); signals: void startTimers(); void stopTimers(int type); void resetTimers(); void stateChanged(RaceState state); void nextStartActionChanged(); void nextStartActionDetailsChanged(); void timersChanged(); }; #endif // SCSTWRACE_H