mirror of https://github.com/qt/qtgamepad.git
Cleanup Examples
Change-Id: I36de0a3ba85b6b89547792badaa06c50f0e4ccc3 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
This commit is contained in:
parent
7aceda1389
commit
9c7ed97cf9
|
|
@ -14,6 +14,7 @@ examples/tutorials/*/*/*
|
||||||
!examples/tutorials/*
|
!examples/tutorials/*
|
||||||
!examples/tutorials/*/*
|
!examples/tutorials/*/*
|
||||||
!examples/ja_JP/*/*
|
!examples/ja_JP/*/*
|
||||||
|
!examples/*/*/qml/*
|
||||||
demos/*/*
|
demos/*/*
|
||||||
!demos/spectrum/*
|
!demos/spectrum/*
|
||||||
demos/spectrum/bin
|
demos/spectrum/bin
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -3,11 +3,13 @@ TEMPLATE = subdirs
|
||||||
SUBDIRS += simple
|
SUBDIRS += simple
|
||||||
|
|
||||||
qtHaveModule(quick) {
|
qtHaveModule(quick) {
|
||||||
SUBDIRS += configureButtons
|
SUBDIRS += \
|
||||||
|
mouseItem \
|
||||||
|
keyNavigation
|
||||||
|
|
||||||
qtHaveModule(widgets) {
|
qtHaveModule(quickcontrols2) {
|
||||||
SUBDIRS += quickGamepad \
|
SUBDIRS += \
|
||||||
keyNavigation \
|
configureButtons \
|
||||||
mouseItem
|
quickGamepad
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
|
|
||||||
QT += qml quick widgets
|
QT += qml quick
|
||||||
|
|
||||||
SOURCES += main.cpp
|
SOURCES += main.cpp
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,10 +40,10 @@
|
||||||
|
|
||||||
|
|
||||||
import QtQuick 2.2
|
import QtQuick 2.2
|
||||||
import QtQuick.Controls 1.1
|
import QtQuick.Window 2.0
|
||||||
import QtGamepad 1.0
|
import QtGamepad 1.0
|
||||||
|
|
||||||
ApplicationWindow {
|
Window {
|
||||||
visible: true
|
visible: true
|
||||||
width: 640
|
width: 640
|
||||||
height: 480
|
height: 480
|
||||||
|
|
|
||||||
|
|
@ -39,12 +39,12 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QGuiApplication>
|
||||||
#include <QQmlApplicationEngine>
|
#include <QQmlApplicationEngine>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
|
|
||||||
QQmlApplicationEngine engine;
|
QQmlApplicationEngine engine;
|
||||||
engine.load(QUrl(QStringLiteral("qrc:///qml/main.qml")));
|
engine.load(QUrl(QStringLiteral("qrc:///qml/main.qml")));
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
|
|
||||||
QT += qml quick widgets
|
QT += qml quick
|
||||||
|
|
||||||
SOURCES += main.cpp
|
SOURCES += main.cpp
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,16 +38,27 @@
|
||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
import QtQuick 2.2
|
import QtQuick 2.2
|
||||||
import QtQuick.Controls 1.1
|
import QtQuick.Window 2.0
|
||||||
import QtGamepad 1.0
|
import QtGamepad 1.0
|
||||||
|
|
||||||
ApplicationWindow {
|
Window {
|
||||||
visible: true
|
visible: true
|
||||||
width: 640
|
width: 640
|
||||||
height: 480
|
height: 480
|
||||||
title: qsTr("Hello World")
|
title: qsTr("Gamepad Mouse Item")
|
||||||
|
|
||||||
|
Text {
|
||||||
|
id: instructionLabel
|
||||||
|
anchors.centerIn: parent
|
||||||
|
text: qsTr("Simulate mouse input using a Gamepad")
|
||||||
|
}
|
||||||
|
Text {
|
||||||
|
id: outputLabel
|
||||||
|
anchors.horizontalCenter: instructionLabel.horizontalCenter
|
||||||
|
anchors.top: instructionLabel.bottom
|
||||||
|
text: ""
|
||||||
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: GamepadManager
|
target: GamepadManager
|
||||||
|
|
@ -61,9 +72,10 @@ ApplicationWindow {
|
||||||
onButtonAChanged: {
|
onButtonAChanged: {
|
||||||
if (value == true) {
|
if (value == true) {
|
||||||
gamepadMouse.mouseButtonPressed(Qt.LeftButton);
|
gamepadMouse.mouseButtonPressed(Qt.LeftButton);
|
||||||
console.log("fake clicked qt: " + gamepadMouse.mousePosition.x + "," + gamepadMouse.mousePosition.y);
|
outputLabel.text = "Mouse click at: " + gamepadMouse.mousePosition.x + "," + gamepadMouse.mousePosition.y;
|
||||||
} else {
|
} else {
|
||||||
gamepadMouse.mouseButtonReleased(Qt.LeftButton);
|
gamepadMouse.mouseButtonReleased(Qt.LeftButton);
|
||||||
|
outputLabel.text = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -76,18 +88,36 @@ ApplicationWindow {
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: cursor
|
id: cursor
|
||||||
width: 4
|
width: 9
|
||||||
height: 4
|
height: 9
|
||||||
|
radius: 4.5
|
||||||
x: gamepadMouse.mousePosition.x
|
x: gamepadMouse.mousePosition.x
|
||||||
y: gamepadMouse.mousePosition.y
|
y: gamepadMouse.mousePosition.y
|
||||||
color: "red"
|
color: "transparent"
|
||||||
|
border.color: "red"
|
||||||
|
Rectangle {
|
||||||
|
x: cursor.width * 0.5 - 0.5
|
||||||
|
y: 1
|
||||||
|
width: 1
|
||||||
|
height: cursor.height - 2
|
||||||
|
color: "black"
|
||||||
|
}
|
||||||
|
Rectangle {
|
||||||
|
x: 1
|
||||||
|
y: cursor.height * 0.5 - 0.5
|
||||||
|
height: 1
|
||||||
|
width: cursor.width - 2
|
||||||
|
color: "black"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked: {
|
onClicked: {
|
||||||
console.log("clicked qt: " + mouse.x + "," + mouse.y);
|
console.log("clicked at: " + mouse.x + "," + mouse.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,191 +39,174 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
import QtQuick 2.2
|
import QtQuick 2.2
|
||||||
import QtQuick.Controls 1.1
|
import QtQuick.Controls 2.0
|
||||||
|
import QtQuick.Layouts 1.1
|
||||||
|
import QtQuick.Window 2.0
|
||||||
import QtGamepad 1.0
|
import QtGamepad 1.0
|
||||||
|
|
||||||
ApplicationWindow {
|
Window {
|
||||||
id: applicationWindow1
|
id: applicationWindow1
|
||||||
visible: true
|
visible: true
|
||||||
width: 800
|
width: 800
|
||||||
height: 600
|
height: 600
|
||||||
title: qsTr("QtGamepad Example")
|
title: qsTr("QtGamepad Example")
|
||||||
|
color: "#363330"
|
||||||
|
|
||||||
Rectangle {
|
Item {
|
||||||
id: background
|
id: background
|
||||||
color: "#363330"
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
Item {
|
ColumnLayout {
|
||||||
id: buttonL2Item
|
anchors.fill: parent
|
||||||
height: leftTrigger.height
|
|
||||||
width: leftTrigger.width + buttonL2Value.width
|
|
||||||
anchors.left: parent.left
|
|
||||||
anchors.leftMargin: 8
|
|
||||||
anchors.top: parent.top
|
|
||||||
anchors.topMargin: 8
|
|
||||||
|
|
||||||
ButtonImage {
|
|
||||||
id: leftTrigger
|
|
||||||
anchors.top: parent.top
|
|
||||||
anchors.left: parent.left
|
|
||||||
anchors.bottom: parent.bottom
|
|
||||||
source: "xboxControllerLeftTrigger.png"
|
|
||||||
active: gamepad.buttonL2 != 0
|
|
||||||
}
|
|
||||||
|
|
||||||
ProgressBar {
|
|
||||||
id: buttonL2Value
|
|
||||||
anchors.top: parent.top
|
|
||||||
anchors.bottom: parent.bottom
|
|
||||||
anchors.left: leftTrigger.right
|
|
||||||
orientation: 0
|
|
||||||
value: gamepad.buttonL2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ButtonImage {
|
|
||||||
id: buttonL1
|
|
||||||
anchors.left: buttonL2Item.left
|
|
||||||
anchors.top: buttonL2Item.bottom
|
|
||||||
anchors.topMargin: 8
|
|
||||||
source: "xboxControllerLeftShoulder.png"
|
|
||||||
active: gamepad.buttonL1
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Item {
|
|
||||||
id: buttonR2Item
|
|
||||||
height: rightTrigger.height
|
|
||||||
width: rightTrigger.width + buttonR2Value.width
|
|
||||||
anchors.right: parent.right
|
|
||||||
anchors.rightMargin: 8
|
|
||||||
anchors.top: parent.top
|
|
||||||
anchors.topMargin: 8
|
|
||||||
|
|
||||||
ButtonImage {
|
|
||||||
id: rightTrigger
|
|
||||||
anchors.top: parent.top
|
|
||||||
anchors.right: parent.right
|
|
||||||
anchors.bottom: parent.bottom
|
|
||||||
source: "xboxControllerRightTrigger.png"
|
|
||||||
active: gamepad.buttonR2 != 0
|
|
||||||
}
|
|
||||||
|
|
||||||
ProgressBar {
|
|
||||||
id: buttonR2Value
|
|
||||||
anchors.top: parent.top
|
|
||||||
anchors.bottom: parent.bottom
|
|
||||||
anchors.right: rightTrigger.left
|
|
||||||
orientation: 0
|
|
||||||
value: gamepad.buttonR2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ButtonImage {
|
|
||||||
id: buttonR1
|
|
||||||
anchors.right: buttonR2Item.right
|
|
||||||
anchors.top: buttonR2Item.bottom
|
|
||||||
anchors.topMargin: 8
|
|
||||||
source: "xboxControllerRightShoulder.png"
|
|
||||||
active: gamepad.buttonR1
|
|
||||||
}
|
|
||||||
|
|
||||||
Item {
|
|
||||||
id: centerButtons
|
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
|
||||||
anchors.top: parent.top
|
|
||||||
anchors.topMargin: 8
|
|
||||||
height: guideButton.height
|
|
||||||
width: guideButton.width + 16 + backButton.width + startButton.width
|
|
||||||
ButtonImage {
|
|
||||||
id: backButton
|
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
|
||||||
anchors.right: guideButton.left
|
|
||||||
anchors.rightMargin: 8
|
|
||||||
source: "xboxControllerBack.png"
|
|
||||||
active: gamepad.buttonSelect
|
|
||||||
}
|
|
||||||
ButtonImage {
|
|
||||||
id: guideButton
|
|
||||||
anchors.centerIn: parent
|
|
||||||
source: "xboxControllerButtonGuide.png"
|
|
||||||
active: gamepad.buttonGuide
|
|
||||||
}
|
|
||||||
ButtonImage {
|
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
|
||||||
anchors.left: guideButton.right
|
|
||||||
anchors.leftMargin: 8
|
|
||||||
id: startButton
|
|
||||||
source: "xboxControllerStart.png"
|
|
||||||
active: gamepad.buttonStart
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DPad {
|
|
||||||
id: dPad
|
|
||||||
gamepad: gamepad
|
|
||||||
anchors.left: parent.left
|
|
||||||
anchors.bottom: parent.bottom
|
|
||||||
anchors.margins: 8
|
anchors.margins: 8
|
||||||
}
|
RowLayout {
|
||||||
|
id: topRow
|
||||||
|
width: parent.width
|
||||||
|
ColumnLayout {
|
||||||
|
id: buttonL2Item
|
||||||
|
Layout.alignment: Qt.AlignLeft
|
||||||
|
ButtonImage {
|
||||||
|
id: leftTrigger
|
||||||
|
Layout.alignment: Qt.AlignCenter
|
||||||
|
source: "xboxControllerLeftTrigger.png"
|
||||||
|
active: gamepad.buttonL2 != 0
|
||||||
|
}
|
||||||
|
ProgressBar {
|
||||||
|
id: buttonL2Value
|
||||||
|
width: leftTrigger.width
|
||||||
|
value: gamepad.buttonL2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Row {
|
Item {
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
id: centerButtons
|
||||||
anchors.bottom: parent.bottom
|
Layout.alignment: Qt.AlignCenter
|
||||||
anchors.margins: 8
|
Layout.fillWidth: true
|
||||||
spacing: 16
|
height: guideButton.height
|
||||||
|
width: guideButton.width + 16 + backButton.width + startButton.width
|
||||||
|
ButtonImage {
|
||||||
|
id: backButton
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
anchors.right: guideButton.left
|
||||||
|
anchors.rightMargin: 8
|
||||||
|
source: "xboxControllerBack.png"
|
||||||
|
active: gamepad.buttonSelect
|
||||||
|
}
|
||||||
|
ButtonImage {
|
||||||
|
id: guideButton
|
||||||
|
anchors.centerIn: parent
|
||||||
|
source: "xboxControllerButtonGuide.png"
|
||||||
|
active: gamepad.buttonGuide
|
||||||
|
}
|
||||||
|
ButtonImage {
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
anchors.left: guideButton.right
|
||||||
|
anchors.leftMargin: 8
|
||||||
|
id: startButton
|
||||||
|
source: "xboxControllerStart.png"
|
||||||
|
active: gamepad.buttonStart
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
LeftThumbstick {
|
|
||||||
id: leftThumbstick
|
ColumnLayout {
|
||||||
gamepad: gamepad
|
id: buttonR2Item
|
||||||
|
Layout.alignment: Qt.AlignRight
|
||||||
|
ButtonImage {
|
||||||
|
id: rightTrigger
|
||||||
|
Layout.alignment: Qt.AlignCenter
|
||||||
|
source: "xboxControllerRightTrigger.png"
|
||||||
|
active: gamepad.buttonR2 != 0
|
||||||
|
}
|
||||||
|
|
||||||
|
ProgressBar {
|
||||||
|
id: buttonR2Value
|
||||||
|
width: rightTrigger.width
|
||||||
|
value: gamepad.buttonR2
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RightThumbstick {
|
RowLayout {
|
||||||
id: rightThumbstick
|
id: middleRow
|
||||||
gamepad: gamepad
|
ButtonImage {
|
||||||
|
id: buttonL1
|
||||||
|
source: "xboxControllerLeftShoulder.png"
|
||||||
|
active: gamepad.buttonL1
|
||||||
|
}
|
||||||
|
Item {
|
||||||
|
id: spacer1
|
||||||
|
Layout.fillWidth: true
|
||||||
|
}
|
||||||
|
|
||||||
|
ButtonImage {
|
||||||
|
id: buttonR1
|
||||||
|
source: "xboxControllerRightShoulder.png"
|
||||||
|
active: gamepad.buttonR1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
id: bottomRow
|
||||||
|
width: parent.width
|
||||||
|
DPad {
|
||||||
|
id: dPad
|
||||||
|
Layout.alignment: Qt.AlignLeft
|
||||||
|
gamepad: gamepad
|
||||||
|
}
|
||||||
|
|
||||||
|
LeftThumbstick {
|
||||||
|
id: leftThumbstick
|
||||||
|
Layout.alignment: Qt.AlignLeft
|
||||||
|
gamepad: gamepad
|
||||||
|
}
|
||||||
|
|
||||||
|
Item {
|
||||||
|
id: spacer2
|
||||||
|
Layout.fillWidth: true
|
||||||
|
}
|
||||||
|
|
||||||
|
RightThumbstick {
|
||||||
|
id: rightThumbstick
|
||||||
|
Layout.alignment: Qt.AlignRight
|
||||||
|
gamepad: gamepad
|
||||||
|
}
|
||||||
|
|
||||||
|
Item {
|
||||||
|
width: 200
|
||||||
|
height: 200
|
||||||
|
Layout.alignment: Qt.AlignRight
|
||||||
|
ButtonImage {
|
||||||
|
id: buttonA
|
||||||
|
anchors.bottom: parent.bottom
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
source: "xboxControllerButtonA.png";
|
||||||
|
active: gamepad.buttonA
|
||||||
|
}
|
||||||
|
ButtonImage {
|
||||||
|
id: buttonB
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
source: "xboxControllerButtonB.png";
|
||||||
|
active: gamepad.buttonB
|
||||||
|
}
|
||||||
|
ButtonImage {
|
||||||
|
id: buttonX
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
source: "xboxControllerButtonX.png";
|
||||||
|
active: gamepad.buttonX
|
||||||
|
}
|
||||||
|
ButtonImage {
|
||||||
|
id: buttonY
|
||||||
|
anchors.top: parent.top
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
source: "xboxControllerButtonY.png";
|
||||||
|
active: gamepad.buttonY
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Item {
|
|
||||||
width: 200
|
|
||||||
height: 200
|
|
||||||
anchors.right: parent.right
|
|
||||||
anchors.rightMargin: 8
|
|
||||||
anchors.bottom: parent.bottom
|
|
||||||
anchors.bottomMargin: 8
|
|
||||||
ButtonImage {
|
|
||||||
id: buttonA
|
|
||||||
anchors.bottom: parent.bottom
|
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
|
||||||
source: "xboxControllerButtonA.png";
|
|
||||||
active: gamepad.buttonA
|
|
||||||
}
|
|
||||||
ButtonImage {
|
|
||||||
id: buttonB
|
|
||||||
anchors.right: parent.right
|
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
|
||||||
source: "xboxControllerButtonB.png";
|
|
||||||
active: gamepad.buttonB
|
|
||||||
}
|
|
||||||
ButtonImage {
|
|
||||||
id: buttonX
|
|
||||||
anchors.left: parent.left
|
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
|
||||||
source: "xboxControllerButtonX.png";
|
|
||||||
active: gamepad.buttonX
|
|
||||||
}
|
|
||||||
ButtonImage {
|
|
||||||
id: buttonY
|
|
||||||
anchors.top: parent.top
|
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
|
||||||
source: "xboxControllerButtonY.png";
|
|
||||||
active: gamepad.buttonY
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue