From 1484cb76315984d4833b510bf9b4e65af4ca696e Mon Sep 17 00:00:00 2001 From: Venu Date: Mon, 1 Jul 2013 15:14:00 +0200 Subject: Updated the example to use SVG content and Qt Quick controls. 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 --- examples/sensors/accelbubble/accelbubble.pro | 2 +- examples/sensors/accelbubble/accelbubble.qml | 49 ++++++++++++--------- examples/sensors/accelbubble/accelbubble.qrc | 2 +- .../sensors/accelbubble/content/Bluebubble.svg | 10 +++++ .../sensors/accelbubble/content/Bluebubble2.png | Bin 12815 -> 0 bytes .../sensors/accelbubble/doc/images/accelbubble.png | Bin 0 -> 5181 bytes .../sensors/accelbubble/doc/src/accelbubble.qdoc | 8 ++-- examples/sensors/accelbubble/main.cpp | 13 +++++- examples/sensors/sensors.pro | 4 +- 9 files changed, 58 insertions(+), 30 deletions(-) create mode 100644 examples/sensors/accelbubble/content/Bluebubble.svg delete mode 100644 examples/sensors/accelbubble/content/Bluebubble2.png create mode 100755 examples/sensors/accelbubble/doc/images/accelbubble.png (limited to 'examples') diff --git a/examples/sensors/accelbubble/accelbubble.pro b/examples/sensors/accelbubble/accelbubble.pro index 3986e4a..d0378bb 100644 --- a/examples/sensors/accelbubble/accelbubble.pro +++ b/examples/sensors/accelbubble/accelbubble.pro @@ -1,6 +1,6 @@ TEMPLATE = app TARGET = accelbubble -QT += quick +QT += quick sensors svg xml SOURCES = main.cpp RESOURCES += \ 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 diff --git a/examples/sensors/accelbubble/accelbubble.qrc b/examples/sensors/accelbubble/accelbubble.qrc index f3ca2f0..5cb6945 100644 --- a/examples/sensors/accelbubble/accelbubble.qrc +++ b/examples/sensors/accelbubble/accelbubble.qrc @@ -1,6 +1,6 @@ accelbubble.qml - content/Bluebubble2.png + content/Bluebubble.svg diff --git a/examples/sensors/accelbubble/content/Bluebubble.svg b/examples/sensors/accelbubble/content/Bluebubble.svg new file mode 100644 index 0000000..d9c406c --- /dev/null +++ b/examples/sensors/accelbubble/content/Bluebubble.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/examples/sensors/accelbubble/content/Bluebubble2.png b/examples/sensors/accelbubble/content/Bluebubble2.png deleted file mode 100644 index f96126e..0000000 Binary files a/examples/sensors/accelbubble/content/Bluebubble2.png and /dev/null differ diff --git a/examples/sensors/accelbubble/doc/images/accelbubble.png b/examples/sensors/accelbubble/doc/images/accelbubble.png new file mode 100755 index 0000000..84e876d Binary files /dev/null and b/examples/sensors/accelbubble/doc/images/accelbubble.png differ diff --git a/examples/sensors/accelbubble/doc/src/accelbubble.qdoc b/examples/sensors/accelbubble/doc/src/accelbubble.qdoc index 83c5d3d..0249dd4 100644 --- a/examples/sensors/accelbubble/doc/src/accelbubble.qdoc +++ b/examples/sensors/accelbubble/doc/src/accelbubble.qdoc @@ -28,13 +28,15 @@ /*! \example accelbubble \title Qt Sensors - Accel Bubble - \brief The AccelBubble example demonstrates the Legacy Accelerometer QML type. + \brief The AccelBubble example demonstrates the Accelerometer QML type. \ingroup qtsensors-examples + \image accelbubble.png + \section1 Overview - Writing a QML application that uses the Legacy Accelerometer QML sensors type requires the following steps: + Writing a QML application that uses the Accelerometer QML sensors type requires the following steps: - Import the Legacy Sensors Declarative module. + Import the Sensors Declarative module. \snippet accelbubble/accelbubble.qml 0 diff --git a/examples/sensors/accelbubble/main.cpp b/examples/sensors/accelbubble/main.cpp index bc55763..222c896 100644 --- a/examples/sensors/accelbubble/main.cpp +++ b/examples/sensors/accelbubble/main.cpp @@ -38,5 +38,14 @@ ** ****************************************************************************/ -#include "../stub.h" -SENSORS_EXAMPLE_MAIN(accelbubble) + +#include +#include + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc,argv); + QQmlApplicationEngine engine(QUrl("qrc:///accelbubble.qml")); + + return app.exec(); +} diff --git a/examples/sensors/sensors.pro b/examples/sensors/sensors.pro index 1c3f8d0..6b994b8 100644 --- a/examples/sensors/sensors.pro +++ b/examples/sensors/sensors.pro @@ -4,11 +4,13 @@ SUBDIRS += grue qtHaveModule(quick) { SUBDIRS += \ - accelbubble \ qmlsensorgestures \ qmlqtsensors \ sensor_explorer \ shakeit + + qtHaveModule(svg): SUBDIRS += \ + accelbubble } qtHaveModule(widgets): SUBDIRS += \ -- cgit v1.2.1