diff --git a/ui/pageview.cpp b/ui/pageview.cpp index 5fbabb298..339ba69c3 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -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( event )); + } + + // do not stop the event + return QAbstractScrollArea::event( event ); +} + + +bool PageView::gestureEvent( QGestureEvent * event ) +{ + QPinchGesture *pinch = static_cast(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(); diff --git a/ui/pageview.h b/ui/pageview.h index 7c43f51cb..77781c38e 100644 --- a/ui/pageview.h +++ b/ui/pageview.h @@ -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;