QJoysticks
A simple way to use joysticks with your Qt application
Public Slots | Signals | Public Member Functions | Static Public Member Functions | Private Slots | Private Attributes | Friends | List of all members
QJoysticks Class Reference

Manages the input systems and communicates them with the application. More...

#include <QJoysticks.h>

Inheritance diagram for QJoysticks:

Public Slots

void updateInterfaces ()
 
void setVirtualJoystickRange (qreal range)
 
void setVirtualJoystickEnabled (bool enabled)
 
void setSortJoysticksByBlacklistState (bool sort)
 
void setBlacklisted (int index, bool blacklisted)
 

Signals

void countChanged ()
 
void POVEvent (const QJoystickPOVEvent &event)
 
void axisEvent (const QJoystickAxisEvent &event)
 
void buttonEvent (const QJoystickButtonEvent &event)
 
void povChanged (const int js, const int pov, const int angle)
 
void axisChanged (const int js, const int axis, const qreal value)
 
void buttonChanged (const int js, const int button, const bool pressed)
 

Public Member Functions

Q_INVOKABLE int count () const
 
Q_INVOKABLE int nonBlacklistedCount ()
 
Q_INVOKABLE int getNumAxes (int index)
 
Q_INVOKABLE int getNumPOVs (int index)
 
Q_INVOKABLE int getNumButtons (int index)
 
Q_INVOKABLE bool isBlacklisted (int index)
 
Q_INVOKABLE bool joystickExists (int index)
 
Q_INVOKABLE QString getName (int index)
 
Q_INVOKABLE QStringList deviceNames () const
 
QList< QJoystickDevice * > inputDevices () const
 
SDL_JoystickssdlJoysticks () const
 
VirtualJoystickvirtualJoystick () const
 
QJoystickDevicegetInputDevice (int index)
 

Static Public Member Functions

static QJoysticksgetInstance ()
 

Private Slots

void resetJoysticks ()
 
void addInputDevice (QJoystickDevice *device)
 
void onPOVEvent (const QJoystickPOVEvent &event)
 
void onAxisEvent (const QJoystickAxisEvent &event)
 
void onButtonEvent (const QJoystickButtonEvent &event)
 

Private Attributes

bool m_sortJoyticks
 
QSettings * m_settings
 
SDL_Joysticksm_sdlJoysticks
 
VirtualJoystickm_virtualJoystick
 
QList< QJoystickDevice * > m_devices
 

Friends

class Test_QJoysticks
 

Detailed Description

Manages the input systems and communicates them with the application.

The QJoysticks class is the "god-object" of this system. It manages every input system used by the application (e.g. SDL for real joysticks and keyboard for virtual joystick) and communicates every module/input system with the rest of the application through standarized types.

The joysticks are assigned a numerical ID, which the QJoysticks can use to identify them. The ID's start with 0 (as with a QList). The ID's are refreshed when a joystick is attached or removed. The first joystick that has been connected to the computer will have 0 as an ID, the second joystick will have 1 as an ID, and so on...

Note
the virtual joystick will ALWAYS be the last joystick to be registered, even if it has been enabled before any SDL joystick has been attached.

Member Function Documentation

void QJoysticks::addInputDevice ( QJoystickDevice device)
privateslot

Registers the given device to the QJoysticks system

Referenced by updateInterfaces().

int QJoysticks::count ( ) const

Returns the number of joysticks that are attached to the computer and/or registered with the QJoysticks system.

Note
This count also includes the virtual joystick (if its enabled)

References inputDevices().

Referenced by joystickExists(), nonBlacklistedCount(), and updateInterfaces().

QStringList QJoysticks::deviceNames ( ) const

Returns a list with the names of all registered joystick.

Note
This list also includes the blacklisted joysticks
This list also includes the virtual joystick (if its enabled)

References inputDevices(), and QJoystickDevice::name.

QJoystickDevice * QJoysticks::getInputDevice ( int  index)

Returns a pointer to the device at the given index.

References inputDevices(), and joystickExists().

Referenced by getNumAxes(), getNumButtons(), and getNumPOVs().

QJoysticks * QJoysticks::getInstance ( )
static

Returns the one and only instance of this class

QString QJoysticks::getName ( int  index)

Returns the name of the given joystick

References joystickExists().

Referenced by setBlacklisted().

int QJoysticks::getNumAxes ( int  index)

Returns the number of axes that the joystick at the given index has.

Note
If the joystick does not exist, this function will return 0

References getInputDevice(), joystickExists(), and QJoystickDevice::numAxes.

int QJoysticks::getNumButtons ( int  index)

Returns the number of buttons that the joystick at the given index has.

Note
If the joystick does not exist, this function will return 0

References getInputDevice(), joystickExists(), and QJoystickDevice::numButtons.

int QJoysticks::getNumPOVs ( int  index)

Returns the number of POVs that the joystick at the given index has.

Note
If the joystick does not exist, this function will return 0

References getInputDevice(), joystickExists(), and QJoystickDevice::numPOVs.

QList< QJoystickDevice * > QJoysticks::inputDevices ( ) const

Returns a pointer to a list containing all registered joysticks. This can be used for advanced hacks or just to get all properties of each joystick.

Referenced by count(), deviceNames(), getInputDevice(), isBlacklisted(), setBlacklisted(), and updateInterfaces().

bool QJoysticks::isBlacklisted ( int  index)

Returns true if the joystick at the given index is blacklisted.

Note
If the joystick does not exist, this function will also return true

References inputDevices(), and joystickExists().

Referenced by nonBlacklistedCount(), onAxisEvent(), onButtonEvent(), and onPOVEvent().

bool QJoysticks::joystickExists ( int  index)

Returns true if the joystick at the given index is valid, otherwise, the function returns false and warns the user through the console.

References count().

Referenced by getInputDevice(), getName(), getNumAxes(), getNumButtons(), getNumPOVs(), isBlacklisted(), and setBlacklisted().

int QJoysticks::nonBlacklistedCount ( )

Returns the number of joysticks that are not blacklisted. This can be considered the "effective" number of joysticks.

References count(), and isBlacklisted().

void QJoysticks::onAxisEvent ( const QJoystickAxisEvent event)
privateslot

Configures the QML-friendly signal based on the information given by the event data

References QJoystickAxisEvent::axis, QJoystickDevice::id, isBlacklisted(), QJoystickAxisEvent::joystick, and QJoystickAxisEvent::value.

void QJoysticks::onButtonEvent ( const QJoystickButtonEvent event)
privateslot

Configures the QML-friendly signal based on the information given by the event data

References QJoystickButtonEvent::button, QJoystickDevice::id, isBlacklisted(), QJoystickButtonEvent::joystick, and QJoystickButtonEvent::pressed.

void QJoysticks::onPOVEvent ( const QJoystickPOVEvent event)
privateslot

Configures the QML-friendly signal based on the information given by the event data

References QJoystickPOVEvent::angle, QJoystickDevice::id, isBlacklisted(), QJoystickPOVEvent::joystick, and QJoystickPOVEvent::pov.

void QJoysticks::resetJoysticks ( )
privateslot

Removes all the registered joysticks and emits appropiate signals.

SDL_Joysticks * QJoysticks::sdlJoysticks ( ) const

Returns a pointer to the SDL joysticks system. This can be used if you need to get more information regarding the joysticks registered and managed with SDL.

Referenced by updateInterfaces().

void QJoysticks::setBlacklisted ( int  index,
bool  blacklisted 
)
slot

Blacklists or whitelists the joystick at the given index.

Note
This function does not have effect if the given joystick does not exist
Once the joystick is blacklisted, the joystick list will be updated

References getName(), inputDevices(), joystickExists(), and updateInterfaces().

void QJoysticks::setSortJoysticksByBlacklistState ( bool  sort)
slot

If sort is set to true, then the device list will put all blacklisted joysticks at the end of the list

References updateInterfaces().

void QJoysticks::setVirtualJoystickEnabled ( bool  enabled)
slot

Enables or disables the virtual joystick

References VirtualJoystick::setJoystickEnabled(), and virtualJoystick().

void QJoysticks::setVirtualJoystickRange ( qreal  range)
slot

Changes the axis value range of the virtual joystick.

Take into account that maximum axis values supported by the QJoysticks system is from -1 to 1.

References VirtualJoystick::setAxisRange(), and virtualJoystick().

void QJoysticks::updateInterfaces ( )
slot
VirtualJoystick * QJoysticks::virtualJoystick ( ) const

Returns a pointer to the virtual joystick system. This can be used if you need to get more information regarding the virtual joystick or want to change its properties directly.

Note
You can also change the properties of the virtual joysticks using the functions of the QJoysticks system class

Referenced by setVirtualJoystickEnabled(), setVirtualJoystickRange(), and updateInterfaces().


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