Skip to content
Permalink
Browse files
[FEATURE] Allow using secondary zoom wheel on mouse to magnify canvas
  • Loading branch information
nyalldawson committed Mar 17, 2017
1 parent 1a50352 commit ecc49256a37d4333d9cefdeefff1f3fd7a38d893
Showing with 13 additions and 3 deletions.
  1. +13 −3 src/gui/qgsmapcanvas.cpp
@@ -1404,25 +1404,35 @@ void QgsMapCanvas::wheelEvent( QWheelEvent *e )
}

double zoomFactor = mWheelZoomFactor;
double delta = e->orientation() == Qt::Vertical ? e->angleDelta().y() : e->angleDelta().x();

// "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() );
zoomFactor = 1.0 + ( zoomFactor - 1.0 ) / 120.0 * qAbs( delta );

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->angleDelta().y() > 0 ? 1 / zoomFactor : zoomFactor;
double signedWheelFactor = delta > 0 ? 1 / zoomFactor : zoomFactor;

// zoom map to mouse cursor by scaling
QgsPoint oldCenter = center();
QgsPoint mousePos( getCoordinateTransform()->toMapPoint( e->x(), e->y() ) );
QgsPoint newCenter( mousePos.x() + ( ( oldCenter.x() - mousePos.x() ) * signedWheelFactor ),
mousePos.y() + ( ( oldCenter.y() - mousePos.y() ) * signedWheelFactor ) );

zoomByFactor( signedWheelFactor, &newCenter );
switch ( e->orientation() )
{
case Qt::Vertical:
zoomByFactor( signedWheelFactor, &newCenter );
break;

case Qt::Horizontal:
setMagnificationFactor( mapSettings().magnificationFactor() / signedWheelFactor );
break;
}
}

void QgsMapCanvas::setWheelFactor( double factor )

0 comments on commit ecc4925

Please sign in to comment.