From 05767badad6408438c6dcffa29318f681522a55a Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Thu, 19 Mar 2009 15:29:51 +0100 Subject: Store the QGestureManager in QApplicationPrivate ... since we don't want these to persist after QApplication has been destroyed --- src/gui/kernel/qapplication.cpp | 26 ++++++++++++++++---------- src/gui/kernel/qapplication_p.h | 2 ++ src/gui/kernel/qgesturemanager.cpp | 4 ++-- src/gui/kernel/qgesturemanager_p.h | 2 +- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index bcc25b9..d9a39c7 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -137,8 +137,6 @@ int QApplicationPrivate::autoMaximizeThreshold = -1; bool QApplicationPrivate::autoSipEnabled = false; #endif -Q_GLOBAL_STATIC(QGestureManager, gestureManager); - QApplicationPrivate::QApplicationPrivate(int &argc, char **argv, QApplication::Type type) : QCoreApplicationPrivate(argc, argv) { @@ -162,6 +160,8 @@ QApplicationPrivate::QApplicationPrivate(int &argc, char **argv, QApplication::T directPainters = 0; #endif + gestureManager = 0; + if (!self) self = this; } @@ -3709,22 +3709,22 @@ bool QApplication::notify(QObject *receiver, QEvent *e) if (e->spontaneous()) { if (QApplication::testAttribute(Qt::AA_EnableGestures)) { QWidget *w = static_cast(receiver); - QGestureManager *gm = gestureManager(); // if we are in gesture mode, we send all mouse events // directly to gesture recognizer. - if (gm->inGestureMode()) { - if (gm->filterEvent(e)) + if (!d->gestureManager) + d->gestureManager = new QGestureManager(this); + if (d->gestureManager->inGestureMode()) { + if (d->gestureManager->filterEvent(e)) return true; } else { - QMouseEvent* mouse = static_cast(e); if (w && (mouse->type() != QEvent::MouseMove || mouse->buttons() != 0)) { // find the gesture target widget QWidget *target = w; while (target && target->d_func()->gestures.isEmpty()) target = target->parentWidget(); if (target) { - gm->setGestureTargetWidget(target); - if (gm->filterEvent(e)) + d->gestureManager->setGestureTargetWidget(target); + if (d->gestureManager->filterEvent(e)) return true; } } @@ -5095,7 +5095,10 @@ bool QApplicationPrivate::shouldSetFocus(QWidget *w, Qt::FocusPolicy policy) */ void QApplication::addGestureRecognizer(QGestureRecognizer *recognizer) { - gestureManager()->addRecognizer(recognizer); + Q_D(QApplication); + if (!d->gestureManager) + d->gestureManager = new QGestureManager(this); + d->gestureManager->addRecognizer(recognizer); } /*! @@ -5105,7 +5108,10 @@ void QApplication::addGestureRecognizer(QGestureRecognizer *recognizer) */ void QApplication::removeGestureRecognizer(QGestureRecognizer *recognizer) { - gestureManager()->removeRecognizer(recognizer); + Q_D(QApplication); + if (!d->gestureManager) + return; + d->gestureManager->removeRecognizer(recognizer); } /*! \fn QDecoration &QApplication::qwsDecoration() diff --git a/src/gui/kernel/qapplication_p.h b/src/gui/kernel/qapplication_p.h index 40cd4ae..a6cb927 100644 --- a/src/gui/kernel/qapplication_p.h +++ b/src/gui/kernel/qapplication_p.h @@ -80,6 +80,7 @@ class QGraphicsSystem; class QInputContext; class QObject; class QWidget; +class QGestureManager; extern bool qt_is_gui_used; #ifndef QT_NO_CLIPBOARD @@ -429,6 +430,7 @@ public: #endif // map number of grabbed widgets (something like refcount) + QGestureManager *gestureManager; QMap grabbedGestures; static void updateTouchPointsForWidget(QWidget *widget, QTouchEvent *touchEvent); diff --git a/src/gui/kernel/qgesturemanager.cpp b/src/gui/kernel/qgesturemanager.cpp index 0e2cea8..753d712 100644 --- a/src/gui/kernel/qgesturemanager.cpp +++ b/src/gui/kernel/qgesturemanager.cpp @@ -64,8 +64,8 @@ bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event); static const unsigned int maximumGestureRecognitionTimeout = 2000; -QGestureManager::QGestureManager() - : targetWidget(0), state(NotGesture) +QGestureManager::QGestureManager(QObject *parent) + : QObject(parent), targetWidget(0), state(NotGesture) { recognizers << new QDoubleTapGestureRecognizer(); recognizers << new QTapAndHoldGestureRecognizer(); diff --git a/src/gui/kernel/qgesturemanager_p.h b/src/gui/kernel/qgesturemanager_p.h index 18eed71..2500ecf 100644 --- a/src/gui/kernel/qgesturemanager_p.h +++ b/src/gui/kernel/qgesturemanager_p.h @@ -67,7 +67,7 @@ class Q_GUI_EXPORT QGestureManager : public QObject { Q_OBJECT public: - QGestureManager(); + QGestureManager(QObject *parent); // should be internal void setGestureTargetWidget(QWidget *widget); -- cgit v0.12