summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVenu <venugopal.shivashankar@digia.com>2013-07-01 15:14:00 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-08-02 14:40:35 +0200
commit1484cb76315984d4833b510bf9b4e65af4ca696e (patch)
tree0446ea1031a51b647b0d7c96dc0f69df64121a82
parent0e86de52c22cef74a6d0536d985a2a047051c0d8 (diff)
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>
-rw-r--r--examples/sensors/accelbubble/accelbubble.pro2
-rw-r--r--examples/sensors/accelbubble/accelbubble.qml49
-rw-r--r--examples/sensors/accelbubble/accelbubble.qrc2
-rw-r--r--examples/sensors/accelbubble/content/Bluebubble.svg10
-rw-r--r--examples/sensors/accelbubble/content/Bluebubble2.pngbin12815 -> 0 bytes
-rwxr-xr-xexamples/sensors/accelbubble/doc/images/accelbubble.pngbin0 -> 5181 bytes
-rw-r--r--examples/sensors/accelbubble/doc/src/accelbubble.qdoc8
-rw-r--r--examples/sensors/accelbubble/main.cpp13
-rw-r--r--examples/sensors/sensors.pro4
9 files changed, 58 insertions, 30 deletions
diff --git a/examples/sensors/accelbubble/accelbubble.pro b/examples/sensors/accelbubble/accelbubble.pro
index 3986e4a2..d0378bb3 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 726fb6ff..8f676dc9 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 f3ca2f05..5cb6945a 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 00000000..d9c406c4
--- /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
deleted file mode 100644
index f96126eb..00000000
--- a/examples/sensors/accelbubble/content/Bluebubble2.png
+++ /dev/null
Binary files differ
diff --git a/examples/sensors/accelbubble/doc/images/accelbubble.png b/examples/sensors/accelbubble/doc/images/accelbubble.png
new file mode 100755
index 00000000..84e876d5
--- /dev/null
+++ b/examples/sensors/accelbubble/doc/images/accelbubble.png
Binary files differ
diff --git a/examples/sensors/accelbubble/doc/src/accelbubble.qdoc b/examples/sensors/accelbubble/doc/src/accelbubble.qdoc
index 83c5d3dc..0249dd41 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 bc557637..222c8966 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 1c3f8d00..6b994b85 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 += \