Commit 9d90a08e authored by Martin Tobias Holmedahl Sandsmark's avatar Martin Tobias Holmedahl Sandsmark
Browse files

Implement zooming with a pinch gesture on a touch screen

Patch by Oliver Sander <oliver.sander@tu-dresden.de>

REVIEW: 128821
BUG: 366781
parent afb5e01a
......@@ -37,6 +37,7 @@
#include <QDesktopServices>
#include <QMimeDatabase>
#include <QMimeData>
#include <QGestureEvent>
#include <qaction.h>
#include <kactionmenu.h>
......@@ -416,6 +417,9 @@ 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)
grabGesture(Qt::PinchGesture);
d->magnifierView = new MagnifierView(document, this);
d->magnifierView->hide();
d->magnifierView->setGeometry(0, 0, 351, 201); // TODO: more dynamic?
......@@ -1481,6 +1485,51 @@ void PageView::setCapability( ViewCapability capability, const QVariant &option
//END View inherited methods
//BEGIN widget events
bool PageView::event( QEvent * event )
{
if ( event->type() == QEvent::Gesture )
{
return gestureEvent(static_cast<QGestureEvent*>( event ));
}
// do not stop the event
return QAbstractScrollArea::event( event );
}
bool PageView::gestureEvent( QGestureEvent * event )
{
QPinchGesture *pinch = static_cast<QPinchGesture*>(event->gesture(Qt::PinchGesture));
if (pinch)
{
// Viewport zoom level at the moment where the pinch gesture starts.
// The viewport zoom level _during_ the gesture will be this value
// times the relative zoom reported by QGestureEvent.
static qreal vanillaZoom = d->zoomFactor;
if (pinch->state() == Qt::GestureStarted)
{
vanillaZoom = d->zoomFactor;
}
// Zoom
if (pinch->changeFlags() & QPinchGesture::ScaleFactorChanged)
{
d->zoomFactor = vanillaZoom * pinch->totalScaleFactor();
d->blockPixmapsRequest = true;
updateZoom( ZoomRefreshCurrent );
d->blockPixmapsRequest = false;
viewport()->repaint();
}
return true;
}
return false;
}
void PageView::paintEvent(QPaintEvent *pe)
{
const QPoint areaPos = contentAreaPosition();
......
......@@ -43,6 +43,8 @@ class PageViewPrivate;
class MagnifierView;
class QGestureEvent;
/**
* @short The main view. Handles zoom and continuous mode.. oh, and page
* @short display of course :-)
......@@ -126,7 +128,10 @@ Q_OBJECT
void fitWindowToPage( const QSize& pageViewPortSize, const QSize& pageSize );
protected:
bool event( QEvent * event ) Q_DECL_OVERRIDE;
void resizeEvent( QResizeEvent* ) Q_DECL_OVERRIDE;
bool gestureEvent( QGestureEvent * e );
// mouse / keyboard events
void keyPressEvent( QKeyEvent* ) Q_DECL_OVERRIDE;
......
Supports Markdown
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