16 #include <QGuiApplication>
17 #include <QMainWindow>
23 m_appInterface(appInterface),
24 m_gamepadInput(nullptr),
26 m_actionEnable(nullptr) {
54 if (!m_gamepadInput) {
60 for (
int step = 0; step < 1; ++step)
62 QGamepadManager* manager = QGamepadManager::instance();
64 showMessage(
"[Gamepad] Manager is not accessible?!", silent);
70 CVLog::Print(
"[Gamepad] Looking for connected gamepads...");
72 for (
int i = 0; i < 3; ++i) {
73 QGuiApplication::processEvents();
74 gamepads = manager->connectedGamepads();
75 if (!gamepads.empty()) {
80 if (gamepads.empty()) {
81 showMessage(
"[Gamepad] No device registered", silent);
86 .arg(gamepads.size()));
88 deviceID = gamepads.front();
89 if (!silent && gamepads.size() > 1) {
92 "Gamepad",
"Connected gamepads",
95 for (
int id : gamepads) {
96 QString
name = QGamepad(
id).name();
98 name = QString(
"Gamepad #%1").arg(
id);
102 if (!poeDlg.exec()) {
109 m_gamepadInput->
stop();
110 m_gamepadInput->setDeviceId(deviceID);
112 if (m_gamepadInput->isConnected()) {
113 CVLog::Print(QString(
"[Gamepad] Device %1 is now enabled")
115 m_gamepadInput->
start();
118 showMessage(QString(
"[Gamepad] Device %1 is not connected")
125 }
else if (m_gamepadInput) {
126 if (deviceID >= 0 && m_gamepadInput->deviceId() != deviceID) {
130 m_gamepadInput->
stop();
132 .arg(m_gamepadInput->deviceId()));
135 m_actionEnable->blockSignals(
true);
136 m_actionEnable->setChecked(state);
137 m_actionEnable->blockSignals(
false);
141 if (m_gamepadInput ==
nullptr)
return;
143 m_gamepadInput->
stop();
144 m_gamepadInput->disconnect(
this);
146 delete m_gamepadInput;
147 m_gamepadInput =
nullptr;
151 if (m_gamepadInput) {
161 connect(m_gamepadInput, &GamepadInput::buttonL1Changed,
this,
163 connect(m_gamepadInput, &GamepadInput::buttonR1Changed,
this,
166 connect(m_gamepadInput, &GamepadInput::buttonStartChanged,
this,
172 connect(m_gamepadInput, &GamepadInput::buttonAChanged,
this,
178 connect(m_gamepadInput, &GamepadInput::buttonBChanged,
this,
185 QGamepadManager* manager = QGamepadManager::instance();
187 connect(manager, &QGamepadManager::gamepadConnected,
this,
189 CVLog::Print(QString(
"gamepad device %1 has been connected")
192 if (m_actionEnable && !m_actionEnable->isChecked()) {
197 connect(manager, &QGamepadManager::gamepadDisconnected,
this,
200 QString(
"gamepad device %1 has been disconnected")
204 if (m_actionEnable && m_actionEnable->isChecked() &&
206 m_gamepadInput->deviceId() == deviceId) {
212 showMessage(
"[Gamepad] Manager is not accessible?!",
true);
218 m_menu =
new QMenu(
"Gamepad");
219 m_menu->setIcon(QIcon(
":/CC/images/gamepad.png"));
222 if (!m_actionEnable) {
223 m_actionEnable =
new QAction(tr(
"Enable"),
this);
224 m_actionEnable->setCheckable(
true);
226 connect(m_actionEnable, &QAction::toggled,
229 m_menu->addAction(m_actionEnable);
234 assert(m_gamepadInput);
238 m_gamepadInput->
update(win);
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
static bool Print(const char *format,...)
Prints out a formatted message in console.
static bool Error(const char *format,...)
Display an error dialog with formatted message.
void enableDevice(bool state, bool silent, int deviceID=-1)
ccGamepadManager(ecvMainAppInterface *appInterface, QObject *parent)
void showMessage(QString message, bool asWarning)
Minimal dialog to pick one element in a list (combox box)
void addElement(const QString &elementName)
Add an element to the combo box.
int getSelectedIndex()
Returns the combo box current index (after completion)
Main application interface (for plugins)
virtual void toggleActiveWindowCenteredPerspective()=0
virtual void setGlobalZoom()=0
virtual QMainWindow * getMainWindow()=0
Returns main window.
virtual void decreasePointSize()=0
virtual void increasePointSize()=0
virtual void toggleActiveWindowViewerBasedPerspective()=0