Changeset 846 for trunk/src/gui/kernel/qgesturemanager.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/gui/kernel/qgesturemanager.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 67 67 #endif 68 68 69 #ifndef QT_NO_GESTURES 70 69 71 QT_BEGIN_NAMESPACE 70 72 71 73 QGestureManager::QGestureManager(QObject *parent) 72 : QObject(parent), state(NotGesture), m_lastCustomGestureId( 0)74 : QObject(parent), state(NotGesture), m_lastCustomGestureId(Qt::CustomGesture) 73 75 { 74 76 qRegisterMetaType<Qt::GestureState>(); … … 118 120 // generate a new custom gesture id 119 121 ++m_lastCustomGestureId; 120 type = Qt::GestureType( Qt::CustomGesture +m_lastCustomGestureId);122 type = Qt::GestureType(m_lastCustomGestureId); 121 123 } 122 124 m_recognizers.insertMulti(type, recognizer); … … 128 130 { 129 131 QList<QGestureRecognizer *> list = m_recognizers.values(type); 130 m_recognizers.remove(type); 132 while (QGestureRecognizer *recognizer = m_recognizers.take(type)) { 133 if (!m_obsoleteGestures.contains(recognizer)) { 134 // inserting even an empty QSet will cause the recognizer to be deleted on destruction of the manager 135 m_obsoleteGestures.insert(recognizer, QSet<QGesture *>()); 136 } 137 } 131 138 foreach (QGesture *g, m_gestureToRecognizer.keys()) { 132 139 QGestureRecognizer *recognizer = m_gestureToRecognizer.value(g); 133 140 if (list.contains(recognizer)) { 134 141 m_deletedRecognizers.insert(g, recognizer); 135 m_gestureToRecognizer.remove(g); 136 } 137 } 138 139 foreach (QGestureRecognizer *recognizer, list) { 140 QList<QGesture *> obsoleteGestures; 141 QMap<ObjectGesture, QList<QGesture *> >::Iterator iter = m_objectGestures.begin(); 142 while (iter != m_objectGestures.end()) { 143 ObjectGesture objectGesture = iter.key(); 144 if (objectGesture.gesture == type) 145 obsoleteGestures << iter.value(); 146 ++iter; 147 } 148 m_obsoleteGestures.insert(recognizer, obsoleteGestures); 142 } 143 } 144 145 QMap<ObjectGesture, QList<QGesture *> >::const_iterator iter = m_objectGestures.begin(); 146 while (iter != m_objectGestures.end()) { 147 ObjectGesture objectGesture = iter.key(); 148 if (objectGesture.gesture == type) { 149 foreach (QGesture *g, iter.value()) { 150 if (QGestureRecognizer *recognizer = m_gestureToRecognizer.value(g)) { 151 m_gestureToRecognizer.remove(g); 152 m_obsoleteGestures[recognizer].insert(g); 153 } 154 } 155 } 156 ++iter; 149 157 } 150 158 } … … 155 163 while (iter != m_objectGestures.end()) { 156 164 ObjectGesture objectGesture = iter.key(); 157 if (objectGesture.gesture == type && target == objectGesture.object.data()) { 158 qDeleteAll(iter.value()); 165 if (objectGesture.gesture == type && target == objectGesture.object) { 166 QSet<QGesture *> gestures = iter.value().toSet(); 167 for (QHash<QGestureRecognizer *, QSet<QGesture *> >::iterator 168 it = m_obsoleteGestures.begin(), e = m_obsoleteGestures.end(); it != e; ++it) { 169 it.value() -= gestures; 170 } 171 foreach (QGesture *g, gestures) { 172 m_deletedRecognizers.remove(g); 173 m_gestureToRecognizer.remove(g); 174 m_maybeGestures.remove(g); 175 m_activeGestures.remove(g); 176 m_gestureOwners.remove(g); 177 m_gestureTargets.remove(g); 178 m_gesturesToDelete.insert(g); 179 } 180 159 181 iter = m_objectGestures.erase(iter); 160 182 } else { … … 167 189 QGesture *QGestureManager::getState(QObject *object, QGestureRecognizer *recognizer, Qt::GestureType type) 168 190 { 169 // if the widget is being deleted we should be careful l andnot to170 // create a new state, as it will create QWeakPointer which doesn t work191 // if the widget is being deleted we should be careful not to 192 // create a new state, as it will create QWeakPointer which doesn't work 171 193 // from the destructor. 172 194 if (object->isWidgetType()) { … … 178 200 } else { 179 201 Q_ASSERT(qobject_cast<QGraphicsObject *>(object)); 202 QGraphicsObject *graphicsObject = static_cast<QGraphicsObject *>(object); 203 if (graphicsObject->QGraphicsItem::d_func()->inDestructor) 204 return 0; 180 205 #endif 181 206 } … … 272 297 QSet<QGesture *> activeToMaybeGestures = m_activeGestures & newMaybeGestures; 273 298 299 // check if a maybe gesture switched to canceled - reset it but don't send an event 300 QSet<QGesture *> maybeToCanceledGestures = m_maybeGestures & notGestures; 301 274 302 // check if a running gesture switched back to not gesture state, 275 303 // i.e. were canceled 276 304 QSet<QGesture *> canceledGestures = m_activeGestures & notGestures; 277 305 278 // start timers for new gestures in maybe state 279 foreach (QGesture *state, newMaybeGestures) { 280 QBasicTimer &timer = m_maybeGestures[state]; 281 if (!timer.isActive()) 282 timer.start(3000, this); 283 } 284 // kill timers for gestures that were in maybe state 306 // new gestures in maybe state 307 m_maybeGestures += newMaybeGestures; 308 309 // gestures that were in maybe state 285 310 QSet<QGesture *> notMaybeGestures = (startedGestures | triggeredGestures 286 311 | finishedGestures | canceledGestures 287 312 | notGestures); 288 foreach(QGesture *gesture, notMaybeGestures) { 289 QHash<QGesture *, QBasicTimer>::iterator it = 290 m_maybeGestures.find(gesture); 291 if (it != m_maybeGestures.end()) { 292 it.value().stop(); 293 m_maybeGestures.erase(it); 294 } 295 } 313 m_maybeGestures -= notMaybeGestures; 296 314 297 315 Q_ASSERT((startedGestures & finishedGestures).isEmpty()); … … 337 355 DEBUG() << "QGestureManager::filterEventThroughContexts:" 338 356 << "\n\tactiveGestures:" << m_activeGestures 339 << "\n\tmaybeGestures:" << m_maybeGestures .keys()357 << "\n\tmaybeGestures:" << m_maybeGestures 340 358 << "\n\tstarted:" << startedGestures 341 359 << "\n\ttriggered:" << triggeredGestures 342 360 << "\n\tfinished:" << finishedGestures 343 << "\n\tcanceled:" << canceledGestures; 361 << "\n\tcanceled:" << canceledGestures 362 << "\n\tmaybe-canceled:" << maybeToCanceledGestures; 344 363 } 345 364 … … 362 381 // reset gestures that ended 363 382 QSet<QGesture *> endedGestures = 364 finishedGestures + canceledGestures + undeliveredGestures ;383 finishedGestures + canceledGestures + undeliveredGestures + maybeToCanceledGestures; 365 384 foreach (QGesture *gesture, endedGestures) { 366 385 recycle(gesture); 367 386 m_gestureTargets.remove(gesture); 368 387 } 388 389 //Clean up the Gestures 390 qDeleteAll(m_gesturesToDelete); 391 m_gesturesToDelete.clear(); 392 369 393 return ret; 370 394 } … … 429 453 { 430 454 QGestureRecognizer *recognizer = m_deletedRecognizers.value(gesture); 431 Q_ASSERT(recognizer); 455 if(!recognizer) //The Gesture is removed while in the even loop, so the recognizers for this gestures was removed 456 return; 432 457 m_deletedRecognizers.remove(gesture); 433 458 if (m_deletedRecognizers.keys(recognizer).isEmpty()) { … … 582 607 // guess the target widget using the hotspot of the gesture 583 608 QPoint pt = gesture->hotSpot().toPoint(); 584 if (QWidget *w = qApp->topLevelAt(pt)) { 585 target = w->childAt(w->mapFromGlobal(pt)); 609 if (QWidget *topLevel = qApp->topLevelAt(pt)) { 610 QWidget *child = topLevel->childAt(topLevel->mapFromGlobal(pt)); 611 target = child ? child : topLevel; 586 612 } 587 613 } else { … … 676 702 } 677 703 678 void QGestureManager::timerEvent(QTimerEvent *event)679 {680 QHash<QGesture *, QBasicTimer>::iterator it = m_maybeGestures.begin(),681 e = m_maybeGestures.end();682 for (; it != e; ) {683 QBasicTimer &timer = it.value();684 Q_ASSERT(timer.isActive());685 if (timer.timerId() == event->timerId()) {686 timer.stop();687 QGesture *gesture = it.key();688 it = m_maybeGestures.erase(it);689 DEBUG() << "QGestureManager::timerEvent: gesture stopped due to timeout:"690 << gesture;691 recycle(gesture);692 } else {693 ++it;694 }695 }696 }697 698 704 void QGestureManager::recycle(QGesture *gesture) 699 705 { … … 702 708 gesture->setGestureCancelPolicy(QGesture::CancelNone); 703 709 recognizer->reset(gesture); 710 m_activeGestures.remove(gesture); 704 711 } else { 705 712 cleanupGesturesForRemovedRecognizer(gesture); … … 709 716 QT_END_NAMESPACE 710 717 718 #endif // QT_NO_GESTURES 719 711 720 #include "moc_qgesturemanager_p.cpp"
Note:
See TracChangeset
for help on using the changeset viewer.