diff options
author | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2009-08-21 09:16:16 (GMT) |
---|---|---|
committer | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2009-08-21 12:52:15 (GMT) |
commit | b69bc882acdc445c5ef2334697f7eec9cb73f16d (patch) | |
tree | 2c2c0ac031b663e8f00fa0abf65653563f29a120 /src/gui/kernel/qstandardgestures.cpp | |
parent | 1a78099a6b5523ad913caf9d1700a4f6ffbea485 (diff) | |
download | Qt-b69bc882acdc445c5ef2334697f7eec9cb73f16d.zip Qt-b69bc882acdc445c5ef2334697f7eec9cb73f16d.tar.gz Qt-b69bc882acdc445c5ef2334697f7eec9cb73f16d.tar.bz2 |
Improved the QPanGesture implementation.
When Pan is implemented with touch events, make sure it pans only when two
fingers are used.
Reviewed-by: trustme
Diffstat (limited to 'src/gui/kernel/qstandardgestures.cpp')
-rw-r--r-- | src/gui/kernel/qstandardgestures.cpp | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/gui/kernel/qstandardgestures.cpp b/src/gui/kernel/qstandardgestures.cpp index 10689ba..8c50c78 100644 --- a/src/gui/kernel/qstandardgestures.cpp +++ b/src/gui/kernel/qstandardgestures.cpp @@ -179,27 +179,29 @@ bool QPanGesture::filterEvent(QEvent *event) d->lastOffset = d->totalOffset = QSize(); } else if (event->type() == QEvent::TouchEnd) { if (state() != Qt::NoGesture) { - if (!ev->touchPoints().isEmpty()) { - QTouchEvent::TouchPoint p = ev->touchPoints().at(0); - const QPoint pos = p.pos().toPoint(); - const QPoint lastPos = p.lastPos().toPoint(); - const QPoint startPos = p.startPos().toPoint(); - d->lastOffset = QSize(pos.x() - lastPos.x(), pos.y() - lastPos.y()); - d->totalOffset = QSize(pos.x() - startPos.x(), pos.y() - startPos.y()); + if (ev->touchPoints().size() == 2) { + QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0); + QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1); + d->lastOffset = + QSize(p1.pos().x() - p1.lastPos().x() + p2.pos().x() - p2.lastPos().x(), + p1.pos().y() - p1.lastPos().y() + p2.pos().y() - p2.lastPos().y()) / 2; + d->totalOffset += d->lastOffset; } updateState(Qt::GestureFinished); } reset(); } else if (event->type() == QEvent::TouchUpdate) { - QTouchEvent::TouchPoint p = ev->touchPoints().at(0); - const QPoint pos = p.pos().toPoint(); - const QPoint lastPos = p.lastPos().toPoint(); - const QPoint startPos = p.startPos().toPoint(); - d->lastOffset = QSize(pos.x() - lastPos.x(), pos.y() - lastPos.y()); - d->totalOffset = QSize(pos.x() - startPos.x(), pos.y() - startPos.y()); - if (d->totalOffset.width() > 10 || d->totalOffset.height() > 10 || - d->totalOffset.width() < -10 || d->totalOffset.height() < -10) { - updateState(Qt::GestureUpdated); + if (ev->touchPoints().size() == 2) { + QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0); + QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1); + d->lastOffset = + QSize(p1.pos().x() - p1.lastPos().x() + p2.pos().x() - p2.lastPos().x(), + p1.pos().y() - p1.lastPos().y() + p2.pos().y() - p2.lastPos().y()) / 2; + d->totalOffset += d->lastOffset; + if (d->totalOffset.width() > 10 || d->totalOffset.height() > 10 || + d->totalOffset.width() < -10 || d->totalOffset.height() < -10) { + updateState(Qt::GestureUpdated); + } } } #ifdef Q_OS_MAC |