| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. |
| 4 | ** Contact: http://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt Gamepad module |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL3$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at http://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or later as published by the Free |
| 28 | ** Software Foundation and appearing in the file LICENSE.GPL included in |
| 29 | ** the packaging of this file. Please review the following information to |
| 30 | ** ensure the GNU General Public License version 2.0 requirements will be |
| 31 | ** met: http://www.gnu.org/licenses/gpl-2.0.html. |
| 32 | ** |
| 33 | ** $QT_END_LICENSE$ |
| 34 | ** |
| 35 | ****************************************************************************/ |
| 36 | |
| 37 | #ifndef QGAMEPAD_H |
| 38 | #define QGAMEPAD_H |
| 39 | |
| 40 | #include <QtCore/QObject> |
| 41 | #include <QtGamepad/qtgamepadglobal.h> |
| 42 | #include <QtGamepad/QGamepadManager> |
| 43 | |
| 44 | QT_BEGIN_NAMESPACE |
| 45 | |
| 46 | class QGamepadPrivate; |
| 47 | |
| 48 | class Q_GAMEPAD_EXPORT QGamepad : public QObject |
| 49 | { |
| 50 | Q_OBJECT |
| 51 | Q_PROPERTY(int deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged) |
| 52 | Q_PROPERTY(bool connected READ isConnected NOTIFY connectedChanged) |
| 53 | Q_PROPERTY(QString name READ name NOTIFY nameChanged) |
| 54 | Q_PROPERTY(double axisLeftX READ axisLeftX NOTIFY axisLeftXChanged) |
| 55 | Q_PROPERTY(double axisLeftY READ axisLeftY NOTIFY axisLeftYChanged) |
| 56 | Q_PROPERTY(double axisRightX READ axisRightX NOTIFY axisRightXChanged) |
| 57 | Q_PROPERTY(double axisRightY READ axisRightY NOTIFY axisRightYChanged) |
| 58 | Q_PROPERTY(bool buttonA READ buttonA NOTIFY buttonAChanged) |
| 59 | Q_PROPERTY(bool buttonB READ buttonB NOTIFY buttonBChanged) |
| 60 | Q_PROPERTY(bool buttonX READ buttonX NOTIFY buttonXChanged) |
| 61 | Q_PROPERTY(bool buttonY READ buttonY NOTIFY buttonYChanged) |
| 62 | Q_PROPERTY(bool buttonL1 READ buttonL1 NOTIFY buttonL1Changed) |
| 63 | Q_PROPERTY(bool buttonR1 READ buttonR1 NOTIFY buttonR1Changed) |
| 64 | Q_PROPERTY(double buttonL2 READ buttonL2 NOTIFY buttonL2Changed) |
| 65 | Q_PROPERTY(double buttonR2 READ buttonR2 NOTIFY buttonR2Changed) |
| 66 | Q_PROPERTY(bool buttonSelect READ buttonSelect NOTIFY buttonSelectChanged) |
| 67 | Q_PROPERTY(bool buttonStart READ buttonStart NOTIFY buttonStartChanged) |
| 68 | Q_PROPERTY(bool buttonL3 READ buttonL3 NOTIFY buttonL3Changed) |
| 69 | Q_PROPERTY(bool buttonR3 READ buttonR3 NOTIFY buttonR3Changed) |
| 70 | Q_PROPERTY(bool buttonUp READ buttonUp NOTIFY buttonUpChanged) |
| 71 | Q_PROPERTY(bool buttonDown READ buttonDown NOTIFY buttonDownChanged) |
| 72 | Q_PROPERTY(bool buttonLeft READ buttonLeft NOTIFY buttonLeftChanged) |
| 73 | Q_PROPERTY(bool buttonRight READ buttonRight NOTIFY buttonRightChanged) |
| 74 | Q_PROPERTY(bool buttonCenter READ buttonCenter NOTIFY buttonCenterChanged) |
| 75 | Q_PROPERTY(bool buttonGuide READ buttonGuide NOTIFY buttonGuideChanged) |
| 76 | public: |
| 77 | explicit QGamepad(int deviceId = 0, QObject *parent = nullptr); |
| 78 | ~QGamepad(); |
| 79 | |
| 80 | int deviceId() const; |
| 81 | |
| 82 | bool isConnected() const; |
| 83 | |
| 84 | QString name() const; |
| 85 | |
| 86 | double axisLeftX() const; |
| 87 | double axisLeftY() const; |
| 88 | double axisRightX() const; |
| 89 | double axisRightY() const; |
| 90 | bool buttonA() const; |
| 91 | bool buttonB() const; |
| 92 | bool buttonX() const; |
| 93 | bool buttonY() const; |
| 94 | bool buttonL1() const; |
| 95 | bool buttonR1() const; |
| 96 | double buttonL2() const; |
| 97 | double buttonR2() const; |
| 98 | bool buttonSelect() const; |
| 99 | bool buttonStart() const; |
| 100 | bool buttonL3() const; |
| 101 | bool buttonR3() const; |
| 102 | bool buttonUp() const; |
| 103 | bool buttonDown() const; |
| 104 | bool buttonLeft() const; |
| 105 | bool buttonRight() const; |
| 106 | bool buttonCenter() const; |
| 107 | bool buttonGuide() const; |
| 108 | |
| 109 | Q_SIGNALS: |
| 110 | |
| 111 | void deviceIdChanged(int value); |
| 112 | void connectedChanged(bool value); |
| 113 | void nameChanged(QString value); |
| 114 | void axisLeftXChanged(double value); |
| 115 | void axisLeftYChanged(double value); |
| 116 | void axisRightXChanged(double value); |
| 117 | void axisRightYChanged(double value); |
| 118 | void buttonAChanged(bool value); |
| 119 | void buttonBChanged(bool value); |
| 120 | void buttonXChanged(bool value); |
| 121 | void buttonYChanged(bool value); |
| 122 | void buttonL1Changed(bool value); |
| 123 | void buttonR1Changed(bool value); |
| 124 | void buttonL2Changed(double value); |
| 125 | void buttonR2Changed(double value); |
| 126 | void buttonSelectChanged(bool value); |
| 127 | void buttonStartChanged(bool value); |
| 128 | void buttonL3Changed(bool value); |
| 129 | void buttonR3Changed(bool value); |
| 130 | void buttonUpChanged(bool value); |
| 131 | void buttonDownChanged(bool value); |
| 132 | void buttonLeftChanged(bool value); |
| 133 | void buttonRightChanged(bool value); |
| 134 | void buttonCenterChanged(bool value); |
| 135 | void buttonGuideChanged(bool value); |
| 136 | |
| 137 | public Q_SLOTS: |
| 138 | |
| 139 | void setDeviceId(int number); |
| 140 | |
| 141 | private: |
| 142 | Q_DECLARE_PRIVATE(QGamepad) |
| 143 | Q_DISABLE_COPY(QGamepad) |
| 144 | Q_PRIVATE_SLOT(d_func(), void _q_handleGamepadConnected(int)) |
| 145 | Q_PRIVATE_SLOT(d_func(), void _q_handleGamepadNameChanged(int, const QString &)) |
| 146 | Q_PRIVATE_SLOT(d_func(), void _q_handleGamepadDisconnected(int)) |
| 147 | Q_PRIVATE_SLOT(d_func(), void _q_handleGamepadAxisEvent(int, QGamepadManager::GamepadAxis, double)) |
| 148 | Q_PRIVATE_SLOT(d_func(), void _q_handleGamepadButtonPressEvent(int, QGamepadManager::GamepadButton, double)) |
| 149 | Q_PRIVATE_SLOT(d_func(), void _q_handleGamepadButtonReleaseEvent(int, QGamepadManager::GamepadButton)) |
| 150 | }; |
| 151 | |
| 152 | QT_END_NAMESPACE |
| 153 | |
| 154 | Q_DECLARE_METATYPE(QGamepad*) |
| 155 | |
| 156 | #endif // QGAMEPAD_H |
| 157 | |