aboutsummaryrefslogtreecommitdiffstats
path: root/src/gamepad
diff options
context:
space:
mode:
authorJohan Solbakken <johan.hvaler@gmail.com>2023-08-15 12:25:56 +0200
committerAndy Nichols <nezticle@gmail.com>2024-06-09 19:22:21 +0200
commit39bbb8049f5d56eaf611e6dfa9db64cd70616137 (patch)
treebc50e1e24d983f6c369a82e3a7012dc6dcefe1b4 /src/gamepad
parent1712e01fb1564705338532ae14a77acda8acd5cb (diff)
Expand scope of QtGamepad to QtUniversalInputHEADdev
This patch transforms the QtGamepad module from Qt 5 into a new module that expands the scope to include all forms of exotic input. The majority of the previous QtGamepad functionality and APIs are preserved, but now there is also a more general API for getting the state of input devices like joysticks, flight yokes, and any other devices that define themselves in terms of buttons and axes. In addition to being able to receive input, it is also now possible to output feedback in devices that support it. Experimental input mapping functionality has been added to facilitate mapping an arbitrary input to a predefined action. Change-Id: Ic35b73282944cfd4eea9defbcf82c4abc55d7237 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src/gamepad')
-rw-r--r--src/gamepad/CMakeLists.txt20
-rw-r--r--src/gamepad/configure.json41
-rw-r--r--src/gamepad/doc/qtgamepad.qdocconf55
-rw-r--r--src/gamepad/doc/src/qtgamepad-cpp.qdoc50
-rw-r--r--src/gamepad/doc/src/qtgamepad-examples.qdoc36
-rw-r--r--src/gamepad/doc/src/qtgamepad-index.qdoc178
-rw-r--r--src/gamepad/doc/src/qtgamepad-qmltypes.qdoc52
-rw-r--r--src/gamepad/gamepad.pro36
-rw-r--r--src/gamepad/qgamepad.cpp430
-rw-r--r--src/gamepad/qgamepad.h129
-rw-r--r--src/gamepad/qgamepadbackend.cpp114
-rw-r--r--src/gamepad/qgamepadbackend_p.h118
-rw-r--r--src/gamepad/qgamepadbackendfactory.cpp60
-rw-r--r--src/gamepad/qgamepadbackendfactory_p.h68
-rw-r--r--src/gamepad/qgamepadbackendplugin.cpp52
-rw-r--r--src/gamepad/qgamepadbackendplugin_p.h79
-rw-r--r--src/gamepad/qgamepadkeynavigation.cpp584
-rw-r--r--src/gamepad/qgamepadkeynavigation.h150
-rw-r--r--src/gamepad/qgamepadmanager.cpp308
-rw-r--r--src/gamepad/qgamepadmanager.h135
-rw-r--r--src/gamepad/qtgamepadglobal.h58
21 files changed, 182 insertions, 2571 deletions
diff --git a/src/gamepad/CMakeLists.txt b/src/gamepad/CMakeLists.txt
new file mode 100644
index 0000000..aed9930
--- /dev/null
+++ b/src/gamepad/CMakeLists.txt
@@ -0,0 +1,20 @@
+# Copyright (C) 2024 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+qt_internal_add_module(Gamepad
+ SOURCES
+ qgamepad.cpp qgamepad.h
+ DEFINES
+ QT_BUILD_GAMEPAD_LIB
+ LIBRARIES
+ Qt::CorePrivate
+ Qt::GuiPrivate
+ PUBLIC_LIBRARIES
+ Qt::Core
+ Qt::Gui
+ Qt::UniversalInput
+ PRIVATE_MODULE_INTERFACE
+ Qt::CorePrivate
+ Qt::GuiPrivate
+ GENERATE_CPP_EXPORTS
+)
diff --git a/src/gamepad/configure.json b/src/gamepad/configure.json
deleted file mode 100644
index fef25d3..0000000
--- a/src/gamepad/configure.json
+++ /dev/null
@@ -1,41 +0,0 @@
-{
- "module": "gamepad",
- "testDir": "../../config.tests",
-
- "libraries": {
- "sdl2": {
- "label": "SDL2",
- "test": "sdl",
- "sources": [
- { "type": "pkgConfig", "args": "sdl2" },
- {
- "libs": "-F/Library/Frameworks/ -framework SDL2",
- "includedir": "/Library/Frameworks/SDL2.framework/Headers",
- "condition": "config.darwin"
- },
- { "libs": "-lSDL2 -lSDL2main", "condition": "config.win32" },
- { "libs": "-lSDL2", "condition": "config.unix && !config.darwin" }
- ]
- }
- },
-
- "features": {
- "sdl2": {
- "label": "SDL2",
- "condition": "libs.sdl2",
- "output": [ "privateFeature" ]
- }
- },
-
- "report": [
- ],
-
- "summary": [
- {
- "section": "Qt Gamepad",
- "entries": [
- "sdl2"
- ]
- }
- ]
-}
diff --git a/src/gamepad/doc/qtgamepad.qdocconf b/src/gamepad/doc/qtgamepad.qdocconf
deleted file mode 100644
index db7f3b5..0000000
--- a/src/gamepad/doc/qtgamepad.qdocconf
+++ /dev/null
@@ -1,55 +0,0 @@
-include($QT_INSTALL_DOCS/global/qt-module-defaults.qdocconf)
-include($QT_INSTALL_DOCS/config/exampleurl-qtgamepad.qdocconf)
-
-project = QtGamepad
-description = Qt Gamepad Reference Documentation
-version = $QT_VERSION
-
-examplesinstallpath = gamepad
-
-qhp.projects = QtGamepad
-
-qhp.QtGamepad.file = qtgamepad.qhp
-qhp.QtGamepad.namespace = org.qt-project.qtgamepad.$QT_VERSION_TAG
-qhp.QtGamepad.virtualFolder = qtgamepad
-qhp.QtGamepad.indexTitle = Qt Gamepad
-qhp.QtGamepad.indexRoot =
-qhp.QtGamepad.filterAttributes = qtgamepad $QT_VERSION qtrefdoc
-qhp.QtGamepad.customFilters.Qt.name = QtGamepad $QT_VERSION
-qhp.QtGamepad.customFilters.Qt.filterAttributes = qtgamepad $QT_VERSION
-
-qhp.QtGamepad.subprojects = qmltypes classes examples
-qhp.QtGamepad.subprojects.qmltypes.title = QML Types
-qhp.QtGamepad.subprojects.qmltypes.indexTitle = Qt Gamepad QML Types
-qhp.QtGamepad.subprojects.qmltypes.selectors = qmlclass
-qhp.QtGamepad.subprojects.qmltypes.sortPages = true
-qhp.QtGamepad.subprojects.classes.title = C++ Classes
-qhp.QtGamepad.subprojects.classes.indexTitle = Qt Gamepad C++ Classes
-qhp.QtGamepad.subprojects.classes.selectors = class fake:headerfile
-qhp.QtGamepad.subprojects.classes.sortPages = true
-qhp.QtGamepad.subprojects.examples.title = Examples
-qhp.QtGamepad.subprojects.examples.indexTitle = Qt Gamepad Examples
-qhp.QtGamepad.subprojects.examples.selectors = fake:example
-qhp.QtGamepad.subprojects.examples.sortPages = true
-
-depends = qtcore qtdoc qmake
-
-headerdirs += ../ \
- ../../plugins
-
-sourcedirs += ../ \
- ../../plugins
-
-exampledirs += ../../../examples/gamepad
-
-imagedirs += images
-
-Cpp.ignoretokens += Q_GAMEPAD_EXPORT
-Cpp.ignoredirectives += Q_DECLARE_LOGGING_CATEGORY
-
-navigation.landingpage = "Qt Gamepad"
-navigation.qmltypespage = "Qt Gamepad QML Types"
-navigation.cppclassespage = "Qt Gamepad C++ Classes"
-
-manifestmeta.thumbnail.names = "QtGamepad/Qt Gamepad Mouse Item Example" \
- "QtGamepad/Qt Gamepad Simple Example"
diff --git a/src/gamepad/doc/src/qtgamepad-cpp.qdoc b/src/gamepad/doc/src/qtgamepad-cpp.qdoc
deleted file mode 100644
index 7e90ed7..0000000
--- a/src/gamepad/doc/src/qtgamepad-cpp.qdoc
+++ /dev/null
@@ -1,50 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*!
- \module QtGamepad
- \title Qt Gamepad C++ Classes
- \ingroup modules
- \qtvariable gamepad
-
- \brief Provides C++ classes for using gamepads.
-
- To include the definitions of the module's classes, use the following directive:
-
- \code
- #include <QtGamepad>
- \endcode
-
- To link against the module, add this line to your \l qmake \c .pro file:
-
- \code
- QT += gamepad
- \endcode
-
- For more information about using these classes in your application,
- see the \l{Qt Gamepad} documentation.
-*/
diff --git a/src/gamepad/doc/src/qtgamepad-examples.qdoc b/src/gamepad/doc/src/qtgamepad-examples.qdoc
deleted file mode 100644
index e9a677e..0000000
--- a/src/gamepad/doc/src/qtgamepad-examples.qdoc
+++ /dev/null
@@ -1,36 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*!
- \group qtgamepad-examples
- \title Qt Gamepad Examples
- \brief Examples for the Qt Gamepad module
-
- These are the Qt Gamepad examples.
-
-*/
-
diff --git a/src/gamepad/doc/src/qtgamepad-index.qdoc b/src/gamepad/doc/src/qtgamepad-index.qdoc
deleted file mode 100644
index 146cb49..0000000
--- a/src/gamepad/doc/src/qtgamepad-index.qdoc
+++ /dev/null
@@ -1,178 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*!
- \page qtgamepad-index.html
- \title Qt Gamepad
- \brief A cross-platform library to facilitate the use of gamepad hardware in Qt and Qt Quick applications.
-
- Qt Gamepad is an add-on library that enables Qt applications to support the
- use of gamepad hardware and in some cases remote control equipment. The
- module provides both QML and C++ interfaces. The primary target audience are
- embedded devices with fullscreen user interfaces, and mobile applications
- targeting TV-like form factors.
-
- The currently supported platforms are:
-
- \list
- \li Windows (Win32 desktop, via XInput 1.3 & 1.4)
- \li Linux (evdev)
- \li Linux (SDL2)
- \li Android
- \li macOS, iOS, tvOS (including the tvOS remote)
- \endlist
-
- This module provides classes that can:
-
- \list
- \li Read input events from game controllers (Button and Axis events),
- \li expose these events both to C++ and Qt Quick (QML),
- \li provide basic gamepad layout configurability, and
- \li provide optional key and mouse event generation upon gamepad button presses.
- \endlist
-
- \note The API is designed with XBox and similar controllers in mind. Joysticks
- are not in scope for this module. A number of third-party gamepads may be
- supported as well, however, some of these may need custom configuration steps
- in order to map the button/trigger codes the device or driver in question
- provides onto what QtGamepad expects. This can be done by the
- \l{Qt Gamepad Configure Buttons Example}{configureButtons} example that can also
- save the generated layout persistently for use by other applications.
-
- \section1 Getting Started
-
- Before you start using the APIs provided by this module, ensure that the
- gamepad is detected by your development environment.
-
- \section2 Linux
-
- On standard Linux distributions such as Ubuntu, gamepads such as XBox or
- PlayStation controllers are detected out-of-the-box. To check if the
- gamepad is detected, \c grep the \c dmesg logs using:
-
- \badcode
- dmesg | grep "<gamepad-make>"
- \endcode
-
- If you do not see the entries for the gamepad you are using, check if
- the \c joystick package is installed. If not, install the package and \c grep
- the \c dmesg logs again.
-
- It is strongly recommended to verify that the gamepad's input device is
- present, and is sending events, via the \c lsinput and \c evtest utilities.
-
- PlayStation controllers will likely need the help of an additional tool like
- \l{https://github.com/xboxdrv/xboxdrv}{xboxdrv}. Once installed, and having a
- PS3 controller connected via USB, the following will ensure correct operation
- with QtGamepad:
-
- \badcode
- sudo xboxdrv --detach-kernel-driver --mimic-xpad -s
- \endcode
-
- Qt Gamepad uses a plugin-based, multi-backend architecture. This means that on
- some platforms, like Linux, there are multiple backends available. In case of
- Linux, the choices are:
-
- \list
-
- \li \c evdev - a backend reading events directly from the evdev input device
-
- \li \c sdl2 - a backend using the Gamepad module of SDL2. This plugin is only
- built when SDL2 is present at build time, and therefore will typically be
- missing from the pre-built Qt packages. This backend likely has broader
- support for various hardware, at the expense of an additional third-party
- dependency.
-
- \endlist
-
- To force a given backend, set the \c QT_GAMEPAD environment variable to the
- name of the desired backend.
-
- The availability of gamepad devices is monitored via \c libudev, assuming Qt
- was built with libudev support enabled. This means that connecting wired
- gamepads or wireless dongles is possible also while an application is
- running.
-
- \note wireless dongles may report one or more input devices even when no
- actual controllers have been connected to them. Qt Gamepad will interpret this
- as having connected gamepads present.
-
- With the \c evdev backend, to explicitly specify the input device to use, set
- the environment variable \c{QT_GAMEPAD_DEVICE} to the desired
- /dev/input/event* node. This should not be needed normally, but can be useful
- in case multiple gamepads are connected and only one of them is interesting to
- the application.
-
- \section2 Windows
-
- The Windows Plug-n-Play service automatically installs the necessary drivers
- when the gamepad is connected through a USB port for the first time. Once the
- drivers are installed, select \uicontrol{Control Panel > Device and Printers}
- and check if the gamepad is listed under the \uicontrol Devices section.
-
- To test whether gamepad input is detected, select
- \uicontrol {Gamepad Controller Settings} from the context menu, select
- \uicontrol {Properties > Test}, and start testing. You can also run the
- \l{Qt Gamepad Qt Quick Example}{quickGamepad} example to test.
-
- \section2 Android
-
- The Android backend uses the \c InputDevice API.
-
- \section2 macOS, iOS, tvOS
-
- This backend uses the \c GCController API.
-
- Besides game controllers, it also supports the tvOS remote (microGamepad). The
- mapping for this is the following:
-
- \list
- \li \c{X button} - play/pause
- \li \c{A button} - pressing the touch area
- \li \c{left thumbstick} - the touch area
- \endlist
-
- \section2 Troubleshooting
-
- Some backends (\c evdev on Linux and \c xinput on Windows) and the plugin
- loader utilize the logging category \c{qt.gamepad}. Enabling this will print
- useful information on the debug output.
-
- \section1 Examples
-
- The \l{Qt Gamepad Examples}{examples} demonstrate how to handle input from a
- gamepad using the QML and C++ APIs.
-
- \section1 API Reference
-
- \list
- \li \l{Qt Gamepad QML Types}
- \li \l{Qt Gamepad C++ Classes}
- \endlist
-
-*/
diff --git a/src/gamepad/doc/src/qtgamepad-qmltypes.qdoc b/src/gamepad/doc/src/qtgamepad-qmltypes.qdoc
deleted file mode 100644
index c136864..0000000
--- a/src/gamepad/doc/src/qtgamepad-qmltypes.qdoc
+++ /dev/null
@@ -1,52 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*!
- \qmlmodule QtGamepad 1.\QtMinorVersion
- \title Qt Gamepad QML Types
- \ingroup qmlmodules
- \brief Provides QML types for using gamepad hardware.
-
- The Qt Gamepad module provides QML types that can be used to access the
- state of gamepad hardware that may be available on a system.
-
- The QML types can be imported into your application using the following
- import statement:
-
- \qml \QtMinorVersion
- import QtGamepad 1.\1
- \endqml
-
- To link against the module, add this line to your \l qmake \c .pro file:
-
- \code
- QT += gamepad
- \endcode
-
- For more information about using these types in your application,
- see the \l{Qt Gamepad} documentation.
-*/
diff --git a/src/gamepad/gamepad.pro b/src/gamepad/gamepad.pro
deleted file mode 100644
index 5151d95..0000000
--- a/src/gamepad/gamepad.pro
+++ /dev/null
@@ -1,36 +0,0 @@
-TARGET = QtGamepad
-QT = core-private core gui
-
-MODULE_PLUGIN_TYPES = gamepads
-
-load(qt_module)
-
-DEFINES += QT_BUILD_GAMEPAD_LIB
-
-QMAKE_DOCS = $$PWD/doc/qtgamepad.qdocconf
-
-HEADERS += \
- qtgamepadglobal.h \
- qgamepadmanager.h \
- qgamepad.h \
- qgamepadbackend_p.h \
- qgamepadbackendfactory_p.h \
- qgamepadkeynavigation.h \
- qgamepadbackendplugin_p.h
-SOURCES += \
- qgamepadmanager.cpp \
- qgamepad.cpp \
- qgamepadbackend.cpp \
- qgamepadbackendfactory.cpp \
- qgamepadkeynavigation.cpp \
- qgamepadbackendplugin.cpp
-
-
-ANDROID_BUNDLED_JAR_DEPENDENCIES = \
- jar/Qt$${QT_MAJOR_VERSION}AndroidGamepad.jar
-
-ANDROID_LIB_DEPENDENCIES = \
- plugins/gamepads/libplugins_gamepads_androidgamepad.so
-
-ANDROID_FEATURES = \
- android.hardware.gamepad
diff --git a/src/gamepad/qgamepad.cpp b/src/gamepad/qgamepad.cpp
index ff57db6..f092a18 100644
--- a/src/gamepad/qgamepad.cpp
+++ b/src/gamepad/qgamepad.cpp
@@ -1,38 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Gamepad module
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qgamepad.h"
@@ -47,69 +14,40 @@ class QGamepadPrivate : public QObjectPrivate
public:
QGamepadPrivate(int deviceId)
: deviceId(deviceId)
- , connected(false)
- , axisLeftX(0.0)
- , axisLeftY(0.0)
- , axisRightX(0.0)
- , axisRightY(0.0)
- , buttonA(false)
- , buttonB(false)
- , buttonX(false)
- , buttonY(false)
- , buttonL1(false)
- , buttonR1(false)
- , buttonL2(0.0)
- , buttonR2(0.0)
- , buttonSelect(false)
- , buttonStart(false)
- , buttonL3(false)
- , buttonR3(false)
- , buttonUp(false)
- , buttonDown(false)
- , buttonLeft(false)
- , buttonRight(false)
- , buttonCenter(false)
- , buttonGuide(false)
{
}
- QGamepadManager *gamepadManager;
-
- int deviceId;
- bool connected;
+ int deviceId = -1;
+ bool connected = false;
QString name;
- double axisLeftX;
- double axisLeftY;
- double axisRightX;
- double axisRightY;
- bool buttonA;
- bool buttonB;
- bool buttonX;
- bool buttonY;
- bool buttonL1;
- bool buttonR1;
- double buttonL2;
- double buttonR2;
- bool buttonSelect;
- bool buttonStart;
- bool buttonL3;
- bool buttonR3;
- bool buttonUp;
- bool buttonDown;
- bool buttonLeft;
- bool buttonRight;
- bool buttonCenter;
- bool buttonGuide;
+ float axisLeftX = 0.0f;
+ float axisLeftY = 0.0f;
+ float axisRightX = 0.0f;
+ float axisRightY = 0.0f;
+ bool buttonA = false;
+ bool buttonB = false;
+ bool buttonX = false;
+ bool buttonY = false;
+ bool buttonL1 = false;
+ bool buttonR1 = false;
+ float buttonL2 = 0.0f;
+ float buttonR2 = 0.0f;
+ bool buttonSelect = false;
+ bool buttonStart = false;
+ bool buttonL3 = false;
+ bool buttonR3 = false;
+ bool buttonUp = false;
+ bool buttonDown = false;
+ bool buttonLeft = false;
+ bool buttonRight = false;
+ bool buttonGuide = false;
void setConnected(bool isConnected);
void setName(const QString &name);
- void _q_handleGamepadConnected(int id);
- void _q_handleGamepadNameChanged(int id, const QString &name);
- void _q_handleGamepadDisconnected(int id);
- void _q_handleGamepadAxisEvent(int id, QGamepadManager::GamepadAxis axis, double value);
- void _q_handleGamepadButtonPressEvent(int id, QGamepadManager::GamepadButton button, double value);
- void _q_handleGamepadButtonReleaseEvent(int id, QGamepadManager::GamepadButton button);
+ void _q_handleGamepadConnectionChangedEvent(int index, bool isConnected);
+ void _q_handleGamepadAxisEvent(int device, JoyAxis axis, float value);
+ void _q_handleGamepadButtonEvent(int device, JoyButton button, bool isPressed);
};
void QGamepadPrivate::setConnected(bool isConnected)
@@ -117,7 +55,7 @@ void QGamepadPrivate::setConnected(bool isConnected)
Q_Q(QGamepad);
if (connected != isConnected) {
connected = isConnected;
- emit q->connectedChanged(connected);
+ emit q->connectedChanged();
}
}
@@ -126,245 +64,134 @@ void QGamepadPrivate::setName(const QString &theName)
Q_Q(QGamepad);
if (name != theName) {
name = theName;
- emit q->nameChanged(name);
+ emit q->nameChanged();
}
}
/*!
* \internal
*/\
-void QGamepadPrivate::_q_handleGamepadConnected(int id)
+void QGamepadPrivate::_q_handleGamepadConnectionChangedEvent(int index, bool isConnected)
{
- if (id == deviceId) {
- setConnected(true);
- }
+ if (index == deviceId)
+ setConnected(isConnected);
}
/*!
* \internal
*/\
-void QGamepadPrivate::_q_handleGamepadNameChanged(int id, const QString &name)
-{
- if (id == deviceId)
- setName(name);
-}
-
-/*!
- * \internal
- */\
-void QGamepadPrivate::_q_handleGamepadDisconnected(int id)
-{
- if (id == deviceId) {
- setConnected(false);
- }
-}
-
-/*!
- * \internal
- */\
-void QGamepadPrivate::_q_handleGamepadAxisEvent(int id, QGamepadManager::GamepadAxis axis, double value)
+void QGamepadPrivate::_q_handleGamepadAxisEvent(int device, JoyAxis axis, float value)
{
Q_Q(QGamepad);
- if (id != deviceId)
+ if (device != deviceId)
return;
switch (axis) {
- case QGamepadManager::AxisLeftX:
+ case JoyAxis::LeftX:
axisLeftX = value;
- emit q->axisLeftXChanged(value);
+ emit q->axisLeftXChanged();
break;
- case QGamepadManager::AxisLeftY:
+ case JoyAxis::LeftY:
axisLeftY = value;
- emit q->axisLeftYChanged(value);
+ emit q->axisLeftYChanged();
break;
- case QGamepadManager::AxisRightX:
+ case JoyAxis::RightX:
axisRightX = value;
- emit q->axisRightXChanged(value);
+ emit q->axisRightXChanged();
break;
- case QGamepadManager::AxisRightY:
+ case JoyAxis::RightY:
axisRightY = value;
- emit q->axisRightYChanged(value);
- break;
- default:
- break;
- }
-}
-
-/*!
- * \internal
- */\
-void QGamepadPrivate::_q_handleGamepadButtonPressEvent(int id, QGamepadManager::GamepadButton button, double value)
-{
- Q_Q(QGamepad);
- if (id != deviceId)
- return;
-
- switch (button) {
- case QGamepadManager::ButtonA:
- buttonA = true;
- emit q->buttonAChanged(true);
- break;
- case QGamepadManager::ButtonB:
- buttonB = true;
- emit q->buttonBChanged(true);
- break;
- case QGamepadManager::ButtonX:
- buttonX = true;
- emit q->buttonXChanged(true);
- break;
- case QGamepadManager::ButtonY:
- buttonY = true;
- emit q->buttonYChanged(true);
- break;
- case QGamepadManager::ButtonL1:
- buttonL1 = true;
- emit q->buttonL1Changed(true);
+ emit q->axisRightYChanged();
break;
- case QGamepadManager::ButtonR1:
- buttonR1 = true;
- emit q->buttonR1Changed(true);
- break;
- case QGamepadManager::ButtonL2:
+ case JoyAxis::TriggerLeft:
buttonL2 = value;
- emit q->buttonL2Changed(value);
+ emit q->buttonL2Changed();
break;
- case QGamepadManager::ButtonR2:
+ case JoyAxis::TriggerRight:
buttonR2 = value;
- emit q->buttonR2Changed(value);
- break;
- case QGamepadManager::ButtonL3:
- buttonL3 = true;
- emit q->buttonL3Changed(true);
- break;
- case QGamepadManager::ButtonR3:
- buttonR3 = true;
- emit q->buttonR3Changed(true);
- break;
- case QGamepadManager::ButtonSelect:
- buttonSelect = true;
- emit q->buttonSelectChanged(true);
- break;
- case QGamepadManager::ButtonStart:
- buttonStart = true;
- emit q->buttonStartChanged(true);
- break;
- case QGamepadManager::ButtonUp:
- buttonUp = true;
- emit q->buttonUpChanged(true);
- break;
- case QGamepadManager::ButtonDown:
- buttonDown = true;
- emit q->buttonDownChanged(true);
- break;
- case QGamepadManager::ButtonLeft:
- buttonLeft = true;
- emit q->buttonLeftChanged(true);
- break;
- case QGamepadManager::ButtonRight:
- buttonRight = true;
- emit q->buttonRightChanged(true);
- break;
- case QGamepadManager::ButtonCenter:
- buttonCenter = true;
- emit q->buttonCenterChanged(true);
- break;
- case QGamepadManager::ButtonGuide:
- buttonGuide = true;
- emit q->buttonGuideChanged(true);
+ emit q->buttonR2Changed();
break;
default:
break;
}
-
}
/*!
* \internal
*/\
-void QGamepadPrivate::_q_handleGamepadButtonReleaseEvent(int id, QGamepadManager::GamepadButton button)
+void QGamepadPrivate::_q_handleGamepadButtonEvent(int device, JoyButton button, bool isPressed)
{
Q_Q(QGamepad);
- if (id != deviceId)
+ if (device != deviceId)
return;
switch (button) {
- case QGamepadManager::ButtonA:
- buttonA = false;
- emit q->buttonAChanged(false);
+ case JoyButton::A:
+ buttonA = isPressed;
+ emit q->buttonAChanged();
break;
- case QGamepadManager::ButtonB:
- buttonB = false;
- emit q->buttonBChanged(false);
+ case JoyButton::B:
+ buttonB = isPressed;
+ emit q->buttonBChanged();
break;
- case QGamepadManager::ButtonX:
- buttonX = false;
- emit q->buttonXChanged(false);
+ case JoyButton::X:
+ buttonX = isPressed;
+ emit q->buttonXChanged();
break;
- case QGamepadManager::ButtonY:
- buttonY = false;
- emit q->buttonYChanged(false);
+ case JoyButton::Y:
+ buttonY = isPressed;
+ emit q->buttonYChanged();
break;
- case QGamepadManager::ButtonL1:
- buttonL1 = false;
- emit q->buttonL1Changed(false);
+ case JoyButton::LeftShoulder:
+ buttonL1 = isPressed;
+ emit q->buttonL1Changed();
break;
- case QGamepadManager::ButtonR1:
- buttonR1 = false;
- emit q->buttonR1Changed(false);
+ case JoyButton::RightShoulder:
+ buttonR1 = isPressed;
+ emit q->buttonR1Changed();
break;
- case QGamepadManager::ButtonL2:
- buttonL2 = 0.0;
- emit q->buttonL2Changed(0.0);
+ case JoyButton::LeftStick:
+ buttonL3 = isPressed;
+ emit q->buttonL3Changed();
break;
- case QGamepadManager::ButtonR2:
- buttonR2 = 0.0;
- emit q->buttonR2Changed(0.0);
+ case JoyButton::RightStick:
+ buttonR3 = isPressed;
+ emit q->buttonR3Changed();
break;
- case QGamepadManager::ButtonL3:
- buttonL3 = false;
- emit q->buttonL3Changed(false);
+ case JoyButton::Back:
+ buttonSelect = isPressed;
+ emit q->buttonSelectChanged();
break;
- case QGamepadManager::ButtonR3:
- buttonR3 = false;
- emit q->buttonR3Changed(false);
+ case JoyButton::Start:
+ buttonStart = isPressed;
+ emit q->buttonStartChanged();
break;
- case QGamepadManager::ButtonSelect:
- buttonSelect = false;
- emit q->buttonSelectChanged(false);
+ case JoyButton::DpadUp:
+ buttonUp = isPressed;
+ emit q->buttonUpChanged();
break;
- case QGamepadManager::ButtonStart:
- buttonStart = false;
- emit q->buttonStartChanged(false);
+ case JoyButton::DpadDown:
+ buttonDown = isPressed;
+ emit q->buttonDownChanged();
break;
- case QGamepadManager::ButtonUp:
- buttonUp = false;
- emit q->buttonUpChanged(false);
+ case JoyButton::DpadLeft:
+ buttonLeft = isPressed;
+ emit q->buttonLeftChanged();
break;
- case QGamepadManager::ButtonDown:
- buttonDown = false;
- emit q->buttonDownChanged(false);
+ case JoyButton::DpadRight:
+ buttonRight = isPressed;
+ emit q->buttonRightChanged();
break;
- case QGamepadManager::ButtonLeft:
- buttonLeft = false;
- emit q->buttonLeftChanged(false);
- break;
- case QGamepadManager::ButtonRight:
- buttonRight = false;
- emit q->buttonRightChanged(false);
- break;
- case QGamepadManager::ButtonCenter:
- buttonCenter = false;
- emit q->buttonCenterChanged(false);
- break;
- case QGamepadManager::ButtonGuide:
- buttonGuide = false;
- emit q->buttonGuideChanged(false);
+ case JoyButton::Guide:
+ buttonGuide = isPressed;
+ emit q->buttonGuideChanged();
break;
default:
break;
}
}
+
/*!
\class QGamepad
\inmodule QtGamepad
@@ -390,17 +217,15 @@ void QGamepadPrivate::_q_handleGamepadButtonReleaseEvent(int id, QGamepadManager
QGamepad::QGamepad(int deviceId, QObject *parent)
: QObject(*new QGamepadPrivate(deviceId), parent)
{
- Q_D(QGamepad);
- d->gamepadManager = QGamepadManager::instance();
- connect(d->gamepadManager, SIGNAL(gamepadConnected(int)), this, SLOT(_q_handleGamepadConnected(int)));
- connect(d->gamepadManager, SIGNAL(gamepadNameChanged(int, QString)), this, SLOT(_q_handleGamepadNameChanged(int, QString)));
- connect(d->gamepadManager, SIGNAL(gamepadDisconnected(int)), this, SLOT(_q_handleGamepadDisconnected(int)));
- connect(d->gamepadManager, SIGNAL(gamepadAxisEvent(int,QGamepadManager::GamepadAxis,double)), this, SLOT(_q_handleGamepadAxisEvent(int,QGamepadManager::GamepadAxis,double)));
- connect(d->gamepadManager, SIGNAL(gamepadButtonPressEvent(int,QGamepadManager::GamepadButton,double)), this, SLOT(_q_handleGamepadButtonPressEvent(int,QGamepadManager::GamepadButton,double)));
- connect(d->gamepadManager, SIGNAL(gamepadButtonReleaseEvent(int,QGamepadManager::GamepadButton)), this, SLOT(_q_handleGamepadButtonReleaseEvent(int,QGamepadManager::GamepadButton)));
+ auto* input = QUniversalInput::instance();
+
+ connect(input, SIGNAL(joyConnectionChanged(int,bool)), this, SLOT(_q_handleGamepadConnectionChangedEvent(int, bool)));
+ connect(input, SIGNAL(joyAxisEvent(int,JoyAxis,float)), this, SLOT(_q_handleGamepadAxisEvent(int, JoyAxis, float)));
+ connect(input, SIGNAL(joyButtonEvent(int,JoyButton,bool)), this, SLOT(_q_handleGamepadButtonEvent(int, JoyButton, bool)));
- d->setConnected(d->gamepadManager->isGamepadConnected(deviceId));
- d->setName(d->gamepadManager->gamepadName(deviceId));
+ Q_D(QGamepad);
+ d->setConnected(input->isJoyConnected(deviceId));
+ d->setName(input->getJoyName(deviceId));
}
QGamepad::~QGamepad()
@@ -472,13 +297,13 @@ QString QGamepad::name() const
* The axis values range from -1.0 to 1.0.
*/
/*!
- * \qmlproperty double Gamepad::axisLeftX
+ * \qmlproperty float Gamepad::axisLeftX
* \readonly
*
* The value of the left thumbstick's X axis.
* The axis values range from -1.0 to 1.0.
*/
-double QGamepad::axisLeftX() const
+float QGamepad::axisLeftX() const
{
Q_D(const QGamepad);
return d->axisLeftX;
@@ -491,13 +316,13 @@ double QGamepad::axisLeftX() const
* The axis values range from -1.0 to 1.0.
*/
/*!
- * \qmlproperty double Gamepad::axisLeftY
+ * \qmlproperty float Gamepad::axisLeftY
* \readonly
*
* The value of the left thumbstick's Y axis.
* The axis values range from -1.0 to 1.0.
*/
-double QGamepad::axisLeftY() const
+float QGamepad::axisLeftY() const
{
Q_D(const QGamepad);
return d->axisLeftY;
@@ -510,13 +335,13 @@ double QGamepad::axisLeftY() const
* The axis values range from -1.0 to 1.0.
*/
/*!
- * \qmlproperty double Gamepad::axisRightX
+ * \qmlproperty float Gamepad::axisRightX
* \readonly
*
* This value of the right thumbstick's X axis.
* The axis values range from -1.0 to 1.0.
*/
-double QGamepad::axisRightX() const
+float QGamepad::axisRightX() const
{
Q_D(const QGamepad);
return d->axisRightX;
@@ -529,13 +354,13 @@ double QGamepad::axisRightX() const
* The axis values range from -1.0 to 1.0.
*/
/*!
- * \qmlproperty double Gamepad::axisRightY
+ * \qmlproperty float Gamepad::axisRightY
* \readonly
*
* This value of the right thumbstick's Y axis.
* The axis values range from -1.0 to 1.0.
*/
-double QGamepad::axisRightY() const
+float QGamepad::axisRightY() const
{
Q_D(const QGamepad);
return d->axisRightY;
@@ -663,14 +488,14 @@ bool QGamepad::buttonR1() const
* when pressed completely.
*/
/*!
- * \qmlproperty double Gamepad::buttonL2
+ * \qmlproperty float Gamepad::buttonL2
* \readonly
*
* The value of the left trigger button.
* This trigger value ranges from 0.0 when not pressed to 1.0
* when pressed completely.
*/
-double QGamepad::buttonL2() const
+float QGamepad::buttonL2() const
{
Q_D(const QGamepad);
return d->buttonL2;
@@ -684,14 +509,14 @@ double QGamepad::buttonL2() const
* when pressed completely.
*/
/*!
- * \qmlproperty double Gamepad::buttonR2
+ * \qmlproperty float Gamepad::buttonR2
* \readonly
*
* The value of the right trigger button.
* This trigger value ranges from 0.0 when not pressed to 1.0
* when pressed completely.
*/
-double QGamepad::buttonR2() const
+float QGamepad::buttonR2() const
{
Q_D(const QGamepad);
return d->buttonR2;
@@ -858,25 +683,6 @@ bool QGamepad::buttonRight() const
}
/*!
- * \property QGamepad::buttonCenter
- *
- * The state of the center button.
- * The value is \c true when pressed, and \c false when not pressed.
- */
-/*
- * \qmlproperty bool Gamepad::buttonCenter
- * \readonly
- *
- * The state of the center button.
- * The value is \c true when pressed, and \c false when not pressed.
- */
-bool QGamepad::buttonCenter() const
-{
- Q_D(const QGamepad);
- return d->buttonCenter;
-}
-
-/*!
* \property QGamepad::buttonGuide
*
* The state of the guide button.
@@ -905,8 +711,10 @@ void QGamepad::setDeviceId(int number)
Q_D(QGamepad);
if (d->deviceId != number) {
d->deviceId = number;
- emit deviceIdChanged(number);
- d->setConnected(d->gamepadManager->isGamepadConnected(d->deviceId));
+ emit deviceIdChanged();
+ auto input = QUniversalInput::instance();
+ d->setName(input->getJoyName(d->deviceId));
+ d->setConnected(input->isJoyConnected(d->deviceId));
}
}
diff --git a/src/gamepad/qgamepad.h b/src/gamepad/qgamepad.h
index 33390f8..b53519a 100644
--- a/src/gamepad/qgamepad.h
+++ b/src/gamepad/qgamepad.h
@@ -1,45 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Gamepad module
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QGAMEPAD_H
#define QGAMEPAD_H
#include <QtCore/QObject>
-#include <QtGamepad/qtgamepadglobal.h>
-#include <QtGamepad/QGamepadManager>
+#include <QtGamepad/qtgamepadexports.h>
QT_BEGIN_NAMESPACE
@@ -51,18 +17,18 @@ class Q_GAMEPAD_EXPORT QGamepad : public QObject
Q_PROPERTY(int deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged)
Q_PROPERTY(bool connected READ isConnected NOTIFY connectedChanged)
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
- Q_PROPERTY(double axisLeftX READ axisLeftX NOTIFY axisLeftXChanged)
- Q_PROPERTY(double axisLeftY READ axisLeftY NOTIFY axisLeftYChanged)
- Q_PROPERTY(double axisRightX READ axisRightX NOTIFY axisRightXChanged)
- Q_PROPERTY(double axisRightY READ axisRightY NOTIFY axisRightYChanged)
+ Q_PROPERTY(float axisLeftX READ axisLeftX NOTIFY axisLeftXChanged)
+ Q_PROPERTY(float axisLeftY READ axisLeftY NOTIFY axisLeftYChanged)
+ Q_PROPERTY(float axisRightX READ axisRightX NOTIFY axisRightXChanged)
+ Q_PROPERTY(float axisRightY READ axisRightY NOTIFY axisRightYChanged)
Q_PROPERTY(bool buttonA READ buttonA NOTIFY buttonAChanged)
Q_PROPERTY(bool buttonB READ buttonB NOTIFY buttonBChanged)
Q_PROPERTY(bool buttonX READ buttonX NOTIFY buttonXChanged)
Q_PROPERTY(bool buttonY READ buttonY NOTIFY buttonYChanged)
Q_PROPERTY(bool buttonL1 READ buttonL1 NOTIFY buttonL1Changed)
Q_PROPERTY(bool buttonR1 READ buttonR1 NOTIFY buttonR1Changed)
- Q_PROPERTY(double buttonL2 READ buttonL2 NOTIFY buttonL2Changed)
- Q_PROPERTY(double buttonR2 READ buttonR2 NOTIFY buttonR2Changed)
+ Q_PROPERTY(float buttonL2 READ buttonL2 NOTIFY buttonL2Changed)
+ Q_PROPERTY(float buttonR2 READ buttonR2 NOTIFY buttonR2Changed)
Q_PROPERTY(bool buttonSelect READ buttonSelect NOTIFY buttonSelectChanged)
Q_PROPERTY(bool buttonStart READ buttonStart NOTIFY buttonStartChanged)
Q_PROPERTY(bool buttonL3 READ buttonL3 NOTIFY buttonL3Changed)
@@ -71,30 +37,30 @@ class Q_GAMEPAD_EXPORT QGamepad : public QObject
Q_PROPERTY(bool buttonDown READ buttonDown NOTIFY buttonDownChanged)
Q_PROPERTY(bool buttonLeft READ buttonLeft NOTIFY buttonLeftChanged)
Q_PROPERTY(bool buttonRight READ buttonRight NOTIFY buttonRightChanged)
- Q_PROPERTY(bool buttonCenter READ buttonCenter NOTIFY buttonCenterChanged)
Q_PROPERTY(bool buttonGuide READ buttonGuide NOTIFY buttonGuideChanged)
public:
explicit QGamepad(int deviceId = 0, QObject *parent = nullptr);
~QGamepad();
int deviceId() const;
+ void setDeviceId(int number);
bool isConnected() const;
QString name() const;
- double axisLeftX() const;
- double axisLeftY() const;
- double axisRightX() const;
- double axisRightY() const;
+ float axisLeftX() const;
+ float axisLeftY() const;
+ float axisRightX() const;
+ float axisRightY() const;
bool buttonA() const;
bool buttonB() const;
bool buttonX() const;
bool buttonY() const;
bool buttonL1() const;
bool buttonR1() const;
- double buttonL2() const;
- double buttonR2() const;
+ float buttonL2() const;
+ float buttonR2() const;
bool buttonSelect() const;
bool buttonStart() const;
bool buttonL3() const;
@@ -103,50 +69,41 @@ public:
bool buttonDown() const;
bool buttonLeft() const;
bool buttonRight() const;
- bool buttonCenter() const;
bool buttonGuide() const;
Q_SIGNALS:
- void deviceIdChanged(int value);
- void connectedChanged(bool value);
- void nameChanged(QString value);
- void axisLeftXChanged(double value);
- void axisLeftYChanged(double value);
- void axisRightXChanged(double value);
- void axisRightYChanged(double value);
- void buttonAChanged(bool value);
- void buttonBChanged(bool value);
- void buttonXChanged(bool value);
- void buttonYChanged(bool value);
- void buttonL1Changed(bool value);
- void buttonR1Changed(bool value);
- void buttonL2Changed(double value);
- void buttonR2Changed(double value);
- void buttonSelectChanged(bool value);
- void buttonStartChanged(bool value);
- void buttonL3Changed(bool value);
- void buttonR3Changed(bool value);
- void buttonUpChanged(bool value);
- void buttonDownChanged(bool value);
- void buttonLeftChanged(bool value);
- void buttonRightChanged(bool value);
- void buttonCenterChanged(bool value);
- void buttonGuideChanged(bool value);
-
-public Q_SLOTS:
-
- void setDeviceId(int number);
+ void deviceIdChanged();
+ void connectedChanged();
+ void nameChanged();
+ void axisLeftXChanged();
+ void axisLeftYChanged();
+ void axisRightXChanged();
+ void axisRightYChanged();
+ void buttonAChanged();
+ void buttonBChanged();
+ void buttonXChanged();
+ void buttonYChanged();
+ void buttonL1Changed();
+ void buttonR1Changed();
+ void buttonL2Changed();
+ void buttonR2Changed();
+ void buttonSelectChanged();
+ void buttonStartChanged();
+ void buttonL3Changed();
+ void buttonR3Changed();
+ void buttonUpChanged();
+ void buttonDownChanged();
+ void buttonLeftChanged();
+ void buttonRightChanged();
+ void buttonGuideChanged();
private:
Q_DECLARE_PRIVATE(QGamepad)
Q_DISABLE_COPY(QGamepad)
- Q_PRIVATE_SLOT(d_func(), void _q_handleGamepadConnected(int))
- Q_PRIVATE_SLOT(d_func(), void _q_handleGamepadNameChanged(int, const QString &))
- Q_PRIVATE_SLOT(d_func(), void _q_handleGamepadDisconnected(int))
- Q_PRIVATE_SLOT(d_func(), void _q_handleGamepadAxisEvent(int, QGamepadManager::GamepadAxis, double))
- Q_PRIVATE_SLOT(d_func(), void _q_handleGamepadButtonPressEvent(int, QGamepadManager::GamepadButton, double))
- Q_PRIVATE_SLOT(d_func(), void _q_handleGamepadButtonReleaseEvent(int, QGamepadManager::GamepadButton))
+ Q_PRIVATE_SLOT(d_func(), void _q_handleGamepadConnectionChangedEvent(int, bool))
+ Q_PRIVATE_SLOT(d_func(), void _q_handleGamepadAxisEvent(int, JoyAxis, float))
+ Q_PRIVATE_SLOT(d_func(), void _q_handleGamepadButtonEvent(int, JoyButton, bool))
};
QT_END_NAMESPACE
diff --git a/src/gamepad/qgamepadbackend.cpp b/src/gamepad/qgamepadbackend.cpp
deleted file mode 100644
index 2b74634..0000000
--- a/src/gamepad/qgamepadbackend.cpp
+++ /dev/null
@@ -1,114 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Gamepad module
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgamepadbackend_p.h"
-#include <QSettings>
-
-QT_BEGIN_NAMESPACE
-
-static const QLatin1String GAMEPAD_GROUP("___gamepad_saved_states_v2");
-
-QGamepadBackend::QGamepadBackend(QObject *parent) :
- QObject(parent)
-{
-}
-
-bool QGamepadBackend::isConfigurationNeeded(int /*deviceId*/)
-{
- return false;
-}
-
-void QGamepadBackend::resetConfiguration(int /*deviceId*/)
-{
-}
-
-bool QGamepadBackend::configureButton(int /*deviceId*/, QGamepadManager::GamepadButton /*button*/)
-{
- return false;
-}
-
-bool QGamepadBackend::configureAxis(int /*deviceId*/, QGamepadManager::GamepadAxis /*axis*/)
-{
- return false;
-}
-
-bool QGamepadBackend::setCancelConfigureButton(int /*deviceId*/, QGamepadManager::GamepadButton /*button*/)
-{
- return false;
-}
-
-void QGamepadBackend::setSettingsFile(const QString &file)
-{
- m_settingsFilePath = file;
-}
-
-void QGamepadBackend::saveSettings(int productId, const QVariant &value)
-{
- QScopedPointer<QSettings> s;
- if (m_settingsFilePath.isNull())
- s.reset(new QSettings());
- else
- s.reset(new QSettings(m_settingsFilePath));
- s->beginGroup(GAMEPAD_GROUP);
- QString key = QString::fromLatin1("id_%1").arg(productId);
- if (value.isNull())
- s->remove(key);
- else
- s->setValue(key, value);
-}
-
-QVariant QGamepadBackend::readSettings(int productId)
-{
- QScopedPointer<QSettings> s;
- if (m_settingsFilePath.isNull())
- s.reset(new QSettings());
- else
- s.reset(new QSettings(m_settingsFilePath));
- s->beginGroup(GAMEPAD_GROUP);
- return s->value(QString::fromLatin1("id_%1").arg(productId));
-}
-
-bool QGamepadBackend::start()
-{
- return true;
-}
-
-void QGamepadBackend::stop()
-{
-
-}
-
-QT_END_NAMESPACE
diff --git a/src/gamepad/qgamepadbackend_p.h b/src/gamepad/qgamepadbackend_p.h
deleted file mode 100644
index 4c5d276..0000000
--- a/src/gamepad/qgamepadbackend_p.h
+++ /dev/null
@@ -1,118 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Gamepad module
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGAMEPADBACKEND_P_H
-#define QGAMEPADBACKEND_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtGamepad/qtgamepadglobal.h>
-
-#include <QtCore/QObject>
-#include <QtGamepad/QGamepadManager>
-#include <QtCore/private/qglobal_p.h>
-
-QT_BEGIN_NAMESPACE
-
-class Q_GAMEPAD_EXPORT QGamepadBackend : public QObject
-{
- Q_OBJECT
-public:
- template <typename T>
- struct AxisInfo {
- AxisInfo(T minValue = 0, T maxValue = 1, QGamepadManager::GamepadAxis gamepadAxis = QGamepadManager::AxisInvalid)
- : minValue(minValue)
- , maxValue(maxValue)
- , gamepadAxis(gamepadAxis)
- {}
-
- virtual double normalized(T value) const
- {
- if (gamepadAxis == QGamepadManager::AxisInvalid && minValue >= 0) {
- // case 0.0 - 1.0
- return double(value - minValue) / double(maxValue - minValue);
- } else {
- // case -1.0 - 1.0
- return 2.0 * double(value - minValue) / double(maxValue - minValue) - 1.0;
- }
- }
- T minValue;
- T maxValue;
- QGamepadManager::GamepadAxis gamepadAxis;
- };
-
-public:
- explicit QGamepadBackend(QObject *parent = nullptr);
- virtual bool isConfigurationNeeded(int deviceId);
- virtual void resetConfiguration(int deviceId);
- virtual bool configureButton(int deviceId, QGamepadManager::GamepadButton button);
- virtual bool configureAxis(int deviceId, QGamepadManager::GamepadAxis axis);
- virtual bool setCancelConfigureButton(int deviceId, QGamepadManager::GamepadButton button);
- virtual void setSettingsFile(const QString &file);
- virtual void saveSettings(int productId, const QVariant &value);
- virtual QVariant readSettings(int productId);
-
-public Q_SLOTS:
- virtual bool start();
- virtual void stop();
-
-Q_SIGNALS:
- void buttonConfigured(int deviceId, QGamepadManager::GamepadButton button);
- void axisConfigured(int deviceId, QGamepadManager::GamepadAxis axis);
- void configurationCanceled(int deviceId);
- void gamepadAdded(int deviceId);
- void gamepadNamed(int deviceId, const QString &name);
- void gamepadRemoved(int deviceId);
- void gamepadAxisMoved(int deviceId, QGamepadManager::GamepadAxis axis, double value);
- void gamepadButtonPressed(int deviceId, QGamepadManager::GamepadButton button, double value);
- void gamepadButtonReleased(int deviceId, QGamepadManager::GamepadButton button);
-
-protected:
- QString m_settingsFilePath;
-};
-
-QT_END_NAMESPACE
-
-#endif // QGAMEPADBACKEND_P_H
diff --git a/src/gamepad/qgamepadbackendfactory.cpp b/src/gamepad/qgamepadbackendfactory.cpp
deleted file mode 100644
index a899cf0..0000000
--- a/src/gamepad/qgamepadbackendfactory.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Gamepad module
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgamepadbackendfactory_p.h"
-#include "qgamepadbackendplugin_p.h"
-#include "qgamepadbackend_p.h"
-
-#include <QtCore/qdebug.h>
-#include <QtCore/private/qfactoryloader_p.h>
-#include <QtCore/QCoreApplication>
-#include <QtCore/QDir>
-
-QT_BEGIN_NAMESPACE
-
-Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, (QtGamepadBackendFactoryInterface_iid, QLatin1String("/gamepads"), Qt::CaseInsensitive))
-
-QStringList QGamepadBackendFactory::keys()
-{
- return loader->keyMap().values();
-}
-
-QGamepadBackend *QGamepadBackendFactory::create(const QString &name, const QStringList &args)
-{
- return qLoadPlugin<QGamepadBackend, QGamepadBackendPlugin>(loader(), name, args);
-}
-
-QT_END_NAMESPACE
diff --git a/src/gamepad/qgamepadbackendfactory_p.h b/src/gamepad/qgamepadbackendfactory_p.h
deleted file mode 100644
index 7782158..0000000
--- a/src/gamepad/qgamepadbackendfactory_p.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Gamepad module
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGAMEPADBACKENDFACTORY_P_H
-#define QGAMEPADBACKENDFACTORY_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtGamepad/qtgamepadglobal.h>
-#include <QtCore/QStringList>
-#include <QtCore/private/qglobal_p.h>
-
-QT_BEGIN_NAMESPACE
-
-class QGamepadBackend;
-
-class Q_GAMEPAD_EXPORT QGamepadBackendFactory
-{
-public:
- static QStringList keys();
- static QGamepadBackend *create(const QString &name, const QStringList &args);
-};
-
-QT_END_NAMESPACE
-
-#endif // QGAMEPADBACKENDFACTORY_P_H
diff --git a/src/gamepad/qgamepadbackendplugin.cpp b/src/gamepad/qgamepadbackendplugin.cpp
deleted file mode 100644
index a06a287..0000000
--- a/src/gamepad/qgamepadbackendplugin.cpp
+++ /dev/null
@@ -1,52 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Gamepad module
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgamepadbackendplugin_p.h"
-
-QT_BEGIN_NAMESPACE
-
-QGamepadBackendPlugin::QGamepadBackendPlugin(QObject *parent) : QObject(parent)
-{
-
-}
-
-QGamepadBackendPlugin::~QGamepadBackendPlugin()
-{
-
-}
-
-QT_END_NAMESPACE
-
diff --git a/src/gamepad/qgamepadbackendplugin_p.h b/src/gamepad/qgamepadbackendplugin_p.h
deleted file mode 100644
index 813259c..0000000
--- a/src/gamepad/qgamepadbackendplugin_p.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Gamepad module
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGAMEPADBACKENDPLUGIN_P_H
-#define QGAMEPADBACKENDPLUGIN_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtGamepad/qtgamepadglobal.h>
-
-#include <QtCore/qplugin.h>
-#include <QtCore/qfactoryinterface.h>
-#include <QtCore/private/qglobal_p.h>
-
-QT_BEGIN_NAMESPACE
-
-class QGamepadBackend;
-
-#define QtGamepadBackendFactoryInterface_iid "org.qt-project.Qt.Gamepad.QtGamepadBackendFactoryInterface.5.9"
-
-class Q_GAMEPAD_EXPORT QGamepadBackendPlugin : public QObject
-{
- Q_OBJECT
-public:
- explicit QGamepadBackendPlugin(QObject *parent = nullptr);
- ~QGamepadBackendPlugin();
-
- virtual QGamepadBackend *create(const QString &key, const QStringList &paramList) = 0;
-
-signals:
-
-public slots:
-};
-
-QT_END_NAMESPACE
-
-#endif // QGAMEPADBACKENDPLUGIN_P_H
diff --git a/src/gamepad/qgamepadkeynavigation.cpp b/src/gamepad/qgamepadkeynavigation.cpp
deleted file mode 100644
index 66c6906..0000000
--- a/src/gamepad/qgamepadkeynavigation.cpp
+++ /dev/null
@@ -1,584 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Gamepad module
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgamepadkeynavigation.h"
-#include <QtGui/QKeyEvent>
-#include <QtGui/QGuiApplication>
-#include <QtGui/QWindow>
-#include <QtGamepad/QGamepad>
-
-#include <private/qobject_p.h>
-
-QT_BEGIN_NAMESPACE
-
-class QGamepadKeyNavigationPrivate : public QObjectPrivate
-{
- Q_DECLARE_PUBLIC(QGamepadKeyNavigation)
-public:
- QGamepadKeyNavigationPrivate()
- : active(true)
- , gamepad(nullptr)
- , buttonL2Pressed(false)
- , buttonR2Pressed(false)
- {
- }
-
- void sendGeneratedKeyEvent(QKeyEvent *event);
-
- bool active;
- QGamepad *gamepad;
- QGamepadManager *gamepadManger;
- bool buttonL2Pressed;
- bool buttonR2Pressed;
- QMap<QGamepadManager::GamepadButton, Qt::Key> keyMapping;
-
- void _q_processGamepadButtonPressEvent(int index, QGamepadManager::GamepadButton button, double value);
- void _q_processGamepadButtonReleaseEvent(int index, QGamepadManager::GamepadButton button);
-};
-
-void QGamepadKeyNavigationPrivate::sendGeneratedKeyEvent(QKeyEvent *event)
-{
- if (!active) {
- delete event;
- return;
- }
- const QGuiApplication *app = qApp;
- QWindow *focusWindow = app ? app->focusWindow() : nullptr;
- if (focusWindow)
- QGuiApplication::sendEvent(focusWindow, event);
-}
-
-void QGamepadKeyNavigationPrivate::_q_processGamepadButtonPressEvent(int index, QGamepadManager::GamepadButton button, double value)
-{
- Q_UNUSED(value);
- // If a gamepad has been set then, only use the events of that gamepad
- if (gamepad && gamepad->deviceId() != index)
- return;
-
- // Trigger buttons are a special case as they get multiple press events as the value changes
- if (button == QGamepadManager::ButtonL2 && buttonL2Pressed)
- return;
- else
- buttonL2Pressed = true;
- if (button == QGamepadManager::ButtonR2 && buttonR2Pressed)
- return;
- else
- buttonR2Pressed = true;
-
- QKeyEvent *event = new QKeyEvent(QEvent::KeyPress, keyMapping[button], Qt::NoModifier);
- sendGeneratedKeyEvent(event);
-}
-
-void QGamepadKeyNavigationPrivate::_q_processGamepadButtonReleaseEvent(int index, QGamepadManager::GamepadButton button)
-{
- // If a gamepad has been set then, only use the events of that gamepad
- if (gamepad && gamepad->deviceId() != index)
- return;
-
- // Free the trigger buttons if necessary
- if (button == QGamepadManager::ButtonL2)
- buttonL2Pressed = false;
- if (button == QGamepadManager::ButtonR2)
- buttonR2Pressed = false;
-
- QKeyEvent *event = new QKeyEvent(QEvent::KeyRelease, keyMapping[button], Qt::NoModifier);
- sendGeneratedKeyEvent(event);
-}
-
-/*!
- \class QGamepadKeyNavigation
- \inmodule QtGamepad
- \brief Provides support for keyboard events triggered by gamepads.
-
- QGamepadKeyNavigation provides support for keyboard events triggered by
- gamepads.
- */
-
-/*!
- * Constructs a QGamepadNavigation object with the given \a parent.
- */
-
-QGamepadKeyNavigation::QGamepadKeyNavigation(QObject *parent)
- : QObject(*new QGamepadKeyNavigationPrivate(), parent)
-{
- Q_D(QGamepadKeyNavigation);
- d->gamepadManger = QGamepadManager::instance();
-
- // Default keymap
- d->keyMapping.insert(QGamepadManager::ButtonUp, Qt::Key_Up);
- d->keyMapping.insert(QGamepadManager::ButtonDown, Qt::Key_Down);
- d->keyMapping.insert(QGamepadManager::ButtonLeft, Qt::Key_Left);
- d->keyMapping.insert(QGamepadManager::ButtonRight, Qt::Key_Right);
- d->keyMapping.insert(QGamepadManager::ButtonA, Qt::Key_Return);
- d->keyMapping.insert(QGamepadManager::ButtonB, Qt::Key_Back);
- d->keyMapping.insert(QGamepadManager::ButtonX, Qt::Key_Back);
- d->keyMapping.insert(QGamepadManager::ButtonY, Qt::Key_Back);
- d->keyMapping.insert(QGamepadManager::ButtonSelect, Qt::Key_Back);
- d->keyMapping.insert(QGamepadManager::ButtonStart, Qt::Key_Return);
- d->keyMapping.insert(QGamepadManager::ButtonGuide, Qt::Key_Back);
- d->keyMapping.insert(QGamepadManager::ButtonL1, Qt::Key_Back);
- d->keyMapping.insert(QGamepadManager::ButtonR1, Qt::Key_Forward);
- d->keyMapping.insert(QGamepadManager::ButtonL2, Qt::Key_Back);
- d->keyMapping.insert(QGamepadManager::ButtonR2, Qt::Key_Forward);
- d->keyMapping.insert(QGamepadManager::ButtonL3, Qt::Key_Back);
- d->keyMapping.insert(QGamepadManager::ButtonR3, Qt::Key_Forward);
-
- connect(d->gamepadManger, SIGNAL(gamepadButtonPressEvent(int,QGamepadManager::GamepadButton,double)),
- this, SLOT(_q_processGamepadButtonPressEvent(int,QGamepadManager::GamepadButton,double)));
- connect(d->gamepadManger, SIGNAL(gamepadButtonReleaseEvent(int,QGamepadManager::GamepadButton)),
- this, SLOT(_q_processGamepadButtonReleaseEvent(int,QGamepadManager::GamepadButton)));
-}
-
-/*!
- * Returns whether key navigation on the gamepad is active or not.
-*/
-bool QGamepadKeyNavigation::active() const
-{
- Q_D(const QGamepadKeyNavigation);
- return d->active;
-}
-
-/*!
- * Returns a pointer the current QGamepad
- */
-QGamepad *QGamepadKeyNavigation::gamepad() const
-{
- Q_D(const QGamepadKeyNavigation);
- return d->gamepad;
-}
-
-/*!
- * Returns the key mapping of the Up button.
- */
-Qt::Key QGamepadKeyNavigation::upKey() const
-{
- Q_D(const QGamepadKeyNavigation);
- return d->keyMapping[QGamepadManager::ButtonUp];
-}
-
-/*!
- * Returns the key mapping of the Down button.
- */
-Qt::Key QGamepadKeyNavigation::downKey() const
-{
- Q_D(const QGamepadKeyNavigation);
- return d->keyMapping[QGamepadManager::ButtonDown];
-}
-
-/*!
- * Returns the key mapping of the Left button.
- */
-Qt::Key QGamepadKeyNavigation::leftKey() const
-{
- Q_D(const QGamepadKeyNavigation);
- return d->keyMapping[QGamepadManager::ButtonLeft];
-}
-
-/*!
- * Returns the key mapping of the Right button.
- */
-Qt::Key QGamepadKeyNavigation::rightKey() const
-{
- Q_D(const QGamepadKeyNavigation);
- return d->keyMapping[QGamepadManager::ButtonRight];
-}
-
-/*!
- * Returns the key mapping of A button.
- */
-Qt::Key QGamepadKeyNavigation::buttonAKey() const
-{
- Q_D(const QGamepadKeyNavigation);
- return d->keyMapping[QGamepadManager::ButtonA];
-}
-
-/*!
- * Returns the key mapping of the B button.
- */
-Qt::Key QGamepadKeyNavigation::buttonBKey() const
-{
- Q_D(const QGamepadKeyNavigation);
- return d->keyMapping[QGamepadManager::ButtonB];
-}
-
-/*!
- * Returns the key mapping of the X button.
- */
-Qt::Key QGamepadKeyNavigation::buttonXKey() const
-{
- Q_D(const QGamepadKeyNavigation);
- return d->keyMapping[QGamepadManager::ButtonX];
-}
-
-/*!
- * Returns the key mapping of the Y button.
- */
-Qt::Key QGamepadKeyNavigation::buttonYKey() const
-{
- Q_D(const QGamepadKeyNavigation);
- return d->keyMapping[QGamepadManager::ButtonY];
-}
-
-/*!
- * Returns the key mapping of the Select button.
- */
-Qt::Key QGamepadKeyNavigation::buttonSelectKey() const
-{
- Q_D(const QGamepadKeyNavigation);
- return d->keyMapping[QGamepadManager::ButtonSelect];
-}
-
-/*!
- * Returns the key mapping of the Start button.
- */
-Qt::Key QGamepadKeyNavigation::buttonStartKey() const
-{
- Q_D(const QGamepadKeyNavigation);
- return d->keyMapping[QGamepadManager::ButtonStart];
-}
-
-/*!
- * Returns the key mapping of the Guide button.
- */
-Qt::Key QGamepadKeyNavigation::buttonGuideKey() const
-{
- Q_D(const QGamepadKeyNavigation);
- return d->keyMapping[QGamepadManager::ButtonGuide];
-}
-
-/*!
- * Returns the key mapping of the left shoulder button.
- */
-Qt::Key QGamepadKeyNavigation::buttonL1Key() const
-{
- Q_D(const QGamepadKeyNavigation);
- return d->keyMapping[QGamepadManager::ButtonL1];
-}
-
-/*!
- * Returns the key mapping of the Right shoulder button.
- */
-Qt::Key QGamepadKeyNavigation::buttonR1Key() const
-{
- Q_D(const QGamepadKeyNavigation);
- return d->keyMapping[QGamepadManager::ButtonL2];
-}
-
-/*!
- * Returns the key mapping of the left trigger button.
- */
-Qt::Key QGamepadKeyNavigation::buttonL2Key() const
-{
- Q_D(const QGamepadKeyNavigation);
- return d->keyMapping[QGamepadManager::ButtonL2];
-}
-
-/*!
- * Returns the key mapping of the Right trigger button.
- */
-Qt::Key QGamepadKeyNavigation::buttonR2Key() const
-{
- Q_D(const QGamepadKeyNavigation);
- return d->keyMapping[QGamepadManager::ButtonL2];
-}
-
-/*!
- * Returns the key mapping of the left stick button.
- */
-Qt::Key QGamepadKeyNavigation::buttonL3Key() const
-{
- Q_D(const QGamepadKeyNavigation);
- return d->keyMapping[QGamepadManager::ButtonL3];
-}
-
-/*!
- * Returns the key mapping of the right stick button.
- */
-Qt::Key QGamepadKeyNavigation::buttonR3Key() const
-{
- Q_D(const QGamepadKeyNavigation);
- return d->keyMapping[QGamepadManager::ButtonL3];
-}
-
-/*!
- * Activates key navigation if \a isActive is true,
- * disables it otherwise.
- */
-void QGamepadKeyNavigation::setActive(bool isActive)
-{
- Q_D(QGamepadKeyNavigation);
- if (d->active != isActive) {
- d->active = isActive;
- emit activeChanged(isActive);
- }
-}
-
-/*!
- * Selects the specified \a gamepad.
-*/
-void QGamepadKeyNavigation::setGamepad(QGamepad *gamepad)
-{
- Q_D(QGamepadKeyNavigation);
- if (d->gamepad != gamepad) {
- d->gamepad = gamepad;
- emit gamepadChanged(gamepad);
- }
-}
-
-/*!
- * Sets the mapping of the Up button with the
- * keycode specified in \a key.
-*/
-void QGamepadKeyNavigation::setUpKey(Qt::Key key)
-{
- Q_D(QGamepadKeyNavigation);
- if (d->keyMapping[QGamepadManager::ButtonUp] != key) {
- d->keyMapping[QGamepadManager::ButtonUp] = key;
- emit upKeyChanged(key);
- }
-}
-
-/*!
- * Sets the mapping of the Down button with the
- * keycode specified in \a key.
-*/
-void QGamepadKeyNavigation::setDownKey(Qt::Key key)
-{
- Q_D(QGamepadKeyNavigation);
- if (d->keyMapping[QGamepadManager::ButtonDown] != key) {
- d->keyMapping[QGamepadManager::ButtonDown] = key;
- emit downKeyChanged(key);
- }
-}
-
-/*!
- * Sets the mapping of the Left button with the
- * keycode specified in \a key.
-*/
-void QGamepadKeyNavigation::setLeftKey(Qt::Key key)
-{
- Q_D(QGamepadKeyNavigation);
- if (d->keyMapping[QGamepadManager::ButtonLeft] != key) {
- d->keyMapping[QGamepadManager::ButtonLeft] = key;
- emit leftKeyChanged(key);
- }
-}
-
-/*!
- * Sets the mapping of the Right button with the
- * keycode specified in \a key.
-*/
-void QGamepadKeyNavigation::setRightKey(Qt::Key key)
-{
- Q_D(QGamepadKeyNavigation);
- if (d->keyMapping[QGamepadManager::ButtonRight] != key) {
- d->keyMapping[QGamepadManager::ButtonRight] = key;
- emit rightKeyChanged(key);
- }
-}
-
-/*!
- * Sets the mapping of the A button with the keycode
- * specified in \a key.
-*/
-void QGamepadKeyNavigation::setButtonAKey(Qt::Key key)
-{
- Q_D(QGamepadKeyNavigation);
- if (d->keyMapping[QGamepadManager::ButtonA] != key) {
- d->keyMapping[QGamepadManager::ButtonA] = key;
- emit buttonAKeyChanged(key);
- }
-}
-
-/*!
- * Sets the mapping of the B button with the keycode
- * specified in \a key.
-*/
-void QGamepadKeyNavigation::setButtonBKey(Qt::Key key)
-{
- Q_D(QGamepadKeyNavigation);
- if (d->keyMapping[QGamepadManager::ButtonB] != key) {
- d->keyMapping[QGamepadManager::ButtonB] = key;
- emit buttonBKeyChanged(key);
- }
-}
-
-/*!
- * Sets the mapping of the X button with the
- * keycode specified in \a key.
-*/
-void QGamepadKeyNavigation::setButtonXKey(Qt::Key key)
-{
- Q_D(QGamepadKeyNavigation);
- if (d->keyMapping[QGamepadManager::ButtonX] != key) {
- d->keyMapping[QGamepadManager::ButtonX] = key;
- emit buttonXKeyChanged(key);
- }
-}
-
-/*!
- * Sets the mapping of the Y button with the
- * keycode specified in \a key.
-*/
-void QGamepadKeyNavigation::setButtonYKey(Qt::Key key)
-{
- Q_D(QGamepadKeyNavigation);
- if (d->keyMapping[QGamepadManager::ButtonY] != key) {
- d->keyMapping[QGamepadManager::ButtonY] = key;
- emit buttonYKeyChanged(key);
- }
-}
-
-/*!
- * Sets the mapping of the Select button with the
- * keycode specified in \a key.
-*/
-void QGamepadKeyNavigation::setButtonSelectKey(Qt::Key key)
-{
- Q_D(QGamepadKeyNavigation);
- if (d->keyMapping[QGamepadManager::ButtonSelect] != key) {
- d->keyMapping[QGamepadManager::ButtonSelect] = key;
- emit buttonSelectKeyChanged(key);
- }
-}
-
-/*!
- * Sets the mapping of the Start button with the
- * keycode specified in \a key.
-*/
-void QGamepadKeyNavigation::setButtonStartKey(Qt::Key key)
-{
- Q_D(QGamepadKeyNavigation);
- if (d->keyMapping[QGamepadManager::ButtonStart] != key) {
- d->keyMapping[QGamepadManager::ButtonStart] = key;
- emit buttonStartKeyChanged(key);
- }
-}
-
-/*!
- * Sets the mapping of the Guide button with the keycode
- * specified in \a key.
-*/
-void QGamepadKeyNavigation::setButtonGuideKey(Qt::Key key)
-{
- Q_D(QGamepadKeyNavigation);
- if (d->keyMapping[QGamepadManager::ButtonGuide] != key) {
- d->keyMapping[QGamepadManager::ButtonGuide] = key;
- emit buttonGuideKeyChanged(key);
- }
-}
-
-/*!
- * Sets the mapping of the left shoulder button with the
- * keycode specified in \a key.
-*/
-void QGamepadKeyNavigation::setButtonL1Key(Qt::Key key)
-{
- Q_D(QGamepadKeyNavigation);
- if (d->keyMapping[QGamepadManager::ButtonL1] != key) {
- d->keyMapping[QGamepadManager::ButtonL1] = key;
- emit buttonL1KeyChanged(key);
- }
-}
-
-/*!
- * Sets the mapping of the right shoulder button with the
- * keycode specified in \a key.
-*/
-void QGamepadKeyNavigation::setButtonR1Key(Qt::Key key)
-{
- Q_D(QGamepadKeyNavigation);
- if (d->keyMapping[QGamepadManager::ButtonR1] != key) {
- d->keyMapping[QGamepadManager::ButtonR1] = key;
- emit buttonR1KeyChanged(key);
- }
-}
-
-/*!
- * Sets the mapping of the left trigger button with the
- * keycode specified in \a key.
-*/
-void QGamepadKeyNavigation::setButtonL2Key(Qt::Key key)
-{
- Q_D(QGamepadKeyNavigation);
- if (d->keyMapping[QGamepadManager::ButtonL2] != key) {
- d->keyMapping[QGamepadManager::ButtonL2] = key;
- emit buttonL1KeyChanged(key);
- }
-}
-
-/*!
- * Sets the mapping of the right trigger button with the
- * keycode specified in \a key.
-*/
-void QGamepadKeyNavigation::setButtonR2Key(Qt::Key key)
-{
- Q_D(QGamepadKeyNavigation);
- if (d->keyMapping[QGamepadManager::ButtonR2] != key) {
- d->keyMapping[QGamepadManager::ButtonR2] = key;
- emit buttonR1KeyChanged(key);
- }
-}
-
-/*!
- * Sets the mapping of the left stick button with the
- * keycode specified in \a key.
-*/
-void QGamepadKeyNavigation::setButtonL3Key(Qt::Key key)
-{
- Q_D(QGamepadKeyNavigation);
- if (d->keyMapping[QGamepadManager::ButtonL3] != key) {
- d->keyMapping[QGamepadManager::ButtonL3] = key;
- emit buttonL1KeyChanged(key);
- }
-}
-
-/*!
- * Sets the mapping of the right stick button with the
- * keycode specified in \a key.
-*/
-void QGamepadKeyNavigation::setButtonR3Key(Qt::Key key)
-{
- Q_D(QGamepadKeyNavigation);
- if (d->keyMapping[QGamepadManager::ButtonR3] != key) {
- d->keyMapping[QGamepadManager::ButtonR3] = key;
- emit buttonR1KeyChanged(key);
- }
-}
-
-QT_END_NAMESPACE
-
-#include "moc_qgamepadkeynavigation.cpp"
diff --git a/src/gamepad/qgamepadkeynavigation.h b/src/gamepad/qgamepadkeynavigation.h
deleted file mode 100644
index fca7714..0000000
--- a/src/gamepad/qgamepadkeynavigation.h
+++ /dev/null
@@ -1,150 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Gamepad module
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGAMEPADKEYNAVIGATION_H
-#define QGAMEPADKEYNAVIGATION_H
-
-#include <QtCore/QObject>
-#include <QtCore/QMap>
-#include <QtGamepad/qtgamepadglobal.h>
-
-#include <QtGamepad/QGamepadManager>
-
-QT_BEGIN_NAMESPACE
-
-class QKeyEvent;
-class QGamepad;
-class QGamepadKeyNavigationPrivate;
-class Q_GAMEPAD_EXPORT QGamepadKeyNavigation : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged)
- Q_PROPERTY(QGamepad *gamepad READ gamepad WRITE setGamepad NOTIFY gamepadChanged)
- Q_PROPERTY(Qt::Key upKey READ upKey WRITE setUpKey NOTIFY upKeyChanged)
- Q_PROPERTY(Qt::Key downKey READ downKey WRITE setDownKey NOTIFY downKeyChanged)
- Q_PROPERTY(Qt::Key leftKey READ leftKey WRITE setLeftKey NOTIFY leftKeyChanged)
- Q_PROPERTY(Qt::Key rightKey READ rightKey WRITE setRightKey NOTIFY rightKeyChanged)
- Q_PROPERTY(Qt::Key buttonAKey READ buttonAKey WRITE setButtonAKey NOTIFY buttonAKeyChanged)
- Q_PROPERTY(Qt::Key buttonBKey READ buttonBKey WRITE setButtonBKey NOTIFY buttonBKeyChanged)
- Q_PROPERTY(Qt::Key buttonXKey READ buttonXKey WRITE setButtonXKey NOTIFY buttonXKeyChanged)
- Q_PROPERTY(Qt::Key buttonYKey READ buttonYKey WRITE setButtonYKey NOTIFY buttonYKeyChanged)
- Q_PROPERTY(Qt::Key buttonSelectKey READ buttonSelectKey WRITE setButtonSelectKey NOTIFY buttonSelectKeyChanged)
- Q_PROPERTY(Qt::Key buttonStartKey READ buttonStartKey WRITE setButtonStartKey NOTIFY buttonStartKeyChanged)
- Q_PROPERTY(Qt::Key buttonGuideKey READ buttonGuideKey WRITE setButtonGuideKey NOTIFY buttonGuideKeyChanged)
- Q_PROPERTY(Qt::Key buttonL1Key READ buttonL1Key WRITE setButtonL1Key NOTIFY buttonL1KeyChanged)
- Q_PROPERTY(Qt::Key buttonR1Key READ buttonR1Key WRITE setButtonR1Key NOTIFY buttonR1KeyChanged)
- Q_PROPERTY(Qt::Key buttonL2Key READ buttonL2Key WRITE setButtonL2Key NOTIFY buttonL2KeyChanged)
- Q_PROPERTY(Qt::Key buttonR2Key READ buttonR2Key WRITE setButtonR2Key NOTIFY buttonR2KeyChanged)
- Q_PROPERTY(Qt::Key buttonL3Key READ buttonL3Key WRITE setButtonL3Key NOTIFY buttonL3KeyChanged)
- Q_PROPERTY(Qt::Key buttonR3Key READ buttonR3Key WRITE setButtonR3Key NOTIFY buttonR3KeyChanged)
-public:
- explicit QGamepadKeyNavigation(QObject *parent = nullptr);
-
- bool active() const;
- QGamepad *gamepad() const;
-
- Qt::Key upKey() const;
- Qt::Key downKey() const;
- Qt::Key leftKey() const;
- Qt::Key rightKey() const;
- Qt::Key buttonAKey() const;
- Qt::Key buttonBKey() const;
- Qt::Key buttonXKey() const;
- Qt::Key buttonYKey() const;
- Qt::Key buttonSelectKey() const;
- Qt::Key buttonStartKey() const;
- Qt::Key buttonGuideKey() const;
- Qt::Key buttonL1Key() const;
- Qt::Key buttonR1Key() const;
- Qt::Key buttonL2Key() const;
- Qt::Key buttonR2Key() const;
- Qt::Key buttonL3Key() const;
- Qt::Key buttonR3Key() const;
-
-Q_SIGNALS:
- void activeChanged(bool isActive);
- void gamepadChanged(QGamepad *gamepad);
-
- void upKeyChanged(Qt::Key key);
- void downKeyChanged(Qt::Key key);
- void leftKeyChanged(Qt::Key key);
- void rightKeyChanged(Qt::Key key);
- void buttonAKeyChanged(Qt::Key key);
- void buttonBKeyChanged(Qt::Key key);
- void buttonXKeyChanged(Qt::Key key);
- void buttonYKeyChanged(Qt::Key key);
- void buttonSelectKeyChanged(Qt::Key key);
- void buttonStartKeyChanged(Qt::Key key);
- void buttonGuideKeyChanged(Qt::Key key);
- void buttonL1KeyChanged(Qt::Key key);
- void buttonR1KeyChanged(Qt::Key key);
- void buttonL2KeyChanged(Qt::Key key);
- void buttonR2KeyChanged(Qt::Key key);
- void buttonL3KeyChanged(Qt::Key key);
- void buttonR3KeyChanged(Qt::Key key);
-
-public Q_SLOTS:
- void setActive(bool isActive);
- void setGamepad(QGamepad *gamepad);
-
- void setUpKey(Qt::Key key);
- void setDownKey(Qt::Key key);
- void setLeftKey(Qt::Key key);
- void setRightKey(Qt::Key key);
- void setButtonAKey(Qt::Key key);
- void setButtonBKey(Qt::Key key);
- void setButtonXKey(Qt::Key key);
- void setButtonYKey(Qt::Key key);
- void setButtonSelectKey(Qt::Key key);
- void setButtonStartKey(Qt::Key key);
- void setButtonGuideKey(Qt::Key key);
- void setButtonL1Key(Qt::Key key);
- void setButtonR1Key(Qt::Key key);
- void setButtonL2Key(Qt::Key key);
- void setButtonR2Key(Qt::Key key);
- void setButtonL3Key(Qt::Key key);
- void setButtonR3Key(Qt::Key key);
-
-private:
- Q_DECLARE_PRIVATE(QGamepadKeyNavigation)
- Q_DISABLE_COPY(QGamepadKeyNavigation)
- Q_PRIVATE_SLOT(d_func(), void _q_processGamepadButtonPressEvent(int, QGamepadManager::GamepadButton, double))
- Q_PRIVATE_SLOT(d_func(), void _q_processGamepadButtonReleaseEvent(int, QGamepadManager::GamepadButton))
-};
-
-QT_END_NAMESPACE
-
-#endif // QGAMEPADKEYNAVIGATION_H
diff --git a/src/gamepad/qgamepadmanager.cpp b/src/gamepad/qgamepadmanager.cpp
deleted file mode 100644
index c1dc740..0000000
--- a/src/gamepad/qgamepadmanager.cpp
+++ /dev/null
@@ -1,308 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Gamepad module
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgamepadmanager.h"
-
-#include "qgamepadbackend_p.h"
-#include "qgamepadbackendfactory_p.h"
-
-#include <QtCore/QLoggingCategory>
-
-#include <private/qobject_p.h>
-
-QT_BEGIN_NAMESPACE
-
-Q_LOGGING_CATEGORY(gp, "qt.gamepad")
-
-class QGamepadManagerPrivate : public QObjectPrivate
-{
- Q_DECLARE_PUBLIC(QGamepadManager)
-public:
- QGamepadManagerPrivate()
- : gamepadBackend(nullptr)
- {
- loadBackend();
- }
-
- void loadBackend();
-
- QGamepadBackend *gamepadBackend;
- QMap<int, QString> connectedGamepads;
-
- // private slots
- void _q_forwardGamepadConnected(int deviceId);
- void _q_forwardGamepadNameChanged(int deviceId, const QString &name);
- void _q_forwardGamepadDisconnected(int deviceId);
- void _q_forwardGamepadAxisEvent(int deviceId, QGamepadManager::GamepadAxis axis, double value);
- void _q_forwardGamepadButtonPressEvent(int deviceId, QGamepadManager::GamepadButton button, double value);
- void _q_forwardGamepadButtonReleaseEvent(int deviceId, QGamepadManager::GamepadButton button);
-};
-
-void QGamepadManagerPrivate::_q_forwardGamepadConnected(int deviceId)
-{
- Q_Q(QGamepadManager);
- connectedGamepads.insert(deviceId, QString());
- emit q->gamepadConnected(deviceId);
- emit q->connectedGamepadsChanged();
-}
-
-void QGamepadManagerPrivate::_q_forwardGamepadNameChanged(int deviceId, const QString &name)
-{
- Q_Q(QGamepadManager);
- connectedGamepads.insert(deviceId, name);
- emit q->gamepadNameChanged(deviceId, name);
-}
-
-void QGamepadManagerPrivate::_q_forwardGamepadDisconnected(int deviceId)
-{
- Q_Q(QGamepadManager);
- connectedGamepads.remove(deviceId);
- emit q->gamepadDisconnected(deviceId);
- emit q->connectedGamepadsChanged();
-}
-
-void QGamepadManagerPrivate::_q_forwardGamepadAxisEvent(int deviceId, QGamepadManager::GamepadAxis axis, double value)
-{
- Q_Q(QGamepadManager);
- emit q->gamepadAxisEvent(deviceId, axis, value);
-}
-
-void QGamepadManagerPrivate::_q_forwardGamepadButtonPressEvent(int deviceId, QGamepadManager::GamepadButton button, double value)
-{
- Q_Q(QGamepadManager);
- emit q->gamepadButtonPressEvent(deviceId, button, value);
-}
-
-void QGamepadManagerPrivate::_q_forwardGamepadButtonReleaseEvent(int deviceId, QGamepadManager::GamepadButton button)
-{
- Q_Q(QGamepadManager);
- emit q->gamepadButtonReleaseEvent(deviceId, button);
-}
-
-void QGamepadManagerPrivate::loadBackend()
-{
- QStringList keys = QGamepadBackendFactory::keys();
- qCDebug(gp) << "Available backends:" << keys;
- if (!keys.isEmpty()) {
- QString requestedKey = QString::fromUtf8(qgetenv("QT_GAMEPAD"));
- QString targetKey = keys.first();
- if (!requestedKey.isEmpty() && keys.contains(requestedKey))
- targetKey = requestedKey;
- if (!targetKey.isEmpty()) {
- qCDebug(gp) << "Loading backend" << targetKey;
- gamepadBackend = QGamepadBackendFactory::create(targetKey, QStringList());
- }
- }
-
- if (!gamepadBackend) {
- // Use dummy backend
- gamepadBackend = new QGamepadBackend();
- qCDebug(gp) << "Using dummy backend";
- }
-}
-
-/*!
- \class QGamepadManager
- \inmodule QtGamepad
- \brief Queries attached gamepads and related events.
-
- QGamepadManager provides a high-level interface for querying the attached
- gamepads and events related to all of the connected devices.
- */
-
-/*!
- * \qmltype GamepadManager
- * \inqmlmodule QtGamepad
- * \instantiates QGamepadManager
- * \brief Queries attached gamepads and related events.
- *
- * GamepadManager QML type provides a high-level interface for
- * querying the attached gamepads and events related to all of the
- * connected devices.
- */
-
-/*!
- * Constructor for QGamepadManager.
- */
-
-QGamepadManager::QGamepadManager() :
- QObject(*new QGamepadManagerPrivate(), nullptr)
-{
- Q_D(QGamepadManager);
-
- qRegisterMetaType<QGamepadManager::GamepadButton>("QGamepadManager::GamepadButton");
- qRegisterMetaType<QGamepadManager::GamepadAxis>("QGamepadManager::GamepadAxis");
-
- connect(d->gamepadBackend, SIGNAL(gamepadAdded(int)), this, SLOT(_q_forwardGamepadConnected(int)));
- connect(d->gamepadBackend, SIGNAL(gamepadNamed(int, QString)), this, SLOT(_q_forwardGamepadNameChanged(int, QString)));
- connect(d->gamepadBackend, SIGNAL(gamepadRemoved(int)), this, SLOT(_q_forwardGamepadDisconnected(int)));
- connect(d->gamepadBackend, SIGNAL(gamepadAxisMoved(int,QGamepadManager::GamepadAxis,double)), this, SLOT(_q_forwardGamepadAxisEvent(int,QGamepadManager::GamepadAxis,double)));
- connect(d->gamepadBackend, SIGNAL(gamepadButtonPressed(int,QGamepadManager::GamepadButton,double)), this, SLOT(_q_forwardGamepadButtonPressEvent(int,QGamepadManager::GamepadButton,double)));
- connect(d->gamepadBackend, SIGNAL(gamepadButtonReleased(int,QGamepadManager::GamepadButton)), this, SLOT(_q_forwardGamepadButtonReleaseEvent(int,QGamepadManager::GamepadButton)));
-
- connect(d->gamepadBackend, &QGamepadBackend::buttonConfigured, this, &QGamepadManager::buttonConfigured);
- connect(d->gamepadBackend, &QGamepadBackend::axisConfigured, this, &QGamepadManager::axisConfigured);
- connect(d->gamepadBackend, &QGamepadBackend::configurationCanceled, this, &QGamepadManager::configurationCanceled);
-
- if (!d->gamepadBackend->start())
- qCWarning(gp) << "Failed to start gamepad backend";
-}
-
-/*!
- * Destructor for QGamepadManager.
- */
-
-QGamepadManager::~QGamepadManager()
-{
- Q_D(QGamepadManager);
- d->gamepadBackend->stop();
- d->gamepadBackend->deleteLater();
-}
-
-/*!
- Returns the instance of the QGamepadManager.
-*/
-QGamepadManager *QGamepadManager::instance()
-{
- static QGamepadManager instance;
- return &instance;
-}
-
-/*!
- Returns a boolean indicating whether the gamepad with
- the specified \a deviceId is connected or not.
-*/
-bool QGamepadManager::isGamepadConnected(int deviceId) const
-{
- Q_D(const QGamepadManager);
- return d->connectedGamepads.contains(deviceId);
-}
-
-/*!
- Returns the name of the gamepad identified by \a deviceId.
- If \a deviceId does not identify a connected gamepad, returns an empty string.
-
- \since 5.11
-*/
-QString QGamepadManager::gamepadName(int deviceId) const
-{
- Q_D(const QGamepadManager);
- return d->connectedGamepads.value(deviceId);
-}
-
-/*!
- \qmlproperty var GamepadManager::connectedGamepads
- \readonly
-
- Returns a list of integers containing the \l {QGamepad::}{deviceId}
- values of the connected gamepads.
-*/
-
-/*!
- Returns a list of integers containing the \l {QGamepad::}{deviceId}
- values of the connected gamepads.
-*/
-const QList<int> QGamepadManager::connectedGamepads() const
-{
- Q_D(const QGamepadManager);
- return d->connectedGamepads.keys();
-}
-
-/*!
- Returns a boolean indicating whether configuration
- is needed for the specified \a deviceId.
-*/
-bool QGamepadManager::isConfigurationNeeded(int deviceId) const
-{
- Q_D(const QGamepadManager);
- return d->gamepadBackend->isConfigurationNeeded(deviceId);
-}
-
-/*!
- Configures the specified \a button on the gamepad with
- this \a deviceId.
- Returns \c true in case of success.
-*/
-bool QGamepadManager::configureButton(int deviceId, QGamepadManager::GamepadButton button)
-{
- Q_D(QGamepadManager);
- return d->gamepadBackend->configureButton(deviceId, button);
-}
-
-/*!
- Configures \a axis on the gamepad with the specified \a deviceId.
- Returns \c true in case of success.
-*/
-bool QGamepadManager::configureAxis(int deviceId, QGamepadManager::GamepadAxis axis)
-{
- Q_D(QGamepadManager);
- return d->gamepadBackend->configureAxis(deviceId, axis);
-}
-
-/*!
- Configures \a button as the cancel button on the gamepad with
- id \a deviceId.
- Returns \c true in case of success.
-*/
-bool QGamepadManager::setCancelConfigureButton(int deviceId, QGamepadManager::GamepadButton button)
-{
- Q_D(QGamepadManager);
- return d->gamepadBackend->setCancelConfigureButton(deviceId, button);
-}
-
-/*!
- Resets the configuration on the gamepad with the
- specified \a deviceId.
-*/
-void QGamepadManager::resetConfiguration(int deviceId)
-{
- Q_D(QGamepadManager);
- d->gamepadBackend->resetConfiguration(deviceId);
-}
-
-/*!
- Sets the name of the \a file that stores the button and axis
- configuration data.
-*/
-void QGamepadManager::setSettingsFile(const QString &file)
-{
- Q_D(QGamepadManager);
- d->gamepadBackend->setSettingsFile(file);
-}
-
-QT_END_NAMESPACE
-
-#include "moc_qgamepadmanager.cpp"
diff --git a/src/gamepad/qgamepadmanager.h b/src/gamepad/qgamepadmanager.h
deleted file mode 100644
index 56b6e6f..0000000
--- a/src/gamepad/qgamepadmanager.h
+++ /dev/null
@@ -1,135 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Gamepad module
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGAMEPADMANAGER_H
-#define QGAMEPADMANAGER_H
-
-#include <QtCore/QObject>
-#include <QtCore/QMap>
-#include <QtGamepad/qtgamepadglobal.h>
-
-QT_BEGIN_NAMESPACE
-
-class QGamepadBackend;
-class QGamepad;
-class QGamepadManagerPrivate;
-
-class Q_GAMEPAD_EXPORT QGamepadManager : public QObject
-{
- Q_OBJECT
- Q_FLAGS(GamepadButton GamepadButtons)
- Q_FLAGS(GamepadAxis GamepadAxes)
- Q_PROPERTY(QList<int> connectedGamepads READ connectedGamepads NOTIFY connectedGamepadsChanged)
-
-public:
- enum GamepadButton {
- ButtonInvalid = -1,
- ButtonA = 0,
- ButtonB,
- ButtonX,
- ButtonY,
- ButtonL1,
- ButtonR1,
- ButtonL2,
- ButtonR2,
- ButtonSelect,
- ButtonStart,
- ButtonL3,
- ButtonR3,
- ButtonUp,
- ButtonDown,
- ButtonRight,
- ButtonLeft,
- ButtonCenter,
- ButtonGuide
- };
- Q_DECLARE_FLAGS(GamepadButtons, GamepadButton)
-
- enum GamepadAxis {
- AxisInvalid = -1,
- AxisLeftX = 0,
- AxisLeftY,
- AxisRightX,
- AxisRightY
- };
- Q_DECLARE_FLAGS(GamepadAxes, GamepadAxis)
-
- static QGamepadManager* instance();
-
- bool isGamepadConnected(int deviceId) const;
- QString gamepadName(int deviceId) const;
- const QList<int> connectedGamepads() const;
-
-public Q_SLOTS:
- bool isConfigurationNeeded(int deviceId) const;
- bool configureButton(int deviceId, GamepadButton button);
- bool configureAxis(int deviceId, GamepadAxis axis);
- bool setCancelConfigureButton(int deviceId, GamepadButton button);
- void resetConfiguration(int deviceId);
- void setSettingsFile(const QString &file);
-
-Q_SIGNALS:
- void connectedGamepadsChanged();
- void gamepadConnected(int deviceId);
- void gamepadNameChanged(int deviceId, const QString &name);
- void gamepadDisconnected(int deviceId);
- void gamepadAxisEvent(int deviceId, QGamepadManager::GamepadAxis axis, double value);
- void gamepadButtonPressEvent(int deviceId, QGamepadManager::GamepadButton button, double value);
- void gamepadButtonReleaseEvent(int deviceId, QGamepadManager::GamepadButton button);
- void buttonConfigured(int deviceId, QGamepadManager::GamepadButton button);
- void axisConfigured(int deviceId, QGamepadManager::GamepadAxis axis);
- void configurationCanceled(int deviceId);
-
-private:
- QGamepadManager();
- ~QGamepadManager();
-
- Q_DECLARE_PRIVATE(QGamepadManager)
- Q_DISABLE_COPY(QGamepadManager)
- Q_PRIVATE_SLOT(d_func(), void _q_forwardGamepadConnected(int))
- Q_PRIVATE_SLOT(d_func(), void _q_forwardGamepadNameChanged(int, const QString&))
- Q_PRIVATE_SLOT(d_func(), void _q_forwardGamepadDisconnected(int))
- Q_PRIVATE_SLOT(d_func(), void _q_forwardGamepadAxisEvent(int, QGamepadManager::GamepadAxis, double))
- Q_PRIVATE_SLOT(d_func(), void _q_forwardGamepadButtonPressEvent(int, QGamepadManager::GamepadButton, double))
- Q_PRIVATE_SLOT(d_func(), void _q_forwardGamepadButtonReleaseEvent(int, QGamepadManager::GamepadButton))
-};
-
-QT_END_NAMESPACE
-
-Q_DECLARE_METATYPE(QGamepadManager::GamepadButton)
-Q_DECLARE_METATYPE(QGamepadManager::GamepadAxis)
-
-#endif // QGAMEPADMANAGER_H
diff --git a/src/gamepad/qtgamepadglobal.h b/src/gamepad/qtgamepadglobal.h
deleted file mode 100644
index 22d1f03..0000000
--- a/src/gamepad/qtgamepadglobal.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Gamepad module
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QTGAMEPADGLOBAL_H
-#define QTGAMEPADGLOBAL_H
-
-#include <QtCore/qglobal.h>
-
-QT_BEGIN_NAMESPACE
-
-#ifndef Q_GAMEPAD_EXPORT
-# ifndef QT_STATIC
-# if defined(QT_BUILD_GAMEPAD_LIB)
-# define Q_GAMEPAD_EXPORT Q_DECL_EXPORT
-# else
-# define Q_GAMEPAD_EXPORT Q_DECL_IMPORT
-# endif
-# else
-# define Q_GAMEPAD_EXPORT
-# endif
-#endif
-
-QT_END_NAMESPACE
-
-#endif