diff options
author | BogDan Vatra <bogdan@kdab.com> | 2015-10-26 12:38:33 +0200 |
---|---|---|
committer | Andy Nichols <andy.nichols@theqtcompany.com> | 2015-10-26 12:40:37 +0000 |
commit | c32e995bc79035e600893e91fdcec984f8293c75 (patch) | |
tree | 6de9a857b695fedfb3a52c5e4e34334759a09acc /examples | |
parent | 00871e531f7fb44feb3dac7abfe4eff0af5dfada (diff) |
Enable the usage of unknown gamepads.
Allowing the user to configure every button & axis of (s)his gamepad,
will enable the usage of any gamepad.
Currently only evdev backed has this feature.
Change-Id: I6e0692980e77b448d20d5ba818b787a7b89e7257
Reviewed-by: Andy Nichols <andy.nichols@theqtcompany.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/configureButtons/configureButtons.pro | 19 | ||||
-rw-r--r-- | examples/configureButtons/deployment.pri | 14 | ||||
-rw-r--r-- | examples/configureButtons/main.cpp | 48 | ||||
-rw-r--r-- | examples/configureButtons/main.qml | 616 | ||||
-rw-r--r-- | examples/configureButtons/qml.qrc | 5 | ||||
-rw-r--r-- | examples/examples.pro | 3 | ||||
-rw-r--r-- | examples/keyNavigation/qml/main.qml | 7 | ||||
-rw-r--r-- | examples/mouseItem/qml/main.qml | 7 | ||||
-rw-r--r-- | examples/quickGamepad/qml/main.qml | 7 |
9 files changed, 721 insertions, 5 deletions
diff --git a/examples/configureButtons/configureButtons.pro b/examples/configureButtons/configureButtons.pro new file mode 100644 index 0000000..480f8fb --- /dev/null +++ b/examples/configureButtons/configureButtons.pro @@ -0,0 +1,19 @@ +TEMPLATE = app + +QT += qml quick gamepad + +SOURCES += main.cpp + +RESOURCES += qml.qrc + +# Additional import path used to resolve QML modules in Qt Creator's code model +QML_IMPORT_PATH = + +# Default rules for deployment. +include(deployment.pri) + +DISTFILES += \ + android/AndroidManifest.xml + +ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android + diff --git a/examples/configureButtons/deployment.pri b/examples/configureButtons/deployment.pri new file mode 100644 index 0000000..c89af25 --- /dev/null +++ b/examples/configureButtons/deployment.pri @@ -0,0 +1,14 @@ +unix:!android { + isEmpty(target.path) { + qnx { + target.path = /tmp/$${TARGET}/bin + } else { + target.path = /opt/$${TARGET}/bin + } + export(target.path) + } + INSTALLS += target +} + +export(INSTALLS) + diff --git a/examples/configureButtons/main.cpp b/examples/configureButtons/main.cpp new file mode 100644 index 0000000..4ee0220 --- /dev/null +++ b/examples/configureButtons/main.cpp @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** Copyright (C) 2015 BogDan Vatra <bogdan@kde.org> +** +** 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 <QGuiApplication> +#include <QQmlApplicationEngine> + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + + QQmlApplicationEngine engine; + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + + return app.exec(); +} + diff --git a/examples/configureButtons/main.qml b/examples/configureButtons/main.qml new file mode 100644 index 0000000..31d1cd7 --- /dev/null +++ b/examples/configureButtons/main.qml @@ -0,0 +1,616 @@ +/**************************************************************************** +** +** Copyright (C) 2015 BogDan Vatra <bogdan@kde.org> +** +** 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$ +** +****************************************************************************/ + +import QtQuick 2.5 +import QtQuick.Controls 1.4 + +import QtQuick 2.5 +import QtQuick.Controls 1.4 +import QtQuick.Layouts 1.2 +import QtQuick.Window 2.0 +import QtGamepad 1.0 + + +ApplicationWindow { + visible: true + title: qsTr("Configure gamepad") + + Component.onCompleted: { + if (Qt.platform.os === "android") + visibility = Window.Maximized + } + + property Button checkedButton: null + function pressButton(button) + { + if (checkedButton !== null && button !== checkedButton) + checkedButton.checked = false; + checkedButton = button + } + + Gamepad { + id: gamepad + deviceId: GamepadManager.connectedGamepads.length > 0 ? GamepadManager.connectedGamepads[0] : -1 + onDeviceIdChanged: GamepadManager.setCancelConfigureButton(deviceId, GamepadManager.ButtonStart); + } + + Connections { + target: GamepadManager + onButtonConfigured: pressButton(null) + onAxisConfigured: pressButton(null) + onConfigurationCanceled: pressButton(null) + } + + ColumnLayout { + anchors.fill: parent + + RowLayout { + Layout.fillWidth: true + Text { + text: qsTr("Connected gamepads") + } + ComboBox { + model: GamepadManager.connectedGamepads + onCurrentIndexChanged: gamepad.deviceId[GamepadManager.connectedGamepads[currentIndex]] + } + } + + Text { + Layout.fillWidth: true + text: qsTr("Start button cancel's current configuration") + } + + RowLayout { + Layout.fillWidth: true + Layout.fillHeight: true + GroupBox { + title: qsTr("Configure Gamepad Buttons") + Layout.fillWidth: true + Layout.fillHeight: true + + ColumnLayout { + anchors.fill: parent + RowLayout { + Layout.fillWidth: true + Text { + text: qsTr("ButtonA") + horizontalAlignment: Text.AlignRight + } + + Text { + text: gamepad.buttonA ? qsTr("DOWN") : qsTr("UP") + Layout.fillWidth: true + horizontalAlignment: Text.AlignHCenter + } + + Button { + text: qsTr("Configure") + checkable: true + enabled: !checked + onCheckedChanged: { + pressButton(this); + if (checked) + GamepadManager.configureButton(gamepad.deviceId, GamepadManager.ButtonA); + } + } + } + RowLayout { + Layout.fillWidth: true + Text { + text: qsTr("ButtonB") + horizontalAlignment: Text.AlignRight + } + Text { + text: gamepad.buttonB ? qsTr("DOWN") : qsTr("UP") + Layout.fillWidth: true + horizontalAlignment: Text.AlignHCenter + } + Button { + text: qsTr("Configure") + checkable: true + enabled: !checked + onCheckedChanged: { + pressButton(this); + if (checked) + GamepadManager.configureButton(gamepad.deviceId, GamepadManager.ButtonB); + } + } + } + RowLayout { + Layout.fillWidth: true + Text { + text: qsTr("ButtonX") + horizontalAlignment: Text.AlignRight + } + Text { + text: gamepad.buttonX ? qsTr("DOWN") : qsTr("UP") + Layout.fillWidth: true + horizontalAlignment: Text.AlignHCenter + } + Button { + text: qsTr("Configure") + checkable: true + enabled: !checked + onCheckedChanged: { + pressButton(this); + if (checked) + GamepadManager.configureButton(gamepad.deviceId, GamepadManager.ButtonX); + } + } + } + RowLayout { + Layout.fillWidth: true + Text { + text: qsTr("ButtonY") + horizontalAlignment: Text.AlignRight + } + Text { + text: gamepad.buttonY ? qsTr("DOWN") : qsTr("UP") + Layout.fillWidth: true + horizontalAlignment: Text.AlignHCenter + } + Button { + text: qsTr("Configure") + checkable: true + enabled: !checked + onCheckedChanged: { + pressButton(this); + if (checked) + GamepadManager.configureButton(gamepad.deviceId, GamepadManager.ButtonY); + } + } + } + RowLayout { + Layout.fillWidth: true + Text { + text: qsTr("ButtonStart") + horizontalAlignment: Text.AlignRight + } + Text { + text: gamepad.buttonStart ? qsTr("DOWN") : qsTr("UP") + Layout.fillWidth: true + horizontalAlignment: Text.AlignHCenter + } + Button { + text: qsTr("Configure") + checkable: true + enabled: !checked + onCheckedChanged: { + pressButton(this); + if (checked) + GamepadManager.configureButton(gamepad.deviceId, GamepadManager.ButtonStart); + } + } + } + RowLayout { + Layout.fillWidth: true + Text { + text: qsTr("ButtonSelect") + horizontalAlignment: Text.AlignRight + } + Text { + text: gamepad.buttonSelect ? qsTr("DOWN") : qsTr("UP") + Layout.fillWidth: true + horizontalAlignment: Text.AlignHCenter + } + Button { + text: qsTr("Configure") + checkable: true + enabled: !checked + onCheckedChanged: { + pressButton(this); + if (checked) + GamepadManager.configureButton(gamepad.deviceId, GamepadManager.ButtonSelect); + } + } + } + RowLayout { + Layout.fillWidth: true + Text { + text: qsTr("Button L1") + horizontalAlignment: Text.AlignRight + } + Text { + text: gamepad.buttonL1 ? qsTr("DOWN") : qsTr("UP") + Layout.fillWidth: true + horizontalAlignment: Text.AlignHCenter + } + Button { + text: qsTr("Configure") + checkable: true + enabled: !checked + onCheckedChanged: { + pressButton(this); + if (checked) + GamepadManager.configureButton(gamepad.deviceId, GamepadManager.ButtonL1); + } + } + } + RowLayout { + Layout.fillWidth: true + Text { + text: qsTr("Button R1") + horizontalAlignment: Text.AlignRight + } + Text { + text: gamepad.buttonR1 ? qsTr("DOWN") : qsTr("UP") + Layout.fillWidth: true + horizontalAlignment: Text.AlignHCenter + } + Button { + text: qsTr("Configure") + checkable: true + enabled: !checked + onCheckedChanged: { + pressButton(this); + if (checked) + GamepadManager.configureButton(gamepad.deviceId, GamepadManager.ButtonR1); + } + } + } + RowLayout { + Layout.fillWidth: true + Text { + text: qsTr("Button L2") + horizontalAlignment: Text.AlignRight + } + Text { + text: gamepad.buttonL2 ? qsTr("DOWN") : qsTr("UP") + Layout.fillWidth: true + horizontalAlignment: Text.AlignHCenter + } + Button { + text: qsTr("Configure") + checkable: true + enabled: !checked + onCheckedChanged: { + pressButton(this); + if (checked) + GamepadManager.configureButton(gamepad.deviceId, GamepadManager.ButtonL2); + } + } + } + RowLayout { + Layout.fillWidth: true + Text { + text: qsTr("Button R2") + horizontalAlignment: Text.AlignRight + } + Text { + text: gamepad.buttonR2 ? qsTr("DOWN") : qsTr("UP") + Layout.fillWidth: true + horizontalAlignment: Text.AlignHCenter + } + Button { + text: qsTr("Configure") + checkable: true + enabled: !checked + onCheckedChanged: { + pressButton(this); + if (checked) + GamepadManager.configureButton(gamepad.deviceId, GamepadManager.ButtonR2); + } + } + } + RowLayout { + Layout.fillWidth: true + Text { + text: qsTr("Button L3") + horizontalAlignment: Text.AlignRight + } + Text { + text: gamepad.buttonL3 ? qsTr("DOWN") : qsTr("UP") + Layout.fillWidth: true + horizontalAlignment: Text.AlignHCenter + } + Button { + text: qsTr("Configure") + checkable: true + enabled: !checked + onCheckedChanged: { + pressButton(this); + if (checked) + GamepadManager.configureButton(gamepad.deviceId, GamepadManager.ButtonL3); + } + } + } + RowLayout { + Layout.fillWidth: true + Text { + text: qsTr("Button R3") + horizontalAlignment: Text.AlignRight + } + Text { + text: gamepad.buttonR3 ? qsTr("DOWN") : qsTr("UP") + Layout.fillWidth: true + horizontalAlignment: Text.AlignHCenter + } + Button { + text: qsTr("Configure") + checkable: true + enabled: !checked + onCheckedChanged: { + pressButton(this); + if (checked) + GamepadManager.configureButton(gamepad.deviceId, GamepadManager.ButtonR3); + } + } + } + RowLayout { + Layout.fillWidth: true + Text { + text: qsTr("Button Up") + horizontalAlignment: Text.AlignRight + } + Text { + text: gamepad.buttonUp ? qsTr("DOWN") : qsTr("UP") + Layout.fillWidth: true + horizontalAlignment: Text.AlignHCenter + } + Button { + text: qsTr("Configure") + checkable: true + enabled: !checked + onCheckedChanged: { + pressButton(this); + if (checked) + GamepadManager.configureButton(gamepad.deviceId, GamepadManager.ButtonUp); + } + } + } + RowLayout { + Layout.fillWidth: true + Text { + text: qsTr("Button Down") + horizontalAlignment: Text.AlignRight + } + Text { + text: gamepad.buttonDown ? qsTr("DOWN") : qsTr("UP") + Layout.fillWidth: true + horizontalAlignment: Text.AlignHCenter + } + Button { + text: qsTr("Configure") + checkable: true + enabled: !checked + onCheckedChanged: { + pressButton(this); + if (checked) + GamepadManager.configureButton(gamepad.deviceId, GamepadManager.ButtonDown ); + } + } + } + RowLayout { + Layout.fillWidth: true + Text { + text: qsTr("Button Left") + horizontalAlignment: Text.AlignRight + } + Text { + Layout.fillWidth: true + text: gamepad.buttonLeft ? qsTr("DOWN") : qsTr("UP") + horizontalAlignment: Text.AlignHCenter + } + Button { + text: qsTr("Configure") + checkable: true + enabled: !checked + onCheckedChanged: { + pressButton(this); + if (checked) + GamepadManager.configureButton(gamepad.deviceId, GamepadManager.ButtonLeft); + } + } + } + RowLayout { + Layout.fillWidth: true + Text { + text: qsTr("Button Right") + horizontalAlignment: Text.AlignRight + } + Text { + Layout.fillWidth: true + text: gamepad.buttonRight ? qsTr("DOWN") : qsTr("UP") + horizontalAlignment: Text.AlignHCenter + } + Button { + text: qsTr("Configure") + checkable: true + enabled: !checked + onCheckedChanged: { + pressButton(this); + if (checked) + GamepadManager.configureButton(gamepad.deviceId, GamepadManager.ButtonRight); + } + } + } + RowLayout { + Layout.fillWidth: true + Text { + text: qsTr("Button Center") + horizontalAlignment: Text.AlignRight + } + Text { + Layout.fillWidth: true + text: gamepad.buttonCenter ? qsTr("DOWN") : qsTr("UP") + horizontalAlignment: Text.AlignHCenter + } + Button { + text: qsTr("Configure") + checkable: true + enabled: !checked + onCheckedChanged: { + pressButton(this); + if (checked) + GamepadManager.configureButton(gamepad.deviceId, GamepadManager.ButtonCenter); + } + } + } + RowLayout { + Layout.fillWidth: true + Text { + text: qsTr("Button Guide") + horizontalAlignment: Text.AlignRight + } + Text { + Layout.fillWidth: true + text: gamepad.buttonGuide ? qsTr("DOWN") : qsTr("UP") + horizontalAlignment: Text.AlignHCenter + } + Button { + text: qsTr("Configure") + checkable: true + enabled: !checked + onCheckedChanged: { + pressButton(this); + if (checked) + GamepadManager.configureButton(gamepad.deviceId, GamepadManager.ButtonGuide); + } + } + } + } + } + GroupBox { + title: qsTr("Gamepad Axies") + Layout.fillWidth: true + Layout.fillHeight: true + + ColumnLayout { + anchors.fill: parent + RowLayout { + Layout.fillWidth: true + Text { + text: qsTr("AxisLeftX") + horizontalAlignment: Text.AlignRight + } + + Text { + text: gamepad.axisLeftX + Layout.fillWidth: true + horizontalAlignment: Text.AlignHCenter + } + + Button { + text: qsTr("Configure") + checkable: true + enabled: !checked + onCheckedChanged: { + pressButton(this); + if (checked) + GamepadManager.configureAxis(gamepad.deviceId, GamepadManager.AxisLeftX); + } + } + } + RowLayout { + Layout.fillWidth: true + Text { + text: qsTr("AxisLeftY") + horizontalAlignment: Text.AlignRight + } + + Text { + text: gamepad.axisLeftY + Layout.fillWidth: true + horizontalAlignment: Text.AlignHCenter + } + + Button { + text: qsTr("Configure") + checkable: true + enabled: !checked + onCheckedChanged: { + pressButton(this); + if (checked) + GamepadManager.configureAxis(gamepad.deviceId, GamepadManager.AxisLeftY); + } + } + } + RowLayout { + Layout.fillWidth: true + Text { + text: qsTr("AxisRightX") + horizontalAlignment: Text.AlignRight + } + + Text { + text: gamepad.axisRightX + Layout.fillWidth: true + horizontalAlignment: Text.AlignHCenter + } + + Button { + text: qsTr("Configure") + checkable: true + enabled: !checked + onCheckedChanged: { + pressButton(this); + if (checked) + GamepadManager.configureAxis(gamepad.deviceId, GamepadManager.AxisRightX); + } + } + } + RowLayout { + Layout.fillWidth: true + Text { + text: qsTr("AxisRightY") + horizontalAlignment: Text.AlignRight + } + + Text { + text: gamepad.axisRightY + Layout.fillWidth: true + horizontalAlignment: Text.AlignHCenter + } + + Button { + text: qsTr("Configure") + checkable: true + enabled: !checked + onCheckedChanged: { + pressButton(this); + if (checked) + GamepadManager.configureAxis(gamepad.deviceId, GamepadManager.AxisRightY); + } + } + } + + Item { + Layout.fillHeight: true + } + } + } + } + } +} diff --git a/examples/configureButtons/qml.qrc b/examples/configureButtons/qml.qrc new file mode 100644 index 0000000..5f6483a --- /dev/null +++ b/examples/configureButtons/qml.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>main.qml</file> + </qresource> +</RCC> diff --git a/examples/examples.pro b/examples/examples.pro index 4461e4d..e5acdd9 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -5,5 +5,6 @@ SUBDIRS += simple \ qtHaveModule(quick) { SUBDIRS += quickGamepad \ - keyNavigation + keyNavigation \ + configureButtons } diff --git a/examples/keyNavigation/qml/main.qml b/examples/keyNavigation/qml/main.qml index 2c4106c..d58bfc5 100644 --- a/examples/keyNavigation/qml/main.qml +++ b/examples/keyNavigation/qml/main.qml @@ -51,7 +51,12 @@ ApplicationWindow { Gamepad { id: gamepad1 - index: 0 + deviceId: GamepadManager.connectedGamepads.length > 0 ? GamepadManager.connectedGamepads[0] : -1 + } + + Connections { + target: GamepadManager + onGamepadConnected: gamepad1.deviceId = deviceId } GamepadKeyNavigation { diff --git a/examples/mouseItem/qml/main.qml b/examples/mouseItem/qml/main.qml index 4ab1f8a..4c05e90 100644 --- a/examples/mouseItem/qml/main.qml +++ b/examples/mouseItem/qml/main.qml @@ -49,9 +49,14 @@ ApplicationWindow { height: 480 title: qsTr("Hello World") + Connections { + target: GamepadManager + onGamepadConnected: gamepad1.deviceId = deviceId + } + Gamepad { id: gamepad1 - index: 0 + deviceId: GamepadManager.connectedGamepads.length > 0 ? GamepadManager.connectedGamepads[0] : -1 onButtonAChanged: { if (value == true) { diff --git a/examples/quickGamepad/qml/main.qml b/examples/quickGamepad/qml/main.qml index 10b6674..049e72b 100644 --- a/examples/quickGamepad/qml/main.qml +++ b/examples/quickGamepad/qml/main.qml @@ -226,10 +226,13 @@ ApplicationWindow { } - + Connections { + target: GamepadManager + onGamepadConnected: gamepad.deviceId = deviceId + } Gamepad { id: gamepad + deviceId: GamepadManager.connectedGamepads.length > 0 ? GamepadManager.connectedGamepads[0] : -1 } - } |