QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
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
18#ifdef HAVE_QTGAMEPAD
19
20#include <QtGamepad/QGamepad>
21
22QgsGamepad2DMapController::QgsGamepad2DMapController( int gamepadDeviceId, QObject *parent )
24 , mGamepadDeviceId( gamepadDeviceId )
25{
26 mGamepad = new QGamepad( gamepadDeviceId, this );
27
28 // proxy raw signals for interested PyQGIS
29 connect( mGamepad, &QGamepad::connectedChanged, this, &QgsGamepad2DMapController::connectedChanged );
30 connect( mGamepad, &QGamepad::axisLeftXChanged, this, &QgsGamepad2DMapController::axisLeftXChanged );
31 connect( mGamepad, &QGamepad::axisLeftYChanged, this, &QgsGamepad2DMapController::axisLeftYChanged );
32 connect( mGamepad, &QGamepad::axisRightXChanged, this, &QgsGamepad2DMapController::axisRightXChanged );
33 connect( mGamepad, &QGamepad::axisRightYChanged, this, &QgsGamepad2DMapController::axisRightYChanged );
34 connect( mGamepad, &QGamepad::buttonAChanged, this, &QgsGamepad2DMapController::buttonAChanged );
35 connect( mGamepad, &QGamepad::buttonBChanged, this, &QgsGamepad2DMapController::buttonBChanged );
36 connect( mGamepad, &QGamepad::buttonXChanged, this, &QgsGamepad2DMapController::buttonXChanged );
37 connect( mGamepad, &QGamepad::buttonYChanged, this, &QgsGamepad2DMapController::buttonYChanged );
38 connect( mGamepad, &QGamepad::buttonL1Changed, this, &QgsGamepad2DMapController::buttonL1Changed );
39 connect( mGamepad, &QGamepad::buttonR1Changed, this, &QgsGamepad2DMapController::buttonR1Changed );
40 connect( mGamepad, &QGamepad::buttonL2Changed, this, &QgsGamepad2DMapController::buttonL2Changed );
41 connect( mGamepad, &QGamepad::buttonR2Changed, this, &QgsGamepad2DMapController::buttonR2Changed );
42 connect( mGamepad, &QGamepad::buttonSelectChanged, this, &QgsGamepad2DMapController::buttonSelectChanged );
43 connect( mGamepad, &QGamepad::buttonStartChanged, this, &QgsGamepad2DMapController::buttonStartChanged );
44 connect( mGamepad, &QGamepad::buttonL3Changed, this, &QgsGamepad2DMapController::buttonL3Changed );
45 connect( mGamepad, &QGamepad::buttonR3Changed, this, &QgsGamepad2DMapController::buttonR3Changed );
46 connect( mGamepad, &QGamepad::buttonUpChanged, this, &QgsGamepad2DMapController::buttonUpChanged );
47 connect( mGamepad, &QGamepad::buttonDownChanged, this, &QgsGamepad2DMapController::buttonDownChanged );
48 connect( mGamepad, &QGamepad::buttonLeftChanged, this, &QgsGamepad2DMapController::buttonLeftChanged );
49 connect( mGamepad, &QGamepad::buttonRightChanged, this, &QgsGamepad2DMapController::buttonRightChanged );
50 connect( mGamepad, &QGamepad::buttonCenterChanged, this, &QgsGamepad2DMapController::buttonCenterChanged );
51 connect( mGamepad, &QGamepad::buttonGuideChanged, this, &QgsGamepad2DMapController::buttonGuideChanged );
52
53 // also here we would make connections to the 2D map controller signals like zoomMap, depending on some
54 // reasonable defaults and user defined QSettings
55#if 0
56 connect( mGamepad, &QGamepad::axisRightYChanged, this, [ = ]( double value )
57 {
58 // actually should be on a timer ;)
59 emit zoomMap( value + 1 );
60 } );
61#endif
62
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.