mirror of
https://invent.kde.org/graphics/okular
synced 2024-08-25 02:45:38 +00:00
Accumulate Control+Wheel Deltas until they reach QWheelEvent::DefaultDeltasPerStep
This way zooming in/out with a touchpad is easier to control BUGS: 377128
This commit is contained in:
parent
c058c809e2
commit
7a50ce0edf
|
@ -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
|
||||
slotZoomIn();
|
||||
}
|
||||
else if ( delta <= -120 && !Okular::Settings::viewContinuous() && vScroll == verticalScrollBar()->maximum() )
|
||||
{
|
||||
// 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 );
|
||||
d->controlWheelAccumulatedDelta = 0;
|
||||
}
|
||||
}
|
||||
else if ( delta >= 120 && !Okular::Settings::viewContinuous() && vScroll == verticalScrollBar()->minimum() )
|
||||
{
|
||||
// go to prev page
|
||||
if ( d->document->currentPage() > 0 )
|
||||
else if ( d->controlWheelAccumulatedDelta >= QWheelEvent::DefaultDeltasPerStep )
|
||||
{
|
||||
// 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 );
|
||||
slotZoomIn();
|
||||
d->controlWheelAccumulatedDelta = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
QAbstractScrollArea::wheelEvent( e );
|
||||
{
|
||||
d->controlWheelAccumulatedDelta = 0;
|
||||
|
||||
if ( delta <= -QWheelEvent::DefaultDeltasPerStep && !Okular::Settings::viewContinuous() && vScroll == verticalScrollBar()->maximum() )
|
||||
{
|
||||
// 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 >= QWheelEvent::DefaultDeltasPerStep && !Okular::Settings::viewContinuous() && vScroll == verticalScrollBar()->minimum() )
|
||||
{
|
||||
// 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 );
|
||||
}
|
||||
|
||||
updateCursor();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue