diff options
Diffstat (limited to 'src')
20 files changed, 1766 insertions, 2 deletions
diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro index 234bd79..c8b9e6a 100644 --- a/src/plugins/plugins.pro +++ b/src/plugins/plugins.pro @@ -1,2 +1,3 @@ TEMPLATE = subdirs SUBDIRS += sensors +SUBDIRS += sensorgestures diff --git a/src/plugins/sensorgestures/sensorgestures.pro b/src/plugins/sensorgestures/sensorgestures.pro new file mode 100644 index 0000000..e300fa7 --- /dev/null +++ b/src/plugins/sensorgestures/sensorgestures.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS += shake diff --git a/src/plugins/sensorgestures/shake/qshakerecognizer.cpp b/src/plugins/sensorgestures/shake/qshakerecognizer.cpp new file mode 100644 index 0000000..e544b5a --- /dev/null +++ b/src/plugins/sensorgestures/shake/qshakerecognizer.cpp @@ -0,0 +1,161 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 <QDebug> +#include <QTimer> + +#include "qshakerecognizer.h" + +QShakeSensorGestureRecognizer::QShakeSensorGestureRecognizer(QObject *parent) + : QSensorGestureRecognizer(parent) + , active(0) +{ + pXaxis = 0;nXaxis = 0; + pYaxis = 0;nYaxis = 0; + pZaxis = 0;nZaxis = 0; + timerTimeout = 1500; +} + +QShakeSensorGestureRecognizer::~QShakeSensorGestureRecognizer() +{ +} + +void QShakeSensorGestureRecognizer::create() +{ + accel = new QAccelerometer(this); + accel->connectToBackend(); + timer = new QTimer(this); + + connect(timer,SIGNAL(timeout()),this,SLOT(timeout())); + timer->setSingleShot(true); + timer->setInterval(timerTimeout); + + connect(accel,SIGNAL(readingChanged()),this,SLOT(accelChanged())); + +} + +bool QShakeSensorGestureRecognizer::start() +{ + active = accel->start(); + + return active; +} + +bool QShakeSensorGestureRecognizer::stop() +{ + accel->stop(); + active = accel->isActive(); + return !active; +} + + +bool QShakeSensorGestureRecognizer::isActive() +{ + return active; +} + +QString QShakeSensorGestureRecognizer::id() const +{ + return QString("QtSensors.shake"); +} + + +#define NUMBER_SHAKES 3 +void QShakeSensorGestureRecognizer::accelChanged() +{ + qreal x = accel->reading()->x(); + qreal z = accel->reading()->z(); + qreal xdiff = pXaxis - x; + + if (abs(xdiff) > 10) { + nXaxis++; + if (timer->isActive()) { + timer->stop(); + } + timer->start(); + } + if (nXaxis >= NUMBER_SHAKES) { + + Q_EMIT shake(); + Q_EMIT detected("shake"); + + if (timer->isActive()) { + timer->stop(); + } + timeout(); + } + + // if (abs(zdiff) > 10) { + // nZaxis++; + // if (timer->isActive()) { + // timer->stop(); + // } + // timer->start(); + // } + + // if (nZaxis >= NUMBER_SHAKES) { + // Q_EMIT detected("ShakeZ"); + // Q_EMITshake(); + // if (timer->isActive()) { + // timer->stop(); + // } + // timeout(); + // } + pXaxis = x; + pZaxis = z; +} + +void QShakeSensorGestureRecognizer::timeout() +{ + nXaxis = 0; + nYaxis = 0; + nZaxis = 0; +} + +int QShakeSensorGestureRecognizer::thresholdTime() const +{ + return timerTimeout; +} + +void QShakeSensorGestureRecognizer::setThresholdTime(int msec) +{ + timer->setInterval(msec); +} diff --git a/src/plugins/sensorgestures/shake/qshakerecognizer.h b/src/plugins/sensorgestures/shake/qshakerecognizer.h new file mode 100644 index 0000000..07c12c1 --- /dev/null +++ b/src/plugins/sensorgestures/shake/qshakerecognizer.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 QSHAKERECOGNIZER_H +#define QSHAKERECOGNIZER_H + + +#include <QtSensors/QSensor> +#include <QtSensors/QAccelerometer> +#include <QtSensors/QAccelerometerFilter> +#include <QDebug> +#include <QTimer> + +#include <qsensorgesturerecognizer.h> + +class QShakeSensorGestureRecognizer : public QSensorGestureRecognizer +{ + Q_OBJECT + +public: + + QShakeSensorGestureRecognizer(QObject *parent = 0); + ~QShakeSensorGestureRecognizer(); + + void create(); + + QString id() const; + bool start(); + bool stop(); + bool isActive(); + + int thresholdTime() const; + void setThresholdTime(int msec); + +Q_SIGNALS: + void shake(); + +private slots: + void accelChanged(); + void timeout(); +private: + QAccelerometer *accel; + + qreal pXaxis; + qreal nXaxis; + + qreal pYaxis; + qreal nYaxis; + + qreal pZaxis; + qreal nZaxis; + + bool detectingState; + QTimer *timer; + int timerTimeout; + bool active; +}; + +#endif // QSHAKERECOGNIZER_H diff --git a/src/plugins/sensorgestures/shake/qshakesensorgestureplugin.cpp b/src/plugins/sensorgestures/shake/qshakesensorgestureplugin.cpp new file mode 100644 index 0000000..6e0f270 --- /dev/null +++ b/src/plugins/sensorgestures/shake/qshakesensorgestureplugin.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 <QtPlugin> +#include <QStringList> +#include <QObject> + +#include "qshakesensorgestureplugin.h" + +#include <qsensorgestureplugininterface.h> +#include <qsensorgesturemanager.h> + +#include "qshakerecognizer.h" + + +QShakeSensorGesturePlugin::QShakeSensorGesturePlugin() +{ +} + +QShakeSensorGesturePlugin::~QShakeSensorGesturePlugin() +{ +} + +QStringList QShakeSensorGesturePlugin::supportedIds() const +{ + QStringList list; + list << "QtSensors.shake"; + return list; +} + +QList <QSensorGestureRecognizer *> QShakeSensorGesturePlugin::createRecognizers() +{ + QList <QSensorGestureRecognizer *> recognizers; + + QSensorGestureRecognizer *sRec = new QShakeSensorGestureRecognizer(this); + recognizers.append(sRec); + + return recognizers; +} + +Q_EXPORT_PLUGIN2(QShakeSensorGestureRecognizer, QShakeSensorGesturePlugin) + diff --git a/src/plugins/sensorgestures/shake/qshakesensorgestureplugin.h b/src/plugins/sensorgestures/shake/qshakesensorgestureplugin.h new file mode 100644 index 0000000..d11b9ee --- /dev/null +++ b/src/plugins/sensorgestures/shake/qshakesensorgestureplugin.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 QSHAKESENSORGESTUREPLUGIN_H +#define QSHAKESENSORGESTUREPLUGIN_H + +#include <QObject> +#include <QStringList> + +#include <qsensorgestureplugininterface.h> + +class QShakeSensorGesturePlugin : public QObject, QSensorGesturePluginInterface +{ + Q_OBJECT + Q_INTERFACES(QSensorGesturePluginInterface) +public: + explicit QShakeSensorGesturePlugin(); + ~QShakeSensorGesturePlugin(); + + QList <QSensorGestureRecognizer *> createRecognizers(); + + QStringList gestureSignals() const; + QStringList supportedIds() const; + QString name() const { return "ShakeGestures"; } +}; + +#endif // QSHAKESENSORGESTUREPLUGIN_H diff --git a/src/plugins/sensorgestures/shake/shake.pro b/src/plugins/sensorgestures/shake/shake.pro new file mode 100644 index 0000000..80197c7 --- /dev/null +++ b/src/plugins/sensorgestures/shake/shake.pro @@ -0,0 +1,17 @@ +TEMPLATE = lib +CONFIG += plugin + +TARGET = qtsensorgestures_shakeplugin + +QT += sensors +DESTDIR = $$QT.sensors.plugins/sensorgestures + +# Input +HEADERS += qshakesensorgestureplugin.h \ + qshakerecognizer.h +SOURCES += qshakesensorgestureplugin.cpp \ + qshakerecognizer.cpp + +target.path += $$[QT_INSTALL_PLUGINS]/sensorgestures +INSTALLS += target + diff --git a/src/sensors/gestures/qsensorgesture.cpp b/src/sensors/gestures/qsensorgesture.cpp new file mode 100644 index 0000000..f84ce18 --- /dev/null +++ b/src/sensors/gestures/qsensorgesture.cpp @@ -0,0 +1,258 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 <QDir> +#include <QPluginLoader> +#include <QDebug> + +#include "qsensorgesture.h" +#include "qsensorgesture_p.h" +#include "qsensorgesturemanager.h" + +#include <private/qmetaobjectbuilder_p.h> + +/*! + \class QSensorGesture + \ingroup sensorgestures_main + \inmodule QtSensors + + \brief The QSensorGesture class represents one or more sensor gesture recognizers. + + In addition to the QSensorGesture::detected() signal, Sensor Gesture Recognizers can + have their own specific signals, and may be discovered through + QSensorGesture::gestureSignals(). + + \sa QSensorGestureRecognizer + + You may use QSensorGestureManager to obtain the systems known sensor gesture ids. + + \sa QSensorGestureManager + */ + +#ifdef Q_QDOC +/*! + \fn QSensorGesture::detected(QString gestureId) + Signals when the \a gestureId gesture has been recognized. + */ +#endif + +/*! + Constructs the sensor gesture, and initializes the \a ids list of recognizers, + with parent \a parent + */ +QSensorGesture::QSensorGesture(const QStringList &ids, QObject *parent) : + QObject(parent) +{ + d_ptr = new QSensorGesturePrivate(); + Q_FOREACH (const QString &id, ids) { + QSensorGestureRecognizer * rec = QSensorGestureManager::sensorGestureRecognizer(id); + if (rec != 0) { + d_ptr->m_sensorRecognizers.append(rec); + d_ptr->availableIds.append(id); + } else { + //add to not available things + } + } + + d_ptr->meta = 0; + + QMetaObjectBuilder builder; + builder.setSuperClass(&QSensorGesture::staticMetaObject); + builder.setClassName("QSensorGesture"); + + Q_FOREACH (QSensorGestureRecognizer *recognizer, d_ptr->m_sensorRecognizers) { + Q_FOREACH (const QString &gesture, recognizer->gestureSignals()) { + QMetaMethodBuilder b = builder.addSignal(gesture.toLatin1()); + if (!d_ptr->localGestureSignals.contains(QLatin1String(b.signature()))) + d_ptr->localGestureSignals.append(QLatin1String(b.signature())); + } + recognizer->createBackend(); + } + d_ptr->meta = builder.toMetaObject(); + + if (d_ptr->m_sensorRecognizers.count() > 0) { + d_ptr->valid = true; + } +} + +/*! + Destroy the QSensorGesture + */ +QSensorGesture::~QSensorGesture() +{ + stopDetection(); + if (d_ptr->meta) + qFree(d_ptr->meta); + delete d_ptr; +} + +/*! + Returns whether this QSensorGesture is valid or not. + */ +bool QSensorGesture::isValid() const +{ + return d_ptr->valid; +} + +/*! + Returns the gestures ids. + */ +QStringList QSensorGesture::availableIds() const +{ + return d_ptr->availableIds; +} + +/*! + Starts the gesture detection routines in the recognizer. + */ +void QSensorGesture::startDetection() +{ + if (d_ptr->m_sensorRecognizers.count() < 1) + return; + if (d_ptr->isActive) + return; + + Q_FOREACH (QSensorGestureRecognizer *recognizer, d_ptr->m_sensorRecognizers) { + if (recognizer !=0) { //it shouldn't be, but I am paranoid + connect(recognizer,SIGNAL(detected(QString)), + this,SIGNAL(detected(QString)),Qt::UniqueConnection); + + //connect recognizer signals + Q_FOREACH (QString method, recognizer->gestureSignals()) { + method.prepend(QLatin1String("2")); + connect(recognizer, method.toLatin1(), + this, method.toLatin1(), Qt::UniqueConnection); + } + + recognizer->startBackend(); + } + } + d_ptr->isActive = true; +} + +/*! + Stops the gesture detection routines. + */ +void QSensorGesture::stopDetection() +{ + if (d_ptr->m_sensorRecognizers.count() < 1) + return; + + if (!d_ptr->isActive) + return; + + Q_FOREACH (QSensorGestureRecognizer *recognizer, d_ptr->m_sensorRecognizers) { + disconnect(recognizer,SIGNAL(detected(QString)), + this,SIGNAL(detected(QString))); + //disconnect recognizer signals + Q_FOREACH (QString method,recognizer->gestureSignals()) { + method.prepend(QLatin1String("2")); + disconnect(recognizer, method.toLatin1(), + this, method.toLatin1()); + } + + recognizer->stopBackend(); + } + d_ptr->isActive = false; +} + +/*! + Returns all the possible gestures signals that may be emitted. + */ +QStringList QSensorGesture::gestureSignals() const +{ + if (d_ptr->m_sensorRecognizers.count() > 0) { + return d_ptr->localGestureSignals; + } + return QStringList(); +} + +/*! + Returns whether this gesture is active or not. + */ + +bool QSensorGesture::isActive() +{ + return d_ptr->isActive; +} + +/*! + Internal +*/ +const QMetaObject* QSensorGesture::metaObject() const +{ + return d_ptr->meta; +} +/*! + Internal +*/ +int QSensorGesture::qt_metacall(QMetaObject::Call c, int id, void **a) +{ + id = QObject::qt_metacall(c, id, a); + + if (id < 0 || !d_ptr->meta) + return id; + + QMetaObject::activate(this, d_ptr->meta, id, a); + return id; +} + +/*! + Internal +*/ +void *QSensorGesture::qt_metacast(const char* className) +{ + if (!className) return 0; + return QObject::qt_metacast(className); +} + +/*! + Internal +*/ +QSensorGesturePrivate::QSensorGesturePrivate(QObject *parent) + : QObject(parent),isActive(0), valid(0) +{ +} + +QSensorGesturePrivate::~QSensorGesturePrivate() +{ + +} diff --git a/src/sensors/gestures/qsensorgesture.h b/src/sensors/gestures/qsensorgesture.h new file mode 100644 index 0000000..0abd5a2 --- /dev/null +++ b/src/sensors/gestures/qsensorgesture.h @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 QSENSORGESTURE_H +#define QSENSORGESTURE_H + +#include <QObject> +#include <QStringList> +#include <qsensorsglobal.h> + +#include <QList> +#include <QMap> +#include <QVector> + +#include <QtCore/qmetatype.h> + +QT_BEGIN_NAMESPACE + +class QSensorGesturePrivate; + +class Q_SENSORS_EXPORT QSensorGesture : public QObject +{ + //Do not use Q_OBJECT here +public: + QSensorGesture(const QStringList &ids, QObject *parent = 0); + ~QSensorGesture(); + + bool isActive(); + + QStringList availableIds() const; + QStringList gestureSignals() const; + + void startDetection(); + void stopDetection(); + + bool isValid() const; + +private: + QSensorGesturePrivate * d_ptr; + + // need to inject unknown recognizer signals at runtime. + virtual const QMetaObject* metaObject() const; + int qt_metacall(QMetaObject::Call c, int id, void **a); + void *qt_metacast(const char* className); + +#ifdef Q_QDOC +signals: + // these signals are created at runtime, along with + // gesture recognizer specific signals. + void detected(QString); +#endif +}; + +QT_END_NAMESPACE + + +#endif // QSENSORGESTURE_H diff --git a/src/sensors/gestures/qsensorgesture_p.h b/src/sensors/gestures/qsensorgesture_p.h new file mode 100644 index 0000000..10faa95 --- /dev/null +++ b/src/sensors/gestures/qsensorgesture_p.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 QSENSORGESTURE_P_H +#define QSENSORGESTURE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// +#include <QtSensors/QSensor> +#include <QtSensors/QAccelerometer> +#include <QtSensors/QAccelerometerFilter> +#include <QTimer> + +#include "qsensorgesture.h" +#include "qsensorgesturemanager.h" +#include <QtCore/private/qmetaobjectbuilder_p.h> +QT_BEGIN_NAMESPACE + +class QSensorGesturePrivate : public QObject +{ + +public: + QSensorGesturePrivate(QObject *parent = 0); + ~QSensorGesturePrivate(); + + QList<QSensorGestureRecognizer *> m_sensorRecognizers; + + QByteArray metadata; + QMetaObject* meta; + bool isActive; + QStringList localGestureSignals; + QStringList availableIds; + bool valid; +}; + + +QT_END_NAMESPACE + +#endif // QSENSORGESTURE_P_H diff --git a/src/sensors/gestures/qsensorgesturemanager.cpp b/src/sensors/gestures/qsensorgesturemanager.cpp new file mode 100644 index 0000000..a0430e1 --- /dev/null +++ b/src/sensors/gestures/qsensorgesturemanager.cpp @@ -0,0 +1,127 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 "qsensorgesturemanager.h" +#include "qsensorgesturemanagerprivate_p.h" + +Q_GLOBAL_STATIC(QSensorGestureManagerPrivate, sensorGestureManagerPrivate) + +/*! + \class QSensorGestureManager + \ingroup sensorgestures_main + \inmodule QtSensors + + \brief The QSensorGestureManager class manages sensor gestures, registers and creates sensor gesture plugins. + + Sensor Gesture plugins register their recognizers using the registerSensorGestureRecognizer() function. + + \snippet snippets/sensorgestures/creating.cpp Receiving sensor gesture signals + + */ + +/*! + \fn QSensorGestureManager::newSensorGestureAvailable() + Signals when a new sensor gesture becomes available for use. + */ + +/*! + Constructs the QSensorGestureManager as a child of \a parent + */ +QSensorGestureManager::QSensorGestureManager(QObject *parent) + : QObject(parent) +{ +} + +/*! + Destroy the QSensorGestureManager +*/ +QSensorGestureManager::~QSensorGestureManager() +{ +} + +/*! + Registers the sensor recognizer \a recognizer for use. + QSensorGestureManager retains ownership of the recognizer object. + Returns true unless the gesture has already been registered, in + which case the object is deleted. + + */ + + bool QSensorGestureManager::registerSensorGestureRecognizer(QSensorGestureRecognizer *recognizer) + { + bool ok = sensorGestureManagerPrivate()->registerSensorGestureRecognizer(recognizer); + if (ok) + Q_EMIT newSensorGestureAvailable(); + else + delete recognizer; + + return ok; + } + + + /*! + Returns the list of the currently registered gestures. + Includes all the standard built-ins as well as available plugins. + */ + QStringList QSensorGestureManager::gestureIds() const + { + return sensorGestureManagerPrivate()->gestureIds(); + } + + /*! + Returns the list of all the gesture signals for the registered \a gestureId gesture recognizer id. + */ + QStringList QSensorGestureManager::recognizerSignals(const QString &gestureId) const + { + QSensorGestureRecognizer *recognizer = sensorGestureRecognizer(gestureId); + if (recognizer != 0) + return recognizer->gestureSignals(); + else + return QStringList(); + } + +/*! + Returns the sensor gesture object for the recognizer \a id. + */ +QSensorGestureRecognizer *QSensorGestureManager::sensorGestureRecognizer(const QString &id) +{ + return sensorGestureManagerPrivate()->sensorGestureRecognizer(id); +} diff --git a/src/sensors/gestures/qsensorgesturemanager.h b/src/sensors/gestures/qsensorgesturemanager.h new file mode 100644 index 0000000..d1935d7 --- /dev/null +++ b/src/sensors/gestures/qsensorgesturemanager.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 QSENSORGESTUREMANAGER_P_H +#define QSENSORGESTUREMANAGER_P_H + +#include <QObject> +#include <QStringList> + +#include "qsensorgesture.h" +#include "qsensorgesturerecognizer.h" + +QT_BEGIN_HEADER +QT_BEGIN_NAMESPACE + +class QSensorGestureManagerPrivate; +class Q_SENSORS_EXPORT QSensorGestureManager : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QSensorGestureManager) + +public: + explicit QSensorGestureManager(QObject *parent = 0); + + ~QSensorGestureManager(); + + bool registerSensorGestureRecognizer(QSensorGestureRecognizer *recognizer); + + QStringList gestureIds() const; + QStringList recognizerSignals(const QString &recognizerId) const; + + static QSensorGestureRecognizer *sensorGestureRecognizer(const QString &id); + +signals: + void newSensorGestureAvailable(); + +}; + + +QT_END_NAMESPACE +QT_END_HEADER + +#define REGISTER_STATIC_PLUGIN_V2(pluginname) \ + QT_PREPEND_NAMESPACE(QObject) *qt_plugin_instance_##pluginname() Q_PLUGIN_INSTANCE(pluginname)\ + Q_IMPORT_PLUGIN(pluginname) + +#endif // QSENSORGESTUREMANAGER_P_H diff --git a/src/sensors/gestures/qsensorgesturemanagerprivate.cpp b/src/sensors/gestures/qsensorgesturemanagerprivate.cpp new file mode 100644 index 0000000..1ac21da --- /dev/null +++ b/src/sensors/gestures/qsensorgesturemanagerprivate.cpp @@ -0,0 +1,174 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 <QDir> +#include <QLibraryInfo> + +#include "qsensorgesturerecognizer.h" +#include "qsensorgesturemanagerprivate_p.h" +#include "qsensorgestureplugininterface.h" +#include "qmobilitypluginsearch.h" + +QT_BEGIN_NAMESPACE + +QSensorGestureManagerPrivate::QSensorGestureManagerPrivate(QObject *parent) : + QObject(parent) +{ + loadPlugins(); +} + +QSensorGestureManagerPrivate::~QSensorGestureManagerPrivate() +{ + qDeleteAll(registeredSensorGestures); + qDeleteAll(plugins); +} + + + void QSensorGestureManagerPrivate::initPlugin(QObject *plugin) +{ + if (QSensorGesturePluginInterface *pInterface + = qobject_cast<QSensorGesturePluginInterface *>(plugin)) { + + Q_FOREACH (const QString &id, pInterface->supportedIds()) { + + if (!knownIds.contains(id)) + knownIds.append(id); + else + qWarning() << id <<"from the plugin" + << pInterface->name() + << "is already known."; + + } + plugins << plugin; + } +} + +/*! + Internal + Loads the sensorgesture plugins. + */ +void QSensorGestureManagerPrivate::loadPlugins() +{ + // Qt-style static plugins + Q_FOREACH (QObject *plugin, QPluginLoader::staticInstances()) { + initPlugin(plugin); + } + + QStringList gestureplugins = mobilityPlugins(QLatin1String("sensorgestures")); + for (int i = 0; i < gestureplugins.count(); i++) { + + QPluginLoader *loader = new QPluginLoader(gestureplugins.at(i), this); + + QObject *plugin = loader->instance(); + if (plugin) { + initPlugin(plugin); + } + } +} + + +/*! + Internal + creates the requested recognizer. + */ + +bool QSensorGestureManagerPrivate::loadRecognizer(const QString &recognizerId) +{ + for (int i= 0; i < plugins.count(); i++) { + + if (QSensorGesturePluginInterface *pInterface + = qobject_cast<QSensorGesturePluginInterface *>(plugins.at(i))) { + if (pInterface->supportedIds().contains(recognizerId)) { + if (!registeredSensorGestures.contains(recognizerId)) { + //create these recognizers + QList <QSensorGestureRecognizer *> recognizers = pInterface->createRecognizers(); + + Q_FOREACH (QSensorGestureRecognizer *recognizer, recognizers) { + + if (registeredSensorGestures.contains(recognizer->id())) { + qWarning() << "Ignoring recognizer " << recognizer->id() << "from plugin" << pInterface->name() << "because it is already registered"; + delete recognizer; + } else { + registeredSensorGestures.insert(recognizer->id(),recognizer); + } + } + } + return true; + } + } + } + return false; +} + +bool QSensorGestureManagerPrivate::registerSensorGestureRecognizer(QSensorGestureRecognizer *recognizer) +{ + if (!knownIds.contains(recognizer->id())) { + knownIds.append(recognizer->id()); + Q_ASSERT (!registeredSensorGestures.contains(recognizer->id())); + recognizer->setParent(0); + registeredSensorGestures.insert(recognizer->id(),recognizer); + + return true; + } + + qWarning() << recognizer->id() << "is already known"; + + return false; +} + +QSensorGestureRecognizer *QSensorGestureManagerPrivate::sensorGestureRecognizer(const QString &id) +{ + QSensorGestureRecognizer *recognizer = 0; + + if (loadRecognizer(id)) { + recognizer= registeredSensorGestures.value(id); + } + + return recognizer; +} + +QStringList QSensorGestureManagerPrivate::gestureIds() +{ + return knownIds; +} + + +QT_END_NAMESPACE diff --git a/src/sensors/gestures/qsensorgesturemanagerprivate_p.h b/src/sensors/gestures/qsensorgesturemanagerprivate_p.h new file mode 100644 index 0000000..b97894e --- /dev/null +++ b/src/sensors/gestures/qsensorgesturemanagerprivate_p.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 QSENSORGESTUREMANAGERPRIVATE_P_H +#define QSENSORGESTUREMANAGERPRIVATE_P_H + +#include <QObject> +#include <QMap> +#include <QStringList> +#include <QDebug> +#include <QSharedPointer> +#include <QPluginLoader> + +#include "qsensorgesture.h" +#include "qsensorgesturerecognizer.h" + +class QSensorGestureManagerPrivate : public QObject +{ + Q_OBJECT +public: + explicit QSensorGestureManagerPrivate(QObject *parent = 0); + ~QSensorGestureManagerPrivate(); + + QMap<QString, QSensorGestureRecognizer *> registeredSensorGestures; + + QList <QObject *> plugins; + + void loadPlugins(); + bool loadRecognizer(const QString &id); + + QSensorGestureRecognizer *sensorGestureRecognizer(const QString &id); + + bool registerSensorGestureRecognizer(QSensorGestureRecognizer *recognizer); + QStringList gestureIds(); + QStringList knownIds; + void initPlugin(QObject *o); +}; + +#endif // QSENSORGESTUREMANAGERPRIVATE_P_H diff --git a/src/sensors/gestures/qsensorgestureplugininterface.cpp b/src/sensors/gestures/qsensorgestureplugininterface.cpp new file mode 100644 index 0000000..8a68fbc --- /dev/null +++ b/src/sensors/gestures/qsensorgestureplugininterface.cpp @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 "qsensorgestureplugininterface.h" + + +/*! + \class QSensorGesturePluginInterface + \ingroup sensorgestures_recognizer + \inmodule QtSensors + + \brief The QSensorGesturePluginInterface class is the pure virtual interface to sensor gesture + plugins. + + \since 5.0 + + The QSensorGesturePluginInterface class is implemented in sensor gesture plugins to register + sensor gesture recognizers with QSensorGestureManager. + + \sa {QtSensorGestures Plugins} +*/ + +/*! + \fn QSensorGesturePluginInterface::createRecognizers() + + Called by the manager to create the recognizers. + Plugins should initialize and register their recognizers using + QSensorGestureManager::registerSensorGestureRecognizer() here. + + \sa QSensorGestureManager +*/ + +/*! + \fn QSensorGesturePluginInterface::supportedIds() const + + Returns a list of the recognizer Id's that this plugin supports. + */ + + +/*! + \fn QSensorGesturePluginInterface::name() const + + Returns this plugins name. + */ + diff --git a/src/sensors/gestures/qsensorgestureplugininterface.h b/src/sensors/gestures/qsensorgestureplugininterface.h new file mode 100644 index 0000000..93185b7 --- /dev/null +++ b/src/sensors/gestures/qsensorgestureplugininterface.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 QSENSORGESTUREPLUGININTERFACE_H +#define QSENSORGESTUREPLUGININTERFACE_H + +#include <QObject> +#include <QtGlobal> + +#include "qsensorgesture.h" +#include "qsensorgesturerecognizer.h" + +QT_BEGIN_NAMESPACE +class QSensorGestureRecognizer; + +class Q_SENSORS_EXPORT QSensorGesturePluginInterface +{ +public: + virtual QList <QSensorGestureRecognizer *> createRecognizers() = 0; + virtual QStringList supportedIds() const = 0; + virtual QString name() const = 0; + +}; + +Q_DECLARE_INTERFACE(QSensorGesturePluginInterface, "com.Nokia.QSensorGesturePluginInterface"); + +QT_END_NAMESPACE + +#endif // QSENSORGESTUREPLUGININTERFACE_H diff --git a/src/sensors/gestures/qsensorgesturerecognizer.cpp b/src/sensors/gestures/qsensorgesturerecognizer.cpp new file mode 100644 index 0000000..e635ee3 --- /dev/null +++ b/src/sensors/gestures/qsensorgesturerecognizer.cpp @@ -0,0 +1,190 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 "qsensorgesturerecognizer.h" +#include "qsensorgesture_p.h" +#include "qsensorgesturemanager.h" + +QT_BEGIN_NAMESPACE + +/*! + \class QSensorGestureRecognizer + \ingroup sensorgestures_recognizer + \inmodule QtSensors + + \brief The QSensorGestureRecognizer class is the base class for a sensor gesture + recognizer. + + QSensorGesture recognizer developers should sub-class this to implement their own recognizer. + + All sensor gesture recognizers have a detected(QString) signal. Implementors can use this + and send recognizer specific gestures, such as detected("shake_left") or implement custom signals + such as shakeLeft(). + + These custom signals will be available in the QSensorGesture object at runtime. + + \sa QSensorGestureRecognizer::gestureSignals() + + */ + +/*! + \fn void QSensorGestureRecognizer::create() + + Called by QSensorGesture object constructor to create the recognizers backend. + + Implementors would use this to instantiate QSensors and connect signals. + + */ + +/*! + \fn QString QSensorGestureRecognizer::id() const + Returns the identifier for this recognizer. + */ +/*! + \fn bool QSensorGestureRecognizer::start() + + Called by QSensorGesture::startDetection() to start this recognizer. + Implementors should start the sensors. + Returns true if the operation is successful. + + */ +/*! + \fn bool QSensorGestureRecognizer::stop() + + Called by QSensorGesture::stopDetection() to stop this recognizer. + Returns true if the call succeeds, otherwise false. + + Implementors should stop the sensors. + + */ +/*! + \fn bool QSensorGestureRecognizer::isActive() + + Returns true if this recognizer is active, otherwise false. + */ + +/*! + \fn QSensorGestureRecognizer::detected(const QString &gestureId) + Signals when the \a gestureId gesture has been recognized. + */ + +class QSensorGestureRecognizerPrivate +{ +public: + bool initialized; + int count; +}; + + +/*! + Constructs the QSensorGestureRecognizer with \a parent as parent. + */ +QSensorGestureRecognizer::QSensorGestureRecognizer(QObject *parent) + :QObject(parent), + d_ptr(new QSensorGestureRecognizerPrivate()) +{ +} + +/*! + Destroy the QSensorGestureRecognizer +*/ +QSensorGestureRecognizer::~QSensorGestureRecognizer() +{ + Q_ASSERT(d_ptr->count == 0); + delete d_ptr; +} + +/*! + Returns a list of signals that this recognizer supports. + + Note that all signals declared will be exported to the QSensorGesture + object. If you need to use signals that are not exported, you should use a private class + to do so. + + */ +QStringList QSensorGestureRecognizer::gestureSignals() const +{ + QStringList list; + bool ok = false; + for (int i = 0; i < this->metaObject()->methodCount(); i++) { + //weed out objectsignals and slots + if (this->metaObject()->indexOfSignal(this->metaObject()->method(i).signature()) != -1) { + QString sig( QLatin1String(this->metaObject()->method(i).signature())); + if (sig.contains(QLatin1String("detected"))) + ok = true; + if (ok) + list.append(sig); + } + } + return list; +} + +/*! + Calls QSensorGestureRecognizer::create() if the recognizer is valid. +*/ +void QSensorGestureRecognizer::createBackend() +{ + if (d_ptr->initialized) { + return; + } + d_ptr->initialized = true; + create(); +} + +/*! + Calls QSensorGestureRecognizer::start() if the recognizer isn't already running. +*/ +void QSensorGestureRecognizer::startBackend() +{ + if (d_ptr->count++ == 0) + start(); +} + +/*! + Calls QSensorGestureRecognizer::stop() if no other clients are using it. +*/ +void QSensorGestureRecognizer::stopBackend() +{ + if (--d_ptr->count == 0) + stop(); +} + +QT_END_NAMESPACE diff --git a/src/sensors/gestures/qsensorgesturerecognizer.h b/src/sensors/gestures/qsensorgesturerecognizer.h new file mode 100644 index 0000000..a6726d6 --- /dev/null +++ b/src/sensors/gestures/qsensorgesturerecognizer.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 QSENSORGESTURERECOGNIZER_H +#define QSENSORGESTURERECOGNIZER_H + +#include <QDebug> +#include <QTimer> +#include <QStringList> + +#include "qsensorgesture.h" + +QT_BEGIN_NAMESPACE + +class QSensorGestureRecognizerPrivate; +class Q_SENSORS_EXPORT QSensorGestureRecognizer : public QObject +{ + Q_OBJECT +public: + QSensorGestureRecognizer(QObject *parent = 0); + virtual ~QSensorGestureRecognizer(); + + virtual QString id() const = 0; + + virtual bool isActive() = 0; + + virtual void create() = 0; + virtual bool start() = 0; + virtual bool stop() = 0; + + void startBackend(); + void stopBackend(); + void createBackend(); + + QStringList gestureSignals() const; + +Q_SIGNALS: + void detected(const QString &); + +private: + QSensorGestureRecognizerPrivate * d_ptr; +}; +QT_END_NAMESPACE + + +#endif // QSENSORGESTURERECOGNIZER_H diff --git a/src/sensors/qsensorsglobal.h b/src/sensors/qsensorsglobal.h index 50f669b..2aaf257 100644 --- a/src/sensors/qsensorsglobal.h +++ b/src/sensors/qsensorsglobal.h @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #ifndef QSENSORSGLOBAL_H #define QSENSORSGLOBAL_H diff --git a/src/sensors/sensors.pro b/src/sensors/sensors.pro index 3377dfb..02d38cf 100644 --- a/src/sensors/sensors.pro +++ b/src/sensors/sensors.pro @@ -9,7 +9,7 @@ CONFIG(debug,debug|release):DEFINES += ENABLE_RUNTIME_SENSORLOG MODULE_PRI = ../../modules/qt_sensors.pri -QT = core +QT = core core-private DEFINES += QT_BUILD_SENSORS_LIB QT_MAKEDLL @@ -53,6 +53,21 @@ SOURCES += qsensorbackend.cpp\ qsensorplugin.cpp\ qsensorpluginloader.cpp\ +SOURCES += \ + gestures/qsensorgesture.cpp \ + gestures/qsensorgesturerecognizer.cpp \ + gestures/qsensorgesturemanager.cpp \ + gestures/qsensorgesturemanagerprivate.cpp \ + gestures/qsensorgestureplugininterface.cpp + +GESTURE_HEADERS += \ + gestures/qsensorgesture.h\ + gestures/qsensorgesture_p.h\ + gestures/qsensorgesturerecognizer.h \ + gestures/qsensorgesturemanager.h \ + gestures/qsensorgesturemanagerprivate_p.h \ + gestures/qsensorgestureplugininterface.h + # 3 files per sensor (including QSensor) SENSORS=\ qsensor\ @@ -76,4 +91,4 @@ for(s,SENSORS) { PRIVATE_HEADERS += $${s}_p.h } -HEADERS = $$PUBLIC_HEADERS $$PRIVATE_HEADERS +HEADERS = $$PUBLIC_HEADERS $$PRIVATE_HEADERS $$GESTURE_HEADERS |