mirror of
https://invent.kde.org/graphics/okular
synced 2024-09-13 05:01:30 +00:00
Change pages in presentation mode by swiping on touch screen
REVIEW: 130012 BUGS: 354012
This commit is contained in:
parent
63a08bc01a
commit
618072f8a2
|
@ -29,6 +29,7 @@
|
|||
#include <qvalidator.h>
|
||||
#include <qapplication.h>
|
||||
#include <qdesktopwidget.h>
|
||||
#include <QGestureEvent>
|
||||
#include <kcursor.h>
|
||||
#include <krandom.h>
|
||||
#include <qtoolbar.h>
|
||||
|
@ -232,6 +233,9 @@ PresentationWidget::PresentationWidget( QWidget * parent, Okular::Document * doc
|
|||
p.setColor( QPalette::Active, QPalette::Background, Qt::darkGray );
|
||||
m_topBar->setPalette( p );
|
||||
|
||||
// Grab swipe gestures to change pages
|
||||
grabGesture(Qt::SwipeGesture);
|
||||
|
||||
// misc stuff
|
||||
setMouseTracking( true );
|
||||
setContextMenuPolicy( Qt::PreventContextMenu );
|
||||
|
@ -528,6 +532,9 @@ void PresentationWidget::setPlayPauseIcon()
|
|||
// <widget events>
|
||||
bool PresentationWidget::event( QEvent * e )
|
||||
{
|
||||
if ( e->type() == QEvent::Gesture )
|
||||
return gestureEvent(static_cast<QGestureEvent*>(e));
|
||||
|
||||
if ( e->type() == QEvent::ToolTip )
|
||||
{
|
||||
QHelpEvent * he = (QHelpEvent*)e;
|
||||
|
@ -549,6 +556,33 @@ bool PresentationWidget::event( QEvent * e )
|
|||
return QWidget::event( e );
|
||||
}
|
||||
|
||||
bool PresentationWidget::gestureEvent( QGestureEvent * event )
|
||||
{
|
||||
// Swiping left or right on a touch screen will go to the previous or next slide, respectively.
|
||||
// The precise gesture is the standard Qt swipe: with three(!) fingers.
|
||||
if (QGesture *swipe = event->gesture(Qt::SwipeGesture))
|
||||
{
|
||||
QSwipeGesture * swipeEvent = static_cast<QSwipeGesture *>(swipe);
|
||||
|
||||
if (swipeEvent->state() == Qt::GestureFinished)
|
||||
{
|
||||
if (swipeEvent->horizontalDirection() == QSwipeGesture::Left)
|
||||
{
|
||||
slotPrevPage();
|
||||
event->accept();
|
||||
return true;
|
||||
}
|
||||
if (swipeEvent->horizontalDirection() == QSwipeGesture::Right)
|
||||
{
|
||||
slotNextPage();
|
||||
event->accept();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
void PresentationWidget::keyPressEvent( QKeyEvent * e )
|
||||
{
|
||||
if ( !m_isSetup )
|
||||
|
@ -664,9 +698,6 @@ void PresentationWidget::mousePressEvent( QMouseEvent * e )
|
|||
overlayClick( e->pos() );
|
||||
return;
|
||||
}
|
||||
|
||||
// if no other actions, go to next page
|
||||
slotNextPage();
|
||||
}
|
||||
// pressing right button
|
||||
else if ( e->button() == Qt::RightButton )
|
||||
|
@ -689,6 +720,9 @@ void PresentationWidget::mouseReleaseEvent( QMouseEvent * e )
|
|||
m_document->processAction( link );
|
||||
m_pressedLink = 0;
|
||||
}
|
||||
|
||||
// if no other actions, go to next page
|
||||
slotNextPage();
|
||||
}
|
||||
|
||||
void PresentationWidget::mouseMoveEvent( QMouseEvent * e )
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
class QLineEdit;
|
||||
class QToolBar;
|
||||
class QTimer;
|
||||
class QGestureEvent;
|
||||
class KActionCollection;
|
||||
class KSelectAction;
|
||||
class SmoothPathEngine;
|
||||
|
@ -71,6 +72,7 @@ class PresentationWidget : public QWidget, public Okular::DocumentObserver
|
|||
void paintEvent( QPaintEvent * e ) override;
|
||||
void resizeEvent( QResizeEvent * e ) override;
|
||||
void leaveEvent( QEvent * e ) override;
|
||||
bool gestureEvent (QGestureEvent * e );
|
||||
|
||||
private:
|
||||
const void * getObjectRect( Okular::ObjectRect::ObjectType type, int x, int y, QRect * geometry = 0 ) const;
|
||||
|
|
Loading…
Reference in a new issue