diff options
author | Venu <venugopal.shivashankar@digia.com> | 2013-07-01 15:14:00 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-08-02 14:40:35 +0200 |
commit | 1484cb76315984d4833b510bf9b4e65af4ca696e (patch) | |
tree | 0446ea1031a51b647b0d7c96dc0f69df64121a82 /examples/sensors/accelbubble/accelbubble.qml | |
parent | 0e86de52c22cef74a6d0536d985a2a047051c0d8 (diff) | |
download | qtsensors-1484cb76315984d4833b510bf9b4e65af4ca696e.tar.gz |
Updated the example to use SVG content and Qt Quick controls.v5.1.1
Using sensors module and svg content in a Qt Quick app has been
tricky so far as the C++ plug-in dependencies are not detected
automatically by creator. This change is intended to make the app
suitable for a tutorial explaining how to create a Qt Quick app
for Android.
Change-Id: I05b7413b1224e009ae739cf7a16181519cab7619
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
Diffstat (limited to 'examples/sensors/accelbubble/accelbubble.qml')
-rw-r--r-- | examples/sensors/accelbubble/accelbubble.qml | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/examples/sensors/accelbubble/accelbubble.qml b/examples/sensors/accelbubble/accelbubble.qml index 726fb6f..8f676dc 100644 --- a/examples/sensors/accelbubble/accelbubble.qml +++ b/examples/sensors/accelbubble/accelbubble.qml @@ -38,16 +38,22 @@ ** ****************************************************************************/ -import QtQuick 2.0 + +import QtQuick 2.1 +import QtQuick.Controls 1.0 + //! [0] import QtSensors 5.0 //! [0] -Rectangle { - id: mainPage +ApplicationWindow { + title: "Accelerate Bubble" + id: mainWindow width: 320 height: 480 + visible: true + //! [1] Accelerometer { @@ -60,45 +66,44 @@ Rectangle { //! [3] onReadingChanged: { - var newx = (bubble.x + calcRoll(accel.reading.x, accel.reading.y, accel.reading.z) * .1) - var newy = (bubble.y - calcPitch(accel.reading.x, accel.reading.y, accel.reading.z) * .1) + var newX = (bubble.x + calcRoll(accel.reading.x, accel.reading.y, accel.reading.z) * .1) + var newY = (bubble.y - calcPitch(accel.reading.x, accel.reading.y, accel.reading.z) * .1) - if (newx < 0) - newx = 0 + if (newX < 0) + newX = 0 - if (newx > mainPage.width - bubble.width) - newx = mainPage.width - bubble.width + if (newX > mainWindow.width - bubble.width) + newX = mainWindow.width - bubble.width - if (newy < 18) - newy = 18 + if (newY < 18) + newY = 18 - if (newy > mainPage.height - bubble.height) - newy = mainPage.height - bubble.height + if (newY > mainWindow.height - bubble.height) + newY = mainWindow.height - bubble.height - bubble.x = newx - bubble.y = newy + bubble.x = newX + bubble.y = newY } //! [3] } function calcPitch(x,y,z) { - return Math.atan(y / Math.sqrt(x*x + z*z)) * 57.2957795; + return -(Math.atan(y / Math.sqrt(x * x + z * z)) * 57.2957795); } function calcRoll(x,y,z) { - return Math.atan(x / Math.sqrt(y*y + z*z)) * 57.2957795; + return -(Math.atan(x / Math.sqrt(y * y + z * z)) * 57.2957795); } Image { id: bubble - source: "content/Bluebubble2.png" - property real centerX: parent.width / 2 - property real centerY: parent.height / 2; + source: "content/Bluebubble.svg" + smooth: true + property real centerX: mainWindow.width / 2 + property real centerY: mainWindow.height / 2 property real bubbleCenter: bubble.width / 2 x: centerX - bubbleCenter y: centerY - bubbleCenter - smooth: true - Behavior on y { SmoothedAnimation { easing.type: Easing.Linear |