/* * Copyright (C) OpenTX * * Based on code named * th9x - http://code.google.com/p/th9x * er9x - http://code.google.com/p/er9x * gruvin9x - http://code.google.com/p/gruvin9x * * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ #ifndef VIRTUALJOYSTICKWIDGET_H #define VIRTUALJOYSTICKWIDGET_H #include #include #include #include #include #include #include #include class CustomGraphicsScene; class Node; class RadioTrimWidget; class VirtualJoystickWidget : public QWidget { Q_OBJECT public: enum ConstraintTypes { HOLD_X = 0, HOLD_Y, FIX_X, FIX_Y }; explicit VirtualJoystickWidget(QWidget * parent = NULL, QChar side = 'L', bool showTrims = true, bool showBtns = true, bool showValues = true, QSize size = QSize(125, 125)); void setStickX(qreal x); void setStickY(qreal y); void setStickPos(QPointF xy); void centerStick(); qreal getStickX(); qreal getStickY(); QPointF getStickPos(); void setTrimValue(int which, int value); void setTrimRange(int which, int min, int max); int getTrimValue(int which); void setStickConstraint(int which, bool active); void setStickColor(const QColor & color); virtual QSize sizeHint() const; virtual void resizeEvent(QResizeEvent *event); signals: void trimButtonPressed(int index); void trimButtonReleased(int index); void trimSliderMoved(int index, int value); protected slots: void onButtonChange(bool checked); void updateNodeValueLabels(); void onGsMouseEvent(QGraphicsSceneMouseEvent * event); protected: void setSize(const QSize & size, const QSize &); RadioTrimWidget * createTrimWidget(QChar type); QToolButton * createButtonWidget(int type); QLayout * createNodeValueLayout(QChar type, QLabel *& valLabel); int getTrimSliderType(QChar type); int getTrimButtonType(QChar type, int pos); RadioTrimWidget * getTrimWidget(int which); QChar stickSide; QSize prefSize; QGridLayout * layout; QGraphicsView * gv; CustomGraphicsScene * scene; Node * node; RadioTrimWidget * hTrimWidget; RadioTrimWidget * vTrimWidget; QToolButton * btnHoldX, * btnHoldY; QToolButton * btnFixX, * btnFixY; QLabel * nodeLabelX, * nodeLabelY; QSize extraSize; float ar; // aspect ratio bool m_stickPressed; }; /* * Custom GraphicsScene for mouse handling */ class CustomGraphicsScene : public QGraphicsScene { Q_OBJECT public: CustomGraphicsScene(QObject *parent = Q_NULLPTR) : QGraphicsScene(parent) {} signals: void mouseEvent(QGraphicsSceneMouseEvent * event); protected: virtual void mousePressEvent(QGraphicsSceneMouseEvent * event); virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event); virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event); }; #endif // VIRTUALJOYSTICKWIDGET_H