| 1 | /**************************************************************************** |
|---|---|
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtSensors module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #include "qsensorgesturemanager.h" |
| 41 | #include "qsensorgesturemanagerprivate_p.h" |
| 42 | |
| 43 | QT_BEGIN_NAMESPACE |
| 44 | |
| 45 | /*! |
| 46 | \class QSensorGestureManager |
| 47 | \ingroup sensorgestures_main |
| 48 | \inmodule QtSensors |
| 49 | \since 5.1 |
| 50 | |
| 51 | \brief The QSensorGestureManager class manages sensor gestures, registers and creates sensor gesture plugins. |
| 52 | |
| 53 | Sensor Gesture plugins register their recognizers using the registerSensorGestureRecognizer() function. |
| 54 | |
| 55 | \snippet sensorgestures/creating.cpp Receiving sensor gesture signals |
| 56 | */ |
| 57 | |
| 58 | /*! |
| 59 | \fn QSensorGestureManager::newSensorGestureAvailable() |
| 60 | Signals when a new sensor gesture becomes available for use. |
| 61 | */ |
| 62 | |
| 63 | /*! |
| 64 | Constructs the QSensorGestureManager as a child of \a parent |
| 65 | */ |
| 66 | QSensorGestureManager::QSensorGestureManager(QObject *parent) |
| 67 | : QObject(parent) |
| 68 | { |
| 69 | QSensorGestureManagerPrivate *d = QSensorGestureManagerPrivate::instance(); |
| 70 | if (!d) return; // hardly likely but just in case... |
| 71 | connect(sender: d,SIGNAL(newSensorGestureAvailable()), |
| 72 | receiver: this,SIGNAL(newSensorGestureAvailable())); |
| 73 | } |
| 74 | |
| 75 | /*! |
| 76 | Destroy the QSensorGestureManager |
| 77 | */ |
| 78 | QSensorGestureManager::~QSensorGestureManager() |
| 79 | { |
| 80 | } |
| 81 | |
| 82 | /*! |
| 83 | Registers the sensor recognizer \a recognizer for use. |
| 84 | QSensorGestureManager retains ownership of the recognizer object. |
| 85 | Returns true unless the gesture has already been registered, in |
| 86 | which case the object is deleted. |
| 87 | |
| 88 | */ |
| 89 | |
| 90 | bool QSensorGestureManager::registerSensorGestureRecognizer(QSensorGestureRecognizer *recognizer) |
| 91 | { |
| 92 | QSensorGestureManagerPrivate *d = QSensorGestureManagerPrivate::instance(); |
| 93 | if (!d) { // hardly likely but just in case... |
| 94 | delete recognizer; |
| 95 | return false; |
| 96 | } |
| 97 | bool ok = d->registerSensorGestureRecognizer(recognizer); |
| 98 | if (!ok) |
| 99 | delete recognizer; |
| 100 | |
| 101 | return ok; |
| 102 | } |
| 103 | |
| 104 | |
| 105 | /*! |
| 106 | Returns the list of the currently registered gestures. |
| 107 | Includes all the standard built-ins as well as available plugins. |
| 108 | */ |
| 109 | QStringList QSensorGestureManager::gestureIds() const |
| 110 | { |
| 111 | QSensorGestureManagerPrivate *d = QSensorGestureManagerPrivate::instance(); |
| 112 | if (!d) return QStringList(); // hardly likely but just in case... |
| 113 | return d->gestureIds(); |
| 114 | } |
| 115 | |
| 116 | /*! |
| 117 | Returns the list of all the gesture signals for the registered \a gestureId gesture recognizer id. |
| 118 | */ |
| 119 | QStringList QSensorGestureManager::recognizerSignals(const QString &gestureId) const |
| 120 | { |
| 121 | QSensorGestureRecognizer *recognizer = sensorGestureRecognizer(id: gestureId); |
| 122 | if (recognizer != 0) |
| 123 | return recognizer->gestureSignals(); |
| 124 | else |
| 125 | return QStringList(); |
| 126 | } |
| 127 | |
| 128 | /*! |
| 129 | Returns the sensor gesture object for the recognizer \a id. |
| 130 | */ |
| 131 | QSensorGestureRecognizer *QSensorGestureManager::sensorGestureRecognizer(const QString &id) |
| 132 | { |
| 133 | QSensorGestureManagerPrivate *d = QSensorGestureManagerPrivate::instance(); |
| 134 | if (!d) return 0; // hardly likely but just in case... |
| 135 | return d->sensorGestureRecognizer(id); |
| 136 | } |
| 137 | |
| 138 | QT_END_NAMESPACE |
| 139 |
