Roomba App  1.0
Joystick Class Reference

The class to visualize analog joystick swing on a widget. More...

#include <joystick.hh>

Inheritance diagram for Joystick:
Collaboration diagram for Joystick:

Public Slots

void setX (const float &value)
 Set the value of the x coordinate. More...
 
void setY (const float &value)
 Set the value of the y coordinate. More...
 
void addXAnimation ()
 Add an animation for the joystick to return to the x-axis zero position. More...
 
void addYAnimation ()
 Add an animation for the joystick to return to the y-axis zero position. More...
 
void removeXAnimation ()
 Remove an animation for the joystick to return to the x-axis zero position. More...
 
void removeYAnimation ()
 Remove an animation for the joystick to return to the y-axis zero position. More...
 
void setAlignment (Qt::Alignment align)
 Set the widget alignment. More...
 
void movePos (const QPoint &coordinates)
 Change the knop coordinates. More...
 

Signals

void xChange (float value)
 Signal emitted when the x coordinate value changed. More...
 
void yChange (float value)
 Signal emitted when the y coordinate value changed. More...
 

Public Member Functions

 Joystick (QWidget *parent=nullptr)
 Construct a new Joystick object. More...
 
float x () const
 Get a coordinate value on the x axis. More...
 
float y () const
 Get a coordinate value on the y axis. More...
 
 ~Joystick ()=default
 Destroy the Joystick object. More...
 

Properties

float x
 
float y
 

Private Member Functions

float checkValue (const float &value, const float &min, const float &max) const
 Check if the coordinate value is in proper range. More...
 
void resizeEvent (QResizeEvent *event) override
 Event handler to change size of widget. More...
 
virtual void paintEvent (QPaintEvent *event) override
 Draw an analog joystick with its' background. More...
 

Private Attributes

const float _midPoint = 2048.0
 Middle value of the raw analog joystick coordinates. More...
 
float _x
 Value of the the x coordinate. More...
 
float _y
 Value of the the y coordinate. More...
 
QRectF _bounds
 Background bounds. More...
 
QRectF _knopBounds
 Knop bounds. More...
 
QParallelAnimationGroup * _animation
 Animation group for two axis. More...
 
QPropertyAnimation * _xAnimation
 Animation on the the x axis. More...
 
QPropertyAnimation * _yAnimation
 Animation on the the y axis. More...
 
Qt::Alignment _alignment
 Widget alignment. More...
 

Detailed Description

Definition at line 25 of file joystick.hh.

Constructor & Destructor Documentation

◆ Joystick()

Joystick::Joystick ( QWidget *  parent = nullptr)
explicit
Parameters
[in,out]parentPointer to the parent QWidget object.

Definition at line 24 of file joystick.cpp.

◆ ~Joystick()

Joystick::~Joystick ( )
default

Member Function Documentation

◆ addXAnimation

void Joystick::addXAnimation ( )
slot

Definition at line 63 of file joystick.cpp.

◆ addYAnimation

void Joystick::addYAnimation ( )
slot

Definition at line 69 of file joystick.cpp.

◆ checkValue()

float Joystick::checkValue ( const float &  value,
const float &  min,
const float &  max 
) const
private
Parameters
[in]valueValue to be check.
[in]minMinimal value.
[in]maxMaximal value.
Return values
minvalue is below range.
maxvalue is above range.
valuevalue is in proper range.

Definition at line 126 of file joystick.cpp.

Here is the caller graph for this function:

◆ movePos

void Joystick::movePos ( const QPoint &  coordinates)
slot

Calculate coordinates which will be used to draw the knob from raw coordinates passed as parameter. Emit signal when coordinates change.

Parameters
[in]coordinatesPoint with the coordinates read from the serial port.

Definition at line 94 of file joystick.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ paintEvent()

void Joystick::paintEvent ( QPaintEvent *  event)
overrideprivatevirtual
Parameters
[in]eventPaint event [not used].

Definition at line 173 of file joystick.cpp.

◆ removeXAnimation

void Joystick::removeXAnimation ( )
slot

Definition at line 75 of file joystick.cpp.

◆ removeYAnimation

void Joystick::removeYAnimation ( )
slot

Definition at line 82 of file joystick.cpp.

◆ resizeEvent()

void Joystick::resizeEvent ( QResizeEvent *  event)
overrideprivate

Change the widget geometry to properly display visualization.

Parameters
[in]eventResize event [not used].

Definition at line 131 of file joystick.cpp.

◆ setAlignment

void Joystick::setAlignment ( Qt::Alignment  align)
slot

Alignment is used in the resizeEvent to properly calculate the widget dimensions.

Parameters
[in]alignAlignment type.

Definition at line 89 of file joystick.cpp.

◆ setX

void Joystick::setX ( const float &  value)
slot
Parameters
[in]valueValue of the x coordinate in range from -1.f to 1.f.

Definition at line 41 of file joystick.cpp.

Here is the call graph for this function:

◆ setY

void Joystick::setY ( const float &  value)
slot
Parameters
[in]valueValue of the y coordinate in range from -1.f to 1.f.

Definition at line 52 of file joystick.cpp.

Here is the call graph for this function:

◆ x()

float Joystick::x ( ) const
inline
Returns
Value of the x coordinate.

Definition at line 42 of file joystick.hh.

◆ xChange

void Joystick::xChange ( float  value)
signal
Parameters
[in]valueValue of the x coordinate.
Here is the caller graph for this function:

◆ y()

float Joystick::y ( ) const
inline
Returns
Value of the y coordinate.

Definition at line 48 of file joystick.hh.

◆ yChange

void Joystick::yChange ( float  value)
signal
Parameters
[in]valueValue of the y coordinate.
Here is the caller graph for this function:

Member Data Documentation

◆ _alignment

Qt::Alignment Joystick::_alignment
private

Definition at line 155 of file joystick.hh.

◆ _animation

QParallelAnimationGroup* Joystick::_animation
private

Definition at line 152 of file joystick.hh.

◆ _bounds

QRectF Joystick::_bounds
private

Definition at line 150 of file joystick.hh.

◆ _knopBounds

QRectF Joystick::_knopBounds
private

Definition at line 151 of file joystick.hh.

◆ _midPoint

const float Joystick::_midPoint = 2048.0
private

Definition at line 147 of file joystick.hh.

◆ _x

float Joystick::_x
private

Definition at line 148 of file joystick.hh.

◆ _xAnimation

QPropertyAnimation* Joystick::_xAnimation
private

Definition at line 153 of file joystick.hh.

◆ _y

float Joystick::_y
private

Definition at line 149 of file joystick.hh.

◆ _yAnimation

QPropertyAnimation* Joystick::_yAnimation
private

Definition at line 154 of file joystick.hh.

Property Documentation

◆ x

float Joystick::x
readwrite

Definition at line 1 of file joystick.hh.

◆ y

float Joystick::y
readwrite

Definition at line 1 of file joystick.hh.


The documentation for this class was generated from the following files: