Cleanup Examples

Change-Id: I36de0a3ba85b6b89547792badaa06c50f0e4ccc3
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
This commit is contained in:
Andy Nichols 2017-02-01 13:27:41 +01:00 committed by Laszlo Agocs
parent 7aceda1389
commit 9c7ed97cf9
9 changed files with 689 additions and 645 deletions

1
.gitignore vendored
View File

@ -14,6 +14,7 @@ examples/tutorials/*/*/*
!examples/tutorials/*
!examples/tutorials/*/*
!examples/ja_JP/*/*
!examples/*/*/qml/*
demos/*/*
!demos/spectrum/*
demos/spectrum/bin

File diff suppressed because it is too large Load Diff

View File

@ -3,11 +3,13 @@ TEMPLATE = subdirs
SUBDIRS += simple
qtHaveModule(quick) {
SUBDIRS += configureButtons
SUBDIRS += \
mouseItem \
keyNavigation
qtHaveModule(widgets) {
SUBDIRS += quickGamepad \
keyNavigation \
mouseItem
qtHaveModule(quickcontrols2) {
SUBDIRS += \
configureButtons \
quickGamepad
}
}

View File

@ -1,6 +1,6 @@
TEMPLATE = app
QT += qml quick widgets
QT += qml quick
SOURCES += main.cpp

View File

@ -40,10 +40,10 @@
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Window 2.0
import QtGamepad 1.0
ApplicationWindow {
Window {
visible: true
width: 640
height: 480

View File

@ -39,12 +39,12 @@
****************************************************************************/
#include <QApplication>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:///qml/main.qml")));

View File

@ -1,6 +1,6 @@
TEMPLATE = app
QT += qml quick widgets
QT += qml quick
SOURCES += main.cpp

View File

@ -38,16 +38,27 @@
**
****************************************************************************/
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Window 2.0
import QtGamepad 1.0
ApplicationWindow {
Window {
visible: true
width: 640
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 {
target: GamepadManager
@ -61,9 +72,10 @@ ApplicationWindow {
onButtonAChanged: {
if (value == true) {
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 {
gamepadMouse.mouseButtonReleased(Qt.LeftButton);
outputLabel.text = "";
}
}
}
@ -76,18 +88,36 @@ ApplicationWindow {
Rectangle {
id: cursor
width: 4
height: 4
width: 9
height: 9
radius: 4.5
x: gamepadMouse.mousePosition.x
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 {
anchors.fill: parent
onClicked: {
console.log("clicked qt: " + mouse.x + "," + mouse.y);
console.log("clicked at: " + mouse.x + "," + mouse.y);
}
}
}

View File

@ -39,191 +39,174 @@
****************************************************************************/
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
ApplicationWindow {
Window {
id: applicationWindow1
visible: true
width: 800
height: 600
title: qsTr("QtGamepad Example")
color: "#363330"
Rectangle {
Item {
id: background
color: "#363330"
anchors.fill: parent
Item {
id: buttonL2Item
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
ColumnLayout {
anchors.fill: parent
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 {
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
anchors.margins: 8
spacing: 16
Item {
id: centerButtons
Layout.alignment: Qt.AlignCenter
Layout.fillWidth: true
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
gamepad: gamepad
ColumnLayout {
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 {
id: rightThumbstick
gamepad: gamepad
RowLayout {
id: middleRow
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 {