Fix doc path
[opentx.git] / companion / src / simulation / widgets / radiokeywidget.h
blobee63c3b71ccea623f24509c00a6ac33ba6d29152
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 RADIOKEYWIDGET_H
22 #define RADIOKEYWIDGET_H
24 #include "radiouiaction.h"
25 #include "radiowidget.h"
27 class RadioKeyWidget : public RadioWidget
29 Q_OBJECT
31 public:
33 explicit RadioKeyWidget(const QPolygon & polygon, const QString &image, RadioUiAction * action = NULL, QWidget * parent = NULL, Qt::WindowFlags f = Qt::WindowFlags()):
34 RadioWidget(action, parent, f),
35 polygon(polygon),
36 imgFile(image)
38 m_type = RADIO_WIDGET_KEY;
39 setValue(0);
40 hide(); // we're a "virtual" button for now
41 setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
44 virtual void setAction(RadioUiAction * action)
46 if (m_action)
47 disconnect(m_action, 0, this, 0);
48 RadioWidget::setAction(action);
49 if (m_action)
50 connect(m_action, &RadioUiAction::toggled, this, &RadioKeyWidget::onActionToggled);
53 virtual int getValue() const
55 return (m_action && m_action->isActive()) ? 1 : 0;
58 void press() {
59 if (m_action)
60 m_action->trigger(true);
63 void release() {
64 if (m_action)
65 m_action->trigger(false);
68 void toggle(bool down)
70 if (down)
71 press();
72 else
73 release();
76 bool contains(const QPoint & point)
78 return polygon.containsPoint(point, Qt::OddEvenFill);
81 signals:
83 void imageChanged(const QString image);
85 protected:
87 virtual void onActionToggled(int index, bool active)
89 RadioWidget::onActionToggled(index, active);
90 emit imageChanged(active ? imgFile : "");
93 QPolygon polygon;
94 QString imgFile;
98 #endif // RADIOKEYWIDGET_H