Skip to content

Commit ecc4925

Browse files
committedMar 17, 2017
[FEATURE] Allow using secondary zoom wheel on mouse to magnify canvas
1 parent 1a50352 commit ecc4925

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed
 

‎src/gui/qgsmapcanvas.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,25 +1404,35 @@ void QgsMapCanvas::wheelEvent( QWheelEvent *e )
14041404
}
14051405

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

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

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

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

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

1425-
zoomByFactor( signedWheelFactor, &newCenter );
1426+
switch ( e->orientation() )
1427+
{
1428+
case Qt::Vertical:
1429+
zoomByFactor( signedWheelFactor, &newCenter );
1430+
break;
1431+
1432+
case Qt::Horizontal:
1433+
setMagnificationFactor( mapSettings().magnificationFactor() / signedWheelFactor );
1434+
break;
1435+
}
14261436
}
14271437

14281438
void QgsMapCanvas::setWheelFactor( double factor )

0 commit comments

Comments
 (0)
Please sign in to comment.