summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qstandardgestures.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/kernel/qstandardgestures.cpp')
-rw-r--r--src/gui/kernel/qstandardgestures.cpp63
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)