Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

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

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 )
// 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;
}
......
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