Allow to rotate the page view using two-finger pinches on a touchscreen

REVIEW: 126809
This commit is contained in:
Oliver Sander 2017-03-11 18:33:59 +01:00 committed by Albert Astals Cid
parent 59dd04766c
commit 54436672fb

View file

@ -420,7 +420,7 @@ PageView::PageView( QWidget *parent, Okular::Document *document )
// connect(...);
setAttribute( Qt::WA_InputMethodEnabled, true );
// Grab pinch gestures to rotate the view (and do things like zooming eventually)
// Grab pinch gestures to zoom and rotate the view
grabGesture(Qt::PinchGesture);
d->magnifierView = new MagnifierView(document, this);
@ -1522,6 +1522,8 @@ bool PageView::gestureEvent( QGestureEvent * event )
vanillaZoom = d->zoomFactor;
}
const QPinchGesture::ChangeFlags changeFlags = pinch->changeFlags();
// Zoom
if (pinch->changeFlags() & QPinchGesture::ScaleFactorChanged)
{
@ -1533,6 +1535,32 @@ bool PageView::gestureEvent( QGestureEvent * event )
viewport()->repaint();
}
// Count the number of 90-degree rotations we did since the start of the pinch gesture.
// Otherwise a pinch turned to 90 degrees and held there will rotate the page again and again.
static int rotations = 0;
if (changeFlags & QPinchGesture::RotationAngleChanged)
{
// Rotation angle relative to the accumulated page rotations triggered by the current pinch
// We actually turn at 80 degrees rather than at 90 degrees. That's less strain on the hands.
const qreal relativeAngle = pinch->rotationAngle() - rotations*90;
if (relativeAngle > 80)
{
slotRotateClockwise();
rotations++;
}
if (relativeAngle < -80)
{
slotRotateCounterClockwise();
rotations--;
}
}
if (pinch->state() == Qt::GestureFinished)
{
rotations = 0;
}
return true;
}