author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 3 | 41300fa6a67c |
child 7 | 3f74d0d4af4c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "private/qgesturemanager_p.h" |
|
43 |
#include "private/qstandardgestures_p.h" |
|
44 |
#include "private/qwidget_p.h" |
|
45 |
#include "private/qgesture_p.h" |
|
46 |
#include "private/qgraphicsitem_p.h" |
|
47 |
#include "private/qevent_p.h" |
|
48 |
#include "qgesture.h" |
|
49 |
#include "qevent.h" |
|
50 |
#include "qgraphicsitem.h" |
|
51 |
||
52 |
#ifdef Q_WS_MAC |
|
53 |
#include "qmacgesturerecognizer_mac_p.h" |
|
54 |
#endif |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
55 |
#if defined(Q_OS_WIN) && !defined(QT_NO_NATIVE_GESTURES) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
56 |
#include "qwinnativepangesturerecognizer_win_p.h" |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
57 |
#endif |
0 | 58 |
|
59 |
#include "qdebug.h" |
|
60 |
||
61 |
// #define GESTURE_DEBUG |
|
62 |
#ifndef GESTURE_DEBUG |
|
63 |
# define DEBUG if (0) qDebug |
|
64 |
#else |
|
65 |
# define DEBUG qDebug |
|
66 |
#endif |
|
67 |
||
68 |
QT_BEGIN_NAMESPACE |
|
69 |
||
70 |
QGestureManager::QGestureManager(QObject *parent) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
71 |
: QObject(parent), state(NotGesture), m_lastCustomGestureId(0) |
0 | 72 |
{ |
73 |
qRegisterMetaType<Qt::GestureState>(); |
|
74 |
||
75 |
#if defined(Q_WS_MAC) |
|
76 |
registerGestureRecognizer(new QMacSwipeGestureRecognizer); |
|
77 |
registerGestureRecognizer(new QMacPinchGestureRecognizer); |
|
78 |
#if defined(QT_MAC_USE_COCOA) |
|
79 |
registerGestureRecognizer(new QMacPanGestureRecognizer); |
|
80 |
#endif |
|
81 |
#else |
|
82 |
registerGestureRecognizer(new QPanGestureRecognizer); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
83 |
registerGestureRecognizer(new QPinchGestureRecognizer); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
84 |
registerGestureRecognizer(new QSwipeGestureRecognizer); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
85 |
registerGestureRecognizer(new QTapGestureRecognizer); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
86 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
87 |
#if defined(Q_OS_WIN) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
88 |
#if !defined(QT_NO_NATIVE_GESTURES) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
89 |
registerGestureRecognizer(new QWinNativePanGestureRecognizer); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
90 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
91 |
#else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
92 |
registerGestureRecognizer(new QTapAndHoldGestureRecognizer); |
0 | 93 |
#endif |
94 |
} |
|
95 |
||
96 |
QGestureManager::~QGestureManager() |
|
97 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
98 |
qDeleteAll(m_recognizers.values()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
99 |
foreach (QGestureRecognizer *recognizer, m_obsoleteGestures.keys()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
100 |
qDeleteAll(m_obsoleteGestures.value(recognizer)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
101 |
delete recognizer; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
102 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
103 |
m_obsoleteGestures.clear(); |
0 | 104 |
} |
105 |
||
106 |
Qt::GestureType QGestureManager::registerGestureRecognizer(QGestureRecognizer *recognizer) |
|
107 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
108 |
QGesture *dummy = recognizer->create(0); |
0 | 109 |
if (!dummy) { |
110 |
qWarning("QGestureManager::registerGestureRecognizer: " |
|
111 |
"the recognizer fails to create a gesture object, skipping registration."); |
|
112 |
return Qt::GestureType(0); |
|
113 |
} |
|
114 |
Qt::GestureType type = dummy->gestureType(); |
|
115 |
if (type == Qt::CustomGesture) { |
|
116 |
// generate a new custom gesture id |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
117 |
++m_lastCustomGestureId; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
118 |
type = Qt::GestureType(Qt::CustomGesture + m_lastCustomGestureId); |
0 | 119 |
} |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
120 |
m_recognizers.insertMulti(type, recognizer); |
0 | 121 |
delete dummy; |
122 |
return type; |
|
123 |
} |
|
124 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
125 |
void QGestureManager::unregisterGestureRecognizer(Qt::GestureType type) |
0 | 126 |
{ |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
127 |
QList<QGestureRecognizer *> list = m_recognizers.values(type); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
128 |
m_recognizers.remove(type); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
129 |
foreach (QGesture *g, m_gestureToRecognizer.keys()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
130 |
QGestureRecognizer *recognizer = m_gestureToRecognizer.value(g); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
131 |
if (list.contains(recognizer)) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
132 |
m_deletedRecognizers.insert(g, recognizer); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
133 |
m_gestureToRecognizer.remove(g); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
134 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
135 |
} |
0 | 136 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
137 |
foreach (QGestureRecognizer *recognizer, list) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
138 |
QList<QGesture *> obsoleteGestures; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
139 |
QMap<ObjectGesture, QList<QGesture *> >::Iterator iter = m_objectGestures.begin(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
140 |
while (iter != m_objectGestures.end()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
141 |
ObjectGesture objectGesture = iter.key(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
142 |
if (objectGesture.gesture == type) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
143 |
obsoleteGestures << iter.value(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
144 |
++iter; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
145 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
146 |
m_obsoleteGestures.insert(recognizer, obsoleteGestures); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
147 |
} |
0 | 148 |
} |
149 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
150 |
void QGestureManager::cleanupCachedGestures(QObject *target, Qt::GestureType type) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
151 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
152 |
QMap<ObjectGesture, QList<QGesture *> >::Iterator iter = m_objectGestures.begin(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
153 |
while (iter != m_objectGestures.end()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
154 |
ObjectGesture objectGesture = iter.key(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
155 |
if (objectGesture.gesture == type && target == objectGesture.object.data()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
156 |
qDeleteAll(iter.value()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
157 |
iter = m_objectGestures.erase(iter); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
158 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
159 |
++iter; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
160 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
161 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
162 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
163 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
164 |
// get or create a QGesture object that will represent the state for a given object, used by the recognizer |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
165 |
QGesture *QGestureManager::getState(QObject *object, QGestureRecognizer *recognizer, Qt::GestureType type) |
0 | 166 |
{ |
167 |
// if the widget is being deleted we should be carefull and not to |
|
168 |
// create a new state, as it will create QWeakPointer which doesnt work |
|
169 |
// from the destructor. |
|
170 |
if (object->isWidgetType()) { |
|
171 |
if (static_cast<QWidget *>(object)->d_func()->data.in_destructor) |
|
172 |
return 0; |
|
173 |
} else if (QGesture *g = qobject_cast<QGesture *>(object)) { |
|
174 |
return g; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
175 |
#ifndef QT_NO_GRAPHICSVIEW |
0 | 176 |
} else { |
177 |
Q_ASSERT(qobject_cast<QGraphicsObject *>(object)); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
178 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
179 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
180 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
181 |
// check if the QGesture for this recognizer has already been created |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
182 |
foreach (QGesture *state, m_objectGestures.value(QGestureManager::ObjectGesture(object, type))) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
183 |
if (m_gestureToRecognizer.value(state) == recognizer) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
184 |
return state; |
0 | 185 |
} |
186 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
187 |
Q_ASSERT(recognizer); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
188 |
QGesture *state = recognizer->create(object); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
189 |
if (!state) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
190 |
return 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
191 |
state->setParent(this); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
192 |
if (state->gestureType() == Qt::CustomGesture) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
193 |
// if the recognizer didn't fill in the gesture type, then this |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
194 |
// is a custom gesture with autogenerated id and we fill it. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
195 |
state->d_func()->gestureType = type; |
0 | 196 |
#if defined(GESTURE_DEBUG) |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
197 |
state->setObjectName(QString::number((int)type)); |
0 | 198 |
#endif |
199 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
200 |
m_objectGestures[QGestureManager::ObjectGesture(object, type)].append(state); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
201 |
m_gestureToRecognizer[state] = recognizer; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
202 |
m_gestureOwners[state] = object; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
203 |
|
0 | 204 |
return state; |
205 |
} |
|
206 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
207 |
bool QGestureManager::filterEventThroughContexts(const QMultiMap<QObject *, |
0 | 208 |
Qt::GestureType> &contexts, |
209 |
QEvent *event) |
|
210 |
{ |
|
211 |
QSet<QGesture *> triggeredGestures; |
|
212 |
QSet<QGesture *> finishedGestures; |
|
213 |
QSet<QGesture *> newMaybeGestures; |
|
214 |
QSet<QGesture *> notGestures; |
|
215 |
||
216 |
// TODO: sort contexts by the gesture type and check if one of the contexts |
|
217 |
// is already active. |
|
218 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
219 |
bool ret = false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
220 |
|
0 | 221 |
// filter the event through recognizers |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
222 |
typedef QMultiMap<QObject *, Qt::GestureType>::const_iterator ContextIterator; |
0 | 223 |
for (ContextIterator cit = contexts.begin(), ce = contexts.end(); cit != ce; ++cit) { |
224 |
Qt::GestureType gestureType = cit.value(); |
|
225 |
QMap<Qt::GestureType, QGestureRecognizer *>::const_iterator |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
226 |
rit = m_recognizers.lowerBound(gestureType), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
227 |
re = m_recognizers.upperBound(gestureType); |
0 | 228 |
for (; rit != re; ++rit) { |
229 |
QGestureRecognizer *recognizer = rit.value(); |
|
230 |
QObject *target = cit.key(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
231 |
QGesture *state = getState(target, recognizer, gestureType); |
0 | 232 |
if (!state) |
233 |
continue; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
234 |
QGestureRecognizer::Result result = recognizer->recognize(state, target, event); |
0 | 235 |
QGestureRecognizer::Result type = result & QGestureRecognizer::ResultState_Mask; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
236 |
result &= QGestureRecognizer::ResultHint_Mask; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
237 |
if (type == QGestureRecognizer::TriggerGesture) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
238 |
DEBUG() << "QGestureManager:Recognizer: gesture triggered: " << state; |
0 | 239 |
triggeredGestures << state; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
240 |
} else if (type == QGestureRecognizer::FinishGesture) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
241 |
DEBUG() << "QGestureManager:Recognizer: gesture finished: " << state; |
0 | 242 |
finishedGestures << state; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
243 |
} else if (type == QGestureRecognizer::MayBeGesture) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
244 |
DEBUG() << "QGestureManager:Recognizer: maybe gesture: " << state; |
0 | 245 |
newMaybeGestures << state; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
246 |
} else if (type == QGestureRecognizer::CancelGesture) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
247 |
DEBUG() << "QGestureManager:Recognizer: not gesture: " << state; |
0 | 248 |
notGestures << state; |
249 |
} else if (type == QGestureRecognizer::Ignore) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
250 |
DEBUG() << "QGestureManager:Recognizer: ignored the event: " << state; |
0 | 251 |
} else { |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
252 |
DEBUG() << "QGestureManager:Recognizer: hm, lets assume the recognizer" |
0 | 253 |
<< "ignored the event: " << state; |
254 |
} |
|
255 |
if (result & QGestureRecognizer::ConsumeEventHint) { |
|
256 |
DEBUG() << "QGestureManager: we were asked to consume the event: " |
|
257 |
<< state; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
258 |
ret = true; |
0 | 259 |
} |
260 |
} |
|
261 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
262 |
if (triggeredGestures.isEmpty() && finishedGestures.isEmpty() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
263 |
&& newMaybeGestures.isEmpty() && notGestures.isEmpty()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
264 |
return ret; |
0 | 265 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
266 |
QSet<QGesture *> startedGestures = triggeredGestures - m_activeGestures; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
267 |
triggeredGestures &= m_activeGestures; |
0 | 268 |
|
269 |
// check if a running gesture switched back to maybe state |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
270 |
QSet<QGesture *> activeToMaybeGestures = m_activeGestures & newMaybeGestures; |
0 | 271 |
|
272 |
// check if a running gesture switched back to not gesture state, |
|
273 |
// i.e. were canceled |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
274 |
QSet<QGesture *> canceledGestures = m_activeGestures & notGestures; |
0 | 275 |
|
276 |
// start timers for new gestures in maybe state |
|
277 |
foreach (QGesture *state, newMaybeGestures) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
278 |
QBasicTimer &timer = m_maybeGestures[state]; |
0 | 279 |
if (!timer.isActive()) |
280 |
timer.start(3000, this); |
|
281 |
} |
|
282 |
// kill timers for gestures that were in maybe state |
|
283 |
QSet<QGesture *> notMaybeGestures = (startedGestures | triggeredGestures |
|
284 |
| finishedGestures | canceledGestures |
|
285 |
| notGestures); |
|
286 |
foreach(QGesture *gesture, notMaybeGestures) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
287 |
QHash<QGesture *, QBasicTimer>::iterator it = |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
288 |
m_maybeGestures.find(gesture); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
289 |
if (it != m_maybeGestures.end()) { |
0 | 290 |
it.value().stop(); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
291 |
m_maybeGestures.erase(it); |
0 | 292 |
} |
293 |
} |
|
294 |
||
295 |
Q_ASSERT((startedGestures & finishedGestures).isEmpty()); |
|
296 |
Q_ASSERT((startedGestures & newMaybeGestures).isEmpty()); |
|
297 |
Q_ASSERT((startedGestures & canceledGestures).isEmpty()); |
|
298 |
Q_ASSERT((finishedGestures & newMaybeGestures).isEmpty()); |
|
299 |
Q_ASSERT((finishedGestures & canceledGestures).isEmpty()); |
|
300 |
Q_ASSERT((canceledGestures & newMaybeGestures).isEmpty()); |
|
301 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
302 |
QSet<QGesture *> notStarted = finishedGestures - m_activeGestures; |
0 | 303 |
if (!notStarted.isEmpty()) { |
304 |
// there are some gestures that claim to be finished, but never started. |
|
305 |
// probably those are "singleshot" gestures so we'll fake the started state. |
|
306 |
foreach (QGesture *gesture, notStarted) |
|
307 |
gesture->d_func()->state = Qt::GestureStarted; |
|
308 |
QSet<QGesture *> undeliveredGestures; |
|
309 |
deliverEvents(notStarted, &undeliveredGestures); |
|
310 |
finishedGestures -= undeliveredGestures; |
|
311 |
} |
|
312 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
313 |
m_activeGestures += startedGestures; |
0 | 314 |
// sanity check: all triggered gestures should already be in active gestures list |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
315 |
Q_ASSERT((m_activeGestures & triggeredGestures).size() == triggeredGestures.size()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
316 |
m_activeGestures -= finishedGestures; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
317 |
m_activeGestures -= activeToMaybeGestures; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
318 |
m_activeGestures -= canceledGestures; |
0 | 319 |
|
320 |
// set the proper gesture state on each gesture |
|
321 |
foreach (QGesture *gesture, startedGestures) |
|
322 |
gesture->d_func()->state = Qt::GestureStarted; |
|
323 |
foreach (QGesture *gesture, triggeredGestures) |
|
324 |
gesture->d_func()->state = Qt::GestureUpdated; |
|
325 |
foreach (QGesture *gesture, finishedGestures) |
|
326 |
gesture->d_func()->state = Qt::GestureFinished; |
|
327 |
foreach (QGesture *gesture, canceledGestures) |
|
328 |
gesture->d_func()->state = Qt::GestureCanceled; |
|
329 |
foreach (QGesture *gesture, activeToMaybeGestures) |
|
330 |
gesture->d_func()->state = Qt::GestureFinished; |
|
331 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
332 |
if (!m_activeGestures.isEmpty() || !m_maybeGestures.isEmpty() || |
0 | 333 |
!startedGestures.isEmpty() || !triggeredGestures.isEmpty() || |
334 |
!finishedGestures.isEmpty() || !canceledGestures.isEmpty()) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
335 |
DEBUG() << "QGestureManager::filterEventThroughContexts:" |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
336 |
<< "\n\tactiveGestures:" << m_activeGestures |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
337 |
<< "\n\tmaybeGestures:" << m_maybeGestures.keys() |
0 | 338 |
<< "\n\tstarted:" << startedGestures |
339 |
<< "\n\ttriggered:" << triggeredGestures |
|
340 |
<< "\n\tfinished:" << finishedGestures |
|
341 |
<< "\n\tcanceled:" << canceledGestures; |
|
342 |
} |
|
343 |
||
344 |
QSet<QGesture *> undeliveredGestures; |
|
345 |
deliverEvents(startedGestures+triggeredGestures+finishedGestures+canceledGestures, |
|
346 |
&undeliveredGestures); |
|
347 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
348 |
foreach (QGesture *g, startedGestures) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
349 |
if (undeliveredGestures.contains(g)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
350 |
continue; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
351 |
if (g->gestureCancelPolicy() == QGesture::CancelAllInContext) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
352 |
DEBUG() << "lets try to cancel some"; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
353 |
// find gestures in context in Qt::GestureStarted or Qt::GestureUpdated state and cancel them |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
354 |
cancelGesturesForChildren(g); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
355 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
356 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
357 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
358 |
m_activeGestures -= undeliveredGestures; |
0 | 359 |
|
360 |
// reset gestures that ended |
|
361 |
QSet<QGesture *> endedGestures = |
|
362 |
finishedGestures + canceledGestures + undeliveredGestures; |
|
363 |
foreach (QGesture *gesture, endedGestures) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
364 |
recycle(gesture); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
365 |
m_gestureTargets.remove(gesture); |
0 | 366 |
} |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
367 |
return ret; |
0 | 368 |
} |
369 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
370 |
// Cancel all gestures of children of the widget that original is associated with |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
371 |
void QGestureManager::cancelGesturesForChildren(QGesture *original) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
372 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
373 |
Q_ASSERT(original); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
374 |
QWidget *originatingWidget = m_gestureTargets.value(original); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
375 |
Q_ASSERT(originatingWidget); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
376 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
377 |
// iterate over all active gestures and all maybe gestures |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
378 |
// for each find the owner |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
379 |
// if the owner is part of our sub-hierarchy, cancel it. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
380 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
381 |
QSet<QGesture*> cancelledGestures; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
382 |
QSet<QGesture*>::Iterator iter = m_activeGestures.begin(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
383 |
while (iter != m_activeGestures.end()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
384 |
QWidget *widget = m_gestureTargets.value(*iter); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
385 |
// note that we don't touch the gestures for our originatingWidget |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
386 |
if (widget != originatingWidget && originatingWidget->isAncestorOf(widget)) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
387 |
DEBUG() << " found a gesture to cancel" << (*iter); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
388 |
(*iter)->d_func()->state = Qt::GestureCanceled; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
389 |
cancelledGestures << *iter; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
390 |
iter = m_activeGestures.erase(iter); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
391 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
392 |
++iter; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
393 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
394 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
395 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
396 |
// TODO handle 'maybe' gestures too |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
397 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
398 |
// sort them per target widget by cherry picking from almostCanceledGestures and delivering |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
399 |
QSet<QGesture *> almostCanceledGestures = cancelledGestures; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
400 |
while (!almostCanceledGestures.isEmpty()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
401 |
QWidget *target = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
402 |
QSet<QGesture*> gestures; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
403 |
iter = almostCanceledGestures.begin(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
404 |
// sort per target widget |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
405 |
while (iter != almostCanceledGestures.end()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
406 |
QWidget *widget = m_gestureTargets.value(*iter); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
407 |
if (target == 0) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
408 |
target = widget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
409 |
if (target == widget) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
410 |
gestures << *iter; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
411 |
iter = almostCanceledGestures.erase(iter); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
412 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
413 |
++iter; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
414 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
415 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
416 |
Q_ASSERT(target); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
417 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
418 |
QSet<QGesture*> undeliveredGestures; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
419 |
deliverEvents(gestures, &undeliveredGestures); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
420 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
421 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
422 |
for (iter = cancelledGestures.begin(); iter != cancelledGestures.end(); ++iter) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
423 |
recycle(*iter); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
424 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
425 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
426 |
void QGestureManager::cleanupGesturesForRemovedRecognizer(QGesture *gesture) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
427 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
428 |
QGestureRecognizer *recognizer = m_deletedRecognizers.value(gesture); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
429 |
Q_ASSERT(recognizer); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
430 |
m_deletedRecognizers.remove(gesture); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
431 |
if (m_deletedRecognizers.keys(recognizer).isEmpty()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
432 |
// no more active gestures, cleanup! |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
433 |
qDeleteAll(m_obsoleteGestures.value(recognizer)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
434 |
m_obsoleteGestures.remove(recognizer); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
435 |
delete recognizer; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
436 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
437 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
438 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
439 |
// return true if accepted (consumed) |
0 | 440 |
bool QGestureManager::filterEvent(QWidget *receiver, QEvent *event) |
441 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
442 |
QMap<Qt::GestureType, int> types; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
443 |
QMultiMap<QObject *, Qt::GestureType> contexts; |
0 | 444 |
QWidget *w = receiver; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
445 |
typedef QMap<Qt::GestureType, Qt::GestureFlags>::const_iterator ContextIterator; |
0 | 446 |
if (!w->d_func()->gestureContext.isEmpty()) { |
447 |
for(ContextIterator it = w->d_func()->gestureContext.begin(), |
|
448 |
e = w->d_func()->gestureContext.end(); it != e; ++it) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
449 |
types.insert(it.key(), 0); |
0 | 450 |
contexts.insertMulti(w, it.key()); |
451 |
} |
|
452 |
} |
|
453 |
// find all gesture contexts for the widget tree |
|
454 |
w = w->isWindow() ? 0 : w->parentWidget(); |
|
455 |
while (w) |
|
456 |
{ |
|
457 |
for (ContextIterator it = w->d_func()->gestureContext.begin(), |
|
458 |
e = w->d_func()->gestureContext.end(); it != e; ++it) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
459 |
if (!(it.value() & Qt::DontStartGestureOnChildren)) { |
0 | 460 |
if (!types.contains(it.key())) { |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
461 |
types.insert(it.key(), 0); |
0 | 462 |
contexts.insertMulti(w, it.key()); |
463 |
} |
|
464 |
} |
|
465 |
} |
|
466 |
if (w->isWindow()) |
|
467 |
break; |
|
468 |
w = w->parentWidget(); |
|
469 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
470 |
return contexts.isEmpty() ? false : filterEventThroughContexts(contexts, event); |
0 | 471 |
} |
472 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
473 |
#ifndef QT_NO_GRAPHICSVIEW |
0 | 474 |
bool QGestureManager::filterEvent(QGraphicsObject *receiver, QEvent *event) |
475 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
476 |
QMap<Qt::GestureType, int> types; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
477 |
QMultiMap<QObject *, Qt::GestureType> contexts; |
0 | 478 |
QGraphicsObject *item = receiver; |
479 |
if (!item->QGraphicsItem::d_func()->gestureContext.isEmpty()) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
480 |
typedef QMap<Qt::GestureType, Qt::GestureFlags>::const_iterator ContextIterator; |
0 | 481 |
for(ContextIterator it = item->QGraphicsItem::d_func()->gestureContext.begin(), |
482 |
e = item->QGraphicsItem::d_func()->gestureContext.end(); it != e; ++it) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
483 |
types.insert(it.key(), 0); |
0 | 484 |
contexts.insertMulti(item, it.key()); |
485 |
} |
|
486 |
} |
|
487 |
// find all gesture contexts for the graphics object tree |
|
488 |
item = item->parentObject(); |
|
489 |
while (item) |
|
490 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
491 |
typedef QMap<Qt::GestureType, Qt::GestureFlags>::const_iterator ContextIterator; |
0 | 492 |
for (ContextIterator it = item->QGraphicsItem::d_func()->gestureContext.begin(), |
493 |
e = item->QGraphicsItem::d_func()->gestureContext.end(); it != e; ++it) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
494 |
if (!(it.value() & Qt::DontStartGestureOnChildren)) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
495 |
if (!types.contains(it.key())) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
496 |
types.insert(it.key(), 0); |
0 | 497 |
contexts.insertMulti(item, it.key()); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
498 |
} |
0 | 499 |
} |
500 |
} |
|
501 |
item = item->parentObject(); |
|
502 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
503 |
return contexts.isEmpty() ? false : filterEventThroughContexts(contexts, event); |
0 | 504 |
} |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
505 |
#endif |
0 | 506 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
507 |
bool QGestureManager::filterEvent(QObject *receiver, QEvent *event) |
0 | 508 |
{ |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
509 |
if (!m_gestureToRecognizer.contains(static_cast<QGesture *>(receiver))) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
510 |
return false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
511 |
QGesture *state = static_cast<QGesture *>(receiver); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
512 |
QMultiMap<QObject *, Qt::GestureType> contexts; |
0 | 513 |
contexts.insert(state, state->gestureType()); |
514 |
return filterEventThroughContexts(contexts, event); |
|
515 |
} |
|
516 |
||
517 |
void QGestureManager::getGestureTargets(const QSet<QGesture*> &gestures, |
|
518 |
QMap<QWidget *, QList<QGesture *> > *conflicts, |
|
519 |
QMap<QWidget *, QList<QGesture *> > *normal) |
|
520 |
{ |
|
521 |
typedef QHash<Qt::GestureType, QHash<QWidget *, QGesture *> > GestureByTypes; |
|
522 |
GestureByTypes gestureByTypes; |
|
523 |
||
524 |
// sort gestures by types |
|
525 |
foreach (QGesture *gesture, gestures) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
526 |
QWidget *receiver = m_gestureTargets.value(gesture, 0); |
0 | 527 |
Q_ASSERT(receiver); |
528 |
gestureByTypes[gesture->gestureType()].insert(receiver, gesture); |
|
529 |
} |
|
530 |
||
531 |
// for each gesture type |
|
532 |
foreach (Qt::GestureType type, gestureByTypes.keys()) { |
|
533 |
QHash<QWidget *, QGesture *> gestures = gestureByTypes.value(type); |
|
534 |
foreach (QWidget *widget, gestures.keys()) { |
|
535 |
QWidget *w = widget->parentWidget(); |
|
536 |
while (w) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
537 |
QMap<Qt::GestureType, Qt::GestureFlags>::const_iterator it |
0 | 538 |
= w->d_func()->gestureContext.find(type); |
539 |
if (it != w->d_func()->gestureContext.end()) { |
|
540 |
// i.e. 'w' listens to gesture 'type' |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
541 |
Qt::GestureFlags flags = it.value(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
542 |
if (!(it.value() & Qt::DontStartGestureOnChildren) && w != widget) { |
0 | 543 |
// conflicting gesture! |
544 |
(*conflicts)[widget].append(gestures[widget]); |
|
545 |
break; |
|
546 |
} |
|
547 |
} |
|
548 |
if (w->isWindow()) { |
|
549 |
w = 0; |
|
550 |
break; |
|
551 |
} |
|
552 |
w = w->parentWidget(); |
|
553 |
} |
|
554 |
if (!w) |
|
555 |
(*normal)[widget].append(gestures[widget]); |
|
556 |
} |
|
557 |
} |
|
558 |
} |
|
559 |
||
560 |
void QGestureManager::deliverEvents(const QSet<QGesture *> &gestures, |
|
561 |
QSet<QGesture *> *undeliveredGestures) |
|
562 |
{ |
|
563 |
if (gestures.isEmpty()) |
|
564 |
return; |
|
565 |
||
566 |
typedef QMap<QWidget *, QList<QGesture *> > GesturesPerWidget; |
|
567 |
GesturesPerWidget conflictedGestures; |
|
568 |
GesturesPerWidget normalStartedGestures; |
|
569 |
||
570 |
QSet<QGesture *> startedGestures; |
|
571 |
// first figure out the initial receivers of gestures |
|
572 |
for (QSet<QGesture *>::const_iterator it = gestures.begin(), |
|
573 |
e = gestures.end(); it != e; ++it) { |
|
574 |
QGesture *gesture = *it; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
575 |
QWidget *target = m_gestureTargets.value(gesture, 0); |
0 | 576 |
if (!target) { |
577 |
// the gesture has just started and doesn't have a target yet. |
|
578 |
Q_ASSERT(gesture->state() == Qt::GestureStarted); |
|
579 |
if (gesture->hasHotSpot()) { |
|
580 |
// guess the target widget using the hotspot of the gesture |
|
581 |
QPoint pt = gesture->hotSpot().toPoint(); |
|
582 |
if (QWidget *w = qApp->topLevelAt(pt)) { |
|
583 |
target = w->childAt(w->mapFromGlobal(pt)); |
|
584 |
} |
|
585 |
} else { |
|
586 |
// or use the context of the gesture |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
587 |
QObject *context = m_gestureOwners.value(gesture, 0); |
0 | 588 |
if (context->isWidgetType()) |
589 |
target = static_cast<QWidget *>(context); |
|
590 |
} |
|
591 |
if (target) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
592 |
m_gestureTargets.insert(gesture, target); |
0 | 593 |
} |
594 |
||
595 |
Qt::GestureType gestureType = gesture->gestureType(); |
|
596 |
Q_ASSERT(gestureType != Qt::CustomGesture); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
597 |
Q_UNUSED(gestureType); |
0 | 598 |
|
599 |
if (target) { |
|
600 |
if (gesture->state() == Qt::GestureStarted) { |
|
601 |
startedGestures.insert(gesture); |
|
602 |
} else { |
|
603 |
normalStartedGestures[target].append(gesture); |
|
604 |
} |
|
605 |
} else { |
|
606 |
DEBUG() << "QGestureManager::deliverEvent: could not find the target for gesture" |
|
607 |
<< gesture->gestureType(); |
|
608 |
qWarning("QGestureManager::deliverEvent: could not find the target for gesture"); |
|
609 |
undeliveredGestures->insert(gesture); |
|
610 |
} |
|
611 |
} |
|
612 |
||
613 |
getGestureTargets(startedGestures, &conflictedGestures, &normalStartedGestures); |
|
614 |
DEBUG() << "QGestureManager::deliverEvents:" |
|
615 |
<< "\nstarted: " << startedGestures |
|
616 |
<< "\nconflicted: " << conflictedGestures |
|
617 |
<< "\nnormal: " << normalStartedGestures |
|
618 |
<< "\n"; |
|
619 |
||
620 |
// if there are conflicting gestures, send the GestureOverride event |
|
621 |
for (GesturesPerWidget::const_iterator it = conflictedGestures.begin(), |
|
622 |
e = conflictedGestures.end(); it != e; ++it) { |
|
623 |
QWidget *receiver = it.key(); |
|
624 |
QList<QGesture *> gestures = it.value(); |
|
625 |
DEBUG() << "QGestureManager::deliverEvents: sending GestureOverride to" |
|
626 |
<< receiver |
|
627 |
<< "gestures:" << gestures; |
|
628 |
QGestureEvent event(gestures); |
|
629 |
event.t = QEvent::GestureOverride; |
|
630 |
// mark event and individual gestures as ignored |
|
631 |
event.ignore(); |
|
632 |
foreach(QGesture *g, gestures) |
|
633 |
event.setAccepted(g, false); |
|
634 |
||
635 |
QApplication::sendEvent(receiver, &event); |
|
636 |
bool eventAccepted = event.isAccepted(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
637 |
foreach(QGesture *gesture, event.gestures()) { |
0 | 638 |
if (eventAccepted || event.isAccepted(gesture)) { |
639 |
QWidget *w = event.d_func()->targetWidgets.value(gesture->gestureType(), 0); |
|
640 |
Q_ASSERT(w); |
|
641 |
DEBUG() << "override event: gesture was accepted:" << gesture << w; |
|
642 |
QList<QGesture *> &gestures = normalStartedGestures[w]; |
|
643 |
gestures.append(gesture); |
|
644 |
// override the target |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
645 |
m_gestureTargets[gesture] = w; |
0 | 646 |
} else { |
647 |
DEBUG() << "override event: gesture wasn't accepted. putting back:" << gesture; |
|
648 |
QList<QGesture *> &gestures = normalStartedGestures[receiver]; |
|
649 |
gestures.append(gesture); |
|
650 |
} |
|
651 |
} |
|
652 |
} |
|
653 |
||
654 |
// delivering gestures that are not in conflicted state |
|
655 |
for (GesturesPerWidget::const_iterator it = normalStartedGestures.begin(), |
|
656 |
e = normalStartedGestures.end(); it != e; ++it) { |
|
657 |
if (!it.value().isEmpty()) { |
|
658 |
DEBUG() << "QGestureManager::deliverEvents: sending to" << it.key() |
|
659 |
<< "gestures:" << it.value(); |
|
660 |
QGestureEvent event(it.value()); |
|
661 |
QApplication::sendEvent(it.key(), &event); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
662 |
bool eventAccepted = event.isAccepted(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
663 |
foreach (QGesture *gesture, event.gestures()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
664 |
if (gesture->state() == Qt::GestureStarted && |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
665 |
(eventAccepted || event.isAccepted(gesture))) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
666 |
QWidget *w = event.d_func()->targetWidgets.value(gesture->gestureType(), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
667 |
Q_ASSERT(w); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
668 |
DEBUG() << "started gesture was delivered and accepted by" << w; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
669 |
m_gestureTargets[gesture] = w; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
670 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
671 |
} |
0 | 672 |
} |
673 |
} |
|
674 |
} |
|
675 |
||
676 |
void QGestureManager::timerEvent(QTimerEvent *event) |
|
677 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
678 |
QHash<QGesture *, QBasicTimer>::iterator it = m_maybeGestures.begin(), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
679 |
e = m_maybeGestures.end(); |
0 | 680 |
for (; it != e; ) { |
681 |
QBasicTimer &timer = it.value(); |
|
682 |
Q_ASSERT(timer.isActive()); |
|
683 |
if (timer.timerId() == event->timerId()) { |
|
684 |
timer.stop(); |
|
685 |
QGesture *gesture = it.key(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
686 |
it = m_maybeGestures.erase(it); |
0 | 687 |
DEBUG() << "QGestureManager::timerEvent: gesture stopped due to timeout:" |
688 |
<< gesture; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
689 |
recycle(gesture); |
0 | 690 |
} else { |
691 |
++it; |
|
692 |
} |
|
693 |
} |
|
694 |
} |
|
695 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
696 |
void QGestureManager::recycle(QGesture *gesture) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
697 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
698 |
QGestureRecognizer *recognizer = m_gestureToRecognizer.value(gesture, 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
699 |
if (recognizer) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
700 |
gesture->setGestureCancelPolicy(QGesture::CancelNone); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
701 |
recognizer->reset(gesture); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
702 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
703 |
cleanupGesturesForRemovedRecognizer(gesture); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
704 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
705 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
706 |
|
0 | 707 |
QT_END_NAMESPACE |
708 |
||
709 |
#include "moc_qgesturemanager_p.cpp" |