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 VIRTUALJOYSTICKWIDGET_H
22 #define VIRTUALJOYSTICKWIDGET_H
24 #include "radiowidget.h"
27 #include <QResizeEvent>
29 #include <QGridLayout>
30 #include <QGraphicsView>
31 #include <QGraphicsScene>
32 #include <QToolButton>
36 class CustomGraphicsScene
;
38 class RadioTrimWidget
;
40 class VirtualJoystickWidget
: public QWidget
45 enum ConstraintTypes
{
52 explicit VirtualJoystickWidget(QWidget
* parent
= NULL
, QChar side
= 'L', bool showTrims
= true, bool showBtns
= true, bool showValues
= true, QSize size
= QSize(125, 125));
56 QPointF
getStickPos();
57 int getTrimValue(int which
);
58 virtual QSize
sizeHint() const;
59 virtual void resizeEvent(QResizeEvent
*event
);
61 int getStickScale() const;
62 void setStickScale(int stickScale
);
65 void setStickX(qreal x
);
66 void setStickY(qreal y
);
67 void setStickPos(QPointF xy
);
68 void setStickAxisValue(int index
, int value
);
70 void setTrimsRange(int min
, int max
);
71 void setTrimsRange(int rng
);
72 void setTrimRange(int index
, int min
, int max
);
73 void setTrimValue(int index
, int value
);
74 void setWidgetValue(const RadioWidget::RadioWidgetType type
, const int index
, const int value
);
76 void setStickIndices(int xIdx
= -1, int yIdx
= -1);
77 void setStickConstraint(quint8 index
, bool active
);
78 void setStickColor(const QColor
& color
);
79 void loadDefaultsForMode(const unsigned mode
);
82 void valueChange(const RadioWidget::RadioWidgetType type
, const int index
, int value
);
85 void onNodeXChanged();
86 void onNodeYChanged();
87 void onButtonChange(bool checked
);
88 void updateNodeValueLabels();
89 void onGsMouseEvent(QGraphicsSceneMouseEvent
* event
);
92 void setSize(const QSize
& size
, const QSize
&);
93 RadioTrimWidget
* createTrimWidget(QChar type
);
94 QToolButton
* createButtonWidget(int type
);
95 QLayout
* createNodeValueLayout(QChar type
, QLabel
*& valLabel
);
96 int getStickIndex(QChar type
);
97 int getTrimSliderType(QChar type
);
98 int getTrimButtonType(QChar type
, int pos
);
99 RadioTrimWidget
* getTrimWidget(int which
);
103 QGridLayout
* layout
;
105 CustomGraphicsScene
* scene
;
107 RadioTrimWidget
* hTrimWidget
;
108 RadioTrimWidget
* vTrimWidget
;
109 QToolButton
* btnHoldX
, * btnHoldY
;
110 QToolButton
* btnFixX
, * btnFixY
;
111 QLabel
* nodeLabelX
, * nodeLabelY
;
113 QTimer centerStickTimer
;
114 float ar
; // aspect ratio
123 * Custom GraphicsScene for mouse handling
125 class CustomGraphicsScene
: public QGraphicsScene
130 CustomGraphicsScene(QObject
*parent
= Q_NULLPTR
) :
131 QGraphicsScene(parent
)
135 void mouseEvent(QGraphicsSceneMouseEvent
* event
);
138 virtual void mousePressEvent(QGraphicsSceneMouseEvent
* event
);
139 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent
* event
);
140 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent
* event
);
143 #endif // VIRTUALJOYSTICKWIDGET_H