Commit 7a50ce0e authored by Albert Astals Cid's avatar Albert Astals Cid

Accumulate Control+Wheel Deltas until they reach QWheelEvent::DefaultDeltasPerStep

This way zooming in/out with a touchpad is easier to control

BUGS: 377128
parent c058c809
......@@ -166,6 +166,7 @@ public:
double lastSourceLocationViewportNormalizedX;
double lastSourceLocationViewportNormalizedY;
QTimer * viewportMoveTimer;
int controlWheelAccumulatedDelta;
// auto scroll
int scrollIncrement;
QTimer * autoScrollTimer;
......@@ -312,6 +313,7 @@ PageView::PageView( QWidget *parent, Okular::Document *document )
d->lastSourceLocationViewportNormalizedX = 0.0;
d->lastSourceLocationViewportNormalizedY = 0.0;
d->viewportMoveTimer = 0;
d->controlWheelAccumulatedDelta = 0;
d->scrollIncrement = 0;
d->autoScrollTimer = 0;
d->annotator = 0;
......@@ -1971,6 +1973,8 @@ void PageView::tabletEvent( QTabletEvent * e )
void PageView::mouseMoveEvent( QMouseEvent * e )
{
d->controlWheelAccumulatedDelta = 0;
// don't perform any mouse action when no document is shown
if ( d->items.isEmpty() )
return;
......@@ -2159,6 +2163,8 @@ void PageView::mouseMoveEvent( QMouseEvent * e )
void PageView::mousePressEvent( QMouseEvent * e )
{
d->controlWheelAccumulatedDelta = 0;
// don't perform any mouse action when no document is shown
if ( d->items.isEmpty() )
return;
......@@ -2392,6 +2398,8 @@ void PageView::mousePressEvent( QMouseEvent * e )
void PageView::mouseReleaseEvent( QMouseEvent * e )
{
d->controlWheelAccumulatedDelta = 0;
// stop the drag scrolling
d->dragScrollTimer.stop();
......@@ -3192,6 +3200,8 @@ void PageView::guessTableDividers()
void PageView::mouseDoubleClickEvent( QMouseEvent * e )
{
d->controlWheelAccumulatedDelta = 0;
if ( e->button() == Qt::LeftButton )
{
const QPoint eventPos = contentAreaPoint( e->pos() );
......@@ -3254,43 +3264,55 @@ void PageView::wheelEvent( QWheelEvent *e )
vScroll = verticalScrollBar()->value();
e->accept();
if ( (e->modifiers() & Qt::ControlModifier) == Qt::ControlModifier ) {
if ( e->delta() < 0 )
d->controlWheelAccumulatedDelta += delta;
if ( d->controlWheelAccumulatedDelta <= -QWheelEvent::DefaultDeltasPerStep )
{
slotZoomOut();
else
d->controlWheelAccumulatedDelta = 0;
}
else if ( d->controlWheelAccumulatedDelta >= QWheelEvent::DefaultDeltasPerStep )
{
slotZoomIn();
d->controlWheelAccumulatedDelta = 0;
}
}
else if ( delta <= -120 && !Okular::Settings::viewContinuous() && vScroll == verticalScrollBar()->maximum() )
else
{
// go to next page
if ( (int)d->document->currentPage() < d->items.count() - 1 )
d->controlWheelAccumulatedDelta = 0;
if ( delta <= -QWheelEvent::DefaultDeltasPerStep && !Okular::Settings::viewContinuous() && vScroll == verticalScrollBar()->maximum() )
{
// more optimized than document->setNextPage and then move view to top
Okular::DocumentViewport newViewport = d->document->viewport();
newViewport.pageNumber += viewColumns();
if ( newViewport.pageNumber >= (int)d->items.count() )
newViewport.pageNumber = d->items.count() - 1;
newViewport.rePos.enabled = true;
newViewport.rePos.normalizedY = 0.0;
d->document->setViewport( newViewport );
// go to next page
if ( (int)d->document->currentPage() < d->items.count() - 1 )
{
// more optimized than document->setNextPage and then move view to top
Okular::DocumentViewport newViewport = d->document->viewport();
newViewport.pageNumber += viewColumns();
if ( newViewport.pageNumber >= (int)d->items.count() )
newViewport.pageNumber = d->items.count() - 1;
newViewport.rePos.enabled = true;
newViewport.rePos.normalizedY = 0.0;
d->document->setViewport( newViewport );
}
}
}
else if ( delta >= 120 && !Okular::Settings::viewContinuous() && vScroll == verticalScrollBar()->minimum() )
{
// go to prev page
if ( d->document->currentPage() > 0 )
else if ( delta >= QWheelEvent::DefaultDeltasPerStep && !Okular::Settings::viewContinuous() && vScroll == verticalScrollBar()->minimum() )
{
// more optimized than document->setPrevPage and then move view to bottom
Okular::DocumentViewport newViewport = d->document->viewport();
newViewport.pageNumber -= viewColumns();
if ( newViewport.pageNumber < 0 )
newViewport.pageNumber = 0;
newViewport.rePos.enabled = true;
newViewport.rePos.normalizedY = 1.0;
d->document->setViewport( newViewport );
// go to prev page
if ( d->document->currentPage() > 0 )
{
// more optimized than document->setPrevPage and then move view to bottom
Okular::DocumentViewport newViewport = d->document->viewport();
newViewport.pageNumber -= viewColumns();
if ( newViewport.pageNumber < 0 )
newViewport.pageNumber = 0;
newViewport.rePos.enabled = true;
newViewport.rePos.normalizedY = 1.0;
d->document->setViewport( newViewport );
}
}
else
QAbstractScrollArea::wheelEvent( e );
}
else
QAbstractScrollArea::wheelEvent( e );
updateCursor();
}
......
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