| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/kernel/qgesturerecognizer.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||
| 2 | ** | - | ||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||
| 5 | ** | - | ||||||
| 6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||
| 7 | ** | - | ||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||
| 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 http://www.qt.io/terms-conditions. For further | - | ||||||
| 15 | ** information use the contact form at http://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 2.1 or version 3 as published by the Free | - | ||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||
| 25 | ** | - | ||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||
| 29 | ** | - | ||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||
| 31 | ** | - | ||||||
| 32 | ****************************************************************************/ | - | ||||||
| 33 | - | |||||||
| 34 | #include "qgesturerecognizer.h" | - | ||||||
| 35 | - | |||||||
| 36 | #include "private/qgesture_p.h" | - | ||||||
| 37 | #include "private/qgesturemanager_p.h" | - | ||||||
| 38 | - | |||||||
| 39 | #ifndef QT_NO_GESTURES | - | ||||||
| 40 | - | |||||||
| 41 | QT_BEGIN_NAMESPACE | - | ||||||
| 42 | - | |||||||
| 43 | /*! | - | ||||||
| 44 | \class QGestureRecognizer | - | ||||||
| 45 | \since 4.6 | - | ||||||
| 46 | \brief The QGestureRecognizer class provides the infrastructure for gesture recognition. | - | ||||||
| 47 | \ingroup gestures | - | ||||||
| 48 | \inmodule QtWidgets | - | ||||||
| 49 | - | |||||||
| 50 | Gesture recognizers are responsible for creating and managing QGesture objects and | - | ||||||
| 51 | monitoring input events sent to QWidget and QGraphicsObject subclasses. | - | ||||||
| 52 | QGestureRecognizer is the base class for implementing custom gestures. | - | ||||||
| 53 | - | |||||||
| 54 | Developers that only need to provide gesture recognition for standard gestures do not | - | ||||||
| 55 | need to use this class directly. Instances will be created behind the scenes by the | - | ||||||
| 56 | framework. | - | ||||||
| 57 | - | |||||||
| 58 | For an overview of gesture handling in Qt and information on using gestures | - | ||||||
| 59 | in your applications, see the \l{Gestures in Widgets and Graphics View} document. | - | ||||||
| 60 | - | |||||||
| 61 | \section1 Recognizing Gestures | - | ||||||
| 62 | - | |||||||
| 63 | The process of recognizing gestures involves filtering input events sent to specific | - | ||||||
| 64 | objects, and modifying the associated QGesture objects to include relevant information | - | ||||||
| 65 | about the user's input. | - | ||||||
| 66 | - | |||||||
| 67 | Gestures are created when the framework calls create() to handle user input | - | ||||||
| 68 | for a particular instance of a QWidget or QGraphicsObject subclass. A QGesture object | - | ||||||
| 69 | is created for each widget or item that is configured to use gestures. | - | ||||||
| 70 | - | |||||||
| 71 | Once a QGesture has been created for a target object, the gesture recognizer will | - | ||||||
| 72 | receive events for it in its recognize() handler function. | - | ||||||
| 73 | - | |||||||
| 74 | When a gesture is canceled, the reset() function is called, giving the recognizer the | - | ||||||
| 75 | chance to update the appropriate properties in the corresponding QGesture object. | - | ||||||
| 76 | - | |||||||
| 77 | \section1 Supporting New Gestures | - | ||||||
| 78 | - | |||||||
| 79 | To add support for new gestures, you need to derive from QGestureRecognizer to create | - | ||||||
| 80 | a custom recognizer class, construct an instance of this class, and register it with | - | ||||||
| 81 | the application by calling QGestureRecognizer::registerRecognizer(). You can also | - | ||||||
| 82 | subclass QGesture to create a custom gesture class, or rely on dynamic properties | - | ||||||
| 83 | to express specific details of the gesture you want to handle. | - | ||||||
| 84 | - | |||||||
| 85 | Your custom QGestureRecognizer subclass needs to reimplement the recognize() | - | ||||||
| 86 | function to handle and filter the incoming input events for QWidget and | - | ||||||
| 87 | QGraphicsObject subclasses. Although the logic for gesture recognition is | - | ||||||
| 88 | implemented in this function, you can store persistent information about the | - | ||||||
| 89 | state of the recognition process in the QGesture object supplied. The | - | ||||||
| 90 | recognize() function must return a value of QGestureRecognizer::Result that | - | ||||||
| 91 | indicates the state of recognition for a given gesture and target object. | - | ||||||
| 92 | This determines whether or not a gesture event will be delivered to a target | - | ||||||
| 93 | object. | - | ||||||
| 94 | - | |||||||
| 95 | If you choose to represent a gesture by a custom QGesture subclass, you will need to | - | ||||||
| 96 | reimplement the create() function to construct instances of your gesture class. | - | ||||||
| 97 | Similarly, you may need to reimplement the reset() function if your custom gesture | - | ||||||
| 98 | objects need to be specially handled when a gesture is canceled. | - | ||||||
| 99 | - | |||||||
| 100 | \sa QGesture | - | ||||||
| 101 | */ | - | ||||||
| 102 | - | |||||||
| 103 | /*! | - | ||||||
| 104 | \enum QGestureRecognizer::ResultFlag | - | ||||||
| 105 | - | |||||||
| 106 | This enum describes the result of the current event filtering step in | - | ||||||
| 107 | a gesture recognizer state machine. | - | ||||||
| 108 | - | |||||||
| 109 | The result consists of a state value (one of Ignore, MayBeGesture, | - | ||||||
| 110 | TriggerGesture, FinishGesture, CancelGesture) and an optional hint | - | ||||||
| 111 | (ConsumeEventHint). | - | ||||||
| 112 | - | |||||||
| 113 | \value Ignore The event does not change the state of the recognizer. | - | ||||||
| 114 | - | |||||||
| 115 | \value MayBeGesture The event changed the internal state of the recognizer, | - | ||||||
| 116 | but it isn't clear yet if it is a gesture or not. The recognizer needs to | - | ||||||
| 117 | filter more events to decide. Gesture recognizers in the MayBeGesture state | - | ||||||
| 118 | may be reset automatically if they take too long to recognize gestures. | - | ||||||
| 119 | - | |||||||
| 120 | \value TriggerGesture The gesture has been triggered and the appropriate | - | ||||||
| 121 | QGesture object will be delivered to the target as a part of a | - | ||||||
| 122 | QGestureEvent. | - | ||||||
| 123 | - | |||||||
| 124 | \value FinishGesture The gesture has been finished successfully and the | - | ||||||
| 125 | appropriate QGesture object will be delivered to the target as a part of a | - | ||||||
| 126 | QGestureEvent. | - | ||||||
| 127 | - | |||||||
| 128 | \value CancelGesture The event made it clear that it is not a gesture. If | - | ||||||
| 129 | the gesture recognizer was in GestureTriggered state before, then the | - | ||||||
| 130 | gesture is canceled and the appropriate QGesture object will be delivered | - | ||||||
| 131 | to the target as a part of a QGestureEvent. | - | ||||||
| 132 | - | |||||||
| 133 | \value ConsumeEventHint This hint specifies that the gesture framework | - | ||||||
| 134 | should consume the filtered event and not deliver it to the receiver. | - | ||||||
| 135 | - | |||||||
| 136 | \omitvalue ResultState_Mask | - | ||||||
| 137 | \omitvalue ResultHint_Mask | - | ||||||
| 138 | - | |||||||
| 139 | \sa QGestureRecognizer::recognize() | - | ||||||
| 140 | */ | - | ||||||
| 141 | - | |||||||
| 142 | /*! | - | ||||||
| 143 | Constructs a new gesture recognizer object. | - | ||||||
| 144 | */ | - | ||||||
| 145 | QGestureRecognizer::QGestureRecognizer() | - | ||||||
| 146 | { | - | ||||||
| 147 | } | - | ||||||
| 148 | - | |||||||
| 149 | /*! | - | ||||||
| 150 | Destroys the gesture recognizer. | - | ||||||
| 151 | */ | - | ||||||
| 152 | QGestureRecognizer::~QGestureRecognizer() | - | ||||||
| 153 | { | - | ||||||
| 154 | } | - | ||||||
| 155 | - | |||||||
| 156 | /*! | - | ||||||
| 157 | This function is called by Qt to create a new QGesture object for the | - | ||||||
| 158 | given \a target (QWidget or QGraphicsObject). | - | ||||||
| 159 | - | |||||||
| 160 | Reimplement this function to create a custom QGesture-derived gesture | - | ||||||
| 161 | object if necessary. | - | ||||||
| 162 | - | |||||||
| 163 | The application takes ownership of the created gesture object. | - | ||||||
| 164 | */ | - | ||||||
| 165 | QGesture *QGestureRecognizer::create(QObject *target) | - | ||||||
| 166 | { | - | ||||||
| 167 | Q_UNUSED(target); | - | ||||||
| 168 | return new QGesture; never executed: return new QGesture; | 0 | ||||||
| 169 | } | - | ||||||
| 170 | - | |||||||
| 171 | /*! | - | ||||||
| 172 | This function is called by the framework to reset a given \a gesture. | - | ||||||
| 173 | - | |||||||
| 174 | Reimplement this function to implement additional requirements for custom QGesture | - | ||||||
| 175 | objects. This may be necessary if you implement a custom QGesture whose properties | - | ||||||
| 176 | need special handling when the gesture is reset. | - | ||||||
| 177 | */ | - | ||||||
| 178 | void QGestureRecognizer::reset(QGesture *gesture) | - | ||||||
| 179 | { | - | ||||||
| 180 | if (gesture) {
| 0 | ||||||
| 181 | QGesturePrivate *d = gesture->d_func(); | - | ||||||
| 182 | d->state = Qt::NoGesture; | - | ||||||
| 183 | d->hotSpot = QPointF(); | - | ||||||
| 184 | d->sceneHotSpot = QPointF(); | - | ||||||
| 185 | d->isHotSpotSet = false; | - | ||||||
| 186 | } never executed: end of block | 0 | ||||||
| 187 | } never executed: end of block | 0 | ||||||
| 188 | - | |||||||
| 189 | /*! | - | ||||||
| 190 | \fn QGestureRecognizer::recognize(QGesture *gesture, QObject *watched, QEvent *event) | - | ||||||
| 191 | - | |||||||
| 192 | Handles the given \a event for the \a watched object, updating the state of the \a gesture | - | ||||||
| 193 | object as required, and returns a suitable result for the current recognition step. | - | ||||||
| 194 | - | |||||||
| 195 | This function is called by the framework to allow the recognizer to filter input events | - | ||||||
| 196 | dispatched to QWidget or QGraphicsObject instances that it is monitoring. | - | ||||||
| 197 | - | |||||||
| 198 | The result reflects how much of the gesture has been recognized. The state of the | - | ||||||
| 199 | \a gesture object is set depending on the result. | - | ||||||
| 200 | - | |||||||
| 201 | \sa QGestureRecognizer::Result | - | ||||||
| 202 | */ | - | ||||||
| 203 | - | |||||||
| 204 | /*! | - | ||||||
| 205 | Registers the given \a recognizer in the gesture framework and returns a gesture ID | - | ||||||
| 206 | for it. | - | ||||||
| 207 | - | |||||||
| 208 | The application takes ownership of the \a recognizer and returns the gesture type | - | ||||||
| 209 | ID associated with it. For gesture recognizers which handle custom QGesture | - | ||||||
| 210 | objects (i.e., those which return Qt::CustomGesture in a QGesture::gestureType() | - | ||||||
| 211 | function) the return value is a generated gesture ID with the Qt::CustomGesture | - | ||||||
| 212 | flag set. | - | ||||||
| 213 | - | |||||||
| 214 | \sa unregisterRecognizer(), QGestureRecognizer::create(), QGesture | - | ||||||
| 215 | */ | - | ||||||
| 216 | Qt::GestureType QGestureRecognizer::registerRecognizer(QGestureRecognizer *recognizer) | - | ||||||
| 217 | { | - | ||||||
| 218 | return QGestureManager::instance()->registerGestureRecognizer(recognizer); never executed: return QGestureManager::instance()->registerGestureRecognizer(recognizer); | 0 | ||||||
| 219 | } | - | ||||||
| 220 | - | |||||||
| 221 | /*! | - | ||||||
| 222 | Unregisters all gesture recognizers of the specified \a type. | - | ||||||
| 223 | - | |||||||
| 224 | \sa registerRecognizer() | - | ||||||
| 225 | */ | - | ||||||
| 226 | void QGestureRecognizer::unregisterRecognizer(Qt::GestureType type) | - | ||||||
| 227 | { | - | ||||||
| 228 | QGestureManager::instance()->unregisterGestureRecognizer(type); | - | ||||||
| 229 | } never executed: end of block | 0 | ||||||
| 230 | - | |||||||
| 231 | QT_END_NAMESPACE | - | ||||||
| 232 | - | |||||||
| 233 | #endif // QT_NO_GESTURES | - | ||||||
| Source code | Switch to Preprocessed file |