summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorDenis Dzyubenko <denis.dzyubenko@nokia.com>2009-04-29 12:15:17 (GMT)
committerDenis Dzyubenko <denis.dzyubenko@nokia.com>2009-05-11 14:52:01 (GMT)
commita321909ced9fe28ea476ab95c7c7592db5090acc (patch)
treec3aa428dbc21785bb087a6cb8f3ac86bcbb7c637 /src/gui
parentba7485012033b0447a9e77d5612db734f9dcffd6 (diff)
downloadQt-a321909ced9fe28ea476ab95c7c7592db5090acc.zip
Qt-a321909ced9fe28ea476ab95c7c7592db5090acc.tar.gz
Qt-a321909ced9fe28ea476ab95c7c7592db5090acc.tar.bz2
Generalized gesture filtering code to allow handling not only mouse
events in gesture recognizers.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/kernel/qapplication.cpp35
-rw-r--r--src/gui/kernel/qgesturemanager.cpp15
-rw-r--r--src/gui/kernel/qgesturemanager_p.h2
-rw-r--r--src/gui/kernel/qgesturerecognizer.cpp11
-rw-r--r--src/gui/kernel/qgesturerecognizer.h3
-rw-r--r--src/gui/kernel/qgesturestandardrecognizers.cpp6
6 files changed, 38 insertions, 34 deletions
diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp
index ebd62e6..9772e0f 100644
--- a/src/gui/kernel/qapplication.cpp
+++ b/src/gui/kernel/qapplication.cpp
@@ -3588,6 +3588,18 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
#endif // !QT_NO_WHEELEVENT || !QT_NO_TABLETEVENT
}
+ if (!d->grabbedGestures.isEmpty() && e->spontaneous() && receiver->isWidgetType()) {
+ const QEvent::Type t = e->type();
+ if (t == QEvent::MouseButtonPress || t == QEvent::MouseButtonRelease || t == QEvent::MouseMove
+ || t == QEvent::MouseButtonDblClick || t == QEvent::Wheel
+ || t == QEvent::KeyPress || t == QEvent::KeyRelease
+ || t == QEvent::TabletPress || t == QEvent::TabletRelease || t == QEvent::TabletMove
+ || t >= QEvent::User) {
+ if (QGestureManager::instance()->filterEvent(static_cast<QWidget*>(receiver), e))
+ return true;
+ }
+ }
+
// User input and window activation makes tooltips sleep
switch (e->type()) {
case QEvent::Wheel:
@@ -3715,28 +3727,6 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
QPoint relpos = mouse->pos();
if (e->spontaneous()) {
- if (!d->grabbedGestures.isEmpty()) {
- QWidget *w = static_cast<QWidget*>(receiver);
- // if we are in gesture mode, we send all mouse events
- // directly to gesture recognizer.
- (void)QGestureManager::instance();
- if (d->gestureManager->inGestureMode()) {
- if (d->gestureManager->filterEvent(e))
- return true;
- } else {
- 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) {
- d->gestureManager->setGestureTargetWidget(w);
- if (d->gestureManager->filterEvent(e))
- return true;
- }
- }
- }
- }
if (e->type() == QEvent::MouseButtonPress) {
QApplicationPrivate::giveFocusAccordingToFocusPolicy(w,
Qt::ClickFocus,
@@ -5107,7 +5097,6 @@ bool QApplicationPrivate::shouldSetFocus(QWidget *w, Qt::FocusPolicy policy)
*/
void QApplication::addGestureRecognizer(QGestureRecognizer *recognizer)
{
- Q_D(QApplication);
QGestureManager::instance()->addRecognizer(recognizer);
}
diff --git a/src/gui/kernel/qgesturemanager.cpp b/src/gui/kernel/qgesturemanager.cpp
index b5b8fb8..1635ac4 100644
--- a/src/gui/kernel/qgesturemanager.cpp
+++ b/src/gui/kernel/qgesturemanager.cpp
@@ -93,8 +93,17 @@ void QGestureManager::removeRecognizer(QGestureRecognizer *recognizer)
recognizers.remove(recognizer);
}
-bool QGestureManager::filterEvent(QEvent *event)
+bool QGestureManager::filterEvent(QWidget *receiver, QEvent *event)
{
+ if (state != Gesture) {
+ // find the target widget
+ while (receiver && receiver->d_func()->gestures.isEmpty())
+ receiver = receiver->parentWidget();
+ if (!receiver) // no widget in the tree that accepts gestures.
+ return false;
+ targetWidget = receiver;
+ }
+
QPoint currentPos;
switch (event->type()) {
case QEvent::MouseButtonPress:
@@ -133,7 +142,7 @@ bool QGestureManager::filterEvent(QEvent *event)
} else if (result == QGestureRecognizer::MaybeGesture) {
DEBUG() << "QGestureManager: maybe gesture: " << r;
newMaybeGestures << r;
- } else {
+ } else if (result == QGestureRecognizer::NotGesture) {
// if it was maybe gesture, but isn't a gesture anymore.
DEBUG() << "QGestureManager: not gesture: " << r;
notGestures << r;
@@ -230,7 +239,7 @@ bool QGestureManager::filterEvent(QEvent *event)
} else if (result == QGestureRecognizer::MaybeGesture) {
DEBUG() << "QGestureManager: maybe gesture: " << r;
newMaybeGestures << r;
- } else {
+ } else if (result == QGestureRecognizer::NotGesture) {
// if it was an active gesture, but isn't a gesture anymore.
if (activeGestures.contains(r)) {
DEBUG() << "QGestureManager: cancelled gesture: " << r;
diff --git a/src/gui/kernel/qgesturemanager_p.h b/src/gui/kernel/qgesturemanager_p.h
index 9d6d500..6de3baa 100644
--- a/src/gui/kernel/qgesturemanager_p.h
+++ b/src/gui/kernel/qgesturemanager_p.h
@@ -77,7 +77,7 @@ public:
void addRecognizer(QGestureRecognizer *recognizer);
void removeRecognizer(QGestureRecognizer *recognizer);
- bool filterEvent(QEvent *event);
+ bool filterEvent(QWidget *receiver, QEvent *event);
bool inGestureMode();
int makeGestureId(const QString &name);
diff --git a/src/gui/kernel/qgesturerecognizer.cpp b/src/gui/kernel/qgesturerecognizer.cpp
index c6e1f65..6600bb0 100644
--- a/src/gui/kernel/qgesturerecognizer.cpp
+++ b/src/gui/kernel/qgesturerecognizer.cpp
@@ -71,7 +71,9 @@ QString qt_getStandardGestureTypeName(Qt::GestureType gestureType);
This enum type defines the state of the gesture recognizer.
- \value NotGesture Not a gesture.
+ \value Ignore Gesture recognizer ignores the event.
+
+ \value NotGesture Not a gesture.
\value GestureStarted The continuous gesture has started. When the
recognizer is in this state, a \l{QGestureEvent}{gesture event}
@@ -126,15 +128,16 @@ QGestureRecognizerPrivate::QGestureRecognizerPrivate()
/*!
Creates a new gesture recognizer object that handles gestures of
- the specific \a type as a child of \a parent.
+ the specific \a gestureType as a child of \a parent.
\sa QApplication::addGestureRecognizer(),
QApplication::removeGestureRecognizer(),
*/
-QGestureRecognizer::QGestureRecognizer(const QString &type, QObject *parent)
+QGestureRecognizer::QGestureRecognizer(const QString &gestureType, QObject *parent)
: QObject(*new QGestureRecognizerPrivate, parent)
{
- d_func()->customGestureType = type;
+ Q_D(QGestureRecognizer);
+ d->customGestureType = gestureType;
}
/*!
diff --git a/src/gui/kernel/qgesturerecognizer.h b/src/gui/kernel/qgesturerecognizer.h
index 9e51e7e..8bc8b97 100644
--- a/src/gui/kernel/qgesturerecognizer.h
+++ b/src/gui/kernel/qgesturerecognizer.h
@@ -58,13 +58,14 @@ class Q_GUI_EXPORT QGestureRecognizer : public QObject
public:
enum Result
{
+ Ignore,
NotGesture,
GestureStarted,
GestureFinished,
MaybeGesture
};
- explicit QGestureRecognizer(const QString &type, QObject *parent = 0);
+ explicit QGestureRecognizer(const QString &gestureType, QObject *parent = 0);
QString gestureType() const;
diff --git a/src/gui/kernel/qgesturestandardrecognizers.cpp b/src/gui/kernel/qgesturestandardrecognizers.cpp
index cf2bb41..f6b8b90 100644
--- a/src/gui/kernel/qgesturestandardrecognizers.cpp
+++ b/src/gui/kernel/qgesturestandardrecognizers.cpp
@@ -144,7 +144,7 @@ QGestureRecognizer::Result QGestureRecognizerPan::filterEvent(const QEvent *even
}
return result;
}
- return QGestureRecognizer::NotGesture;
+ return QGestureRecognizer::Ignore;
}
QGesture* QGestureRecognizerPan::getGesture()
@@ -202,10 +202,12 @@ QGestureRecognizer::Result QDoubleTapGestureRecognizer::filterEvent(const QEvent
} else if ((pressedPosition - ev->pos()).manhattanLength() < 10) {
return QGestureRecognizer::GestureFinished;
}
+ return QGestureRecognizer::NotGesture;
} else if (event->type() == QEvent::MouseButtonRelease) {
const QMouseEvent *ev = static_cast<const QMouseEvent*>(event);
if (!pressedPosition.isNull() && (pressedPosition - ev->pos()).manhattanLength() < 10)
return QGestureRecognizer::MaybeGesture;
+ return QGestureRecognizer::NotGesture;
} else if (event->type() == QEvent::MouseButtonDblClick) {
const QMouseEvent *ev = static_cast<const QMouseEvent*>(event);
pressedPosition = ev->pos();
@@ -264,7 +266,7 @@ QGestureRecognizer::Result QTapAndHoldGestureRecognizer::filterEvent(const QEven
timer.stop();
return QGestureRecognizer::NotGesture;
}
- return QGestureRecognizer::NotGesture;
+ return QGestureRecognizer::Ignore;
}
void QTapAndHoldGestureRecognizer::timerEvent(QTimerEvent *event)