Commit 54436672 authored by Oliver Sander's avatar Oliver Sander Committed by Albert Astals Cid
Browse files

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

REVIEW: 126809
parent 59dd0476
...@@ -420,7 +420,7 @@ PageView::PageView( QWidget *parent, Okular::Document *document ) ...@@ -420,7 +420,7 @@ PageView::PageView( QWidget *parent, Okular::Document *document )
// connect(...); // connect(...);
setAttribute( Qt::WA_InputMethodEnabled, true ); 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); grabGesture(Qt::PinchGesture);
d->magnifierView = new MagnifierView(document, this); d->magnifierView = new MagnifierView(document, this);
...@@ -1522,6 +1522,8 @@ bool PageView::gestureEvent( QGestureEvent * event ) ...@@ -1522,6 +1522,8 @@ bool PageView::gestureEvent( QGestureEvent * event )
vanillaZoom = d->zoomFactor; vanillaZoom = d->zoomFactor;
} }
const QPinchGesture::ChangeFlags changeFlags = pinch->changeFlags();
// Zoom // Zoom
if (pinch->changeFlags() & QPinchGesture::ScaleFactorChanged) if (pinch->changeFlags() & QPinchGesture::ScaleFactorChanged)
{ {
...@@ -1533,6 +1535,32 @@ bool PageView::gestureEvent( QGestureEvent * event ) ...@@ -1533,6 +1535,32 @@ bool PageView::gestureEvent( QGestureEvent * event )
viewport()->repaint(); 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; return true;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment