QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
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}
65
66QgsGamepad2DMapController *QgsGamepad2DMapController::clone() const
67{
68 return new QgsGamepad2DMapController( mGamepadDeviceId );
69}
70
71QString QgsGamepad2DMapController::deviceId() const
72{
73 return QStringLiteral( "gamepad2d:%1" ).arg( mGamepadDeviceId );
74}
75
76bool QgsGamepad2DMapController::isConnected() const
77{
78 return mGamepad->isConnected();
79}
80
81QString QgsGamepad2DMapController::name() const
82{
83 return mGamepad->name();
84}
85
86double QgsGamepad2DMapController::axisLeftX() const
87{
88 return mGamepad->axisLeftX();
89}
90
91double QgsGamepad2DMapController::axisLeftY() const
92{
93 return mGamepad->axisLeftY();
94}
95
96double QgsGamepad2DMapController::axisRightX() const
97{
98 return mGamepad->axisRightX();
99}
100
101double QgsGamepad2DMapController::axisRightY() const
102{
103 return mGamepad->axisRightY();
104}
105
106bool QgsGamepad2DMapController::buttonA() const
107{
108 return mGamepad->buttonA();
109}
110
111bool QgsGamepad2DMapController::buttonB() const
112{
113 return mGamepad->buttonB();
114}
115
116bool QgsGamepad2DMapController::buttonX() const
117{
118 return mGamepad->buttonX();
119}
120
121bool QgsGamepad2DMapController::buttonY() const
122{
123 return mGamepad->buttonY();
124}
125
126bool QgsGamepad2DMapController::buttonL1() const
127{
128 return mGamepad->buttonL1();
129}
130
131bool QgsGamepad2DMapController::buttonR1() const
132{
133 return mGamepad->buttonR1();
134}
135
136double QgsGamepad2DMapController::buttonL2() const
137{
138 return mGamepad->buttonL2();
139}
140
141double QgsGamepad2DMapController::buttonR2() const
142{
143 return mGamepad->buttonR2();
144}
145
146bool QgsGamepad2DMapController::buttonSelect() const
147{
148 return mGamepad->buttonSelect();
149}
150
151bool QgsGamepad2DMapController::buttonStart() const
152{
153 return mGamepad->buttonStart();
154}
155
156bool QgsGamepad2DMapController::buttonL3() const
157{
158 return mGamepad->buttonL3();
159}
160
161bool QgsGamepad2DMapController::buttonR3() const
162{
163 return mGamepad->buttonR3();
164}
165
166bool QgsGamepad2DMapController::buttonUp() const
167{
168 return mGamepad->buttonUp();
169}
170
171bool QgsGamepad2DMapController::buttonDown() const
172{
173 return mGamepad->buttonDown();
174}
175
176bool QgsGamepad2DMapController::buttonLeft() const
177{
178 return mGamepad->buttonLeft();
179}
180
181bool QgsGamepad2DMapController::buttonRight() const
182{
183 return mGamepad->buttonRight();
184}
185
186bool QgsGamepad2DMapController::buttonCenter() const
187{
188 return mGamepad->buttonCenter();
189}
190
191bool QgsGamepad2DMapController::buttonGuide() const
192{
193 return mGamepad->buttonGuide();
194}
195
196#endif
Abstract base class for all 2D map controllers.