Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/kernel/qgesturemanager.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    6767#endif
    6868
     69#ifndef QT_NO_GESTURES
     70
    6971QT_BEGIN_NAMESPACE
    7072
    7173QGestureManager::QGestureManager(QObject *parent)
    72     : QObject(parent), state(NotGesture), m_lastCustomGestureId(0)
     74    : QObject(parent), state(NotGesture), m_lastCustomGestureId(Qt::CustomGesture)
    7375{
    7476    qRegisterMetaType<Qt::GestureState>();
     
    118120        // generate a new custom gesture id
    119121        ++m_lastCustomGestureId;
    120         type = Qt::GestureType(Qt::CustomGesture + m_lastCustomGestureId);
     122        type = Qt::GestureType(m_lastCustomGestureId);
    121123    }
    122124    m_recognizers.insertMulti(type, recognizer);
     
    128130{
    129131    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    }
    131138    foreach (QGesture *g, m_gestureToRecognizer.keys()) {
    132139        QGestureRecognizer *recognizer = m_gestureToRecognizer.value(g);
    133140        if (list.contains(recognizer)) {
    134141            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;
    149157    }
    150158}
     
    155163    while (iter != m_objectGestures.end()) {
    156164        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
    159181            iter = m_objectGestures.erase(iter);
    160182        } else {
     
    167189QGesture *QGestureManager::getState(QObject *object, QGestureRecognizer *recognizer, Qt::GestureType type)
    168190{
    169     // if the widget is being deleted we should be carefull and not to
    170     // create a new state, as it will create QWeakPointer which doesnt work
     191    // 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
    171193    // from the destructor.
    172194    if (object->isWidgetType()) {
     
    178200    } else {
    179201        Q_ASSERT(qobject_cast<QGraphicsObject *>(object));
     202        QGraphicsObject *graphicsObject = static_cast<QGraphicsObject *>(object);
     203        if (graphicsObject->QGraphicsItem::d_func()->inDestructor)
     204            return 0;
    180205#endif
    181206    }
     
    272297    QSet<QGesture *> activeToMaybeGestures = m_activeGestures & newMaybeGestures;
    273298
     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
    274302    // check if a running gesture switched back to not gesture state,
    275303    // i.e. were canceled
    276304    QSet<QGesture *> canceledGestures = m_activeGestures & notGestures;
    277305
    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
    285310    QSet<QGesture *> notMaybeGestures = (startedGestures | triggeredGestures
    286311                                         | finishedGestures | canceledGestures
    287312                                         | 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;
    296314
    297315    Q_ASSERT((startedGestures & finishedGestures).isEmpty());
     
    337355        DEBUG() << "QGestureManager::filterEventThroughContexts:"
    338356                << "\n\tactiveGestures:" << m_activeGestures
    339                 << "\n\tmaybeGestures:" << m_maybeGestures.keys()
     357                << "\n\tmaybeGestures:" << m_maybeGestures
    340358                << "\n\tstarted:" << startedGestures
    341359                << "\n\ttriggered:" << triggeredGestures
    342360                << "\n\tfinished:" << finishedGestures
    343                 << "\n\tcanceled:" << canceledGestures;
     361                << "\n\tcanceled:" << canceledGestures
     362                << "\n\tmaybe-canceled:" << maybeToCanceledGestures;
    344363    }
    345364
     
    362381    // reset gestures that ended
    363382    QSet<QGesture *> endedGestures =
    364             finishedGestures + canceledGestures + undeliveredGestures;
     383            finishedGestures + canceledGestures + undeliveredGestures + maybeToCanceledGestures;
    365384    foreach (QGesture *gesture, endedGestures) {
    366385        recycle(gesture);
    367386        m_gestureTargets.remove(gesture);
    368387    }
     388
     389    //Clean up the Gestures
     390    qDeleteAll(m_gesturesToDelete);
     391    m_gesturesToDelete.clear();
     392
    369393    return ret;
    370394}
     
    429453{
    430454    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;
    432457    m_deletedRecognizers.remove(gesture);
    433458    if (m_deletedRecognizers.keys(recognizer).isEmpty()) {
     
    582607                // guess the target widget using the hotspot of the gesture
    583608                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;
    586612                }
    587613            } else {
     
    676702}
    677703
    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 
    698704void QGestureManager::recycle(QGesture *gesture)
    699705{
     
    702708        gesture->setGestureCancelPolicy(QGesture::CancelNone);
    703709        recognizer->reset(gesture);
     710        m_activeGestures.remove(gesture);
    704711    } else {
    705712        cleanupGesturesForRemovedRecognizer(gesture);
     
    709716QT_END_NAMESPACE
    710717
     718#endif // QT_NO_GESTURES
     719
    711720#include "moc_qgesturemanager_p.cpp"
Note: See TracChangeset for help on using the changeset viewer.