From 8684d1e799d379a913535b527b301f31cd566a01 Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Mon, 17 Oct 2011 14:43:35 +1000 Subject: add QSensorGestures API. Long live QSensorGestures! Change-Id: Iada4e8888aad8b7b2180cc0bfb8576a766f75b24 Sanity-Review: Qt Sanity Bot Reviewed-by: Lincoln Ramsay --- doc/src/qtsensorgestures-cpp.qdoc | 63 +++ doc/src/qtsensorgestures-plugins.qdoc | 59 ++ doc/src/qtsensors.qdoc | 19 + doc/src/snippets/sensorgestures/creating.cpp | 73 +++ doc/src/snippets/sensorgestures/main.cpp | 45 ++ doc/src/snippets/sensorgestures/myplugin.h | 82 +++ doc/src/snippets/sensorgestures/plugin.cpp | 103 ++++ doc/src/snippets/sensorgestures/sensorgestures.pro | 9 + doc/src/snippets/snippets.pro | 2 + examples/sensors/sensorgestures/gesture.png | Bin 0 -> 3400 bytes examples/sensors/sensorgestures/main.cpp | 51 ++ examples/sensors/sensorgestures/mainwindow.cpp | 94 ++++ examples/sensors/sensorgestures/mainwindow.h | 67 +++ examples/sensors/sensorgestures/mainwindow.ui | 61 ++ examples/sensors/sensorgestures/sensorgestures.pro | 21 + examples/sensors/sensors.pro | 3 +- src/plugins/plugins.pro | 1 + src/plugins/sensorgestures/sensorgestures.pro | 2 + .../sensorgestures/shake/qshakerecognizer.cpp | 161 ++++++ .../sensorgestures/shake/qshakerecognizer.h | 97 ++++ .../shake/qshakesensorgestureplugin.cpp | 80 +++ .../shake/qshakesensorgestureplugin.h | 65 +++ src/plugins/sensorgestures/shake/shake.pro | 17 + src/sensors/gestures/qsensorgesture.cpp | 258 +++++++++ src/sensors/gestures/qsensorgesture.h | 95 ++++ src/sensors/gestures/qsensorgesture_p.h | 85 +++ src/sensors/gestures/qsensorgesturemanager.cpp | 127 +++++ src/sensors/gestures/qsensorgesturemanager.h | 85 +++ .../gestures/qsensorgesturemanagerprivate.cpp | 174 ++++++ .../gestures/qsensorgesturemanagerprivate_p.h | 77 +++ .../gestures/qsensorgestureplugininterface.cpp | 83 +++ .../gestures/qsensorgestureplugininterface.h | 67 +++ src/sensors/gestures/qsensorgesturerecognizer.cpp | 190 +++++++ src/sensors/gestures/qsensorgesturerecognizer.h | 84 +++ src/sensors/qsensorsglobal.h | 1 + src/sensors/sensors.pro | 19 +- tests/auto/auto.pro | 2 +- .../plugins/test/qtest2recognizer.cpp | 99 ++++ .../plugins/test/qtest2recognizer.h | 76 +++ .../plugins/test/qtestrecognizer.cpp | 106 ++++ .../qsensorgestures/plugins/test/qtestrecognizer.h | 79 +++ .../plugins/test/qtestsensorgestureplugin.cpp | 110 ++++ .../plugins/test/qtestsensorgestureplugin_p.h | 70 +++ .../plugins/test1/qtest2recognizerdup.cpp | 96 ++++ .../plugins/test1/qtest2recognizerdup.h | 75 +++ .../plugins/test1/qtestrecognizerdup.cpp | 95 ++++ .../plugins/test1/qtestrecognizerdup.h | 77 +++ .../plugins/test1/qtestsensorgestureplugindup.cpp | 108 ++++ .../plugins/test1/qtestsensorgestureplugindup.h | 71 +++ tests/auto/qsensorgestures/plugins/test1/test1.pro | 18 + tests/auto/qsensorgestures/qsensorgestures.pro | 33 ++ .../qsensorgestures/tst_qsensorgesturetest.cpp | 621 +++++++++++++++++++++ tests/tests.pro | 1 - 53 files changed, 4252 insertions(+), 5 deletions(-) create mode 100644 doc/src/qtsensorgestures-cpp.qdoc create mode 100644 doc/src/qtsensorgestures-plugins.qdoc create mode 100644 doc/src/snippets/sensorgestures/creating.cpp create mode 100644 doc/src/snippets/sensorgestures/main.cpp create mode 100644 doc/src/snippets/sensorgestures/myplugin.h create mode 100644 doc/src/snippets/sensorgestures/plugin.cpp create mode 100644 doc/src/snippets/sensorgestures/sensorgestures.pro create mode 100644 examples/sensors/sensorgestures/gesture.png create mode 100644 examples/sensors/sensorgestures/main.cpp create mode 100644 examples/sensors/sensorgestures/mainwindow.cpp create mode 100644 examples/sensors/sensorgestures/mainwindow.h create mode 100644 examples/sensors/sensorgestures/mainwindow.ui create mode 100644 examples/sensors/sensorgestures/sensorgestures.pro create mode 100644 src/plugins/sensorgestures/sensorgestures.pro create mode 100644 src/plugins/sensorgestures/shake/qshakerecognizer.cpp create mode 100644 src/plugins/sensorgestures/shake/qshakerecognizer.h create mode 100644 src/plugins/sensorgestures/shake/qshakesensorgestureplugin.cpp create mode 100644 src/plugins/sensorgestures/shake/qshakesensorgestureplugin.h create mode 100644 src/plugins/sensorgestures/shake/shake.pro create mode 100644 src/sensors/gestures/qsensorgesture.cpp create mode 100644 src/sensors/gestures/qsensorgesture.h create mode 100644 src/sensors/gestures/qsensorgesture_p.h create mode 100644 src/sensors/gestures/qsensorgesturemanager.cpp create mode 100644 src/sensors/gestures/qsensorgesturemanager.h create mode 100644 src/sensors/gestures/qsensorgesturemanagerprivate.cpp create mode 100644 src/sensors/gestures/qsensorgesturemanagerprivate_p.h create mode 100644 src/sensors/gestures/qsensorgestureplugininterface.cpp create mode 100644 src/sensors/gestures/qsensorgestureplugininterface.h create mode 100644 src/sensors/gestures/qsensorgesturerecognizer.cpp create mode 100644 src/sensors/gestures/qsensorgesturerecognizer.h create mode 100644 tests/auto/qsensorgestures/plugins/test/qtest2recognizer.cpp create mode 100644 tests/auto/qsensorgestures/plugins/test/qtest2recognizer.h create mode 100644 tests/auto/qsensorgestures/plugins/test/qtestrecognizer.cpp create mode 100644 tests/auto/qsensorgestures/plugins/test/qtestrecognizer.h create mode 100644 tests/auto/qsensorgestures/plugins/test/qtestsensorgestureplugin.cpp create mode 100644 tests/auto/qsensorgestures/plugins/test/qtestsensorgestureplugin_p.h create mode 100644 tests/auto/qsensorgestures/plugins/test1/qtest2recognizerdup.cpp create mode 100644 tests/auto/qsensorgestures/plugins/test1/qtest2recognizerdup.h create mode 100644 tests/auto/qsensorgestures/plugins/test1/qtestrecognizerdup.cpp create mode 100644 tests/auto/qsensorgestures/plugins/test1/qtestrecognizerdup.h create mode 100644 tests/auto/qsensorgestures/plugins/test1/qtestsensorgestureplugindup.cpp create mode 100644 tests/auto/qsensorgestures/plugins/test1/qtestsensorgestureplugindup.h create mode 100644 tests/auto/qsensorgestures/plugins/test1/test1.pro create mode 100644 tests/auto/qsensorgestures/qsensorgestures.pro create mode 100644 tests/auto/qsensorgestures/tst_qsensorgesturetest.cpp diff --git a/doc/src/qtsensorgestures-cpp.qdoc b/doc/src/qtsensorgestures-cpp.qdoc new file mode 100644 index 00000000..ba7d1f3a --- /dev/null +++ b/doc/src/qtsensorgestures-cpp.qdoc @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** 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 documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** GNU Free Documentation License +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. +** +** 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$ +** +****************************************************************************/ + +/*! +\page qtsensorgestures-cpp.html +\title QtSensorGestures C++ API +\brief Information about the QtSensorGestures C++ API + +\tableofcontents + +\section1 + + +\section1 Using QtSensorGestures + +With QtSensorGestures, you are able to easily utilize device gesturing using +sensors such as the accelerometer and proximity. +For example 'shake','spin', 'drop','cover' and 'turnover'. + + +Using QtSensorGestures is easy. There are two main classes you will need to use. + +QSensorGestureManager can be used for determining what sensor gestures are available, and +QSensorGesture for connecting the sensor gesture signals. + +\snippet snippets/sensorgestures/creating.cpp Receiving sensor gesture signals + +More information about the sensor gesture recognizers can be found in +\l{QtSensorGestures Plugins}. + +\section1 Main Classes + +The primary classes that make up the QtSensorGestures API. + +\annotatedlist sensorgestures_main + + +*/ + diff --git a/doc/src/qtsensorgestures-plugins.qdoc b/doc/src/qtsensorgestures-plugins.qdoc new file mode 100644 index 00000000..e73be5b9 --- /dev/null +++ b/doc/src/qtsensorgestures-plugins.qdoc @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** 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 documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** GNU Free Documentation License +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. +** +** 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$ +** +****************************************************************************/ + +/*! +\group sensorgesture_plugins_topics +\title QtSensorGestures Plugins +\brief Information about the QtSensorGestures recognizer plugins. + +The QtSensorGestures recognizer plugins are the way to create your own +sensor gestures. + +\tableofcontents + +\section1 Overview + + The steps to creating a sensor gesture plugin are as follows: +\list +\o Sub-class from QSensorGesturePluginInterface +\o Sub-class from QSensorGestureRecognizer and implement gesture recognizer logic using QtSensors. +\o Create an instance of that recognizer in the derived QSensorGesturePluginInterface class, and call + QSensorGestureManager::registerSensorGestureRecognizer(sRec); in your registerRecognizers() +function. QSensorGestureManager will retain ownership of the recognizer object. +\endlist + +\snippet snippets/sensorgestures/plugin.cpp Plugin + + +\section1 Recognizer Classes +If you are making sensorgestures available through the QtSensorGestures API, these are the +sensor gesture classes to use. + +\annotatedlist sensorgestures_recognizer + + +*/ diff --git a/doc/src/qtsensors.qdoc b/doc/src/qtsensors.qdoc index 13291db4..11af5156 100644 --- a/doc/src/qtsensors.qdoc +++ b/doc/src/qtsensors.qdoc @@ -73,5 +73,24 @@ \o \l {QtMobility.sensors 1.x}{Legacy QML API} \o Information about the legacy QtMobility.sensors QML API \endtable + + + \section1 Information for QtSensorGestures API + + \table + \row + \o \l {QtSensorGestures C++ API}{C++ API} + \o Information about the QtSensorGestures C++ API + \endtable + + \section1 Information for QtSensorGestures Recognizer Plugin Implementors. + + \table + \row + \o \l {QtSensorGestures Plugins}{Plugins} + \o Information about the QtSensorGestures recognizer plugins. + + \endtable + */ diff --git a/doc/src/snippets/sensorgestures/creating.cpp b/doc/src/snippets/sensorgestures/creating.cpp new file mode 100644 index 00000000..37191707 --- /dev/null +++ b/doc/src/snippets/sensorgestures/creating.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** 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:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +class MyObject : public QObject +{ + void create(); +public slots: + void gestureDetected(const QString &); +}; + +void MyObject::create() +{ +//! [Receiving sensor gesture signals] + +// Create a QSensorGestureManager + QSensorGestureManager gestureManager; + +// Get a list of known recognizers + QStringList recognizersList = gestureManager.gestureIds(); + +// Create a QSensorGeture object for each of those gesture recognizers + QSensorGesture *gesture = new QSensorGesture( gestureManager.gestureIds(), this); +// Connect the known signals up. + connect(gesture, SIGNAL(detected(QString)), this, SLOT(gestureDetected(QString))); +//! [Receiving sensor gesture signals] +} + +void MyObject::gestureDetected(const QString &gesture) +{ + Q_UNUSED(gesture); +} + diff --git a/doc/src/snippets/sensorgestures/main.cpp b/doc/src/snippets/sensorgestures/main.cpp new file mode 100644 index 00000000..1f68b7dc --- /dev/null +++ b/doc/src/snippets/sensorgestures/main.cpp @@ -0,0 +1,45 @@ +/**************************************************************************** +** +** 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:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +int main(int /*argc*/, char ** /*argv*/) +{ + return 0; +} + diff --git a/doc/src/snippets/sensorgestures/myplugin.h b/doc/src/snippets/sensorgestures/myplugin.h new file mode 100644 index 00000000..91020f0b --- /dev/null +++ b/doc/src/snippets/sensorgestures/myplugin.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** 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:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MYPLUGIN_H +#define MYPLUGIN_H + +#include +#include +#include + +class MySensorGestureRecognizer : public QSensorGestureRecognizer +{ + Q_OBJECT + public: + + MySensorGestureRecognizer(QObject *parent = 0); + ~MySensorGestureRecognizer(); + + void create(); + + QString id() const; + bool start(); + bool stop(); + bool isActive(); + +Q_SIGNALS: +// all signals will get exported to QSensorGesture + void mySignal(); +}; + +class MySensorGesturePlugin : public QObject, QSensorGesturePluginInterface +{ + Q_OBJECT + Q_INTERFACES(QSensorGesturePluginInterface) + explicit MySensorGesturePlugin(); + ~MySensorGesturePlugin(); + + QList createRecognizers(); + QStringList supportedIds() const; + QString name() const { return "MyGestures"; } +}; + +//Q_EXPORT_PLUGIN2(MySensorGestureRecognizer, MySensorGesturePlugin) + +#endif diff --git a/doc/src/snippets/sensorgestures/plugin.cpp b/doc/src/snippets/sensorgestures/plugin.cpp new file mode 100644 index 00000000..cc68cebb --- /dev/null +++ b/doc/src/snippets/sensorgestures/plugin.cpp @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** 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:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "myplugin.h" + +#include +#include + +//! [Plugin] + +MySensorGestureRecognizer::MySensorGestureRecognizer(QObject *parent) + : QSensorGestureRecognizer(parent) +{ +} + +MySensorGestureRecognizer::~MySensorGestureRecognizer() +{ +} + +bool MySensorGestureRecognizer::start() +{ + Q_EMIT mySignal(); + return true; +} + +bool MySensorGestureRecognizer::stop() +{ + return true; +} + +bool MySensorGestureRecognizer::isActive() +{ + return true; +} + +void MySensorGestureRecognizer::create() +{ +} + +QString MySensorGestureRecognizer::id() const +{ + return QString("QtSensors.mygestures"); +} + + +MySensorGesturePlugin::MySensorGesturePlugin(){} +MySensorGesturePlugin::~MySensorGesturePlugin(){} + +QList MySensorGesturePlugin::createRecognizers() +{ + QList recognizers; + MySensorGestureRecognizer *recognizer = new MySensorGestureRecognizer(this); + recognizers.append(recognizer); + + return recognizers; +} + +QStringList MySensorGesturePlugin::supportedIds() const +{ + return QStringList() << "QtSensors.mygestures"; +} + +//! [Plugin] + +//Q_EXPORT_PLUGIN2(libmy_plugin_file_name, MySensorGesturePlugin); +//#include "plugin.moc" diff --git a/doc/src/snippets/sensorgestures/sensorgestures.pro b/doc/src/snippets/sensorgestures/sensorgestures.pro new file mode 100644 index 00000000..c34a0188 --- /dev/null +++ b/doc/src/snippets/sensorgestures/sensorgestures.pro @@ -0,0 +1,9 @@ +TEMPLATE=app +TARGET=sensorgesturessdocsnippet +QT += sensors +SOURCES+=main.cpp\ + creating.cpp\ + plugin.cpp +HEADERS+=myplugin.h +LIBS+=-rdynamic +QT+=widgets diff --git a/doc/src/snippets/snippets.pro b/doc/src/snippets/snippets.pro index 0685c62c..f73d4a35 100644 --- a/doc/src/snippets/snippets.pro +++ b/doc/src/snippets/snippets.pro @@ -1,3 +1,5 @@ TEMPLATE = subdirs SUBDIRS += sensors +SUBDIRS += sensorgestures + diff --git a/examples/sensors/sensorgestures/gesture.png b/examples/sensors/sensorgestures/gesture.png new file mode 100644 index 00000000..707d5c4e Binary files /dev/null and b/examples/sensors/sensorgestures/gesture.png differ diff --git a/examples/sensors/sensorgestures/main.cpp b/examples/sensors/sensorgestures/main.cpp new file mode 100644 index 00000000..e7329a67 --- /dev/null +++ b/examples/sensors/sensorgestures/main.cpp @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** 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:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/examples/sensors/sensorgestures/mainwindow.cpp b/examples/sensors/sensorgestures/mainwindow.cpp new file mode 100644 index 00000000..668d7a21 --- /dev/null +++ b/examples/sensors/sensorgestures/mainwindow.cpp @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** 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:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" +#include "ui_mainwindow.h" + +#include +#include + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + + QSensorGestureManager manager; + + QSensorGesture *thisGesture = new QSensorGesture(manager.gestureIds(), this); + + if (thisGesture->availableIds().contains("QtSensors.shake")) { + connect(thisGesture,SIGNAL(shake()), + this,SLOT(onShake())); + } + + connect(thisGesture,SIGNAL(detected(QString)), + this,SLOT(detectedShake(QString))); + thisGesture->startDetection(); + + ui->textEdit->setReadOnly(true); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::detectedShake(const QString &name) +{ + QString str = ""+name+"
"; + ui->textEdit->insertHtml(str); + ui->textEdit->ensureCursorVisible(); +} + +void MainWindow::on_pushButton_clicked() +{ + ui->textEdit->clear(); +} + +void MainWindow::onShake() +{ + QString str = "onShake()
"; + ui->textEdit->insertHtml(str); + ui->textEdit->ensureCursorVisible(); +} + diff --git a/examples/sensors/sensorgestures/mainwindow.h b/examples/sensors/sensorgestures/mainwindow.h new file mode 100644 index 00000000..24a6f63c --- /dev/null +++ b/examples/sensors/sensorgestures/mainwindow.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:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +namespace Ui { + class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + +private: + Ui::MainWindow *ui; +private slots: + void detectedShake(const QString&); + void onShake(); + + void on_pushButton_clicked(); +}; + +#endif // MAINWINDOW_H diff --git a/examples/sensors/sensorgestures/mainwindow.ui b/examples/sensors/sensorgestures/mainwindow.ui new file mode 100644 index 00000000..b0bff42d --- /dev/null +++ b/examples/sensors/sensorgestures/mainwindow.ui @@ -0,0 +1,61 @@ + + + MainWindow + + + + 0 + 0 + 400 + 300 + + + + MainWindow + + + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Lucida Grande'; font-size:13pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:8pt;">hello</span></p></body></html> + + + + + + + Clear + + + + + + + + + 0 + 0 + 400 + 22 + + + + + + TopToolBarArea + + + false + + + + + + + + diff --git a/examples/sensors/sensorgestures/sensorgestures.pro b/examples/sensors/sensorgestures/sensorgestures.pro new file mode 100644 index 00000000..82306a9e --- /dev/null +++ b/examples/sensors/sensorgestures/sensorgestures.pro @@ -0,0 +1,21 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2011-08-10T11:04:07 +# +#------------------------------------------------- + +QT += core gui sensors widgets + +TARGET = gesture +TEMPLATE = app + +SOURCES += main.cpp\ + mainwindow.cpp + +HEADERS += mainwindow.h + +FORMS += mainwindow.ui + + +OTHER_FILES += \ + gesture.png diff --git a/examples/sensors/sensors.pro b/examples/sensors/sensors.pro index 8e909b7f..9826b522 100644 --- a/examples/sensors/sensors.pro +++ b/examples/sensors/sensors.pro @@ -5,4 +5,5 @@ SUBDIRS += \ grue contains(QT_CONFIG,widgets):SUBDIRS += \ - sensor_explorer + sensor_explorer \ + sensorgestures diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro index 234bd799..c8b9e6ab 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 00000000..e300fa77 --- /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 00000000..e544b5aa --- /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 +#include + +#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 00000000..07c12c1e --- /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 +#include +#include +#include +#include + +#include + +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 00000000..6e0f270e --- /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 +#include +#include + +#include "qshakesensorgestureplugin.h" + +#include +#include + +#include "qshakerecognizer.h" + + +QShakeSensorGesturePlugin::QShakeSensorGesturePlugin() +{ +} + +QShakeSensorGesturePlugin::~QShakeSensorGesturePlugin() +{ +} + +QStringList QShakeSensorGesturePlugin::supportedIds() const +{ + QStringList list; + list << "QtSensors.shake"; + return list; +} + +QList QShakeSensorGesturePlugin::createRecognizers() +{ + QList 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 00000000..d11b9ee9 --- /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 +#include + +#include + +class QShakeSensorGesturePlugin : public QObject, QSensorGesturePluginInterface +{ + Q_OBJECT + Q_INTERFACES(QSensorGesturePluginInterface) +public: + explicit QShakeSensorGesturePlugin(); + ~QShakeSensorGesturePlugin(); + + QList 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 00000000..80197c7e --- /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 00000000..f84ce18b --- /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 +#include +#include + +#include "qsensorgesture.h" +#include "qsensorgesture_p.h" +#include "qsensorgesturemanager.h" + +#include + +/*! + \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 00000000..0abd5a22 --- /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 +#include +#include + +#include +#include +#include + +#include + +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 00000000..10faa95a --- /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 +#include +#include +#include + +#include "qsensorgesture.h" +#include "qsensorgesturemanager.h" +#include +QT_BEGIN_NAMESPACE + +class QSensorGesturePrivate : public QObject +{ + +public: + QSensorGesturePrivate(QObject *parent = 0); + ~QSensorGesturePrivate(); + + QList 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 00000000..a0430e15 --- /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 00000000..d1935d71 --- /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 +#include + +#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 00000000..1ac21da2 --- /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 +#include + +#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(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(plugins.at(i))) { + if (pInterface->supportedIds().contains(recognizerId)) { + if (!registeredSensorGestures.contains(recognizerId)) { + //create these recognizers + QList 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 00000000..b97894e7 --- /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 +#include +#include +#include +#include +#include + +#include "qsensorgesture.h" +#include "qsensorgesturerecognizer.h" + +class QSensorGestureManagerPrivate : public QObject +{ + Q_OBJECT +public: + explicit QSensorGestureManagerPrivate(QObject *parent = 0); + ~QSensorGestureManagerPrivate(); + + QMap registeredSensorGestures; + + QList 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 00000000..8a68fbcf --- /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 00000000..93185b77 --- /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 +#include + +#include "qsensorgesture.h" +#include "qsensorgesturerecognizer.h" + +QT_BEGIN_NAMESPACE +class QSensorGestureRecognizer; + +class Q_SENSORS_EXPORT QSensorGesturePluginInterface +{ +public: + virtual QList 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 00000000..e635ee3a --- /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 00000000..a6726d64 --- /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 +#include +#include + +#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 50f669be..2aaf2576 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 3377dfb0..02d38cf2 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 diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index e16b33c0..b3042af2 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -4,4 +4,4 @@ SUBDIRS += qsensor SUBDIRS += sensors2qmlapi SUBDIRS += legacy_sensors SUBDIRS += qtsensors5 - +SUBDIRS += qsensorgestures diff --git a/tests/auto/qsensorgestures/plugins/test/qtest2recognizer.cpp b/tests/auto/qsensorgestures/plugins/test/qtest2recognizer.cpp new file mode 100644 index 00000000..d493143c --- /dev/null +++ b/tests/auto/qsensorgestures/plugins/test/qtest2recognizer.cpp @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** 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 "qtest2recognizer.h" + +#include "qtestsensorgestureplugin_p.h" + +QTest2Recognizer::QTest2Recognizer(QObject *parent) + : QSensorGestureRecognizer(parent), + active(0) +{ +} + +QTest2Recognizer::~QTest2Recognizer() +{ +} + +bool QTest2Recognizer::start() +{ + Q_EMIT test2(); + + Q_EMIT detected("test2"); + + Q_EMIT test3(true); + active = true; + + return true; +} + +bool QTest2Recognizer::stop() +{ + active = false; + return true; +} + +bool QTest2Recognizer::isActive() +{ + return active; +} + + +void QTest2Recognizer::create() +{ + active = false; +} + +QString QTest2Recognizer::id() const +{ + return QString("QtSensors.test2"); +} + +int QTest2Recognizer::thresholdTime() const +{ + return timerTimeout; +} + +void QTest2Recognizer::setThresholdTime(int msec) +{ + timer->setInterval(msec); +} + diff --git a/tests/auto/qsensorgestures/plugins/test/qtest2recognizer.h b/tests/auto/qsensorgestures/plugins/test/qtest2recognizer.h new file mode 100644 index 00000000..01059975 --- /dev/null +++ b/tests/auto/qsensorgestures/plugins/test/qtest2recognizer.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** 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 QTEST2RECOGNIZER_H +#define QTEST2RECOGNIZER_H + +#include + +class QTest2Recognizer : public QSensorGestureRecognizer +{ + Q_OBJECT + +public: + QTest2Recognizer(QObject *parent = 0); + ~QTest2Recognizer(); + + void create(); + + QString id() const; + bool start(); + bool stop(); + bool isActive(); + + int thresholdTime() const; + void setThresholdTime(int msec); + +Q_SIGNALS: + void test2(); + void test3(bool); + +private: + int timerTimeout; + QTimer *timer; + bool active; +}; + + +#endif // QTEST2RECOGNIZER_H diff --git a/tests/auto/qsensorgestures/plugins/test/qtestrecognizer.cpp b/tests/auto/qsensorgestures/plugins/test/qtestrecognizer.cpp new file mode 100644 index 00000000..dcbb9fd1 --- /dev/null +++ b/tests/auto/qsensorgestures/plugins/test/qtestrecognizer.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** 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 +#include + +#include "qtestrecognizer.h" +#include "qtestsensorgestureplugin_p.h" + + +QTestRecognizer::QTestRecognizer(QObject *parent) + : QSensorGestureRecognizer(parent), + active(0) +{ + QTimer::singleShot(2000,this, SLOT(timeout())); +} + +QTestRecognizer::~QTestRecognizer() +{ +} + +void QTestRecognizer::timeout() +{ + Q_EMIT detected("tested"); + Q_EMIT tested(); + QTimer::singleShot(2000,this, SLOT(timeout())); +} + + +bool QTestRecognizer::start() +{ + Q_EMIT detected("tested"); + Q_EMIT tested(); + active = true; + return true; +} + +bool QTestRecognizer::stop() +{ + active = false; + return true; +} + +bool QTestRecognizer::isActive() +{ + return active; +} + +void QTestRecognizer::create() +{ + active = false; +} + +QString QTestRecognizer::id() const +{ + return QString("QtSensors.test"); +} + + +int QTestRecognizer::thresholdTime() const +{ + return timerTimeout; +} + +void QTestRecognizer::setThresholdTime(int msec) +{ + timer->setInterval(msec); +} diff --git a/tests/auto/qsensorgestures/plugins/test/qtestrecognizer.h b/tests/auto/qsensorgestures/plugins/test/qtestrecognizer.h new file mode 100644 index 00000000..620c28b7 --- /dev/null +++ b/tests/auto/qsensorgestures/plugins/test/qtestrecognizer.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** 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 QTESTRECOGNIZER_H +#define QTESTRECOGNIZER_H + +#include + +class QTestRecognizer : public QSensorGestureRecognizer +{ + Q_OBJECT + Q_PROPERTY(int thresholdTime READ thresholdTime WRITE setThresholdTime) + +public: + + QTestRecognizer(QObject *parent = 0); + ~QTestRecognizer(); + + void create(); + + QString id() const; + bool start(); + bool stop(); + bool isActive(); + + int thresholdTime() const; + void setThresholdTime(int msec); + +Q_SIGNALS: + void tested(); + +private: + int timerTimeout; + QTimer *timer; + bool active; + +public slots: + void timeout(); +}; + +#endif // QTESTRECOGNIZER_H diff --git a/tests/auto/qsensorgestures/plugins/test/qtestsensorgestureplugin.cpp b/tests/auto/qsensorgestures/plugins/test/qtestsensorgestureplugin.cpp new file mode 100644 index 00000000..c7077e15 --- /dev/null +++ b/tests/auto/qsensorgestures/plugins/test/qtestsensorgestureplugin.cpp @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** 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 +#include +#include +#include +#include + +#include "qtestrecognizer.h" +#include "qtest2recognizer.h" + +#include "qtestsensorgestureplugin_p.h" + +#include +#include +#include + + +QTestSensorGesturePlugin::QTestSensorGesturePlugin() +{ +} + +QTestSensorGesturePlugin::~QTestSensorGesturePlugin() +{ +} + + +///*! +// Describes this gesture's possible gesture signals. +//handled through the detected(const QString &) signal. +// */ +//QStringList QTestSensorGesturePlugin::gestureSignals() const +//{ +// QStringList list; +// Q_FOREACH (const QSensorGestureRecognizer* rec, recognizersList) { +// list.append(rec->gestureSignals()); +// } +// return list; +//} + +QList QTestSensorGesturePlugin::createRecognizers() +{ + QSensorGestureRecognizer *sRec = new QTestRecognizer(this); + recognizersList.append(sRec); + + QSensorGestureRecognizer *sRec2 = new QTest2Recognizer(this); + recognizersList.append(sRec2); + + return recognizersList; +} + +QStringList QTestSensorGesturePlugin::supportedIds() const +{ + QStringList list; + list << "QtSensors.test"; + list <<"QtSensors.test2"; + + return list; +} + +QList QTestSensorGesturePlugin::recognizers() const +{ + return recognizersList; +} + +QString QTestSensorGesturePlugin::name() const +{ + return "TestGestures"; +} + +REGISTER_STATIC_PLUGIN_V2(QTestSensorGesturePlugin) diff --git a/tests/auto/qsensorgestures/plugins/test/qtestsensorgestureplugin_p.h b/tests/auto/qsensorgestures/plugins/test/qtestsensorgestureplugin_p.h new file mode 100644 index 00000000..a87f6a0c --- /dev/null +++ b/tests/auto/qsensorgestures/plugins/test/qtestsensorgestureplugin_p.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** 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 QTESTSENSORGESTUREPLUGIN_P_H +#define QTESTSENSORGESTUREPLUGIN_P_H + +#include +#include + +class QTestSensorGesturePlugin : public QObject, QSensorGesturePluginInterface +{ + Q_OBJECT + Q_INTERFACES(QSensorGesturePluginInterface) +public: + explicit QTestSensorGesturePlugin(); + ~QTestSensorGesturePlugin(); + + QList createRecognizers(); + +// QStringList gestureSignals() const; + QStringList supportedIds() const; + QString name() const; + + QList recognizers() const; + + QList recognizersList; + +}; + + + +#endif // QTESTSENSORGESTUREPLUGIN_H diff --git a/tests/auto/qsensorgestures/plugins/test1/qtest2recognizerdup.cpp b/tests/auto/qsensorgestures/plugins/test1/qtest2recognizerdup.cpp new file mode 100644 index 00000000..0523d84c --- /dev/null +++ b/tests/auto/qsensorgestures/plugins/test1/qtest2recognizerdup.cpp @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** 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 "qtest2recognizerdup.h" + +#include "qtestsensorgestureplugindup.h" + +QTest2RecognizerDup::QTest2RecognizerDup(QObject *parent) + : QSensorGestureRecognizer(parent), + active(0) +{ +} + +QTest2RecognizerDup::~QTest2RecognizerDup() +{ +} + +bool QTest2RecognizerDup::start() +{ + Q_EMIT test2_dup(); + + active = true; + + return true; +} + +bool QTest2RecognizerDup::stop() +{ + active = false; + return true; +} + +bool QTest2RecognizerDup::isActive() +{ + return active; +} + + +void QTest2RecognizerDup::create() +{ + active = false; +} + +QString QTest2RecognizerDup::id() const +{ + return QString("QtSensors.test.dup"); +} + +int QTest2RecognizerDup::thresholdTime() const +{ + return timerTimeout; +} + +void QTest2RecognizerDup::setThresholdTime(int msec) +{ + timer->setInterval(msec); +} + diff --git a/tests/auto/qsensorgestures/plugins/test1/qtest2recognizerdup.h b/tests/auto/qsensorgestures/plugins/test1/qtest2recognizerdup.h new file mode 100644 index 00000000..502918c1 --- /dev/null +++ b/tests/auto/qsensorgestures/plugins/test1/qtest2recognizerdup.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** 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 QTEST2RECOGNIZERDUP_H +#define QTEST2RECOGNIZERDUP_H + +#include + +class QTest2RecognizerDup : public QSensorGestureRecognizer +{ + Q_OBJECT + +public: + QTest2RecognizerDup(QObject *parent = 0); + ~QTest2RecognizerDup(); + + void create(); + + QString id() const; + bool start(); + bool stop(); + bool isActive(); + + int thresholdTime() const; + void setThresholdTime(int msec); + +Q_SIGNALS: + void test2_dup(); + +private: + int timerTimeout; + QTimer *timer; + bool active; +}; + + +#endif // QTEST2RECOGNIZERDUP_H diff --git a/tests/auto/qsensorgestures/plugins/test1/qtestrecognizerdup.cpp b/tests/auto/qsensorgestures/plugins/test1/qtestrecognizerdup.cpp new file mode 100644 index 00000000..ded86e33 --- /dev/null +++ b/tests/auto/qsensorgestures/plugins/test1/qtestrecognizerdup.cpp @@ -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$ +** +****************************************************************************/ + +#include + +#include "qtestrecognizerdup.h" +#include "qtestsensorgestureplugindup.h" + +QTestRecognizerDup::QTestRecognizerDup(QObject *parent) + : QSensorGestureRecognizer(parent), + active(0) +{ +} + +QTestRecognizerDup::~QTestRecognizerDup() +{ +} + +bool QTestRecognizerDup::start() +{ + active = true; + Q_EMIT detected("test2_dup"); + Q_EMIT test2_dup(); + return true; +} + +bool QTestRecognizerDup::stop() +{ + active = false; + return true; +} + +bool QTestRecognizerDup::isActive() +{ + return active; +} + +void QTestRecognizerDup::create() +{ + active = false; +} + +QString QTestRecognizerDup::id() const +{ + return QString("QtSensors.test.dup"); +} + + +int QTestRecognizerDup::thresholdTime() const +{ + return timerTimeout; +} + +void QTestRecognizerDup::setThresholdTime(int msec) +{ + timer->setInterval(msec); +} diff --git a/tests/auto/qsensorgestures/plugins/test1/qtestrecognizerdup.h b/tests/auto/qsensorgestures/plugins/test1/qtestrecognizerdup.h new file mode 100644 index 00000000..7ca06f82 --- /dev/null +++ b/tests/auto/qsensorgestures/plugins/test1/qtestrecognizerdup.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 QTESTRECOGNIZERDUP_H +#define QTESTRECOGNIZERDUP_H + +#include + +class QTestRecognizerDup : public QSensorGestureRecognizer +{ + Q_OBJECT + Q_PROPERTY(int thresholdTime READ thresholdTime WRITE setThresholdTime) + +public: + + QTestRecognizerDup(QObject *parent = 0); + ~QTestRecognizerDup(); + + void create(); + + QString id() const; + bool start(); + bool stop(); + bool isActive(); + + int thresholdTime() const; + void setThresholdTime(int msec); + +Q_SIGNALS: + void test2_dup(); + +private: + int timerTimeout; + QTimer *timer; + bool active; + +}; + +#endif // QTESTRECOGNIZERDUP_H diff --git a/tests/auto/qsensorgestures/plugins/test1/qtestsensorgestureplugindup.cpp b/tests/auto/qsensorgestures/plugins/test1/qtestsensorgestureplugindup.cpp new file mode 100644 index 00000000..3b2b5da9 --- /dev/null +++ b/tests/auto/qsensorgestures/plugins/test1/qtestsensorgestureplugindup.cpp @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** 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 +#include +#include +#include + +#include "qtestrecognizerdup.h" +#include "qtest2recognizerdup.h" + +#include "qtestsensorgestureplugindup.h" + +#include +#include +#include + + +QTestSensorGestureDupPlugin::QTestSensorGestureDupPlugin() +{ +} + +QTestSensorGestureDupPlugin::~QTestSensorGestureDupPlugin() +{ +} + +/*! + Describes this gesture's possible gesture signals. +handled through the detected(const QString &) signal. + */ +QStringList QTestSensorGestureDupPlugin::gestureSignals() const +{ + QStringList list; + Q_FOREACH (const QSensorGestureRecognizer* rec,recognizersList) { + list.append(rec->gestureSignals()); + } + return list; +} + +QList QTestSensorGestureDupPlugin::createRecognizers() +{ + QSensorGestureRecognizer *sRec = new QTestRecognizerDup(this); + recognizersList.append(sRec); + + QSensorGestureRecognizer *sRec2 = new QTest2RecognizerDup(this); + recognizersList.append(sRec2); + + return recognizersList; +} + +QStringList QTestSensorGestureDupPlugin::supportedIds() const +{ + QStringList list; + list << "QtSensors.test.dup"; + list << "QtSensors.test.dup"; + + return list; +} + +QList QTestSensorGestureDupPlugin::recognizers() const +{ + return recognizersList; +} + +QString QTestSensorGestureDupPlugin::name() const +{ + return "TestGesturesDup"; +} + +REGISTER_STATIC_PLUGIN_V2(QTestSensorGestureDupPlugin) diff --git a/tests/auto/qsensorgestures/plugins/test1/qtestsensorgestureplugindup.h b/tests/auto/qsensorgestures/plugins/test1/qtestsensorgestureplugindup.h new file mode 100644 index 00000000..b6c083bf --- /dev/null +++ b/tests/auto/qsensorgestures/plugins/test1/qtestsensorgestureplugindup.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** 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 QTESTSENSORGESTUREDUPPLUGIN_H +#define QTESTSENSORGESTUREDUPPLUGIN_H + +#include +#include + +class QTestSensorGestureDupPlugin : public QObject, public QSensorGesturePluginInterface +{ + Q_OBJECT + Q_INTERFACES(QSensorGesturePluginInterface) +public: + explicit QTestSensorGestureDupPlugin(); + ~QTestSensorGestureDupPlugin(); + + + QList createRecognizers(); + + QStringList gestureSignals() const; + QStringList supportedIds() const; + QString name() const; + + QList recognizers() const; + + QList recognizersList; + +}; + + + +#endif // QTESTSENSORGESTUREDUPPLUGIN_H diff --git a/tests/auto/qsensorgestures/plugins/test1/test1.pro b/tests/auto/qsensorgestures/plugins/test1/test1.pro new file mode 100644 index 00000000..bd3e428e --- /dev/null +++ b/tests/auto/qsensorgestures/plugins/test1/test1.pro @@ -0,0 +1,18 @@ +TEMPLATE = lib +CONFIG += plugin + +TARGET = qtsensorgestures_testplugin1 + +QT += sensors sensorgestures +DESTDIR = $$QT.sensorgestures.plugins/sensorgestures + +# Input +HEADERS += qtestsensorgestureplugindup_p.h \ + qtestrecognizerdup.h \ + qtest2recognizerdup.h +SOURCES += qtestsensorgestureplugindup.cpp \ + qtestrecognizerdup.cpp \ + qtest2recognizerduo.cpp + +target.path += $$[QT_INSTALL_PLUGINS]/sensorgestures +INSTALLS += target diff --git a/tests/auto/qsensorgestures/qsensorgestures.pro b/tests/auto/qsensorgestures/qsensorgestures.pro new file mode 100644 index 00000000..5bccd762 --- /dev/null +++ b/tests/auto/qsensorgestures/qsensorgestures.pro @@ -0,0 +1,33 @@ +TEMPLATE = app +TARGET = tst_qsensorgesturetest +CONFIG += testcase + +QT += core testlib sensors +QT -= gui + +SOURCES += tst_qsensorgesturetest.cpp + + +PLUGIN_1_HEADERS = \ + plugins/test1/qtestsensorgestureplugindup.h \ + plugins/test1/qtestrecognizerdup.h \ + plugins/test1/qtest2recognizerdup.h + +PLUGIN_1_SOURCES = \ + plugins/test1/qtestsensorgestureplugindup.cpp \ + plugins/test1/qtestrecognizerdup.cpp \ + plugins/test1/qtest2recognizerdup.cpp + +HEADERS += $$PLUGIN_1_HEADERS +SOURCES += $$PLUGIN_1_SOURCES + +HEADERS += \ + plugins/test/qtestsensorgestureplugin_p.h \ + plugins/test/qtestrecognizer.h \ + plugins/test/qtest2recognizer.h + +SOURCES += \ + plugins/test/qtestsensorgestureplugin.cpp \ + plugins/test/qtestrecognizer.cpp \ + plugins/test/qtest2recognizer.cpp + diff --git a/tests/auto/qsensorgestures/tst_qsensorgesturetest.cpp b/tests/auto/qsensorgestures/tst_qsensorgesturetest.cpp new file mode 100644 index 00000000..8f88425b --- /dev/null +++ b/tests/auto/qsensorgestures/tst_qsensorgesturetest.cpp @@ -0,0 +1,621 @@ +/**************************************************************************** +** +** 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 +#include +#include +#include +#include + +#include +#include + +#include +#include + +static bool waitForSignal(QObject *obj, const char *signal, int timeout = 0) +{ + QEventLoop loop; + QObject::connect(obj, signal, &loop, SLOT(quit())); + QTimer timer; + QSignalSpy timeoutSpy(&timer, SIGNAL(timeout())); + if (timeout > 0) { + QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); + timer.setSingleShot(true); + timer.start(timeout); + } + loop.exec(); + return timeoutSpy.isEmpty(); +} + +class QTest3Recognizer : public QSensorGestureRecognizer +{ + Q_OBJECT + +public: + + QTest3Recognizer(QObject *parent = 0); + + void create(); + + QString id() const; + bool start() ; + bool stop(); + bool isActive(); + void changeId(const QString &); + + QString recognizerId; +}; + +QTest3Recognizer::QTest3Recognizer(QObject *parent) : QSensorGestureRecognizer(parent), + recognizerId("QtSensors/test3"){} + +void QTest3Recognizer::create(){} + +QString QTest3Recognizer::id() const{ return recognizerId; } +bool QTest3Recognizer::start(){return true;} +bool QTest3Recognizer::stop() { return true;} +bool QTest3Recognizer::isActive() { return true; } +void QTest3Recognizer::changeId(const QString &id) +{ + recognizerId = id; +} + + +class GestureThread : public QThread +{ + Q_OBJECT +public: + GestureThread(const QStringList &name) { ids = name;} + ~GestureThread() { delete gesture; } + void run() + { + gesture = new QSensorGesture(ids, this); + QObject::connect(gesture,SIGNAL(detected(QString)),this,SIGNAL(detected(QString))); + gesture->startDetection(); + } + + QSensorGesture *gesture; + QStringList ids; + +Q_SIGNALS: + void detected(const QString &); +}; + +class Tst_qsensorgestureTest : public QObject +{ + Q_OBJECT + +public: + Tst_qsensorgestureTest(); + +private Q_SLOTS: + + void tst_recognizer_dup(); //comes first to weed out messages + + void tst_manager(); + void tst_manager_gestureids(); + void tst_manager_recognizerSignals(); + void tst_manager_registerSensorGestureRecognizer(); + void tst_manager__newSensorAvailable(); + + void tst_sensor_gesture_signals(); + void tst_sensor_gesture_threaded(); + + void tst_sensor_gesture(); + + void tst_recognizer(); + + void tst_sensorgesture_noid(); + + void tst_sensor_gesture_multi(); + + void shakeDetected(const QString &); + +private: + QString currentSignal; +}; + +Tst_qsensorgestureTest::Tst_qsensorgestureTest() +{ +} + +void Tst_qsensorgestureTest::tst_recognizer_dup() +{ + { + QStringList idList; + QTest::ignoreMessage(QtWarningMsg, "\"QtSensors.test.dup\" from the plugin \"TestGesturesDup\" is already known. "); + QSensorGestureManager manager; + idList = manager.gestureIds(); + + for (int i = 0; i < idList.count(); i++) { + if (idList.at(i) == "QtSensors.test.dup") + + QTest::ignoreMessage(QtWarningMsg, "Ignoring recognizer \"QtSensors.test.dup\" from plugin \"TestGesturesDup\" because it is already registered "); + QStringList recognizerSignalsList = manager.recognizerSignals(idList.at(i)); + + QVERIFY(!recognizerSignalsList.contains("QtSensors.test2")); + } + + QSensorGesture *sensorGesture = new QSensorGesture(idList, this); + QVERIFY(sensorGesture->availableIds().contains("QtSensors.test2")); + QVERIFY(sensorGesture->availableIds().contains("QtSensors.test")); + QVERIFY(sensorGesture->availableIds().contains("QtSensors.test.dup")); + delete sensorGesture; + } + + QSensorGesture *thisGesture; + QString plugin; + plugin = "QtSensors.test2"; + thisGesture = new QSensorGesture(QStringList() << plugin, this); + QVERIFY(thisGesture->availableIds().contains("QtSensors.test2")); + + plugin = "QtSensors.test.dup"; + thisGesture = new QSensorGesture(QStringList() << plugin, this); + QVERIFY(!thisGesture->availableIds().contains("QtSensors.test2")); + delete thisGesture; +} + +void Tst_qsensorgestureTest::tst_manager() +{ + QSensorGestureManager *manager2; + manager2 = new QSensorGestureManager(this); + QVERIFY(manager2 != 0); + delete manager2; +} + +void Tst_qsensorgestureTest::tst_manager_gestureids() +{ + { + QStringList idList; + QSensorGestureManager manager; + idList = manager.gestureIds(); + + QVERIFY(idList.count() > 0); + + QVERIFY(idList.contains("QtSensors.test")); + QVERIFY(idList.contains("QtSensors.test2")); + QVERIFY(idList.contains("QtSensors.test.dup")); + } +} + +void Tst_qsensorgestureTest::tst_manager_recognizerSignals() +{ + { + QStringList idList; + + QSensorGestureManager manager; + idList = manager.gestureIds(); + + idList.removeOne("QtSensors.test.dup"); + + for (int i = 0; i < idList.count(); i++) { + + QStringList recognizerSignalsList = manager.recognizerSignals(idList.at(i)); + + if (idList.at(i) == "QtSensors.test") { + QStringList signalList; + signalList << "detected(QString)"; + signalList << "tested()"; + QVERIFY(recognizerSignalsList.count() == 2); + + QVERIFY(recognizerSignalsList == signalList); + + } else if (idList.at(i) == "QtSensors.test2") { + QStringList signalList; + signalList << "detected(QString)"; + signalList << "test2()"; + signalList << "test3(bool)"; + + QVERIFY(recognizerSignalsList.count() == 3); + QVERIFY(recognizerSignalsList == signalList); + } + } + } +} + +void Tst_qsensorgestureTest::tst_manager_registerSensorGestureRecognizer() +{ + QSensorGestureManager manager; + int num = manager.gestureIds().count(); + QSensorGestureRecognizer *recognizer = new QTest3Recognizer; + bool ok = manager.registerSensorGestureRecognizer(recognizer); + QCOMPARE(ok, true); + QVERIFY(num+1 == manager.gestureIds().count()); + + recognizer = new QTest3Recognizer; + QTest::ignoreMessage(QtWarningMsg, "\"QtSensors/test3\" is already known "); + ok = manager.registerSensorGestureRecognizer(recognizer); + QCOMPARE(ok, false); + QVERIFY(num+1 == manager.gestureIds().count()); + +} + +void Tst_qsensorgestureTest::tst_manager__newSensorAvailable() +{ + QSensorGestureManager manager; + + QSignalSpy spy_manager_available(&manager, SIGNAL(newSensorGestureAvailable())); + + manager.gestureIds(); + QCOMPARE(spy_manager_available.count(),0); + + QTest3Recognizer *recognizer = new QTest3Recognizer; + recognizer->changeId("QtSensors.test4"); + + bool ok = manager.registerSensorGestureRecognizer(recognizer); + QCOMPARE(ok, true); + QCOMPARE(spy_manager_available.count(),1); + + recognizer = new QTest3Recognizer; + recognizer->changeId("QtSensors.test4"); + QTest::ignoreMessage(QtWarningMsg, "\"QtSensors.test4\" is already known "); + ok = manager.registerSensorGestureRecognizer(recognizer); + QCOMPARE(ok, false); + QCOMPARE(spy_manager_available.count(),1); +} + + +void Tst_qsensorgestureTest::tst_sensor_gesture_signals() +{ + QStringList testidList; + testidList << "QtSensors.test"; + testidList << "QtSensors.test2"; + + Q_FOREACH (const QString &plugin, testidList) { + + QSensorGesture *thisGesture; + thisGesture = new QSensorGesture(QStringList() << plugin, this); + + QSignalSpy spy_gesture_detected(thisGesture, SIGNAL(detected(QString))); + + QSignalSpy *spy_gesture_tested; + QSignalSpy *spy_gesture_test2; + + if (plugin == "QtSensors.test") { + QStringList signalList; + signalList << "detected(QString)"; + signalList << "tested()"; + + QVERIFY(thisGesture->gestureSignals().count() == 2); + QVERIFY(thisGesture->gestureSignals() == signalList); + + QVERIFY(thisGesture->gestureSignals().at(1) == "tested()"); + + spy_gesture_tested = new QSignalSpy(thisGesture, SIGNAL(tested())); + } + + if (plugin == "QtSensors.test2") { + QStringList signalList; + signalList << "detected(QString)"; + signalList << "test2()"; + signalList << "test3(bool)"; + QVERIFY(thisGesture->gestureSignals().count() == 3); + QVERIFY(thisGesture->gestureSignals() == signalList); + + QVERIFY(thisGesture->gestureSignals().at(1) == "test2()"); + spy_gesture_test2 = new QSignalSpy(thisGesture, SIGNAL(test2())); + + } + + QVERIFY( thisGesture->availableIds() != QStringList()); + thisGesture->startDetection(); + + QCOMPARE(spy_gesture_detected.count(),1); + + if (plugin == "QtSensors.test") { + QCOMPARE(spy_gesture_tested->count(),1); + QList arguments ; + arguments = spy_gesture_detected.takeFirst(); // take the first signal + QVERIFY(arguments.at(0) == "tested"); + } + + if (plugin == "QtSensors.test2") { + QCOMPARE(spy_gesture_test2->count(),1); + } + + delete thisGesture; + thisGesture = 0; + } + +} + + +void Tst_qsensorgestureTest::tst_sensor_gesture_threaded() +{ + + QSensorGesture *gesture = new QSensorGesture(QStringList() << "QtSensors.test", this); + + GestureThread *thread = new GestureThread( QStringList() << "QtSensors.test"); + + currentSignal = gesture->gestureSignals().at(0).left(gesture->gestureSignals().at(0).indexOf("(")); + + QSignalSpy thread_gesture(thread, SIGNAL(detected(QString))); + QSignalSpy spy_gesture2(gesture, SIGNAL(detected(QString))); + + QCOMPARE(gesture->isActive(),false); + gesture->startDetection(); + + QCOMPARE(thread_gesture.count(),0); + QCOMPARE(spy_gesture2.count(),1); + + QCOMPARE(gesture->isActive(),true); + + thread->run(); + QCOMPARE(thread->gesture->isActive(),true); + + QVERIFY(::waitForSignal(thread, SIGNAL(detected(QString)), 60 * 1000)); + + QVERIFY(::waitForSignal(gesture, SIGNAL(detected(QString)), 60 * 1000)); + + thread->gesture->stopDetection(); + + QCOMPARE(thread->gesture->isActive(),false); + QCOMPARE(gesture->isActive(),true); + + delete gesture; + gesture = 0; + delete thread; + thread = 0; +} + +void Tst_qsensorgestureTest::tst_sensor_gesture() +{ + QSensorGesture *gesture = new QSensorGesture(QStringList() << "QtSensors.test", this); + + QSensorGesture *gesture2 = new QSensorGesture(QStringList() << "QtSensors.test2", this); + QSensorGesture *gesture3 = new QSensorGesture(QStringList() << "QtSensors.test2", this); + + QCOMPARE(gesture->availableIds(),QStringList() << "QtSensors.test"); + + QCOMPARE(gesture->gestureSignals().at(1).left(gesture->gestureSignals().at(1).indexOf("(")),QString("tested")); + + currentSignal = gesture->gestureSignals().at(1).left(gesture->gestureSignals().at(1).indexOf("(")); + + QSignalSpy spy_gesture(gesture, SIGNAL(detected(QString))); + + QSignalSpy spy_gesture2(gesture2, SIGNAL(detected(QString))); + + QSignalSpy spy_gesture3_detected(gesture3, SIGNAL(detected(QString))); + + QSignalSpy spy_gesture4_test2(gesture3, SIGNAL(test2())); + QSignalSpy spy_gesture5_test3(gesture3, SIGNAL(test3(bool))); + + + QCOMPARE(gesture->isActive(),false); + gesture->startDetection(); + + QCOMPARE(spy_gesture.count(),1); + + QCOMPARE(gesture->isActive(),true); + QCOMPARE(gesture2->availableIds(),QStringList() <<"QtSensors.test2"); + QCOMPARE(gesture2->gestureSignals().at(1).left(gesture2->gestureSignals().at(1).indexOf("(")),QString("test2")); + currentSignal = gesture2->gestureSignals().at(1).left(gesture2->gestureSignals().at(1).indexOf("(")); + + connect(gesture2,SIGNAL(detected(QString)), + this,SLOT(shakeDetected(QString))); + + QCOMPARE(gesture2->isActive(),false); + + gesture2->startDetection(); + + QCOMPARE(gesture2->isActive(),true); + + QCOMPARE(spy_gesture2.count(),1); + + QCOMPARE(spy_gesture3_detected.count(),0); + + gesture2->stopDetection(); + + QCOMPARE(gesture2->isActive(),false); + QCOMPARE(gesture3->isActive(),false); + + gesture3->startDetection(); + + QCOMPARE(gesture3->isActive(),true); + QCOMPARE(gesture2->isActive(),false); + + QCOMPARE(spy_gesture.count(),1); + + QCOMPARE(spy_gesture2.count(),1); + + + QCOMPARE(spy_gesture3_detected.count(),1); + + QCOMPARE(spy_gesture4_test2.count(),1); + + QCOMPARE(spy_gesture5_test3.count(),1); + + QList arguments2 = spy_gesture5_test3.takeFirst(); + QVERIFY(arguments2.at(0).type() == QVariant::Bool); + QVERIFY(arguments2.at(0) == true); + + delete gesture; + gesture = 0; + delete gesture2; + gesture2 = 0; + delete gesture3; + gesture3 = 0; +} + + +void Tst_qsensorgestureTest::tst_recognizer() +{ + QSensorGesture *gesture = new QSensorGesture(QStringList() << "QtSensors.test", this); + QSensorGesture *gesture2 = new QSensorGesture(QStringList() << "QtSensors.test", this); + + QSignalSpy spy_gesture(gesture, SIGNAL(detected(QString))); + QSignalSpy spy_gesture2(gesture2, SIGNAL(detected(QString))); + + QCOMPARE(gesture->isActive(),false); + QCOMPARE(gesture2->isActive(),false); + + currentSignal = gesture2->gestureSignals().at(0).left(gesture2->gestureSignals().at(0).indexOf("(")); + + gesture2->startDetection();//activate 2 + + QCOMPARE(gesture->isActive(),false); + QCOMPARE(gesture2->isActive(),true); + + QCOMPARE(spy_gesture.count(),0); + + QCOMPARE(spy_gesture2.count(),1); + + QList arguments = spy_gesture2.takeFirst(); + QVERIFY(arguments.at(0) == "tested"); + + QCOMPARE(spy_gesture2.count(),0); + + gesture->startDetection(); //activate 1 + + QCOMPARE(gesture->isActive(),true); + QCOMPARE(gesture2->isActive(),true); + + QVERIFY(::waitForSignal(gesture, SIGNAL(detected(QString)), 5 * 1000)); + QCOMPARE(spy_gesture.count(),1); + + QCOMPARE(spy_gesture2.count(),1); + + arguments = spy_gesture.takeFirst(); // take the first signal + QVERIFY(arguments.at(0) == "tested"); + spy_gesture2.removeFirst(); + + gesture->stopDetection(); //stop 1 gesture object + + QCOMPARE(gesture->isActive(),false); + QCOMPARE(gesture2->isActive(),true); + + gesture2->startDetection(); + + QCOMPARE(gesture->isActive(),false); + QCOMPARE(spy_gesture.count(),0); + + QCOMPARE(gesture2->isActive(),true); + + QVERIFY(::waitForSignal(gesture2, SIGNAL(detected(QString)), 60 * 1000)); + + delete gesture; + gesture = 0; + delete gesture2; + gesture2 = 0; +} + + +void Tst_qsensorgestureTest::tst_sensorgesture_noid() +{ + QSensorGesture *gesture = new QSensorGesture(QStringList() << "QtSensors.noid", this); + QVERIFY(gesture->availableIds().isEmpty()); + QVERIFY(!gesture->isValid()); + + QTest::ignoreMessage(QtWarningMsg, "QSignalSpy: No such signal: 'detected(QString)'"); + QSignalSpy spy_gesture(gesture, SIGNAL(detected(QString))); + + QCOMPARE(spy_gesture.count(),0); + + gesture->startDetection(); + QCOMPARE(gesture->isActive(),false); + QCOMPARE(spy_gesture.count(),0); + + gesture->stopDetection(); + QCOMPARE(gesture->isActive(),false); + QCOMPARE(spy_gesture.count(),0); + + QVERIFY(gesture->gestureSignals().isEmpty()); + + delete gesture; + gesture = 0; +} + +void Tst_qsensorgestureTest::tst_sensor_gesture_multi() +{ + + QStringList ids; + ids << "QtSensors.test"; + ids <<"QtSensors.test2"; + ids << "QtSensors.bogus"; + + QSensorGesture *gesture = new QSensorGesture(ids,this); + QStringList gestureSignals = gesture->gestureSignals(); + + gestureSignals.removeDuplicates() ; + QVERIFY(gestureSignals == gesture->gestureSignals()); + + QVERIFY(gesture->gestureSignals().count() == 4); + QVERIFY(!gesture->availableIds().contains("QtSensors.bogus")); + + QCOMPARE(gesture->isActive(),false); + + QSignalSpy spy_gesture_detected(gesture, SIGNAL(detected(QString))); + gesture->startDetection(); + QCOMPARE(gesture->isActive(),true); + QCOMPARE(spy_gesture_detected.count(),2); + + QList arguments ; + arguments = spy_gesture_detected.takeAt(0); + QVERIFY(arguments.at(0) == "tested"); + + arguments = spy_gesture_detected.takeAt(0); + QVERIFY(arguments.at(0) == "test2"); + + QVERIFY(::waitForSignal(gesture, SIGNAL(detected(QString)), 60 * 1000)); + QCOMPARE(spy_gesture_detected.count(),1); + + gesture->stopDetection(); + + QCOMPARE(gesture->isActive(),false); + + { + QSensorGestureManager manager; + QVERIFY(!manager.gestureIds().contains("QtSensors.bogus")); + QSensorGestureRecognizer *recognizer = manager.sensorGestureRecognizer("QtSensors.bogus"); + QVERIFY(recognizer == NULL); + } + +} + +void Tst_qsensorgestureTest::shakeDetected(const QString &type) +{ + QCOMPARE(type,currentSignal); +} + +QTEST_MAIN(Tst_qsensorgestureTest); + +#include "tst_qsensorgesturetest.moc" diff --git a/tests/tests.pro b/tests/tests.pro index f1633f70..f9277000 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -1,4 +1,3 @@ TEMPLATE = subdirs SUBDIRS += auto - -- cgit v1.2.3