summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/declarative/sensors/qmlsensorgesture.cpp266
-rw-r--r--plugins/declarative/sensors/qmlsensorgesture.h106
-rw-r--r--plugins/declarative/sensors/sensors.cpp30
-rw-r--r--plugins/declarative/sensors/sensors.pro8
-rw-r--r--plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.cpp2
-rw-r--r--plugins/sensorgestures/qtsensors/qshake2recognizer.cpp1
-rw-r--r--plugins/sensorgestures/qtsensors/qshake2recognizer.h1
-rw-r--r--plugins/sensorgestures/qtsensors/qtsensorgesturesensorhandler.cpp24
8 files changed, 428 insertions, 10 deletions
diff --git a/plugins/declarative/sensors/qmlsensorgesture.cpp b/plugins/declarative/sensors/qmlsensorgesture.cpp
new file mode 100644
index 0000000000..2225dcf55f
--- /dev/null
+++ b/plugins/declarative/sensors/qmlsensorgesture.cpp
@@ -0,0 +1,266 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Mobility Components.
+**
+** $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 "qmlsensorgesture.h"
+#include "qsensorgesture.h"
+#include "qsensorgesturemanager.h"
+#include "qsensor.h"
+
+QTM_BEGIN_NAMESPACE
+//#define LOGGESTURQMLAPI
+
+/*!
+ \qmltype SensorGesture
+ \instantiates QmlSensorGesture
+ \inqmlmodule QtSensors 5.0
+ \since QtSensors 5.0
+ \brief Provides notifications when sensor-based gestures are detected.
+
+ This type provides notification when sensor gestures are triggered.
+
+ The following QML code creates a "shake" and "template" SensorGesture QML type, and
+ displays the detected gesture in a text type.
+
+ QtSensors.shake gesture is available with the Qt Sensors API, but the QtSensors.SecondCounter
+ sensor gesture is provided as example code for the \l {Qt Sensors - SensorGesture QML Type example}
+
+ \qml
+ Item {
+ SensorGesture {
+ id: sensorGesture
+ enabled: false
+ gestures : ["QtSensors.shake", "QtSensors.SecondCounter"]
+ onDetected:{
+ detectedText.text = gesture
+ }
+ }
+ Text {
+ id: detectedText
+ x:5
+ y:160
+ text: ""
+ }
+ }
+ \endqml
+
+ \l {Qt Sensor Gestures} contains a list of currently supported sensor gestures and their
+ descriptions.
+
+
+*/
+QmlSensorGesture::QmlSensorGesture(QObject* parent)
+ : QObject(parent)
+ , isEnabled(false)
+ , oldGestureEnabled(false)
+ , initDone(false)
+ , sensorGesture(0)
+ , sensorGestureManager(new QSensorGestureManager(this))
+{
+ connect(sensorGestureManager, SIGNAL(newSensorGestureAvailable()), this, SIGNAL(availableGesturesChanged()));
+}
+
+QmlSensorGesture::~QmlSensorGesture()
+{
+}
+
+/*
+ QQmlParserStatus interface implementation
+*/
+void QmlSensorGesture::classBegin()
+{
+}
+
+void QmlSensorGesture::componentComplete()
+{
+ /*
+ this is needed in the case the customer defines the type(s) and set it enabled = true
+ */
+ initDone = true;
+ setEnabled(isEnabled);
+
+}
+/*
+ End of QQmlParserStatus interface implementation
+*/
+
+/*!
+ \qmlproperty stringlist QtSensors::SensorGesture::availableGestures
+ This property can be used to determine all available gestures on the system.
+*/
+QStringList QmlSensorGesture::availableGestures()
+{
+ return sensorGestureManager->gestureIds();
+}
+
+/*!
+ \qmlproperty stringlist QtSensors::SensorGesture::gestures
+ Set this property to a list of the gestures that the application is interested in detecting.
+ This property cannot be changed while the type is enabled.
+
+ The properties validGestures and invalidGestures will be set as appropriate immediately.
+ To determine all available getures on the system please use the
+ \l {QtSensors::SensorGesture::availableGestures} {availableGestures} property.
+
+ \sa {QtSensorGestures Plugins}
+*/
+QStringList QmlSensorGesture::gestures() const
+{
+ return gestureList;
+}
+
+void QmlSensorGesture::setGestures(const QStringList& value)
+{
+ if (gestureList == value)
+ return;
+
+ if (initDone && enabled()) {
+ qWarning() << "Cannot change gestures while running.";
+ return;
+ }
+ gestureList = value;
+ createGesture();
+ Q_EMIT gesturesChanged();
+}
+
+
+/*!
+ \qmlproperty stringlist QtSensors::SensorGesture::validGestures
+ This property holds the requested gestures that were found on the system.
+*/
+QStringList QmlSensorGesture::validGestures() const
+{
+ if (sensorGesture)
+ return sensorGesture->validIds();
+ return QStringList();
+}
+
+/*!
+ \qmlproperty stringlist QtSensors::SensorGesture::invalidGestures
+ This property holds the requested gestures that were not found on the system.
+*/
+QStringList QmlSensorGesture::invalidGestures() const
+{
+ if (sensorGesture)
+ return sensorGesture->invalidIds();
+ return QStringList();
+}
+
+/*!
+ \qmlproperty bool QtSensors::SensorGesture::enabled
+ This property can be used to activate or deactivate the sensor gesture.
+ Default value is false;
+ \sa {QtSensors::SensorGesture::detected}, {detected}
+*/
+bool QmlSensorGesture::enabled() const
+{
+ return isEnabled;
+}
+
+void QmlSensorGesture::setEnabled(bool value)
+{
+ bool hasChanged = false;
+ if (isEnabled != value) {
+ isEnabled = value;
+ hasChanged = true;
+ }
+ if (!initDone)
+ return;
+
+ if (sensorGesture) {
+ if (value) {
+ sensorGesture->startDetection();
+ } else {
+ sensorGesture->stopDetection();
+ }
+ }
+ if (hasChanged)
+ Q_EMIT enabledChanged();
+
+}
+
+/*!
+ \qmlsignal QtSensors::SensorGesture::detected(string gesture)
+ This signal is emitted whenever a gesture is detected.
+ The gesture parameter contains the gesture that was detected.
+*/
+
+/*
+ private funtion implementation
+*/
+void QmlSensorGesture::deleteGesture()
+{
+ if (sensorGesture) {
+ bool emitInvalidChange = !invalidGestures().isEmpty();
+ bool emitValidChange = !validGestures().isEmpty();
+
+ if (sensorGesture->isActive()) {
+ sensorGesture->stopDetection();
+ }
+ delete sensorGesture;
+ sensorGesture = 0;
+
+ if (emitInvalidChange) {
+ Q_EMIT invalidGesturesChanged();
+ }
+ if (emitValidChange) {
+ Q_EMIT validGesturesChanged();
+ }
+ }
+}
+
+void QmlSensorGesture::createGesture()
+{
+ deleteGesture();
+ if (!validGestures().isEmpty()) {
+ QObject::connect(sensorGesture, SIGNAL(detected(QString)),
+ this , SIGNAL(detected(QString)));
+ Q_EMIT validGesturesChanged();
+ }
+ if (!invalidGestures().isEmpty())
+ Q_EMIT invalidGesturesChanged();
+}
+
+/*
+ End of private funtion implementation
+*/
+
+#include "moc_qmlsensorgesture.cpp"
+
+QTM_END_NAMESPACE
diff --git a/plugins/declarative/sensors/qmlsensorgesture.h b/plugins/declarative/sensors/qmlsensorgesture.h
new file mode 100644
index 0000000000..2a652306ed
--- /dev/null
+++ b/plugins/declarative/sensors/qmlsensorgesture.h
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Mobility Components.
+**
+** $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 QMLSENSORGESTURE_H
+#define QMLSENSORGESTURE_H
+
+#include <QStringList>
+#include <QObject>
+#include <QMap>
+#include <QDeclarativeParserStatus>
+
+#include <qmobilityglobal.h>
+#include "qsensor.h"
+
+QTM_BEGIN_NAMESPACE
+
+class QSensorGesture;
+class QSensorGestureManager;
+
+class QmlSensorGesture : public QObject, public QDeclarativeParserStatus
+{
+ Q_OBJECT
+ Q_PROPERTY(QStringList availableGestures READ availableGestures NOTIFY availableGesturesChanged)
+ Q_PROPERTY(QStringList gestures READ gestures WRITE setGestures NOTIFY gesturesChanged)
+ Q_PROPERTY(QStringList validGestures READ validGestures NOTIFY validGesturesChanged)
+ Q_PROPERTY(QStringList invalidGestures READ invalidGestures NOTIFY invalidGesturesChanged)
+ Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
+
+public:
+ QmlSensorGesture(QObject* parent = 0);
+ virtual ~QmlSensorGesture();
+ void classBegin();
+ void componentComplete();
+
+Q_SIGNALS:
+ void detected(const QString &gesture);
+ void availableGesturesChanged();
+ void gesturesChanged();
+ void validGesturesChanged();
+ void invalidGesturesChanged();
+ void enabledChanged();
+
+public:
+ QStringList availableGestures();
+ QStringList gestures() const;
+ void setGestures(const QStringList& value);
+ bool enabled() const;
+ void setEnabled(bool value);
+ QStringList validGestures() const;
+ QStringList invalidGestures() const;
+
+private:
+ void deleteGesture();
+ void createGesture();
+
+private:
+ QStringList gestureIds;
+ bool isEnabled;
+ bool oldGestureEnabled;
+ bool initDone;
+ QStringList gestureList;
+
+ QSensorGesture* sensorGesture;
+ QSensorGestureManager* sensorGestureManager;
+};
+QTM_END_NAMESPACE
+
+#endif
diff --git a/plugins/declarative/sensors/sensors.cpp b/plugins/declarative/sensors/sensors.cpp
index aaf5bdcd3e..d4ee8751b0 100644
--- a/plugins/declarative/sensors/sensors.cpp
+++ b/plugins/declarative/sensors/sensors.cpp
@@ -41,6 +41,7 @@
#include <QtDeclarative/qdeclarativeextensionplugin.h>
#include <QtDeclarative/qdeclarative.h>
+#include <QDebug>
#include <qaccelerometer.h>
#include <qambientlightsensor.h>
@@ -52,6 +53,7 @@
#include <qtapsensor.h>
#include <qlightsensor.h>
#include <qgyroscope.h>
+#include "qmlsensorgesture.h"
QT_BEGIN_NAMESPACE
@@ -112,6 +114,34 @@ public:
qmlRegisterUncreatableType<QLightReading >(package, major, minor, "LightReading", QLatin1String("Cannot create LightReading"));
qmlRegisterType <QGyroscope >(package, major, minor, "Gyroscope");
qmlRegisterUncreatableType<QGyroscopeReading >(package, major, minor, "GyroscopeReading", QLatin1String("Cannot create GyroscopeReading"));
+
+ major = 1;
+ minor = 3;
+ qmlRegisterUncreatableType<QSensor >(package, major, minor, "Sensor", QLatin1String("Cannot create Sensor "));
+ qmlRegisterUncreatableType<QSensorReading >(package, major, minor, "SensorReading", QLatin1String("Cannot create Sensor Reading"));
+ qmlRegisterType <QAccelerometer >(package, major, minor, "Accelerometer");
+ qmlRegisterUncreatableType<QAccelerometerReading>(package, major, minor, "AccelerometerReading", QLatin1String("Cannot create Accele rometerReading"));
+ qmlRegisterType <QAmbientLightSensor >(package, major, minor, "AmbientLightSensor");
+ qmlRegisterUncreatableType<QAmbientLightReading >(package, major, minor, "AmbientLightReading", QLatin1String("Cannot create Ambien tLightReading"));
+ qmlRegisterType <QCompass >(package, major, minor, "Compass");
+ qmlRegisterUncreatableType<QCompassReading >(package, major, minor, "CompassReading", QLatin1String("Cannot create Compas sReading"));
+ qmlRegisterType <QMagnetometer >(package, major, minor, "Magnetometer");
+ qmlRegisterUncreatableType<QMagnetometerReading >(package, major, minor, "MagnetometerReading", QLatin1String("Cannot create Magnet ometerReading"));
+ qmlRegisterType <QOrientationSensor >(package, major, minor, "OrientationSensor");
+ qmlRegisterUncreatableType<QOrientationReading >(package, major, minor, "OrientationReading", QLatin1String("Cannot create Orient ationReading"));
+ qmlRegisterType <QProximitySensor >(package, major, minor, "ProximitySensor");
+ qmlRegisterUncreatableType<QProximityReading >(package, major, minor, "ProximityReading", QLatin1String("Cannot create Proxim ityReading"));
+ qmlRegisterType <QRotationSensor >(package, major, minor, "RotationSensor");
+ qmlRegisterUncreatableType<QRotationReading >(package, major, minor, "RotationReading", QLatin1String("Cannot create Rotati onReading"));
+ qmlRegisterType <QTapSensor >(package, major, minor, "TapSensor");
+ qmlRegisterUncreatableType<QTapReading >(package, major, minor, "TapReading", QLatin1String("Cannot create TapRea ding"));
+ qmlRegisterType <QLightSensor >(package, major, minor, "LightSensor");
+ qmlRegisterUncreatableType<QLightReading >(package, major, minor, "LightReading", QLatin1String("Cannot create LightR eading"));
+ qmlRegisterType <QGyroscope >(package, major, minor, "Gyroscope");
+ qmlRegisterUncreatableType<QGyroscopeReading >(package, major, minor, "GyroscopeReading", QLatin1String("Cannot create Gyrosc opeReading"));
+
+ qmlRegisterType <QmlSensorGesture >(package, major, minor, "SensorGesture");
+
}
};
diff --git a/plugins/declarative/sensors/sensors.pro b/plugins/declarative/sensors/sensors.pro
index 6503b53619..5470d405dd 100644
--- a/plugins/declarative/sensors/sensors.pro
+++ b/plugins/declarative/sensors/sensors.pro
@@ -1,6 +1,8 @@
include(../../../features/utils.pri)
-INCLUDEPATH += ../../../src/sensors
+INCLUDEPATH += $${QT_MOBILITY_SOURCE_TREE}/src/sensors
+INCLUDEPATH += $${QT_MOBILITY_SOURCE_TREE}/src/sensors/gestures
+
INCLUDEPATH += ../../../src/global
TEMPLATE = lib
@@ -12,7 +14,9 @@ include(../../../common.pri)
QT += declarative
-SOURCES += sensors.cpp
+SOURCES += sensors.cpp \
+qmlsensorgesture.cpp
+HEADERS += qmlsensorgesture.h
CONFIG += mobility
MOBILITY += sensors
diff --git a/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.cpp b/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.cpp
index a092f35979..21927cb3ce 100644
--- a/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.cpp
+++ b/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.cpp
@@ -81,6 +81,7 @@ bool QCoverSensorGestureRecognizer::start()
QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Proximity);
active = false;
}
+
} else {
active = false;
}
@@ -114,6 +115,7 @@ void QCoverSensorGestureRecognizer::proximityChanged(QProximityReading *reading)
proximityReading = reading->close();
+
// look at case of face up->face down->face up.
if (orientationReading->orientation() == QOrientationReading::FaceUp
&& proximityReading) {
diff --git a/plugins/sensorgestures/qtsensors/qshake2recognizer.cpp b/plugins/sensorgestures/qtsensors/qshake2recognizer.cpp
index 6eb5e14230..3b17c6c53f 100644
--- a/plugins/sensorgestures/qtsensors/qshake2recognizer.cpp
+++ b/plugins/sensorgestures/qtsensors/qshake2recognizer.cpp
@@ -39,7 +39,6 @@
**
****************************************************************************/
-#include <QDebug>
#include <QTimer>
#include "qshake2recognizer.h"
diff --git a/plugins/sensorgestures/qtsensors/qshake2recognizer.h b/plugins/sensorgestures/qtsensors/qshake2recognizer.h
index 121e5861a5..47932a80cb 100644
--- a/plugins/sensorgestures/qtsensors/qshake2recognizer.h
+++ b/plugins/sensorgestures/qtsensors/qshake2recognizer.h
@@ -42,7 +42,6 @@
#ifndef QSHAKERECOGNIZER_H
#define QSHAKERECOGNIZER_H
-#include <QDebug>
#include <QTimer>
#include <qsensorgesturerecognizer.h>
diff --git a/plugins/sensorgestures/qtsensors/qtsensorgesturesensorhandler.cpp b/plugins/sensorgestures/qtsensors/qtsensorgesturesensorhandler.cpp
index e12636da50..a2f8b151a2 100644
--- a/plugins/sensorgestures/qtsensors/qtsensorgesturesensorhandler.cpp
+++ b/plugins/sensorgestures/qtsensors/qtsensorgesturesensorhandler.cpp
@@ -39,7 +39,8 @@
**
****************************************************************************/
-#include <QDebug>
+#include <QStringList>
+#include <QTimer>
#include "qtsensorgesturesensorhandler.h"
@@ -94,7 +95,16 @@ bool QtSensorGestureSensorHandler::startSensor(SensorGestureSensors sensor)
if (accel == 0x0) {
accel = new QAccelerometer(this);
ok = accel->connectToBackend();
- accel->setDataRate(50);
+// qrangelist rangeList = accel->availableDataRates();
+
+// QStringList ranges;
+// foreach (const qrange &range, rangeList) {
+// if (range.first == range.second)
+// ranges << QString("%1 Hz").arg(range.first);
+// else
+// ranges << QString("%1-%2 Hz").arg(range.first).arg(range.second);
+// }
+ accel->setDataRate(100);
qoutputrangelist outputranges = accel->outputRanges();
if (outputranges.count() > 0)
@@ -111,11 +121,13 @@ bool QtSensorGestureSensorHandler::startSensor(SensorGestureSensors sensor)
if (orientation == 0x0) {
orientation = new QOrientationSensor(this);
ok = orientation->connectToBackend();
- orientation->setDataRate(50);
+ orientation->setDataRate(100);
connect(orientation,SIGNAL(readingChanged()),this,SLOT(orientationChanged()));
}
- if (ok && !orientation->isActive())
+ if (ok && !orientation->isActive()) {
orientation->start();
+ QTimer::singleShot(100,this,SLOT(orientationChanged()));
+ }
break;
case Proximity:
//proximity
@@ -124,8 +136,9 @@ bool QtSensorGestureSensorHandler::startSensor(SensorGestureSensors sensor)
ok = proximity->connectToBackend();
connect(proximity,SIGNAL(readingChanged()),this,SLOT(proximityChanged()));
}
- if (ok && !proximity->isActive())
+ if (ok && !proximity->isActive()) {
proximity->start();
+ }
break;
case IrProximity:
// //irproximity
@@ -156,7 +169,6 @@ bool QtSensorGestureSensorHandler::startSensor(SensorGestureSensors sensor)
void QtSensorGestureSensorHandler::stopSensor(SensorGestureSensors sensor)
{
- // qDebug() << __FUNCTION__ << sensor;
if (usedSensorsMap.value(sensor) == 0)
return;
int val = usedSensorsMap.value(sensor);