diff options
author | Thomas Zander <t.zander@nokia.com> | 2010-07-05 15:05:04 (GMT) |
---|---|---|
committer | Thomas Zander <t.zander@nokia.com> | 2010-07-06 13:19:18 (GMT) |
commit | fa9c62460791c9b9add365fc9543ec0392f50cee (patch) | |
tree | f320305e24282aaac7f64dc4a7b777dbf3cdecba /src/gui | |
parent | 4fe7291edcac2688f042a11ff5c23374c6c0375d (diff) | |
download | Qt-fa9c62460791c9b9add365fc9543ec0392f50cee.zip Qt-fa9c62460791c9b9add365fc9543ec0392f50cee.tar.gz Qt-fa9c62460791c9b9add365fc9543ec0392f50cee.tar.bz2 |
Adapt the TapAndHold recognizer to non-touch too
The QTapAndHoldGestureRecognizer now can trigger also on mouse and
GraphicsSceneMouse events and all of them will cause the gesture start
event to be sent after the touch interval timed out.
Reviewed-by: Denis
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/kernel/qstandardgestures.cpp | 63 |
1 files changed, 40 insertions, 23 deletions
diff --git a/src/gui/kernel/qstandardgestures.cpp b/src/gui/kernel/qstandardgestures.cpp index 8a3e89e..62d8a53 100644 --- a/src/gui/kernel/qstandardgestures.cpp +++ b/src/gui/kernel/qstandardgestures.cpp @@ -45,6 +45,7 @@ #include "qevent.h" #include "qwidget.h" #include "qabstractscrollarea.h" +#include <qgraphicssceneevent.h> #include "qdebug.h" #ifndef QT_NO_GESTURES @@ -509,49 +510,65 @@ QTapAndHoldGestureRecognizer::recognize(QGesture *state, QObject *object, if (object == state && event->type() == QEvent::Timer) { q->killTimer(d->timerId); d->timerId = 0; - return QGestureRecognizer::Ignore | QGestureRecognizer::ConsumeEventHint; + return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint; } const QTouchEvent *ev = static_cast<const QTouchEvent *>(event); - - QGestureRecognizer::Result result = QGestureRecognizer::CancelGesture; + const QMouseEvent *me = static_cast<const QMouseEvent *>(event); + const QGraphicsSceneMouseEvent *gsme = static_cast<const QGraphicsSceneMouseEvent *>(event); enum { TimerInterval = 2000 }; enum { TapRadius = 40 }; switch (event->type()) { + case QEvent::GraphicsSceneMousePress: + d->position = gsme->screenPos(); + q->setHotSpot(d->position); + if (d->timerId) + q->killTimer(d->timerId); + d->timerId = q->startTimer(TimerInterval); + return QGestureRecognizer::MayBeGesture; // we don't show a sign of life until the timeout + case QEvent::MouseButtonPress: + d->position = me->globalPos(); + q->setHotSpot(d->position); + if (d->timerId) + q->killTimer(d->timerId); + d->timerId = q->startTimer(TimerInterval); + return QGestureRecognizer::MayBeGesture; // we don't show a sign of life until the timeout case QEvent::TouchBegin: - d->position = ev->touchPoints().at(0).pos(); + d->position = ev->touchPoints().at(0).startScreenPos(); + q->setHotSpot(d->position); if (d->timerId) q->killTimer(d->timerId); d->timerId = q->startTimer(TimerInterval); - q->setHotSpot(ev->touchPoints().at(0).startScreenPos()); - result = QGestureRecognizer::TriggerGesture; - break; + return QGestureRecognizer::MayBeGesture; // we don't show a sign of life until the timeout + case QEvent::GraphicsSceneMouseRelease: + case QEvent::MouseButtonRelease: case QEvent::TouchEnd: - if (d->timerId) - result = QGestureRecognizer::CancelGesture; - else - result = QGestureRecognizer::FinishGesture; - break; + return QGestureRecognizer::CancelGesture; // get out of the MayBeGesture state case QEvent::TouchUpdate: - if (q->state() != Qt::NoGesture && ev->touchPoints().size() == 1) { + if (d->timerId && ev->touchPoints().size() == 1) { QTouchEvent::TouchPoint p = ev->touchPoints().at(0); QPoint delta = p.pos().toPoint() - p.startPos().toPoint(); if (delta.manhattanLength() <= TapRadius) - result = QGestureRecognizer::TriggerGesture; + return QGestureRecognizer::MayBeGesture; } - break; - case QEvent::MouseButtonPress: - case QEvent::MouseMove: - case QEvent::MouseButtonRelease: - result = QGestureRecognizer::Ignore; - break; + return QGestureRecognizer::CancelGesture; + case QEvent::MouseMove: { + QPoint delta = me->globalPos() - d->position.toPoint(); + if (d->timerId && delta.manhattanLength() <= TapRadius) + return QGestureRecognizer::MayBeGesture; + return QGestureRecognizer::CancelGesture; + } + case QEvent::GraphicsSceneMouseMove: { + QPoint delta = gsme->screenPos() - d->position.toPoint(); + if (d->timerId && delta.manhattanLength() <= TapRadius) + return QGestureRecognizer::MayBeGesture; + return QGestureRecognizer::CancelGesture; + } default: - result = QGestureRecognizer::Ignore; - break; + return QGestureRecognizer::Ignore; } - return result; } void QTapAndHoldGestureRecognizer::reset(QGesture *state) |