summaryrefslogtreecommitdiff
path: root/examples/QtSensors/grue
diff options
context:
space:
mode:
authorWolfgang Beck <wolfgang.beck@nokia.com>2012-05-17 12:27:18 +1000
committerQt by Nokia <qt-info@nokia.com>2012-05-24 03:06:56 +0200
commit17d908ba5205513e9ed0be33aebeb3736bda0326 (patch)
treeda04213540ee61853aab6b4260721f1badd703b2 /examples/QtSensors/grue
parent32e2d98ea438041e7e0c4df7e67053c5ee7527a7 (diff)
downloadqtsensors-17d908ba5205513e9ed0be33aebeb3736bda0326.tar.gz
Unfork the examples.
Some examples were forked off and updated. Unfork by bringing these changes back (a later update will bring the other examples in line with this new style). The changes are primarily made up of file renaming. Also, JPG files have been converted to PNG. Some documentation updates have been done. Change-Id: Ib090abb5ebea2003d479d2336a23317f52b8c4d8 Reviewed-by: Lincoln Ramsay <lincoln.ramsay@nokia.com>
Diffstat (limited to 'examples/QtSensors/grue')
-rw-r--r--examples/QtSensors/grue/console_app/console_app.pro6
-rw-r--r--examples/QtSensors/grue/console_app/main.cpp89
-rw-r--r--examples/QtSensors/grue/grue.pro8
-rw-r--r--examples/QtSensors/grue/import/import.pro33
-rw-r--r--examples/QtSensors/grue/import/main.cpp142
-rw-r--r--examples/QtSensors/grue/import/plugin.json1
-rw-r--r--examples/QtSensors/grue/import/qmldir1
-rw-r--r--examples/QtSensors/grue/lib/gruesensor.cpp137
-rw-r--r--examples/QtSensors/grue/lib/gruesensor.h85
-rw-r--r--examples/QtSensors/grue/lib/gruesensor_p.h66
-rw-r--r--examples/QtSensors/grue/lib/lib.pro27
-rw-r--r--examples/QtSensors/grue/plugin/gruesensorimpl.cpp140
-rw-r--r--examples/QtSensors/grue/plugin/gruesensorimpl.h77
-rw-r--r--examples/QtSensors/grue/plugin/main.cpp81
-rw-r--r--examples/QtSensors/grue/plugin/plugin.json1
-rw-r--r--examples/QtSensors/grue/plugin/plugin.pro27
-rw-r--r--examples/QtSensors/grue/qml_app/grue.pngbin0 -> 11207 bytes
-rw-r--r--examples/QtSensors/grue/qml_app/grue.xcfbin0 -> 23704 bytes
-rw-r--r--examples/QtSensors/grue/qml_app/icon.pngbin0 -> 7951 bytes
-rw-r--r--examples/QtSensors/grue/qml_app/icon.xcfbin0 -> 22397 bytes
-rw-r--r--examples/QtSensors/grue/qml_app/info.json12
-rw-r--r--examples/QtSensors/grue/qml_app/main.qml95
-rw-r--r--examples/QtSensors/grue/qml_app/qml_app.pro15
23 files changed, 1043 insertions, 0 deletions
diff --git a/examples/QtSensors/grue/console_app/console_app.pro b/examples/QtSensors/grue/console_app/console_app.pro
new file mode 100644
index 0000000..33d4317
--- /dev/null
+++ b/examples/QtSensors/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/QtSensors/grue/console_app/main.cpp b/examples/QtSensors/grue/console_app/main.cpp
new file mode 100644
index 0000000..dc62e4d
--- /dev/null
+++ b/examples/QtSensors/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 <QtCore>
+#include <qsensor.h>
+
+class Filter : public QSensorFilter
+{
+ int lastPercent;
+public:
+ Filter()
+ : QSensorFilter()
+ , lastPercent(0)
+ {
+ }
+
+ bool filter(QSensorReading *reading)
+ {
+ int percent = reading->property("chanceOfBeingEaten").value<qreal>() * 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/QtSensors/grue/grue.pro b/examples/QtSensors/grue/grue.pro
new file mode 100644
index 0000000..0405286
--- /dev/null
+++ b/examples/QtSensors/grue/grue.pro
@@ -0,0 +1,8 @@
+TEMPLATE = subdirs
+
+SUBDIRS += lib plugin console_app
+SUBDIRS += import qml_app
+
+plugin.depends = lib
+import.depends = lib
+
diff --git a/examples/QtSensors/grue/import/import.pro b/examples/QtSensors/grue/import/import.pro
new file mode 100644
index 0000000..753e1ef
--- /dev/null
+++ b/examples/QtSensors/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/QtSensors/grue/import/main.cpp b/examples/QtSensors/grue/import/main.cpp
new file mode 100644
index 0000000..6c32703
--- /dev/null
+++ b/examples/QtSensors/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 <QtQml/qqmlextensionplugin.h>
+#include <QtQml/qqml.h>
+
+#include <gruesensor.h>
+#include <QDebug>
+
+#ifdef BUNDLED_PLUGIN
+#include <QPluginLoader>
+#include <QSensorPluginInterface>
+#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 <GrueSensor >(package, major, minor, "GrueSensor");
+ qmlRegisterUncreatableType<GrueSensorReading>(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<QSensorChangesInterface*>(instance);
+ if (m_changes) {
+ QSensor *sensor = new QSensor(QByteArray(), this);
+ connect(sensor, SIGNAL(availableSensorsChanged()), this, SLOT(sensorsChanged()));
+ m_changes->sensorsChanged();
+ }
+ QSensorPluginInterface *plugin = qobject_cast<QSensorPluginInterface*>(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 element reports on your chance of being eaten by a Grue.
+
+ The GrueSensor element reports on your chance of being eaten by a Grue.
+
+ This element 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 element holds the most recent GrueSensor reading.
+
+ The GrueSensorReading element holds the most recent GrueSensor reading.
+
+ This element wraps the GrueSensorReading class. Please see the documentation for
+ GrueSensorReading for details.
+
+ This element cannot be directly created.
+*/
+
+/*
+ \qmlproperty qreal Grue1::GrueSensorReading::chanceOfBeingEaten
+ Please see GrueSensorReading::chanceOfBeingEaten for information about this property.
+*/
diff --git a/examples/QtSensors/grue/import/plugin.json b/examples/QtSensors/grue/import/plugin.json
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/examples/QtSensors/grue/import/plugin.json
@@ -0,0 +1 @@
+{}
diff --git a/examples/QtSensors/grue/import/qmldir b/examples/QtSensors/grue/import/qmldir
new file mode 100644
index 0000000..266b7c1
--- /dev/null
+++ b/examples/QtSensors/grue/import/qmldir
@@ -0,0 +1 @@
+plugin declarative_grue
diff --git a/examples/QtSensors/grue/lib/gruesensor.cpp b/examples/QtSensors/grue/lib/gruesensor.cpp
new file mode 100644
index 0000000..b1f00ed
--- /dev/null
+++ b/examples/QtSensors/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/QtSensors/grue/lib/gruesensor.h b/examples/QtSensors/grue/lib/gruesensor.h
new file mode 100644
index 0000000..8088988
--- /dev/null
+++ b/examples/QtSensors/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 <qsensor.h>
+
+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<GrueSensorReading*>(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<GrueSensorReading*>(QSensor::reading()); }
+ static char const * const type;
+};
+// end generated code
+
+#endif
diff --git a/examples/QtSensors/grue/lib/gruesensor_p.h b/examples/QtSensors/grue/lib/gruesensor_p.h
new file mode 100644
index 0000000..4996e86
--- /dev/null
+++ b/examples/QtSensors/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/QtSensors/grue/lib/lib.pro b/examples/QtSensors/grue/lib/lib.pro
new file mode 100644
index 0000000..e048e60
--- /dev/null
+++ b/examples/QtSensors/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/QtSensors/grue/plugin/gruesensorimpl.cpp b/examples/QtSensors/grue/plugin/gruesensorimpl.cpp
new file mode 100644
index 0000000..e7152a6
--- /dev/null
+++ b/examples/QtSensors/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 <QDebug>
+#include <QTimer>
+
+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<GrueSensorReading>(&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/QtSensors/grue/plugin/gruesensorimpl.h b/examples/QtSensors/grue/plugin/gruesensorimpl.h
new file mode 100644
index 0000000..ed89711
--- /dev/null
+++ b/examples/QtSensors/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 <qsensorbackend.h>
+#include "gruesensor.h"
+#include <qambientlightsensor.h>
+#include <QTime>
+
+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/QtSensors/grue/plugin/main.cpp b/examples/QtSensors/grue/plugin/main.cpp
new file mode 100644
index 0000000..36aec29
--- /dev/null
+++ b/examples/QtSensors/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 <qsensorplugin.h>
+#include <qsensorbackend.h>
+#include <qsensormanager.h>
+#include <QFile>
+#include <QDebug>
+
+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/QtSensors/grue/plugin/plugin.json b/examples/QtSensors/grue/plugin/plugin.json
new file mode 100644
index 0000000..8a55b3a
--- /dev/null
+++ b/examples/QtSensors/grue/plugin/plugin.json
@@ -0,0 +1 @@
+{ "Keys": [ "notused" ] }
diff --git a/examples/QtSensors/grue/plugin/plugin.pro b/examples/QtSensors/grue/plugin/plugin.pro
new file mode 100644
index 0000000..32e127f
--- /dev/null
+++ b/examples/QtSensors/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/QtSensors/grue/qml_app/grue.png b/examples/QtSensors/grue/qml_app/grue.png
new file mode 100644
index 0000000..f0b070b
--- /dev/null
+++ b/examples/QtSensors/grue/qml_app/grue.png
Binary files differ
diff --git a/examples/QtSensors/grue/qml_app/grue.xcf b/examples/QtSensors/grue/qml_app/grue.xcf
new file mode 100644
index 0000000..2837ed7
--- /dev/null
+++ b/examples/QtSensors/grue/qml_app/grue.xcf
Binary files differ
diff --git a/examples/QtSensors/grue/qml_app/icon.png b/examples/QtSensors/grue/qml_app/icon.png
new file mode 100644
index 0000000..f3f038c
--- /dev/null
+++ b/examples/QtSensors/grue/qml_app/icon.png
Binary files differ
diff --git a/examples/QtSensors/grue/qml_app/icon.xcf b/examples/QtSensors/grue/qml_app/icon.xcf
new file mode 100644
index 0000000..8416c49
--- /dev/null
+++ b/examples/QtSensors/grue/qml_app/icon.xcf
Binary files differ
diff --git a/examples/QtSensors/grue/qml_app/info.json b/examples/QtSensors/grue/qml_app/info.json
new file mode 100644
index 0000000..2e14fc7
--- /dev/null
+++ b/examples/QtSensors/grue/qml_app/info.json
@@ -0,0 +1,12 @@
+{
+ "info-version": "1.0",
+ "dict": {
+ "DisplayName": "Grue Sensor",
+ "Identifier": "com.nokia.mt.grue",
+ "Runtime": "qml",
+ "MainQML": "main.qml",
+ "Version": "1.0.0",
+ "Category": "application",
+ "Summary": "The Grue sensor identifies your chance of being eaten by a Grue."
+ }
+}
diff --git a/examples/QtSensors/grue/qml_app/main.qml b/examples/QtSensors/grue/qml_app/main.qml
new file mode 100644
index 0000000..05d267c
--- /dev/null
+++ b/examples/QtSensors/grue/qml_app/main.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 = "<p>" + thetext + "</p>";
+ 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/QtSensors/grue/qml_app/qml_app.pro b/examples/QtSensors/grue/qml_app/qml_app.pro
new file mode 100644
index 0000000..c017dcc
--- /dev/null
+++ b/examples/QtSensors/grue/qml_app/qml_app.pro
@@ -0,0 +1,15 @@
+TEMPLATE = aux
+
+app.files = \
+ icon.png \
+ info.json \
+ main.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
+}
+