QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgs2dgamepadcontroller.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgs2dgamepadcontroller.cpp
3 ---------------------
4 begin : March 2023
5 copyright : (C) 2023 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17#include "moc_qgs2dgamepadcontroller.cpp"
18
19#ifdef HAVE_QTGAMEPAD
20
21#include <QtGamepad/QGamepad>
22
23QgsGamepad2DMapController::QgsGamepad2DMapController( int gamepadDeviceId, QObject *parent )
25 , mGamepadDeviceId( gamepadDeviceId )
26{
27 mGamepad = new QGamepad( gamepadDeviceId, this );
28
29 // proxy raw signals for interested PyQGIS
30 connect( mGamepad, &QGamepad::connectedChanged, this, &QgsGamepad2DMapController::connectedChanged );
31 connect( mGamepad, &QGamepad::axisLeftXChanged, this, &QgsGamepad2DMapController::axisLeftXChanged );
32 connect( mGamepad, &QGamepad::axisLeftYChanged, this, &QgsGamepad2DMapController::axisLeftYChanged );
33 connect( mGamepad, &QGamepad::axisRightXChanged, this, &QgsGamepad2DMapController::axisRightXChanged );
34 connect( mGamepad, &QGamepad::axisRightYChanged, this, &QgsGamepad2DMapController::axisRightYChanged );
35 connect( mGamepad, &QGamepad::buttonAChanged, this, &QgsGamepad2DMapController::buttonAChanged );
36 connect( mGamepad, &QGamepad::buttonBChanged, this, &QgsGamepad2DMapController::buttonBChanged );
37 connect( mGamepad, &QGamepad::buttonXChanged, this, &QgsGamepad2DMapController::buttonXChanged );
38 connect( mGamepad, &QGamepad::buttonYChanged, this, &QgsGamepad2DMapController::buttonYChanged );
39 connect( mGamepad, &QGamepad::buttonL1Changed, this, &QgsGamepad2DMapController::buttonL1Changed );
40 connect( mGamepad, &QGamepad::buttonR1Changed, this, &QgsGamepad2DMapController::buttonR1Changed );
41 connect( mGamepad, &QGamepad::buttonL2Changed, this, &QgsGamepad2DMapController::buttonL2Changed );
42 connect( mGamepad, &QGamepad::buttonR2Changed, this, &QgsGamepad2DMapController::buttonR2Changed );
43 connect( mGamepad, &QGamepad::buttonSelectChanged, this, &QgsGamepad2DMapController::buttonSelectChanged );
44 connect( mGamepad, &QGamepad::buttonStartChanged, this, &QgsGamepad2DMapController::buttonStartChanged );
45 connect( mGamepad, &QGamepad::buttonL3Changed, this, &QgsGamepad2DMapController::buttonL3Changed );
46 connect( mGamepad, &QGamepad::buttonR3Changed, this, &QgsGamepad2DMapController::buttonR3Changed );
47 connect( mGamepad, &QGamepad::buttonUpChanged, this, &QgsGamepad2DMapController::buttonUpChanged );
48 connect( mGamepad, &QGamepad::buttonDownChanged, this, &QgsGamepad2DMapController::buttonDownChanged );
49 connect( mGamepad, &QGamepad::buttonLeftChanged, this, &QgsGamepad2DMapController::buttonLeftChanged );
50 connect( mGamepad, &QGamepad::buttonRightChanged, this, &QgsGamepad2DMapController::buttonRightChanged );
51 connect( mGamepad, &QGamepad::buttonCenterChanged, this, &QgsGamepad2DMapController::buttonCenterChanged );
52 connect( mGamepad, &QGamepad::buttonGuideChanged, this, &QgsGamepad2DMapController::buttonGuideChanged );
53
54 // also here we would make connections to the 2D map controller signals like zoomMap, depending on some
55 // reasonable defaults and user defined QSettings
56#if 0
57 connect( mGamepad, &QGamepad::axisRightYChanged, this, [ = ]( double value )
58 {
59 // actually should be on a timer ;)
60 emit zoomMap( value + 1 );
61 } );
62#endif
63}
64
65QgsGamepad2DMapController *QgsGamepad2DMapController::clone() const
66{
67 return new QgsGamepad2DMapController( mGamepadDeviceId );
68}
69
70QString QgsGamepad2DMapController::deviceId() const
71{
72 return QStringLiteral( "gamepad2d:%1" ).arg( mGamepadDeviceId );
73}
74
75bool QgsGamepad2DMapController::isConnected() const
76{
77 return mGamepad->isConnected();
78}
79
80QString QgsGamepad2DMapController::name() const
81{
82 return mGamepad->name();
83}
84
85double QgsGamepad2DMapController::axisLeftX() const
86{
87 return mGamepad->axisLeftX();
88}
89
90double QgsGamepad2DMapController::axisLeftY() const
91{
92 return mGamepad->axisLeftY();
93}
94
95double QgsGamepad2DMapController::axisRightX() const
96{
97 return mGamepad->axisRightX();
98}
99
100double QgsGamepad2DMapController::axisRightY() const
101{
102 return mGamepad->axisRightY();
103}
104
105bool QgsGamepad2DMapController::buttonA() const
106{
107 return mGamepad->buttonA();
108}
109
110bool QgsGamepad2DMapController::buttonB() const
111{
112 return mGamepad->buttonB();
113}
114
115bool QgsGamepad2DMapController::buttonX() const
116{
117 return mGamepad->buttonX();
118}
119
120bool QgsGamepad2DMapController::buttonY() const
121{
122 return mGamepad->buttonY();
123}
124
125bool QgsGamepad2DMapController::buttonL1() const
126{
127 return mGamepad->buttonL1();
128}
129
130bool QgsGamepad2DMapController::buttonR1() const
131{
132 return mGamepad->buttonR1();
133}
134
135double QgsGamepad2DMapController::buttonL2() const
136{
137 return mGamepad->buttonL2();
138}
139
140double QgsGamepad2DMapController::buttonR2() const
141{
142 return mGamepad->buttonR2();
143}
144
145bool QgsGamepad2DMapController::buttonSelect() const
146{
147 return mGamepad->buttonSelect();
148}
149
150bool QgsGamepad2DMapController::buttonStart() const
151{
152 return mGamepad->buttonStart();
153}
154
155bool QgsGamepad2DMapController::buttonL3() const
156{
157 return mGamepad->buttonL3();
158}
159
160bool QgsGamepad2DMapController::buttonR3() const
161{
162 return mGamepad->buttonR3();
163}
164
165bool QgsGamepad2DMapController::buttonUp() const
166{
167 return mGamepad->buttonUp();
168}
169
170bool QgsGamepad2DMapController::buttonDown() const
171{
172 return mGamepad->buttonDown();
173}
174
175bool QgsGamepad2DMapController::buttonLeft() const
176{
177 return mGamepad->buttonLeft();
178}
179
180bool QgsGamepad2DMapController::buttonRight() const
181{
182 return mGamepad->buttonRight();
183}
184
185bool QgsGamepad2DMapController::buttonCenter() const
186{
187 return mGamepad->buttonCenter();
188}
189
190bool QgsGamepad2DMapController::buttonGuide() const
191{
192 return mGamepad->buttonGuide();
193}
194
195#endif
Abstract base class for all 2D map controllers.