diff options
author | Richard Moe Gustavsen <richard.gustavsen@nokia.com> | 2009-08-04 07:45:47 (GMT) |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@nokia.com> | 2009-08-04 08:01:10 (GMT) |
commit | d2e03cc83b5dabc5fd1986a8b8119ff8f0d76179 (patch) | |
tree | fc8ad909307a167add065f5c53cc5adb389cffc9 /examples | |
parent | c96ed4426db7ae3287ee88b0ac7ffd2bd5070310 (diff) | |
download | Qt-d2e03cc83b5dabc5fd1986a8b8119ff8f0d76179.zip Qt-d2e03cc83b5dabc5fd1986a8b8119ff8f0d76179.tar.gz Qt-d2e03cc83b5dabc5fd1986a8b8119ff8f0d76179.tar.bz2 |
Modify imagewidget example so it works with new API
Diffstat (limited to 'examples')
-rw-r--r-- | examples/gestures/imageviewer/imagewidget.cpp | 46 |
1 files changed, 15 insertions, 31 deletions
diff --git a/examples/gestures/imageviewer/imagewidget.cpp b/examples/gestures/imageviewer/imagewidget.cpp index 717bb09..0b39997 100644 --- a/examples/gestures/imageviewer/imagewidget.cpp +++ b/examples/gestures/imageviewer/imagewidget.cpp @@ -100,7 +100,7 @@ void ImageWidget::paintEvent(QPaintEvent*) p.setPen(QPen(Qt::gray, 2)); p.drawEllipse(touchFeedback.position, 5, 5); if (touchFeedback.doubleTapped) { - p.setPen(QPen(Qt::gray, 2, Qt::DotLine)); + p.setPen(QPen(Qt::darkGray, 2, Qt::DotLine)); p.drawEllipse(touchFeedback.position, 15, 15); } else if (touchFeedback.tapAndHoldState != 0) { QPoint pts[8] = { @@ -159,51 +159,35 @@ void ImageWidget::gestureTriggered() touchFeedback.tapped = false; touchFeedback.doubleTapped = false; - QGesture *g = qobject_cast<QGesture*>(sender()); if (sender() == panGesture) { + QPanGesture *pg = qobject_cast<QPanGesture*>(sender()); if (zoomedIn) { - // usual panning #ifndef QT_NO_CURSOR - if (g->state() == Qt::GestureStarted) - setCursor(Qt::SizeAllCursor); - else - setCursor(Qt::ArrowCursor); + switch (pg->state()) { + case Qt::GestureStarted: + case Qt::GestureUpdated: + setCursor(Qt::SizeAllCursor); + break; + default: + setCursor(Qt::ArrowCursor); + } #endif - const int dx = g->pos().x() - g->lastPos().x(); - const int dy = g->pos().y() - g->lastPos().y(); - horizontalOffset += dx; - verticalOffset += dy; + horizontalOffset += pg->lastOffset().width(); + verticalOffset += pg->lastOffset().height(); update(); } else { // only slide gesture should be accepted - const QPanGesture *pg = static_cast<const QPanGesture*>(g); - if (g->state() == Qt::GestureFinished) { + if (pg->state() == Qt::GestureFinished) { touchFeedback.sliding = false; zoomed = rotated = false; - if (pg->totalOffset().width() > 0) { - qDebug() << "slide right"; + if (pg->totalOffset().width() > 0) goNextImage(); - } else { - qDebug() << "slide left"; + else goPrevImage(); - } updateImage(); } } feedbackFadeOutTimer.start(500, this); - } else if (sender() == tapAndHoldGesture) { - if (g->state() == Qt::GestureFinished) { - qDebug() << "tap and hold detected"; - touchFeedback.reset(); - update(); - - QMenu menu; - menu.addAction("Action 1"); - menu.addAction("Action 2"); - menu.addAction("Action 3"); - menu.exec(mapToGlobal(g->pos())); - } - feedbackFadeOutTimer.start(500, this); } } |