diff options
Diffstat (limited to 'src')
66 files changed, 1 insertions, 4419 deletions
diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index 0da96701..64b9584e 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -1,2 +1 @@ add_subdirectory(sensors) -# add_subdirectory(sensorgestures) diff --git a/src/plugins/sensorgestures/CMakeLists.txt b/src/plugins/sensorgestures/CMakeLists.txt deleted file mode 100644 index 07fbacc9..00000000 --- a/src/plugins/sensorgestures/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_subdirectory(shake) -add_subdirectory(qtsensors) diff --git a/src/plugins/sensorgestures/qtsensors/CMakeLists.txt b/src/plugins/sensorgestures/qtsensors/CMakeLists.txt deleted file mode 100644 index b08a7f47..00000000 --- a/src/plugins/sensorgestures/qtsensors/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -##################################################################### -## QtSensorGesturePlugin Plugin: -##################################################################### - -qt_internal_add_plugin(QtSensorGesturePlugin - OUTPUT_NAME qtsensorgestures_plugin - PLUGIN_TYPE sensorgestures - DEFAULT_IF FALSE - SOURCES - qcoversensorgesturerecognizer.cpp qcoversensorgesturerecognizer.h - qdoubletapsensorgesturerecognizer.cpp qdoubletapsensorgesturerecognizer.h - qfreefallsensorgesturerecognizer.cpp qfreefallsensorgesturerecognizer.h - qhoversensorgesturerecognizer.cpp qhoversensorgesturerecognizer.h - qpickupsensorgesturerecognizer.cpp qpickupsensorgesturerecognizer.h - qshake2recognizer.cpp qshake2recognizer.h - qslamgesturerecognizer.cpp qslamgesturerecognizer.h - qtsensorgestureplugin.cpp qtsensorgestureplugin.h - qtsensorgesturesensorhandler.cpp qtsensorgesturesensorhandler.h - qturnoversensorgesturerecognizer.cpp qturnoversensorgesturerecognizer.h - qtwistsensorgesturerecognizer.cpp qtwistsensorgesturerecognizer.h - qwhipsensorgesturerecognizer.cpp qwhipsensorgesturerecognizer.h - LIBRARIES - Qt::Core - Qt::Sensors -) - -#### Keys ignored in scope 1:.:.:qtsensors.pro:<TRUE>: -# OTHER_FILES = "plugin.json" -# PLUGIN_EXTENDS = "-" diff --git a/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.cpp deleted file mode 100644 index e7b4cd84..00000000 --- a/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.cpp +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#include "qcoversensorgesturerecognizer.h" -#include "qtsensorgesturesensorhandler.h" - -QT_BEGIN_NAMESPACE - -QCoverSensorGestureRecognizer::QCoverSensorGestureRecognizer(QObject *parent) - : QSensorGestureRecognizer(parent), - orientationReading(0), - proximityReading(0), - timer(0), - active(0), - detecting(0) -{ -} - -QCoverSensorGestureRecognizer::~QCoverSensorGestureRecognizer() -{ -} - -void QCoverSensorGestureRecognizer::create() -{ - timer = new QTimer(this); - connect(timer,SIGNAL(timeout()),this,SLOT(timeout())); - timer->setSingleShot(true); - timer->setInterval(750); -} - -QString QCoverSensorGestureRecognizer::id() const -{ - return QString("QtSensors.cover"); -} - -bool QCoverSensorGestureRecognizer::start() -{ - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Proximity)) { - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Orientation)) { - active = true; - connect(QtSensorGestureSensorHandler::instance(),SIGNAL(proximityReadingChanged(QProximityReading*)), - this,SLOT(proximityChanged(QProximityReading*))); - - connect(QtSensorGestureSensorHandler::instance(),SIGNAL(orientationReadingChanged(QOrientationReading*)), - this,SLOT(orientationReadingChanged(QOrientationReading*))); - } else { - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Proximity); - active = false; - } - } else { - active = false; - } - return active; -} - -bool QCoverSensorGestureRecognizer::stop() -{ - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Proximity); - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Orientation); - - disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(proximityReadingChanged(QProximityReading*)), - this,SLOT(proximityChanged(QProximityReading*))); - disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(orientationReadingChanged(QOrientationReading*)), - this,SLOT(orientationReadingChanged(QOrientationReading*))); - - active = false; - timer->stop(); - return active; -} - -bool QCoverSensorGestureRecognizer::isActive() -{ - return active; -} - -void QCoverSensorGestureRecognizer::proximityChanged(QProximityReading *reading) -{ - if (orientationReading == 0) - return; - - proximityReading = reading->close(); - - // look at case of face up->face down->face up. - if (orientationReading->orientation() == QOrientationReading::FaceUp - && proximityReading) { - if (!timer->isActive()) { - timer->start(); - detecting = true; - } - } -} - -void QCoverSensorGestureRecognizer::orientationReadingChanged(QOrientationReading *reading) -{ - orientationReading = reading; -} - -void QCoverSensorGestureRecognizer::timeout() -{ - if ((orientationReading->orientation() == QOrientationReading::FaceUp) - && proximityReading) { - Q_EMIT cover(); - Q_EMIT detected("cover"); - detecting = false; - } -} - -QT_END_NAMESPACE diff --git a/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.h b/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.h deleted file mode 100644 index 2981fa1a..00000000 --- a/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.h +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - - -#ifndef QCOVERSENSORGESTURERECOGNIZER_H -#define QCOVERSENSORGESTURERECOGNIZER_H - -#include <QtSensors/qsensorgesturerecognizer.h> -#include <QTimer> - -#include "qtsensorgesturesensorhandler.h" - -QT_BEGIN_NAMESPACE - -class QCoverSensorGestureRecognizer : public QSensorGestureRecognizer -{ - Q_OBJECT -public: - explicit QCoverSensorGestureRecognizer(QObject *parent = 0); - ~QCoverSensorGestureRecognizer(); - - void create() override; - - QString id() const override; - bool start() override; - bool stop() override; - bool isActive() override; - -Q_SIGNALS: - void cover(); - -private slots: - void proximityChanged(QProximityReading *reading); - void orientationReadingChanged(QOrientationReading *reading); - void timeout(); - -private: - - QOrientationReading *orientationReading; - bool proximityReading; - - QTimer *timer; - bool active; - bool detecting; -}; - -QT_END_NAMESPACE -#endif // QCOVERSENSORGESTURERECOGNIZER_H diff --git a/src/plugins/sensorgestures/qtsensors/qdoubletapsensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qdoubletapsensorgesturerecognizer.cpp deleted file mode 100644 index 95d4de72..00000000 --- a/src/plugins/sensorgestures/qtsensors/qdoubletapsensorgesturerecognizer.cpp +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#include <QtSensors/QTapSensor> -#include "qdoubletapsensorgesturerecognizer.h" -QT_BEGIN_NAMESPACE - -QDoubleTapSensorGestureRecognizer::QDoubleTapSensorGestureRecognizer(QObject *parent) : - QSensorGestureRecognizer(parent) - , active(0) -{ -} - -QDoubleTapSensorGestureRecognizer::~QDoubleTapSensorGestureRecognizer() -{ -} - -void QDoubleTapSensorGestureRecognizer::create() -{ -} - - -QString QDoubleTapSensorGestureRecognizer::id() const -{ - return QString("QtSensors.doubletap"); -} - -bool QDoubleTapSensorGestureRecognizer::start() -{ - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Tap)) { - active = true; - connect(QtSensorGestureSensorHandler::instance(),SIGNAL(dTabReadingChanged(QTapReading*)), - this,SLOT(tapChanged(QTapReading*))); - } else { - active = false; - } - return active; -} - -bool QDoubleTapSensorGestureRecognizer::stop() -{ - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Tap); - disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(dTabReadingChanged(QTapReading*)), - this,SLOT(tapChanged(QTapReading*))); - active = false; - return active; -} - -bool QDoubleTapSensorGestureRecognizer::isActive() -{ - return active; -} - -void QDoubleTapSensorGestureRecognizer::tapChanged(QTapReading *reading) -{ - if (reading->isDoubleTap()) { - Q_EMIT doubletap(); - Q_EMIT detected("doubletap"); - } -} - - -QT_END_NAMESPACE diff --git a/src/plugins/sensorgestures/qtsensors/qdoubletapsensorgesturerecognizer.h b/src/plugins/sensorgestures/qtsensors/qdoubletapsensorgesturerecognizer.h deleted file mode 100644 index 9eb04b90..00000000 --- a/src/plugins/sensorgestures/qtsensors/qdoubletapsensorgesturerecognizer.h +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#ifndef QDOUBLETAPSENSORGESTURERECOGNIZER_H -#define QDOUBLETAPSENSORGESTURERECOGNIZER_H - -#include <QtSensors/QSensor> - -#include <QtSensors/qsensorgesturerecognizer.h> -#include <QtSensors/QTapSensor> - -#include "qtsensorgesturesensorhandler.h" - -QT_BEGIN_NAMESPACE - -class QDoubleTapSensorGestureRecognizer : public QSensorGestureRecognizer -{ - Q_OBJECT -public: - explicit QDoubleTapSensorGestureRecognizer(QObject *parent = 0); - ~QDoubleTapSensorGestureRecognizer(); - - void create() override; - - QString id() const override; - bool start() override; - bool stop() override; - bool isActive() override; - -Q_SIGNALS: - void doubletap(); - -private slots: - void tapChanged(QTapReading *reading); - -private: - QTapSensor *tapSensor; - bool active; - -}; -QT_END_NAMESPACE -#endif // QDOUBLETAPSENSORGESTURERECOGNIZER_H diff --git a/src/plugins/sensorgestures/qtsensors/qfreefallsensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qfreefallsensorgesturerecognizer.cpp deleted file mode 100644 index aaa2f4ce..00000000 --- a/src/plugins/sensorgestures/qtsensors/qfreefallsensorgesturerecognizer.cpp +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright (C) 2016 Lorn Potter -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only -#include <qmath.h> - -#include "qfreefallsensorgesturerecognizer.h" - -QT_BEGIN_NAMESPACE - -QFreefallSensorGestureRecognizer::QFreefallSensorGestureRecognizer(QObject *parent) - : QSensorGestureRecognizer(parent) - , active(0) - , detecting(0) -{ -} - -QFreefallSensorGestureRecognizer::~QFreefallSensorGestureRecognizer() -{ -} - -void QFreefallSensorGestureRecognizer::create() -{ -} - -QString QFreefallSensorGestureRecognizer::id() const -{ - return QString("QtSensors.freefall"); -} - -bool QFreefallSensorGestureRecognizer::start() -{ - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Accel)) { - active = true; - connect(QtSensorGestureSensorHandler::instance(),SIGNAL(accelReadingChanged(QAccelerometerReading*)), - this,SLOT(accelChanged(QAccelerometerReading*))); - } else { - active = false; - } - return active; - -} - -bool QFreefallSensorGestureRecognizer::stop() -{ - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Accel); - disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(accelReadingChanged(QAccelerometerReading*)), - this,SLOT(accelChanged(QAccelerometerReading*))); - active = false; - - return active; -} - -bool QFreefallSensorGestureRecognizer::isActive() -{ - return active; -} - -#define FREEFALL_THRESHOLD 1.0 -#define LANDED_THRESHOLD 20.0 -#define FREEFALL_MAX 4 - -void QFreefallSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) -{ - const qreal x = reading->x(); - const qreal y = reading->y(); - const qreal z = reading->z(); - qreal sum = qSqrt(x * x + y * y + z * z); - - if (qAbs(sum) < FREEFALL_THRESHOLD) { - detecting = true; - freefallList.append(sum); - } else { - if (detecting && qAbs(sum) > LANDED_THRESHOLD) { - Q_EMIT landed(); - Q_EMIT detected("landed"); - freefallList.clear(); - } - } - - if (freefallList.count() > FREEFALL_MAX) { - Q_EMIT freefall(); - Q_EMIT detected("freefall"); - } -} - - -QT_END_NAMESPACE - diff --git a/src/plugins/sensorgestures/qtsensors/qfreefallsensorgesturerecognizer.h b/src/plugins/sensorgestures/qtsensors/qfreefallsensorgesturerecognizer.h deleted file mode 100644 index 00da78f0..00000000 --- a/src/plugins/sensorgestures/qtsensors/qfreefallsensorgesturerecognizer.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (C) 2016 Lorn Potter -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - - - -#ifndef QFREEFALLSENSORGESTURERECOGNIZER_H -#define QFREEFALLSENSORGESTURERECOGNIZER_H - -#include <QtSensors/qsensorgesturerecognizer.h> - -#include "qtsensorgesturesensorhandler.h" - -QT_BEGIN_NAMESPACE - -class QFreefallSensorGestureRecognizer : public QSensorGestureRecognizer -{ - Q_OBJECT -public: - explicit QFreefallSensorGestureRecognizer(QObject *parent = 0); - ~QFreefallSensorGestureRecognizer(); - - void create() override; - - QString id() const override; - bool start() override; - bool stop() override; - bool isActive() override; - -Q_SIGNALS: - void freefall(); - void landed(); - -private slots: - void accelChanged(QAccelerometerReading *reading); - -private: - - bool active; - bool detecting; - QList <qreal> freefallList; - -}; -QT_END_NAMESPACE -#endif // QPICKUPSENSORGESTURERECOGNIZER_H diff --git a/src/plugins/sensorgestures/qtsensors/qhoversensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qhoversensorgesturerecognizer.cpp deleted file mode 100644 index bf26d219..00000000 --- a/src/plugins/sensorgestures/qtsensors/qhoversensorgesturerecognizer.cpp +++ /dev/null @@ -1,186 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - - -#include "qhoversensorgesturerecognizer.h" -#include <math.h> - -#define TIMER2_TIMEOUT 5000 - -QT_BEGIN_NAMESPACE - -QHoverSensorGestureRecognizer::QHoverSensorGestureRecognizer(QObject *parent) : - QSensorGestureRecognizer(parent), - orientationReading(0),reflectance(0), - hoverOk(0), detecting(0), active(0), initialReflectance(0), useHack(0), - lastTimestamp(0), timer2Active(0), lapsedTime2(0) -{ -} - -QHoverSensorGestureRecognizer::~QHoverSensorGestureRecognizer() -{ -} - -void QHoverSensorGestureRecognizer::create() -{ - -} - -QString QHoverSensorGestureRecognizer::id() const -{ - return QString("QtSensors.hover"); -} - -bool QHoverSensorGestureRecognizer::start() -{ - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::IrProximity)) { - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Orientation)) { - active = true; - connect(QtSensorGestureSensorHandler::instance(),SIGNAL(irProximityReadingChanged(QIRProximityReading*)), - this,SLOT(irProximityReadingChanged(QIRProximityReading*))); - connect(QtSensorGestureSensorHandler::instance(),SIGNAL(orientationReadingChanged(QOrientationReading*)), - this,SLOT(orientationReadingChanged(QOrientationReading*))); - } else { - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::IrProximity); - active = false; - } - } else { - active = false; - } - - detecting = false; - detectedHigh = 0; - initialReflectance = 0; - useHack = false; - timer2Active = false; - lapsedTime2 = 0; - return active; -} - -bool QHoverSensorGestureRecognizer::stop() -{ - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::IrProximity); - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Orientation); - disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(irProximityReadingChanged(QIRProximityReading*)), - this,SLOT(irProximityReadingChanged(QIRProximityReading*))); - disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(orientationReadingChanged(QOrientationReading*)), - this,SLOT(orientationReadingChanged(QOrientationReading*))); - active = false; - timer2Active = false; - initialReflectance = 0; - return active; -} - -bool QHoverSensorGestureRecognizer::isActive() -{ - return active; -} - - -void QHoverSensorGestureRecognizer::orientationReadingChanged(QOrientationReading *reading) -{ - orientationReading = reading; -} - -void QHoverSensorGestureRecognizer::irProximityReadingChanged(QIRProximityReading *reading) -{ - reflectance = reading->reflectance(); - if (reflectance == 0) - return; - - if (initialReflectance == 0) { - initialReflectance = reflectance; - } - - if (initialReflectance > .2) { - useHack = true; - initialReflectance -= .1; - } - if (useHack) - reflectance -= .1; - - if (detecting && !hoverOk) { - detectedHigh = qMax(detectedHigh, reflectance); - } - - if (reflectance > 0.4) { - // if close stop detecting - hoverOk = false; - detecting = false; - detectedHigh = 0; - } - - qreal detectedPercent = 100 - (detectedHigh / reflectance * 100); - - qint16 percentCheck; - if (useHack) - percentCheck = -60; - else - percentCheck = -101; - - quint64 timestamp = reading->timestamp(); - - if (!detecting - && checkForHovering()) { - detecting = true; - detecting = true; - timer2Active = true; - detectedHigh = reflectance; - } else if (detecting - && detectedPercent < percentCheck - && !checkForHovering()) { - // went light again after 1 seconds - Q_EMIT hover(); - Q_EMIT detected("hover"); - hoverOk = false; - detecting = false; - detectedHigh = 0; - timer2Active = false;; - } - if (detecting && reflectance < 0.2) { - timeout(); - } - if (timer2Active && lastTimestamp > 0) - lapsedTime2 += (timestamp - lastTimestamp )/1000; - - if (timer2Active && lapsedTime2 >= TIMER2_TIMEOUT) { - timeout2(); - } - - lastTimestamp = reading->timestamp(); -} - -bool QHoverSensorGestureRecognizer::checkForHovering() -{ - if (orientationReading == 0) { - return false; - } - if (orientationReading->orientation() != QOrientationReading::FaceUp) - return false; - if ( (reflectance > 0.2 && reflectance < 0.4) - && (initialReflectance - reflectance) < -0.1) - return true; - - return false; -} - - -void QHoverSensorGestureRecognizer::timeout() -{ - if (checkForHovering()) { - hoverOk = true; - timer2Active = true; - } else { - detecting = false; - detectedHigh = 0; - } -} - -void QHoverSensorGestureRecognizer::timeout2() -{ - detecting = false; - hoverOk = false; - detectedHigh = 0; -} - -QT_END_NAMESPACE diff --git a/src/plugins/sensorgestures/qtsensors/qhoversensorgesturerecognizer.h b/src/plugins/sensorgestures/qtsensors/qhoversensorgesturerecognizer.h deleted file mode 100644 index 1f5cfba0..00000000 --- a/src/plugins/sensorgestures/qtsensors/qhoversensorgesturerecognizer.h +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - - -#ifndef QHOVERSENSORGESTURERECOGNIZER_H -#define QHOVERSENSORGESTURERECOGNIZER_H - -#include <QtSensors/QSensorGestureRecognizer> - -#include "qtsensorgesturesensorhandler.h" - - -QT_BEGIN_NAMESPACE - -class QHoverSensorGestureRecognizer : public QSensorGestureRecognizer -{ - Q_OBJECT -public: - explicit QHoverSensorGestureRecognizer(QObject *parent = 0); - ~QHoverSensorGestureRecognizer(); - - void create() override; - - QString id() const override; - bool start() override; - bool stop() override; - bool isActive() override; - -Q_SIGNALS: - void hover(); - -private slots: - void orientationReadingChanged(QOrientationReading *reading); - void irProximityReadingChanged(QIRProximityReading *reading); - void timeout(); - void timeout2(); -private: - QOrientationReading *orientationReading; - qreal reflectance; - bool hoverOk; - bool detecting; - - qreal detectedHigh; - bool active; - qreal initialReflectance; - bool checkForHovering(); - bool useHack; - - quint64 lastTimestamp; - - bool timer2Active; - quint64 lapsedTime2; - -}; -QT_END_NAMESPACE -#endif // QHOVERSENSORGESTURERECOGNIZER_H diff --git a/src/plugins/sensorgestures/qtsensors/qpickupsensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qpickupsensorgesturerecognizer.cpp deleted file mode 100644 index 061110cd..00000000 --- a/src/plugins/sensorgestures/qtsensors/qpickupsensorgesturerecognizer.cpp +++ /dev/null @@ -1,177 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#include "qpickupsensorgesturerecognizer.h" - -#include <QtCore/qmath.h> - -#define TIMER_TIMEOUT 250 - -QT_BEGIN_NAMESPACE - -QPickupSensorGestureRecognizer::QPickupSensorGestureRecognizer(QObject *parent) - : QSensorGestureRecognizer(parent) - , accelReading(0) - , active(0) - , pXaxis(0) - , pYaxis(0) - , pZaxis(0) - , lastpitch(0) - , detecting(0) -{ -} - -QPickupSensorGestureRecognizer::~QPickupSensorGestureRecognizer() -{ -} - -void QPickupSensorGestureRecognizer::create() -{ -} - -QString QPickupSensorGestureRecognizer::id() const -{ - return QString("QtSensors.pickup"); -} - -bool QPickupSensorGestureRecognizer::start() -{ - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Accel)) { - active = true; - connect(QtSensorGestureSensorHandler::instance(),SIGNAL(accelReadingChanged(QAccelerometerReading*)), - this,SLOT(accelChanged(QAccelerometerReading*))); - } else { - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Accel); - active = false; - } - clear(); - - return active; - -} - -bool QPickupSensorGestureRecognizer::stop() -{ - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Accel); - disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(accelReadingChanged(QAccelerometerReading*)), - this,SLOT(accelChanged(QAccelerometerReading*))); - active = false; - - return active; -} - -bool QPickupSensorGestureRecognizer::isActive() -{ - return active; -} - -#define PICKUP_BOTTOM_THRESHOLD 25 -#define PICKUP_TOP_THRESHOLD 80 -#define PICKUP_ANGLE_THRESHOLD 25 -#define PICKUP_ROLL_THRESHOLD 13 - -void QPickupSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) -{ - accelReading = reading; - const qreal x = reading->x(); - const qreal y = reading->y(); - const qreal z = reading->z(); - const qreal xdiff = pXaxis - x; - const qreal ydiff = pYaxis - y; - const qreal zdiff = pZaxis - z; - - qreal pitch = qRadiansToDegrees(qAtan(y / qSqrt(x * x + z * z))); - qreal roll = qRadiansToDegrees(qAtan(x / qSqrt(y * y + z * z))); - - if ((qAbs(xdiff) < 0.7 && qAbs(ydiff) < .7 && qAbs(zdiff) < .7) - || z < 0) { - detecting = false; - } else if (pitch > PICKUP_BOTTOM_THRESHOLD && pitch < PICKUP_TOP_THRESHOLD) { - detecting = true; - } - - if ( pitchList.count() > 21) { - pitchList.removeFirst(); - } - if ( rollList.count() > 21) { - rollList.removeFirst(); - } - - if (pitch > 1) { - pitchList.append(pitch); - } - if (roll > 1) { - rollList.append(roll); - } - - if (detecting && pitchList.count() > 5 ) { - timeout(); - } - - lastpitch = pitch; - pXaxis = x; - pYaxis = y; - pZaxis = z; -} - -void QPickupSensorGestureRecognizer::timeout() -{ - qreal averageRoll = 0; - for (int r = 0; r < rollList.count(); r++) { - averageRoll += rollList.at(r); - } - averageRoll /= rollList.count(); - - if (averageRoll > PICKUP_ROLL_THRESHOLD) { - clear(); - return; - } - if (pitchList.isEmpty() - || pitchList.at(0) > PICKUP_BOTTOM_THRESHOLD) { - clear(); - return; - } - - qreal previousPitch = 0; - qreal startPitch = -1.0; - int goodCount = 0; - - qreal averagePitch = 0; - for (int i = 0; i < pitchList.count(); i++) { - averagePitch += pitchList.at(i); - if (previousPitch < pitchList.at(i) - && qAbs(pitchList.at(i)) - qAbs(previousPitch) < 20) { - if (goodCount == 1 && previousPitch != 0) { - startPitch = previousPitch; - } - goodCount++; - } - - previousPitch = pitchList.at(i); - } - averagePitch /= pitchList.count(); - - if (averagePitch < 5) { - clear(); - return; - } - - if (goodCount >= 3 && - (pitchList.last() < PICKUP_TOP_THRESHOLD - && pitchList.last() > PICKUP_BOTTOM_THRESHOLD) - && startPitch > 0 - && (pitchList.last() - startPitch) > PICKUP_ANGLE_THRESHOLD) { - Q_EMIT pickup(); - Q_EMIT detected("pickup"); - } - clear(); -} - -void QPickupSensorGestureRecognizer::clear() -{ - pitchList.clear(); - detecting = false; -} - -QT_END_NAMESPACE - diff --git a/src/plugins/sensorgestures/qtsensors/qpickupsensorgesturerecognizer.h b/src/plugins/sensorgestures/qtsensors/qpickupsensorgesturerecognizer.h deleted file mode 100644 index 7728185a..00000000 --- a/src/plugins/sensorgestures/qtsensors/qpickupsensorgesturerecognizer.h +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - - -#ifndef QPICKUPSENSORGESTURERECOGNIZER_H -#define QPICKUPSENSORGESTURERECOGNIZER_H - -#include <QtSensors/qsensorgesturerecognizer.h> -#include "qtsensorgesturesensorhandler.h" - -QT_BEGIN_NAMESPACE - -class QPickupSensorGestureRecognizer : public QSensorGestureRecognizer -{ - Q_OBJECT -public: - explicit QPickupSensorGestureRecognizer(QObject *parent = 0); - ~QPickupSensorGestureRecognizer(); - - void create() override; - - QString id() const override; - bool start() override; - bool stop() override; - bool isActive() override; - -Q_SIGNALS: - void pickup(); - -private slots: - void accelChanged(QAccelerometerReading *reading); - - void timeout(); -private: - QAccelerometerReading *accelReading; - - bool active; - qreal pXaxis; - qreal pYaxis; - qreal pZaxis; - - qreal lastpitch; - bool detecting; - - QList <qreal> pitchList; - QList <qreal> rollList; - - void clear(); -}; -QT_END_NAMESPACE -#endif // QPICKUPSENSORGESTURERECOGNIZER_H diff --git a/src/plugins/sensorgestures/qtsensors/qshake2recognizer.cpp b/src/plugins/sensorgestures/qtsensors/qshake2recognizer.cpp deleted file mode 100644 index 1a366308..00000000 --- a/src/plugins/sensorgestures/qtsensors/qshake2recognizer.cpp +++ /dev/null @@ -1,195 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#include <QDebug> - -#include "qshake2recognizer.h" -#include <math.h> - - -QT_BEGIN_NAMESPACE - -QShake2SensorGestureRecognizer::QShake2SensorGestureRecognizer(QObject *parent) - : QSensorGestureRecognizer(parent) - , active(0) - , shakeDirection(QShake2SensorGestureRecognizer::ShakeUndefined) - , shaking(0) - , shakeCount(0) - , lapsedTime(0) - , lastTimestamp(0), - timerActive(0) -{ - timerTimeout = 250; -} - -QShake2SensorGestureRecognizer::~QShake2SensorGestureRecognizer() -{ -} - -void QShake2SensorGestureRecognizer::create() -{ -} - -bool QShake2SensorGestureRecognizer::start() -{ - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Accel)) { - active = true; - connect(QtSensorGestureSensorHandler::instance(),SIGNAL(accelReadingChanged(QAccelerometerReading*)), - this,SLOT(accelChanged(QAccelerometerReading*))); - } else { - active = false; - } - prevData.x = 0; - prevData.y = 0; - prevData.z = 0; - shakeCount = 0; - shaking = false; - shakeDirection = QShake2SensorGestureRecognizer::ShakeUndefined; - - return active; -} - -bool QShake2SensorGestureRecognizer::stop() -{ - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Accel); - disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(accelReadingChanged(QAccelerometerReading*)), - this,SLOT(accelChanged(QAccelerometerReading*))); - active = false; - return active; -} - -bool QShake2SensorGestureRecognizer::isActive() -{ - return active; -} - -QString QShake2SensorGestureRecognizer::id() const -{ - return QString("QtSensors.shake2"); -} - -#define NUMBER_SHAKES 3 -#define THRESHOLD 25 - -void QShake2SensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) -{ - const qreal x = reading->x(); - const qreal y = reading->y(); - const qreal z = reading->z(); - - const quint64 timestamp = reading->timestamp(); - - currentData.x = x; - currentData.y = y; - currentData.z = z; - - if (qAbs(prevData.x - currentData.x) < 1 - && qAbs(prevData.y - currentData.y) < 1 - && qAbs(prevData.z - currentData.z) < 1) { - - prevData.x = currentData.x; - prevData.y = currentData.y; - prevData.z = currentData.z; - return; - } - - bool wasShake; - wasShake = checkForShake(prevData, currentData, THRESHOLD); - - if (!shaking && wasShake && - shakeCount == NUMBER_SHAKES) { - shaking = true; - shakeCount = 0; - lapsedTime = 0; - timerActive = false; - switch (shakeDirection) { - case QShake2SensorGestureRecognizer::ShakeLeft: - Q_EMIT shakeLeft(); - Q_EMIT detected("shakeLeft"); - break; - case QShake2SensorGestureRecognizer::ShakeRight: - Q_EMIT shakeRight(); - Q_EMIT detected("shakeRight"); - break; - case QShake2SensorGestureRecognizer::ShakeUp: - Q_EMIT shakeUp(); - Q_EMIT detected("shakeUp"); - break; - case QShake2SensorGestureRecognizer::ShakeDown: - Q_EMIT shakeDown(); - Q_EMIT detected("shakeDown"); - break; - default: - break; - }; - - } else if (wasShake) { - - if (shakeCount == 0 && shakeDirection == QShake2SensorGestureRecognizer::ShakeUndefined) { - - const int xdiff = prevData.x - currentData.x; - const int ydiff = prevData.x - currentData.y; - - const int max = qMax(qAbs(ydiff), qAbs(xdiff)); - if (max == qAbs(xdiff)) { - if (isNegative(xdiff)) - shakeDirection = QShake2SensorGestureRecognizer::ShakeLeft; - else - shakeDirection = QShake2SensorGestureRecognizer::ShakeRight; - - } else if (max == qAbs(ydiff)) { - if (isNegative(ydiff)) - shakeDirection = QShake2SensorGestureRecognizer::ShakeDown; - else - shakeDirection = QShake2SensorGestureRecognizer::ShakeUp; - } - } - shakeCount++; - if (shakeCount == NUMBER_SHAKES) { - timerActive = true; - } - } - - if (timerActive && lastTimestamp > 0) - lapsedTime += (timestamp - lastTimestamp )/1000; - - if (timerActive && lapsedTime >= timerTimeout) { - timeout(); - } - prevData.x = currentData.x; - prevData.y = currentData.y; - prevData.z = currentData.z; - lastTimestamp = timestamp; -} - -void QShake2SensorGestureRecognizer::timeout() -{ - shakeCount = 0; - shaking = false; - shakeDirection = QShake2SensorGestureRecognizer::ShakeUndefined; - timerActive = false; - lapsedTime = 0; - lastTimestamp = 0; -} - -bool QShake2SensorGestureRecognizer::checkForShake(ShakeData prevSensorData, ShakeData currentSensorData, qreal threshold) -{ - const double deltaX = qAbs(prevSensorData.x - currentSensorData.x); - const double deltaY = qAbs(prevSensorData.y - currentSensorData.y); - const double deltaZ = qAbs(prevSensorData.z - currentSensorData.z); - - return (deltaX > threshold - || deltaY > threshold - || deltaZ > threshold); -} - -bool QShake2SensorGestureRecognizer::isNegative(qreal num) -{ - if (num < 0) - return true; - return false; -} - - - -QT_END_NAMESPACE diff --git a/src/plugins/sensorgestures/qtsensors/qshake2recognizer.h b/src/plugins/sensorgestures/qtsensors/qshake2recognizer.h deleted file mode 100644 index 2fbcb230..00000000 --- a/src/plugins/sensorgestures/qtsensors/qshake2recognizer.h +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#ifndef QSHAKERECOGNIZER_H -#define QSHAKERECOGNIZER_H - -#include <QDebug> - -#include <QtSensors/qsensorgesturerecognizer.h> - -#include "qtsensorgesturesensorhandler.h" - -QT_BEGIN_NAMESPACE - -struct ShakeData { - qreal x; - qreal y; - qreal z; -}; - -class QShake2SensorGestureRecognizer : public QSensorGestureRecognizer -{ - Q_OBJECT - -public: - - enum ShakeDirection { - ShakeUndefined = 0, - ShakeLeft, - ShakeRight, - ShakeUp, - ShakeDown - }; - - QShake2SensorGestureRecognizer(QObject *parent = 0); - ~QShake2SensorGestureRecognizer(); - - void create() override; - - QString id() const override; - bool start() override; - bool stop() override; - bool isActive() override; - - int timerTimeout; - - -Q_SIGNALS: - void shakeLeft(); - void shakeRight(); - void shakeUp(); - void shakeDown(); - -private slots: - void accelChanged(QAccelerometerReading *reading); - void timeout(); - - -private: - QAccelerometerReading *accelReading; - - bool active; - - ShakeDirection shakeDirection; - - ShakeData prevData; - ShakeData currentData; - - bool checkForShake(ShakeData prevSensorData, ShakeData currentSensorData, qreal threshold); - bool shaking; - int shakeCount; - int threshold; - - bool isNegative(qreal num); - qreal lapsedTime; - quint64 lastTimestamp; - bool timerActive; -}; -QT_END_NAMESPACE -#endif // QSHAKERECOGNIZER_H diff --git a/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp deleted file mode 100644 index 4cc6c7e4..00000000 --- a/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#include "qslamgesturerecognizer.h" -#include "qtsensorgesturesensorhandler.h" - - -#include <QtCore/qmath.h> - -QT_BEGIN_NAMESPACE - -QSlamSensorGestureRecognizer::QSlamSensorGestureRecognizer(QObject *parent) : - QSensorGestureRecognizer(parent), - orientationReading(0), - accelRange(0), - active(0), - lastX(0), - lastY(0), - lastZ(0), - detectedX(0), - detecting(0), - accelX(0), - roll(0), - resting(0), - lastTimestamp(0), - lapsedTime(0), - timerActive(0) -{ -} - -QSlamSensorGestureRecognizer::~QSlamSensorGestureRecognizer() -{ -} - -void QSlamSensorGestureRecognizer::create() -{ -} - - -QString QSlamSensorGestureRecognizer::id() const -{ - return QString("QtSensors.slam"); -} - -bool QSlamSensorGestureRecognizer::start() -{ - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Accel)) { - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Orientation)) { - active = true; - accelRange = QtSensorGestureSensorHandler::instance()->accelRange; - connect(QtSensorGestureSensorHandler::instance(),SIGNAL(orientationReadingChanged(QOrientationReading*)), - this,SLOT(orientationReadingChanged(QOrientationReading*))); - - connect(QtSensorGestureSensorHandler::instance(),SIGNAL(accelReadingChanged(QAccelerometerReading*)), - this,SLOT(accelChanged(QAccelerometerReading*))); - } else { - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Accel); - active = false; - } - } else { - active = false; - } - return active; -} - -bool QSlamSensorGestureRecognizer::stop() -{ - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Accel); - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Orientation); - disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(orientationReadingChanged(QOrientationReading*)), - this,SLOT(orientationReadingChanged(QOrientationReading*))); - - disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(accelReadingChanged(QAccelerometerReading*)), - this,SLOT(accelChanged(QAccelerometerReading*))); - detecting = false; - restingList.clear(); - active = false; - return active; -} - -bool QSlamSensorGestureRecognizer::isActive() -{ - return active; -} - -void QSlamSensorGestureRecognizer::orientationReadingChanged(QOrientationReading *reading) -{ - orientationReading = reading; -} - -#define SLAM_DETECTION_FACTOR 0.3 // 11.7 -#define SLAM_RESTING_FACTOR 2.5 -#define SLAM_RESTING_COUNT 5 -#define SLAM_ZERO_FACTOR .02 - -void QSlamSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) -{ - const qreal x = reading->x(); - const qreal y = reading->y(); - const qreal z = reading->z(); - quint64 timestamp = reading->timestamp(); - - if (qAbs(lastX - x) < SLAM_RESTING_FACTOR - && qAbs(lastY - y) < SLAM_RESTING_FACTOR - && qAbs(lastZ - z) < SLAM_RESTING_FACTOR) { - resting = true; - } else { - resting = false; - } - - if (restingList.count() > SLAM_RESTING_COUNT) - restingList.removeLast(); - restingList.insert(0, resting); - - - if (timerActive && lastTimestamp > 0) - lapsedTime += (timestamp - lastTimestamp )/1000; - - if (timerActive && lapsedTime >= 250) { - doSlam(); - } - lastTimestamp = timestamp; - - if (orientationReading == 0) { - return; - } - - const qreal difference = lastX - x; - - if (!detecting - && orientationReading->orientation() == QOrientationReading::TopUp - && resting - && hasBeenResting()) { - detectedX = x; - // start of gesture - detecting = true; - if (difference > 0) - wasNegative = false; - else - wasNegative = true; - restingList.clear(); - } - if (detecting - && qAbs(difference) > (accelRange * SLAM_DETECTION_FACTOR)) { - timerActive = true; - } - if (detecting && - (qAbs(difference) < SLAM_ZERO_FACTOR && qAbs(difference) > 0)) { - detecting = false; - } - lastX = x; - lastY = y; - lastZ = z; -} - -bool QSlamSensorGestureRecognizer::hasBeenResting() -{ - for (int i = 0; i < restingList.count() - 1; i++) { - if (!restingList.at(i)) { - return false; - } - } - return true; -} - -void QSlamSensorGestureRecognizer::doSlam() -{ - if (detecting && (orientationReading->orientation() == QOrientationReading::RightUp - || orientationReading->orientation() == QOrientationReading::LeftUp)) { - Q_EMIT slam(); - Q_EMIT detected("slam"); - restingList.clear(); - detecting = false; - } - timerActive = false; - lapsedTime = 0; -} - -QT_END_NAMESPACE diff --git a/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.h b/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.h deleted file mode 100644 index dbc263e5..00000000 --- a/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.h +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - - -#ifndef QSLAMSENSORGESTURERECOGNIZER_H -#define QSLAMSENSORGESTURERECOGNIZER_H - -#include <QtSensors/qsensorgesturerecognizer.h> -#include <QtSensors/QOrientationSensor> -#include <QtSensors/QAccelerometer> -#include <QtSensors/QAccelerometerReading> -#include <QtSensors/QOrientationReading> -QT_BEGIN_NAMESPACE - -class QSlamSensorGestureRecognizer : public QSensorGestureRecognizer -{ - Q_OBJECT -public: - explicit QSlamSensorGestureRecognizer(QObject *parent = 0); - ~QSlamSensorGestureRecognizer(); - - void create() override; - - QString id() const override; - bool start() override; - bool stop() override; - bool isActive() override; - -Q_SIGNALS: - void slam(); - -private slots: - void accelChanged(QAccelerometerReading *reading); - void orientationReadingChanged(QOrientationReading *reading); - void doSlam(); - -private: - - QAccelerometer *accel; - QOrientationReading *orientationReading; - int accelRange; - bool active; - - bool wasNegative; - qreal lastX; - qreal lastY; - qreal lastZ; - qreal detectedX; - - bool detecting; - - qreal accelX; - qreal roll; - QList<qreal> restingList; - bool resting; - - bool hasBeenResting(); - quint64 lastTimestamp; - quint64 lapsedTime; - bool timerActive; -}; - -QT_END_NAMESPACE -#endif // QSLAMSENSORGESTURERECOGNIZER_H diff --git a/src/plugins/sensorgestures/qtsensors/qtsensorgestureplugin.cpp b/src/plugins/sensorgestures/qtsensors/qtsensorgestureplugin.cpp deleted file mode 100644 index ea642383..00000000 --- a/src/plugins/sensorgestures/qtsensors/qtsensorgestureplugin.cpp +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#include <QtPlugin> -#include <QStringList> -#include <QObject> - -#include "qtsensorgestureplugin.h" - -#include <QtSensors/qsensorgestureplugininterface.h> - -#include "qcoversensorgesturerecognizer.h" -#include "qtwistsensorgesturerecognizer.h" -#include "qdoubletapsensorgesturerecognizer.h" -#include "qhoversensorgesturerecognizer.h" -#include "qpickupsensorgesturerecognizer.h" -#include "qshake2recognizer.h" -#include "qslamgesturerecognizer.h" -#include "qturnoversensorgesturerecognizer.h" -#include "qwhipsensorgesturerecognizer.h" -#include "qfreefallsensorgesturerecognizer.h" - - -QT_BEGIN_NAMESPACE - - -QtSensorGesturePlugin::QtSensorGesturePlugin() -{ -} - -QtSensorGesturePlugin::~QtSensorGesturePlugin() -{ -} - -QStringList QtSensorGesturePlugin::supportedIds() const -{ - QStringList list; - list << "QtSensors.cover"; - list << "QtSensors.doubletap"; - list << "QtSensors.hover"; - list << "QtSensors.freefall"; - list << "QtSensors.pickup"; - list << "QtSensors.shake2"; - list << "QtSensors.slam"; - list << "QtSensors.turnover"; - list << "QtSensors.twist"; - list << "QtSensors.whip"; - return list; -} - -QList <QSensorGestureRecognizer *> QtSensorGesturePlugin::createRecognizers() -{ - QList <QSensorGestureRecognizer *> recognizers; - - recognizers.append(new QCoverSensorGestureRecognizer(this)); - - recognizers.append(new QDoubleTapSensorGestureRecognizer(this)); - - recognizers.append(new QHoverSensorGestureRecognizer(this)); - - recognizers.append(new QPickupSensorGestureRecognizer(this)); - - recognizers.append(new QShake2SensorGestureRecognizer(this)); - - recognizers.append(new QSlamSensorGestureRecognizer(this)); - - recognizers.append(new QTurnoverSensorGestureRecognizer(this)); - - recognizers.append(new QWhipSensorGestureRecognizer(this)); - - recognizers.append(new QTwistSensorGestureRecognizer(this)); - - recognizers.append(new QFreefallSensorGestureRecognizer(this)); - return recognizers; -} - -QT_END_NAMESPACE diff --git a/src/plugins/sensorgestures/qtsensors/qtsensorgestureplugin.h b/src/plugins/sensorgestures/qtsensors/qtsensorgestureplugin.h deleted file mode 100644 index 4f7bdd66..00000000 --- a/src/plugins/sensorgestures/qtsensors/qtsensorgestureplugin.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#ifndef QTSENSORGESTURESPLUGIN_H -#define QTSENSORGESTURESPLUGIN_H - -#include <QObject> -#include <QStringList> - -#include <QtSensors/qsensorgestureplugininterface.h> - -QT_BEGIN_NAMESPACE - -class QtSensorGesturePlugin : public QObject, public QSensorGesturePluginInterface -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID "org.qt-project.QSensorGesturePluginInterface") - Q_INTERFACES(QSensorGesturePluginInterface) - -public: - explicit QtSensorGesturePlugin(); - ~QtSensorGesturePlugin(); - QList <QSensorGestureRecognizer *> createRecognizers() override; - - QStringList gestureSignals() const; - QStringList supportedIds() const override; - QString name() const override { return "QtSensorGestures"; } - -}; - -QT_END_NAMESPACE -#endif // QTSENSORGESTURESPLUGIN_H diff --git a/src/plugins/sensorgestures/qtsensors/qtsensorgesturesensorhandler.cpp b/src/plugins/sensorgestures/qtsensors/qtsensorgesturesensorhandler.cpp deleted file mode 100644 index 83fbba5f..00000000 --- a/src/plugins/sensorgestures/qtsensors/qtsensorgesturesensorhandler.cpp +++ /dev/null @@ -1,157 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#include <QDebug> - -#include "qtsensorgesturesensorhandler.h" - -QtSensorGestureSensorHandler::QtSensorGestureSensorHandler(QObject *parent) : - QObject(parent), - accel(0), orientation(0), proximity(0), irProx(0),tapSensor(0) -{ -} - -QtSensorGestureSensorHandler* QtSensorGestureSensorHandler::instance() -{ - static QtSensorGestureSensorHandler *instance = 0; - if (!instance) { - instance = new QtSensorGestureSensorHandler; - } - return instance; -} - -void QtSensorGestureSensorHandler::accelChanged() -{ - Q_EMIT accelReadingChanged(accel->reading()); -} - -void QtSensorGestureSensorHandler::orientationChanged() -{ - Q_EMIT orientationReadingChanged(orientation->reading()); -} - -void QtSensorGestureSensorHandler::proximityChanged() -{ - Q_EMIT proximityReadingChanged(proximity->reading()); -} - -void QtSensorGestureSensorHandler::irProximityChanged() -{ - Q_EMIT irProximityReadingChanged(irProx->reading()); -} - -void QtSensorGestureSensorHandler::doubletap() -{ - Q_EMIT dTabReadingChanged(tapSensor->reading()); -} - -bool QtSensorGestureSensorHandler::startSensor(SensorGestureSensors sensor) -{ - bool ok = true; - switch (sensor) { - case Accel: - //accel - if (accel == 0x0) { - accel = new QAccelerometer(this); - ok = accel->connectToBackend(); - accel->setDataRate(100); - qoutputrangelist outputranges = accel->outputRanges(); - - if (outputranges.count() > 0) - accelRange = (int)(outputranges.at(0).maximum);//39 - else - accelRange = 39; //this should never happen - connect(accel,SIGNAL(readingChanged()),this,SLOT(accelChanged())); - } - if (ok && !accel->isActive()) - accel->start(); - break; - case Orientation: - //orientation - if (orientation == 0x0) { - orientation = new QOrientationSensor(this); - ok = orientation->connectToBackend(); - orientation->setDataRate(50); - connect(orientation,SIGNAL(readingChanged()),this,SLOT(orientationChanged())); - } - if (ok && !orientation->isActive()) - orientation->start(); - break; - case Proximity: - //proximity - if (proximity == 0x0) { - proximity = new QProximitySensor(this); - ok = proximity->connectToBackend(); - connect(proximity,SIGNAL(readingChanged()),this,SLOT(proximityChanged())); - } - if (ok && !proximity->isActive()) - proximity->start(); - break; - case IrProximity: - //irproximity - if (irProx == 0x0) { - irProx = new QIRProximitySensor(this); - irProx->setDataRate(50); - ok = irProx->connectToBackend(); - connect(irProx,SIGNAL(readingChanged()),this,SLOT(irProximityChanged())); - } - if (ok && !irProx->isActive()) - irProx->start(); - break; - case Tap: - //dtap - if (tapSensor == 0x0) { - tapSensor = new QTapSensor(this); - ok = tapSensor->connectToBackend(); - connect(tapSensor,SIGNAL(readingChanged()),this,SLOT(doubletap())); - } - if (ok && !tapSensor->isActive()) - tapSensor->start(); - break; - }; - int val = usedSensorsMap.value(sensor); - usedSensorsMap.insert(sensor,++val); - - return ok; -} - -void QtSensorGestureSensorHandler::stopSensor(SensorGestureSensors sensor) -{ - // qDebug() << __FUNCTION__ << sensor; - if (usedSensorsMap.value(sensor) == 0) - return; - int val = usedSensorsMap.value(sensor); - usedSensorsMap.insert(sensor,--val); - switch (sensor) { - case Accel: - //accel - if (usedSensorsMap.value(sensor) == 0) { - accel->stop(); - } - break; - case Orientation: - if (usedSensorsMap.value(sensor) == 0) { - orientation->stop(); - } - //orientation - break; - case Proximity: - if (usedSensorsMap.value(sensor) == 0) { - proximity->stop(); - } - //proximity - break; - case IrProximity: - if (usedSensorsMap.value(sensor) == 0) { - irProx->stop(); - } - //irproximity - break; - case Tap: - if (usedSensorsMap.value(sensor) == 0) { - tapSensor->stop(); - } - //dtap - break; - }; -} diff --git a/src/plugins/sensorgestures/qtsensors/qtsensorgesturesensorhandler.h b/src/plugins/sensorgestures/qtsensors/qtsensorgesturesensorhandler.h deleted file mode 100644 index 0090e3d6..00000000 --- a/src/plugins/sensorgestures/qtsensors/qtsensorgesturesensorhandler.h +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#ifndef QTSENSORGESTURESENSORHANDLER_H -#define QTSENSORGESTURESENSORHANDLER_H - -#include <QObject> - -#include <QtSensors/QAccelerometer> -#include <QtSensors/QAccelerometerFilter> -#include <QtSensors/QSensor> -#include <QtSensors/QOrientationSensor> -#include <QtSensors/QProximitySensor> -#include <QtSensors/QIRProximitySensor> -#include <QtSensors/QTapSensor> - -class QtSensorGestureSensorHandler : public QObject -{ - Q_OBJECT -public: - explicit QtSensorGestureSensorHandler(QObject *parent = 0); - - enum SensorGestureSensors { - Accel = 0, - Orientation, - Proximity, - IrProximity, - Tap - }; - Q_ENUM(SensorGestureSensors) - static QtSensorGestureSensorHandler *instance(); - qreal accelRange; - -public slots: - void accelChanged(); - void orientationChanged(); - void proximityChanged(); - void irProximityChanged(); - void doubletap(); - - bool startSensor(SensorGestureSensors sensor); - void stopSensor(SensorGestureSensors sensor); - -Q_SIGNALS: - void accelReadingChanged(QAccelerometerReading *reading); - void orientationReadingChanged(QOrientationReading *reading); - void proximityReadingChanged(QProximityReading *reading); - void irProximityReadingChanged(QIRProximityReading *reading); - void dTabReadingChanged(QTapReading *reading); - -private: - QAccelerometer *accel; - QOrientationSensor *orientation; - QProximitySensor *proximity; - QIRProximitySensor *irProx; - QTapSensor *tapSensor; - - QMap<SensorGestureSensors, int> usedSensorsMap; - -}; - -#endif // QTSENSORGESTURESENSORHANDLER_H diff --git a/src/plugins/sensorgestures/qtsensors/qturnoversensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qturnoversensorgesturerecognizer.cpp deleted file mode 100644 index 15dfc837..00000000 --- a/src/plugins/sensorgestures/qtsensors/qturnoversensorgesturerecognizer.cpp +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#include <QtSensors/QSensor> - -#include "qturnoversensorgesturerecognizer.h" -#include "qtsensorgesturesensorhandler.h" - -QT_BEGIN_NAMESPACE - -// turnover and put down i.e. facedown - -QTurnoverSensorGestureRecognizer::QTurnoverSensorGestureRecognizer(QObject *parent) : - QSensorGestureRecognizer(parent), - isClose(0) - , isFaceDown(0), active(0) -{ -} - -QTurnoverSensorGestureRecognizer::~QTurnoverSensorGestureRecognizer() -{ -} - -void QTurnoverSensorGestureRecognizer::create() -{ -} - -bool QTurnoverSensorGestureRecognizer::start() -{ - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Proximity)) { - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Orientation)) { - active = true; - connect(QtSensorGestureSensorHandler::instance(),SIGNAL(proximityReadingChanged(QProximityReading*)), - this,SLOT(proximityChanged(QProximityReading*))); - - connect(QtSensorGestureSensorHandler::instance(),SIGNAL(orientationReadingChanged(QOrientationReading*)), - this,SLOT(orientationReadingChanged(QOrientationReading*))); - } else { - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Proximity); - active = false; - } - } else { - active = false; - } - return active; -} - -bool QTurnoverSensorGestureRecognizer::stop() -{ - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Proximity); - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Orientation); - - disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(proximityReadingChanged(QProximityReading*)), - this,SLOT(proximityChanged(QProximityReading*))); - disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(orientationReadingChanged(QOrientationReading*)), - this,SLOT(orientationReadingChanged(QOrientationReading*))); - - active = false; - - return active; -} - -bool QTurnoverSensorGestureRecognizer::isActive() -{ - return active; -} - -QString QTurnoverSensorGestureRecognizer::id() const -{ - return QString("QtSensors.turnover"); -} - -void QTurnoverSensorGestureRecognizer::proximityChanged(QProximityReading *reading) -{ - isClose = reading->close(); - if (isClose) - isRecognized(); -} - -void QTurnoverSensorGestureRecognizer::orientationReadingChanged(QOrientationReading *reading) -{ - switch (reading->orientation()) { - case QOrientationReading::FaceDown: - { - isFaceDown = true; - isRecognized(); - } - break; - default: - isFaceDown = false; - break; - }; -} - -void QTurnoverSensorGestureRecognizer::isRecognized() -{ - if (isClose && isFaceDown) { - Q_EMIT turnover(); - Q_EMIT detected("turnover"); - } -} -QT_END_NAMESPACE - diff --git a/src/plugins/sensorgestures/qtsensors/qturnoversensorgesturerecognizer.h b/src/plugins/sensorgestures/qtsensors/qturnoversensorgesturerecognizer.h deleted file mode 100644 index f5770dfd..00000000 --- a/src/plugins/sensorgestures/qtsensors/qturnoversensorgesturerecognizer.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#ifndef QTURNOVERSENSORGESTURERECOGNIZER_H -#define QTURNOVERSENSORGESTURERECOGNIZER_H - -#include <QtSensors/qsensorgesturerecognizer.h> -#include "qtsensorgesturesensorhandler.h" - -QT_BEGIN_NAMESPACE - -class QTurnoverSensorGestureRecognizer : public QSensorGestureRecognizer -{ - Q_OBJECT -public: - explicit QTurnoverSensorGestureRecognizer(QObject *parent = 0); - ~QTurnoverSensorGestureRecognizer(); - - void create() override; - - QString id() const override; - bool start() override; - bool stop() override; - bool isActive() override; - -Q_SIGNALS: - void turnover(); - -private slots: - void orientationReadingChanged(QOrientationReading *reading); - void proximityChanged(QProximityReading *reading); - void isRecognized(); - -private: - - bool isClose; - bool isFaceDown; - bool active; - - QList<qreal> zList; - -}; -QT_END_NAMESPACE -#endif // QTURNOVERSENSORGESTURERECOGNIZER_H diff --git a/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.cpp deleted file mode 100644 index 5ac06724..00000000 --- a/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.cpp +++ /dev/null @@ -1,255 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - - -#include "qtwistsensorgesturerecognizer.h" - -#include <QtCore/qmath.h> - -QT_BEGIN_NAMESPACE - -#define TIMER_TIMEOUT 750 -QTwistSensorGestureRecognizer::QTwistSensorGestureRecognizer(QObject *parent) - : QSensorGestureRecognizer(parent) - , orientationReading(0) - , active(0) - , detecting(0) - , checking(0) - , increaseCount(0) - , decreaseCount(0) - , lastAngle(0) - , detectedAngle(0) -{ -} - -QTwistSensorGestureRecognizer::~QTwistSensorGestureRecognizer() -{ -} - -void QTwistSensorGestureRecognizer::create() -{ -} - -QString QTwistSensorGestureRecognizer::id() const -{ - return QString("QtSensors.twist"); -} - -bool QTwistSensorGestureRecognizer::start() -{ - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Accel)) { - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Orientation)) { - active = true; - connect(QtSensorGestureSensorHandler::instance(),SIGNAL(orientationReadingChanged(QOrientationReading*)), - this,SLOT(orientationReadingChanged(QOrientationReading*))); - - connect(QtSensorGestureSensorHandler::instance(),SIGNAL(accelReadingChanged(QAccelerometerReading*)), - this,SLOT(accelChanged(QAccelerometerReading*))); - } else { - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Accel); - active = false; - } - } else { - - active = false; - } - - return active; -} - -bool QTwistSensorGestureRecognizer::stop() -{ - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Accel); - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Orientation); - disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(orientationReadingChanged(QOrientationReading*)), - this,SLOT(orientationReadingChanged(QOrientationReading*))); - - disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(accelReadingChanged(QAccelerometerReading*)), - this,SLOT(accelChanged(QAccelerometerReading*))); - - reset(); - orientationList.clear(); - active = false; - return active; -} - -bool QTwistSensorGestureRecognizer::isActive() -{ - return active; -} - -void QTwistSensorGestureRecognizer::orientationReadingChanged(QOrientationReading *reading) -{ - orientationReading = reading; - if (orientationList.count() == 3) - orientationList.removeFirst(); - - orientationList.append(reading->orientation()); - - if (orientationList.count() == 3 - && orientationList.at(2) == QOrientationReading::FaceUp - && (orientationList.at(1) == QOrientationReading::RightUp - || orientationList.at(1) == QOrientationReading::LeftUp)) { - checkTwist(); - } - - checkOrientation(); -} - -bool QTwistSensorGestureRecognizer::checkOrientation() -{ - if (orientationReading->orientation() == QOrientationReading::TopDown - || orientationReading->orientation() == QOrientationReading::FaceDown) { - reset(); - return false; - } - return true; -} - -void QTwistSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) -{ - if (orientationReading == 0) - return; - - const qreal x = reading->x(); - const qreal y = reading->y(); - const qreal z = reading->z(); - - if (!detecting && !checking&& dataList.count() > 21) - dataList.removeFirst(); - - qreal angle = qRadiansToDegrees(qAtan(x / qSqrt(y * y + z * z))); - - if (qAbs(angle) > 2) { - if (detecting) { - if ((angle > 0 && angle < lastAngle) - || (angle < 0 && angle > lastAngle)) { - decreaseCount++; - } else { - if (decreaseCount > 0) - decreaseCount--; - } - } - - if (!detecting && ((angle > 0 && angle > lastAngle) - || (angle < 0 && angle < lastAngle)) - && ((angle > 0 && lastAngle > 0) - || (angle < 0 && lastAngle < 0))) { - increaseCount++; - } else - if (!detecting && increaseCount > 3 && qAbs(angle) > 30) { - decreaseCount = 0; - detecting = true; - detectedAngle = qRadiansToDegrees(qAtan(y / qSqrt(x * x + z * z))); - } - } else { - increaseCount = 0; - increaseCount = 0; - } - - lastAngle = angle; - if (detecting && decreaseCount >= 4 && qAbs(angle) < 25) { - checkTwist(); - } - - twistAccelData data; - data.x = x; - data.y = y; - data.z = z; - - if (qAbs(x) > 1) - dataList.append(data); - - if (qAbs(z) > 15.0) { - reset(); - } - -} - -void QTwistSensorGestureRecognizer::checkTwist() -{ - checking = true; - int lastx = 0; - bool ok = false; - bool spinpoint = false; - - if (detectedAngle < 0) { - reset(); - return; - } - - //// check for orientation changes first - if (orientationList.count() < 2) - return; - - if (orientationList.count() > 2) - if (orientationList.at(0) == orientationList.at(2) - && (orientationList.at(1) == QOrientationReading::LeftUp - || orientationList.at(1) == QOrientationReading::RightUp)) { - ok = true; - if (orientationList.at(1) == QOrientationReading::RightUp) - detectedAngle = 1; - else - detectedAngle = -1; - } - - // now the manual increase/decrease count - if (!ok) { - if (increaseCount < 1 || decreaseCount < 3) - return; - - if (increaseCount > 6 && decreaseCount > 4) { - ok = true; - if (orientationList.at(1) == QOrientationReading::RightUp) - detectedAngle = 1; - else - detectedAngle = -1; - } - } - // now we're really grasping for anything - if (!ok) - for (int i = 0; i < dataList.count(); i++) { - twistAccelData curData = dataList.at(i); - if (!spinpoint && qAbs(curData.x) < 1) - continue; - if (curData.z >= 0 ) { - if (!spinpoint && (curData.x > lastx || curData.x < lastx) && curData.x - lastx > 1) { - ok = true; - } else if (spinpoint && (curData.x < lastx || curData.x > lastx)&& lastx - curData.x > 1) { - ok = true; - } else { - ok = false; - } - } else if (!spinpoint && curData.z < 0) { - spinpoint = true; - } else if (spinpoint && curData.z > 9) { - break; - } - - lastx = curData.x; - } - if (ok) { - if (detectedAngle > 0) { - Q_EMIT twistLeft(); - Q_EMIT detected("twistLeft"); - } else { - Q_EMIT twistRight(); - Q_EMIT detected("twistRight"); - } - } - reset(); -} - -void QTwistSensorGestureRecognizer::reset() -{ - detecting = false; - checking = false; - dataList.clear(); - increaseCount = 0; - decreaseCount = 0; - lastAngle = 0; -} - - - -QT_END_NAMESPACE diff --git a/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.h b/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.h deleted file mode 100644 index 6db83ba2..00000000 --- a/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.h +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - - -#ifndef QWFLICKSENSORGESTURERECOGNIZER_H -#define QWFLICKSENSORGESTURERECOGNIZER_H - -#include <QtSensors/qsensorgesturerecognizer.h> -#include <QtSensors/QAccelerometer> -#include <QtSensors/QOrientationSensor> -#include "qtsensorgesturesensorhandler.h" - -QT_BEGIN_NAMESPACE - -struct twistAccelData { - qreal x; - qreal y; - qreal z; -}; - -class QTwistSensorGestureRecognizer : public QSensorGestureRecognizer -{ - Q_OBJECT -public: - explicit QTwistSensorGestureRecognizer(QObject *parent = 0); - ~QTwistSensorGestureRecognizer(); - - void create() override; - - QString id() const override; - bool start() override; - bool stop() override; - bool isActive() override; - -Q_SIGNALS: - void twistLeft(); - void twistRight(); - -private slots: - void accelChanged(QAccelerometerReading *reading); - void orientationReadingChanged(QOrientationReading *reading); - void checkTwist(); - -private: - - QOrientationReading *orientationReading; - bool active; - bool detecting; - QList <twistAccelData> dataList; - bool checking; - void reset(); - bool checkOrientation(); - int increaseCount; - int decreaseCount; - qreal lastAngle; - QList <QOrientationReading::Orientation> orientationList; - qreal detectedAngle; -}; -QT_END_NAMESPACE -#endif // QWFLICKSENSORGESTURERECOGNIZER_H diff --git a/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp deleted file mode 100644 index da6621c5..00000000 --- a/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp +++ /dev/null @@ -1,204 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - - -#include "qwhipsensorgesturerecognizer.h" -#include "qtsensorgesturesensorhandler.h" - -#include <QtCore/qmath.h> - -#define TIMER_TIMEOUT 850 - -QT_BEGIN_NAMESPACE - -QWhipSensorGestureRecognizer::QWhipSensorGestureRecognizer(QObject *parent) - : QSensorGestureRecognizer(parent), - orientationReading(0), - accelRange(0), - active(0), - lastX(0), - lastY(0), - lastZ(0), - detecting(0), - whipOk(0) - , lastTimestamp(0) - , timerActive(0) - , lapsedTime(0) -{ -} - -QWhipSensorGestureRecognizer::~QWhipSensorGestureRecognizer() -{ -} - -void QWhipSensorGestureRecognizer::create() -{ -} - -QString QWhipSensorGestureRecognizer::id() const -{ - return QString("QtSensors.whip"); -} - -bool QWhipSensorGestureRecognizer::start() -{ - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Accel)) { - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Orientation)) { - accelRange = QtSensorGestureSensorHandler::instance()->accelRange; - active = true; - connect(QtSensorGestureSensorHandler::instance(),SIGNAL(orientationReadingChanged(QOrientationReading*)), - this,SLOT(orientationReadingChanged(QOrientationReading*))); - - connect(QtSensorGestureSensorHandler::instance(),SIGNAL(accelReadingChanged(QAccelerometerReading*)), - this,SLOT(accelChanged(QAccelerometerReading*))); - } else { - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Accel); - active = false; - } - } else { - active = false; - } - lastTimestamp = 0; - timerActive = false; - lapsedTime = 0; - return active; -} - -bool QWhipSensorGestureRecognizer::stop() -{ - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Accel); - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Orientation); - disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(orientationReadingChanged(QOrientationReading*)), - this,SLOT(orientationReadingChanged(QOrientationReading*))); - - disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(accelReadingChanged(QAccelerometerReading*)), - this,SLOT(accelChanged(QAccelerometerReading*))); - active = false; - return active; -} - -bool QWhipSensorGestureRecognizer::isActive() -{ - return active; -} - -void QWhipSensorGestureRecognizer::orientationReadingChanged(QOrientationReading *reading) -{ - orientationReading = reading; -} - -#define WHIP_FACTOR -11.0 -#define WHIP_WIGGLE_FACTOR 0.35 - -void QWhipSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) -{ - const qreal x = reading->x(); - const qreal y = reading->y(); - qreal z = reading->z(); - - quint64 timestamp = reading->timestamp(); - - if (zList.count() > 4) - zList.removeLast(); - - qreal averageZ = 0; - for (const qreal& az : qAsConst<QList<qreal>>(zList)) - averageZ += az; - - averageZ /= zList.count(); - - zList.insert(0,z); - - if (orientationReading == 0) - return; - //// very hacky - if (orientationReading->orientation() == QOrientationReading::FaceUp) { - z = z - 9.8; - } - - const qreal diffX = lastX - x; - const qreal diffY = lastY - y; - - if (detecting && whipMap.count() > 5 && whipMap.at(5) == true) { - checkForWhip(); - } - - if (whipMap.count() > 5) - whipMap.removeLast(); - - if (negativeList.count() > 5) - negativeList.removeLast(); - - if (z < WHIP_FACTOR - && qAbs(diffX) > -(accelRange * .1285)//-5.0115 - && qAbs(lastX) < 7 - && qAbs(x) < 7) { - whipMap.insert(0,true); - if (!detecting && !timerActive) { - timerActive = true; - detecting = true; - } - } else { - whipMap.insert(0,false); - } - - // check if shaking - if ((((x < 0 && lastX > 0) || (x > 0 && lastX < 0)) - && qAbs(diffX) > (accelRange * 0.7)) //27.3 - || (((y < 0 && lastY > 0) || (y > 0 && lastY < 0)) - && qAbs(diffY) > (accelRange * 0.7))) { - negativeList.insert(0,true); - } else { - negativeList.insert(0,false); - } - - lastX = x; - lastY = y; - lastZ = z; - - if (timerActive && lastTimestamp > 0) - lapsedTime += (timestamp - lastTimestamp )/1000; - - if (timerActive && lapsedTime >= TIMER_TIMEOUT) { - timeout(); - } -} - -void QWhipSensorGestureRecognizer::timeout() -{ - detecting = false; -} - - -void QWhipSensorGestureRecognizer::checkForWhip() -{ - whipOk = false; - - int check = 0; - for (const qreal& az : qAsConst<QList<qreal>>(zList)) { - if (az < -10) - check++; - } - if (check >= 4) - whipOk = true; - else - return; - - if (whipOk) { - bool ok = true; - for (int i = 0; i < negativeList.count() - 1; i++) { - if (negativeList.at(i)) { - ok = false; - } - } - if (ok) { - Q_EMIT whip(); - Q_EMIT detected("whip"); - } - detecting = false; - whipMap.clear(); - timerActive = false; - } -} - -QT_END_NAMESPACE diff --git a/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.h b/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.h deleted file mode 100644 index 5f9a304d..00000000 --- a/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.h +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - - -#ifndef QWHIPSENSORGESTURERECOGNIZER_H -#define QWHIPSENSORGESTURERECOGNIZER_H - -#include <QtSensors/qsensorgesturerecognizer.h> - -#include "qtsensorgesturesensorhandler.h" - -QT_BEGIN_NAMESPACE - -class QWhipSensorGestureRecognizer : public QSensorGestureRecognizer -{ - Q_OBJECT -public: - explicit QWhipSensorGestureRecognizer(QObject *parent = 0); - ~QWhipSensorGestureRecognizer(); - - void create() override; - - QString id() const override; - bool start() override; - bool stop() override; - bool isActive() override; - -Q_SIGNALS: - void whip(); - -private slots: - void accelChanged(QAccelerometerReading *reading); - void orientationReadingChanged(QOrientationReading *reading); - void timeout(); - -private: - QOrientationReading *orientationReading; - qreal accelRange; - bool active; - - qreal lastX; - qreal lastY; - qreal lastZ; - - bool detecting; - bool whipOk; - - QList<bool> whipMap; - - void checkForWhip(); - - QList <bool> negativeList; - - QList<qreal> zList; - - quint64 lastTimestamp; - - bool timerActive; - quint64 lapsedTime; - -}; - -QT_END_NAMESPACE -#endif // QWHIPSENSORGESTURERECOGNIZER_H diff --git a/src/plugins/sensorgestures/shake/CMakeLists.txt b/src/plugins/sensorgestures/shake/CMakeLists.txt deleted file mode 100644 index afc43656..00000000 --- a/src/plugins/sensorgestures/shake/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -##################################################################### -## QShakeSensorGesturePlugin Plugin: -##################################################################### - -qt_internal_add_plugin(QShakeSensorGesturePlugin - OUTPUT_NAME qtsensorgestures_shakeplugin - PLUGIN_TYPE sensorgestures - DEFAULT_IF FALSE - SOURCES - qshakerecognizer.cpp qshakerecognizer.h - qshakesensorgestureplugin.cpp qshakesensorgestureplugin.h - LIBRARIES - Qt::Core - Qt::Sensors -) - -#### Keys ignored in scope 1:.:.:shake.pro:<TRUE>: -# OTHER_FILES = "plugin.json" -# PLUGIN_EXTENDS = "-" diff --git a/src/plugins/sensorgestures/shake/qshakerecognizer.cpp b/src/plugins/sensorgestures/shake/qshakerecognizer.cpp deleted file mode 100644 index d2739c8b..00000000 --- a/src/plugins/sensorgestures/shake/qshakerecognizer.cpp +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#include <QDebug> -#include <QTimer> - -#include "qshakerecognizer.h" - -QShakeSensorGestureRecognizer::QShakeSensorGestureRecognizer(QObject *parent) - : QSensorGestureRecognizer(parent) - , timerTimeout(450) - , active(0) - , shaking(0) - , shakeCount(0) -{ -} - -QShakeSensorGestureRecognizer::~QShakeSensorGestureRecognizer() -{ -} - -void QShakeSensorGestureRecognizer::create() -{ - accel = new QAccelerometer(this); - accel->connectToBackend(); - accel->setDataRate(50); - - qoutputrangelist outputranges = accel->outputRanges(); - - if (outputranges.count() > 0) - accelRange = (int)(outputranges.at(0).maximum *2) / 9.8; //approx range in g's - else - accelRange = 4; //this should never happen - - connect(accel,SIGNAL(readingChanged()),this,SLOT(accelChanged())); - timer = new QTimer(this); - connect(timer,SIGNAL(timeout()),this,SLOT(timeout())); - timer->setSingleShot(true); - timer->setInterval(timerTimeout); -} - -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 -#define THRESHOLD 25 - -void QShakeSensorGestureRecognizer::accelChanged() -{ - qreal x = accel->reading()->x(); - qreal y = accel->reading()->y(); - qreal z = accel->reading()->z(); - - currentData.x = x; - currentData.y = y; - currentData.z = z; - - if (qAbs(prevData.x - currentData.x) < 1 - && qAbs(prevData.y - currentData.y) < 1 - && qAbs(prevData.z - currentData.z) < 1) { - prevData.x = currentData.x; - prevData.y = currentData.y; - prevData.z = currentData.z; - return; - } - - bool wasShake = checkForShake(prevData, currentData, THRESHOLD); - if (!shaking && wasShake && - shakeCount >= NUMBER_SHAKES) { - shaking = true; - shakeCount = 0; - Q_EMIT shake(); - Q_EMIT detected("shake"); - - } else if (wasShake) { - - shakeCount++; - if (shakeCount > NUMBER_SHAKES) { - timer->start(); - } - } - - prevData.x = currentData.x; - prevData.y = currentData.y; - prevData.z = currentData.z; -} - -void QShakeSensorGestureRecognizer::timeout() -{ - shakeCount = 0; - shaking = false; -} - -bool QShakeSensorGestureRecognizer::checkForShake(AccelData prevSensorData, AccelData currentSensorData, qreal threshold) -{ - double deltaX = qAbs(prevSensorData.x - currentSensorData.x); - double deltaY = qAbs(prevSensorData.y - currentSensorData.y); - double deltaZ = qAbs(prevSensorData.z - currentSensorData.z); - - return (deltaX > threshold - || deltaY > threshold - || deltaZ > threshold); -} - diff --git a/src/plugins/sensorgestures/shake/qshakerecognizer.h b/src/plugins/sensorgestures/shake/qshakerecognizer.h deleted file mode 100644 index 2be0ced8..00000000 --- a/src/plugins/sensorgestures/shake/qshakerecognizer.h +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#ifndef QSHAKERECOGNIZER_H -#define QSHAKERECOGNIZER_H - - -#include <QtSensors/QSensor> -#include <QtSensors/QAccelerometer> -#include <QtSensors/QAccelerometerFilter> -#include <QDebug> -#include <QTimer> - -#include <QtSensors/qsensorgesturerecognizer.h> - - struct AccelData { - qreal x; - qreal y; - qreal z; -}; - -class QShakeSensorGestureRecognizer : public QSensorGestureRecognizer -{ - Q_OBJECT - -public: - - QShakeSensorGestureRecognizer(QObject *parent = 0); - ~QShakeSensorGestureRecognizer(); - - void create() override; - - QString id() const override; - bool start() override; - bool stop() override; - bool isActive() override; - - QTimer *timer; - int timerTimeout; - -Q_SIGNALS: - void shake(); - -private slots: - void accelChanged(); - void timeout(); -private: - QAccelerometer *accel; - bool active; - int accelRange; - - AccelData prevData; - AccelData currentData; - - bool checkForShake(AccelData prevSensorData, AccelData currentSensorData, qreal threshold); - bool shaking; - int shakeCount; - int threshold; - -}; - -#endif // QSHAKERECOGNIZER_H diff --git a/src/plugins/sensorgestures/shake/qshakesensorgestureplugin.cpp b/src/plugins/sensorgestures/shake/qshakesensorgestureplugin.cpp deleted file mode 100644 index f1151368..00000000 --- a/src/plugins/sensorgestures/shake/qshakesensorgestureplugin.cpp +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#include <QtPlugin> -#include <QStringList> -#include <QObject> - -#include "qshakesensorgestureplugin.h" - -#include <QtSensors/qsensorgestureplugininterface.h> - -#include "qshakerecognizer.h" - - -QShakeSensorGesturePlugin::QShakeSensorGesturePlugin() -{ -} - -QShakeSensorGesturePlugin::~QShakeSensorGesturePlugin() -{ -} - -QStringList QShakeSensorGesturePlugin::supportedIds() const -{ - QStringList list; - list << "QtSensors.shake"; - return list; -} - -QList <QSensorGestureRecognizer *> QShakeSensorGesturePlugin::createRecognizers() -{ - QList <QSensorGestureRecognizer *> recognizers; - - QSensorGestureRecognizer *sRec = new QShakeSensorGestureRecognizer(this); - recognizers.append(sRec); - - return recognizers; -} diff --git a/src/plugins/sensorgestures/shake/qshakesensorgestureplugin.h b/src/plugins/sensorgestures/shake/qshakesensorgestureplugin.h deleted file mode 100644 index a76bab57..00000000 --- a/src/plugins/sensorgestures/shake/qshakesensorgestureplugin.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#ifndef QSHAKESENSORGESTUREPLUGIN_H -#define QSHAKESENSORGESTUREPLUGIN_H - -#include <QObject> -#include <QStringList> - -#include <QtSensors/qsensorgestureplugininterface.h> - -class QShakeSensorGesturePlugin : public QObject, public QSensorGesturePluginInterface -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID "org.qt-project.QSensorGesturePluginInterface") - Q_INTERFACES(QSensorGesturePluginInterface) - -public: - explicit QShakeSensorGesturePlugin(); - ~QShakeSensorGesturePlugin(); - - QList <QSensorGestureRecognizer *> createRecognizers() override; - - QStringList gestureSignals() const; - QStringList supportedIds() const override; - QString name() const override { return "ShakeGestures"; } -}; - -#endif // QSHAKESENSORGESTUREPLUGIN_H diff --git a/src/sensors/CMakeLists.txt b/src/sensors/CMakeLists.txt index ae2cc9d9..34f9b976 100644 --- a/src/sensors/CMakeLists.txt +++ b/src/sensors/CMakeLists.txt @@ -6,13 +6,8 @@ ##################################################################### qt_internal_add_module(Sensors - PLUGIN_TYPES sensors # sensorgestures + PLUGIN_TYPES sensors SOURCES - # gestures/qsensorgesture.cpp gestures/qsensorgesture.h gestures/qsensorgesture_p.h - # gestures/qsensorgesturemanager.cpp gestures/qsensorgesturemanager.h - # gestures/qsensorgesturemanagerprivate.cpp gestures/qsensorgesturemanagerprivate_p.h - # gestures/qsensorgestureplugininterface.cpp gestures/qsensorgestureplugininterface.h - # gestures/qsensorgesturerecognizer.cpp gestures/qsensorgesturerecognizer.h qsensorbackend.cpp qsensorbackend.h qsensormanager.cpp qsensormanager.h qsensorplugin.cpp qsensorplugin.h diff --git a/src/sensors/doc/images/sensorgesture-cover.png b/src/sensors/doc/images/sensorgesture-cover.png Binary files differdeleted file mode 100644 index 7b4fbc5f..00000000 --- a/src/sensors/doc/images/sensorgesture-cover.png +++ /dev/null diff --git a/src/sensors/doc/images/sensorgesture-doubletap.png b/src/sensors/doc/images/sensorgesture-doubletap.png Binary files differdeleted file mode 100644 index 6253d0f8..00000000 --- a/src/sensors/doc/images/sensorgesture-doubletap.png +++ /dev/null diff --git a/src/sensors/doc/images/sensorgesture-facedown.png b/src/sensors/doc/images/sensorgesture-facedown.png Binary files differdeleted file mode 100644 index a85664f1..00000000 --- a/src/sensors/doc/images/sensorgesture-facedown.png +++ /dev/null diff --git a/src/sensors/doc/images/sensorgesture-faceup.png b/src/sensors/doc/images/sensorgesture-faceup.png Binary files differdeleted file mode 100644 index c20ef089..00000000 --- a/src/sensors/doc/images/sensorgesture-faceup.png +++ /dev/null diff --git a/src/sensors/doc/images/sensorgesture-flat.png b/src/sensors/doc/images/sensorgesture-flat.png Binary files differdeleted file mode 100644 index e8eafafb..00000000 --- a/src/sensors/doc/images/sensorgesture-flat.png +++ /dev/null diff --git a/src/sensors/doc/images/sensorgesture-hover.png b/src/sensors/doc/images/sensorgesture-hover.png Binary files differdeleted file mode 100644 index fecf6b3a..00000000 --- a/src/sensors/doc/images/sensorgesture-hover.png +++ /dev/null diff --git a/src/sensors/doc/images/sensorgesture-shake.png b/src/sensors/doc/images/sensorgesture-shake.png Binary files differdeleted file mode 100644 index 06f9eeaf..00000000 --- a/src/sensors/doc/images/sensorgesture-shake.png +++ /dev/null diff --git a/src/sensors/doc/images/sensorgesture-slam_1.png b/src/sensors/doc/images/sensorgesture-slam_1.png Binary files differdeleted file mode 100644 index d56f8892..00000000 --- a/src/sensors/doc/images/sensorgesture-slam_1.png +++ /dev/null diff --git a/src/sensors/doc/images/sensorgesture-slam_2.png b/src/sensors/doc/images/sensorgesture-slam_2.png Binary files differdeleted file mode 100644 index 5fe8ecba..00000000 --- a/src/sensors/doc/images/sensorgesture-slam_2.png +++ /dev/null diff --git a/src/sensors/doc/images/sensorgesture-twist.png b/src/sensors/doc/images/sensorgesture-twist.png Binary files differdeleted file mode 100644 index bec15854..00000000 --- a/src/sensors/doc/images/sensorgesture-twist.png +++ /dev/null diff --git a/src/sensors/doc/images/sensorgesture-whip.png b/src/sensors/doc/images/sensorgesture-whip.png Binary files differdeleted file mode 100644 index aa998bb7..00000000 --- a/src/sensors/doc/images/sensorgesture-whip.png +++ /dev/null diff --git a/src/sensors/doc/qtsensors.qdocconf b/src/sensors/doc/qtsensors.qdocconf index 75dec6f6..be4bd6ea 100644 --- a/src/sensors/doc/qtsensors.qdocconf +++ b/src/sensors/doc/qtsensors.qdocconf @@ -43,17 +43,6 @@ examplesinstallpath = sensors imagedirs += images -# Gestures have been disabled for the time being -excludedirs += ../../../examples/sensors/qmlsensorgestures \ - ../../../examples/sensors/shakeit \ - ../../../examples/sensors/sensorgestures \ - ../../plugins/sensorgestures \ - ../../sensors/gestures - -excludefiles += ../../sensorsquick/qmlsensorgesture.cpp \ - src/qtsensorgestures-cpp.qdoc \ - src/qtsensorgestures-plugins.qdoc - depends += qtcore qtdoc qtgui qtquick qtcmake navigation.landingpage = "Qt Sensors" diff --git a/src/sensors/doc/snippets/sensorgestures/CMakeLists.txt b/src/sensors/doc/snippets/sensorgestures/CMakeLists.txt deleted file mode 100644 index a1eb16ef..00000000 --- a/src/sensors/doc/snippets/sensorgestures/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(sensorgesturessdocsnippet LANGUAGES CXX) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) - -find_package(Qt6 COMPONENTS Core Sensors) - -qt_add_executable(sensorgesturessdocsnippet - creating.cpp - main.cpp - myplugin.h - plugin.cpp -) - -target_link_libraries(sensorgesturessdocsnippet PUBLIC - Qt::Sensors -) - -if (GCC AND UNIX) - target_link_libraries(sensorgesturessdocsnippet PUBLIC - rdynamic - log - ) -endif() diff --git a/src/sensors/doc/snippets/sensorgestures/creating.cpp b/src/sensors/doc/snippets/sensorgestures/creating.cpp deleted file mode 100644 index d1e08285..00000000 --- a/src/sensors/doc/snippets/sensorgestures/creating.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#include <QObject> -#include <QString> -#include <QSensorGestureManager> - -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/src/sensors/doc/snippets/sensorgestures/main.cpp b/src/sensors/doc/snippets/sensorgestures/main.cpp deleted file mode 100644 index d53eb039..00000000 --- a/src/sensors/doc/snippets/sensorgestures/main.cpp +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -int main(int /*argc*/, char ** /*argv*/) -{ - return 0; -} - diff --git a/src/sensors/doc/snippets/sensorgestures/myplugin.h b/src/sensors/doc/snippets/sensorgestures/myplugin.h deleted file mode 100644 index 0f03ff47..00000000 --- a/src/sensors/doc/snippets/sensorgestures/myplugin.h +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#ifndef MYPLUGIN_H -#define MYPLUGIN_H - -#include <QObject> -#include <qsensorgestureplugininterface.h> -#include <qsensorgesturerecognizer.h> - -class MySensorGestureRecognizer : public QSensorGestureRecognizer -{ - Q_OBJECT - public: - - MySensorGestureRecognizer(QObject *parent = 0); - ~MySensorGestureRecognizer(); - - void create() override; - - QString id() const override; - bool start() override; - bool stop() override; - bool isActive() override; - -Q_SIGNALS: -// all signals will get exported to QSensorGesture - void mySignal(); -}; - -class MySensorGesturePlugin : public QObject, public QSensorGesturePluginInterface -{ - Q_OBJECT - //Q_PLUGIN_METADATA(IID "com.Nokia.QSensorGesturePluginInterface" FILE "plugin.json") - Q_INTERFACES(QSensorGesturePluginInterface) -public: - - explicit MySensorGesturePlugin(); - ~MySensorGesturePlugin(); - - QList<QSensorGestureRecognizer *> createRecognizers() override; - QStringList supportedIds() const override; - QString name() const override { return "MyGestures"; } -}; - -#endif diff --git a/src/sensors/doc/snippets/sensorgestures/plugin.cpp b/src/sensors/doc/snippets/sensorgestures/plugin.cpp deleted file mode 100644 index c65d4be4..00000000 --- a/src/sensors/doc/snippets/sensorgestures/plugin.cpp +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#include "myplugin.h" - -#include <qsensorgestureplugininterface.h> -#include <qsensorgesturemanager.h> - -//! [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 <QSensorGestureRecognizer *> MySensorGesturePlugin::createRecognizers() -{ - QList <QSensorGestureRecognizer *> recognizers; - MySensorGestureRecognizer *recognizer = new MySensorGestureRecognizer(this); - recognizers.append(recognizer); - - return recognizers; -} - -QStringList MySensorGesturePlugin::supportedIds() const -{ - return QStringList() << "QtSensors.mygestures"; -} - -//! [Plugin] diff --git a/src/sensors/doc/src/qtsensorgestures-cpp.qdoc b/src/sensors/doc/src/qtsensorgestures-cpp.qdoc deleted file mode 100644 index d7c5ebfc..00000000 --- a/src/sensors/doc/src/qtsensorgestures-cpp.qdoc +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only - -/*! -\page qtsensorgestures-cpp.html -\title Sensor Gestures C++ Overview -\brief Explains how to use the QtSensorGestures C++ API - -\tableofcontents - -\section1 Using QtSensorGestures - -With the Sensor Gestures classes, you are able to easily utilize device gesturing using -sensors, such as the accelerometer and proximity. - -A list of currently supported sensor gestures and their descriptions can be found here: -\l {Qt Sensor Gestures} - -Using \c QtSensorGestures is easy. There are two main classes you will need to use: - -\list - \li QSensorGestureManager: can be used for determining which sensor gestures are available. - \li QSensorGesture : for connecting the sensor gesture signals. -\endlist - -\snippet 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 - -The primary classes that make up the \c QtSensorGesturesRecognizers API: - -\annotatedlist sensorgestures_recognizer - -Details of the \c QSensorGesturePlugins available - -\annotatedlist sensorgesture_plugins_topics - -*/ - diff --git a/src/sensors/doc/src/qtsensorgestures-plugins.qdoc b/src/sensors/doc/src/qtsensorgestures-plugins.qdoc deleted file mode 100644 index 2baf1a85..00000000 --- a/src/sensors/doc/src/qtsensorgestures-plugins.qdoc +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only - -/*! -\group sensorgesture_plugins_topics -\title QtSensorGestures Plugins -\brief Explains how to develop recognizer plugins with QtSensorGestures - -The QtSensorGestures recognizer plugins are the way to create your own -sensor gestures. - -Creating software to recognize motion gestures using sensors is a huge subject not covered here. - -The QSensorGesture API does not limit usage to any of the common classification methods of gesture -recognition, such as Hidden Markov Models, Neural Networks, Dynamic Time Warping, or even the -ad-hoc heuristic recognizers of Qt's built-in sensor gesture recognizers. It's basically a -signaling system for lower level gesture recogition methods and algorithms to communicate to the -higher level applications. - -\tableofcontents - -\section1 Overview - - The steps for creating a sensor gesture plugin are as follows: -\list -\li Sub-class from QSensorGesturePluginInterface -\li Sub-class from QSensorGestureRecognizer and implement gesture recognizer logic using QtSensors. -\li 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. - -This is the class in which the gesture recognizer system should be implemented from. - -\endlist - -\snippet sensorgestures/plugin.cpp Plugin - - -\section2 Recognizer Classes - -If you are making sensorgestures available through the QtSensorGestures API, these are the -classes to subclass. - -\annotatedlist sensorgestures_recognizer - -\target Qt Sensor Gestures -\section3 Recognizer Plugins - -The Sensor Gesture Recognizers that come with Qt are made using an ad-hoc heuristic approach. -The user cannot define their own gestures, and must learn how to perform and accommodate the -pre-defined gestures herein. - -A developer may use any method, including computationally- and training-intensive well- -known classifiers, to produce gesture recognizers. There are currently no classes in Qt for -gesture training, nor is it possible for the user to define his own sensor-based motion gestures. - -A procedure for writing ad-hoc recognizers might include: -\list - \li Obtain and gather output from the accelerometer through \c QAccelerometerReading of a gesture being performed. - \li Use various methods and constraints on the accelerometer data to recognize the various states: - \list i - \li Initial "listening" state for a gesture - \li Start of a possible gesture, moving into a "detecting" state - \li End of a possible gesture, moving into a "recognizing" state - \li and finally, if it is recognized, the "recognized" state, or if not recognized, move back to - the "listening" state. - \endlist - \li Test procedure to make sure it is easy to perform, and will not - produce too many false positive recognitions, or collisions if used with other gestures. Meaning -that gestures performed get recognized as another gesture instead. - -\endlist - -Below you will find a list of included plugins and their signals. - -For the ShakeGestures plugin: - \table - \row - \li Recognizer Id - \li Signals - \row - \li QtSensors.shake - \li shake -\endtable - -For the QtSensorGestures plugin: - \table - \row - \li Recognizer Id - \li Signals - \li Description - \li Images - \row - \li QtSensors.cover - \li cover - \li Hand covers up phone display for one second, when it's face up, using the Proximity and Orientation sensors. - \li \image sensorgesture-cover.png - \row - \li QtSensors.doubletap - \li doubletap - \li Double tap of finger on phone, using the DoubleTap sensor. - \li \image sensorgesture-doubletap.png - \row - \li QtSensors.hover - \li hover - \li Hand hovers about 4 cm above the phone for more than 1 second, then is removed when face up, - using the IR Proximity sensor. - \li \image sensorgesture-hover.png - \row - \li QtSensors.pickup - \li pickup - \li Phone is resting face up on a flat curface, and is then picked up and brought up into viewing position. Uses the Accelerometer sensor. - \li \image sensorgesture-faceup.png - \row - \li QtSensors.shake2 - \li shakeLeft, shakeRight, shakeUp, shakeDown - \li Shake phone in a certain direction, using the Accelerometer sensor. - \li \image sensorgesture-shake.png - \row - \li QtSensors.slam - \li slam - \li Phone is held in a top up position with a side facing forward for a moment. Swing it quickly with a downward motion - like it is being used to point at something with the top corner. Uses the Accelerometer and Orientation sensors. - \li \image sensorgesture-slam_1.png - \image sensorgesture-slam_2.png - \row - \li QtSensors.turnover - \li turnover - \li Phone is turned face down and placed on a surface, using Proximity and Orientation sensors. - \li \image sensorgesture-facedown.png - \row - \li QtSensors.twist - \li twistLeft, twistRight - \li Phone is held face up and then twisted left or right (left side up or right side up) and back, using the Accelerometer and Orientation sensors. - \li \image sensorgesture-twist.png - \row - \li QtSensors.whip - \li whip - \li Move phone quickly down and then back up. Uses the Accelerometer and Orientation sensors. - \li \image sensorgesture-whip.png - \endtable - -*/ diff --git a/src/sensors/gestures/qsensorgesture.cpp b/src/sensors/gestures/qsensorgesture.cpp deleted file mode 100644 index dd1fdf80..00000000 --- a/src/sensors/gestures/qsensorgesture.cpp +++ /dev/null @@ -1,214 +0,0 @@ -// Copyright (C) 2019 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#include <QDir> -#include <QPluginLoader> -#include <QDebug> - -#include "qsensorgesture.h" -#include "qsensorgesture_p.h" -#include "qsensorgesturemanager.h" - -#include <private/qmetaobjectbuilder_p.h> - -/*! - \class QSensorGesture - \ingroup sensorgestures_main - \inmodule QtSensors - \since 5.1 - - \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(). - - \b {Note that QSensorGesture uses a custom meta-object in order to provide - recognizer-specific signals. This means it is not possible to sub-class - QSensorGesture and use Q_OBJECT. Also qobject_cast<QSensorGesture*>(ptr) will - not work.} - - \sa QSensorGestureRecognizer - - You may use QSensorGestureManager to obtain the systems known sensor gesture ids. - - \sa QSensorGestureManager - */ - -/*! - \fn void QSensorGesture::detected(QString) - Signals when the gesture has been recognized. - */ - -/*! - 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(); - for (const QString &id : ids) { - QSensorGestureRecognizer * rec = QSensorGestureManager::sensorGestureRecognizer(id); - if (rec != 0) { - d_ptr->m_sensorRecognizers.append(rec); - d_ptr->availableIds.append(id); - } else { - d_ptr->invalidIds.append(id); - //add to not available things - } - } - - d_ptr->meta = 0; - - QMetaObjectBuilder builder; - builder.setSuperClass(&QObject::staticMetaObject); - builder.setClassName("QSensorGesture"); - - for (QSensorGestureRecognizer *recognizer : d_ptr->m_sensorRecognizers) { - for (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) - free(d_ptr->meta); - delete d_ptr; -} - -/*! - Returns the gesture recognizer ids that were found. - */ -QStringList QSensorGesture::validIds() const -{ - return d_ptr->availableIds; -} - -/*! - Returns the gesture recognizer ids that were not found. - */ -QStringList QSensorGesture::invalidIds() const -{ - return d_ptr->invalidIds; -} - -/*! - Starts the gesture detection routines in the recognizer. - */ -void QSensorGesture::startDetection() -{ - if (d_ptr->m_sensorRecognizers.count() < 1) - return; - if (d_ptr->isActive) - return; - - for (QSensorGestureRecognizer *recognizer : d_ptr->m_sensorRecognizers) { - - Q_ASSERT(recognizer !=0); - - connect(recognizer,SIGNAL(detected(QString)), - this,SIGNAL(detected(QString)),Qt::UniqueConnection); - - //connect recognizer signals - for (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; - - for (QSensorGestureRecognizer *recognizer : d_ptr->m_sensorRecognizers) { - disconnect(recognizer,SIGNAL(detected(QString)), - this,SIGNAL(detected(QString))); - //disconnect recognizer signals - for (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; -} - -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 deleted file mode 100644 index 93282805..00000000 --- a/src/sensors/gestures/qsensorgesture.h +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (C) 2019 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#ifndef QSENSORGESTURE_H -#define QSENSORGESTURE_H - -#include <QtCore/QObject> -#include <QtCore/QStringList> -#include <QtSensors/qsensorsglobal.h> - -#include <QtCore/QList> -#include <QtCore/QMap> - -#include <QtCore/qmetatype.h> - -QT_BEGIN_NAMESPACE - -class QSensorGesturePrivate; - -class Q_SENSORS_EXPORT QSensorGesture : public QObject -{ - //Do not use Q_OBJECT here -public: - explicit QSensorGesture(const QStringList &ids, QObject *parent = nullptr); - ~QSensorGesture(); - - bool isActive(); - - QStringList validIds() const; - QStringList invalidIds() const; - - QStringList gestureSignals() const; - - void startDetection(); - void stopDetection(); - - // Pretend to be a Q_OBJECT - const QMetaObject *metaObject() const override; - int qt_metacall(QMetaObject::Call, int, void **) override; - -private: - QSensorGesturePrivate * d_ptr; - -Q_SIGNALS: - // these signals are created at runtime, along with - // gesture recognizer specific signals. - void detected(QString); -}; - -QT_END_NAMESPACE - - -#endif // QSENSORGESTURE_H diff --git a/src/sensors/gestures/qsensorgesture_p.h b/src/sensors/gestures/qsensorgesture_p.h deleted file mode 100644 index 9794be66..00000000 --- a/src/sensors/gestures/qsensorgesture_p.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#ifndef QSENSORGESTURE_P_H -#define QSENSORGESTURE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// -#include <QtSensors/QSensor> -#include <QtSensors/QAccelerometer> -#include <QtSensors/QAccelerometerFilter> -#include <QTimer> - -#include "qsensorgesture.h" -#include "qsensorgesturemanager.h" -#include <QtCore/private/qmetaobjectbuilder_p.h> - -QT_BEGIN_NAMESPACE - -class QSensorGesturePrivate : public QObject -{ - -public: - QSensorGesturePrivate(QObject *parent = 0); - ~QSensorGesturePrivate(); - - QList<QSensorGestureRecognizer *> m_sensorRecognizers; - - QByteArray metadata; - QMetaObject* meta; - bool isActive; - QStringList localGestureSignals; - QStringList availableIds; - QStringList invalidIds; - bool valid; -}; - - -QT_END_NAMESPACE - -#endif // QSENSORGESTURE_P_H diff --git a/src/sensors/gestures/qsensorgesturemanager.cpp b/src/sensors/gestures/qsensorgesturemanager.cpp deleted file mode 100644 index b754878f..00000000 --- a/src/sensors/gestures/qsensorgesturemanager.cpp +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#include "qsensorgesturemanager.h" -#include "qsensorgesturemanagerprivate_p.h" - -QT_BEGIN_NAMESPACE - -/*! - \class QSensorGestureManager - \ingroup sensorgestures_main - \inmodule QtSensors - \since 5.1 - - \brief The QSensorGestureManager class manages sensor gestures, registers and creates sensor gesture plugins. - - Sensor Gesture plugins register their recognizers using the registerSensorGestureRecognizer() function. - - \snippet 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) -{ - QSensorGestureManagerPrivate *d = QSensorGestureManagerPrivate::instance(); - if (!d) return; // hardly likely but just in case... - connect(d,SIGNAL(newSensorGestureAvailable()), - this,SIGNAL(newSensorGestureAvailable())); -} - -/*! - 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) - { - QSensorGestureManagerPrivate *d = QSensorGestureManagerPrivate::instance(); - if (!d) { // hardly likely but just in case... - delete recognizer; - return false; - } - bool ok = d->registerSensorGestureRecognizer(recognizer); - if (!ok) - 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 - { - QSensorGestureManagerPrivate *d = QSensorGestureManagerPrivate::instance(); - if (!d) return QStringList(); // hardly likely but just in case... - return d->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) -{ - QSensorGestureManagerPrivate *d = QSensorGestureManagerPrivate::instance(); - if (!d) return 0; // hardly likely but just in case... - return d->sensorGestureRecognizer(id); -} - -QT_END_NAMESPACE diff --git a/src/sensors/gestures/qsensorgesturemanager.h b/src/sensors/gestures/qsensorgesturemanager.h deleted file mode 100644 index 948a63cb..00000000 --- a/src/sensors/gestures/qsensorgesturemanager.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#ifndef QSENSORGESTUREMANAGER_P_H -#define QSENSORGESTUREMANAGER_P_H - -#include <QtCore/QObject> -#include <QtCore/QStringList> - -#include <QtSensors/qsensorgesture.h> -#include <QtSensors/qsensorgesturerecognizer.h> - -QT_BEGIN_NAMESPACE - -class QSensorGestureManagerPrivate; -class Q_SENSORS_EXPORT QSensorGestureManager : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QSensorGestureManager) - -public: - explicit QSensorGestureManager(QObject *parent = nullptr); - - ~QSensorGestureManager(); - - bool registerSensorGestureRecognizer(QSensorGestureRecognizer *recognizer); - - QStringList gestureIds() const; - QStringList recognizerSignals(const QString &recognizerId) const; - - static QSensorGestureRecognizer *sensorGestureRecognizer(const QString &id); - -Q_SIGNALS: - void newSensorGestureAvailable(); - -}; - - -QT_END_NAMESPACE - -#endif // QSENSORGESTUREMANAGER_P_H diff --git a/src/sensors/gestures/qsensorgesturemanagerprivate.cpp b/src/sensors/gestures/qsensorgesturemanagerprivate.cpp deleted file mode 100644 index d87823e2..00000000 --- a/src/sensors/gestures/qsensorgesturemanagerprivate.cpp +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#include <QDir> -#include <QLibraryInfo> - -#include <QtCore/private/qfactoryloader_p.h> - -#include "qsensorgesturerecognizer.h" -#include "qsensorgesturemanagerprivate_p.h" -#include "qsensorgestureplugininterface.h" - -Q_GLOBAL_STATIC(QSensorGestureManagerPrivate, sensorGestureManagerPrivate) - -QT_BEGIN_NAMESPACE - -QSensorGestureManagerPrivate::QSensorGestureManagerPrivate(QObject *parent) : - QObject(parent) -{ - loader = new QFactoryLoader("org.qt-project.QSensorGesturePluginInterface", QLatin1String("/sensorgestures")); - loadPlugins(); -} - -QSensorGestureManagerPrivate::~QSensorGestureManagerPrivate() -{ -// qDeleteAll(registeredSensorGestures); -// delete loader; -} - - - void QSensorGestureManagerPrivate::initPlugin(QObject *plugin) -{ - if (QSensorGesturePluginInterface *pInterface - = qobject_cast<QSensorGesturePluginInterface *>(plugin)) { - for (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; - } else { - qWarning() << "Could not load "<< plugin; - } -} - - -/*! - Internal - Loads the sensorgesture plugins. - */ -void QSensorGestureManagerPrivate::loadPlugins() -{ - for (QObject *plugin : QPluginLoader::staticInstances()) - initPlugin(plugin); - - QList<QPluginParsedMetaData> meta = loader->metaData(); - for (int i = 0; i < meta.count(); i++) { - QObject *plugin = loader->instance(i); - initPlugin(plugin); - } -} - - -/*! - Internal - creates the requested recognizer. - */ - -bool QSensorGestureManagerPrivate::loadRecognizer(const QString &recognizerId) -{ - //if no plugin is used return true if this is a registered recognizer - - if (registeredSensorGestures.contains(recognizerId)) - return true; - - for (int i= 0; i < plugins.count(); i++) { - - if (QSensorGesturePluginInterface *pInterface - = qobject_cast<QSensorGesturePluginInterface *>(plugins.at(i))) { - - if (pInterface->supportedIds().contains(recognizerId)) { - - if (!registeredSensorGestures.contains(recognizerId)) { - //create these recognizers - QList <QSensorGestureRecognizer *> recognizers = pInterface->createRecognizers(); - - for (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); - Q_EMIT newSensorGestureAvailable(); - - return true; - } - 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; -} - -QSensorGestureManagerPrivate * QSensorGestureManagerPrivate::instance() -{ - QSensorGestureManagerPrivate *priv = sensorGestureManagerPrivate(); - // It's safe to return 0 because this is checked when used - //if (!priv) qFatal("Cannot return from QSensorGestureManagerPrivate::instance() because sensorGestureManagerPrivate() returned 0."); - return priv; -} - - -QT_END_NAMESPACE diff --git a/src/sensors/gestures/qsensorgesturemanagerprivate_p.h b/src/sensors/gestures/qsensorgesturemanagerprivate_p.h deleted file mode 100644 index 2a62d5f7..00000000 --- a/src/sensors/gestures/qsensorgesturemanagerprivate_p.h +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#ifndef QSENSORGESTUREMANAGERPRIVATE_P_H -#define QSENSORGESTUREMANAGERPRIVATE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QObject> -#include <QMap> -#include <QStringList> -#include <QDebug> -#include <QSharedPointer> -#include <QPluginLoader> - -#include "qsensorgesture.h" -#include "qsensorgesturerecognizer.h" -#include "private/qglobal_p.h" - -QT_BEGIN_NAMESPACE - -class QFactoryLoader; - -class QSensorGestureManagerPrivate : public QObject -{ - Q_OBJECT -public: - explicit QSensorGestureManagerPrivate(QObject *parent = 0); - ~QSensorGestureManagerPrivate(); - - QMap<QString, QSensorGestureRecognizer *> registeredSensorGestures; - - QList <QObject *> plugins; - - QFactoryLoader *loader; - void loadPlugins(); - bool loadRecognizer(const QString &id); - - QSensorGestureRecognizer *sensorGestureRecognizer(const QString &id); - - bool registerSensorGestureRecognizer(QSensorGestureRecognizer *recognizer); - QStringList gestureIds(); - QStringList knownIds; - void initPlugin(QObject *o); - - static QSensorGestureManagerPrivate * instance(); -Q_SIGNALS: - void newSensorGestureAvailable(); -}; - -QT_END_NAMESPACE - -#endif // QSENSORGESTUREMANAGERPRIVATE_P_H diff --git a/src/sensors/gestures/qsensorgestureplugininterface.cpp b/src/sensors/gestures/qsensorgestureplugininterface.cpp deleted file mode 100644 index c9e54f77..00000000 --- a/src/sensors/gestures/qsensorgestureplugininterface.cpp +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#include "qsensorgestureplugininterface.h" - -QT_BEGIN_NAMESPACE - -/*! - \class QSensorGesturePluginInterface - \ingroup sensorgestures_recognizer - \inmodule QtSensors - - \brief The QSensorGesturePluginInterface class is the pure virtual interface to sensor gesture - plugins. - - \since 5.1 - - 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. - */ - -/*! - Construct the QSensorGesturePluginInterface. -*/ -QSensorGesturePluginInterface::QSensorGesturePluginInterface() -{ -} - -/*! - Destroy the QSensorGesturePluginInterface. -*/ -QSensorGesturePluginInterface::~QSensorGesturePluginInterface() -{ -} - -QT_END_NAMESPACE diff --git a/src/sensors/gestures/qsensorgestureplugininterface.h b/src/sensors/gestures/qsensorgestureplugininterface.h deleted file mode 100644 index fa98385d..00000000 --- a/src/sensors/gestures/qsensorgestureplugininterface.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#ifndef QSENSORGESTUREPLUGININTERFACE_H -#define QSENSORGESTUREPLUGININTERFACE_H - -#include <QtCore/QObject> -#include <QtCore/QtGlobal> -#include <QtCore/qplugin.h> -#include <QtSensors/qsensorgesture.h> -#include <QtSensors/qsensorgesturerecognizer.h> - -QT_BEGIN_NAMESPACE - -class QSensorGestureRecognizer; - -class Q_SENSORS_EXPORT QSensorGesturePluginInterface -{ -public: - QSensorGesturePluginInterface(); - virtual ~QSensorGesturePluginInterface(); - virtual QList <QSensorGestureRecognizer *> createRecognizers() = 0; - virtual QStringList supportedIds() const = 0; - virtual QString name() const = 0; -}; - -Q_DECLARE_INTERFACE(QSensorGesturePluginInterface, "org.qt-project.QSensorGesturePluginInterface") - -QT_END_NAMESPACE - -#endif // QSENSORGESTUREPLUGININTERFACE_H diff --git a/src/sensors/gestures/qsensorgesturerecognizer.cpp b/src/sensors/gestures/qsensorgesturerecognizer.cpp deleted file mode 100644 index eb5dc32b..00000000 --- a/src/sensors/gestures/qsensorgesturerecognizer.cpp +++ /dev/null @@ -1,171 +0,0 @@ -// Copyright (C) 2019 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#include "qsensorgesturerecognizer.h" -#include "qsensorgesture_p.h" -#include "qsensorgesturemanager.h" - -QT_BEGIN_NAMESPACE - -/*! - \class QSensorGestureRecognizer - \ingroup sensorgestures_recognizer - \inmodule QtSensors - \since 5.1 - - \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 &) - Signals when a gesture is recognized. Implementors can use this signal to send - recognizer-specific gestures, such as \c detected("shake_left") or implement - custom signals such as \c shakeLeft(). - - The custom signals are available in the QSensorGesture object at runtime. - */ - -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() -{ - 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 - const QByteArray sig(this->metaObject()->method(i).methodSignature()); - if (this->metaObject()->indexOfSignal(sig) != -1) { - if (sig.contains("detected")) - ok = true; - if (ok) - list.append(QString::fromLatin1(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 initialized. - This is called by the QSensorGesture object, so please use that instead. - -\sa QSensorGesture::startDetection() - -*/ -void QSensorGestureRecognizer::startBackend() -{ - if (!d_ptr->initialized) { - qWarning() << "Not starting. Gesture Recognizer not initialized"; - return; - } - if (d_ptr->count++ == 0) - start(); -} - -/*! - Calls QSensorGestureRecognizer::stop() if no other clients are using it. - This is called by the QSensorGesture object, so please use that instead. - -\sa QSensorGesture::stopDetection() -*/ -void QSensorGestureRecognizer::stopBackend() -{ - if (!d_ptr->initialized) { - qWarning() << "Not stopping. Gesture Recognizer not initialized"; - return; - } - if (--d_ptr->count == 0) - stop(); -} - -QT_END_NAMESPACE diff --git a/src/sensors/gestures/qsensorgesturerecognizer.h b/src/sensors/gestures/qsensorgesturerecognizer.h deleted file mode 100644 index 1d5a6513..00000000 --- a/src/sensors/gestures/qsensorgesturerecognizer.h +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#ifndef QSENSORGESTURERECOGNIZER_H -#define QSENSORGESTURERECOGNIZER_H - -#include <QtCore/QDebug> -#include <QtCore/QTimer> -#include <QtCore/QStringList> - -#include <QtSensors/qsensorgesture.h> - -QT_BEGIN_NAMESPACE - -class QSensorGestureRecognizerPrivate; -class Q_SENSORS_EXPORT QSensorGestureRecognizer : public QObject -{ - Q_OBJECT -public: - explicit QSensorGestureRecognizer(QObject *parent = nullptr); - virtual ~QSensorGestureRecognizer(); - - virtual QString id() const = 0; - - virtual bool isActive() = 0; - - void startBackend(); - void stopBackend(); - void createBackend(); - - QStringList gestureSignals() const; - -Q_SIGNALS: - void detected(const QString &); - -protected: - virtual void create() = 0; - virtual bool start() = 0; - virtual bool stop() = 0; - -private: - QSensorGestureRecognizerPrivate * d_ptr; -}; - -QT_END_NAMESPACE - -#endif // QSENSORGESTURERECOGNIZER_H diff --git a/src/sensorsquick/CMakeLists.txt b/src/sensorsquick/CMakeLists.txt index c9047e28..29552a81 100644 --- a/src/sensorsquick/CMakeLists.txt +++ b/src/sensorsquick/CMakeLists.txt @@ -20,7 +20,6 @@ qt_internal_add_qml_module(SensorsQuick qmlproximitysensor.cpp qmlproximitysensor_p.h qmlrotationsensor.cpp qmlrotationsensor_p.h qmlsensor.cpp qmlsensor_p.h - # qmlsensorgesture.cpp qmlsensorgesture_p.h qmlsensorglobal.cpp qmlsensorglobal_p.h qmlsensorrange.cpp qmlsensorrange_p.h qmltapsensor.cpp qmltapsensor_p.h diff --git a/src/sensorsquick/qmlsensorgesture.cpp b/src/sensorsquick/qmlsensorgesture.cpp deleted file mode 100644 index 518280f9..00000000 --- a/src/sensorsquick/qmlsensorgesture.cpp +++ /dev/null @@ -1,226 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#include "qmlsensorgesture_p.h" -#include <QtSensors/qsensorgesture.h> -#include <QtSensors/qsensorgesturemanager.h> - -QT_BEGIN_NAMESPACE - -/*! - \qmltype SensorGesture - \instantiates QmlSensorGesture - \inqmlmodule QtSensors - \since QtSensors 5.0 - \brief Provides notifications when sensor-based gestures are detected. - - This type provides notification when sensor gestures are triggered. - - The following QML code creates a "shake" and "SecondCounter" SensorGesture QML type, and - displays the detected gesture in a text type. - - QtSensors.shake gesture is available with the Qt Sensors API, but the QtSensors.SecondCounter - sensor gesture is provided as example code for the \l {Qt Sensors - SensorGesture QML Type Example} - - \qml - Item { - SensorGesture { - id: sensorGesture - enabled: false - gestures : ["QtSensors.shake", "QtSensors.SecondCounter"] - onDetected:{ - detectedText.text = gesture - } - } - Text { - id: detectedText - x:5 - y:160 - } - } - \endqml - - \l {Qt Sensor Gestures} contains a list of currently supported sensor gestures and their - descriptions. - - -*/ -QmlSensorGesture::QmlSensorGesture(QObject* parent) - : QObject(parent) - , isEnabled(false) - , initDone(false) - , sensorGesture(0) - , sensorGestureManager(new QSensorGestureManager(this)) -{ - connect(sensorGestureManager, SIGNAL(newSensorGestureAvailable()), SIGNAL(availableGesturesChanged())); -} - -QmlSensorGesture::~QmlSensorGesture() -{ -} - -/* - QQmlParserStatus interface implementation -*/ -void QmlSensorGesture::classBegin() -{ -} - -void QmlSensorGesture::componentComplete() -{ - /* - this is needed in the case the customer defines the type(s) and set it enabled = true - */ - initDone = true; - setEnabled(isEnabled); -} -/* - End of QQmlParserStatus interface implementation -*/ - -/*! - \qmlproperty stringlist SensorGesture::availableGestures - This property can be used to determine all available gestures on the system. -*/ -QStringList QmlSensorGesture::availableGestures() -{ - return sensorGestureManager->gestureIds(); -} - -/*! - \qmlproperty stringlist SensorGesture::gestures - Set this property to a list of the gestures that the application is interested in detecting. - This property cannot be changed while the type is enabled. - - The properties validGestures and invalidGestures will be set as appropriate immediately. - To determine all available getures on the system please use the - \l {SensorGesture::availableGestures} {availableGestures} property. - - \sa {QtSensorGestures Plugins} -*/ -QStringList QmlSensorGesture::gestures() const -{ - return gestureList; -} - -void QmlSensorGesture::setGestures(const QStringList& value) -{ - if (gestureList == value) - return; - - if (initDone && enabled()) { - qWarning() << "Cannot change gestures while running."; - return; - } - gestureList = value; - createGesture(); - Q_EMIT gesturesChanged(); -} - - -/*! - \qmlproperty stringlist SensorGesture::validGestures - This property holds the requested gestures that were found on the system. -*/ -QStringList QmlSensorGesture::validGestures() const -{ - if (sensorGesture) - return sensorGesture->validIds(); - return QStringList(); -} - -/*! - \qmlproperty stringlist SensorGesture::invalidGestures - This property holds the requested gestures that were not found on the system. -*/ -QStringList QmlSensorGesture::invalidGestures() const -{ - if (sensorGesture) - return sensorGesture->invalidIds(); - return QStringList(); -} - -/*! - \qmlproperty bool SensorGesture::enabled - This property can be used to activate or deactivate the sensor gesture. - Default value is false; - \sa {SensorGesture::detected}, {detected} -*/ -bool QmlSensorGesture::enabled() const -{ - return isEnabled; -} - -void QmlSensorGesture::setEnabled(bool value) -{ - bool hasChanged = false; - if (isEnabled != value) { - isEnabled = value; - hasChanged = true; - } - if (!initDone) - return; - - if (sensorGesture) { - if (value) { - sensorGesture->startDetection(); - } else { - sensorGesture->stopDetection(); - } - } - if (hasChanged) - Q_EMIT enabledChanged(); -} - -/*! - \qmlsignal SensorGesture::detected(string gesture) - This signal is emitted whenever a gesture is detected. - The \a gesture parameter contains the gesture that was detected. - - The corresponding handler is \c onDetected. -*/ - -/* - private function implementation -*/ -void QmlSensorGesture::deleteGesture() -{ - if (sensorGesture) { - bool emitInvalidChange = !invalidGestures().isEmpty(); - bool emitValidChange = !validGestures().isEmpty(); - - if (sensorGesture->isActive()) { - sensorGesture->stopDetection(); - } - delete sensorGesture; - sensorGesture = 0; - - if (emitInvalidChange) { - Q_EMIT invalidGesturesChanged(); - } - if (emitValidChange) { - Q_EMIT validGesturesChanged(); - } - } -} - -void QmlSensorGesture::createGesture() -{ - deleteGesture(); - sensorGesture = new QSensorGesture(gestureList, this); - if (!validGestures().isEmpty()) { - QObject::connect(sensorGesture - , SIGNAL(detected(QString)) - , this - , SIGNAL(detected(QString))); - Q_EMIT validGesturesChanged(); - } - if (!invalidGestures().isEmpty()) - Q_EMIT invalidGesturesChanged(); -} - -/* - End of private function implementation -*/ - -QT_END_NAMESPACE diff --git a/src/sensorsquick/qmlsensorgesture_p.h b/src/sensorsquick/qmlsensorgesture_p.h deleted file mode 100644 index f87beff7..00000000 --- a/src/sensorsquick/qmlsensorgesture_p.h +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#ifndef QMLSENSORGESTURE_P_H -#define QMLSENSORGESTURE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QQmlParserStatus> -#include <QtQml/qqml.h> -#include <QStringList> - -#include "qsensorsquickglobal_p.h" - -QT_BEGIN_NAMESPACE - -class QSensorGesture; -class QSensorGestureManager; - -class Q_SENSORSQUICK_PRIVATE_EXPORT QmlSensorGesture : public QObject, public QQmlParserStatus -{ - Q_OBJECT - Q_PROPERTY(QStringList availableGestures READ availableGestures NOTIFY availableGesturesChanged) - Q_PROPERTY(QStringList gestures READ gestures WRITE setGestures NOTIFY gesturesChanged) - Q_PROPERTY(QStringList validGestures READ validGestures NOTIFY validGesturesChanged) - Q_PROPERTY(QStringList invalidGestures READ invalidGestures NOTIFY invalidGesturesChanged) - Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) - Q_INTERFACES(QQmlParserStatus) - QML_NAMED_ELEMENT(SensorGesture) - QML_ADDED_IN_VERSION(5,0) - -public: - explicit QmlSensorGesture(QObject* parent = 0); - ~QmlSensorGesture(); - void classBegin() override; - void componentComplete() override; - -Q_SIGNALS: - void detected(const QString &gesture); - void availableGesturesChanged(); - void gesturesChanged(); - void validGesturesChanged(); - void invalidGesturesChanged(); - void enabledChanged(); - -public: - QStringList availableGestures(); - QStringList gestures() const; - void setGestures(const QStringList& value); - bool enabled() const; - void setEnabled(bool value); - QStringList validGestures() const; - QStringList invalidGestures() const; - -private: - void deleteGesture(); - void createGesture(); - -private: - QStringList gestureIds; - bool isEnabled; - bool initDone; - QStringList gestureList; - - QSensorGesture* sensorGesture; - QSensorGestureManager* sensorGestureManager; -}; - -QT_END_NAMESPACE - -#endif |