You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
4.8 KiB

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