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.

726 lines
19 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. #include "qgamepad.h"
  37. #include <private/qobject_p.h>
  38. QT_BEGIN_NAMESPACE
  39. class QGamepadPrivate : public QObjectPrivate
  40. {
  41. Q_DECLARE_PUBLIC(QGamepad)
  42. public:
  43. QGamepadPrivate(int deviceId)
  44. : deviceId(deviceId)
  45. , connected(false)
  46. , axisLeftX(0.0)
  47. , axisLeftY(0.0)
  48. , axisRightX(0.0)
  49. , axisRightY(0.0)
  50. , buttonA(false)
  51. , buttonB(false)
  52. , buttonX(false)
  53. , buttonY(false)
  54. , buttonL1(false)
  55. , buttonR1(false)
  56. , buttonL2(0.0)
  57. , buttonR2(0.0)
  58. , buttonSelect(false)
  59. , buttonStart(false)
  60. , buttonL3(false)
  61. , buttonR3(false)
  62. , buttonUp(false)
  63. , buttonDown(false)
  64. , buttonLeft(false)
  65. , buttonRight(false)
  66. , buttonCenter(false)
  67. , buttonGuide(false)
  68. {
  69. }
  70. QGamepadManager *gamepadManager;
  71. int deviceId;
  72. bool connected;
  73. QString name;
  74. double axisLeftX;
  75. double axisLeftY;
  76. double axisRightX;
  77. double axisRightY;
  78. bool buttonA;
  79. bool buttonB;
  80. bool buttonX;
  81. bool buttonY;
  82. bool buttonL1;
  83. bool buttonR1;
  84. double buttonL2;
  85. double buttonR2;
  86. bool buttonSelect;
  87. bool buttonStart;
  88. bool buttonL3;
  89. bool buttonR3;
  90. bool buttonUp;
  91. bool buttonDown;
  92. bool buttonLeft;
  93. bool buttonRight;
  94. bool buttonCenter;
  95. bool buttonGuide;
  96. void setConnected(bool isConnected);
  97. void setName(const QString &name);
  98. void _q_handleGamepadConnected(int id);
  99. void _q_handleGamepadNameChanged(int id, const QString &name);
  100. void _q_handleGamepadDisconnected(int id);
  101. void _q_handleGamepadAxisEvent(int id, QGamepadManager::GamepadAxis axis, double value);
  102. void _q_handleGamepadButtonPressEvent(int id, QGamepadManager::GamepadButton button, double value);
  103. void _q_handleGamepadButtonReleaseEvent(int id, QGamepadManager::GamepadButton button);
  104. };
  105. void QGamepadPrivate::setConnected(bool isConnected)
  106. {
  107. Q_Q(QGamepad);
  108. if (connected != isConnected) {
  109. connected = isConnected;
  110. emit q->connectedChanged(connected);
  111. }
  112. }
  113. void QGamepadPrivate::setName(const QString &theName)
  114. {
  115. Q_Q(QGamepad);
  116. if (name != theName) {
  117. name = theName;
  118. emit q->nameChanged(name);
  119. }
  120. }
  121. /*!
  122. * \internal
  123. */\
  124. void QGamepadPrivate::_q_handleGamepadConnected(int id)
  125. {
  126. if (id == deviceId) {
  127. setConnected(true);
  128. }
  129. }
  130. /*!
  131. * \internal
  132. */\
  133. void QGamepadPrivate::_q_handleGamepadNameChanged(int id, const QString &name)
  134. {
  135. if (id == deviceId)
  136. setName(name);
  137. }
  138. /*!
  139. * \internal
  140. */\
  141. void QGamepadPrivate::_q_handleGamepadDisconnected(int id)
  142. {
  143. if (id == deviceId) {
  144. setConnected(false);
  145. }
  146. }
  147. /*!
  148. * \internal
  149. */\
  150. void QGamepadPrivate::_q_handleGamepadAxisEvent(int id, QGamepadManager::GamepadAxis axis, double value)
  151. {
  152. Q_Q(QGamepad);
  153. if (id != deviceId)
  154. return;
  155. switch (axis) {
  156. case QGamepadManager::AxisLeftX:
  157. axisLeftX = value;
  158. emit q->axisLeftXChanged(value);
  159. break;
  160. case QGamepadManager::AxisLeftY:
  161. axisLeftY = value;
  162. emit q->axisLeftYChanged(value);
  163. break;
  164. case QGamepadManager::AxisRightX:
  165. axisRightX = value;
  166. emit q->axisRightXChanged(value);
  167. break;
  168. case QGamepadManager::AxisRightY:
  169. axisRightY = value;
  170. emit q->axisRightYChanged(value);
  171. break;
  172. default:
  173. break;
  174. }
  175. }
  176. /*!
  177. * \internal
  178. */\
  179. void QGamepadPrivate::_q_handleGamepadButtonPressEvent(int id, QGamepadManager::GamepadButton button, double value)
  180. {
  181. Q_Q(QGamepad);
  182. if (id != deviceId)
  183. return;
  184. switch (button) {
  185. case QGamepadManager::ButtonA:
  186. buttonA = true;
  187. emit q->buttonAChanged(true);
  188. break;
  189. case QGamepadManager::ButtonB:
  190. buttonB = true;
  191. emit q->buttonBChanged(true);
  192. break;
  193. case QGamepadManager::ButtonX:
  194. buttonX = true;
  195. emit q->buttonXChanged(true);
  196. break;
  197. case QGamepadManager::ButtonY:
  198. buttonY = true;
  199. emit q->buttonYChanged(true);
  200. break;
  201. case QGamepadManager::ButtonL1:
  202. buttonL1 = true;
  203. emit q->buttonL1Changed(true);
  204. break;
  205. case QGamepadManager::ButtonR1:
  206. buttonR1 = true;
  207. emit q->buttonR1Changed(true);
  208. break;
  209. case QGamepadManager::ButtonL2:
  210. buttonL2 = value;
  211. emit q->buttonL2Changed(value);
  212. break;
  213. case QGamepadManager::ButtonR2:
  214. buttonR2 = value;
  215. emit q->buttonR2Changed(value);
  216. break;
  217. case QGamepadManager::ButtonL3:
  218. buttonL3 = true;
  219. emit q->buttonL3Changed(true);
  220. break;
  221. case QGamepadManager::ButtonR3:
  222. buttonR3 = true;
  223. emit q->buttonR3Changed(true);
  224. break;
  225. case QGamepadManager::ButtonSelect:
  226. buttonSelect = true;
  227. emit q->buttonSelectChanged(true);
  228. break;
  229. case QGamepadManager::ButtonStart:
  230. buttonStart = true;
  231. emit q->buttonStartChanged(true);
  232. break;
  233. case QGamepadManager::ButtonUp:
  234. buttonUp = true;
  235. emit q->buttonUpChanged(true);
  236. break;
  237. case QGamepadManager::ButtonDown:
  238. buttonDown = true;
  239. emit q->buttonDownChanged(true);
  240. break;
  241. case QGamepadManager::ButtonLeft:
  242. buttonLeft = true;
  243. emit q->buttonLeftChanged(true);
  244. break;
  245. case QGamepadManager::ButtonRight:
  246. buttonRight = true;
  247. emit q->buttonRightChanged(true);
  248. break;
  249. case QGamepadManager::ButtonCenter:
  250. buttonCenter = true;
  251. emit q->buttonCenterChanged(true);
  252. break;
  253. case QGamepadManager::ButtonGuide:
  254. buttonGuide = true;
  255. emit q->buttonGuideChanged(true);
  256. break;
  257. default:
  258. break;
  259. }
  260. }
  261. /*!
  262. * \internal
  263. */\
  264. void QGamepadPrivate::_q_handleGamepadButtonReleaseEvent(int id, QGamepadManager::GamepadButton button)
  265. {
  266. Q_Q(QGamepad);
  267. if (id != deviceId)
  268. return;
  269. switch (button) {
  270. case QGamepadManager::ButtonA:
  271. buttonA = false;
  272. emit q->buttonAChanged(false);
  273. break;
  274. case QGamepadManager::ButtonB:
  275. buttonB = false;
  276. emit q->buttonBChanged(false);
  277. break;
  278. case QGamepadManager::ButtonX:
  279. buttonX = false;
  280. emit q->buttonXChanged(false);
  281. break;
  282. case QGamepadManager::ButtonY:
  283. buttonY = false;
  284. emit q->buttonYChanged(false);
  285. break;
  286. case QGamepadManager::ButtonL1:
  287. buttonL1 = false;
  288. emit q->buttonL1Changed(false);
  289. break;
  290. case QGamepadManager::ButtonR1:
  291. buttonR1 = false;
  292. emit q->buttonR1Changed(false);
  293. break;
  294. case QGamepadManager::ButtonL2:
  295. buttonL2 = 0.0;
  296. emit q->buttonL2Changed(0.0);
  297. break;
  298. case QGamepadManager::ButtonR2:
  299. buttonR2 = 0.0;
  300. emit q->buttonR2Changed(0.0);
  301. break;
  302. case QGamepadManager::ButtonL3:
  303. buttonL3 = false;
  304. emit q->buttonL3Changed(false);
  305. break;
  306. case QGamepadManager::ButtonR3:
  307. buttonR3 = false;
  308. emit q->buttonR3Changed(false);
  309. break;
  310. case QGamepadManager::ButtonSelect:
  311. buttonSelect = false;
  312. emit q->buttonSelectChanged(false);
  313. break;
  314. case QGamepadManager::ButtonStart:
  315. buttonStart = false;
  316. emit q->buttonStartChanged(false);
  317. break;
  318. case QGamepadManager::ButtonUp:
  319. buttonUp = false;
  320. emit q->buttonUpChanged(false);
  321. break;
  322. case QGamepadManager::ButtonDown:
  323. buttonDown = false;
  324. emit q->buttonDownChanged(false);
  325. break;
  326. case QGamepadManager::ButtonLeft:
  327. buttonLeft = false;
  328. emit q->buttonLeftChanged(false);
  329. break;
  330. case QGamepadManager::ButtonRight:
  331. buttonRight = false;
  332. emit q->buttonRightChanged(false);
  333. break;
  334. case QGamepadManager::ButtonCenter:
  335. buttonCenter = false;
  336. emit q->buttonCenterChanged(false);
  337. break;
  338. case QGamepadManager::ButtonGuide:
  339. buttonGuide = false;
  340. emit q->buttonGuideChanged(false);
  341. break;
  342. default:
  343. break;
  344. }
  345. }
  346. /*!
  347. \class QGamepad
  348. \inmodule QtGamepad
  349. \brief A gamepad device connected to a system
  350. QGamepad is used to access the current state of gamepad hardware connected
  351. to a system.
  352. */
  353. /*!
  354. * Constructs a QGamepad with the given \a deviceId and \a parent.
  355. */
  356. QGamepad::QGamepad(int deviceId, QObject *parent)
  357. : QObject(*new QGamepadPrivate(deviceId), parent)
  358. {
  359. Q_D(QGamepad);
  360. d->gamepadManager = QGamepadManager::instance();
  361. connect(d->gamepadManager, SIGNAL(gamepadConnected(int)), this, SLOT(_q_handleGamepadConnected(int)));
  362. connect(d->gamepadManager, SIGNAL(gamepadNameChanged(int, QString)), this, SLOT(_q_handleGamepadNameChanged(int, QString)));
  363. connect(d->gamepadManager, SIGNAL(gamepadDisconnected(int)), this, SLOT(_q_handleGamepadDisconnected(int)));
  364. connect(d->gamepadManager, SIGNAL(gamepadAxisEvent(int,QGamepadManager::GamepadAxis,double)), this, SLOT(_q_handleGamepadAxisEvent(int,QGamepadManager::GamepadAxis,double)));
  365. connect(d->gamepadManager, SIGNAL(gamepadButtonPressEvent(int,QGamepadManager::GamepadButton,double)), this, SLOT(_q_handleGamepadButtonPressEvent(int,QGamepadManager::GamepadButton,double)));
  366. connect(d->gamepadManager, SIGNAL(gamepadButtonReleaseEvent(int,QGamepadManager::GamepadButton)), this, SLOT(_q_handleGamepadButtonReleaseEvent(int,QGamepadManager::GamepadButton)));
  367. d->setConnected(d->gamepadManager->isGamepadConnected(deviceId));
  368. d->setName(d->gamepadManager->gamepadName(deviceId));
  369. }
  370. /*!
  371. * \brief Destroys the QGamepad.
  372. */
  373. QGamepad::~QGamepad()
  374. {
  375. }
  376. /*!
  377. * \property QGamepad::deviceId
  378. *
  379. * This property holds the deviceId of the gamepad device. Multiple gamepad devices can be
  380. * connected at any given time, so setting this property defines which gamepad to use.
  381. *
  382. * \sa QGamepadManager::connectedGamepads()
  383. */
  384. int QGamepad::deviceId() const
  385. {
  386. Q_D(const QGamepad);
  387. return d->deviceId;
  388. }
  389. /*!
  390. * \property QGamepad::connected
  391. * This read-only property holds the connectivity state of the gamepad device.
  392. * If a gamepad is connected, this property will be true, otherwise false.
  393. */
  394. bool QGamepad::isConnected() const
  395. {
  396. Q_D(const QGamepad);
  397. return d->connected;
  398. }
  399. /*!
  400. * \property QGamepad::name
  401. *
  402. * This read-only property holds the reported name of the gamepad if one
  403. * is available.
  404. */
  405. QString QGamepad::name() const
  406. {
  407. Q_D(const QGamepad);
  408. return d->name;
  409. }
  410. /*!
  411. * \property QGamepad::axisLeftX
  412. *
  413. * This read-only property holds the value of the left thumbstick's X axis.
  414. * The axis values range from -1.0 to 1.0.
  415. */
  416. double QGamepad::axisLeftX() const
  417. {
  418. Q_D(const QGamepad);
  419. return d->axisLeftX;
  420. }
  421. /*!
  422. * \property QGamepad::axisLeftY
  423. *
  424. * This read-only property holds the value of the left thumbstick's Y axis.
  425. * The axis values range from -1.0 to 1.0.
  426. */
  427. double QGamepad::axisLeftY() const
  428. {
  429. Q_D(const QGamepad);
  430. return d->axisLeftY;
  431. }
  432. /*!
  433. * \property QGamepad::axisRightX
  434. *
  435. * This read-only property holds the value of the right thumbstick's X axis.
  436. * The axis values range from -1.0 to 1.0.
  437. */
  438. double QGamepad::axisRightX() const
  439. {
  440. Q_D(const QGamepad);
  441. return d->axisRightX;
  442. }
  443. /*!
  444. * \property QGamepad::axisRightY
  445. *
  446. * This read-only property holds the value of the right thumbstick's Y axis.
  447. * The axis values range from -1.0 to 1.0.
  448. */
  449. double QGamepad::axisRightY() const
  450. {
  451. Q_D(const QGamepad);
  452. return d->axisRightY;
  453. }
  454. /*!
  455. * \property QGamepad::buttonA
  456. *
  457. * This read-only property holds the state of the A button.
  458. * The value is \c true when pressed, and \c false when not pressed.
  459. */
  460. bool QGamepad::buttonA() const
  461. {
  462. Q_D(const QGamepad);
  463. return d->buttonA;
  464. }
  465. /*!
  466. * \property QGamepad::buttonB
  467. *
  468. * This read-only property holds the state of the B button.
  469. * The value is \c true when pressed, and \c false when not pressed.
  470. *
  471. * \sa QGamepadManager::connectedGamepads()
  472. */
  473. bool QGamepad::buttonB() const
  474. {
  475. Q_D(const QGamepad);
  476. return d->buttonB;
  477. }
  478. /*!
  479. * \property QGamepad::buttonX
  480. *
  481. * This read-only property holds the state of the X button.
  482. * The value is \c true when pressed, and \c false when not pressed.
  483. */
  484. bool QGamepad::buttonX() const
  485. {
  486. Q_D(const QGamepad);
  487. return d->buttonX;
  488. }
  489. /*!
  490. * \property QGamepad::buttonY
  491. *
  492. * This read-only property holds the state of the Y button.
  493. * The value is \c true when pressed, and \c false when not pressed.
  494. */
  495. bool QGamepad::buttonY() const
  496. {
  497. Q_D(const QGamepad);
  498. return d->buttonY;
  499. }
  500. /*!
  501. * \property QGamepad::buttonL1
  502. *
  503. * This read-only property holds the state of the left shoulder button.
  504. * The value is \c true when pressed, and \c false when not pressed.
  505. */
  506. bool QGamepad::buttonL1() const
  507. {
  508. Q_D(const QGamepad);
  509. return d->buttonL1;
  510. }
  511. /*!
  512. * \property QGamepad::buttonR1
  513. *
  514. * This read-only property holds the state of the right shoulder button.
  515. * The value is \c true when pressed, and \c false when not pressed.
  516. */
  517. bool QGamepad::buttonR1() const
  518. {
  519. Q_D(const QGamepad);
  520. return d->buttonR1;
  521. }
  522. /*!
  523. * \property QGamepad::buttonL2
  524. *
  525. * This read-only property holds the value of the left trigger button.
  526. * This trigger value ranges from 0.0 when not pressed to 1.0
  527. * when pressed completely.
  528. */
  529. double QGamepad::buttonL2() const
  530. {
  531. Q_D(const QGamepad);
  532. return d->buttonL2;
  533. }
  534. /*!
  535. * \property QGamepad::buttonR2
  536. *
  537. * This read-only property holds the value of the right trigger button.
  538. * This trigger value ranges from 0.0 when not pressed to 1.0
  539. * when pressed completely.
  540. */
  541. double QGamepad::buttonR2() const
  542. {
  543. Q_D(const QGamepad);
  544. return d->buttonR2;
  545. }
  546. /*!
  547. * \property QGamepad::buttonSelect
  548. *
  549. * This read-only property holds the state of the Select button.
  550. * The value is \c true when pressed, and \c false when not pressed.
  551. * This button can sometimes be labeled as the Back button on some gamepads.
  552. */
  553. bool QGamepad::buttonSelect() const
  554. {
  555. Q_D(const QGamepad);
  556. return d->buttonSelect;
  557. }
  558. /*!
  559. * \property QGamepad::buttonStart
  560. *
  561. * This read-only property holds the state of the Start button.
  562. * The value is \c true when pressed, and \c false when not pressed.
  563. * This button can sometimes be labeled as the Forward button on some gamepads.
  564. */
  565. bool QGamepad::buttonStart() const
  566. {
  567. Q_D(const QGamepad);
  568. return d->buttonStart;
  569. }
  570. /*!
  571. * \property QGamepad::buttonL3
  572. *
  573. * This read-only property holds the state of the left stick button.
  574. * The value is \c true when pressed, and \c false when not pressed.
  575. * This button is usually triggered by pressing the left joystick itself.
  576. */
  577. bool QGamepad::buttonL3() const
  578. {
  579. Q_D(const QGamepad);
  580. return d->buttonL3;
  581. }
  582. /*!
  583. * \property QGamepad::buttonR3
  584. *
  585. * This read-only property holds the state of the right stick button.
  586. * The value is \c true when pressed, and \c false when not pressed.
  587. * This button is usually triggered by pressing the right joystick itself.
  588. */
  589. bool QGamepad::buttonR3() const
  590. {
  591. Q_D(const QGamepad);
  592. return d->buttonR3;
  593. }
  594. /*!
  595. * \property QGamepad::buttonUp
  596. *
  597. * This read-only property holds the state of the direction pad up button.
  598. * The value is \c true when pressed, and \c false when not pressed.
  599. */
  600. bool QGamepad::buttonUp() const
  601. {
  602. Q_D(const QGamepad);
  603. return d->buttonUp;
  604. }
  605. /*!
  606. * \property QGamepad::buttonDown
  607. *
  608. * This read-only property holds the state of the direction pad down button.
  609. * The value is \c true when pressed, and \c false when not pressed.
  610. */
  611. bool QGamepad::buttonDown() const
  612. {
  613. Q_D(const QGamepad);
  614. return d->buttonDown;
  615. }
  616. /*!
  617. * \property QGamepad::buttonLeft
  618. *
  619. * This read-only property holds the state of the direction pad left button.
  620. * The value is \c true when pressed, and \c false when not pressed.
  621. */
  622. bool QGamepad::buttonLeft() const
  623. {
  624. Q_D(const QGamepad);
  625. return d->buttonLeft;
  626. }
  627. /*!
  628. * \property QGamepad::buttonRight
  629. *
  630. * This read-only property holds the state of the direction pad right button.
  631. * The value is \c true when pressed, and \c false when not pressed.
  632. */
  633. bool QGamepad::buttonRight() const
  634. {
  635. Q_D(const QGamepad);
  636. return d->buttonRight;
  637. }
  638. /*!
  639. * \property QGamepad::buttonCenter
  640. *
  641. * This read-only property holds the state of the center button.
  642. * The value is \c true when pressed, and \c false when not pressed.
  643. */
  644. bool QGamepad::buttonCenter() const
  645. {
  646. Q_D(const QGamepad);
  647. return d->buttonCenter;
  648. }
  649. /*!
  650. * \property QGamepad::buttonGuide
  651. *
  652. * This read-only property holds the state of the guide button.
  653. * The value is \c true when pressed, and \c false when not pressed.
  654. * This button is typically the one in the center of the gamepad with a logo.
  655. * Some gamepads will not have a guide button.
  656. */
  657. bool QGamepad::buttonGuide() const
  658. {
  659. Q_D(const QGamepad);
  660. return d->buttonGuide;
  661. }
  662. void QGamepad::setDeviceId(int number)
  663. {
  664. Q_D(QGamepad);
  665. if (d->deviceId != number) {
  666. d->deviceId = number;
  667. emit deviceIdChanged(number);
  668. d->setConnected(d->gamepadManager->isGamepadConnected(d->deviceId));
  669. }
  670. }
  671. QT_END_NAMESPACE
  672. #include "moc_qgamepad.cpp"