79 lines
1.8 KiB
C
79 lines
1.8 KiB
C
|
#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
|
||
|
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;
|
||
|
|
||
|
/**
|
||
|
* @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<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
|