-
Notifications
You must be signed in to change notification settings - Fork 0
/
framelever.hxx
131 lines (118 loc) · 4.6 KB
/
framelever.hxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#ifndef FRAMELEVER_HXX
#define FRAMELEVER_HXX
#include <QMainWindow>
#include <QSvgWidget>
#include <QMap>
#include <QObject>
#include <QDebug>
#include <QPushButton>
#include <QScreen>
#include <QGuiApplication>
#include <QSoundEffect>
#include <QSound>
#include <QTimer>
#include "global_params.hxx"
#include "scaling.hxx"
namespace EWRB
{
class FrameLever;
class PointsChange : public QObject
{
Q_OBJECT
private:
FrameLever* _parent;
QSoundEffect* _sound_effect = new QSoundEffect;
QTimer* _timer = new QTimer();
bool _sound_finished = false;
public:
PointsChange(FrameLever* _parent);
bool getState();
void run()
{
_sound_finished = false;
_sound_effect->play();
_timer->start(2000);
_sound_finished = true;
}
public slots:
void timerEnded()
{
if(_sound_finished)
{
emit soundFinished();
}
_sound_finished = false;
}
signals:
void soundFinished();
};
class FrameLever : public QObject
{
Q_OBJECT
private:
QWidget* _parent = nullptr;
QMap<LeverState, QSvgWidget*> _svgs = {{}};
PointsChange* _points_change = new PointsChange(this);
EWRB::LeverType _type;
int _coords[2] = {0,0};
const int _id = -1;
bool _locked = false;
LeverState _current_state = LeverState::Off, _prev_state= EWRB::LeverState::Off;
public:
FrameLever(){}
FrameLever(const int& id, const QString& lever_name, QWidget* parent, EWRB::LeverType type) :
_id(id), _parent(parent), _type(type)
{
const Scaler* scaler_ = new Scaler;
connect(_points_change, SIGNAL(soundFinished()), this, SLOT(pointsChangedFinished()));
_svgs[LeverState::Off] = new QSvgWidget(QString(":/svgs/svgs/")+lever_name+QString("_LeverBack.svg"), _parent);
_svgs[LeverState::Off]->setFixedSize(scaler_->scale_width(25), scaler_->scale_height(100));
_svgs[LeverState::Off]->hide();
_svgs[LeverState::Mid] = new QSvgWidget(QString(":/svgs/svgs/")+lever_name+QString("_LeverMid.svg"), _parent);
_svgs[LeverState::Mid]->setFixedSize(scaler_->scale_width(25), scaler_->scale_height(100));
_svgs[LeverState::Mid]->hide();
_svgs[LeverState::On] = new QSvgWidget(QString(":/svgs/svgs/")+lever_name+QString("_LeverForward.svg"), _parent);
_svgs[LeverState::On]->setFixedSize(scaler_->scale_width(25), scaler_->scale_height(100));
_svgs[LeverState::On]->hide();
}
EWRB::LeverState reverse(EWRB::LeverState state) const
{
return (state == EWRB::LeverState::On) ? EWRB::LeverState::Off : EWRB::LeverState::On;
}
QSvgWidget* getWidget() const {return _svgs[_current_state];}
void PlaceAt(const int& x, const int& y);
void hideSVG();
void showSVG();
void moveLever(EWRB::LeverState state = EWRB::LeverState::Off, bool points_delay=false);
void Lock(bool lock_lever) {_locked = lock_lever;}
bool isLocked() const {return _locked;}
EWRB::LeverType getType() const {return _type;}
EWRB::LeverState getState() const {return _current_state;}
int id() const {return _id;}
signals:
void sendCurrentLeverDestination(EWRB::LeverState state);
public slots:
void pointsChangedFinished();
};
class HomeLever : public FrameLever
{
public:
HomeLever(const int& id, QWidget* parent) : FrameLever(id, QString("Red"), parent, EWRB::LeverType::Signal) {}
};
class PointsLever : public FrameLever
{
public:
PointsLever(const int& id, QWidget* parent) : FrameLever(id, QString("Black"), parent, EWRB::LeverType::Points){}
};
class EmergencySignalReleaseLever : public FrameLever
{
public:
EmergencySignalReleaseLever(const int& id, QWidget* parent) : FrameLever(id, QString("Yellow"), parent, EWRB::LeverType::Points){}
};
class SpareLever : public FrameLever
{
public:
SpareLever(const int& id, QWidget* parent) : FrameLever(id, QString("White"), parent, EWRB::LeverType::Points){}
};
};
#endif // FRAMELEVER_HXX