From b2e97817684f40ab9353fa279a4c02ef9c12e13d Mon Sep 17 00:00:00 2001 From: Lincoln Ramsay Date: Tue, 19 Jun 2012 15:47:09 +1000 Subject: Remove the 'special' naming of examples. Just go back to the naming convention we had before. Change-Id: Iefecb7a5e0ab3aa4d22267b4f475a8e9c1c96058 Reviewed-by: Lorn Potter --- examples/sensors/accel/accel.pro | 7 + examples/sensors/accel/main.cpp | 77 ++++ examples/sensors/accelbubble/accelbubble.pro | 16 + examples/sensors/accelbubble/accelbubble.qml | 113 +++++ .../sensors/accelbubble/content/Bluebubble2.png | Bin 0 -> 12815 bytes examples/sensors/accelbubble/icon.png | Bin 0 -> 2034 bytes examples/sensors/accelbubble/info.json | 14 + examples/sensors/cubehouse/Cube.qml | 81 ++++ examples/sensors/cubehouse/Room.qml | 288 ++++++++++++ examples/sensors/cubehouse/Table.qml | 50 +++ examples/sensors/cubehouse/content/ground.jpg | Bin 0 -> 3077 bytes examples/sensors/cubehouse/content/qtlogo.png | Bin 0 -> 13923 bytes examples/sensors/cubehouse/content/roof.jpg | Bin 0 -> 3866 bytes examples/sensors/cubehouse/content/wall.jpg | Bin 0 -> 6195 bytes examples/sensors/cubehouse/cubehouse.pro | 16 + examples/sensors/cubehouse/cubehouse.qml | 113 +++++ examples/sensors/cubehouse/icon.png | Bin 0 -> 7607 bytes examples/sensors/cubehouse/info.json | 14 + examples/sensors/cubehouse/mesh/table.3ds | Bin 0 -> 9149 bytes examples/sensors/grue/console_app/console_app.pro | 6 + examples/sensors/grue/console_app/main.cpp | 89 ++++ examples/sensors/grue/grue.png | Bin 0 -> 11207 bytes examples/sensors/grue/grue.pro | 8 + examples/sensors/grue/grue.qml | 95 ++++ examples/sensors/grue/grue.xcf | Bin 0 -> 23704 bytes examples/sensors/grue/icon.png | Bin 0 -> 7951 bytes examples/sensors/grue/icon.xcf | Bin 0 -> 22397 bytes examples/sensors/grue/import/import.pro | 33 ++ examples/sensors/grue/import/main.cpp | 142 ++++++ examples/sensors/grue/import/plugin.json | 1 + examples/sensors/grue/import/qmldir | 1 + examples/sensors/grue/info.json | 14 + examples/sensors/grue/lib/gruesensor.cpp | 137 ++++++ examples/sensors/grue/lib/gruesensor.h | 85 ++++ examples/sensors/grue/lib/gruesensor_p.h | 66 +++ examples/sensors/grue/lib/lib.pro | 27 ++ examples/sensors/grue/plugin/gruesensorimpl.cpp | 140 ++++++ examples/sensors/grue/plugin/gruesensorimpl.h | 77 ++++ examples/sensors/grue/plugin/main.cpp | 81 ++++ examples/sensors/grue/plugin/plugin.json | 1 + examples/sensors/grue/plugin/plugin.pro | 27 ++ examples/sensors/grue/qml.pro | 15 + examples/sensors/maze/Congratulation.qml | 61 +++ examples/sensors/maze/LabyrinthSquare.qml | 80 ++++ examples/sensors/maze/Mouse.qml | 96 ++++ .../sensors/maze/components/ApplicationWindow.qml | 51 +++ examples/sensors/maze/components/Button.qml | 75 ++++ .../images/button_background_disabled.png | Bin 0 -> 579 bytes .../components/images/button_background_normal.png | Bin 0 -> 901 bytes .../images/button_background_pressed.png | Bin 0 -> 334 bytes examples/sensors/maze/content/00.png | Bin 0 -> 186 bytes examples/sensors/maze/content/01.png | Bin 0 -> 708 bytes examples/sensors/maze/content/cheese.png | Bin 0 -> 317 bytes examples/sensors/maze/content/cheeseeating.gif | Bin 0 -> 650 bytes examples/sensors/maze/content/congratulations.gif | Bin 0 -> 10811 bytes examples/sensors/maze/content/mouse_down.gif | Bin 0 -> 974 bytes examples/sensors/maze/content/start.png | Bin 0 -> 677 bytes examples/sensors/maze/icon.png | Bin 0 -> 4693 bytes examples/sensors/maze/info.json | 15 + examples/sensors/maze/lib.js | 264 +++++++++++ examples/sensors/maze/maze.pro | 4 + examples/sensors/maze/maze.qml | 293 ++++++++++++ examples/sensors/maze/qml.pro | 17 + .../qmlqtsensors/components/ApplicationWindow.qml | 51 +++ .../sensors/qmlqtsensors/components/Button.qml | 75 ++++ .../images/button_background_disabled.png | Bin 0 -> 579 bytes .../components/images/button_background_normal.png | Bin 0 -> 901 bytes .../images/button_background_pressed.png | Bin 0 -> 334 bytes examples/sensors/qmlqtsensors/icon.png | Bin 0 -> 2122 bytes examples/sensors/qmlqtsensors/info.json | 15 + examples/sensors/qmlqtsensors/qml.pro | 15 + examples/sensors/qmlqtsensors/qmlqtsensors.pro | 4 + examples/sensors/qmlqtsensors/qmlqtsensors.qml | 493 +++++++++++++++++++++ examples/sensors/qmlsensorgestures/Button.qml | 129 ++++++ examples/sensors/qmlsensorgestures/GestureList.qml | 133 ++++++ examples/sensors/qmlsensorgestures/GestureView.qml | 153 +++++++ .../sensors/qmlsensorgestures/GesturesView.qml | 156 +++++++ examples/sensors/qmlsensorgestures/icon.png | Bin 0 -> 2298 bytes examples/sensors/qmlsensorgestures/info.json | 14 + .../sensors/qmlsensorgestures/plugin/plugin.json | 1 + .../sensors/qmlsensorgestures/plugin/plugin.pro | 21 + .../plugin/qcountergestureplugin.cpp | 75 ++++ .../plugin/qcountergestureplugin.h | 66 +++ .../plugin/qcounterrecognizer.cpp | 89 ++++ .../qmlsensorgestures/plugin/qcounterrecognizer.h | 70 +++ examples/sensors/qmlsensorgestures/qml.pro | 14 + .../qmlsensorgestures/qmlsensorgestures.pro | 6 + .../qmlsensorgestures/qmlsensorgestures.qml | 116 +++++ examples/sensors/sensor_explorer/PropertyList.qml | 130 ++++++ examples/sensors/sensor_explorer/SensorList.qml | 149 +++++++ .../components/ApplicationWindow.qml | 51 +++ .../sensors/sensor_explorer/components/Button.qml | 75 ++++ .../sensor_explorer/components/TextField.qml | 109 +++++ .../images/button_background_disabled.png | Bin 0 -> 579 bytes .../components/images/button_background_normal.png | Bin 0 -> 901 bytes .../images/button_background_pressed.png | Bin 0 -> 334 bytes .../images/textfield_background_disabled.png | Bin 0 -> 936 bytes .../images/textfield_background_normal.png | Bin 0 -> 767 bytes .../sensor_explorer/content/listitem_select.png | Bin 0 -> 156 bytes examples/sensors/sensor_explorer/icon.png | Bin 0 -> 2205 bytes .../sensors/sensor_explorer/import/explorer.cpp | 143 ++++++ examples/sensors/sensor_explorer/import/explorer.h | 79 ++++ examples/sensors/sensor_explorer/import/import.pro | 25 ++ examples/sensors/sensor_explorer/import/main.cpp | 66 +++ .../sensors/sensor_explorer/import/plugin.json | 1 + .../sensor_explorer/import/propertyinfo.cpp | 140 ++++++ .../sensors/sensor_explorer/import/propertyinfo.h | 83 ++++ examples/sensors/sensor_explorer/import/qmldir | 1 + .../sensors/sensor_explorer/import/sensoritem.cpp | 322 ++++++++++++++ .../sensors/sensor_explorer/import/sensoritem.h | 96 ++++ examples/sensors/sensor_explorer/info.json | 15 + examples/sensors/sensor_explorer/qml.pro | 16 + .../sensors/sensor_explorer/sensor_explorer.pro | 6 + .../sensors/sensor_explorer/sensor_explorer.qml | 196 ++++++++ examples/sensors/sensorgestures/gesture.png | Bin 0 -> 3400 bytes examples/sensors/sensorgestures/main.cpp | 51 +++ examples/sensors/sensorgestures/mainwindow.cpp | 168 +++++++ examples/sensors/sensorgestures/mainwindow.h | 76 ++++ examples/sensors/sensorgestures/mainwindow.ui | 84 ++++ examples/sensors/sensorgestures/sensorgestures.pro | 13 + examples/sensors/sensors.pro | 16 + examples/sensors/shakeit/audio/loopy2a_mono.wav | Bin 0 -> 67772 bytes examples/sensors/shakeit/audio/phone.wav | Bin 0 -> 22094 bytes examples/sensors/shakeit/content/triangle.png | Bin 0 -> 7251 bytes examples/sensors/shakeit/content/triangle2.png | Bin 0 -> 5633 bytes examples/sensors/shakeit/content/triangle3.png | Bin 0 -> 5101 bytes examples/sensors/shakeit/icon.png | Bin 0 -> 10695 bytes examples/sensors/shakeit/info.json | 14 + examples/sensors/shakeit/qml.pro | 16 + examples/sensors/shakeit/shakeit.pro | 3 + examples/sensors/shakeit/shakeit.qml | 323 ++++++++++++++ 131 files changed, 6953 insertions(+) create mode 100644 examples/sensors/accel/accel.pro create mode 100644 examples/sensors/accel/main.cpp create mode 100644 examples/sensors/accelbubble/accelbubble.pro create mode 100644 examples/sensors/accelbubble/accelbubble.qml create mode 100644 examples/sensors/accelbubble/content/Bluebubble2.png create mode 100644 examples/sensors/accelbubble/icon.png create mode 100644 examples/sensors/accelbubble/info.json create mode 100644 examples/sensors/cubehouse/Cube.qml create mode 100644 examples/sensors/cubehouse/Room.qml create mode 100644 examples/sensors/cubehouse/Table.qml create mode 100644 examples/sensors/cubehouse/content/ground.jpg create mode 100644 examples/sensors/cubehouse/content/qtlogo.png create mode 100644 examples/sensors/cubehouse/content/roof.jpg create mode 100644 examples/sensors/cubehouse/content/wall.jpg create mode 100644 examples/sensors/cubehouse/cubehouse.pro create mode 100644 examples/sensors/cubehouse/cubehouse.qml create mode 100644 examples/sensors/cubehouse/icon.png create mode 100644 examples/sensors/cubehouse/info.json create mode 100644 examples/sensors/cubehouse/mesh/table.3ds create mode 100644 examples/sensors/grue/console_app/console_app.pro create mode 100644 examples/sensors/grue/console_app/main.cpp create mode 100644 examples/sensors/grue/grue.png create mode 100644 examples/sensors/grue/grue.pro create mode 100644 examples/sensors/grue/grue.qml create mode 100644 examples/sensors/grue/grue.xcf create mode 100644 examples/sensors/grue/icon.png create mode 100644 examples/sensors/grue/icon.xcf create mode 100644 examples/sensors/grue/import/import.pro create mode 100644 examples/sensors/grue/import/main.cpp create mode 100644 examples/sensors/grue/import/plugin.json create mode 100644 examples/sensors/grue/import/qmldir create mode 100644 examples/sensors/grue/info.json create mode 100644 examples/sensors/grue/lib/gruesensor.cpp create mode 100644 examples/sensors/grue/lib/gruesensor.h create mode 100644 examples/sensors/grue/lib/gruesensor_p.h create mode 100644 examples/sensors/grue/lib/lib.pro create mode 100644 examples/sensors/grue/plugin/gruesensorimpl.cpp create mode 100644 examples/sensors/grue/plugin/gruesensorimpl.h create mode 100644 examples/sensors/grue/plugin/main.cpp create mode 100644 examples/sensors/grue/plugin/plugin.json create mode 100644 examples/sensors/grue/plugin/plugin.pro create mode 100644 examples/sensors/grue/qml.pro create mode 100644 examples/sensors/maze/Congratulation.qml create mode 100644 examples/sensors/maze/LabyrinthSquare.qml create mode 100644 examples/sensors/maze/Mouse.qml create mode 100644 examples/sensors/maze/components/ApplicationWindow.qml create mode 100644 examples/sensors/maze/components/Button.qml create mode 100644 examples/sensors/maze/components/images/button_background_disabled.png create mode 100644 examples/sensors/maze/components/images/button_background_normal.png create mode 100644 examples/sensors/maze/components/images/button_background_pressed.png create mode 100644 examples/sensors/maze/content/00.png create mode 100644 examples/sensors/maze/content/01.png create mode 100644 examples/sensors/maze/content/cheese.png create mode 100644 examples/sensors/maze/content/cheeseeating.gif create mode 100644 examples/sensors/maze/content/congratulations.gif create mode 100644 examples/sensors/maze/content/mouse_down.gif create mode 100644 examples/sensors/maze/content/start.png create mode 100644 examples/sensors/maze/icon.png create mode 100644 examples/sensors/maze/info.json create mode 100644 examples/sensors/maze/lib.js create mode 100644 examples/sensors/maze/maze.pro create mode 100644 examples/sensors/maze/maze.qml create mode 100644 examples/sensors/maze/qml.pro create mode 100644 examples/sensors/qmlqtsensors/components/ApplicationWindow.qml create mode 100644 examples/sensors/qmlqtsensors/components/Button.qml create mode 100644 examples/sensors/qmlqtsensors/components/images/button_background_disabled.png create mode 100644 examples/sensors/qmlqtsensors/components/images/button_background_normal.png create mode 100644 examples/sensors/qmlqtsensors/components/images/button_background_pressed.png create mode 100644 examples/sensors/qmlqtsensors/icon.png create mode 100644 examples/sensors/qmlqtsensors/info.json create mode 100644 examples/sensors/qmlqtsensors/qml.pro create mode 100644 examples/sensors/qmlqtsensors/qmlqtsensors.pro create mode 100644 examples/sensors/qmlqtsensors/qmlqtsensors.qml create mode 100644 examples/sensors/qmlsensorgestures/Button.qml create mode 100644 examples/sensors/qmlsensorgestures/GestureList.qml create mode 100644 examples/sensors/qmlsensorgestures/GestureView.qml create mode 100644 examples/sensors/qmlsensorgestures/GesturesView.qml create mode 100644 examples/sensors/qmlsensorgestures/icon.png create mode 100644 examples/sensors/qmlsensorgestures/info.json create mode 100644 examples/sensors/qmlsensorgestures/plugin/plugin.json create mode 100644 examples/sensors/qmlsensorgestures/plugin/plugin.pro create mode 100644 examples/sensors/qmlsensorgestures/plugin/qcountergestureplugin.cpp create mode 100644 examples/sensors/qmlsensorgestures/plugin/qcountergestureplugin.h create mode 100644 examples/sensors/qmlsensorgestures/plugin/qcounterrecognizer.cpp create mode 100644 examples/sensors/qmlsensorgestures/plugin/qcounterrecognizer.h create mode 100644 examples/sensors/qmlsensorgestures/qml.pro create mode 100644 examples/sensors/qmlsensorgestures/qmlsensorgestures.pro create mode 100644 examples/sensors/qmlsensorgestures/qmlsensorgestures.qml create mode 100644 examples/sensors/sensor_explorer/PropertyList.qml create mode 100644 examples/sensors/sensor_explorer/SensorList.qml create mode 100644 examples/sensors/sensor_explorer/components/ApplicationWindow.qml create mode 100644 examples/sensors/sensor_explorer/components/Button.qml create mode 100644 examples/sensors/sensor_explorer/components/TextField.qml create mode 100644 examples/sensors/sensor_explorer/components/images/button_background_disabled.png create mode 100644 examples/sensors/sensor_explorer/components/images/button_background_normal.png create mode 100644 examples/sensors/sensor_explorer/components/images/button_background_pressed.png create mode 100644 examples/sensors/sensor_explorer/components/images/textfield_background_disabled.png create mode 100644 examples/sensors/sensor_explorer/components/images/textfield_background_normal.png create mode 100644 examples/sensors/sensor_explorer/content/listitem_select.png create mode 100644 examples/sensors/sensor_explorer/icon.png create mode 100644 examples/sensors/sensor_explorer/import/explorer.cpp create mode 100644 examples/sensors/sensor_explorer/import/explorer.h create mode 100644 examples/sensors/sensor_explorer/import/import.pro create mode 100644 examples/sensors/sensor_explorer/import/main.cpp create mode 100644 examples/sensors/sensor_explorer/import/plugin.json create mode 100644 examples/sensors/sensor_explorer/import/propertyinfo.cpp create mode 100644 examples/sensors/sensor_explorer/import/propertyinfo.h create mode 100644 examples/sensors/sensor_explorer/import/qmldir create mode 100644 examples/sensors/sensor_explorer/import/sensoritem.cpp create mode 100644 examples/sensors/sensor_explorer/import/sensoritem.h create mode 100644 examples/sensors/sensor_explorer/info.json create mode 100644 examples/sensors/sensor_explorer/qml.pro create mode 100644 examples/sensors/sensor_explorer/sensor_explorer.pro create mode 100644 examples/sensors/sensor_explorer/sensor_explorer.qml create mode 100644 examples/sensors/sensorgestures/gesture.png create mode 100644 examples/sensors/sensorgestures/main.cpp create mode 100644 examples/sensors/sensorgestures/mainwindow.cpp create mode 100644 examples/sensors/sensorgestures/mainwindow.h create mode 100644 examples/sensors/sensorgestures/mainwindow.ui create mode 100644 examples/sensors/sensorgestures/sensorgestures.pro create mode 100644 examples/sensors/sensors.pro create mode 100644 examples/sensors/shakeit/audio/loopy2a_mono.wav create mode 100644 examples/sensors/shakeit/audio/phone.wav create mode 100644 examples/sensors/shakeit/content/triangle.png create mode 100644 examples/sensors/shakeit/content/triangle2.png create mode 100644 examples/sensors/shakeit/content/triangle3.png create mode 100644 examples/sensors/shakeit/icon.png create mode 100644 examples/sensors/shakeit/info.json create mode 100644 examples/sensors/shakeit/qml.pro create mode 100644 examples/sensors/shakeit/shakeit.pro create mode 100644 examples/sensors/shakeit/shakeit.qml (limited to 'examples/sensors') diff --git a/examples/sensors/accel/accel.pro b/examples/sensors/accel/accel.pro new file mode 100644 index 00000000..86303eca --- /dev/null +++ b/examples/sensors/accel/accel.pro @@ -0,0 +1,7 @@ +TEMPLATE=app +TARGET=accel + +QT=core sensors + +SOURCES=main.cpp + diff --git a/examples/sensors/accel/main.cpp b/examples/sensors/accel/main.cpp new file mode 100644 index 00000000..012c8c61 --- /dev/null +++ b/examples/sensors/accel/main.cpp @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +QAccelerometer *accelerometer; + +class AccelerometerFilter : public QAccelerometerFilter +{ +public: + bool filter(QAccelerometerReading *reading) + { + qDebug() << "acceleration: " + << QString().sprintf("%0.2f %0.2f %0.2f", + reading->x(), + reading->y(), + reading->z()); + return false; // don't store the reading in the sensor + } +}; + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + + QAccelerometer sensor; + accelerometer = &sensor; + AccelerometerFilter filter; + sensor.addFilter(&filter); + sensor.start(); + + if (!sensor.isActive()) { + qWarning("Accelerometer didn't start!"); + return 1; + } + + return app.exec(); +} + diff --git a/examples/sensors/accelbubble/accelbubble.pro b/examples/sensors/accelbubble/accelbubble.pro new file mode 100644 index 00000000..25b12aaa --- /dev/null +++ b/examples/sensors/accelbubble/accelbubble.pro @@ -0,0 +1,16 @@ +TEMPLATE = aux + +app.files = \ + info.json \ + $$files(*.qml) \ + icon.png \ + content \ + images + +MT_SYSROOT=$$(MT_SYSROOT) +!isEmpty(MT_SYSROOT):EXAMPLES_PREFIX=/opt/mt/applications +!isEmpty(EXAMPLES_PREFIX) { + app.path = $$EXAMPLES_PREFIX/com.nokia.mt.accelbubble + INSTALLS = app +} + diff --git a/examples/sensors/accelbubble/accelbubble.qml b/examples/sensors/accelbubble/accelbubble.qml new file mode 100644 index 00000000..a212b595 --- /dev/null +++ b/examples/sensors/accelbubble/accelbubble.qml @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +//! [0] +import QtMobility.sensors 1.2 +//! [0] + + +Rectangle { + id: mainPage + +//! [1] + Accelerometer { + id: accel + dataRate: 100 +//! [1] +//! [2] + active:true +//! [2] + +//! [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) + + if (newx < 0) + newx = 0 + + if (newx > mainPage.width - bubble.width) + newx = mainPage.width - bubble.width + + if (newy < 18) + newy = 18 + + if (newy > mainPage.height - bubble.height) + newy = mainPage.height - bubble.height + + bubble.x = newx + bubble.y = newy + } +//! [3] + } + + function calcPitch(x,y,z) { + 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; + } + + Image { + id: bubble + source: "content/Bluebubble2.png" + property real centerX: parent.width / 2 + property real centerY: parent.height / 2; + property real bubbleCenter: bubble.width / 2 + x: centerX - bubbleCenter + y: centerY - bubbleCenter + + smooth: true + + Behavior on y { + SmoothedAnimation { + easing.type: Easing.Linear + duration: 100 + } + } + Behavior on x { + SmoothedAnimation { + easing.type: Easing.Linear + duration: 100 + } + } + } +} diff --git a/examples/sensors/accelbubble/content/Bluebubble2.png b/examples/sensors/accelbubble/content/Bluebubble2.png new file mode 100644 index 00000000..f96126eb Binary files /dev/null and b/examples/sensors/accelbubble/content/Bluebubble2.png differ diff --git a/examples/sensors/accelbubble/icon.png b/examples/sensors/accelbubble/icon.png new file mode 100644 index 00000000..d74f1111 Binary files /dev/null and b/examples/sensors/accelbubble/icon.png differ diff --git a/examples/sensors/accelbubble/info.json b/examples/sensors/accelbubble/info.json new file mode 100644 index 00000000..b91dd9fc --- /dev/null +++ b/examples/sensors/accelbubble/info.json @@ -0,0 +1,14 @@ +{ + "info-version": "1.0", + "dict": { + "displayName": { + "en_US": "Accel Bubble" + }, + "identifier": "com.nokia.mt.accelbubble", + "runtime": "qml", + "main": "QtSensors_accelbubble.qml", + "version": "1.0.0", + "category": "application", + "subcategory": "utility" + } +} diff --git a/examples/sensors/cubehouse/Cube.qml b/examples/sensors/cubehouse/Cube.qml new file mode 100644 index 00000000..b8afe81f --- /dev/null +++ b/examples/sensors/cubehouse/Cube.qml @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import Qt3D 1.0 +import Qt3D.Shapes 1.0 + +Cube { + objectName: "cube" + + transform: [ + Rotation3D { + angle: 45.0 + axis: Qt.vector3d(1, 0, 0) + }, + Rotation3D { + angle: 45.0 + axis: Qt.vector3d(0, 0, 1) + }, + Rotation3D { + id: yRT + angle: 0 + axis: Qt.vector3d(0, -1, 0) + } + ] + + SequentialAnimation { + running: true + loops: Animation.Infinite + NumberAnimation { + target: yRT + property: "angle" + from: 0 + to: 360 + duration: 1000 + } + } + + effect: Effect { + color: "#aaca00" + texture: "content/qtlogo.png" + decal: true + } +} diff --git a/examples/sensors/cubehouse/Room.qml b/examples/sensors/cubehouse/Room.qml new file mode 100644 index 00000000..848735b7 --- /dev/null +++ b/examples/sensors/cubehouse/Room.qml @@ -0,0 +1,288 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import Qt3D 1.0 +import Qt3D.Shapes 1.0 +import "." + +Item3D{ + id: room + property double scale: 1.0 + property bool yspin: false + property bool xspin: false + property int yrot: 0 + property int xrot: 0 + property double distanceCorrection: 3.7 + + transform: [ + Rotation3D { + id: yRT + angle: 0 + axis: Qt.vector3d(0, -1, 0) + }, + Rotation3D { + id: xRT + angle: 0 + axis: Qt.vector3d(-1, 0, 0) + } + ] + + SequentialAnimation { + running: yspin + NumberAnimation { + target: yRT + property: "angle" + to: yrot + easing.type:"Linear" + duration: 50 + } + onCompleted: yspin = false + } + + SequentialAnimation { + running: xspin + NumberAnimation { + target: xRT + property: "angle" + to: xrot + easing.type:"Linear" + duration: 50 + } + onCompleted: xspin = false + } + + function rotateY(y) + { + room.yrot=y; + room.yspin = true; + } + + function rotateX(x) + { + room.xrot=x; + room.xspin = true; + } + + Quad { + id: frontWall + scale: room.scale + effect: Effect { + texture: "content/wall.jpg" + } + transform: [ + Translation3D { + translate: Qt.vector3d(0, -frontWall.scale + room.distanceCorrection, 0) + }, + Rotation3D { + angle: 90 + axis: Qt.vector3d(1, 0, 0) + }, + Rotation3D { + angle: 0 + axis: Qt.vector3d(0, 1, 0) + }, + Rotation3D { + angle: 0 + axis: Qt.vector3d(0, 0, 1) + } + ] + } + + Quad { + id: ground + scale: room.scale + effect: Effect { + texture: "content/ground.jpg" + } + transform: [ + Translation3D { + translate: Qt.vector3d(0, -ground.scale + room.distanceCorrection, 0) + }, + Rotation3D { + angle: 90 + axis: Qt.vector3d(1, 0, 0) + }, + Rotation3D { + angle: 90 + axis: Qt.vector3d(0, 1, 0) + }, + Rotation3D { + angle: 90 + axis: Qt.vector3d(0, 0, 1) + } + ] + } + + Quad { + id: leftWall + scale: room.scale + effect: Effect { + texture: "content/wall.jpg" + } + transform: [ + Translation3D { + translate: Qt.vector3d(0, -leftWall.scale + room.distanceCorrection, 0) + }, + Rotation3D { + angle: 0 + axis: Qt.vector3d(1, 0, 0) + }, + Rotation3D { + angle: 90 + axis: Qt.vector3d(0, 1, 0) + }, + Rotation3D { + angle: 90 + axis: Qt.vector3d(0, 0, 1) + } + ] + } + + Quad { + id: rightWall + scale: room.scale + effect: Effect { + texture: "content/wall.jpg" + } + transform: [ + Translation3D { + translate: Qt.vector3d(0, -rightWall.scale + room.distanceCorrection, 0) + }, + Rotation3D { + angle: 180 + axis: Qt.vector3d(1, 0, 0) + }, + Rotation3D { + angle: 90 + axis: Qt.vector3d(0, 1, 0) + }, + Rotation3D { + angle: 90 + axis: Qt.vector3d(0, 0, 1) + } + ] + } + + Quad { + id: roof + scale: room.scale + effect: Effect { + texture: "content/roof.jpg" + } + transform: [ + Translation3D { + translate: Qt.vector3d(0, -roof.scale + room.distanceCorrection, 0) + }, + Rotation3D { + angle: 90 + axis: Qt.vector3d(1, 0, 0) + }, + Rotation3D { + angle: -90 + axis: Qt.vector3d(0, 1, 0) + }, + Rotation3D { + angle: 90 + axis: Qt.vector3d(0, 0, 1) + } + ] + } + + Quad { + id: backWall + scale: room.scale + effect: Effect { + texture: "content/wall.jpg" + } + transform: [ + Translation3D { + translate: Qt.vector3d(0, -backWall.scale + room.distanceCorrection, 0) + }, + Rotation3D { + angle: -90 + axis: Qt.vector3d(1, 0, 0) + }, + Rotation3D { + angle: 0 + axis: Qt.vector3d(0, 1, 0) + }, + Rotation3D { + angle: 0 + axis: Qt.vector3d(0, 0, 1) + } + ] + } + + Cube { + id: cube + scale: 0.5 + + transform: [ + Translation3D { + translate: Qt.vector3d(0.0, 0.0, 0.0) + } + ] + } + + Table { + scale: 0.025 + transform: [ + Translation3D { + translate: Qt.vector3d(0, -7 + room.distanceCorrection, 0) + } + ] + } + + Teapot { + scale: 0.5 + + effect: Effect { + color: "#ffffaa" + decal: true + } + + transform: [ + Translation3D { + translate: Qt.vector3d(0.0, -4.50 + room.distanceCorrection, 0.0) + } + ] + } +} diff --git a/examples/sensors/cubehouse/Table.qml b/examples/sensors/cubehouse/Table.qml new file mode 100644 index 00000000..683d28de --- /dev/null +++ b/examples/sensors/cubehouse/Table.qml @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import Qt3D 1.0 +import Qt3D.Shapes 1.0 +import "." + +Item3D { + id: table + scale: 1 + mesh: Mesh { source: "mesh/table.3ds" } +} diff --git a/examples/sensors/cubehouse/content/ground.jpg b/examples/sensors/cubehouse/content/ground.jpg new file mode 100644 index 00000000..2664b99e Binary files /dev/null and b/examples/sensors/cubehouse/content/ground.jpg differ diff --git a/examples/sensors/cubehouse/content/qtlogo.png b/examples/sensors/cubehouse/content/qtlogo.png new file mode 100644 index 00000000..7d3e97eb Binary files /dev/null and b/examples/sensors/cubehouse/content/qtlogo.png differ diff --git a/examples/sensors/cubehouse/content/roof.jpg b/examples/sensors/cubehouse/content/roof.jpg new file mode 100644 index 00000000..53a35d64 Binary files /dev/null and b/examples/sensors/cubehouse/content/roof.jpg differ diff --git a/examples/sensors/cubehouse/content/wall.jpg b/examples/sensors/cubehouse/content/wall.jpg new file mode 100644 index 00000000..7c56e23f Binary files /dev/null and b/examples/sensors/cubehouse/content/wall.jpg differ diff --git a/examples/sensors/cubehouse/cubehouse.pro b/examples/sensors/cubehouse/cubehouse.pro new file mode 100644 index 00000000..995446c0 --- /dev/null +++ b/examples/sensors/cubehouse/cubehouse.pro @@ -0,0 +1,16 @@ +TEMPLATE = aux + +app.files = \ + $$files(*.qml) \ + icon.png \ + images \ + info.json \ + mesh + +MT_SYSROOT=$$(MT_SYSROOT) +!isEmpty(MT_SYSROOT):EXAMPLES_PREFIX=/opt/mt/applications +!isEmpty(EXAMPLES_PREFIX) { + app.path = $$EXAMPLES_PREFIX/com.nokia.mt.cubehouse + INSTALLS = app +} + diff --git a/examples/sensors/cubehouse/cubehouse.qml b/examples/sensors/cubehouse/cubehouse.qml new file mode 100644 index 00000000..5a1b91f8 --- /dev/null +++ b/examples/sensors/cubehouse/cubehouse.qml @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import Qt3D 1.0 +import Qt3D.Shapes 1.0 + +//! [0] +import QtMobility.sensors 1.3 +//! [0] + +import "." + +Item { + id: mainWindow + width: 320 + height: 480 + + Viewport { + id: view + anchors.top: parent.top + width: parent.width + height: parent.height + fillColor: "darkblue" + objectName: "cube viewport" + camera: Camera { eye: Qt.vector3d(0, 3, 1.6 * room.scale - 4)} + + Room{ + id: room + scale: 7.0 + } + + function rotateY(y) + { + room.rotateY(y); + } + + function rotateX(x) + { + room.rotateX(x); + } + } + +//! [1] + Accelerometer { + id: accel + active: true + dataRate: 20 +//! [1] + +//! [2] + property double pitch: 0.0 + property double roll: 0.0 +//! [2] + +//! [3] + onReadingChanged: { + pitch = -(Math.atan2(reading.x, Math.sqrt(reading.y * reading.y + reading.z * reading.z)) * 180) / Math.PI; + roll = (Math.atan2(reading.y, Math.sqrt(reading.x * reading.x + reading.z * reading.z)) * 180) / Math.PI; + } + } +//! [3] + + + //Timer to read out the x and y rotation of the TiltSensor +//! [4] + Timer { + interval: 50; running: true; repeat: true + + onTriggered: { + view.rotateY(accel.pitch); + view.rotateX(accel.roll); + } + } +//! [4] +} diff --git a/examples/sensors/cubehouse/icon.png b/examples/sensors/cubehouse/icon.png new file mode 100644 index 00000000..193ad561 Binary files /dev/null and b/examples/sensors/cubehouse/icon.png differ diff --git a/examples/sensors/cubehouse/info.json b/examples/sensors/cubehouse/info.json new file mode 100644 index 00000000..7b1c5af3 --- /dev/null +++ b/examples/sensors/cubehouse/info.json @@ -0,0 +1,14 @@ +{ + "info-version": "1.0", + "dict": { + "displayName": { + "en_US": "Cubehouse" + }, + "identifier": "com.nokia.mt.cubehouse", + "runtime": "qml", + "main": "QtSensors_cubehouse.qml", + "version": "1.0.0", + "category": "application", + "subcategory": "utility" + } +} diff --git a/examples/sensors/cubehouse/mesh/table.3ds b/examples/sensors/cubehouse/mesh/table.3ds new file mode 100644 index 00000000..3e576bd1 Binary files /dev/null and b/examples/sensors/cubehouse/mesh/table.3ds differ diff --git a/examples/sensors/grue/console_app/console_app.pro b/examples/sensors/grue/console_app/console_app.pro new file mode 100644 index 00000000..33d43176 --- /dev/null +++ b/examples/sensors/grue/console_app/console_app.pro @@ -0,0 +1,6 @@ +TEMPLATE=app +TARGET=detect_grue +CONFIG += console +QT=core sensors +SOURCES=main.cpp + diff --git a/examples/sensors/grue/console_app/main.cpp b/examples/sensors/grue/console_app/main.cpp new file mode 100644 index 00000000..dc62e4de --- /dev/null +++ b/examples/sensors/grue/console_app/main.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +class Filter : public QSensorFilter +{ + int lastPercent; +public: + Filter() + : QSensorFilter() + , lastPercent(0) + { + } + + bool filter(QSensorReading *reading) + { + int percent = reading->property("chanceOfBeingEaten").value() * 100; + if (percent == 0) { + qDebug() << "It is light. You are safe from Grues."; + } else if (lastPercent == 0) { + qDebug() << "It is dark. You are likely to be eaten by a Grue."; + } + if (percent == 100) { + qDebug() << "You have been eaten by a Grue!"; + QCoreApplication::instance()->quit(); + } else if (percent) + qDebug() << "Your chance of being eaten by a Grue:" << percent << "percent."; + lastPercent = percent; + return false; + } +}; + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + + QSensor sensor("GrueSensor"); + + Filter filter; + sensor.addFilter(&filter); + sensor.start(); + + if (!sensor.isActive()) { + qWarning("The Grue sensor didn't start. You're on your own!"); + return 1; + } + + return app.exec(); +} + diff --git a/examples/sensors/grue/grue.png b/examples/sensors/grue/grue.png new file mode 100644 index 00000000..f0b070b4 Binary files /dev/null and b/examples/sensors/grue/grue.png differ diff --git a/examples/sensors/grue/grue.pro b/examples/sensors/grue/grue.pro new file mode 100644 index 00000000..de917bf7 --- /dev/null +++ b/examples/sensors/grue/grue.pro @@ -0,0 +1,8 @@ +TEMPLATE = subdirs + +SUBDIRS += lib plugin console_app +SUBDIRS += import qml.pro + +plugin.depends = lib +import.depends = lib + diff --git a/examples/sensors/grue/grue.qml b/examples/sensors/grue/grue.qml new file mode 100644 index 00000000..05d267c7 --- /dev/null +++ b/examples/sensors/grue/grue.qml @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtMobility.sensors 1.3 +import Grue 1.0 + +Rectangle { + width: 240 + height: 320 + color: "black" + + GrueSensor { + id: sensor + active: true + onReadingChanged: { + var percent = reading.chanceOfBeingEaten; + var thetext = ""; + var theopacity = 0; + if (percent === 0) { + thetext = "It is light. You are safe from Grues."; + } + else if (percent === 100) { + thetext = "You have been eaten by a Grue!"; + sensor.active = false; + theopacity = 1; + } + else if (percent > 0) { + thetext = "It is dark. You are likely to be eaten by a Grue. " + + "Your chance of being eaten by a Grue: "+percent+" percent."; + theopacity = 0.05 + (percent * 0.001); + } + text.font.pixelSize = 30; + text.text = "

" + thetext + "

"; + grueimg.opacity = theopacity; + } + } + + Text { + id: text + anchors.top: parent.top + anchors.topMargin: 20 + anchors.left: parent.left + anchors.right: parent.right + text: "I can't tell if you're going to be eaten by a Grue or not. You're on your own!" + wrapMode: Text.WordWrap + font.pixelSize: 50 + color: "white" + } + + Image { + id: grueimg + anchors.bottom: parent.bottom + anchors.horizontalCenter: parent.horizontalCenter + source: "grue.png" + opacity: 0 + } +} diff --git a/examples/sensors/grue/grue.xcf b/examples/sensors/grue/grue.xcf new file mode 100644 index 00000000..2837ed7e Binary files /dev/null and b/examples/sensors/grue/grue.xcf differ diff --git a/examples/sensors/grue/icon.png b/examples/sensors/grue/icon.png new file mode 100644 index 00000000..f3f038c7 Binary files /dev/null and b/examples/sensors/grue/icon.png differ diff --git a/examples/sensors/grue/icon.xcf b/examples/sensors/grue/icon.xcf new file mode 100644 index 00000000..8416c49f Binary files /dev/null and b/examples/sensors/grue/icon.xcf differ diff --git a/examples/sensors/grue/import/import.pro b/examples/sensors/grue/import/import.pro new file mode 100644 index 00000000..753e1ef8 --- /dev/null +++ b/examples/sensors/grue/import/import.pro @@ -0,0 +1,33 @@ +TEMPLATE = lib +CONFIG += plugin + +TARGET = $$qtLibraryTarget(declarative_grue) +TARGETPATH = Grue + +QT = core gui qml sensors + +INCLUDEPATH += $$PWD/../lib +LIBS += -L$$OUT_PWD/../lib -lgruesensor + +SOURCES = main.cpp + +MT_SYSROOT=$$(MT_SYSROOT) +!isEmpty(MT_SYSROOT):EXAMPLES_PREFIX=/opt/mt/applications +!isEmpty(EXAMPLES_PREFIX):DESTPATH=$$EXAMPLES_PREFIX/com.nokia.mt.grue/imports/Grue +else:DESTPATH=$$[QT_INSTALL_IMPORTS]/Grue + +target.path=$$DESTPATH +INSTALLS += target + +qmldir.files=$$PWD/qmldir +qmldir.path=$$DESTPATH +INSTALLS += qmldir + +OTHER_FILES += \ + plugin.json qmldir + +!isEmpty(EXAMPLES_PREFIX) { + QMAKE_LFLAGS += -Wl,-rpath,$$EXAMPLES_PREFIX/com.nokia.mt.grue/lib + DEFINES += "BUNDLED_PLUGIN=\\\"$$EXAMPLES_PREFIX/com.nokia.mt.grue/plugins/sensors/libqtsensors_grue.so\\\"" +} + diff --git a/examples/sensors/grue/import/main.cpp b/examples/sensors/grue/import/main.cpp new file mode 100644 index 00000000..d8a6d5ab --- /dev/null +++ b/examples/sensors/grue/import/main.cpp @@ -0,0 +1,142 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include +#include + +#ifdef BUNDLED_PLUGIN +#include +#include +#endif + +QT_BEGIN_NAMESPACE + +class GrueSensorQmlImport : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface" FILE "plugin.json") +public: + virtual void registerTypes(const char *uri) + { + char const * const package = "Grue"; + if (QLatin1String(uri) != QLatin1String(package)) return; + int major; + int minor; + + // Register the 1.0 interfaces + major = 1; + minor = 0; + qmlRegisterType (package, major, minor, "GrueSensor"); + qmlRegisterUncreatableType(package, major, minor, "GrueSensorReading", QLatin1String("Cannot create GrueSensorReading")); + } + +#ifdef BUNDLED_PLUGIN + GrueSensorQmlImport() + { + // For now, this is getting called after Sensors has loaded + // Ensure that a change later does not break this by forcing + // sensors to load now + (void)QSensor::sensorTypes(); + + // Load the bundled sensor plugin + QPluginLoader loader(QString::fromLocal8Bit(BUNDLED_PLUGIN)); + QObject *instance = loader.instance(); + m_changes = qobject_cast(instance); + if (m_changes) { + QSensor *sensor = new QSensor(QByteArray(), this); + connect(sensor, SIGNAL(availableSensorsChanged()), this, SLOT(sensorsChanged())); + m_changes->sensorsChanged(); + } + QSensorPluginInterface *plugin = qobject_cast(instance); + if (plugin) { + plugin->registerSensors(); + } + } + +private slots: + void sensorsChanged() + { + m_changes->sensorsChanged(); + } + +private: + QSensorChangesInterface *m_changes; +#endif +}; + +QT_END_NAMESPACE + +#include "main.moc" + +/* + \qmlclass GrueSensor GrueSensor + \inherits QtMobility.sensors1::Sensor + \inqmlmodule Grue 1 + \brief The GrueSensor type reports on your chance of being eaten by a Grue. + + The GrueSensor type reports on your chance of being eaten by a Grue. + + This type wraps the GrueSensor class. Please see the documentation for + GrueSensor for details. + + \sa {QtMobility.sensors QML Limitations} +*/ + +/* + \qmlclass GrueSensorReading GrueSensorReading + \inherits QtMobility.sensors1::SensorReading + \inqmlmodule Grue 1 + \brief The GrueSensorReading type holds the most recent GrueSensor reading. + + The GrueSensorReading type holds the most recent GrueSensor reading. + + This type wraps the GrueSensorReading class. Please see the documentation for + GrueSensorReading for details. + + This type cannot be directly created. +*/ + +/* + \qmlproperty qreal Grue1::GrueSensorReading::chanceOfBeingEaten + Please see GrueSensorReading::chanceOfBeingEaten for information about this property. +*/ diff --git a/examples/sensors/grue/import/plugin.json b/examples/sensors/grue/import/plugin.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/examples/sensors/grue/import/plugin.json @@ -0,0 +1 @@ +{} diff --git a/examples/sensors/grue/import/qmldir b/examples/sensors/grue/import/qmldir new file mode 100644 index 00000000..266b7c11 --- /dev/null +++ b/examples/sensors/grue/import/qmldir @@ -0,0 +1 @@ +plugin declarative_grue diff --git a/examples/sensors/grue/info.json b/examples/sensors/grue/info.json new file mode 100644 index 00000000..75129054 --- /dev/null +++ b/examples/sensors/grue/info.json @@ -0,0 +1,14 @@ +{ + "info-version": "1.0", + "dict": { + "displayName": { + "en_US": "Grue Sensor" + }, + "identifier": "com.nokia.mt.grue", + "runtime": "qml", + "main": "QtSensors_grue.qml", + "version": "1.0.0", + "category": "application", + "subcategory": "utility" + } +} diff --git a/examples/sensors/grue/lib/gruesensor.cpp b/examples/sensors/grue/lib/gruesensor.cpp new file mode 100644 index 00000000..b1f00ede --- /dev/null +++ b/examples/sensors/grue/lib/gruesensor.cpp @@ -0,0 +1,137 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "gruesensor.h" +#include "gruesensor_p.h" + +IMPLEMENT_READING(GrueSensorReading) + +/* + \class GrueSensorReading + + \brief The GrueSensorReading class holds readings from the Grue sensor. + + The Grue Sensor informs you of your chance of being eaten by a Grue. + + Grues love the dark so as long as your surroundings are relatively light + you are safe. However the more time you spend in the dark, the higher + your chances are of being eaten by a Grue. +*/ + +/* + \property GrueSensorReading::chanceOfBeingEaten + \brief holds your chance of being eaten. + + The value is the probability (from 0 to 100) that a Grue will eat you. + A probability of 100 means you are currently being eaten. The darker + it is, the more likely you are to be eaten by a Grue. The longer you + stay in a dark area, the more likely you are to be eaten by a Grue. + If you are in a lit room, the probability will be 0 as Grues fear light. +*/ + +int GrueSensorReading::chanceOfBeingEaten() const +{ + return d->chanceOfBeingEaten; +} + +void GrueSensorReading::setChanceOfBeingEaten(int chanceOfBeingEaten) +{ + d->chanceOfBeingEaten = chanceOfBeingEaten; +} + +// ===================================================================== + +// begin generated code + +/* + \class GrueFilter + + \brief The GrueFilter class is a convenience wrapper around QSensorFilter. + + The only difference is that the filter() method features a pointer to GrueSensorReading + instead of QSensorReading. +*/ + +/* + \fn GrueFilter::filter(GrueSensorReading *reading) + + Called when \a reading changes. Returns false to prevent the reading from propagating. + + \sa QSensorFilter::filter() +*/ + +char const * const GrueSensor::type("GrueSensor"); + +/* + \class GrueSensor + + \brief The GrueSensor class is a convenience wrapper around QSensor. + + The only behavioural difference is that this class sets the type properly. + + This class also features a reading() function that returns a GrueSensorReading instead of a QSensorReading. + + For details about how the sensor works, see \l GrueSensorReading. + + \sa GrueSensorReading +*/ + +/* + \fn GrueSensor::GrueSensor(QObject *parent) + + Construct the sensor as a child of \a parent. +*/ + +/* + \fn GrueSensor::~GrueSensor() + + Destroy the sensor. Stops the sensor if it has not already been stopped. +*/ + +/* + \fn GrueSensor::reading() const + + Returns the reading class for this sensor. + + \sa QSensor::reading() +*/ +// end generated code + +#include "moc_gruesensor.cpp" diff --git a/examples/sensors/grue/lib/gruesensor.h b/examples/sensors/grue/lib/gruesensor.h new file mode 100644 index 00000000..8088988d --- /dev/null +++ b/examples/sensors/grue/lib/gruesensor.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef GRUESENSOR_H +#define GRUESENSOR_H + +#include + +class GrueSensorReadingPrivate; + +#if defined(QT_BUILD_GRUE_LIB) +# define Q_GRUE_EXPORT Q_DECL_EXPORT +#else +# define Q_GRUE_EXPORT Q_DECL_IMPORT +#endif + +class Q_GRUE_EXPORT GrueSensorReading : public QSensorReading +{ + Q_OBJECT + Q_PROPERTY(int chanceOfBeingEaten READ chanceOfBeingEaten WRITE setChanceOfBeingEaten) + DECLARE_READING(GrueSensorReading) +public: + int chanceOfBeingEaten() const; + void setChanceOfBeingEaten(int chanceOfBeingEaten); +}; + +// begin generated code + +class Q_GRUE_EXPORT GrueFilter : public QSensorFilter +{ +public: + virtual bool filter(GrueSensorReading *reading) = 0; +private: + bool filter(QSensorReading *reading) { return filter(static_cast(reading)); } +}; + +class Q_GRUE_EXPORT GrueSensor : public QSensor +{ + Q_OBJECT +public: + explicit GrueSensor(QObject *parent = 0) : QSensor(GrueSensor::type, parent) {} + virtual ~GrueSensor() {} + GrueSensorReading *reading() const { return static_cast(QSensor::reading()); } + static char const * const type; +}; +// end generated code + +#endif diff --git a/examples/sensors/grue/lib/gruesensor_p.h b/examples/sensors/grue/lib/gruesensor_p.h new file mode 100644 index 00000000..4996e868 --- /dev/null +++ b/examples/sensors/grue/lib/gruesensor_p.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef GRUESENSOR_P_H +#define GRUESENSOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +class GrueSensorReadingPrivate +{ +public: + GrueSensorReadingPrivate() + : chanceOfBeingEaten(-1) + { + } + + int chanceOfBeingEaten; +}; + +#endif diff --git a/examples/sensors/grue/lib/lib.pro b/examples/sensors/grue/lib/lib.pro new file mode 100644 index 00000000..e048e607 --- /dev/null +++ b/examples/sensors/grue/lib/lib.pro @@ -0,0 +1,27 @@ +TEMPLATE = lib +TARGET = gruesensor + +# avoid going to release/debug subdirectory +win32:DESTDIR = $$OUT_PWD + +DEFINES *= QT_BUILD_GRUE_LIB +QT = core sensors + +HEADERS += gruesensor.h\ + gruesensor_p.h\ + +SOURCES += gruesensor.cpp\ + +target.path=$$[QT_INSTALL_LIBS] +INSTALLS += target + +MT_SYSROOT=$$(MT_SYSROOT) +!isEmpty(MT_SYSROOT):EXAMPLES_PREFIX=/opt/mt/applications +!isEmpty(EXAMPLES_PREFIX) { + target.path = $$EXAMPLES_PREFIX/com.nokia.mt.grue/lib + remove_so.commands = "rm $(INSTALL_ROOT)$${target.path}/lib$${TARGET}.so" + remove_so.CONFIG = no_path + remove_so.depends = install_target + INSTALLS += remove_so +} + diff --git a/examples/sensors/grue/plugin/gruesensorimpl.cpp b/examples/sensors/grue/plugin/gruesensorimpl.cpp new file mode 100644 index 00000000..e7152a67 --- /dev/null +++ b/examples/sensors/grue/plugin/gruesensorimpl.cpp @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "gruesensorimpl.h" +#include +#include + +char const * const gruesensorimpl::id("grue.gruesensor"); + +gruesensorimpl::gruesensorimpl(QSensor *sensor) + : QSensorBackend(sensor) + , lightLevel(QAmbientLightReading::Undefined) +{ + // We need a light sensor + lightSensor = new QAmbientLightSensor(this); + connect(lightSensor, SIGNAL(readingChanged()), this, SLOT(lightChanged())); + lightSensor->connectToBackend(); + + // We need a timer + darkTimer = new QTimer(this); + darkTimer->setInterval(1000); + connect(darkTimer, SIGNAL(timeout()), this, SLOT(increaseChance())); + + // We use this as our timestamp source + timer.start(); + +//! [setReading] + // Register our reading instance + setReading(&m_reading); +//! [setReading] + +//! [metadata] + // Supply metadata + // We can run as fast as the light sensor does + setDataRates(lightSensor); + // Only one output range, 0 to 1 in .1 increments + addOutputRange(0, 1, 0.1); + setDescription(QLatin1String("Grue Sensor")); +//! [metadata] +} + +void gruesensorimpl::start() +{ +//! [start] + lightSensor->setDataRate(sensor()->dataRate()); + lightSensor->start(); + // If the light sensor doesn't work we don't work either + if (!lightSensor->isActive()) + sensorStopped(); + if (lightSensor->isBusy()) + sensorBusy(); +//! [start] +} + +void gruesensorimpl::stop() +{ + lightSensor->stop(); +} + +void gruesensorimpl::lightChanged() +{ + if (lightLevel == lightSensor->reading()->lightLevel()) + return; + + lightLevel = lightSensor->reading()->lightLevel(); + + int chance = 0; + darkTimer->stop(); + + switch (lightSensor->reading()->lightLevel()) { + case QAmbientLightReading::Dark: + // It is dark. You are likely to be eaten by a grue. + chance = 10; + darkTimer->start(); + break; + default: + break; + } + + // Only send an update if the value has changed. + if (chance != m_reading.chanceOfBeingEaten() || m_reading.timestamp() == 0) { + m_reading.setTimestamp(timer.elapsed()); + m_reading.setChanceOfBeingEaten(chance); + newReadingAvailable(); + } +} + +void gruesensorimpl::increaseChance() +{ + // The longer you stay in the dark, the higher your chance of being eaten + int chance = m_reading.chanceOfBeingEaten() + 10; + + m_reading.setTimestamp(timer.elapsed()); + m_reading.setChanceOfBeingEaten(chance); + + newReadingAvailable(); + + // No point in using the timer anymore if we've hit 100... you can't get more + // likely to be eaten than 100% + if (chance >= 100) + darkTimer->stop(); +} + diff --git a/examples/sensors/grue/plugin/gruesensorimpl.h b/examples/sensors/grue/plugin/gruesensorimpl.h new file mode 100644 index 00000000..ed89711d --- /dev/null +++ b/examples/sensors/grue/plugin/gruesensorimpl.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef GRUESENSORIMPL_H +#define GRUESENSORIMPL_H + +#include +#include "gruesensor.h" +#include +#include + +QT_BEGIN_NAMESPACE +class QTimer; +QT_END_NAMESPACE + +class gruesensorimpl : public QSensorBackend +{ + Q_OBJECT +public: + static char const * const id; + + gruesensorimpl(QSensor *sensor); + + void start(); + void stop(); + +private Q_SLOTS: + void lightChanged(); + void increaseChance(); + +private: + GrueSensorReading m_reading; + QAmbientLightSensor *lightSensor; + QTimer *darkTimer; + QTime timer; + QAmbientLightReading::LightLevel lightLevel; +}; + +#endif + diff --git a/examples/sensors/grue/plugin/main.cpp b/examples/sensors/grue/plugin/main.cpp new file mode 100644 index 00000000..36aec298 --- /dev/null +++ b/examples/sensors/grue/plugin/main.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "gruesensorimpl.h" +#include +#include +#include +#include +#include + +class GrueSensorPlugin : public QObject, public QSensorPluginInterface, public QSensorChangesInterface, public QSensorBackendFactory +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "com.nokia.Qt.QSensorPluginInterface/1.0" FILE "plugin.json") + Q_INTERFACES(QSensorPluginInterface QSensorChangesInterface) +public: + void registerSensors() + { + qDebug() << "loaded the grue plugin"; + } + + void sensorsChanged() + { + if (!QSensor::defaultSensorForType(QAmbientLightSensor::type).isEmpty()) { + // There is a light sensor available. Register the backend + if (!QSensorManager::isBackendRegistered(GrueSensor::type, gruesensorimpl::id)) + QSensorManager::registerBackend(GrueSensor::type, gruesensorimpl::id, this); + } else { + if (QSensorManager::isBackendRegistered(GrueSensor::type, gruesensorimpl::id)) + QSensorManager::unregisterBackend(GrueSensor::type, gruesensorimpl::id); + } + } + + QSensorBackend *createBackend(QSensor *sensor) + { + if (sensor->identifier() == gruesensorimpl::id) + return new gruesensorimpl(sensor); + + return 0; + } +}; + +#include "main.moc" + diff --git a/examples/sensors/grue/plugin/plugin.json b/examples/sensors/grue/plugin/plugin.json new file mode 100644 index 00000000..8a55b3ae --- /dev/null +++ b/examples/sensors/grue/plugin/plugin.json @@ -0,0 +1 @@ +{ "Keys": [ "notused" ] } diff --git a/examples/sensors/grue/plugin/plugin.pro b/examples/sensors/grue/plugin/plugin.pro new file mode 100644 index 00000000..32e127f1 --- /dev/null +++ b/examples/sensors/grue/plugin/plugin.pro @@ -0,0 +1,27 @@ +TEMPLATE = lib +CONFIG += plugin +TARGET = $$qtLibraryTarget(qtsensors_grue) +PLUGIN_TYPE = sensors + +QT = core sensors + +INCLUDEPATH += $$PWD/../lib +LIBS += -L$$OUT_PWD/../lib -lgruesensor + +HEADERS += gruesensorimpl.h\ + +SOURCES += gruesensorimpl.cpp\ + main.cpp\ + +target.path=$$[QT_INSTALL_PLUGINS]/sensors +INSTALLS += target + +OTHER_FILES += \ + plugin.json + +MT_SYSROOT=$$(MT_SYSROOT) +!isEmpty(MT_SYSROOT):EXAMPLES_PREFIX=/opt/mt/applications +!isEmpty(EXAMPLES_PREFIX) { + target.path = $$EXAMPLES_PREFIX/com.nokia.mt.grue/plugins/sensors +} + diff --git a/examples/sensors/grue/qml.pro b/examples/sensors/grue/qml.pro new file mode 100644 index 00000000..e3d021e0 --- /dev/null +++ b/examples/sensors/grue/qml.pro @@ -0,0 +1,15 @@ +TEMPLATE = aux + +app.files = \ + icon.png \ + info.json \ + $$files(*.qml) \ + grue.png + +MT_SYSROOT=$$(MT_SYSROOT) +!isEmpty(MT_SYSROOT):EXAMPLES_PREFIX=/opt/mt/applications +!isEmpty(EXAMPLES_PREFIX) { + app.path = $$EXAMPLES_PREFIX/com.nokia.mt.grue + INSTALLS = app +} + diff --git a/examples/sensors/maze/Congratulation.qml b/examples/sensors/maze/Congratulation.qml new file mode 100644 index 00000000..a8d6c41c --- /dev/null +++ b/examples/sensors/maze/Congratulation.qml @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Import the declarative plugins +import QtQuick 2.0 + +//Import the javascript functions for this game +import "lib.js" as Lib + +//Implementation of the Congratulation control +Item { + x: Lib.cellDimension + y: Lib.cellDimension + width: Lib.cellDimension * (Lib.dimension - 2) + height: Lib.cellDimension * (Lib.dimension - 2) + + //Containing a animated gif image + AnimatedImage { + id: img + anchors.fill: parent + visible: true + source: "content/congratulations.gif" + } +} diff --git a/examples/sensors/maze/LabyrinthSquare.qml b/examples/sensors/maze/LabyrinthSquare.qml new file mode 100644 index 00000000..e5aacfcd --- /dev/null +++ b/examples/sensors/maze/LabyrinthSquare.qml @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Import the declarative plugins +import QtQuick 2.0 + +//Import the javascript functions for this game +import "lib.js" as Lib + +//Implementation of the Labyrinth square control. +Rectangle { + id: sq + x: 0 + y: 0 + width: Lib.cellDimension + height: Lib.cellDimension + color: "white" + property int val: 0 + property AnimatedImage picture: img + + //Dependend of its position and the labyrinth value a square can be the start, cheese, empty or a wall + AnimatedImage { + id: img + anchors.fill: parent + source: "" + } + + function updateImage() + { + if (sq.val == -1) + sq.picture.source = "content/start.png"; + else if (sq.val == 3) + sq.picture.source = "content/cheese.png"; + else if (sq.val == 4){ + sq.picture.source = "content/cheeseeating.gif"; + sq.picture.playing = true; + } + else if (sq.val == 1) + sq.picture.source = "content/01.png"; + else + sq.picture.source = "content/00.png"; + } +} diff --git a/examples/sensors/maze/Mouse.qml b/examples/sensors/maze/Mouse.qml new file mode 100644 index 00000000..434acebb --- /dev/null +++ b/examples/sensors/maze/Mouse.qml @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Import the declarative plugins +import QtQuick 2.0 + +//Import the javascript functions for this game +import "lib.js" as Lib + +//Implementation of the Mouse control. +Item { + id: mouse + x: 0 + y: 0 + width: Lib.cellDimension + height: Lib.cellDimension + property int angle + + AnimatedImage { + id: img + source: "content/mouse_down.gif" + anchors.fill: parent + visible: true + } + + function distance(origX, origY, newX, newY) { + return Math.sqrt((Math.pow((newX - origX),2)) + (Math.pow((newY - origY),2))) + } + + //Function for moving the mouse + function move(newx, newy) + { + if (mouse.x === newx && mouse.y === newy) + return + // somehow this actually works +//! [0] + var a = newy - mouse.y + var b = newx - mouse.x + var c = distance(mouse.x, mouse.y, newx, newy) + var radians_to_degrees = 57.2957795 + + if (a > 0) + angle = -Math.acos(a / b) * radians_to_degrees + else + angle = -Math.asin(b / c) * radians_to_degrees + if (b > 0) + angle = -Math.acos(a / c) * radians_to_degrees + else + angle = Math.acos(a / c) * radians_to_degrees + + if (angle < 0) + angle = 360 + angle + + img.rotation = angle + mouse.x = newx; + mouse.y = newy; +//! [0] + } +} diff --git a/examples/sensors/maze/components/ApplicationWindow.qml b/examples/sensors/maze/components/ApplicationWindow.qml new file mode 100644 index 00000000..cab5e94c --- /dev/null +++ b/examples/sensors/maze/components/ApplicationWindow.qml @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Import the declarative plugins +import QtQuick 2.0 + +Rectangle { + id: appWnd + x: 0 + y: 0 + width: 320 + height: 480 + color: "#ececec" +} diff --git a/examples/sensors/maze/components/Button.qml b/examples/sensors/maze/components/Button.qml new file mode 100644 index 00000000..537a8bce --- /dev/null +++ b/examples/sensors/maze/components/Button.qml @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Import the declarative plugins +import QtQuick 2.0 + +//Implementation of the Button control. +Item { + id: button + width: 30 + height: 100 + property alias text: innerText.text + signal clicked + + Image { + id: backgroundImage + anchors.fill: parent + source: (button.enabled ? "images/button_background_normal.png" : "images/button_background_disabled.png") + } + + Text { + id: innerText + anchors.centerIn: parent + color: "white" + font.bold: true + } + + //Mouse area to react on click events + MouseArea { + anchors.fill: button + onClicked: { button.clicked();} + onPressed: { + backgroundImage.source = "images/button_background_pressed.png" } + onReleased: { + backgroundImage.source = (button.enabled ? "images/button_background_normal.png" : "images/button_background_disabled.png") + } + } +} diff --git a/examples/sensors/maze/components/images/button_background_disabled.png b/examples/sensors/maze/components/images/button_background_disabled.png new file mode 100644 index 00000000..62a00b9a Binary files /dev/null and b/examples/sensors/maze/components/images/button_background_disabled.png differ diff --git a/examples/sensors/maze/components/images/button_background_normal.png b/examples/sensors/maze/components/images/button_background_normal.png new file mode 100644 index 00000000..1fecad5b Binary files /dev/null and b/examples/sensors/maze/components/images/button_background_normal.png differ diff --git a/examples/sensors/maze/components/images/button_background_pressed.png b/examples/sensors/maze/components/images/button_background_pressed.png new file mode 100644 index 00000000..149529e1 Binary files /dev/null and b/examples/sensors/maze/components/images/button_background_pressed.png differ diff --git a/examples/sensors/maze/content/00.png b/examples/sensors/maze/content/00.png new file mode 100644 index 00000000..ab29a622 Binary files /dev/null and b/examples/sensors/maze/content/00.png differ diff --git a/examples/sensors/maze/content/01.png b/examples/sensors/maze/content/01.png new file mode 100644 index 00000000..0e70d1b2 Binary files /dev/null and b/examples/sensors/maze/content/01.png differ diff --git a/examples/sensors/maze/content/cheese.png b/examples/sensors/maze/content/cheese.png new file mode 100644 index 00000000..ecef4503 Binary files /dev/null and b/examples/sensors/maze/content/cheese.png differ diff --git a/examples/sensors/maze/content/cheeseeating.gif b/examples/sensors/maze/content/cheeseeating.gif new file mode 100644 index 00000000..6b2cb47f Binary files /dev/null and b/examples/sensors/maze/content/cheeseeating.gif differ diff --git a/examples/sensors/maze/content/congratulations.gif b/examples/sensors/maze/content/congratulations.gif new file mode 100644 index 00000000..70204176 Binary files /dev/null and b/examples/sensors/maze/content/congratulations.gif differ diff --git a/examples/sensors/maze/content/mouse_down.gif b/examples/sensors/maze/content/mouse_down.gif new file mode 100644 index 00000000..5491c18f Binary files /dev/null and b/examples/sensors/maze/content/mouse_down.gif differ diff --git a/examples/sensors/maze/content/start.png b/examples/sensors/maze/content/start.png new file mode 100644 index 00000000..698c0b1c Binary files /dev/null and b/examples/sensors/maze/content/start.png differ diff --git a/examples/sensors/maze/icon.png b/examples/sensors/maze/icon.png new file mode 100644 index 00000000..1e7ff8d8 Binary files /dev/null and b/examples/sensors/maze/icon.png differ diff --git a/examples/sensors/maze/info.json b/examples/sensors/maze/info.json new file mode 100644 index 00000000..8e2ad1a8 --- /dev/null +++ b/examples/sensors/maze/info.json @@ -0,0 +1,15 @@ +{ + "info-version": "1.0", + "dict": { + "category": "application", + "runtime": "qml", + "displayName": { + "en_US": "Maze" + }, + "subcategory": "utility", + "main": "QtSensors_maze.qml", + "version": "1.0.0", + "identifier": "com.nokia.mt.maze", + "author": "Qt" + } +} diff --git a/examples/sensors/maze/lib.js b/examples/sensors/maze/lib.js new file mode 100644 index 00000000..3bae6a86 --- /dev/null +++ b/examples/sensors/maze/lib.js @@ -0,0 +1,264 @@ +//global variables +var labyrinth = null; +var dimension = 24; +var cellDimension = 13; +var won; +var objectArray = null; +var sec = 0.0 + +//Allocate labyrinth arrays and create labyrinth and way reflected in the labyrinth array +function createLabyrinth() +{ + won = false; + //create the labyrinth matrix + labyrinth = null; + labyrinth = new Array(dimension); + for (var x = 0; x < dimension; x++ ){ + labyrinth[x] = new Array(dimension); + for (var y = 0; y < dimension; y++ ){ + labyrinth[x][y] = 0; + } + } + createWay(); + createLab(); +} + +//Create a way where the mouse can reach the cheese +function createWay() +{ + //Create rnd way to have at least one solution + //A way square is marked as a 2 in the labyrinth array + var x = 0; + var y = 0; + var ox = x; + var oy = y; + labyrinth[0][0] = 2; + while (x < dimension && y < dimension){ + var rnd = Math.floor(Math.random()*5); + if (Math.floor(Math.random()*2) == 1){ + if (rnd == 0) x--; + if (rnd >= 1) x++; + if (x < 0) x++; + if (x >= dimension){ + x = ox; + break; + } + } + else { + if (rnd == 0) y--; + if (rnd >= 1) y++; + if (y < 0) y++; + if (y >= dimension){ + y = oy; + break; + } + } + + /*avoid to have [2]2| + |2|2|*/ + if (x < (dimension - 1) && y < (dimension - 1)){ + if (labyrinth[x + 1][y] == 2 + && labyrinth[x][y + 1] == 2 + && labyrinth[x + 1][y + 1] == 2){ + y = oy; + x = ox; + continue; + } + } + /*avoid to have |2[2] + |2|2|*/ + if (x > 0 && y < (dimension - 1)){ + if (labyrinth[x - 1][y] == 2 + && labyrinth[x][y + 1] == 2 + && labyrinth[x - 1][y + 1] == 2){ + y = oy; + x = ox; + continue; + } + } + /*avoid to have |2|2| + [2]2|*/ + if (x < (dimension - 1) && y > 0){ + if (labyrinth[x + 1][y] == 2 + && labyrinth[x][y - 1] == 2 + && labyrinth[x + 1][y - 1] == 2){ + y = oy; + x = ox; + continue; + } + } + /*avoid to have |2|2| + |2[2]*/ + if (x > 0 && y > 0){ + if (labyrinth[x - 1][y] == 2 + && labyrinth[x][y - 1] == 2 + && labyrinth[x - 1][y - 1] == 2){ + y = oy; + x = ox; + continue; + } + } + + labyrinth[x][y] = 2; + ox = x; + oy = y; + } + //finish way + while (x < (dimension - 1)){ + labyrinth[x][y] = 2; + x++; + } + while (y < (dimension - 1)){ + labyrinth[x][y] = 2; + y++; + } +} + +//Create the labyrinth with rnd values +function createLab() +{ + //A wall square is marked as a 1 in the labyrinth array + //Not a wall square is marked as a 0 in the labyrinth array + //The Cheese square is marked as a 3 in the labyrinth array + //The start is marked as a -1 in the labyrinth array + for (var x = 0; x < dimension; x++ ){ + var rnd = 0; + for (var y = 0; y < dimension; y++){ + //But don't overwrite the way + if (labyrinth[x][y] != 2){ + var rnd = Math.floor(Math.random()*2); + var xy = 0; + var xxy = 0; + var xyy = 0; + var xxyy = 0; + + if (x > 0 && y > 0){ + xy = labyrinth[x - 1][y - 1]; + if (xy == 2) + xy = 0; + + xyy = labyrinth[x - 1][y]; + if (xyy == 2) + xyy = 0; + + xxy = labyrinth[x][y - 1]; + if (xxy == 2) + xxy = 0; + + xxyy = rnd; + if (xxyy == 2) + xxyy = 0; + + //avoid to have to many |0|1| or |1|0| [xy ][xxy ] + // |1[0] |0[1] [xyy ][xxyy] + if (xyy == xxy && xy == xxyy && xy != xxy){ + if (rnd == 1) + rnd = 0; + else rnd = 1; + } + + //avoid to have to many |1|1| or |0|0| + // |1[1] |0[0] + if (xy == xxy && xxy == xxyy && xxyy == xyy){ + if (rnd == 1) + rnd = 0; + else rnd = 1; + } + } + else if (x == 0 && y > 0){ + xy = labyrinth[x][y - 1]; + if (xy == 2) + xy = 0; + + xyy = rnd; + if (xyy == 2) + xyy = 0; + + xxy = labyrinth[x + 1][y - 1]; + if (xxy == 2) + xxy = 0; + + xxyy = labyrinth[x + 1][y]; + if (xxyy == 2) + xxyy = 0; + + //avoid to have to many |1|1| or |0|0| + // |1[1] |0[0] + if (xy == xxy && xxy == xxyy && xxyy == xyy){ + if (rnd == 1) + rnd = 0; + else rnd = 1; + } + + //avoid to have to many |0|1| or |1|0| [xy ][xxy ] + // |1[0] |0[1] [xyy ][xxyy] + if (xyy == xxy && xy == xxyy && xy != xxy){ + if (rnd == 1) + rnd = 0; + else rnd = 1; + } + } + labyrinth[x][y] = rnd; + } + + } + } + //set start and end + labyrinth[0][0] = -1; + labyrinth[0][1] = 0; + labyrinth[1][0] = 0; + labyrinth[1][1] = 0; + + labyrinth[dimension - 2][dimension - 2] = 0; + labyrinth[dimension - 2][dimension - 1] = 0; + labyrinth[dimension - 1][dimension - 2] = 0; + labyrinth[dimension - 1][dimension - 1] = 3; +} + +//Function that checks if the mouse can be moved in x and y +function canMove(x, y) +{ + //Check if movement is allowed + var xcenter = x + (cellDimension / 2); + var ycenter = y + (cellDimension / 2); + //try to get the index + var idx = Math.floor(xcenter / cellDimension); + var idy = Math.floor(ycenter / cellDimension); + var dx = xcenter - (idx * cellDimension + ( cellDimension / 2 )); + var dy = ycenter - (idy * cellDimension + ( cellDimension / 2 )); + + if (dx > 0){ + if (labyrinth[idx][idy] == 1) + return false; + } + if (dx < 0){ + if (labyrinth[idx][idy] == 1) + return false; + } + if (dy > 0){ + if (labyrinth[idx][idy] == 1) + return false; + } + if (dy < 0){ + if (labyrinth[idx][idy] == 1) + return false; + } + //check if won + if (idx == (dimension - 1) && idy == (dimension - 1)) + won = true; + return true; +} + +//Function that prints out the labyrith array values in the console +function printLab() +{ + //for debug purposes print out lab n console + var iy = 0; + for (var y = 0; y < dimension; y++ ){ + var line = ""; + for (var x = 0; x < dimension; x++ ){ + line += labyrinth[x][y]; + } + console.log(line); + } +} diff --git a/examples/sensors/maze/maze.pro b/examples/sensors/maze/maze.pro new file mode 100644 index 00000000..a15e39ef --- /dev/null +++ b/examples/sensors/maze/maze.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs + +SUBDIRS = qml.pro + diff --git a/examples/sensors/maze/maze.qml b/examples/sensors/maze/maze.qml new file mode 100644 index 00000000..40c1d1dd --- /dev/null +++ b/examples/sensors/maze/maze.qml @@ -0,0 +1,293 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* Layout + mainWnd + / +------------------------------/ gameRect +| / +|-----------------------------/ +||---------------------------| +||||M| || +||| \ || +||| mouseCtrl || +||| || +||| || +||| Labyrinth || +||| || +||| || +||| cheeseSquare || +||| \ || +||| |C||| +||---------------------------| +|----------------------------- +| +|----------------------------- +|| || | +|----------------------------- +| \ \ +| \ timePlayingLabel +| newGameButton +------------------------------ + +*/ +//Import the declarative plugins +import QtQuick 2.0 +import "components" + +//! [0] +import QtSensors 5.0 +//! [0] +import QtSystemInfo 5.0 + +//Import the javascript functions for this game +import "lib.js" as Lib + +ApplicationWindow { + id: mainWnd + + property Mouse mouseCtrl; + property LabyrinthSquare cheeseSquare; + property Congratulation congratulation; + ScreenSaver { screenSaverEnabled: !tiltTimer.running } + + Rectangle { + id: gameRect + x: (mainWnd.width - width) / 2 + y: 25 + width: Lib.dimension * Lib.cellDimension + height: Lib.dimension * Lib.cellDimension + color: "transparent" + border.width: 2 + + //timer for starting the labyrinth game + Timer { + id: startTimer + interval: 50; running: true; repeat: false + onTriggered: { + + //reset game time + timePlayingLabel.text = "--"; + Lib.sec = 0.0; + Lib.createLabyrinth(); + + //create labyrinth elements (only at the first time) + var needloadcomponent = false; + if (Lib.objectArray === null) { + needloadcomponent = true; + Lib.objectArray = new Array(Lib.dimension * Lib.dimension); + } + var idx = 0; + for (var y = 0; y < Lib.dimension; y++ ) { + for (var x = 0; x < Lib.dimension; x++ ) { + var component = null; + + //create labyrinth components (only at the first time) + if (needloadcomponent) { + component = Qt.createComponent("LabyrinthSquare.qml"); + if (component.status == Component.Ready) { + var square = component.createObject(parent); + square.x = x * square.width; + square.y = y * square.height; + square.val = Lib.labyrinth[x][y]; + square.updateImage(); + Lib.objectArray[idx] = square; + if (x == (Lib.dimension - 1) && y == (Lib.dimension - 1)) { + cheeseSquare = square; + var component1 = Qt.createComponent("Congratulation.qml"); + if (component1.status == Component.Ready) { + congratulation = component1.createObject(parent); + congratulation.visible = false; + } + } + } + } + else{ + Lib.objectArray[idx].val = Lib.labyrinth[x][y]; + Lib.objectArray[idx].updateImage(); + if (x == (Lib.dimension - 1) && y == (Lib.dimension - 1)) { + cheeseSquare = Lib.objectArray[idx]; + congratulation.visible = false; + } + } + idx++; + } + } + + //Lib.printLab(); //this is for debug. Labyrinth will be printed out in the console + + //Create the mouse control (only at the first time) + if (mouseCtrl === null) { + var component = Qt.createComponent("Mouse.qml"); + if (component.status == Component.Ready) { + mouseCtrl = component.createObject(parent); + } + } + mouseCtrl.x = 0; + mouseCtrl.y = 0; + newGameButton.enabled = true; + + //Start the Tilt reader timer + tiltTimer.running = true; + } + } + } + +//! [1] + TiltSensor{ + id: tiltSensor + unit: TiltSensor.Degrees + enabled: true + accuracy: 5.0 + } +//! [1] + + //Timer to read out the x and y rotation of the TiltSensor + Timer { + id: tiltTimer + interval: 50; running: false; repeat: true + +//! [2] + onTriggered: { + if (!tiltSensor.enabled) + tiltSensor.enabled = true; +//! [2] + + if (mouseCtrl === null) + return; + + //check if already solved + if (Lib.won !== true) { + Lib.sec += 0.05; + timePlayingLabel.text = Math.floor(Lib.sec) + " seconds"; + + //check if we can move the mouse + var xval = -1; + var yval = -1; + +//! [3] + var xstep = 0; + xstep = tiltSensor.yRotation * 0.1 //acceleration + + var ystep = 0; + ystep = tiltSensor.xRotation * 0.1 //acceleration +//! [3] +//! [4] + if (xstep < 1 && xstep > 0) + xstep = 0 + else if (xstep > -1 && xstep < 0) + xstep = 0 + + if (ystep < 1 && ystep > 0) + ystep = 0; + else if (ystep > -1 && ystep < 0) + ystep = 0; + + if ((xstep < 0 && mouseCtrl.x > 0 + && Lib.canMove(mouseCtrl.x + xstep,mouseCtrl.y))) { + xval = mouseCtrl.x + xstep; + + } else if (xstep > 0 && mouseCtrl.x < (Lib.cellDimension * (Lib.dimension - 1)) + && Lib.canMove(mouseCtrl.x + xstep,mouseCtrl.y)) { + xval = mouseCtrl.x + xstep; + } else + xval = mouseCtrl.x; + + if (ystep < 0 && mouseCtrl.y > 0 + && Lib.canMove(mouseCtrl.x, mouseCtrl.y + ystep)) { + yval = mouseCtrl.y + ystep; + } else if (ystep > 0 && (mouseCtrl.y < (Lib.cellDimension * (Lib.dimension - 1))) + && Lib.canMove(mouseCtrl.x, mouseCtrl.y + ystep)) { + yval = mouseCtrl.y + ystep; + } else + yval = mouseCtrl.y + + mouseCtrl.move(xval, yval); +//! [4] + + } else { + //game won, stop the tilt meter + mainWnd.cheeseSquare.val = 4; + mainWnd.cheeseSquare.updateImage(); + mainWnd.congratulation.visible = true; + newGameButton.enabled = true; + tiltTimer.running = false; + } + } + } + + + //Button to start a new Game + Button{ + id: newGameButton + anchors.left: gameRect.left + anchors.top: gameRect.bottom + anchors.topMargin: 5 + height: 30 + width: 100 + text: "new game" + enabled: false; + onClicked: { + newGameButton.enabled = false; + startTimer.start(); + } + } + Button{ + id: calibrateButton + anchors.left: gameRect.left + anchors.top: newGameButton.bottom + anchors.topMargin: 5 + height: 30 + width: 100 + text: "calibrate" + onClicked: { + tiltSensor.calibrate(); + } + } + + //Label to print out the game time + Text{ + id: timePlayingLabel + anchors.right: gameRect.right + anchors.top: gameRect.bottom + anchors.topMargin: 5 + } +} + diff --git a/examples/sensors/maze/qml.pro b/examples/sensors/maze/qml.pro new file mode 100644 index 00000000..95fbb65e --- /dev/null +++ b/examples/sensors/maze/qml.pro @@ -0,0 +1,17 @@ +TEMPLATE = aux + +app.files = \ + components \ + info.json \ + $$files(*.qml) \ + $$files(*.js) \ + icon.png \ + content + +MT_SYSROOT=$$(MT_SYSROOT) +!isEmpty(MT_SYSROOT):EXAMPLES_PREFIX=/opt/mt/applications +!isEmpty(EXAMPLES_PREFIX) { + app.path = $$EXAMPLES_PREFIX/com.nokia.mt.maze + INSTALLS = app +} + diff --git a/examples/sensors/qmlqtsensors/components/ApplicationWindow.qml b/examples/sensors/qmlqtsensors/components/ApplicationWindow.qml new file mode 100644 index 00000000..cab5e94c --- /dev/null +++ b/examples/sensors/qmlqtsensors/components/ApplicationWindow.qml @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Import the declarative plugins +import QtQuick 2.0 + +Rectangle { + id: appWnd + x: 0 + y: 0 + width: 320 + height: 480 + color: "#ececec" +} diff --git a/examples/sensors/qmlqtsensors/components/Button.qml b/examples/sensors/qmlqtsensors/components/Button.qml new file mode 100644 index 00000000..537a8bce --- /dev/null +++ b/examples/sensors/qmlqtsensors/components/Button.qml @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Import the declarative plugins +import QtQuick 2.0 + +//Implementation of the Button control. +Item { + id: button + width: 30 + height: 100 + property alias text: innerText.text + signal clicked + + Image { + id: backgroundImage + anchors.fill: parent + source: (button.enabled ? "images/button_background_normal.png" : "images/button_background_disabled.png") + } + + Text { + id: innerText + anchors.centerIn: parent + color: "white" + font.bold: true + } + + //Mouse area to react on click events + MouseArea { + anchors.fill: button + onClicked: { button.clicked();} + onPressed: { + backgroundImage.source = "images/button_background_pressed.png" } + onReleased: { + backgroundImage.source = (button.enabled ? "images/button_background_normal.png" : "images/button_background_disabled.png") + } + } +} diff --git a/examples/sensors/qmlqtsensors/components/images/button_background_disabled.png b/examples/sensors/qmlqtsensors/components/images/button_background_disabled.png new file mode 100644 index 00000000..62a00b9a Binary files /dev/null and b/examples/sensors/qmlqtsensors/components/images/button_background_disabled.png differ diff --git a/examples/sensors/qmlqtsensors/components/images/button_background_normal.png b/examples/sensors/qmlqtsensors/components/images/button_background_normal.png new file mode 100644 index 00000000..1fecad5b Binary files /dev/null and b/examples/sensors/qmlqtsensors/components/images/button_background_normal.png differ diff --git a/examples/sensors/qmlqtsensors/components/images/button_background_pressed.png b/examples/sensors/qmlqtsensors/components/images/button_background_pressed.png new file mode 100644 index 00000000..149529e1 Binary files /dev/null and b/examples/sensors/qmlqtsensors/components/images/button_background_pressed.png differ diff --git a/examples/sensors/qmlqtsensors/icon.png b/examples/sensors/qmlqtsensors/icon.png new file mode 100644 index 00000000..d3243c5b Binary files /dev/null and b/examples/sensors/qmlqtsensors/icon.png differ diff --git a/examples/sensors/qmlqtsensors/info.json b/examples/sensors/qmlqtsensors/info.json new file mode 100644 index 00000000..e5484028 --- /dev/null +++ b/examples/sensors/qmlqtsensors/info.json @@ -0,0 +1,15 @@ +{ + "info-version": "1.0", + "dict": { + "category": "application", + "runtime": "qml", + "displayName": { + "en_US": "QML QtSensors" + }, + "subcategory": "utility", + "main": "QtSensors_qmlqtsensors.qml", + "version": "1.0.0", + "identifier": "com.nokia.mt.qmlqtsensors", + "author": "Qt" + } +} diff --git a/examples/sensors/qmlqtsensors/qml.pro b/examples/sensors/qmlqtsensors/qml.pro new file mode 100644 index 00000000..741070ff --- /dev/null +++ b/examples/sensors/qmlqtsensors/qml.pro @@ -0,0 +1,15 @@ +TEMPLATE = aux + +app.files = \ + info.json \ + $$files(*.qml) \ + icon.png \ + components + +MT_SYSROOT=$$(MT_SYSROOT) +!isEmpty(MT_SYSROOT):EXAMPLES_PREFIX=/opt/mt/applications +!isEmpty(EXAMPLES_PREFIX) { + app.path = $$EXAMPLES_PREFIX/com.nokia.mt.qmlqtsensors + INSTALLS = app +} + diff --git a/examples/sensors/qmlqtsensors/qmlqtsensors.pro b/examples/sensors/qmlqtsensors/qmlqtsensors.pro new file mode 100644 index 00000000..a15e39ef --- /dev/null +++ b/examples/sensors/qmlqtsensors/qmlqtsensors.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs + +SUBDIRS = qml.pro + diff --git a/examples/sensors/qmlqtsensors/qmlqtsensors.qml b/examples/sensors/qmlqtsensors/qmlqtsensors.qml new file mode 100644 index 00000000..44be63aa --- /dev/null +++ b/examples/sensors/qmlqtsensors/qmlqtsensors.qml @@ -0,0 +1,493 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* Layout + mainWnd + / +--------------------------------------------------------------------------------- +|-------------------------------------------------------------------------------- +|| labelTitle | +|-------------------------------------------------------------------------------- +|-------------------------------------------------------------------------------- <---- tiltLine +|-------------------------------------------------------------------------------- +|| labelTilt | +|-------------------------------------------------------------------------------- +| / accuracyRect / speedRect +|-------------------------------------------||----------------------------------| +|| Accuracy <----- textAccuracy || Speed <-----textSpeed | +|| value <- textAccuracyValue || value <- textSpeedValue | +|| ----------------- ------------------ || --------------- ---------------- | +|| | accuracyLower | | accuracyHigher | || | speedLower | | speedHigher | | +|| ----------------- ------------------ || --------------- ---------------- | +|------------------------------------------ ||----------------------------------| +| ----------- +| |Calibrate| <------------------ calibrate +| ----------- +| --------- +| |Degree | <-------------------- useRadian X Rotation: 0 <------------------ xrottext +| --------- +| --------- +| |Start | <-------------------- tiltStart Y Rotation: 0 <------------------ yrottext +| --------- +|-------------------------------------------------------------------------------- <---- ambientlightLine +|-------------------------------------------------------------------------------- +|| labelAmbientLight | +|-------------------------------------------------------------------------------- +| --------- +| |Start | <-------------------- ablStart Ambient light: - <--------------- abltext +| --------- +|-------------------------------------------------------------------------------- <---- proximityLine +|-------------------------------------------------------------------------------- +|| labelProximityLight | +|-------------------------------------------------------------------------------- +| --------- +| |Start | <-------------------- proxiStart Proximity: - <--------------- proxitext +| --------- +------------------------------------------------------------------------------ +*/ + +//Import the declarative plugins +import QtQuick 2.0 +import "components" + +//! [0] +import QtSensors 5.0 +//! [0] + +ApplicationWindow { + id: appWnd + + Rectangle { + id: mainWnd + x: 0 + y: 0 + width: 320 + height: 480 + color: "transparent" + + property int accuracy: 1 + property string speed: "Slow" + + Text { + id: labelTitle + anchors.top: mainWnd.top + anchors.topMargin: 25 + anchors.left: mainWnd.left + anchors.right: mainWnd.right + + horizontalAlignment: Text.AlignHCenter + font.pixelSize: 30 + font.bold: true + text: "QML QtSensors" + } + + //Tile region + + Rectangle { + id: tiltLine + anchors.top: labelTitle.bottom + anchors.topMargin: 5 + anchors.left: mainWnd.left + anchors.leftMargin: 5 + anchors.right: mainWnd.right + anchors.rightMargin: 5 + border.width: 1 + height: 1 + border.color: "#888888" + } + + Text { + id: labelTilt + anchors.top: tiltLine.bottom + anchors.topMargin: 5 + anchors.left: mainWnd.left + anchors.right: mainWnd.right + + horizontalAlignment: Text.AlignHCenter + font.bold: true + text: "TiltSensor" + } + +//! [1] + TiltSensor { + id: tilt + unit: TiltSensor.Degrees + enabled: false + accuracy: 1.0 + speed: TiltSensor.Slow + } +//! [1] + + Rectangle{ + id: accuracyRect + anchors.top: labelTilt.bottom + anchors.topMargin: 5 + anchors.left: mainWnd.left + anchors.leftMargin: 5 + anchors.right: mainWnd.right + anchors.rightMargin: mainWnd.width / 2 + height: 110 + color: "transparent" + + Text{ + id: textAccuracy + anchors.top: accuracyRect.top + anchors.left: accuracyRect.left + text: "Accuracy" + font.bold: true + } + + Text{ + id: textAccuracyValue + anchors.top: textAccuracy.bottom + anchors.topMargin: 5 + anchors.left: accuracyHigher.left + anchors.right: accuracyHigher.right + text: mainWnd.accuracy + verticalAlignment: Text.AlignVCenter + } + + Button{ + id: accuracyLower + anchors.top: textAccuracyValue.bottom + anchors.left: accuracyRect.left + height: 30 + width: 40 + text: "-" + + onClicked:{ + if (mainWnd.accuracy > 1){ + mainWnd.accuracy--; + tilt.accuracy = mainWnd.accuracy; + } + } + } + + Button{ + id: accuracyHigher + anchors.top: textAccuracyValue.bottom + anchors.left: accuracyLower.right + height: 30 + width: 40 + text: "+" + + onClicked:{ + if (mainWnd.accuracy < 10){ + mainWnd.accuracy++; + tilt.accuracy = mainWnd.accuracy; + } + } + } + } + + Rectangle{ + id: speedRect + anchors.top: labelTilt.bottom + anchors.topMargin: 5 + anchors.left: mainWnd.left + anchors.leftMargin: mainWnd.width / 2 + anchors.right: mainWnd.right + anchors.rightMargin: 5 + height: 110 + color: "transparent" + + Text{ + id: textSpeed + anchors.top: speedRect.top + anchors.left: speedRect.left + text: "Speed" + font.bold: true + } + + Text{ + id: textSpeedValue + anchors.top: textSpeed.bottom + anchors.topMargin: 5 + anchors.left: speedLower.left + anchors.right: speedHigher.right + text: mainWnd.speed + verticalAlignment: Text.AlignVCenter + } + + Button{ + id: speedLower + anchors.top: textSpeedValue.bottom + anchors.left: speedRect.left + height: 30 + width: 40 + text: "-" + + onClicked:{ + if (tilt.speed === TiltSensor.Fast) { + mainWnd.speed = "Medium"; + tilt.speed = TiltSensor.Medium; + } + else if (tilt.speed === TiltSensor.Medium) { + mainWnd.speed = "Slow"; + tilt.speed = TiltSensor.Slow; + } + } + } + + Button{ + id: speedHigher + anchors.top: textSpeedValue.bottom + anchors.left: speedLower.right + height: 30 + width: 40 + text: "+" + + onClicked:{ + if (tilt.speed === TiltSensor.Slow) { + mainWnd.speed = "Medium"; + tilt.speed = TiltSensor.Medium; + } + else if (tilt.speed === TiltSensor.Medium) { + mainWnd.speed = "Fast"; + tilt.speed = TiltSensor.Fast; + } + } + } + } + + Button{ + id: calibrate + anchors.left: mainWnd.left + anchors.leftMargin: 5 + anchors.top: accuracyRect.bottom + height: 30 + width: 80 + text: "Calibrate" + + onClicked:{ + tilt.calibrate(); + } + } + + Button{ + id: useRadian + anchors.top: calibrate.bottom + anchors.left: mainWnd.left + anchors.leftMargin: 5 + height: 30 + width: 80 + text: (tilt !== null ? tilt.unit === TiltSensor.Radians ? "Degree" : "Radians" : "Degree") + + onClicked:{ + tilt.unit = (useRadian.text === "Radians" ? TiltSensor.Radians : TiltSensor.Degrees); + } + } + + Button{ + id: tiltStart + anchors.top: useRadian.bottom + anchors.left: mainWnd.left + anchors.leftMargin: 5 + height: 30 + width: 80 + text: tilt.enabled ? "Stop" : "Start" + + onClicked:{ +//! [2] + tilt.enabled = (tiltStart.text === "Start" ? true: false); +//! [2] + } + } + + Text { + id: xrottext + anchors.right: mainWnd.right + anchors.rightMargin: 5 + anchors.left: useRadian.right + anchors.leftMargin: 15 + anchors.top: useRadian.top + anchors.bottom: useRadian.bottom + verticalAlignment: Text.AlignVCenter +//! [3] + text: "X Rotation: " + tilt.xRotation + (tilt.unit === TiltSensor.Radians ? " rad" : "°") +//! [3] + } + + Text { + id: yrottext + anchors.right: mainWnd.right + anchors.rightMargin: 5 + anchors.left: tiltStart.right + anchors.leftMargin: 15 + anchors.top: tiltStart.top + anchors.bottom: tiltStart.bottom + verticalAlignment: Text.AlignVCenter +//! [4] + text: "Y Rotation: " + tilt.yRotation + (tilt.unit === TiltSensor.Radians ? " rad" : "°") +//! [4] + } + + //Ambient Light region + + Rectangle { + id: ambientlightLine + anchors.top: tiltStart.bottom + anchors.topMargin: 5 + anchors.left: mainWnd.left + anchors.leftMargin: 5 + anchors.right: mainWnd.right + anchors.rightMargin: 5 + border.width: 1 + height: 1 + border.color: "#888888" + } + + Text { + id: labelAmbientLight + anchors.top: ambientlightLine.bottom + anchors.topMargin: 5 + anchors.left: mainWnd.left + anchors.right: mainWnd.right + + horizontalAlignment: Text.AlignHCenter + font.bold: true + text: "AmbientLightSensor" + } + + AmbientLightSensor { + id: ambientlight + enabled: false +//! [5] + onLightLevelChanged:{ + if (ambientlight.lightLevel == AmbientLightSensor.Unknown) + ambientlighttext.text = "Ambient light: Unknown"; + else if (ambientlight.lightLevel == AmbientLightSensor.Dark) + ambientlighttext.text = "Ambient light: Dark"; + else if (ambientlight.lightLevel == AmbientLightSensor.Twilight) + ambientlighttext.text = "Ambient light: Twilight"; + else if (ambientlight.lightLevel == AmbientLightSensor.Light) + ambientlighttext.text = "Ambient light: Light"; + else if (ambientlight.lightLevel == AmbientLightSensor.Bright) + ambientlighttext.text = "Ambient light: Bright"; + else if (ambientlight.lightLevel == AmbientLightSensor.Sunny) + ambientlighttext.text = "Ambient light: Sunny"; + } +//! [5] + } + + Button{ + id: ambientlightStart + anchors.top: labelAmbientLight.bottom + anchors.topMargin: 5 + anchors.left: mainWnd.left + anchors.leftMargin: 5 + height: 30 + width: 80 + text: ambientlight.enabled ? "Stop" : "Start" + + onClicked:{ + ambientlight.enabled = (ambientlightStart.text === "Start" ? true: false); + } + } + + Text { + id: ambientlighttext + anchors.left: ambientlightStart.right + anchors.leftMargin: 15 + anchors.top: ambientlightStart.top + anchors.bottom: ambientlightStart.bottom + verticalAlignment: Text.AlignVCenter + text: "Ambient light: -" + } + + //Proximity region + + Rectangle { + id: proximityLine + anchors.top: ambientlightStart.bottom + anchors.topMargin: 5 + anchors.left: mainWnd.left + anchors.leftMargin: 5 + anchors.right: mainWnd.right + anchors.rightMargin: 5 + border.width: 1 + height: 1 + border.color: "#888888" + } + + Text { + id: labelProximityLight + anchors.top: proximityLine.bottom + anchors.topMargin: 5 + anchors.left: mainWnd.left + anchors.right: mainWnd.right + horizontalAlignment: Text.AlignHCenter + font.bold: true + text: "ProximitySensor" + } + + ProximitySensor { + id: proxi + enabled: false + } + + Button{ + id: proxiStart + anchors.top: labelProximityLight.bottom + anchors.topMargin: 5 + anchors.left: mainWnd.left + anchors.leftMargin: 5 + height: 30 + width: 80 + text: proxi.enabled ? "Stop" : "Start" + + onClicked:{ + proxi.enabled = (proxiStart.text === "Start" ? true: false); + } + } + + Text { + id: proxitext + anchors.left: proxiStart.right + anchors.leftMargin: 15 + anchors.top: proxiStart.top + anchors.bottom: proxiStart.bottom + verticalAlignment: Text.AlignVCenter +//! [6] + text: "Proximity: " + (proxi.near ? "near" : "far") +//! [6] + } + } +} diff --git a/examples/sensors/qmlsensorgestures/Button.qml b/examples/sensors/qmlsensorgestures/Button.qml new file mode 100644 index 00000000..23fc0f66 --- /dev/null +++ b/examples/sensors/qmlsensorgestures/Button.qml @@ -0,0 +1,129 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Import the declarative plugins +import QtQuick 2.0 + +//Implementation of the Button control. +Item { + id: button + width: 30 + height: 30 + property alias buttonText: innerText.text; + property color color: "white" + property color hoverColor: "#aaaaaa" + property color pressColor: "slategray" + property int fontSize: 10 + property int borderWidth: 1 + property int borderRadius: 2 + scale: state === "Pressed" ? 0.96 : 1.0 + onEnabledChanged: state = "" + signal clicked + + //define a scale animation + Behavior on scale { + NumberAnimation { + duration: 100 + easing.type: Easing.InOutQuad + } + } + + //Rectangle to draw the button + Rectangle { + id: rectangleButton + anchors.fill: parent + radius: borderRadius + color: button.enabled ? button.color : "grey" + border.width: borderWidth + border.color: "black" + + Text { + id: innerText + font.pointSize: fontSize + anchors.centerIn: parent + } + } + + //change the color of the button in differen button states + states: [ + State { + name: "Hovering" + PropertyChanges { + target: rectangleButton + color: hoverColor + } + }, + State { + name: "Pressed" + PropertyChanges { + target: rectangleButton + color: pressColor + } + } + ] + + //define transmission for the states + transitions: [ + Transition { + from: ""; to: "Hovering" + ColorAnimation { duration: 200 } + }, + Transition { + from: "*"; to: "Pressed" + ColorAnimation { duration: 10 } + } + ] + + //Mouse area to react on click events + MouseArea { + hoverEnabled: true + anchors.fill: button + onEntered: { button.state='Hovering'} + onExited: { button.state=''} + onClicked: { button.clicked();} + onPressed: { button.state="Pressed" } + onReleased: { + if (containsMouse) + button.state="Hovering"; + else + button.state=""; + } + } +} diff --git a/examples/sensors/qmlsensorgestures/GestureList.qml b/examples/sensors/qmlsensorgestures/GestureList.qml new file mode 100644 index 00000000..9dc3fd92 --- /dev/null +++ b/examples/sensors/qmlsensorgestures/GestureList.qml @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Import the declarative plugins +import QtQuick 2.0 +import QtSensors 5.0 + +/* Layout + gesturerect + / +---------------------------------------/ +|-------------------------------------| +|| labelGesture || +|-------------------------------------| +|-------------------------------------| +|| |<---- gestureListRect +|| || +|| || +|| gestureList || +|| || +|| || +|| || +|| || +|| || +|| || +|-------------------------------------| +*/ + +Rectangle { + id: gesturerect + border.width: 1 + anchors.margins: 5 + + property string selectedGesture: ""; + signal selectedGestureChanged(); + + SensorGesture { + id: gesture + } + + Text { + id: labelGesture + anchors.top: gesturerect.top + anchors.left: gesturerect.left + anchors.right: gesturerect.right + horizontalAlignment: Text.AlignHCenter + font.pixelSize: 30 + font.bold: true + text: "Gestures" + } + + Rectangle { + id: gestureListRect + border.width: 1 + anchors.top: labelGesture.bottom + anchors.left: gesturerect.left + anchors.right: gesturerect.right + anchors.bottom: gesturerect.bottom + anchors.margins: 5 + +//! [4] + ListView { + id: gestureList + anchors.fill: gestureListRect + anchors.margins: 5 + model: gesture.availableGestures + focus: true + currentIndex: -1 + delegate: gestureListDelegate + clip: true + } +//! [4] + Component { + id: gestureListDelegate + + Rectangle { + width: gestureList.width + height: itemText.height + color: (index === gestureList.currentIndex ? "#999933" : "#FFFFFF") + + Text { + id: itemText + text: model.modelData + } + MouseArea { + anchors.fill: parent + onClicked: { + gestureList.currentIndex = index; + selectedGesture = model.modelData; + selectedGestureChanged(); + } + } + } + } + } +} diff --git a/examples/sensors/qmlsensorgestures/GestureView.qml b/examples/sensors/qmlsensorgestures/GestureView.qml new file mode 100644 index 00000000..07a9a5cc --- /dev/null +++ b/examples/sensors/qmlsensorgestures/GestureView.qml @@ -0,0 +1,153 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Import the declarative plugins +import QtQuick 2.0 + +//! [0] +import QtSensors 5.0 +//! [0] + +/* Layout + gesturerect + / +---------------------------------------/ +| ----------------------------------- | +| | id: titleText | | +| ----------------------------------- | +| | +| | +| ----------------------------------- | +| | id: detectionText | | +| ----------------------------------- | +| | +| | +| | +| ----------------------------------- | +| | id: valueText | | +| ----------------------------------- | +| | +| | +| | +| ------------------------------ | +| | id: gestureStartStopButton | | +| ------------------------------ | +--------------------------------------- +*/ + +Rectangle { + id: gesturerect + border.width: 1 + anchors.margins: 5 +//! [2] + property alias gestureid: sensorGesture.gestures +//! [2] + property alias gesturetitle: titleText.text + property alias enabled: sensorGesture.enabled + property string oldgesture: "" + property int count: 0 + +//! [1] + SensorGesture { + id: sensorGesture + enabled: false + onDetected:{ + if (gesture !== oldgesture) + count = 0; + valueText.text = gesture + " " + count; + oldgesture = gesture; + count++; + } + onEnabledChanged: { + valueText.text = "" + } + } +//! [1] + + Text { + id: titleText + anchors.top: gesturerect.top + anchors.left: gesturerect.left + anchors.right: gesturerect.right + horizontalAlignment: Text.AlignHCenter + font.pixelSize: 20 + font.bold: true + text: "" + } + + Text { + id: detectionText + anchors.top: titleText.bottom + anchors.left: gesturerect.left + anchors.right: gesturerect.right + horizontalAlignment: Text.AlignHCenter + font.pixelSize: 15 + text: "detection:" + } + + Text { + id: valueText + anchors.top: detectionText.bottom + anchors.left: gesturerect.left + anchors.right: gesturerect.right + horizontalAlignment: Text.AlignHCenter + font.pixelSize: 15 + text: ("") + visible: sensorGesture.enabled + } + + Button{ + id: gestureStartStopButton + anchors.left: gesturerect.left + anchors.bottom: gesturerect.bottom + height: 30 + width: 100 + buttonText: (sensorGesture.enabled ? "Stop" : "Start") + enabled: true; + onClicked: { + if (gestureStartStopButton.buttonText === "Start") { + sensorGesture.enabled = true; + } + else { + sensorGesture.enabled = false; + } + } + } +} diff --git a/examples/sensors/qmlsensorgestures/GesturesView.qml b/examples/sensors/qmlsensorgestures/GesturesView.qml new file mode 100644 index 00000000..23924cad --- /dev/null +++ b/examples/sensors/qmlsensorgestures/GesturesView.qml @@ -0,0 +1,156 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Import the declarative plugins +import QtQuick 2.0 +import QtSensors 5.0 + +/* Layout + gesturerect + / +---------------------------------------/ +| ----------------------------------- | +| | id: titleText | | +| ----------------------------------- | +| | +| | +| ----------------------------------- | +| | id: detectionText | | +| ----------------------------------- | +| | +| | +| | +| ----------------- ----------------- | +| | id: valueText | | id: valueText1| | +| ----------------- ----------------- | +| | +| | +| | +| ------------------------------ | +| | id: gestureStartStopButton | | +| ------------------------------ | +--------------------------------------- +*/ + +Rectangle { + id: gesturerect + border.width: 1 + anchors.margins: 5 + property alias enabled: sensorGuesture.enabled + property int count: 0 + property int count1: 0 + + SensorGesture { + id: sensorGuesture + enabled: true + gestures: availableGestures + onDetected:{ + if (gesture === "QtSensors.shake") + gesturerect.count++; + else + gesturerect.count1++; + } + onEnabledChanged: { + gesturerect.count = 0; + gesturerect.count1 = 0; + } + } + + Text { + id: titleText + anchors.top: gesturerect.top + anchors.left: gesturerect.left + anchors.right: gesturerect.right + horizontalAlignment: Text.AlignHCenter + font.pixelSize: 20 + font.bold: true + text: "templates gestures" + } + + Text { + id: detectionText + anchors.top: titleText.bottom + anchors.left: gesturerect.left + anchors.right: gesturerect.right + horizontalAlignment: Text.AlignHCenter + font.pixelSize: 15 + text: "shake : SecondCounter" + } + + Text { + id: valueText + anchors.top: detectionText.bottom + anchors.left: gesturerect.left + width: gesturerect.width / 2 + horizontalAlignment: Text.AlignHCenter + font.pixelSize: 15 + text: gesturerect.count + visible: sensorGuesture.enabled + } + + Text { + id: valueText1 + anchors.top: detectionText.bottom + anchors.right: gesturerect.right + width: gesturerect.width / 2 + horizontalAlignment: Text.AlignHCenter + font.pixelSize: 15 + text: gesturerect.count1 + visible: sensorGuesture.enabled + } + + Button{ + id: gestureStartStopButton + anchors.left: gesturerect.left + anchors.bottom: gesturerect.bottom + height: 30 + width: 100 + buttonText: (sensorGuesture.enabled ? "Stop" : "Start") + enabled: true; + onClicked: { + if (gestureStartStopButton.buttonText === "Start") { + sensorGuesture.enabled = true; + } + else { + sensorGuesture.enabled = false; + } + } + } +} diff --git a/examples/sensors/qmlsensorgestures/icon.png b/examples/sensors/qmlsensorgestures/icon.png new file mode 100644 index 00000000..c445bd7f Binary files /dev/null and b/examples/sensors/qmlsensorgestures/icon.png differ diff --git a/examples/sensors/qmlsensorgestures/info.json b/examples/sensors/qmlsensorgestures/info.json new file mode 100644 index 00000000..57241dab --- /dev/null +++ b/examples/sensors/qmlsensorgestures/info.json @@ -0,0 +1,14 @@ +{ + "info-version": "1.0", + "dict": { + "displayName": { + "en_US": "Gesture" + }, + "identifier": "com.nokia.mt.qmlsensorsgesture", + "runtime": "qml", + "main": "QtSensors_qmlsensorgestures.qml", + "version": "1.0.0", + "category": "application", + "subcategory": "utility" + } +} diff --git a/examples/sensors/qmlsensorgestures/plugin/plugin.json b/examples/sensors/qmlsensorgestures/plugin/plugin.json new file mode 100644 index 00000000..8a55b3ae --- /dev/null +++ b/examples/sensors/qmlsensorgestures/plugin/plugin.json @@ -0,0 +1 @@ +{ "Keys": [ "notused" ] } diff --git a/examples/sensors/qmlsensorgestures/plugin/plugin.pro b/examples/sensors/qmlsensorgestures/plugin/plugin.pro new file mode 100644 index 00000000..2003e910 --- /dev/null +++ b/examples/sensors/qmlsensorgestures/plugin/plugin.pro @@ -0,0 +1,21 @@ +TEMPLATE = lib +CONFIG += plugin + +TARGET = qtsensorgestures_counterplugin + +QT += sensors +DESTDIR = $$QT.sensors.plugins/sensorgestures + +HEADERS += \ + qcountergestureplugin.h \ + qcounterrecognizer.h +SOURCES += \ + qcountergestureplugin.cpp \ + qcounterrecognizer.cpp + +target.path += $$[QT_INSTALL_PLUGINS]/sensorgestures +INSTALLS += target + +OTHER_FILES += \ + plugin.json + diff --git a/examples/sensors/qmlsensorgestures/plugin/qcountergestureplugin.cpp b/examples/sensors/qmlsensorgestures/plugin/qcountergestureplugin.cpp new file mode 100644 index 00000000..1fda1879 --- /dev/null +++ b/examples/sensors/qmlsensorgestures/plugin/qcountergestureplugin.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +#include "qcountergestureplugin.h" +#include +#include +#include "qcounterrecognizer.h" + + +QCounterGesturePlugin::QCounterGesturePlugin() +{ +} + +QCounterGesturePlugin::~QCounterGesturePlugin() +{ +} + +QStringList QCounterGesturePlugin::supportedIds() const +{ + QStringList list; + list << "QtSensors.SecondCounter"; + return list; +} + + +QList QCounterGesturePlugin::createRecognizers() +{ + QList recognizers; + + QSensorGestureRecognizer *sRec = new QCounterGestureRecognizer(this); + recognizers.append(sRec); + + return recognizers; +} diff --git a/examples/sensors/qmlsensorgestures/plugin/qcountergestureplugin.h b/examples/sensors/qmlsensorgestures/plugin/qcountergestureplugin.h new file mode 100644 index 00000000..4755f96e --- /dev/null +++ b/examples/sensors/qmlsensorgestures/plugin/qcountergestureplugin.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QCOUNTERGESTUREPLUGIN_H +#define QCOUNTERGESTUREPLUGIN_H + +#include +#include + +#include + +class QCounterGesturePlugin : public QObject, public QSensorGesturePluginInterface +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "com.Nokia.QSensorGesturePluginInterface" FILE "plugin.json") + Q_INTERFACES(QSensorGesturePluginInterface) + +public: + explicit QCounterGesturePlugin(); + ~QCounterGesturePlugin(); + + QList createRecognizers(); + + QStringList gestureSignals() const; + QStringList supportedIds() const; + QString name() const { return "CounterGestures"; } +}; + +#endif // QCOUNTERGESTUREPLUGIN_H diff --git a/examples/sensors/qmlsensorgestures/plugin/qcounterrecognizer.cpp b/examples/sensors/qmlsensorgestures/plugin/qcounterrecognizer.cpp new file mode 100644 index 00000000..03319e81 --- /dev/null +++ b/examples/sensors/qmlsensorgestures/plugin/qcounterrecognizer.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include "qcounterrecognizer.h" + +QCounterGestureRecognizer::QCounterGestureRecognizer(QObject *parent) + : QSensorGestureRecognizer(parent) +{ +} + +QCounterGestureRecognizer::~QCounterGestureRecognizer() +{ + +} + +void QCounterGestureRecognizer::create() +{ + connect(&_timer,SIGNAL(timeout()),this,SLOT(timeout())); + _timer.setInterval(1000); +} + +bool QCounterGestureRecognizer::start() +{ + Q_EMIT detected(id()); + _timer.start(); + return _timer.isActive(); +} + +bool QCounterGestureRecognizer::stop() +{ + _timer.stop(); + return true; +} + + +bool QCounterGestureRecognizer::isActive() +{ + return _timer.isActive(); +} + +QString QCounterGestureRecognizer::id() const +{ + return QString("QtSensors.SecondCounter"); +} + +void QCounterGestureRecognizer::timeout() +{ + Q_EMIT detected(id()); +} diff --git a/examples/sensors/qmlsensorgestures/plugin/qcounterrecognizer.h b/examples/sensors/qmlsensorgestures/plugin/qcounterrecognizer.h new file mode 100644 index 00000000..37c16eb1 --- /dev/null +++ b/examples/sensors/qmlsensorgestures/plugin/qcounterrecognizer.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QCOUNTERGESTURERECOGNIZER_H +#define QCOUNTERGESTURERECOGNIZER_H + +#include +#include +#include + +class QCounterGestureRecognizer : public QSensorGestureRecognizer +{ + Q_OBJECT +public: + + QCounterGestureRecognizer(QObject *parent = 0); + ~QCounterGestureRecognizer(); + + void create(); + + QString id() const; + bool start(); + bool stop(); + bool isActive(); + +private slots: + void timeout(); + +private: + QTimer _timer; +}; + +#endif // QCOUNTERGESTURERECOGNIZER_H diff --git a/examples/sensors/qmlsensorgestures/qml.pro b/examples/sensors/qmlsensorgestures/qml.pro new file mode 100644 index 00000000..333f251c --- /dev/null +++ b/examples/sensors/qmlsensorgestures/qml.pro @@ -0,0 +1,14 @@ +TEMPLATE = aux + +app.files = \ + $$files(*.qml) \ + info.json \ + icon.png + +MT_SYSROOT=$$(MT_SYSROOT) +!isEmpty(MT_SYSROOT):EXAMPLES_PREFIX=/opt/mt/applications +!isEmpty(EXAMPLES_PREFIX) { + app.path = $$EXAMPLES_PREFIX/com.nokia.mt.qmlsensorgestures + INSTALLS = app +} + diff --git a/examples/sensors/qmlsensorgestures/qmlsensorgestures.pro b/examples/sensors/qmlsensorgestures/qmlsensorgestures.pro new file mode 100644 index 00000000..011f5f95 --- /dev/null +++ b/examples/sensors/qmlsensorgestures/qmlsensorgestures.pro @@ -0,0 +1,6 @@ +TEMPLATE = subdirs +CONFIG += ordered + +SUBDIRS = \ + plugin \ + qml.pro diff --git a/examples/sensors/qmlsensorgestures/qmlsensorgestures.qml b/examples/sensors/qmlsensorgestures/qmlsensorgestures.qml new file mode 100644 index 00000000..5a7a4e20 --- /dev/null +++ b/examples/sensors/qmlsensorgestures/qmlsensorgestures.qml @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Import the declarative plugins +import QtQuick 2.0 +import QtSensors 5.0 + +/* Layout +-------------------------------------------------- +| ---------------------------------------------- | +| | | | +| | | | +| | | | +| | gestureList | | +| | | | +| | | | +| | | | +| | | | +| | | | +| | | | +| | | | +| | | | +| ---------------------------------------------- | +| ---------------------------------------------- | +| | | | +| | gesture | | +| | | | +| | | | +| ---------------------------------------------- | +| ---------------------------------------------- | +| | | | +| | gestures | | +| | | | +| | | | +| ---------------------------------------------- | +-------------------------------------------------- +*/ + +Rectangle { + id: viewArea + width: 320 + height: 460 + y: 20 + color: '#d6d6d6' + + GestureList { + id: gestureList + parent: viewArea + anchors.left: viewArea.left + anchors.top: viewArea.top + anchors.right: viewArea.right + height: viewArea.height / 2 +//! [3] + onSelectedGestureChanged: { + gesture.enabled = false; + gesture.gestureid = gestureList.selectedGesture; +//! [3] + gesture.gesturetitle = gestureList.selectedGesture; + } + } + + GestureView { + id: gesture + parent: viewArea + anchors.left: viewArea.left + anchors.top: gestureList.bottom + anchors.right: viewArea.right + height: 100 + } + + GesturesView { + id: gestures + parent: viewArea + anchors.left: viewArea.left + anchors.top: gesture.bottom + anchors.right: viewArea.right + height: 100 + } +} diff --git a/examples/sensors/sensor_explorer/PropertyList.qml b/examples/sensors/sensor_explorer/PropertyList.qml new file mode 100644 index 00000000..846c4cca --- /dev/null +++ b/examples/sensors/sensor_explorer/PropertyList.qml @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Import the declarative plugins +import QtQuick 2.0 +import Explorer 1.0 + +Rectangle { + id: controlrect + anchors.margins: 5 + color: "transparent" + + property PropertyInfo selectedItem: null; + signal selectedItemChanged(); + property alias listmodel: itemList.model + + onListmodelChanged: { + itemList.currentIndex = -1; + selectedItem = null; + selectedItemChanged(); + } + + Rectangle { + id: itemListRect + anchors.fill: parent + color: "transparent" + + ListView { + id: itemList + anchors.fill: itemListRect + anchors.leftMargin: 5 + anchors.rightMargin: 5 + focus: true + currentIndex: -1 + delegate: itemListDelegate + clip: true + + Rectangle { + id: scrollbar + anchors.right: itemList.right + y: itemList.visibleArea.yPosition * itemList.height + width: 2 + height: itemList.visibleArea.heightRatio * itemList.height + color: "black" + } + } + + Component { + id: itemListDelegate + + Rectangle { + width: itemList.width + height: itemNameText.font.pixelSize + 3 + color: "transparent" + + Image { + id: backgroundImage + anchors.fill: parent + source: "content/listitem_select.png" + visible: itemList.currentIndex === index + } + + Text { + id: itemNameText + text: model.modelData.name + font.pixelSize: 15 + color: (itemList.currentIndex === index ? "#1c94ff" : "black") + } + + Text { + id: itemValueText + anchors.left: parent.left + anchors.right: parent.right + anchors.rightMargin: 5 + font.pixelSize: 15 + horizontalAlignment: Text.AlignRight + text: model.modelData.value + color: (itemList.currentIndex === index ? "#1c94ff" : "black") + } + + MouseArea { + anchors.fill: parent + + onClicked: { + itemList.currentIndex = index; + selectedItem = model.modelData; + selectedItemChanged(); + } + } + } + } + } +} diff --git a/examples/sensors/sensor_explorer/SensorList.qml b/examples/sensors/sensor_explorer/SensorList.qml new file mode 100644 index 00000000..da157378 --- /dev/null +++ b/examples/sensors/sensor_explorer/SensorList.qml @@ -0,0 +1,149 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Import the declarative plugins +import QtQuick 2.0 +import Explorer 1.0 + +Rectangle { + id: controlrect + anchors.margins: 5 + color: "transparent" + + property SensorItem selectedItem: null; + signal selectedItemChanged(); + property alias title: labelTitle.text + property alias listmodel: itemList.model + + onListmodelChanged: { + itemList.currentIndex = -1; + selectedItem = null; + selectedItemChanged(); + } + + Text { + id: labelTitle + anchors.top: controlrect.top + anchors.left: controlrect.left + anchors.right: controlrect.right + horizontalAlignment: Text.AlignHCenter + font.pixelSize: 30 + font.bold: true + text: "" + } + + Rectangle { + id: titleLine + anchors.top: labelTitle.bottom + anchors.left: controlrect.left + anchors.right: controlrect.right + height: 1 + border.width: 1 + border.color: "#999999" + } + + Rectangle { + id: itemListRect + anchors.top: titleLine.bottom + anchors.left: controlrect.left + anchors.right: controlrect.right + anchors.bottom: controlrect.bottom + color: "transparent" + + ListView { + id: itemList + anchors.fill: itemListRect + anchors.leftMargin: 5 + anchors.rightMargin: 5 + focus: true + currentIndex: -1 + delegate: itemListDelegate + clip: true + + Rectangle { + id: scrollbar + anchors.right: itemList.right + y: itemList.visibleArea.yPosition * itemList.height + width: 2 + height: itemList.visibleArea.heightRatio * itemList.height + color: "black" + } + } + + Component { + id: itemListDelegate + + Rectangle { + width: itemList.width + height: 30 + color: "transparent" + + Image { + id: backgroundImage + anchors.fill: parent + source: "content/listitem_select.png" + visible: itemList.currentIndex === index + } + + Text { + id: itemText + height: 30 + anchors.top: parent.top + anchors.left: parent.left + anchors.leftMargin: 5 + text: model.modelData.id + color: (itemList.currentIndex === index ? "#1c94ff" : "black") + verticalAlignment: Text.AlignVCenter + font.pixelSize: 15 + } + + MouseArea { + anchors.fill: parent + + onClicked: { + itemList.currentIndex = index; + selectedItem = model.modelData; + selectedItemChanged(); + } + } + } + } + } +} diff --git a/examples/sensors/sensor_explorer/components/ApplicationWindow.qml b/examples/sensors/sensor_explorer/components/ApplicationWindow.qml new file mode 100644 index 00000000..cab5e94c --- /dev/null +++ b/examples/sensors/sensor_explorer/components/ApplicationWindow.qml @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Import the declarative plugins +import QtQuick 2.0 + +Rectangle { + id: appWnd + x: 0 + y: 0 + width: 320 + height: 480 + color: "#ececec" +} diff --git a/examples/sensors/sensor_explorer/components/Button.qml b/examples/sensors/sensor_explorer/components/Button.qml new file mode 100644 index 00000000..537a8bce --- /dev/null +++ b/examples/sensors/sensor_explorer/components/Button.qml @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Import the declarative plugins +import QtQuick 2.0 + +//Implementation of the Button control. +Item { + id: button + width: 30 + height: 100 + property alias text: innerText.text + signal clicked + + Image { + id: backgroundImage + anchors.fill: parent + source: (button.enabled ? "images/button_background_normal.png" : "images/button_background_disabled.png") + } + + Text { + id: innerText + anchors.centerIn: parent + color: "white" + font.bold: true + } + + //Mouse area to react on click events + MouseArea { + anchors.fill: button + onClicked: { button.clicked();} + onPressed: { + backgroundImage.source = "images/button_background_pressed.png" } + onReleased: { + backgroundImage.source = (button.enabled ? "images/button_background_normal.png" : "images/button_background_disabled.png") + } + } +} diff --git a/examples/sensors/sensor_explorer/components/TextField.qml b/examples/sensors/sensor_explorer/components/TextField.qml new file mode 100644 index 00000000..c1feaf21 --- /dev/null +++ b/examples/sensors/sensor_explorer/components/TextField.qml @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Import the declarative plugins +import QtQuick 2.0 + +Item { + id: textInputFrame + property alias text: textInput.text + signal accepted + + resources: [ + Component{ + id: cursorA + Rectangle { + id: cursor_rect + width: 2 + height: 20 + color: "#1c94ff" + visible: textInput.cursorVisible + + PropertyAnimation on opacity { + easing.type: Easing.OutSine + loops: Animation.Infinite + from: 0 + to: 1.0 + duration: 750 + } + } + } + ] + + Image { + id: backgroundImage + anchors.fill: parent + source: (textInputFrame.enabled ? "images/textfield_background_normal.png" : "images/textfield_background_disabled.png") + } + + TextInput { + id: textInput + anchors.fill: parent + anchors.topMargin: 5 + anchors.leftMargin: 5 + anchors.rightMargin: 5 + activeFocusOnPress: false + + cursorDelegate: cursorA + + onEnabledChanged: { + textInput.focus = false; + } + + onAccepted: { + textInputFrame.accepted(); + } + + MouseArea { + anchors.fill: parent + + onClicked: { + if (!textInput.activeFocus) { + textInput.forceActiveFocus() + textInput.openSoftwareInputPanel(); + } else { + textInput.focus = false; + } + } + + onPressAndHold: textInput.closeSoftwareInputPanel(); + } + } +} diff --git a/examples/sensors/sensor_explorer/components/images/button_background_disabled.png b/examples/sensors/sensor_explorer/components/images/button_background_disabled.png new file mode 100644 index 00000000..62a00b9a Binary files /dev/null and b/examples/sensors/sensor_explorer/components/images/button_background_disabled.png differ diff --git a/examples/sensors/sensor_explorer/components/images/button_background_normal.png b/examples/sensors/sensor_explorer/components/images/button_background_normal.png new file mode 100644 index 00000000..1fecad5b Binary files /dev/null and b/examples/sensors/sensor_explorer/components/images/button_background_normal.png differ diff --git a/examples/sensors/sensor_explorer/components/images/button_background_pressed.png b/examples/sensors/sensor_explorer/components/images/button_background_pressed.png new file mode 100644 index 00000000..149529e1 Binary files /dev/null and b/examples/sensors/sensor_explorer/components/images/button_background_pressed.png differ diff --git a/examples/sensors/sensor_explorer/components/images/textfield_background_disabled.png b/examples/sensors/sensor_explorer/components/images/textfield_background_disabled.png new file mode 100644 index 00000000..98bc601f Binary files /dev/null and b/examples/sensors/sensor_explorer/components/images/textfield_background_disabled.png differ diff --git a/examples/sensors/sensor_explorer/components/images/textfield_background_normal.png b/examples/sensors/sensor_explorer/components/images/textfield_background_normal.png new file mode 100644 index 00000000..b90b50cd Binary files /dev/null and b/examples/sensors/sensor_explorer/components/images/textfield_background_normal.png differ diff --git a/examples/sensors/sensor_explorer/content/listitem_select.png b/examples/sensors/sensor_explorer/content/listitem_select.png new file mode 100644 index 00000000..def234f1 Binary files /dev/null and b/examples/sensors/sensor_explorer/content/listitem_select.png differ diff --git a/examples/sensors/sensor_explorer/icon.png b/examples/sensors/sensor_explorer/icon.png new file mode 100644 index 00000000..c48b6095 Binary files /dev/null and b/examples/sensors/sensor_explorer/icon.png differ diff --git a/examples/sensors/sensor_explorer/import/explorer.cpp b/examples/sensors/sensor_explorer/import/explorer.cpp new file mode 100644 index 00000000..12b35f9e --- /dev/null +++ b/examples/sensors/sensor_explorer/import/explorer.cpp @@ -0,0 +1,143 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "explorer.h" +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +/* + \class QSensorExplorer + \brief The QSensorExplorer type provides an easy access for reading all avalaible sensors installed on the system. +*/ + +/* + Construct a QSensorExplorer object with parent \a parent +*/ +QSensorExplorer::QSensorExplorer(QObject* parent) + : QObject(parent) + , _selectedSensorItem(0) +{ + loadSensors(); +} + +/* + Destructor of a QSensorExplorer +*/ +QSensorExplorer::~QSensorExplorer() +{ +} + +/* + Load all available sensors and store it in a list. +*/ +void QSensorExplorer::loadSensors() +{ + //! [0] + _availableSensors.clear(); + + foreach (const QByteArray &type, QSensor::sensorTypes()) { + qDebug() << "Found type" << type; + foreach (const QByteArray &identifier, QSensor::sensorsForType(type)) { + qDebug() << "Found identifier" << identifier; + // Don't put in sensors we can't connect to + QSensor* sensor = new QSensor(type, this); + sensor->setIdentifier(identifier); + if (!sensor->connectToBackend()) { + qDebug() << "Couldn't connect to" << identifier; + continue; + } + + qDebug() << "Adding identifier" << identifier; + _availableSensors.append(new QSensorItem(sensor, this)); + } + } + emit availableSensorsChanged(); + //! [0] +} + +/* + \fn QSensorExplorer::availableSensorsChanged() + Notifies the client if the list of the available sensors was changed +*/ + +/* + \property QSensorExplorer::availableSensors + Returns a list of all available sensor. +*/ +QQmlListProperty QSensorExplorer::availableSensors() +{ + return QQmlListProperty(this,_availableSensors); +} + +/* + \fn QSensorExplorer::selectedSensorItemChanged() + Notifies the client if the selected sensor has been changed +*/ + +/* + \property QSensorExplorer::selectedSensorItem + Returns the current selected sensor item. +*/ +QSensorItem* QSensorExplorer::selectedSensorItem() +{ + return _selectedSensorItem; +} + +/* + \fn QSensorExplorer::setSelectedSensorItem(QSensorItem* selitem) + Sets the QSensorItem \a selitem as the current selected QSensorItem. +*/ +void QSensorExplorer::setSelectedSensorItem(QSensorItem* selitem) +{ + if (selitem && _selectedSensorItem != selitem) { + if (_selectedSensorItem) + _selectedSensorItem->unSelect(); + _selectedSensorItem = selitem; + _selectedSensorItem->select(); + emit selectedSensorItemChanged(); + } +} + +QT_END_NAMESPACE diff --git a/examples/sensors/sensor_explorer/import/explorer.h b/examples/sensors/sensor_explorer/import/explorer.h new file mode 100644 index 00000000..eaac8104 --- /dev/null +++ b/examples/sensors/sensor_explorer/import/explorer.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSEONSOREXPLORER_H +#define QSEONSOREXPLORER_H + +#include +#include +#include "sensoritem.h" + +QT_BEGIN_NAMESPACE + +class QSensorExplorer : public QObject +{ + Q_OBJECT + Q_PROPERTY(QQmlListProperty availableSensors READ availableSensors NOTIFY availableSensorsChanged) + Q_PROPERTY(QSensorItem* selectedSensorItem READ selectedSensorItem WRITE setSelectedSensorItem NOTIFY selectedSensorItemChanged) +public: + QSensorExplorer(QObject* parent = 0); + virtual ~QSensorExplorer(); + +private: + QQmlListProperty availableSensors(); + void loadSensors(); + void setSelectedSensorItem(QSensorItem* selitem); + QSensorItem* selectedSensorItem(); + +Q_SIGNALS: + void availableSensorsChanged(); + void selectedSensorItemChanged(); + +private: + QList _availableSensors; + QSensorItem* _selectedSensorItem; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QSensorExplorer) + +#endif // QSEONSOREXPLORER_H diff --git a/examples/sensors/sensor_explorer/import/import.pro b/examples/sensors/sensor_explorer/import/import.pro new file mode 100644 index 00000000..1f97b67e --- /dev/null +++ b/examples/sensors/sensor_explorer/import/import.pro @@ -0,0 +1,25 @@ +TEMPLATE = lib +CONFIG += plugin + +TARGET = $$qtLibraryTarget(declarative_explorer) +TARGETPATH = Explorer + +QT += qml sensors + +SOURCES = main.cpp explorer.cpp sensoritem.cpp propertyinfo.cpp +HEADERS = explorer.h sensoritem.h propertyinfo.h + +MT_SYSROOT=$$(MT_SYSROOT) +!isEmpty(MT_SYSROOT):EXAMPLES_PREFIX=/opt/mt/applications +!isEmpty(EXAMPLES_PREFIX):DESTPATH=$$EXAMPLES_PREFIX/com.nokia.mt.sensor_explorer/imports/Explorer +else:DESTPATH=$$[QT_INSTALL_IMPORTS]/Explorer + +target.path=$$DESTPATH +INSTALLS += target + +qmldir.files=$$PWD/qmldir +qmldir.path=$$DESTPATH +INSTALLS += qmldir + +OTHER_FILES += \ + plugin.json qmldir diff --git a/examples/sensors/sensor_explorer/import/main.cpp b/examples/sensors/sensor_explorer/import/main.cpp new file mode 100644 index 00000000..80e2510d --- /dev/null +++ b/examples/sensors/sensor_explorer/import/main.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include "explorer.h" +#include + +QT_BEGIN_NAMESPACE + +class SensorExplorerDeclarativeModule : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface" FILE "plugin.json") +public: + virtual void registerTypes(const char *uri) + { + qDebug() << "SensorExplorerDeclarativeModule::registerTypes(const char *uri)"; + + Q_ASSERT(QLatin1String(uri) == QLatin1String("Explorer")); + qmlRegisterType(uri, 1, 0, "SensorExplorer"); + qmlRegisterType(uri, 1, 0, "SensorItem"); + qmlRegisterType(uri, 1, 0, "PropertyInfo"); + } +}; + +QT_END_NAMESPACE + +#include "main.moc" diff --git a/examples/sensors/sensor_explorer/import/plugin.json b/examples/sensors/sensor_explorer/import/plugin.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/examples/sensors/sensor_explorer/import/plugin.json @@ -0,0 +1 @@ +{} diff --git a/examples/sensors/sensor_explorer/import/propertyinfo.cpp b/examples/sensors/sensor_explorer/import/propertyinfo.cpp new file mode 100644 index 00000000..00f43e44 --- /dev/null +++ b/examples/sensors/sensor_explorer/import/propertyinfo.cpp @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensoritem.h" +#include +#include + +QT_BEGIN_NAMESPACE + +/* + \class QPropertyInfo + \brief The QPropertyInfo type provides an easy access for reading and writing the property values. +*/ + +/* + Construct a QPropertyInfo object with parent \a parent +*/ +QPropertyInfo::QPropertyInfo(QObject* parent) + : QObject(parent) + , _index(0) + , _isWriteable(false) + , _name("") + , _typeName("") + , _value("") +{} + +/* + Construct a QPropertyInfo object with parent \a parent, property name \a name, property index \a index, + property write access \a writeable, property type \a typeName and property value \a value +*/ +QPropertyInfo::QPropertyInfo(const QString& name, int index, bool writeable, const QString& typeName, const QString& value, QObject* parent) + : QObject(parent) + , _index(index) + , _isWriteable(writeable) + , _name(name) + , _typeName(typeName) + , _value(value) +{} + +/* + \property QPropertyInfo::name + Returns the name of the property +*/ +QString QPropertyInfo::name() +{ + return _name; +} + +/* + \property QPropertyInfo::typeName + Returns the type of the property +*/ +QString QPropertyInfo::typeName() +{ + return _typeName; +} + +/* + \property QPropertyInfo::value + Returns the current value of the property +*/ +QString QPropertyInfo::value() +{ + return _value; +} + +/* + \fn void QPropertyInfo::valueChanged() + Signal that notifies the client if the property value was changed. +*/ + +/* + \fn QPropertyInfo::setValue(const QString& value) + Sets the value \a value of the property +*/ +void QPropertyInfo::setValue(const QString& value) +{ + if (value != _value){ + _value = value; + emit valueChanged(); + } +} + +/* + \fn QPropertyInfo::index() + Returns the meta-data index of the property +*/ +int QPropertyInfo::index() +{ + return _index; +} + +/* + \property QPropertyInfo::isWriteable + Returns true if the property is writeable false if property is read only +*/ +bool QPropertyInfo::isWriteable() +{ + return _isWriteable; +} + +QT_END_NAMESPACE diff --git a/examples/sensors/sensor_explorer/import/propertyinfo.h b/examples/sensors/sensor_explorer/import/propertyinfo.h new file mode 100644 index 00000000..b3ebe4c0 --- /dev/null +++ b/examples/sensors/sensor_explorer/import/propertyinfo.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QPROPERTYINFO_H +#define QPROPERTYINFO_H + +#include +#include + +QT_BEGIN_NAMESPACE + +class QPropertyInfo : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name CONSTANT) + Q_PROPERTY(QString typeName READ typeName CONSTANT) + Q_PROPERTY(QString value READ value NOTIFY valueChanged) + Q_PROPERTY(bool isWriteable READ isWriteable CONSTANT) + +public: + QPropertyInfo(QObject* parent = 0); + QPropertyInfo(const QString& name, int index, bool writeable, const QString& typeName, const QString& value, QObject* parent=0); + QString name(); + QString typeName(); + QString value(); + void setValue(const QString& value); + int index(); + bool isWriteable(); + +Q_SIGNALS: + void valueChanged(); + +private: + int _index; + bool _isWriteable; + QString _name; + QString _typeName; + QString _value; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QPropertyInfo) + +#endif // QPROPERTYINFO_H diff --git a/examples/sensors/sensor_explorer/import/qmldir b/examples/sensors/sensor_explorer/import/qmldir new file mode 100644 index 00000000..60d8f883 --- /dev/null +++ b/examples/sensors/sensor_explorer/import/qmldir @@ -0,0 +1 @@ +plugin declarative_explorer diff --git a/examples/sensors/sensor_explorer/import/sensoritem.cpp b/examples/sensors/sensor_explorer/import/sensoritem.cpp new file mode 100644 index 00000000..dd9d0365 --- /dev/null +++ b/examples/sensors/sensor_explorer/import/sensoritem.cpp @@ -0,0 +1,322 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensoritem.h" +#include +#include + +QT_BEGIN_NAMESPACE + +/* + \class QSensorItem + \brief The QSensorItem type provides information about the meta-datas from a sensors installed on the system. +*/ + +/* + Construct a QSensorItem object with parent \a parent +*/ +QSensorItem::QSensorItem(QObject* parent) + : QObject(parent) + , _qsensor(0) +{ +} + +/* + Construct a QSensorItem object with QSensor \a sensor and parent \a parent +*/ +QSensorItem::QSensorItem(QSensor* sensor, QObject* parent) + : QObject(parent) + , _qsensor(sensor) +{ +} + +/* + Destructor of a QSensorItem +*/ +QSensorItem::~QSensorItem() +{ +} + +/* + \fn QSensorItem::startChanged() + Notifies the client if the sensors has changed its start active status +*/ + +/* + \property QSensorItem::start + This property starts or stops the sensor +*/ +bool QSensorItem::start() +{ + return (_qsensor ? _qsensor->isActive() : false); +} + +void QSensorItem::setStart(bool run) +{ + if (_qsensor) + _qsensor->setActive(run); +} + +/* + \property QSensorItem::id + Returns the sensor id of the sensor item +*/ +QString QSensorItem::id() +{ + return (_qsensor ? _qsensor->identifier() : ""); +} + +/* + Set the new value \a val to the QPropertyInfo object \a property +*/ +void QSensorItem::changePropertyValue(QPropertyInfo* property, const QString& val) +{ + if (_qsensor && _sensorProperties.contains(property)){ + if ( _qsensor->setProperty(property->name().toLatin1().constData(), QVariant(val))) + updateSensorPropertyValues(); + else + qWarning() << "new property value couldn't be set"; + } +} + +/* + Reading the meta-datas and activates the sensor. +*/ +void QSensorItem::select() +{ + if (_sensorProperties.isEmpty()) { + // Probe the reading using Qt's meta-object facilities + //Read properties from reader + QSensorReading *reading = _qsensor->reading(); + const QMetaObject *mo = reading->metaObject(); + int firstProperty = QSensorReading::staticMetaObject.propertyOffset(); + + for (int i = firstProperty; i < mo->propertyCount(); ++i) { + QString typeName = QLatin1String(mo->property(i).typeName()); + int crap = typeName.lastIndexOf("::"); + if (crap != -1) + typeName = typeName.mid(crap + 2); + + QPropertyInfo* pi = new QPropertyInfo(mo->property(i).name() + , i + , isWriteable(mo->property(i).name()) + , typeName + , "-" + , this); + _readerProperties.append(pi); + } + + //Read properties from sensor + const QMetaObject *mo1 = _qsensor->metaObject(); + firstProperty = QSensorReading::staticMetaObject.propertyOffset(); + + for (int i = firstProperty; i < mo1->propertyCount(); ++i) { + QString propertyname = mo1->property(i).name(); + if (ignoreProperty(propertyname)) + continue; + + QString typeName = QLatin1String(mo1->property(i).typeName()); + int crap = typeName.lastIndexOf("::"); + if (crap != -1) + typeName = typeName.mid(crap + 2); + + QPropertyInfo* pi = new QPropertyInfo(propertyname + , i + , isWriteable(propertyname) + , typeName + , "-" + , this); + _sensorProperties.append(pi); + } + updateSensorPropertyValues(); + connect(_qsensor, SIGNAL(readingChanged()), this, SLOT(sensorReadingChanged())); + } + connect(_qsensor, SIGNAL(activeChanged()), SIGNAL(startChanged())); +} + +/* + Unselect the sensor by stopping the sensor. +*/ +void QSensorItem::unSelect() +{ + _qsensor->stop(); + disconnect(_qsensor, SIGNAL(activeChanged()), this , SIGNAL(startChanged())); +} + +/* + Updates the property values from QSensor +*/ +void QSensorItem::updateSensorPropertyValues() +{ + if (_qsensor){ + const QMetaObject *mo = _qsensor->metaObject(); + for (int i = 0; i < _sensorProperties.count(); i++){ + QVariant val = mo->property(_sensorProperties[i]->index()).read(_qsensor); + _sensorProperties[i]->setValue(convertValue(_sensorProperties[i]->typeName(), val)); + } + } +} + +/* + \fn QSensorItem::propertiesChanged() + Notifies the client if the list of the properties was changed +*/ + +/* + Updates the property values from the QSensorReader +*/ +void QSensorItem::sensorReadingChanged() +{ + QSensorReading *reading = _qsensor->reading(); + const QMetaObject *mo = reading->metaObject(); + for (int i = 0; i < _readerProperties.count(); i++){ + QVariant val = mo->property(_readerProperties[i]->index()).read(reading); + _readerProperties[i]->setValue(convertValue(_readerProperties[i]->typeName(), val)); + } +} + +/* + Returns true if the property with the name \a propertyname should be ignored +*/ +bool QSensorItem::ignoreProperty(const QString& propertyname) +{ + if (propertyname == "reading" || + propertyname == "active" || + propertyname == "sensorid" || + propertyname == "connectedToBackend" || + propertyname == "busy") + return true; + + return false; +} + +/* + Returns true if the property with the name \a propertyname is writeable +*/ +bool QSensorItem::isWriteable(const QString& propertyname) +{ + if (_qsensor){ + const QMetaObject *mo = _qsensor->metaObject(); + int propertyindex = mo->indexOfProperty(propertyname.toLocal8Bit().constData()); + if (propertyindex >= 0){ + QMetaProperty prop = mo->property(propertyindex); + return prop.isWritable(); + } + else { + QSensorReading *reading = _qsensor->reading(); + const QMetaObject *moreader = reading->metaObject(); + propertyindex = moreader->indexOfProperty(propertyname.toLocal8Bit().constData()); + if (propertyindex >= 0){ + QMetaProperty prop = mo->property(propertyindex); + return prop.isWritable(); + } + } + } + + return false; +} + +/* + Convert the variant \a val dependend on the type \a type and returns the converted value as a QString +*/ +QString QSensorItem::convertValue(const QString& type, const QVariant& val) +{ + if (type == "LightLevel"){ + switch (val.toInt()) { + case 1: return "Dark"; + case 2: return "Twilight"; + case 3: return "Light"; + case 4: return "Bright"; + case 5: return "Sunny"; + default: return "Undefined"; + } + } + else if (type == "Orientation"){ + switch (val.toInt()) { + case 1: return "TopUp"; + case 2: return "TopDown"; + case 3: return "LeftUp"; + case 4: return "RightUp"; + case 5: return "FaceUp"; + case 6: return "FaceDown"; + default: return "Undefined"; + } + } + else if (type == "qrangelist"){ + qrangelist rangelist = val.value(); + QStringList ranges; + foreach (const qrange &r, rangelist) { + if (r.first == r.second) + ranges << QString("%1 Hz").arg(r.first); + else + ranges << QString("%1-%2 Hz").arg(r.first).arg(r.second); + } + if (ranges.count() > 0) + return ranges.join(", "); + return "-"; + } + else if (type == "qoutputrangelist") { + qoutputrangelist rangelist = val.value(); + QStringList ranges; + foreach (const qoutputrange &r, rangelist) { + ranges << QString("(%1, %2) += %3").arg(r.minimum).arg(r.maximum).arg(r.accuracy); + } + if (ranges.count() > 0) + return ranges.join(", "); + return "-"; + } + + return val.toString(); +} + +/* + \property QSensorItem::properties + Returns a list of all properties from the sensor +*/ +QQmlListProperty QSensorItem::properties() +{ + _properties.clear(); + _properties.append(_sensorProperties); + _properties.append(_readerProperties); + return QQmlListProperty (this, _properties); +} + +QT_END_NAMESPACE diff --git a/examples/sensors/sensor_explorer/import/sensoritem.h b/examples/sensors/sensor_explorer/import/sensoritem.h new file mode 100644 index 00000000..b937687f --- /dev/null +++ b/examples/sensors/sensor_explorer/import/sensoritem.h @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSENSORITEM_H +#define QSENSORITEM_H + +#include +#include +#include "propertyinfo.h" + +QT_BEGIN_NAMESPACE + +class QSensor; +class QSensorItem : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool start READ start WRITE setStart NOTIFY startChanged) + Q_PROPERTY(QString id READ id CONSTANT) + Q_PROPERTY(QQmlListProperty properties READ properties NOTIFY propertiesChanged) +public: + QSensorItem(QObject* parent = 0); + QSensorItem(QSensor* sensor, QObject* parent = 0); + virtual ~QSensorItem(); + +public slots: + void select(); + void unSelect(); + void changePropertyValue(QPropertyInfo* property, const QString& val); + +private slots: + void sensorReadingChanged(); + +private: + QString id(); + bool start(); + void setStart(bool run); + QQmlListProperty properties(); + QString convertValue(const QString& type, const QVariant& val); + bool isWriteable(const QString& propertyname); + bool ignoreProperty(const QString& propertyname); + void updateSensorPropertyValues(); + +Q_SIGNALS: + void propertiesChanged(); + void startChanged(); + +private: + QSensor* _qsensor; + QList _properties; + QList _readerProperties; + QList _sensorProperties; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QSensorItem) + +#endif // QSENSORITEM_H diff --git a/examples/sensors/sensor_explorer/info.json b/examples/sensors/sensor_explorer/info.json new file mode 100644 index 00000000..18f3e8d5 --- /dev/null +++ b/examples/sensors/sensor_explorer/info.json @@ -0,0 +1,15 @@ +{ + "info-version": "1.0", + "dict": { + "category": "application", + "runtime": "qml", + "displayName": { + "en_US": "Sensors Explorer" + }, + "subcategory": "utility", + "main": "QtSensors_sensor_explorer.qml", + "version": "1.0.0", + "identifier": "com.nokia.mt.sensorexplorer", + "author": "Qt" + } +} diff --git a/examples/sensors/sensor_explorer/qml.pro b/examples/sensors/sensor_explorer/qml.pro new file mode 100644 index 00000000..fae3705d --- /dev/null +++ b/examples/sensors/sensor_explorer/qml.pro @@ -0,0 +1,16 @@ +TEMPLATE = aux + +app.files = \ + info.json \ + $$files(*.qml) \ + icon.png \ + components \ + content + +MT_SYSROOT=$$(MT_SYSROOT) +!isEmpty(MT_SYSROOT):EXAMPLES_PREFIX=/opt/mt/applications +!isEmpty(EXAMPLES_PREFIX) { + app.path = $$EXAMPLES_PREFIX/com.nokia.mt.sensor_explorer + INSTALLS = app +} + diff --git a/examples/sensors/sensor_explorer/sensor_explorer.pro b/examples/sensors/sensor_explorer/sensor_explorer.pro new file mode 100644 index 00000000..85ba45ef --- /dev/null +++ b/examples/sensors/sensor_explorer/sensor_explorer.pro @@ -0,0 +1,6 @@ +TEMPLATE = subdirs +CONFIG += ordered + +SUBDIRS = \ + import \ + qml.pro diff --git a/examples/sensors/sensor_explorer/sensor_explorer.qml b/examples/sensors/sensor_explorer/sensor_explorer.qml new file mode 100644 index 00000000..88641604 --- /dev/null +++ b/examples/sensors/sensor_explorer/sensor_explorer.qml @@ -0,0 +1,196 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Import the declarative plugins +import QtQuick 2.0 +import "components" + +//! [0] +import Explorer 1.0 +//! [0] + +ApplicationWindow { + id: mainWnd + +//! [1] + SensorExplorer { + id: explorer + } +//! [1] + + SensorList { + id: sensorList + anchors.top: parent.top + anchors.topMargin: 20 + anchors.left: parent.left + anchors.right: parent.right + height: 170 + title: "sensor explorer" + +//! [2] + listmodel: explorer.availableSensors +//! [2] + + onSelectedItemChanged: { + explorer.selectedSensorItem = sensorList.selectedItem; + startstopButton.text=(explorer.selectedSensorItem !== null ? + (explorer.selectedSensorItem.start === true ? "Stop" : "Start") : "Start") + if (sensorList.selectedItem !== null) + +//! [3] + propertyList.listmodel = sensorList.selectedItem.properties; +//! [3] + } + } + + Rectangle { + id: listSplitLine + anchors.top: sensorList.bottom + anchors.left: parent.left + anchors.right: parent.right + anchors.leftMargin: 5 + anchors.rightMargin: 5 + height: 1 + border.width: 1 + border.color: "#999999" + } + + PropertyList { + id: propertyList + anchors.top: listSplitLine.bottom + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: listPropertyEndLine.top + anchors.bottomMargin: 5 + + onSelectedItemChanged: { + textfield.enabled = (propertyList.selectedItem === null ? + false : propertyList.selectedItem.isWriteable); + } + } + + Rectangle { + id: listPropertyEndLine + anchors.bottom: startstopButton.top + anchors.bottomMargin: 5 + anchors.left: parent.left + anchors.right: parent.right + anchors.leftMargin: 5 + anchors.rightMargin: 5 + height: 1 + border.width: 1 + border.color: "#999999" + } + + + Button { + id: startstopButton + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.margins: 5 + text: (explorer.selectedSensorItem !== null ? + (explorer.selectedSensorItem.start === true ? "Stop" : "Start") : "Start") + enabled: true + height: 30 + width: 80 + + onClicked: { + if (explorer.selectedSensorItem !== null) { +//! [5] + if (text === "Start") { + explorer.selectedSensorItem.start = true; + text = "Stop"; + } + else { + explorer.selectedSensorItem.start = false; + text = "Start"; + } +//! [5] + } + + textfield.text = ""; + } + } + + TextField { + id: textfield + anchors.top: parent.bottom + anchors.topMargin: -35 + anchors.left: startstopButton.right + anchors.right: parent.right + anchors.margins: 5 + height: 30 + enabled: false + + onEnabledChanged: { + if (!textfield.enabled) { + textfield.closeSoftwareInputPanel(); + textfield.anchors.top= parent.bottom; + textfield.anchors.topMargin= -35; + textfield.text = ""; + } + } + + onFocusChanged: { + if (textfield.focus) { + textfield.anchors.top= sensorList.bottom + textfield.anchors.topMargin= -15 + } + else { + textfield.closeSoftwareInputPanel(); + textfield.anchors.top= parent.bottom; + textfield.anchors.topMargin= -35; + } + } + + onAccepted: { + + if (explorer.selectedSensorItem !== null + && propertyList.selectedItem !== null) { +//! [4] + explorer.selectedSensorItem.changePropertyValue(propertyList.selectedItem, textfield.text); +//! [4] + propertyList.focus=true; + } + textfield.text = ""; + } + } +} + diff --git a/examples/sensors/sensorgestures/gesture.png b/examples/sensors/sensorgestures/gesture.png new file mode 100644 index 00000000..707d5c4e Binary files /dev/null and b/examples/sensors/sensorgestures/gesture.png differ diff --git a/examples/sensors/sensorgestures/main.cpp b/examples/sensors/sensorgestures/main.cpp new file mode 100644 index 00000000..49594d4e --- /dev/null +++ b/examples/sensors/sensorgestures/main.cpp @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/examples/sensors/sensorgestures/mainwindow.cpp b/examples/sensors/sensorgestures/mainwindow.cpp new file mode 100644 index 00000000..9dd8a611 --- /dev/null +++ b/examples/sensors/sensorgestures/mainwindow.cpp @@ -0,0 +1,168 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include "mainwindow.h" +#include "ui_mainwindow.h" + +#include +#include + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + //! [0] + + QSensorGestureManager manager; + + Q_FOREACH (const QString &gesture, manager.gestureIds()) { + + QTreeWidgetItem *gestureId = new QTreeWidgetItem(ui->treeWidget); + QStringList recognizerSignals = manager.recognizerSignals(gesture); + gestureId->setText(0,gesture); + + for (int i = 0; i < recognizerSignals.count(); i++) { + QTreeWidgetItem *oneSignal = new QTreeWidgetItem(gestureId); + oneSignal->setText(0,recognizerSignals.at(i)); + } + ui->treeWidget->insertTopLevelItem(0,gestureId); + } + //! [0] + + + ui->textEdit->setReadOnly(true); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::detectedShake(const QString &name) +{ + QString str = ""+name+"
"; + ui->textEdit->insertHtml(str); + ui->textEdit->ensureCursorVisible(); +} + +void MainWindow::on_pushButton_clicked() +{ + ui->textEdit->clear(); +} + +void MainWindow::onShake() +{ + QString str = "onShake()
"; + ui->textEdit->insertHtml(str); + ui->textEdit->ensureCursorVisible(); +} + +void MainWindow::on_startPushButton_clicked() +{ + if (ui->treeWidget->currentItem() == 0) + return; + QString currentRecognizer; + + if (ui->treeWidget->currentItem()->childCount() == 0) { + currentRecognizer = ui->treeWidget->currentItem()->parent()->text(0); + } else { + currentRecognizer = ui->treeWidget->currentItem()->text(0); + } + + if (recognizerMap.contains(currentRecognizer)) + return; + //! [1] + QSensorGestureManager manager; + QSensorGesture *thisGesture = new QSensorGesture(QStringList() << currentRecognizer, this); + + if (currentRecognizer.contains("QtSensors.shake")) { + connect(thisGesture,SIGNAL(shake()), + this,SLOT(onShake())); + } + + connect(thisGesture,SIGNAL(detected(QString)), + this,SLOT(detectedShake(QString))); + thisGesture->startDetection(); + + //! [1] + + recognizerMap.insert(currentRecognizer,thisGesture); + + QString str = QString("Started %1
").arg(currentRecognizer); + ui->textEdit->insertHtml(str); + ui->textEdit->ensureCursorVisible(); +} + +void MainWindow::on_stopPushButton_clicked() +{ + if (ui->treeWidget->currentItem() == 0) + return; + QString currentRecognizer; + + if (ui->treeWidget->currentItem()->childCount() == 0) { + currentRecognizer = ui->treeWidget->currentItem()->parent()->text(0); + } else { + currentRecognizer = ui->treeWidget->currentItem()->text(0); + } + + if (!recognizerMap.contains(currentRecognizer)) + return; + //! [2] + + recognizerMap[currentRecognizer]->stopDetection(); + + if (currentRecognizer == "QtSensors.shake") { + disconnect(recognizerMap[currentRecognizer],SIGNAL(shake()), + this,SLOT(onShake())); + } + disconnect(recognizerMap[currentRecognizer],SIGNAL(detected(QString)), + this,SLOT(detectedShake(QString))); + //! [2] + + recognizerMap.take(currentRecognizer); + + QString str = QString("Stopped %1
").arg(currentRecognizer); + ui->textEdit->insertHtml(str); + ui->textEdit->ensureCursorVisible(); +} diff --git a/examples/sensors/sensorgestures/mainwindow.h b/examples/sensors/sensorgestures/mainwindow.h new file mode 100644 index 00000000..1e38f1be --- /dev/null +++ b/examples/sensors/sensorgestures/mainwindow.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +QT_BEGIN_NAMESPACE +namespace Ui { + class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + +private: + Ui::MainWindow *ui; + QMap recognizerMap; + +private slots: + void detectedShake(const QString&); + void onShake(); + + void on_pushButton_clicked(); + + void on_startPushButton_clicked(); + void on_stopPushButton_clicked(); +}; + + +QT_END_NAMESPACE + +#endif // MAINWINDOW_H diff --git a/examples/sensors/sensorgestures/mainwindow.ui b/examples/sensors/sensorgestures/mainwindow.ui new file mode 100644 index 00000000..baccf98c --- /dev/null +++ b/examples/sensors/sensorgestures/mainwindow.ui @@ -0,0 +1,84 @@ + + + MainWindow + + + + 0 + 0 + 423 + 474 + + + + MainWindow + + + + + + + + Gesture Recognizer Id + + + + + + + + Start + + + + + + + Stop + + + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Lucida Grande'; font-size:13pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:9pt;"></p></body></html> + + + + + + + Clear + + + + + + + + + 0 + 0 + 423 + 22 + + + + + + TopToolBarArea + + + false + + + + + + + + diff --git a/examples/sensors/sensorgestures/sensorgestures.pro b/examples/sensors/sensorgestures/sensorgestures.pro new file mode 100644 index 00000000..295db944 --- /dev/null +++ b/examples/sensors/sensorgestures/sensorgestures.pro @@ -0,0 +1,13 @@ +TEMPLATE = app +TARGET = gesture +QT += core gui sensors widgets + +SOURCES += main.cpp\ + mainwindow.cpp + +HEADERS += mainwindow.h + +FORMS += mainwindow.ui + +OTHER_FILES += \ + gesture.png diff --git a/examples/sensors/sensors.pro b/examples/sensors/sensors.pro new file mode 100644 index 00000000..f865ece5 --- /dev/null +++ b/examples/sensors/sensors.pro @@ -0,0 +1,16 @@ +TEMPLATE = subdirs + +SUBDIRS += \ + accel \ + accelbubble \ + cubehouse \ + grue \ + qmlsensorgestures \ + maze \ + qmlqtsensors \ + sensor_explorer \ + shakeit + +!isEmpty(QT.widgets.name):SUBDIRS += \ + sensorgestures + diff --git a/examples/sensors/shakeit/audio/loopy2a_mono.wav b/examples/sensors/shakeit/audio/loopy2a_mono.wav new file mode 100644 index 00000000..7d76cb65 Binary files /dev/null and b/examples/sensors/shakeit/audio/loopy2a_mono.wav differ diff --git a/examples/sensors/shakeit/audio/phone.wav b/examples/sensors/shakeit/audio/phone.wav new file mode 100644 index 00000000..884e9ac2 Binary files /dev/null and b/examples/sensors/shakeit/audio/phone.wav differ diff --git a/examples/sensors/shakeit/content/triangle.png b/examples/sensors/shakeit/content/triangle.png new file mode 100644 index 00000000..f366537e Binary files /dev/null and b/examples/sensors/shakeit/content/triangle.png differ diff --git a/examples/sensors/shakeit/content/triangle2.png b/examples/sensors/shakeit/content/triangle2.png new file mode 100644 index 00000000..9318d5a3 Binary files /dev/null and b/examples/sensors/shakeit/content/triangle2.png differ diff --git a/examples/sensors/shakeit/content/triangle3.png b/examples/sensors/shakeit/content/triangle3.png new file mode 100644 index 00000000..4cc5ccda Binary files /dev/null and b/examples/sensors/shakeit/content/triangle3.png differ diff --git a/examples/sensors/shakeit/icon.png b/examples/sensors/shakeit/icon.png new file mode 100644 index 00000000..d8f21546 Binary files /dev/null and b/examples/sensors/shakeit/icon.png differ diff --git a/examples/sensors/shakeit/info.json b/examples/sensors/shakeit/info.json new file mode 100644 index 00000000..a98f6f2b --- /dev/null +++ b/examples/sensors/shakeit/info.json @@ -0,0 +1,14 @@ +{ + "info-version": "1.0", + "dict": { + "displayName": { + "en_US": "ShakeIt!" + }, + "identifier": "com.nokia.mt.shakeit", + "runtime": "qml", + "main": "QtSensors_shakeit.qml", + "version": "1.0.0", + "category": "application", + "subcategory": "utility" + } +} diff --git a/examples/sensors/shakeit/qml.pro b/examples/sensors/shakeit/qml.pro new file mode 100644 index 00000000..1265d8e9 --- /dev/null +++ b/examples/sensors/shakeit/qml.pro @@ -0,0 +1,16 @@ +TEMPLATE = aux + +app.files = \ + info.json \ + $$files(*.qml) \ + icon.png \ + audio \ + content + +MT_SYSROOT=$$(MT_SYSROOT) +!isEmpty(MT_SYSROOT):EXAMPLES_PREFIX=/opt/mt/applications +!isEmpty(EXAMPLES_PREFIX) { + app.path = $$EXAMPLES_PREFIX/com.nokia.mt.shakeit + INSTALLS = app +} + diff --git a/examples/sensors/shakeit/shakeit.pro b/examples/sensors/shakeit/shakeit.pro new file mode 100644 index 00000000..6dc685b9 --- /dev/null +++ b/examples/sensors/shakeit/shakeit.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs + +SUBDIRS = qml.pro diff --git a/examples/sensors/shakeit/shakeit.qml b/examples/sensors/shakeit/shakeit.qml new file mode 100644 index 00000000..3b3b1f5c --- /dev/null +++ b/examples/sensors/shakeit/shakeit.qml @@ -0,0 +1,323 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +//! [0] +import QtSensors 5.0 +//! [0] +import QtMultimedia 5.0 + + + +Rectangle { + id: window + + 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") + y: parent.height / 4 + anchors.horizontalCenter: parent.horizontalCenter + } + Image { + id: triangle1 + smooth: true + source: "content/triangle.png" + x: parent.width / 2 - (triangle1.width / 2) + y: parent.height / 2 - (triangle1.height); + Behavior on x { SmoothedAnimation { velocity: 200 } } + Behavior on y { SmoothedAnimation { velocity: 200 } } + transform: Rotation { + id: myRot + } + } + Image { + id: triangle2 + smooth: true + source: "content/triangle2.png" + x: parent.width / 2 - (triangle1.width + triangle2.width / 2) + y: parent.height / 2 + (triangle2.height / 2); + Behavior on x { SmoothedAnimation { velocity: 200 } } + Behavior on y { SmoothedAnimation { velocity: 200 } } + } + Image { + id: triangle3 + smooth: true + 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 } } + } + + states: [ + State { + name: "rotated" + PropertyChanges { target: triangle1; rotation: 180 } + PropertyChanges { target: triangle2; rotation: 90 } + PropertyChanges { target: triangle3; rotation: 270 } + }, + State { + name: "default" + PropertyChanges { target: triangle1; rotation: 0; + x: parent.width / 2 - (triangle1.width / 2) + y: parent.height / 2 - (triangle1.height); + } + PropertyChanges { target: triangle2; rotation: 0; + x: parent.width / 2 - (triangle1.width + triangle2.width / 2) + y: parent.height / 2 + (triangle2.height / 2); + } + PropertyChanges { target: triangle3; rotation: 0; + x: parent.width / 2 + (triangle1.width / 2) + y: parent.height / 2 + (triangle3.height / 2); + } + }, + State { + name: "whipped" + PropertyChanges { target: triangle1; rotation: 0; x:0; } + PropertyChanges { target: triangle2; rotation: 0; x:0; y:triangle1.x + triangle1.height; } + PropertyChanges { target: triangle3; rotation: 0; x:0; + y: triangle2.y + triangle2.height; } + }, + State { + name: "twistedR" + PropertyChanges { target: triangle1; rotation: 270; + x:window.width - triangle1.width; + } + PropertyChanges { target: triangle2; rotation: 180; + x:window.width - triangle2.width; + } + PropertyChanges { target: triangle3; rotation: 90; + x:window.width - triangle3.width; + y:triangle2.y + triangle2.height; + } + }, + State { + name: "twistedL" + PropertyChanges { target: triangle1; rotation: 270; + x:0; + } + PropertyChanges { target: triangle2; rotation: 180; + x:0; + } + PropertyChanges { target: triangle3; rotation: 90; + x:0; + y:triangle2.y + triangle2.height; + } + }, + State { + name: "covered" + PropertyChanges { target: triangle1; rotation: 0; + x: window.width / 3 - triangle1.width / 2; + y: window.height - triangle1.height; + } + PropertyChanges { target: triangle2; rotation: 0; + x: window.width / 2 - triangle2.width / 2; // middle + y: window.height - triangle2.height; + } + PropertyChanges { target: triangle3; rotation: 0; + x: (window.width / 3 + window.width / 3) - triangle3.width / 2; + y: window.height - triangle3.height; + } + }, + State { + name: "hovered" + PropertyChanges { target: triangle1; rotation: 90; + x: window.width / 3 - triangle1.width / 2; + y: triangle1.height; + } + PropertyChanges { target: triangle2; rotation: 270; + x: window.width / 2 - triangle2.width / 2; // middle + y: triangle2.height; + } + PropertyChanges { target: triangle3; rotation: 195; + x: (window.width / 3 + window.width / 3) - triangle3.width / 2; + y: triangle3.height + } + }, + State { + name :"slammed" + PropertyChanges { target: triangle1; rotation: 0; + x: 0; + y: 0 + 30 + } + PropertyChanges { target: triangle2; rotation: 0; + x: window.width - triangle2.width; + y: 0 + 30 + ;} + PropertyChanges { target: triangle3; rotation: 0; + x: window.width / 2 - triangle3.width / 2; + y:window.height - triangle3.height; + } + }, + State { + name: "doubletapped" + PropertyChanges { target: triangle1; rotation: 114; + transformOrigin: Item.BottomLeft + } + PropertyChanges { target: triangle2; rotation: 120; + transformOrigin: Item.BottomLeft + } + } + ] + + + transitions: [ + Transition { + + ParallelAnimation { + 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; + direction: RotationAnimation.Counterclockwise } + RotationAnimation { id: t3Rotation; target: triangle3; duration: 2000; + direction: RotationAnimation.Clockwise } + } + + }, Transition { + to: "slammed" + SequentialAnimation { + NumberAnimation { properties: "x"; easing.type: Easing.OutBounce;duration: 500; } + + } + }, Transition { + to: "doubletapped" + 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; } + } + }, Transition { + from: "doubletapped" + SequentialAnimation { + NumberAnimation { properties: "rotation"; easing.type: Easing.OutBounce;duration: 1500; } + PropertyAction { target: triangle1; property: "transformOrigin" } + PropertyAction { target: triangle2; property: "transformOrigin" } + } + } + ] + +//! [1] + SensorGesture { +//! [1] + id: sensorGesture +//! [3] + enabled: true +//! [3] +//! [2] + gestures : ["QtSensors.shake", "QtSensors.whip", "QtSensors.twist", "QtSensors.cover", + "QtSensors.hover", "QtSensors.turnover", "QtSensors.pickup", "QtSensors.slam" , "QtSensors.doubletap"] +//! [2] +//! [4] + onDetected:{ + console.debug(gesture) + label.text = gesture + + if (gesture == "shake") { + window.state == "rotated" ? window.state = "default" : window.state = "rotated" + timer.start() + } + if (gesture == "whip") { + window.state == "whipped" ? window.state = "default" : window.state = "whipped" + timer.start() + } + if (gesture == "twistRight") { + window.state == "twistedR" ? window.state = "default" : window.state = "twistedR" + timer.start() + } + if (gesture == "twistLeft") { + window.state == "twistedL" ? window.state = "default" : window.state = "twistedL" + timer.start() + } + if (gesture == "cover") { + window.state == "covered" ? window.state = "default" : window.state = "covered" + timer.start() + } + if (gesture == "hover") { + window.state == "hovered" ? window.state = "default" : window.state = "hovered" + timer.start() + } + if (gesture == "turnover") { + window.state = "default" + loopy2a_mono.play(); + timer.start() + } + if (gesture == "pickup") { + window.state = "default" + phone.play() + timer.start() + } + if (gesture == "slam") { + window.state == "slammed" ? window.state = "default" : window.state = "slammed" + timer.start() + } + if (gesture == "doubletap") { + window.state == "doubletapped" ? window.state = "default" : window.state = "doubletapped" + timer.start() + } + } +//! [4] + } + Timer { + id: timer + running: false + repeat: false + interval: 3000 + onTriggered: { + console.log("timer triggered") + window.state = "default" + label.text = "Try another gesture" + } + } +} -- cgit v1.2.3