summaryrefslogtreecommitdiffstats
path: root/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp
diff options
context:
space:
mode:
authorJørgen Lind <jorgen.lind@nokia.com>2009-11-04 15:58:55 (GMT)
committerJørgen Lind <jorgen.lind@nokia.com>2009-11-04 15:58:55 (GMT)
commit5ff97be22a5246c11851c2c6471a0b7ee2399425 (patch)
tree4318dec329f4b3401184c9df80272c09e242bec3 /tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp
parent0009fa533e4d5ca1a75ba3b56af082cdcfee55cc (diff)
parent56b8d24c337d30c6bcdda101fbc664c4fd6d642d (diff)
downloadQt-5ff97be22a5246c11851c2c6471a0b7ee2399425.zip
Qt-5ff97be22a5246c11851c2c6471a0b7ee2399425.tar.gz
Qt-5ff97be22a5246c11851c2c6471a0b7ee2399425.tar.bz2
Merge branch '4.6' of scm.dev.nokia.troll.no:qt/qt into 4.6
Diffstat (limited to 'tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp')
-rw-r--r--tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp37
1 files changed, 21 insertions, 16 deletions
diff --git a/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp b/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp
index 63d3e76..66fcf18 100644
--- a/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp
+++ b/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp
@@ -49,34 +49,39 @@ MousePanGestureRecognizer::MousePanGestureRecognizer()
{
}
-QGesture* MousePanGestureRecognizer::createGesture(QObject *)
+QGesture *MousePanGestureRecognizer::create(QObject *)
{
return new QPanGesture;
}
-QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *state, QObject *, QEvent *event)
+QGestureRecognizer::Result MousePanGestureRecognizer::recognize(QGesture *state, QObject *, QEvent *event)
{
QPanGesture *g = static_cast<QPanGesture *>(state);
+ if (event->type() == QEvent::TouchBegin) {
+ // ignore the following mousepress event
+ g->setProperty("ignoreMousePress", QVariant::fromValue<bool>(true));
+ } else if (event->type() == QEvent::TouchEnd) {
+ g->setProperty("ignoreMousePress", QVariant::fromValue<bool>(false));
+ }
QMouseEvent *me = static_cast<QMouseEvent *>(event);
- if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick) {
+ if (event->type() == QEvent::MouseButtonPress) {
+ if (g->property("ignoreMousePress").toBool())
+ return QGestureRecognizer::Ignore;
g->setHotSpot(me->globalPos());
- g->setProperty("lastPos", me->globalPos());
+ g->setProperty("startPos", me->globalPos());
g->setProperty("pressed", QVariant::fromValue<bool>(true));
- return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint;
+ return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint;
} else if (event->type() == QEvent::MouseMove) {
if (g->property("pressed").toBool()) {
- QPoint pos = me->globalPos();
- QPoint lastPos = g->property("lastPos").toPoint();
+ QPoint offset = me->globalPos() - g->property("startPos").toPoint();
g->setLastOffset(g->offset());
- lastPos = pos - lastPos;
- g->setOffset(QPointF(lastPos.x(), lastPos.y()));
- g->setTotalOffset(g->totalOffset() + QPointF(lastPos.x(), lastPos.y()));
- g->setProperty("lastPos", pos);
- return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint;
+ g->setOffset(QPointF(offset.x(), offset.y()));
+ return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint;
}
- return QGestureRecognizer::NotGesture;
+ return QGestureRecognizer::CancelGesture;
} else if (event->type() == QEvent::MouseButtonRelease) {
- return QGestureRecognizer::GestureFinished | QGestureRecognizer::ConsumeEventHint;
+ if (g->property("pressed").toBool())
+ return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint;
}
return QGestureRecognizer::Ignore;
}
@@ -84,11 +89,11 @@ QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *stat
void MousePanGestureRecognizer::reset(QGesture *state)
{
QPanGesture *g = static_cast<QPanGesture *>(state);
- g->setTotalOffset(QPointF());
g->setLastOffset(QPointF());
g->setOffset(QPointF());
g->setAcceleration(0);
- g->setProperty("lastPos", QVariant());
+ g->setProperty("startPos", QVariant());
g->setProperty("pressed", QVariant::fromValue<bool>(false));
+ g->setProperty("ignoreMousePress", QVariant::fromValue<bool>(false));
QGestureRecognizer::reset(state);
}