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.

156 lines
6.1 KiB

8 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 QGAMEPAD_H
  37. #define QGAMEPAD_H
  38. #include <QtCore/QObject>
  39. #include "qtgamepadglobal.h"
  40. #include "qgamepadmanager.h"
  41. QT_BEGIN_NAMESPACE
  42. class QGamepadPrivate;
  43. class Q_GAMEPAD_EXPORT QGamepad : public QObject
  44. {
  45. Q_OBJECT
  46. Q_PROPERTY(int deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged)
  47. Q_PROPERTY(bool connected READ isConnected NOTIFY connectedChanged)
  48. Q_PROPERTY(QString name READ name NOTIFY nameChanged)
  49. Q_PROPERTY(double axisLeftX READ axisLeftX NOTIFY axisLeftXChanged)
  50. Q_PROPERTY(double axisLeftY READ axisLeftY NOTIFY axisLeftYChanged)
  51. Q_PROPERTY(double axisRightX READ axisRightX NOTIFY axisRightXChanged)
  52. Q_PROPERTY(double axisRightY READ axisRightY NOTIFY axisRightYChanged)
  53. Q_PROPERTY(bool buttonA READ buttonA NOTIFY buttonAChanged)
  54. Q_PROPERTY(bool buttonB READ buttonB NOTIFY buttonBChanged)
  55. Q_PROPERTY(bool buttonX READ buttonX NOTIFY buttonXChanged)
  56. Q_PROPERTY(bool buttonY READ buttonY NOTIFY buttonYChanged)
  57. Q_PROPERTY(bool buttonL1 READ buttonL1 NOTIFY buttonL1Changed)
  58. Q_PROPERTY(bool buttonR1 READ buttonR1 NOTIFY buttonR1Changed)
  59. Q_PROPERTY(double buttonL2 READ buttonL2 NOTIFY buttonL2Changed)
  60. Q_PROPERTY(double buttonR2 READ buttonR2 NOTIFY buttonR2Changed)
  61. Q_PROPERTY(bool buttonSelect READ buttonSelect NOTIFY buttonSelectChanged)
  62. Q_PROPERTY(bool buttonStart READ buttonStart NOTIFY buttonStartChanged)
  63. Q_PROPERTY(bool buttonL3 READ buttonL3 NOTIFY buttonL3Changed)
  64. Q_PROPERTY(bool buttonR3 READ buttonR3 NOTIFY buttonR3Changed)
  65. Q_PROPERTY(bool buttonUp READ buttonUp NOTIFY buttonUpChanged)
  66. Q_PROPERTY(bool buttonDown READ buttonDown NOTIFY buttonDownChanged)
  67. Q_PROPERTY(bool buttonLeft READ buttonLeft NOTIFY buttonLeftChanged)
  68. Q_PROPERTY(bool buttonRight READ buttonRight NOTIFY buttonRightChanged)
  69. Q_PROPERTY(bool buttonCenter READ buttonCenter NOTIFY buttonCenterChanged)
  70. Q_PROPERTY(bool buttonGuide READ buttonGuide NOTIFY buttonGuideChanged)
  71. public:
  72. explicit QGamepad(int deviceId = 0, QObject *parent = nullptr);
  73. ~QGamepad();
  74. int deviceId() const;
  75. bool isConnected() const;
  76. QString name() const;
  77. double axisLeftX() const;
  78. double axisLeftY() const;
  79. double axisRightX() const;
  80. double axisRightY() const;
  81. bool buttonA() const;
  82. bool buttonB() const;
  83. bool buttonX() const;
  84. bool buttonY() const;
  85. bool buttonL1() const;
  86. bool buttonR1() const;
  87. double buttonL2() const;
  88. double buttonR2() const;
  89. bool buttonSelect() const;
  90. bool buttonStart() const;
  91. bool buttonL3() const;
  92. bool buttonR3() const;
  93. bool buttonUp() const;
  94. bool buttonDown() const;
  95. bool buttonLeft() const;
  96. bool buttonRight() const;
  97. bool buttonCenter() const;
  98. bool buttonGuide() const;
  99. Q_SIGNALS:
  100. void deviceIdChanged(int value);
  101. void connectedChanged(bool value);
  102. void nameChanged(QString value);
  103. void axisLeftXChanged(double value);
  104. void axisLeftYChanged(double value);
  105. void axisRightXChanged(double value);
  106. void axisRightYChanged(double value);
  107. void buttonAChanged(bool value);
  108. void buttonBChanged(bool value);
  109. void buttonXChanged(bool value);
  110. void buttonYChanged(bool value);
  111. void buttonL1Changed(bool value);
  112. void buttonR1Changed(bool value);
  113. void buttonL2Changed(double value);
  114. void buttonR2Changed(double value);
  115. void buttonSelectChanged(bool value);
  116. void buttonStartChanged(bool value);
  117. void buttonL3Changed(bool value);
  118. void buttonR3Changed(bool value);
  119. void buttonUpChanged(bool value);
  120. void buttonDownChanged(bool value);
  121. void buttonLeftChanged(bool value);
  122. void buttonRightChanged(bool value);
  123. void buttonCenterChanged(bool value);
  124. void buttonGuideChanged(bool value);
  125. public Q_SLOTS:
  126. void setDeviceId(int number);
  127. private:
  128. Q_DECLARE_PRIVATE(QGamepad)
  129. Q_DISABLE_COPY(QGamepad)
  130. Q_PRIVATE_SLOT(d_func(), void _q_handleGamepadConnected(int))
  131. Q_PRIVATE_SLOT(d_func(), void _q_handleGamepadNameChanged(int, const QString &))
  132. Q_PRIVATE_SLOT(d_func(), void _q_handleGamepadDisconnected(int))
  133. Q_PRIVATE_SLOT(d_func(), void _q_handleGamepadAxisEvent(int, QGamepadManager::GamepadAxis, double))
  134. Q_PRIVATE_SLOT(d_func(), void _q_handleGamepadButtonPressEvent(int, QGamepadManager::GamepadButton, double))
  135. Q_PRIVATE_SLOT(d_func(), void _q_handleGamepadButtonReleaseEvent(int, QGamepadManager::GamepadButton))
  136. };
  137. QT_END_NAMESPACE
  138. Q_DECLARE_METATYPE(QGamepad*)
  139. #endif // QGAMEPAD_H