Skip to content

Commit 698d693

Browse files
author
mhugent
committedMar 25, 2008
Applied patch 1004 that adds zoom to direction of mouse cursor
git-svn-id: http://svn.osgeo.org/qgis/trunk@8265 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 26aafb7 commit 698d693

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed
 

‎src/gui/qgsmapcanvas.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -819,12 +819,30 @@ void QgsMapCanvas::wheelEvent(QWheelEvent *e)
819819
// zoom without changing extent
820820
zoom(e->delta() > 0);
821821
break;
822-
822+
823823
case WheelZoomAndRecenter:
824824
// zoom and don't change extent
825825
zoomWithCenter(e->x(), e->y(), e->delta() > 0);
826826
break;
827-
827+
828+
case WheelZoomToMouseCursor:
829+
{
830+
// zoom map to mouse cursor
831+
double scaleFactor = e->delta() > 0 ? 1 / mWheelZoomFactor : mWheelZoomFactor;
832+
833+
QgsPoint oldCenter(mMapRender->extent().center());
834+
QgsPoint mousePos(getCoordinateTransform()->toMapPoint(e->x(), e->y()));
835+
QgsPoint newCenter(mousePos.x() + ((oldCenter.x() - mousePos.x()) * scaleFactor),
836+
mousePos.y() + ((oldCenter.y() - mousePos.y()) * scaleFactor));
837+
838+
// same as zoomWithCenter (no coordinate transformations are needed)
839+
QgsRect extent = mMapRender->extent();
840+
extent.scale(scaleFactor, &newCenter);
841+
setExtent(extent);
842+
refresh();
843+
break;
844+
}
845+
828846
case WheelNothing:
829847
// well, nothing!
830848
break;

‎src/gui/qgsmapcanvas.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
9595

9696
public:
9797

98-
enum WheelAction { WheelZoom, WheelZoomAndRecenter, WheelNothing };
98+
enum WheelAction { WheelZoom, WheelZoomAndRecenter, WheelZoomToMouseCursor, WheelNothing };
9999

100100
//! Constructor
101101
QgsMapCanvas(QWidget * parent = 0, const char *name = 0);

‎src/ui/qgsoptionsbase.ui

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,11 @@
487487
<string>Zoom and recenter</string>
488488
</property>
489489
</item>
490+
<item>
491+
<property name="text" >
492+
<string>Zoom to mouse cursor</string>
493+
</property>
494+
</item>
490495
<item>
491496
<property name="text" >
492497
<string>Nothing</string>

0 commit comments

Comments
 (0)
Please sign in to comment.