Roomba App  1.0
joystick.hh
Go to the documentation of this file.
1 
15 #ifndef JOYSTICK_HH
16 #define JOYSTICK_HH
17 
18 #include <QParallelAnimationGroup>
19 #include <QPropertyAnimation>
20 #include <QWidget>
21 
25 class Joystick : public QWidget
26 {
27  Q_OBJECT
28  Q_PROPERTY(float x READ x WRITE setX NOTIFY xChange)
29  Q_PROPERTY(float y READ y WRITE setY NOTIFY yChange)
30 
31  public:
36  explicit Joystick(QWidget* parent = nullptr);
37 
42  float x() const { return _x; }
43 
48  float y() const { return _y; }
49 
53  ~Joystick() = default;
54 
55  signals:
60  void xChange(float value);
61 
66  void yChange(float value);
67 
68  public slots:
73  void setX(const float& value);
74 
79  void setY(const float& value);
80 
84  void addXAnimation();
85 
89  void addYAnimation();
90 
94  void removeXAnimation();
95 
99  void removeYAnimation();
100 
108  void setAlignment(Qt::Alignment align);
109 
118  void movePos(const QPoint& coordinates);
119 
120  private:
130  float checkValue(const float& value, const float& min, const float& max) const;
131 
139  void resizeEvent(QResizeEvent* event) override;
140 
145  virtual void paintEvent(QPaintEvent* event) override;
146 
147  const float _midPoint = 2048.0;
148  float _x;
149  float _y;
150  QRectF _bounds;
151  QRectF _knopBounds;
152  QParallelAnimationGroup* _animation;
153  QPropertyAnimation* _xAnimation;
154  QPropertyAnimation* _yAnimation;
155  Qt::Alignment _alignment;
156 };
157 
158 #endif /* JOYSTICK_HH */
The class to visualize analog joystick swing on a widget.
Definition: joystick.hh:26
const float _midPoint
Middle value of the raw analog joystick coordinates.
Definition: joystick.hh:147
float checkValue(const float &value, const float &min, const float &max) const
Check if the coordinate value is in proper range.
Definition: joystick.cpp:126
void addYAnimation()
Add an animation for the joystick to return to the y-axis zero position.
Definition: joystick.cpp:69
void yChange(float value)
Signal emitted when the y coordinate value changed.
Qt::Alignment _alignment
Widget alignment.
Definition: joystick.hh:155
QPropertyAnimation * _xAnimation
Animation on the the x axis.
Definition: joystick.hh:153
void removeYAnimation()
Remove an animation for the joystick to return to the y-axis zero position.
Definition: joystick.cpp:82
float x() const
Get a coordinate value on the x axis.
Definition: joystick.hh:42
QPropertyAnimation * _yAnimation
Animation on the the y axis.
Definition: joystick.hh:154
void movePos(const QPoint &coordinates)
Change the knop coordinates.
Definition: joystick.cpp:94
QRectF _knopBounds
Knop bounds.
Definition: joystick.hh:151
void setX(const float &value)
Set the value of the x coordinate.
Definition: joystick.cpp:41
void setY(const float &value)
Set the value of the y coordinate.
Definition: joystick.cpp:52
float _y
Value of the the y coordinate.
Definition: joystick.hh:149
float _x
Value of the the x coordinate.
Definition: joystick.hh:148
float y() const
Get a coordinate value on the y axis.
Definition: joystick.hh:48
void removeXAnimation()
Remove an animation for the joystick to return to the x-axis zero position.
Definition: joystick.cpp:75
virtual void paintEvent(QPaintEvent *event) override
Draw an analog joystick with its' background.
Definition: joystick.cpp:173
float y
Definition: joystick.hh:29
QParallelAnimationGroup * _animation
Animation group for two axis.
Definition: joystick.hh:152
void addXAnimation()
Add an animation for the joystick to return to the x-axis zero position.
Definition: joystick.cpp:63
~Joystick()=default
Destroy the Joystick object.
void setAlignment(Qt::Alignment align)
Set the widget alignment.
Definition: joystick.cpp:89
void resizeEvent(QResizeEvent *event) override
Event handler to change size of widget.
Definition: joystick.cpp:131
Joystick(QWidget *parent=nullptr)
Construct a new Joystick object.
Definition: joystick.cpp:24
float x
Definition: joystick.hh:28
void xChange(float value)
Signal emitted when the x coordinate value changed.
QRectF _bounds
Background bounds.
Definition: joystick.hh:150