QJoysticks
A simple way to use joysticks with your Qt application
|
Manages the input systems and communicates them with the application. More...
#include <QJoysticks.h>
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_Joysticks * | sdlJoysticks () const |
VirtualJoystick * | virtualJoystick () const |
QJoystickDevice * | getInputDevice (int index) |
Static Public Member Functions | |
static QJoysticks * | getInstance () |
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_Joysticks * | m_sdlJoysticks |
VirtualJoystick * | m_virtualJoystick |
QList< QJoystickDevice * > | m_devices |
Friends | |
class | Test_QJoysticks |
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...
|
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.
References inputDevices().
Referenced by joystickExists(), nonBlacklistedCount(), and updateInterfaces().
QStringList QJoysticks::deviceNames | ( | ) | const |
Returns a list with the names of all registered joystick.
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().
|
static |
Returns the one and only instance of this class
QString QJoysticks::getName | ( | int | index | ) |
int QJoysticks::getNumAxes | ( | int | index | ) |
Returns the number of axes that the joystick at the given index has.
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.
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.
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.
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().
|
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.
|
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.
|
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.
|
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().
|
slot |
Blacklists or whitelists the joystick at the given index.
References getName(), inputDevices(), joystickExists(), and updateInterfaces().
|
slot |
If sort is set to true, then the device list will put all blacklisted joysticks at the end of the list
References updateInterfaces().
|
slot |
Enables or disables the virtual joystick
References VirtualJoystick::setJoystickEnabled(), and virtualJoystick().
|
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().
|
slot |
'Rescans' for new/removed joysticks and registers them again.
References addInputDevice(), QJoystickDevice::blacklisted, count(), inputDevices(), VirtualJoystick::joystick(), QJoystickDevice::name, sdlJoysticks(), VirtualJoystick::setJoystickID(), and virtualJoystick().
Referenced by setBlacklisted(), and setSortJoysticksByBlacklistState().
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.
QJoysticks
system class Referenced by setVirtualJoystickEnabled(), setVirtualJoystickRange(), and updateInterfaces().