summaryrefslogtreecommitdiffstats
path: root/examples/keyboardinput-qml/main.qml
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire.ecortex@kdab.com>2014-11-14 08:52:40 +0100
committerSean Harmer <sean.harmer@kdab.com>2014-11-14 20:30:39 +0100
commitf526de47fbc2991937472548ac6e9978c05eb7d2 (patch)
tree79b45b1e6bfcd58e1aabfb67f8ccacc8802d6567 /examples/keyboardinput-qml/main.qml
parenta17624a960d100e34313a21b5667ff35cbb19645 (diff)
keyboardinput-qml example now working with inputs
Demonstates how keyboard events can be used to interact with the scene. Usage: Use tab to switch the focus between the spheres Use W,A,S,D to interact with the right most sphere (when it has the focus) Change-Id: I02972d4b62b59259d3e1daa610c5e0554c70c704 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'examples/keyboardinput-qml/main.qml')
-rw-r--r--examples/keyboardinput-qml/main.qml36
1 files changed, 32 insertions, 4 deletions
diff --git a/examples/keyboardinput-qml/main.qml b/examples/keyboardinput-qml/main.qml
index f0b1665f0..b36c9eaa9 100644
--- a/examples/keyboardinput-qml/main.qml
+++ b/examples/keyboardinput-qml/main.qml
@@ -102,7 +102,7 @@ Entity {
}
property Transform transform: Transform {
Translate {
- dx: -5
+ dx: 5
}
Scale {
scale: sphere1.input.focus ? 2 : 1
@@ -110,7 +110,10 @@ Entity {
}
property KeyboardInput input: KeyboardInput {
controller: keyboardController
- focus: false
+ focus: true
+ onTabPressed: {
+ sphere2.input.focus = true
+ }
}
components: [material, transform, sphereMesh, input]
@@ -131,7 +134,10 @@ Entity {
}
property KeyboardInput input: KeyboardInput {
controller: keyboardController
- focus: true
+
+ onTabPressed: {
+ sphere3.input.focus = true;
+ }
}
components: [material, transform, sphereMesh, input]
@@ -144,7 +150,8 @@ Entity {
}
property Transform transform: Transform {
Translate {
- dx: 5
+ id: sphere3dTranslate
+ dx: -5
}
Scale {
scale: sphere3.input.focus ? 2 : 1
@@ -152,6 +159,27 @@ Entity {
}
property KeyboardInput input: KeyboardInput {
controller: keyboardController
+
+ onPressed: {
+ switch (event.key) {
+ case Qt.Key_W:
+ sphere3dTranslate.dy += 0.1;
+ break;
+ case Qt.Key_S:
+ sphere3dTranslate.dy -= 0.1;
+ break;
+ case Qt.Key_A:
+ sphere3dTranslate.dx += 0.1;
+ break;
+ case Qt.Key_D:
+ sphere3dTranslate.dx -= 0.1;
+ break;
+ }
+ }
+ onTabPressed: {
+ sphere1.input.focus = true;
+ }
+
}
components: [material, transform, sphereMesh, input]