Fix doc path
[opentx.git] / companion / src / simulation / widgets / radiowidget.h
blobaf218495b492b3c2c2bf9403336825791a248d46
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 _RADIOWIDGET_H_
22 #define _RADIOWIDGET_H_
24 #include <QGridLayout>
25 #include <QDebug>
26 #include <QLabel>
27 #include <QWidget>
29 #define RADIO_WIDGET_STATE_VERSION 1
31 class RadioUiAction;
33 class RadioWidget : public QWidget
35 Q_OBJECT
37 public:
39 // These are saved to persistent user settings in RadioWidgetState,
40 // so only append entires here, do not change index value if it can be avoided.
41 enum RadioWidgetType {
42 RADIO_WIDGET_NONE = 0,
43 RADIO_WIDGET_SWITCH,
44 RADIO_WIDGET_KNOB,
45 RADIO_WIDGET_FADER,
46 RADIO_WIDGET_TRIM, // trim axis, usually 2 buttons & slider
47 RADIO_WIDGET_STICK, // actually one axis of a stick
48 RADIO_WIDGET_KEY, // UI key/pushbutton
49 RADIO_WIDGET_ENUM_COUNT
52 enum RadioTrimWidgetButtonStates { RADIO_TRIM_BTN_ON = 1024, RADIO_TRIM_BTN_OFF = -1024 };
54 struct RadioWidgetState {
55 public:
56 RadioWidgetState(quint8 type = 0, qint8 index = 0, qint16 value = 0, quint16 flags = 0) :
57 type(type), index(index), value(value), flags(flags),
58 _version(RADIO_WIDGET_STATE_VERSION)
59 { }
61 quint8 type;
62 qint8 index;
63 qint16 value;
64 quint16 flags;
66 friend QDataStream & operator << (QDataStream &out, const RadioWidgetState & o);
67 friend QDataStream & operator >> (QDataStream &in, RadioWidgetState & o);
68 friend QDebug operator << (QDebug d, const RadioWidgetState & o);
70 private:
71 quint8 _version = RADIO_WIDGET_STATE_VERSION; // structure definition version
74 explicit RadioWidget(QWidget * parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags());
75 explicit RadioWidget(RadioUiAction * action = NULL, QWidget * parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags());
76 explicit RadioWidget(const QString & labelText, int value = 0, QWidget * parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags());
78 virtual int getValue() const;
79 virtual int getIndex() const;
80 virtual int getType() const;
81 virtual QByteArray getStateData() const;
82 virtual RadioWidgetState getState() const;
83 virtual RadioUiAction * getAction() const;
85 public slots:
87 virtual void setIndex(const int & index);
88 virtual void setType(const RadioWidgetType & type);
89 virtual void setValue(const int & value);
90 virtual void setValueQual(const RadioWidgetType & type, const int & index, const int & value);
91 virtual void setFlags(const quint16 & flags);
92 virtual void setShowLabel(const bool show);
93 virtual void setLabelText(const QString & labelText, bool showLabel = true);
94 virtual void setStateData(const RadioWidgetState & state);
95 virtual void changeVisibility(bool visible);
96 virtual void setAction(RadioUiAction * action);
98 signals:
100 void valueChange(const RadioWidgetType type, const int index, int value);
101 void valueChanged(const int value);
102 void flagsChanged(const quint16 flags);
104 protected:
106 void addLayout();
107 void addLabel();
108 void setWidget(QWidget * widget = NULL, Qt::Alignment align = Qt::AlignHCenter);
109 virtual void onActionToggled(int index, bool active);
111 QGridLayout * m_gridLayout;
112 QWidget * m_controlWidget;
113 QLabel * m_nameLabel;
114 RadioUiAction * m_action;
116 int m_value;
117 int m_index;
118 quint16 m_flags;
119 bool m_valueReset;
120 bool m_showLabel;
121 QString m_labelText;
122 RadioWidgetType m_type;
126 Q_DECLARE_METATYPE(RadioWidget::RadioWidgetState)
128 #endif // _RADIOWIDGET_H_