OpenCoverage

qgesturerecognizer.cpp

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

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9