Skip to content

Commit

Permalink
Add support for fine-resolution mouse wheel zooming
Browse files Browse the repository at this point in the history
Some mouses (notably on mac) have finer resolutions. They send mouse
wheel events in a higher frequency but with smaller angleDelta() values.
So far, zooming with such mouses was leading to unusable fast zoom
actions.
  • Loading branch information
m-kuhn committed Dec 9, 2016
1 parent 322b703 commit cf5f373
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/gui/qgsmapcanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1449,13 +1449,17 @@ void QgsMapCanvas::wheelEvent( QWheelEvent *e )
}

double zoomFactor = mWheelZoomFactor;

// "Normal" mouse have an angle delta of 120, precision mouses provide data faster, in smaller steps
zoomFactor = 1.0 + ( zoomFactor - 1.0 ) / 120.0 * qAbs( e->angleDelta().y() );

if ( e->modifiers() & Qt::ControlModifier )
{
//holding ctrl while wheel zooming results in a finer zoom
zoomFactor = 1.0 + ( zoomFactor - 1.0 ) / 20.0;
}

double signedWheelFactor = e->delta() > 0 ? 1 / zoomFactor : zoomFactor;
double signedWheelFactor = e->angleDelta().y() > 0 ? 1 / zoomFactor : zoomFactor;

// zoom map to mouse cursor by scaling
QgsPoint oldCenter = center();
Expand Down

1 comment on commit cf5f373

@NathanW2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix.

Please sign in to comment.