diff options
author | Richard Moe Gustavsen <richard.gustavsen@nokia.com> | 2009-08-26 11:49:18 (GMT) |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@nokia.com> | 2009-08-27 12:06:13 (GMT) |
commit | 42b1e49335377175b73a499236a800fca40a1d3e (patch) | |
tree | 4ed9868696e18521c5338c921dbbfa76d9a3f916 /src/gui | |
parent | 220bb878d78eadfdfd390ca51c1a24378859d4ba (diff) | |
download | Qt-42b1e49335377175b73a499236a800fca40a1d3e.zip Qt-42b1e49335377175b73a499236a800fca40a1d3e.tar.gz Qt-42b1e49335377175b73a499236a800fca40a1d3e.tar.bz2 |
Cocoa: implement pan gestures to follow mouse
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/kernel/qstandardgestures.cpp | 25 | ||||
-rw-r--r-- | src/gui/kernel/qstandardgestures_p.h | 2 |
2 files changed, 14 insertions, 13 deletions
diff --git a/src/gui/kernel/qstandardgestures.cpp b/src/gui/kernel/qstandardgestures.cpp index ac8c0c3..0bd8133 100644 --- a/src/gui/kernel/qstandardgestures.cpp +++ b/src/gui/kernel/qstandardgestures.cpp @@ -214,19 +214,14 @@ bool QPanGesture::filterEvent(QEvent *event) switch (event->type()) { case QEvent::TouchBegin: { - if (ev->touchPoints().size() == 1) + if (ev->touchPoints().size() == 1) { + d->lastPosition = QCursor::pos(); d->singleTouchPanTimer.start(panBeginDelay, this); + } break;} case QEvent::TouchEnd: { - if (state() != Qt::NoGesture) { - if (ev->touchPoints().size() == 1) { - QTouchEvent::TouchPoint p = ev->touchPoints().at(0); - QPointF dist = p.pos() - p.lastPos(); - d->lastOffset = QSizeF(dist.x(), dist.y()); - d->totalOffset += d->lastOffset; - } + if (state() != Qt::NoGesture) updateState(Qt::GestureFinished); - } reset(); break;} case QEvent::TouchUpdate: { @@ -239,13 +234,18 @@ bool QPanGesture::filterEvent(QEvent *event) const QPoint p = ev->touchPoints().at(0).pos().toPoint(); if ((startPos - p).manhattanLength() > panBeginRadius) reset(); + else + d->lastPosition = QCursor::pos(); } else { - QTouchEvent::TouchPoint p = ev->touchPoints().at(0); - QPointF dist = p.pos() - p.lastPos(); + QPointF mousePos = QCursor::pos(); + QPointF dist = mousePos - d->lastPosition; + d->lastPosition = mousePos; d->lastOffset = QSizeF(dist.x(), dist.y()); d->totalOffset += d->lastOffset; updateState(Qt::GestureUpdated); } + } else if (state() == Qt::NoGesture) { + reset(); } break;} default: @@ -262,10 +262,11 @@ void QPanGesture::reset() { Q_D(QPanGesture); d->lastOffset = d->totalOffset = QSize(0, 0); - d->lastPosition = QPoint(); + d->lastPosition = QPoint(0, 0); #if defined(QT_MAC_USE_COCOA) d->singleTouchPanTimer.stop(); + d->prevMousePos = QPointF(0, 0); #endif QGesture::reset(); diff --git a/src/gui/kernel/qstandardgestures_p.h b/src/gui/kernel/qstandardgestures_p.h index 8d84f51..5adcf3a 100644 --- a/src/gui/kernel/qstandardgestures_p.h +++ b/src/gui/kernel/qstandardgestures_p.h @@ -78,7 +78,7 @@ public: #if defined(QT_MAC_USE_COCOA) QBasicTimer singleTouchPanTimer; - QPointF singleTouchBeginPoint; + QPointF prevMousePos; #endif }; |