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 | |
parent | 0e86de52c22cef74a6d0536d985a2a047051c0d8 (diff) | |
download | qtsensors-1484cb76315984d4833b510bf9b4e65af4ca696e.tar.gz qtsensors-1484cb76315984d4833b510bf9b4e65af4ca696e.tar.bz2 qtsensors-1484cb76315984d4833b510bf9b4e65af4ca696e.zip |
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 <eskil.abrahamsen-blomfeldt@digia.com>
-rw-r--r-- | examples/sensors/accelbubble/accelbubble.pro | 2 | ||||
-rw-r--r-- | examples/sensors/accelbubble/accelbubble.qml | 49 | ||||
-rw-r--r-- | examples/sensors/accelbubble/accelbubble.qrc | 2 | ||||
-rw-r--r-- | examples/sensors/accelbubble/content/Bluebubble.svg | 10 | ||||
-rw-r--r-- | examples/sensors/accelbubble/content/Bluebubble2.png | bin | 12815 -> 0 bytes | |||
-rwxr-xr-x | examples/sensors/accelbubble/doc/images/accelbubble.png | bin | 0 -> 5181 bytes | |||
-rw-r--r-- | examples/sensors/accelbubble/doc/src/accelbubble.qdoc | 8 | ||||
-rw-r--r-- | examples/sensors/accelbubble/main.cpp | 13 | ||||
-rw-r--r-- | examples/sensors/sensors.pro | 4 |
9 files changed, 58 insertions, 30 deletions
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 @@ <RCC> <qresource prefix="/"> <file>accelbubble.qml</file> - <file>content/Bluebubble2.png</file> + <file>content/Bluebubble.svg</file> </qresource> </RCC> 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 @@ +<?xml version="1.0"?> +<svg xmlns="http://www.w3.org/2000/svg" version="1.2" baseProfile="tiny"> + <defs> + <radialGradient id="grad1" cx="0.5" cy="0.7" r="0.7" fx="0.5" fy="0.4"> + <stop offset="0" style="stop-color:rgb(255,255,255)" /> + <stop offset="1.5" style="stop-color:rgb(0,102,153)" /> + </radialGradient> + </defs> + <circle cx="100" cy="80" r="42" fill="url(#grad1)"/> +</svg> diff --git a/examples/sensors/accelbubble/content/Bluebubble2.png b/examples/sensors/accelbubble/content/Bluebubble2.png Binary files differdeleted file mode 100644 index f96126e..0000000 --- a/examples/sensors/accelbubble/content/Bluebubble2.png +++ /dev/null diff --git a/examples/sensors/accelbubble/doc/images/accelbubble.png b/examples/sensors/accelbubble/doc/images/accelbubble.png Binary files differnew file mode 100755 index 0000000..84e876d --- /dev/null +++ b/examples/sensors/accelbubble/doc/images/accelbubble.png 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 <QtGui/QGuiApplication> +#include <QtQml/QQmlApplicationEngine> + +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 += \ |