[Simulator] Fix and refactor Joystick configuration dialog and internal stick-to...
[opentx.git] / companion / src / simulation / simulatorwidget.h
blob727200252778ad93a7c4d49358e91f50728c7fb1
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #ifndef _SIMULATORWIDGET_H_
22 #define _SIMULATORWIDGET_H_
24 #include "constants.h"
25 #include "helpers.h"
26 #include "radiodata.h"
27 #include "simulator.h"
29 #include <QTimer>
30 #include <QWidget>
31 #include <QVector>
33 #define FLASH_DURATION 10
35 #define CBEEP_ON "QLabel { background-color: #FF364E }"
36 #define CBEEP_OFF "QLabel { }"
38 void traceCb(const char * text);
40 class Firmware;
41 class SimulatorInterface;
42 class SimulatedUIWidget;
43 class RadioWidget;
44 class RadioSwitchWidget;
45 class VirtualJoystickWidget;
46 #ifdef JOYSTICKS
47 class Joystick;
48 #endif
50 class QWidget;
51 class QSlider;
52 class QLabel;
53 class QFrame;
55 namespace Ui {
56 class SimulatorWidget;
59 using namespace Simulator;
61 class SimulatorWidget : public QWidget
63 Q_OBJECT
65 public:
66 explicit SimulatorWidget(QWidget * parent, SimulatorInterface *simulator, quint8 flags=0);
67 virtual ~SimulatorWidget();
69 void setSdPath(const QString & sdPath);
70 void setDataPath(const QString & dataPath);
71 void setPaths(const QString & sdPath, const QString & dataPath);
72 void setRadioSettings(const GeneralSettings settings);
73 bool setStartupData(const QByteArray & dataSource = NULL, bool fromFile = false);
74 bool setRadioData(RadioData * radioData);
75 bool setOptions(SimulatorOptions & options, bool withSave = true);
76 bool saveRadioData(RadioData * radioData, const QString & path = "", QString * error = NULL);
77 bool useTempDataPath(bool deleteOnClose = true);
78 bool saveTempData();
79 void deleteTempData();
80 void saveState();
81 void setUiAreaStyle(const QString & style);
82 void captureScreenshot(bool);
83 void setupJoysticks();
85 QString getSdPath() const { return sdCardPath; }
86 QString getDataPath() const { return radioDataPath; }
87 QVector<keymapHelp_t> * getKeymapHelp() { return &keymapHelp; }
89 public slots:
90 void start();
91 void stop();
92 void restart();
93 void shutdown();
95 private:
96 void setRadioProfileId(int value);
97 void setupRadioWidgets();
98 void setupTimer();
99 void restoreRadioWidgetsState();
100 QList<QByteArray> saveRadioWidgetsState();
102 void setValues();
103 void getValues();
104 void setTrims();
107 Ui::SimulatorWidget * ui;
108 SimulatorInterface * simulator;
109 Firmware * firmware;
110 GeneralSettings radioSettings;
112 QTimer * timer;
113 QString windowName;
114 QVector<keymapHelp_t> keymapHelp;
116 SimulatedUIWidget * radioUiWidget;
117 VirtualJoystickWidget * vJoyLeft;
118 VirtualJoystickWidget * vJoyRight;
120 QVector<RadioSwitchWidget *> switches;
121 QVector<RadioWidget *> analogs;
123 QString sdCardPath;
124 QString radioDataPath;
125 QByteArray startupData;
126 Board::Type m_board;
127 quint8 flags;
128 int radioProfileId;
129 int lastPhase;
130 int buttonPressed;
131 int trimPressed;
132 bool startupFromFile;
133 bool deleteTempRadioData;
134 bool saveTempRadioData;
135 bool middleButtonPressed;
136 bool firstShow;
138 #ifdef JOYSTICKS
139 Joystick *joystick;
140 #endif
142 private slots:
143 //virtual void showEvent(QShowEvent *);
144 //virtual void closeEvent(QCloseEvent *);
145 virtual void mousePressEvent(QMouseEvent *event);
146 virtual void mouseReleaseEvent(QMouseEvent *event);
147 virtual void wheelEvent(QWheelEvent *event);
149 void onTimerEvent();
150 void onTrimPressed(int which);
151 void onTrimReleased();
152 void onTrimSliderMoved(int which, int value);
153 void centerSticks();
154 void onjoystickAxisValueChanged(int axis, int value);
158 #endif // _SIMULATORWIDGET_H_