summaryrefslogtreecommitdiffstats
path: root/src/imports/sensors
diff options
context:
space:
mode:
authorLincoln Ramsay <lincoln.ramsay@nokia.com>2012-03-02 14:13:39 +1000
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-03 09:22:38 +0200
commit4c61854d60fb5d2c68c6dcb1fb5bdf5c0dead3e2 (patch)
treeb41d70a37b8a1ff76c32025d8562a94581a3bd22 /src/imports/sensors
parentfb68fb8c052ae08fabed8f49256e79b0d0915fb0 (diff)
Add TiltSensor to QtMobility.sensors 1.3
This has been adapted from the TiltSensor type in QtSensors 5.0 import but the code there has been split into multiple pieces. There's a C++ class, a generic backend and a QML interface. Change-Id: Ic09465a5f76250a02a13938abe4789958137376f Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Diffstat (limited to 'src/imports/sensors')
-rw-r--r--src/imports/sensors/plugins.qmltypes16
-rw-r--r--src/imports/sensors/qmlirproximitysensor.h1
-rw-r--r--src/imports/sensors/qmltiltsensor.cpp166
-rw-r--r--src/imports/sensors/qmltiltsensor.h94
-rw-r--r--src/imports/sensors/sensors.cpp29
-rw-r--r--src/imports/sensors/sensors.pro20
6 files changed, 310 insertions, 16 deletions
diff --git a/src/imports/sensors/plugins.qmltypes b/src/imports/sensors/plugins.qmltypes
index 49c2e748..eecc3a93 100644
--- a/src/imports/sensors/plugins.qmltypes
+++ b/src/imports/sensors/plugins.qmltypes
@@ -495,5 +495,21 @@ Module {
Signal { name: "tapDirectionChanged"; type: "void" }
Signal { name: "isDoubleTapChanged"; type: "void" }
}
+ Component {
+ name: "QmlTiltSensor"
+ prototype: "QmlSensor"
+ exports: ["TiltSensor 1.3"]
+ }
+ Method { name: "calibrate"; type: "void" }
+ }
+ Component {
+ name: "QmlTiltSensorReading"
+ prototype: "QmlSensorReading"
+ exports: ["TiltReading 1.3"]
+ Property { name: "yRotation"; type: "double"; isReadonly: true }
+ Property { name: "xRotation"; type: "double"; isReadonly: true }
+ Signal { name: "yRotationChanged"; type: "void" }
+ Signal { name: "xRotationChanged"; type: "void" }
+ }
ModuleApi { version: 1.3; name: "QmlSensorGlobal" }
}
diff --git a/src/imports/sensors/qmlirproximitysensor.h b/src/imports/sensors/qmlirproximitysensor.h
index bf188d2a..2b2d4c49 100644
--- a/src/imports/sensors/qmlirproximitysensor.h
+++ b/src/imports/sensors/qmlirproximitysensor.h
@@ -56,7 +56,6 @@ public:
explicit QmlIRProximitySensor(QObject *parent = 0);
~QmlIRProximitySensor();
-
private:
QSensor *sensor() const Q_DECL_OVERRIDE;
QIRProximitySensor *m_sensor;
diff --git a/src/imports/sensors/qmltiltsensor.cpp b/src/imports/sensors/qmltiltsensor.cpp
new file mode 100644
index 00000000..26f6611d
--- /dev/null
+++ b/src/imports/sensors/qmltiltsensor.cpp
@@ -0,0 +1,166 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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, Digia gives you certain additional
+** rights. These rights are described in the Digia 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.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qmltiltsensor.h"
+#include <QtSensors/qtiltsensor.h>
+
+QT_BEGIN_NAMESPACE
+QT_END_NAMESPACE
+
+/*!
+ \qmltype TiltSensor
+ \instantiates QmlTiltSensor
+ \ingroup qml-sensors_type
+ \inqmlmodule QtMobility.sensors 1.3
+ \since QtMobility.sensors 1.1
+ \inherits QtMobility.sensors1::Sensor
+ \brief The TiltSensor element reports tilt events
+ along the X and Y axes.
+
+ The TiltSensor element reports tilt events along the X and Y axes.
+
+ This element wraps the QTiltSensor class. Please see the documentation for
+ QTiltSensor for details.
+
+ \sa TiltReading
+*/
+
+QmlTiltSensor::QmlTiltSensor(QObject *parent)
+ : QmlSensor(parent)
+ , m_sensor(new QTiltSensor(this))
+{
+}
+
+QmlTiltSensor::~QmlTiltSensor()
+{
+}
+
+QmlSensorReading *QmlTiltSensor::createReading() const
+{
+ return new QmlTiltSensorReading(m_sensor);
+}
+
+QSensor *QmlTiltSensor::sensor() const
+{
+ return m_sensor;
+}
+
+/*!
+ \qmlmethod QtMobility.sensors1::TiltSensor::calibrate()
+ Calibrate the tilt sensor.
+
+ Please see QTiltSensor::calibrate() for information about this property.
+*/
+void QmlTiltSensor::calibrate()
+{
+ m_sensor->calibrate();
+}
+
+/*!
+ \qmltype TiltReading
+ \instantiates QmlTiltSensorReading
+ \ingroup qml-sensors_reading
+ \inqmlmodule QtMobility.sensors 1.3
+ \since QtMobility.sensors 1.1
+ \inherits QtMobility.sensors1::SensorReading
+ \brief The TiltReading element holds the most recent TiltSensor reading.
+
+ The TiltReading element holds the most recent TiltSensor reading.
+
+ This element wraps the QTiltReading class. Please see the documentation for
+ QTiltReading for details.
+
+ This element cannot be directly created.
+*/
+
+QmlTiltSensorReading::QmlTiltSensorReading(QTiltSensor *sensor)
+ : QmlSensorReading(sensor)
+ , m_sensor(sensor)
+{
+ update();
+}
+
+QmlTiltSensorReading::~QmlTiltSensorReading()
+{
+}
+
+/*!
+ \qmlproperty qreal QtMobility.sensors1::TiltReading::yRotation
+ This property holds the amount of tilt on the Y axis.
+
+ Please see QTiltReading::yRotation for information about this property.
+*/
+
+qreal QmlTiltSensorReading::yRotation() const
+{
+ return m_yRotation;
+}
+
+/*!
+ \qmlproperty qreal QtMobility.sensors1::TiltReading::xRotation
+ This property holds the amount of tilt on the X axis.
+
+ Please see QTiltReading::xRotation for information about this property.
+*/
+
+qreal QmlTiltSensorReading::xRotation() const
+{
+ return m_xRotation;
+}
+
+QSensorReading *QmlTiltSensorReading::reading() const
+{
+ return m_sensor->reading();
+}
+
+void QmlTiltSensorReading::readingUpdate()
+{
+ qreal tiltY = m_sensor->reading()->yRotation();
+ if (m_yRotation != tiltY) {
+ m_yRotation = tiltY;
+ Q_EMIT yRotationChanged();
+ }
+ qreal tiltX = m_sensor->reading()->xRotation();
+ if (m_xRotation != tiltX) {
+ m_xRotation = tiltX;
+ Q_EMIT xRotationChanged();
+ }
+}
diff --git a/src/imports/sensors/qmltiltsensor.h b/src/imports/sensors/qmltiltsensor.h
new file mode 100644
index 00000000..9afed564
--- /dev/null
+++ b/src/imports/sensors/qmltiltsensor.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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, Digia gives you certain additional
+** rights. These rights are described in the Digia 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.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QMLTILTSENSOR_H
+#define QMLTILTSENSOR_H
+
+#include "qmlsensor.h"
+#include <QtSensors/QTiltSensor>
+
+QT_BEGIN_HEADER
+QT_BEGIN_NAMESPACE
+
+class QTiltSensor;
+
+class QmlTiltSensor : public QmlSensor
+{
+ Q_OBJECT
+public:
+
+ explicit QmlTiltSensor(QObject *parent = 0);
+ ~QmlTiltSensor();
+ Q_INVOKABLE void calibrate();
+
+private:
+ QSensor *sensor() const Q_DECL_OVERRIDE;
+ QTiltSensor *m_sensor;
+ QmlSensorReading *createReading() const Q_DECL_OVERRIDE;
+};
+
+class QmlTiltSensorReading : public QmlSensorReading
+{
+ Q_OBJECT
+ Q_PROPERTY(qreal yRotation READ yRotation NOTIFY yRotationChanged)
+ Q_PROPERTY(qreal xRotation READ xRotation NOTIFY xRotationChanged)
+public:
+ explicit QmlTiltSensorReading(QTiltSensor *sensor);
+ ~QmlTiltSensorReading();
+
+ qreal yRotation() const;
+ qreal xRotation() const;
+
+Q_SIGNALS:
+ void yRotationChanged();
+ void xRotationChanged();
+
+private:
+ QSensorReading *reading() const Q_DECL_OVERRIDE;
+ void readingUpdate() Q_DECL_OVERRIDE;
+ QTiltSensor *m_sensor;
+ qreal m_yRotation;
+ qreal m_xRotation;
+};
+
+QT_END_NAMESPACE
+QT_END_HEADER
+#endif
diff --git a/src/imports/sensors/sensors.cpp b/src/imports/sensors/sensors.cpp
index e5f43835..9e425297 100644
--- a/src/imports/sensors/sensors.cpp
+++ b/src/imports/sensors/sensors.cpp
@@ -41,18 +41,20 @@
#include <QtQml/qqmlextensionplugin.h>
#include <QtQml/qqml.h>
+#include <QtSensors/QSensorManager>
-#include <qaccelerometer.h>
-#include <qambientlightsensor.h>
-#include <qcompass.h>
-#include <qmagnetometer.h>
-#include <qorientationsensor.h>
-#include <qproximitysensor.h>
-#include <qrotationsensor.h>
-#include <qtapsensor.h>
-#include <qlightsensor.h>
-#include <qgyroscope.h>
-#include <qirproximitysensor.h>
+#include <QtSensors/qaccelerometer.h>
+#include <QtSensors/qambientlightsensor.h>
+#include <QtSensors/qcompass.h>
+#include <QtSensors/qmagnetometer.h>
+#include <QtSensors/qorientationsensor.h>
+#include <QtSensors/qproximitysensor.h>
+#include <QtSensors/qrotationsensor.h>
+#include <QtSensors/qtapsensor.h>
+#include <QtSensors/qlightsensor.h>
+#include <QtSensors/qgyroscope.h>
+#include <QtSensors/qirproximitysensor.h>
+#include <QtSensors/qtiltsensor.h>
#include "qmlsensorglobal.h"
#include "qmlsensor.h"
@@ -67,6 +69,7 @@
#include "qmlproximitysensor.h"
#include "qmlrotationsensor.h"
#include "qmltapsensor.h"
+#include "qmltiltsensor.h"
QT_BEGIN_NAMESPACE
@@ -75,7 +78,7 @@ static QObject *global_object_13(QQmlEngine *, QJSEngine *)
return new QmlSensorGlobal;
}
-class QSensorsDeclarativeModule : public QQmlExtensionPlugin
+class QtSensorsDeclarativeModule : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface" FILE "plugin.json")
@@ -164,6 +167,8 @@ public:
qmlRegisterUncreatableType<QmlRotationSensorReading >(package, major, minor, "RotationReading", QLatin1String("Cannot create RotationReading"));
qmlRegisterType <QmlTapSensor >(package, major, minor, "TapSensor");
qmlRegisterUncreatableType<QmlTapSensorReading >(package, major, minor, "TapReading", QLatin1String("Cannot create TapReading"));
+ qmlRegisterType <QmlTiltSensor >(package, major, minor, "TiltSensor");
+ qmlRegisterUncreatableType<QmlTiltSensorReading >(package, major, minor, "TiltReading", QLatin1String("Cannot create TiltReading"));
}
};
diff --git a/src/imports/sensors/sensors.pro b/src/imports/sensors/sensors.pro
index ac59fcde..89af5ead 100644
--- a/src/imports/sensors/sensors.pro
+++ b/src/imports/sensors/sensors.pro
@@ -3,7 +3,9 @@ TARGET = declarative_sensors
TARGETPATH = QtMobility/sensors
IMPORT_VERSION = 1.3 # Doesn't matter, as long as it's a valid version?!
-QT += qml sensors
+include(qsensorsimport.pri)
+
+QT += qml sensors sensors-private
HEADERS += \
qmlsensor.h \
@@ -19,7 +21,9 @@ HEADERS += \
qmlproximitysensor.h \
qmltapsensor.h \
qmlrotationsensor.h \
- qmlsensorglobal.h
+ qmlsensorglobal.h \
+ qmltiltsensor.h
+
SOURCES += sensors.cpp \
qmlsensor.cpp \
qmlsensorrange.cpp \
@@ -34,7 +38,17 @@ SOURCES += sensors.cpp \
qmlproximitysensor.cpp \
qmltapsensor.cpp \
qmlrotationsensor.cpp \
- qmlsensorglobal.cpp
+ qmlsensorglobal.cpp \
+ qmltiltsensor.cpp
+
+
+DESTDIR = $$QT.sensors.imports/$$TARGETPATH
+target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
+
+qmldir.files += $$PWD/qmldir $$PWD/plugin.qmltypes
+qmldir.path += $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
+
+INSTALLS += target qmldir
load(qml_plugin)