diff options
author | Shawn Rutledge <shawn.rutledge@digia.com> | 2015-02-25 10:53:31 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@digia.com> | 2015-03-03 13:30:25 +0000 |
commit | a9515cd02fabcb90691093c388be9849282a9e22 (patch) | |
tree | 8501b78ef0179a599541b1fefbff7e6a33d537bc /examples/widgets/gestures/imagegestures/imagewidget.cpp | |
parent | 2b5982aac8ad103443e33379fe5654f5bd419c87 (diff) |
doc: imagegestures example: document the pinch handler
The swipe handler is simple, and also doesn't currently work on every
platform. But the pinch handler is the one that needs explanation,
because the difference between incremental and absolute values of the
rotation and scale properties is tricky.
Change-Id: Ie3c7f4941d4a17734c9a920a8dd978f86fb03c4b
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Reviewed-by: Topi Reiniƶ <topi.reinio@digia.com>
Diffstat (limited to 'examples/widgets/gestures/imagegestures/imagewidget.cpp')
-rw-r--r-- | examples/widgets/gestures/imagegestures/imagewidget.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/examples/widgets/gestures/imagegestures/imagewidget.cpp b/examples/widgets/gestures/imagegestures/imagewidget.cpp index 38319a9dbe..3d0d7e7a93 100644 --- a/examples/widgets/gestures/imagegestures/imagewidget.cpp +++ b/examples/widgets/gestures/imagegestures/imagewidget.cpp @@ -77,6 +77,7 @@ bool ImageWidget::event(QEvent *event) } //! [event handler] +//! [paint method] void ImageWidget::paintEvent(QPaintEvent*) { QPainter p(this); @@ -93,6 +94,7 @@ void ImageWidget::paintEvent(QPaintEvent*) p.translate(-iw/2, -ih/2); p.drawImage(0, 0, currentImage); } +//! [paint method] void ImageWidget::mouseDoubleClickEvent(QMouseEvent *) { @@ -138,16 +140,20 @@ void ImageWidget::panTriggered(QPanGesture *gesture) update(); } +//! [pinch function] void ImageWidget::pinchTriggered(QPinchGesture *gesture) { QPinchGesture::ChangeFlags changeFlags = gesture->changeFlags(); if (changeFlags & QPinchGesture::RotationAngleChanged) { - rotationAngle += gesture->rotationAngle() - gesture->lastRotationAngle(); - qCDebug(lcExample) << "pinchTriggered(): rotate to" << rotationAngle; + qreal rotationDelta = gesture->rotationAngle() - gesture->lastRotationAngle(); + rotationAngle += rotationDelta; + qCDebug(lcExample) << "pinchTriggered(): rotate by" << + rotationDelta << "->" << rotationAngle; } if (changeFlags & QPinchGesture::ScaleFactorChanged) { currentStepScaleFactor = gesture->totalScaleFactor(); - qCDebug(lcExample) << "pinchTriggered(): zoom by" << gesture->scaleFactor() << "->" << currentStepScaleFactor; + qCDebug(lcExample) << "pinchTriggered(): zoom by" << + gesture->scaleFactor() << "->" << currentStepScaleFactor; } if (gesture->state() == Qt::GestureFinished) { scaleFactor *= currentStepScaleFactor; @@ -155,6 +161,7 @@ void ImageWidget::pinchTriggered(QPinchGesture *gesture) } update(); } +//! [pinch function] //! [swipe function] void ImageWidget::swipeTriggered(QSwipeGesture *gesture) |