summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorTamas Martinec <tamas.martinec@symbio.com>2021-07-01 15:53:41 +0300
committerTamas Martinec <tamas.martinec@symbio.com>2021-08-18 12:30:19 +0300
commitdb9f0807ac3a7edccf46d845dac65aa13caff461 (patch)
treec6413269457cd2b9bda17c704b9f1a7d11f16df8 /examples
parenta1df957679a5e6f32940a71491bae244562177f6 (diff)
QtSensors: Fix and simplify the Shakeit example
Removed the Multimedia dependency and added two new animations instead of the audio playback. Changed fixed window size to dynamic. Pick-to: 6.2 Task-number: QTBUG-92514 Change-Id: I136d08a1bb5c1f06ae0612ceeec177c3abf39084 Reviewed-by: Juha Vuolle <juha.vuolle@insta.fi>
Diffstat (limited to 'examples')
-rw-r--r--examples/sensors/CMakeLists.txt4
-rw-r--r--examples/sensors/shakeit/shakeit.pro4
-rw-r--r--examples/sensors/shakeit/shakeit.qml93
3 files changed, 71 insertions, 30 deletions
diff --git a/examples/sensors/CMakeLists.txt b/examples/sensors/CMakeLists.txt
index 32699493..cb66e663 100644
--- a/examples/sensors/CMakeLists.txt
+++ b/examples/sensors/CMakeLists.txt
@@ -5,9 +5,7 @@ if(TARGET Qt::Quick)
# add_subdirectory(qmlsensorgestures)
add_subdirectory(qmlqtsensors)
add_subdirectory(sensor_explorer)
-# if (TARGET Qt::Multimedia)
-# add_subdirectory(shakeit)
-# endif()
+# add_subdirectory(shakeit)
if(TARGET Qt::Svg)
add_subdirectory(accelbubble)
endif()
diff --git a/examples/sensors/shakeit/shakeit.pro b/examples/sensors/shakeit/shakeit.pro
index 00eb1ab3..327c669b 100644
--- a/examples/sensors/shakeit/shakeit.pro
+++ b/examples/sensors/shakeit/shakeit.pro
@@ -1,6 +1,8 @@
TEMPLATE = app
TARGET = shakeit
-QT += quick
+QT += quick sensors
+qtConfig(static):QTPLUGIN += qtsensorgestures_plugin qtsensorgestures_shakeplugin
+
SOURCES = main.cpp
RESOURCES += \
diff --git a/examples/sensors/shakeit/shakeit.qml b/examples/sensors/shakeit/shakeit.qml
index 6ea44979..d2524b16 100644
--- a/examples/sensors/shakeit/shakeit.qml
+++ b/examples/sensors/shakeit/shakeit.qml
@@ -52,26 +52,13 @@ import QtQuick
//! [0]
import QtSensors
//! [0]
-import QtMultimedia
-
-
Rectangle {
id: window
- width: 320
- height: 480
+ anchors.fill: parent
state: "default"
- Audio {
- id :phone
- source: "audio/phone.wav" //mono
- }
- Audio {
- id :loopy2a_mono
- source: "audio/loopy2a_mono.wav" //mono
- }
-
Text {
id: label
text: qsTr("Shake to rotate triangles")
@@ -105,7 +92,6 @@ Rectangle {
source: "content/triangle3.png"
x: parent.width / 2 + (triangle1.width / 2)
y: parent.height / 2 + (triangle3.height / 2);
-
Behavior on x { SmoothedAnimation { velocity: 200 } }
Behavior on y { SmoothedAnimation { velocity: 200 } }
}
@@ -121,21 +107,26 @@ Rectangle {
name: "default"
PropertyChanges { target: triangle1; rotation: 0;
x: parent.width / 2 - (triangle1.width / 2)
- y: parent.height / 2 - (triangle1.height);
+ y: parent.height / 2 - (triangle1.height)
+ scale: 1;
+
}
PropertyChanges { target: triangle2; rotation: 0;
x: parent.width / 2 - (triangle1.width + triangle2.width / 2)
y: parent.height / 2 + (triangle2.height / 2);
+ scale: 1;
}
PropertyChanges { target: triangle3; rotation: 0;
x: parent.width / 2 + (triangle1.width / 2)
y: parent.height / 2 + (triangle3.height / 2);
+ scale: 1;
}
},
State {
name: "whipped"
PropertyChanges { target: triangle1; rotation: 0; x:0; }
- PropertyChanges { target: triangle2; rotation: 0; x:0; y:triangle1.x + triangle1.height; }
+ PropertyChanges { target: triangle2; rotation: 0; x:0;
+ y: triangle1.x + triangle1.height; }
PropertyChanges { target: triangle3; rotation: 0; x:0;
y: triangle2.y + triangle2.height; }
},
@@ -218,6 +209,24 @@ Rectangle {
PropertyChanges { target: triangle2; rotation: 120;
transformOrigin: Item.BottomLeft
}
+ },
+ State {
+ name: "turnedover"
+ PropertyChanges { target: triangle1; rotation: 180;
+ }
+ PropertyChanges { target: triangle2; rotation: 180;
+ }
+ PropertyChanges { target: triangle3; rotation: 180;
+ }
+ },
+ State {
+ name: "pickedup"
+ PropertyChanges { target: triangle1; scale: 1.5;
+ }
+ PropertyChanges { target: triangle2; scale: 1.5;
+ }
+ PropertyChanges { target: triangle3; scale: 1.5;
+ }
}
]
@@ -226,7 +235,8 @@ Rectangle {
Transition {
ParallelAnimation {
- NumberAnimation { properties: "x,y"; easing.type: Easing.OutBounce;duration: 2000; }
+ NumberAnimation { properties: "x,y"; easing.type: Easing.OutBounce;
+ duration: 2000; }
RotationAnimation { id: t1Rotation; target: triangle1; duration: 1000;
direction: RotationAnimation.Clockwise }
RotationAnimation { id: t2Rotation; target: triangle2; duration: 2000;
@@ -246,16 +256,47 @@ Rectangle {
SequentialAnimation {
PropertyAction { target: triangle1; property: "transformOrigin" }
PropertyAction { target: triangle2; property: "transformOrigin" }
- NumberAnimation { target: triangle1; properties: "rotation"; easing.type: Easing.OutBounce;duration: 500; }
- NumberAnimation { target: triangle2; properties: "rotation"; easing.type: Easing.OutBounce;duration: 1500; }
+ NumberAnimation { target: triangle1; properties: "rotation";
+ easing.type: Easing.OutBounce;duration: 500; }
+ NumberAnimation { target: triangle2; properties: "rotation";
+ easing.type: Easing.OutBounce;duration: 1500; }
}
}, Transition {
from: "doubletapped"
SequentialAnimation {
- NumberAnimation { properties: "rotation"; easing.type: Easing.OutBounce;duration: 1500; }
+ NumberAnimation { properties: "rotation";
+ easing.type: Easing.OutBounce;duration: 1500; }
PropertyAction { target: triangle1; property: "transformOrigin" }
PropertyAction { target: triangle2; property: "transformOrigin" }
}
+ }, Transition {
+ to: "turnedover"
+ SequentialAnimation {
+ NumberAnimation { properties: "rotation";
+ easing.type: Easing.OutBounce;duration: 750; }
+ PropertyAction { target: triangle1; property: "transformOrigin" }
+ PropertyAction { target: triangle2; property: "transformOrigin" }
+ }
+ }, Transition {
+ from: "turnedover"
+ SequentialAnimation {
+ NumberAnimation { properties: "rotation";
+ easing.type: Easing.OutBounce;duration: 750; }
+ PropertyAction { target: triangle1; property: "transformOrigin" }
+ PropertyAction { target: triangle2; property: "transformOrigin" }
+ }
+ }, Transition {
+ to: "pickedup"
+ SequentialAnimation {
+ NumberAnimation { properties: "scale";
+ easing.type: Easing.OutBounce;duration: 750; }
+ }
+ }, Transition {
+ from: "pickedup"
+ SequentialAnimation {
+ NumberAnimation { properties: "scale";
+ easing.type: Easing.OutBounce;duration: 750; }
+ }
}
]
@@ -268,11 +309,13 @@ Rectangle {
//! [3]
//! [2]
gestures : ["QtSensors.shake", "QtSensors.whip", "QtSensors.twist", "QtSensors.cover",
- "QtSensors.hover", "QtSensors.turnover", "QtSensors.pickup", "QtSensors.slam" , "QtSensors.doubletap"]
+ "QtSensors.hover", "QtSensors.turnover", "QtSensors.pickup", "QtSensors.slam",
+ "QtSensors.doubletap"]
//! [2]
//! [4]
onDetected:{
console.debug(gesture)
+
label.text = gesture
if (gesture == "shake") {
@@ -300,13 +343,11 @@ Rectangle {
timer.start()
}
if (gesture == "turnover") {
- window.state = "default"
- loopy2a_mono.play();
+ window.state == "turnedover" ? window.state = "default" : window.state = "hovered"
timer.start()
}
if (gesture == "pickup") {
- window.state = "default"
- phone.play()
+ window.state == "pickedup" ? window.state = "default" : window.state = "pickedup"
timer.start()
}
if (gesture == "slam") {