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 QGAMEPADMANAGER_H
38#define QGAMEPADMANAGER_H
39
40#include <QtCore/QObject>
41#include <QtCore/QMap>
42#include <QtGamepad/qtgamepadglobal.h>
43
44QT_BEGIN_NAMESPACE
45
46class QGamepadBackend;
47class QGamepad;
48class QGamepadManagerPrivate;
49
50class Q_GAMEPAD_EXPORT QGamepadManager : public QObject
51{
52 Q_OBJECT
53 Q_FLAGS(GamepadButton GamepadButtons)
54 Q_FLAGS(GamepadAxis GamepadAxes)
55 Q_PROPERTY(QList<int> connectedGamepads READ connectedGamepads NOTIFY connectedGamepadsChanged)
56
57public:
58 enum GamepadButton {
59 ButtonInvalid = -1,
60 ButtonA = 0,
61 ButtonB,
62 ButtonX,
63 ButtonY,
64 ButtonL1,
65 ButtonR1,
66 ButtonL2,
67 ButtonR2,
68 ButtonSelect,
69 ButtonStart,
70 ButtonL3,
71 ButtonR3,
72 ButtonUp,
73 ButtonDown,
74 ButtonRight,
75 ButtonLeft,
76 ButtonCenter,
77 ButtonGuide
78 };
79 Q_DECLARE_FLAGS(GamepadButtons, GamepadButton)
80
81 enum GamepadAxis {
82 AxisInvalid = -1,
83 AxisLeftX = 0,
84 AxisLeftY,
85 AxisRightX,
86 AxisRightY
87 };
88 Q_DECLARE_FLAGS(GamepadAxes, GamepadAxis)
89
90 static QGamepadManager* instance();
91
92 bool isGamepadConnected(int deviceId) const;
93 QString gamepadName(int deviceId) const;
94 const QList<int> connectedGamepads() const;
95
96public Q_SLOTS:
97 bool isConfigurationNeeded(int deviceId) const;
98 bool configureButton(int deviceId, GamepadButton button);
99 bool configureAxis(int deviceId, GamepadAxis axis);
100 bool setCancelConfigureButton(int deviceId, GamepadButton button);
101 void resetConfiguration(int deviceId);
102 void setSettingsFile(const QString &file);
103
104Q_SIGNALS:
105 void connectedGamepadsChanged();
106 void gamepadConnected(int deviceId);
107 void gamepadNameChanged(int deviceId, const QString &name);
108 void gamepadDisconnected(int deviceId);
109 void gamepadAxisEvent(int deviceId, QGamepadManager::GamepadAxis axis, double value);
110 void gamepadButtonPressEvent(int deviceId, QGamepadManager::GamepadButton button, double value);
111 void gamepadButtonReleaseEvent(int deviceId, QGamepadManager::GamepadButton button);
112 void buttonConfigured(int deviceId, QGamepadManager::GamepadButton button);
113 void axisConfigured(int deviceId, QGamepadManager::GamepadAxis axis);
114 void configurationCanceled(int deviceId);
115
116private:
117 QGamepadManager();
118 ~QGamepadManager();
119
120 Q_DECLARE_PRIVATE(QGamepadManager)
121 Q_DISABLE_COPY(QGamepadManager)
122 Q_PRIVATE_SLOT(d_func(), void _q_forwardGamepadConnected(int))
123 Q_PRIVATE_SLOT(d_func(), void _q_forwardGamepadNameChanged(int, const QString&))
124 Q_PRIVATE_SLOT(d_func(), void _q_forwardGamepadDisconnected(int))
125 Q_PRIVATE_SLOT(d_func(), void _q_forwardGamepadAxisEvent(int, QGamepadManager::GamepadAxis, double))
126 Q_PRIVATE_SLOT(d_func(), void _q_forwardGamepadButtonPressEvent(int, QGamepadManager::GamepadButton, double))
127 Q_PRIVATE_SLOT(d_func(), void _q_forwardGamepadButtonReleaseEvent(int, QGamepadManager::GamepadButton))
128};
129
130QT_END_NAMESPACE
131
132Q_DECLARE_METATYPE(QGamepadManager::GamepadButton)
133Q_DECLARE_METATYPE(QGamepadManager::GamepadAxis)
134
135#endif // QGAMEPADMANAGER_H
136

source code of qtgamepad/src/gamepad/qgamepadmanager.h