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