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 | #include "qgamepad.h" |
38 | |
39 | #include <private/qobject_p.h> |
40 | |
41 | QT_BEGIN_NAMESPACE |
42 | |
43 | class QGamepadPrivate : public QObjectPrivate |
44 | { |
45 | Q_DECLARE_PUBLIC(QGamepad) |
46 | |
47 | public: |
48 | QGamepadPrivate(int deviceId) |
49 | : deviceId(deviceId) |
50 | , connected(false) |
51 | , axisLeftX(0.0) |
52 | , axisLeftY(0.0) |
53 | , axisRightX(0.0) |
54 | , axisRightY(0.0) |
55 | , buttonA(false) |
56 | , buttonB(false) |
57 | , buttonX(false) |
58 | , buttonY(false) |
59 | , buttonL1(false) |
60 | , buttonR1(false) |
61 | , buttonL2(0.0) |
62 | , buttonR2(0.0) |
63 | , buttonSelect(false) |
64 | , buttonStart(false) |
65 | , buttonL3(false) |
66 | , buttonR3(false) |
67 | , buttonUp(false) |
68 | , buttonDown(false) |
69 | , buttonLeft(false) |
70 | , buttonRight(false) |
71 | , buttonCenter(false) |
72 | , buttonGuide(false) |
73 | { |
74 | } |
75 | |
76 | QGamepadManager *gamepadManager; |
77 | |
78 | int deviceId; |
79 | bool connected; |
80 | QString name; |
81 | double axisLeftX; |
82 | double axisLeftY; |
83 | double axisRightX; |
84 | double axisRightY; |
85 | bool buttonA; |
86 | bool buttonB; |
87 | bool buttonX; |
88 | bool buttonY; |
89 | bool buttonL1; |
90 | bool buttonR1; |
91 | double buttonL2; |
92 | double buttonR2; |
93 | bool buttonSelect; |
94 | bool buttonStart; |
95 | bool buttonL3; |
96 | bool buttonR3; |
97 | bool buttonUp; |
98 | bool buttonDown; |
99 | bool buttonLeft; |
100 | bool buttonRight; |
101 | bool buttonCenter; |
102 | bool buttonGuide; |
103 | |
104 | void setConnected(bool isConnected); |
105 | void setName(const QString &name); |
106 | |
107 | void _q_handleGamepadConnected(int id); |
108 | void _q_handleGamepadNameChanged(int id, const QString &name); |
109 | void _q_handleGamepadDisconnected(int id); |
110 | void _q_handleGamepadAxisEvent(int id, QGamepadManager::GamepadAxis axis, double value); |
111 | void _q_handleGamepadButtonPressEvent(int id, QGamepadManager::GamepadButton button, double value); |
112 | void _q_handleGamepadButtonReleaseEvent(int id, QGamepadManager::GamepadButton button); |
113 | }; |
114 | |
115 | void QGamepadPrivate::setConnected(bool isConnected) |
116 | { |
117 | Q_Q(QGamepad); |
118 | if (connected != isConnected) { |
119 | connected = isConnected; |
120 | emit q->connectedChanged(value: connected); |
121 | } |
122 | } |
123 | |
124 | void QGamepadPrivate::setName(const QString &theName) |
125 | { |
126 | Q_Q(QGamepad); |
127 | if (name != theName) { |
128 | name = theName; |
129 | emit q->nameChanged(value: name); |
130 | } |
131 | } |
132 | |
133 | /*! |
134 | * \internal |
135 | */\ |
136 | void QGamepadPrivate::_q_handleGamepadConnected(int id) |
137 | { |
138 | if (id == deviceId) { |
139 | setConnected(true); |
140 | } |
141 | } |
142 | |
143 | /*! |
144 | * \internal |
145 | */\ |
146 | void QGamepadPrivate::_q_handleGamepadNameChanged(int id, const QString &name) |
147 | { |
148 | if (id == deviceId) |
149 | setName(name); |
150 | } |
151 | |
152 | /*! |
153 | * \internal |
154 | */\ |
155 | void QGamepadPrivate::_q_handleGamepadDisconnected(int id) |
156 | { |
157 | if (id == deviceId) { |
158 | setConnected(false); |
159 | } |
160 | } |
161 | |
162 | /*! |
163 | * \internal |
164 | */\ |
165 | void QGamepadPrivate::_q_handleGamepadAxisEvent(int id, QGamepadManager::GamepadAxis axis, double value) |
166 | { |
167 | Q_Q(QGamepad); |
168 | if (id != deviceId) |
169 | return; |
170 | |
171 | switch (axis) { |
172 | case QGamepadManager::AxisLeftX: |
173 | axisLeftX = value; |
174 | emit q->axisLeftXChanged(value); |
175 | break; |
176 | case QGamepadManager::AxisLeftY: |
177 | axisLeftY = value; |
178 | emit q->axisLeftYChanged(value); |
179 | break; |
180 | case QGamepadManager::AxisRightX: |
181 | axisRightX = value; |
182 | emit q->axisRightXChanged(value); |
183 | break; |
184 | case QGamepadManager::AxisRightY: |
185 | axisRightY = value; |
186 | emit q->axisRightYChanged(value); |
187 | break; |
188 | default: |
189 | break; |
190 | } |
191 | } |
192 | |
193 | /*! |
194 | * \internal |
195 | */\ |
196 | void QGamepadPrivate::_q_handleGamepadButtonPressEvent(int id, QGamepadManager::GamepadButton button, double value) |
197 | { |
198 | Q_Q(QGamepad); |
199 | if (id != deviceId) |
200 | return; |
201 | |
202 | switch (button) { |
203 | case QGamepadManager::ButtonA: |
204 | buttonA = true; |
205 | emit q->buttonAChanged(value: true); |
206 | break; |
207 | case QGamepadManager::ButtonB: |
208 | buttonB = true; |
209 | emit q->buttonBChanged(value: true); |
210 | break; |
211 | case QGamepadManager::ButtonX: |
212 | buttonX = true; |
213 | emit q->buttonXChanged(value: true); |
214 | break; |
215 | case QGamepadManager::ButtonY: |
216 | buttonY = true; |
217 | emit q->buttonYChanged(value: true); |
218 | break; |
219 | case QGamepadManager::ButtonL1: |
220 | buttonL1 = true; |
221 | emit q->buttonL1Changed(value: true); |
222 | break; |
223 | case QGamepadManager::ButtonR1: |
224 | buttonR1 = true; |
225 | emit q->buttonR1Changed(value: true); |
226 | break; |
227 | case QGamepadManager::ButtonL2: |
228 | buttonL2 = value; |
229 | emit q->buttonL2Changed(value); |
230 | break; |
231 | case QGamepadManager::ButtonR2: |
232 | buttonR2 = value; |
233 | emit q->buttonR2Changed(value); |
234 | break; |
235 | case QGamepadManager::ButtonL3: |
236 | buttonL3 = true; |
237 | emit q->buttonL3Changed(value: true); |
238 | break; |
239 | case QGamepadManager::ButtonR3: |
240 | buttonR3 = true; |
241 | emit q->buttonR3Changed(value: true); |
242 | break; |
243 | case QGamepadManager::ButtonSelect: |
244 | buttonSelect = true; |
245 | emit q->buttonSelectChanged(value: true); |
246 | break; |
247 | case QGamepadManager::ButtonStart: |
248 | buttonStart = true; |
249 | emit q->buttonStartChanged(value: true); |
250 | break; |
251 | case QGamepadManager::ButtonUp: |
252 | buttonUp = true; |
253 | emit q->buttonUpChanged(value: true); |
254 | break; |
255 | case QGamepadManager::ButtonDown: |
256 | buttonDown = true; |
257 | emit q->buttonDownChanged(value: true); |
258 | break; |
259 | case QGamepadManager::ButtonLeft: |
260 | buttonLeft = true; |
261 | emit q->buttonLeftChanged(value: true); |
262 | break; |
263 | case QGamepadManager::ButtonRight: |
264 | buttonRight = true; |
265 | emit q->buttonRightChanged(value: true); |
266 | break; |
267 | case QGamepadManager::ButtonCenter: |
268 | buttonCenter = true; |
269 | emit q->buttonCenterChanged(value: true); |
270 | break; |
271 | case QGamepadManager::ButtonGuide: |
272 | buttonGuide = true; |
273 | emit q->buttonGuideChanged(value: true); |
274 | break; |
275 | default: |
276 | break; |
277 | } |
278 | |
279 | } |
280 | |
281 | /*! |
282 | * \internal |
283 | */\ |
284 | void QGamepadPrivate::_q_handleGamepadButtonReleaseEvent(int id, QGamepadManager::GamepadButton button) |
285 | { |
286 | Q_Q(QGamepad); |
287 | if (id != deviceId) |
288 | return; |
289 | |
290 | switch (button) { |
291 | case QGamepadManager::ButtonA: |
292 | buttonA = false; |
293 | emit q->buttonAChanged(value: false); |
294 | break; |
295 | case QGamepadManager::ButtonB: |
296 | buttonB = false; |
297 | emit q->buttonBChanged(value: false); |
298 | break; |
299 | case QGamepadManager::ButtonX: |
300 | buttonX = false; |
301 | emit q->buttonXChanged(value: false); |
302 | break; |
303 | case QGamepadManager::ButtonY: |
304 | buttonY = false; |
305 | emit q->buttonYChanged(value: false); |
306 | break; |
307 | case QGamepadManager::ButtonL1: |
308 | buttonL1 = false; |
309 | emit q->buttonL1Changed(value: false); |
310 | break; |
311 | case QGamepadManager::ButtonR1: |
312 | buttonR1 = false; |
313 | emit q->buttonR1Changed(value: false); |
314 | break; |
315 | case QGamepadManager::ButtonL2: |
316 | buttonL2 = 0.0; |
317 | emit q->buttonL2Changed(value: 0.0); |
318 | break; |
319 | case QGamepadManager::ButtonR2: |
320 | buttonR2 = 0.0; |
321 | emit q->buttonR2Changed(value: 0.0); |
322 | break; |
323 | case QGamepadManager::ButtonL3: |
324 | buttonL3 = false; |
325 | emit q->buttonL3Changed(value: false); |
326 | break; |
327 | case QGamepadManager::ButtonR3: |
328 | buttonR3 = false; |
329 | emit q->buttonR3Changed(value: false); |
330 | break; |
331 | case QGamepadManager::ButtonSelect: |
332 | buttonSelect = false; |
333 | emit q->buttonSelectChanged(value: false); |
334 | break; |
335 | case QGamepadManager::ButtonStart: |
336 | buttonStart = false; |
337 | emit q->buttonStartChanged(value: false); |
338 | break; |
339 | case QGamepadManager::ButtonUp: |
340 | buttonUp = false; |
341 | emit q->buttonUpChanged(value: false); |
342 | break; |
343 | case QGamepadManager::ButtonDown: |
344 | buttonDown = false; |
345 | emit q->buttonDownChanged(value: false); |
346 | break; |
347 | case QGamepadManager::ButtonLeft: |
348 | buttonLeft = false; |
349 | emit q->buttonLeftChanged(value: false); |
350 | break; |
351 | case QGamepadManager::ButtonRight: |
352 | buttonRight = false; |
353 | emit q->buttonRightChanged(value: false); |
354 | break; |
355 | case QGamepadManager::ButtonCenter: |
356 | buttonCenter = false; |
357 | emit q->buttonCenterChanged(value: false); |
358 | break; |
359 | case QGamepadManager::ButtonGuide: |
360 | buttonGuide = false; |
361 | emit q->buttonGuideChanged(value: false); |
362 | break; |
363 | default: |
364 | break; |
365 | } |
366 | } |
367 | |
368 | /*! |
369 | \class QGamepad |
370 | \inmodule QtGamepad |
371 | \brief A gamepad device connected to a system. |
372 | |
373 | QGamepad is used to access the current state of gamepad hardware connected |
374 | to a system. |
375 | */ |
376 | |
377 | /*! |
378 | * \qmltype Gamepad |
379 | * \inqmlmodule QtGamepad |
380 | * \brief A gamepad device connected to a system. |
381 | * \instantiates QGamepad |
382 | * |
383 | * Gamepad QML type is used to access the current state of gamepad |
384 | * hardware connected to a system. |
385 | */ |
386 | |
387 | /*! |
388 | * Constructs a QGamepad with the given \a deviceId and \a parent. |
389 | */ |
390 | QGamepad::QGamepad(int deviceId, QObject *parent) |
391 | : QObject(*new QGamepadPrivate(deviceId), parent) |
392 | { |
393 | Q_D(QGamepad); |
394 | d->gamepadManager = QGamepadManager::instance(); |
395 | connect(sender: d->gamepadManager, SIGNAL(gamepadConnected(int)), receiver: this, SLOT(_q_handleGamepadConnected(int))); |
396 | connect(sender: d->gamepadManager, SIGNAL(gamepadNameChanged(int, QString)), receiver: this, SLOT(_q_handleGamepadNameChanged(int, QString))); |
397 | connect(sender: d->gamepadManager, SIGNAL(gamepadDisconnected(int)), receiver: this, SLOT(_q_handleGamepadDisconnected(int))); |
398 | connect(sender: d->gamepadManager, SIGNAL(gamepadAxisEvent(int,QGamepadManager::GamepadAxis,double)), receiver: this, SLOT(_q_handleGamepadAxisEvent(int,QGamepadManager::GamepadAxis,double))); |
399 | connect(sender: d->gamepadManager, SIGNAL(gamepadButtonPressEvent(int,QGamepadManager::GamepadButton,double)), receiver: this, SLOT(_q_handleGamepadButtonPressEvent(int,QGamepadManager::GamepadButton,double))); |
400 | connect(sender: d->gamepadManager, SIGNAL(gamepadButtonReleaseEvent(int,QGamepadManager::GamepadButton)), receiver: this, SLOT(_q_handleGamepadButtonReleaseEvent(int,QGamepadManager::GamepadButton))); |
401 | |
402 | d->setConnected(d->gamepadManager->isGamepadConnected(deviceId)); |
403 | d->setName(d->gamepadManager->gamepadName(deviceId)); |
404 | } |
405 | |
406 | QGamepad::~QGamepad() |
407 | { |
408 | } |
409 | |
410 | /*! |
411 | * \property QGamepad::deviceId |
412 | * |
413 | * This property holds the deviceId of the gamepad device. Multiple gamepad devices can be |
414 | * connected at any given time, so setting this property defines which gamepad to use. |
415 | * |
416 | * \sa QGamepadManager::connectedGamepads() |
417 | */ |
418 | /*! |
419 | * \qmlproperty int Gamepad::deviceId |
420 | * |
421 | * This property holds the deviceId of the gamepad device. Multiple gamepad devices can be |
422 | * connected at any given time, so setting this property defines which gamepad to use. |
423 | * |
424 | * \sa {GamepadManager::connectedGamepads}{GamepadManager.connectedGamepads} |
425 | */ |
426 | int QGamepad::deviceId() const |
427 | { |
428 | Q_D(const QGamepad); |
429 | return d->deviceId; |
430 | } |
431 | |
432 | /*! |
433 | * \property QGamepad::connected |
434 | * |
435 | * The connectivity state of the gamepad device. |
436 | * If a gamepad is connected, this property will be \c true, otherwise \c false. |
437 | */ |
438 | /*! |
439 | * \qmlproperty bool Gamepad::connected |
440 | * \readonly |
441 | * |
442 | * The connectivity state of the gamepad device. |
443 | * If a gamepad is connected, this property will be \c true, otherwise \c false. |
444 | */ |
445 | bool QGamepad::isConnected() const |
446 | { |
447 | Q_D(const QGamepad); |
448 | return d->connected; |
449 | } |
450 | |
451 | /*! |
452 | * \property QGamepad::name |
453 | * |
454 | * The reported name of the gamepad if one is available. |
455 | */ |
456 | /*! |
457 | * \qmlproperty string Gamepad::name |
458 | * \readonly |
459 | * |
460 | * The reported name of the gamepad if one is available. |
461 | */ |
462 | QString QGamepad::name() const |
463 | { |
464 | Q_D(const QGamepad); |
465 | return d->name; |
466 | } |
467 | |
468 | /*! |
469 | * \property QGamepad::axisLeftX |
470 | * |
471 | * The value of the left thumbstick's X axis. |
472 | * The axis values range from -1.0 to 1.0. |
473 | */ |
474 | /*! |
475 | * \qmlproperty double Gamepad::axisLeftX |
476 | * \readonly |
477 | * |
478 | * The value of the left thumbstick's X axis. |
479 | * The axis values range from -1.0 to 1.0. |
480 | */ |
481 | double QGamepad::axisLeftX() const |
482 | { |
483 | Q_D(const QGamepad); |
484 | return d->axisLeftX; |
485 | } |
486 | |
487 | /*! |
488 | * \property QGamepad::axisLeftY |
489 | * |
490 | * The value of the left thumbstick's Y axis. |
491 | * The axis values range from -1.0 to 1.0. |
492 | */ |
493 | /*! |
494 | * \qmlproperty double Gamepad::axisLeftY |
495 | * \readonly |
496 | * |
497 | * The value of the left thumbstick's Y axis. |
498 | * The axis values range from -1.0 to 1.0. |
499 | */ |
500 | double QGamepad::axisLeftY() const |
501 | { |
502 | Q_D(const QGamepad); |
503 | return d->axisLeftY; |
504 | } |
505 | |
506 | /*! |
507 | * \property QGamepad::axisRightX |
508 | * |
509 | * This value of the right thumbstick's X axis. |
510 | * The axis values range from -1.0 to 1.0. |
511 | */ |
512 | /*! |
513 | * \qmlproperty double Gamepad::axisRightX |
514 | * \readonly |
515 | * |
516 | * This value of the right thumbstick's X axis. |
517 | * The axis values range from -1.0 to 1.0. |
518 | */ |
519 | double QGamepad::axisRightX() const |
520 | { |
521 | Q_D(const QGamepad); |
522 | return d->axisRightX; |
523 | } |
524 | |
525 | /*! |
526 | * \property QGamepad::axisRightY |
527 | * |
528 | * This value of the right thumbstick's Y axis. |
529 | * The axis values range from -1.0 to 1.0. |
530 | */ |
531 | /*! |
532 | * \qmlproperty double Gamepad::axisRightY |
533 | * \readonly |
534 | * |
535 | * This value of the right thumbstick's Y axis. |
536 | * The axis values range from -1.0 to 1.0. |
537 | */ |
538 | double QGamepad::axisRightY() const |
539 | { |
540 | Q_D(const QGamepad); |
541 | return d->axisRightY; |
542 | } |
543 | |
544 | /*! |
545 | * \property QGamepad::buttonA |
546 | * |
547 | * The state of the A button. |
548 | * The value is \c true when pressed, and \c false when not pressed. |
549 | */ |
550 | /*! |
551 | * \qmlproperty bool Gamepad::buttonA |
552 | * \readonly |
553 | * |
554 | * The state of the A button. |
555 | * The value is \c true when pressed, and \c false when not pressed. |
556 | */ |
557 | bool QGamepad::buttonA() const |
558 | { |
559 | Q_D(const QGamepad); |
560 | return d->buttonA; |
561 | } |
562 | |
563 | /*! |
564 | * \property QGamepad::buttonB |
565 | * |
566 | * The state of the B button. |
567 | * The value is \c true when pressed, and \c false when not pressed. |
568 | */ |
569 | /*! |
570 | * \qmlproperty bool Gamepad::buttonB |
571 | * \readonly |
572 | * |
573 | * The state of the B button. |
574 | * The value is \c true when pressed, and \c false when not pressed. |
575 | */ |
576 | bool QGamepad::buttonB() const |
577 | { |
578 | Q_D(const QGamepad); |
579 | return d->buttonB; |
580 | } |
581 | |
582 | /*! |
583 | * \property QGamepad::buttonX |
584 | * |
585 | * The state of the X button. |
586 | * The value is \c true when pressed, and \c false when not pressed. |
587 | */ |
588 | /*! |
589 | * \qmlproperty bool Gamepad::buttonX |
590 | * \readonly |
591 | * |
592 | * The state of the X button. |
593 | * The value is \c true when pressed, and \c false when not pressed. |
594 | */ |
595 | bool QGamepad::buttonX() const |
596 | { |
597 | Q_D(const QGamepad); |
598 | return d->buttonX; |
599 | } |
600 | |
601 | /*! |
602 | * \property QGamepad::buttonY |
603 | * |
604 | * The state of the Y button. |
605 | * The value is \c true when pressed, and \c false when not pressed. |
606 | */ |
607 | /*! |
608 | * \qmlproperty bool Gamepad::buttonY |
609 | * \readonly |
610 | * |
611 | * The state of the Y button. |
612 | * The value is \c true when pressed, and \c false when not pressed. |
613 | */ |
614 | bool QGamepad::buttonY() const |
615 | { |
616 | Q_D(const QGamepad); |
617 | return d->buttonY; |
618 | } |
619 | |
620 | /*! |
621 | * \property QGamepad::buttonL1 |
622 | * |
623 | * The state of the left shoulder button. |
624 | * The value is \c true when pressed, and \c false when not pressed. |
625 | */ |
626 | /*! |
627 | * \qmlproperty bool Gamepad::buttonL1 |
628 | * \readonly |
629 | * |
630 | * The state of the left shoulder button. |
631 | * The value is \c true when pressed, and \c false when not pressed. |
632 | */ |
633 | bool QGamepad::buttonL1() const |
634 | { |
635 | Q_D(const QGamepad); |
636 | return d->buttonL1; |
637 | } |
638 | |
639 | /*! |
640 | * \property QGamepad::buttonR1 |
641 | * |
642 | * The state of the right shoulder button. |
643 | * The value is \c true when pressed, and \c false when not pressed. |
644 | */ |
645 | /*! |
646 | * \qmlproperty bool Gamepad::buttonR1 |
647 | * \readonly |
648 | * |
649 | * The state of the right shoulder button. |
650 | * The value is \c true when pressed, and \c false when not pressed. |
651 | */ |
652 | bool QGamepad::buttonR1() const |
653 | { |
654 | Q_D(const QGamepad); |
655 | return d->buttonR1; |
656 | } |
657 | |
658 | /*! |
659 | * \property QGamepad::buttonL2 |
660 | * |
661 | * The value of the left trigger button. |
662 | * This trigger value ranges from 0.0 when not pressed to 1.0 |
663 | * when pressed completely. |
664 | */ |
665 | /*! |
666 | * \qmlproperty double Gamepad::buttonL2 |
667 | * \readonly |
668 | * |
669 | * The value of the left trigger button. |
670 | * This trigger value ranges from 0.0 when not pressed to 1.0 |
671 | * when pressed completely. |
672 | */ |
673 | double QGamepad::buttonL2() const |
674 | { |
675 | Q_D(const QGamepad); |
676 | return d->buttonL2; |
677 | } |
678 | |
679 | /*! |
680 | * \property QGamepad::buttonR2 |
681 | * |
682 | * The value of the right trigger button. |
683 | * This trigger value ranges from 0.0 when not pressed to 1.0 |
684 | * when pressed completely. |
685 | */ |
686 | /*! |
687 | * \qmlproperty double Gamepad::buttonR2 |
688 | * \readonly |
689 | * |
690 | * The value of the right trigger button. |
691 | * This trigger value ranges from 0.0 when not pressed to 1.0 |
692 | * when pressed completely. |
693 | */ |
694 | double QGamepad::buttonR2() const |
695 | { |
696 | Q_D(const QGamepad); |
697 | return d->buttonR2; |
698 | } |
699 | |
700 | /*! |
701 | * \property QGamepad::buttonSelect |
702 | * |
703 | * The state of the Select button. |
704 | * The value is \c true when pressed, and \c false when not pressed. |
705 | * This button can sometimes be labeled as the Back button on some gamepads. |
706 | */ |
707 | /*! |
708 | * \qmlproperty bool Gamepad::buttonSelect |
709 | * \readonly |
710 | * |
711 | * The state of the Select button. |
712 | * The value is \c true when pressed, and \c false when not pressed. |
713 | * This button can sometimes be labeled as the Back button on some gamepads. |
714 | */ |
715 | bool QGamepad::buttonSelect() const |
716 | { |
717 | Q_D(const QGamepad); |
718 | return d->buttonSelect; |
719 | } |
720 | |
721 | /*! |
722 | * \property QGamepad::buttonStart |
723 | * |
724 | * The state of the Start button. |
725 | * The value is \c true when pressed, and \c false when not pressed. |
726 | * This button can sometimes be labeled as the Forward button on some gamepads. |
727 | */ |
728 | /*! |
729 | * \qmlproperty bool Gamepad::buttonStart |
730 | * \readonly |
731 | * |
732 | * The state of the Start button. |
733 | * The value is \c true when pressed, and \c false when not pressed. |
734 | * This button can sometimes be labeled as the Forward button on some gamepads. |
735 | */ |
736 | bool QGamepad::buttonStart() const |
737 | { |
738 | Q_D(const QGamepad); |
739 | return d->buttonStart; |
740 | } |
741 | |
742 | /*! |
743 | * \property QGamepad::buttonL3 |
744 | * |
745 | * The state of the left stick button. |
746 | * The value is \c true when pressed, and \c false when not pressed. |
747 | * This button is usually triggered by pressing the left joystick itself. |
748 | */ |
749 | /*! |
750 | * \qmlproperty bool Gamepad::buttonL3 |
751 | * \readonly |
752 | * |
753 | * The state of the left stick button. |
754 | * The value is \c true when pressed, and \c false when not pressed. |
755 | * This button is usually triggered by pressing the left joystick itself. |
756 | */ |
757 | bool QGamepad::buttonL3() const |
758 | { |
759 | Q_D(const QGamepad); |
760 | return d->buttonL3; |
761 | } |
762 | |
763 | /*! |
764 | * \property QGamepad::buttonR3 |
765 | * |
766 | * The state of the right stick button. |
767 | * The value is \c true when pressed, and \c false when not pressed. |
768 | * This button is usually triggered by pressing the right joystick itself. |
769 | */ |
770 | /*! |
771 | * \qmlproperty bool Gamepad::buttonR3 |
772 | * \readonly |
773 | * |
774 | * The state of the right stick button. |
775 | * The value is \c true when pressed, and \c false when not pressed. |
776 | * This button is usually triggered by pressing the right joystick itself. |
777 | */ |
778 | bool QGamepad::buttonR3() const |
779 | { |
780 | Q_D(const QGamepad); |
781 | return d->buttonR3; |
782 | } |
783 | |
784 | /*! |
785 | * \property QGamepad::buttonUp |
786 | * |
787 | * The state of the direction pad up button. |
788 | * The value is \c true when pressed, and \c false when not pressed. |
789 | */ |
790 | /*! |
791 | * \qmlproperty bool Gamepad::buttonUp |
792 | * \readonly |
793 | * |
794 | * The state of the direction pad up button. |
795 | * The value is \c true when pressed, and \c false when not pressed. |
796 | */ |
797 | bool QGamepad::buttonUp() const |
798 | { |
799 | Q_D(const QGamepad); |
800 | return d->buttonUp; |
801 | } |
802 | |
803 | /*! |
804 | * \property QGamepad::buttonDown |
805 | * |
806 | * The state of the direction pad down button. |
807 | * The value is \c true when pressed, and \c false when not pressed. |
808 | */ |
809 | /*! |
810 | * \qmlproperty bool Gamepad::buttonDown |
811 | * \readonly |
812 | * |
813 | * The state of the direction pad down button. |
814 | * The value is \c true when pressed, and \c false when not pressed. |
815 | */ |
816 | bool QGamepad::buttonDown() const |
817 | { |
818 | Q_D(const QGamepad); |
819 | return d->buttonDown; |
820 | } |
821 | |
822 | /*! |
823 | * \property QGamepad::buttonLeft |
824 | * |
825 | * The state of the direction pad left button. |
826 | * The value is \c true when pressed, and \c false when not pressed. |
827 | */ |
828 | /*! |
829 | * \qmlproperty bool Gamepad::buttonLeft |
830 | * \readonly |
831 | * |
832 | * The state of the direction pad left button. |
833 | * The value is \c true when pressed, and \c false when not pressed. |
834 | */ |
835 | bool QGamepad::buttonLeft() const |
836 | { |
837 | Q_D(const QGamepad); |
838 | return d->buttonLeft; |
839 | } |
840 | |
841 | /*! |
842 | * \property QGamepad::buttonRight |
843 | * |
844 | * The state of the direction pad right button. |
845 | * The value is \c true when pressed, and \c false when not pressed. |
846 | */ |
847 | /*! |
848 | * \qmlproperty bool Gamepad::buttonRight |
849 | * \readonly |
850 | * |
851 | * The state of the direction pad right button. |
852 | * The value is \c true when pressed, and \c false when not pressed. |
853 | */ |
854 | bool QGamepad::buttonRight() const |
855 | { |
856 | Q_D(const QGamepad); |
857 | return d->buttonRight; |
858 | } |
859 | |
860 | /*! |
861 | * \property QGamepad::buttonCenter |
862 | * |
863 | * The state of the center button. |
864 | * The value is \c true when pressed, and \c false when not pressed. |
865 | */ |
866 | /* |
867 | * \qmlproperty bool Gamepad::buttonCenter |
868 | * \readonly |
869 | * |
870 | * The state of the center button. |
871 | * The value is \c true when pressed, and \c false when not pressed. |
872 | */ |
873 | bool QGamepad::buttonCenter() const |
874 | { |
875 | Q_D(const QGamepad); |
876 | return d->buttonCenter; |
877 | } |
878 | |
879 | /*! |
880 | * \property QGamepad::buttonGuide |
881 | * |
882 | * The state of the guide button. |
883 | * The value is \c true when pressed, and \c false when not pressed. |
884 | * This button is typically the one in the center of the gamepad with a logo. |
885 | * Not all gamepads have a guide button. |
886 | */ |
887 | /* |
888 | * \qmlproperty bool Gamepad::buttonGuide |
889 | * \readonly |
890 | * |
891 | * The state of the guide button. |
892 | * The value is \c true when pressed, and \c false when not pressed. |
893 | * This button is typically the one in the center of the gamepad with a logo. |
894 | * Not all gamepads have a guide button. |
895 | */ |
896 | |
897 | bool QGamepad::buttonGuide() const |
898 | { |
899 | Q_D(const QGamepad); |
900 | return d->buttonGuide; |
901 | } |
902 | |
903 | void QGamepad::setDeviceId(int number) |
904 | { |
905 | Q_D(QGamepad); |
906 | if (d->deviceId != number) { |
907 | d->deviceId = number; |
908 | emit deviceIdChanged(value: number); |
909 | d->setConnected(d->gamepadManager->isGamepadConnected(deviceId: d->deviceId)); |
910 | } |
911 | } |
912 | |
913 | QT_END_NAMESPACE |
914 | |
915 | #include "moc_qgamepad.cpp" |
916 | |