Skip to content
Permalink
Browse files
Applied patch 1004 that adds zoom to direction of mouse cursor
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@8265 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Mar 25, 2008
1 parent 0a79f08 commit 513a0ea1cffd2e0f4e117909c558b8c0d01bb388
Showing with 26 additions and 3 deletions.
  1. +20 −2 src/gui/qgsmapcanvas.cpp
  2. +1 −1 src/gui/qgsmapcanvas.h
  3. +5 −0 src/ui/qgsoptionsbase.ui
@@ -819,12 +819,30 @@ void QgsMapCanvas::wheelEvent(QWheelEvent *e)
// zoom without changing extent
zoom(e->delta() > 0);
break;

case WheelZoomAndRecenter:
// zoom and don't change extent
zoomWithCenter(e->x(), e->y(), e->delta() > 0);
break;


case WheelZoomToMouseCursor:
{
// zoom map to mouse cursor
double scaleFactor = e->delta() > 0 ? 1 / mWheelZoomFactor : mWheelZoomFactor;

QgsPoint oldCenter(mMapRender->extent().center());
QgsPoint mousePos(getCoordinateTransform()->toMapPoint(e->x(), e->y()));
QgsPoint newCenter(mousePos.x() + ((oldCenter.x() - mousePos.x()) * scaleFactor),
mousePos.y() + ((oldCenter.y() - mousePos.y()) * scaleFactor));

// same as zoomWithCenter (no coordinate transformations are needed)
QgsRect extent = mMapRender->extent();
extent.scale(scaleFactor, &newCenter);
setExtent(extent);
refresh();
break;
}

case WheelNothing:
// well, nothing!
break;
@@ -95,7 +95,7 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView

public:

enum WheelAction { WheelZoom, WheelZoomAndRecenter, WheelNothing };
enum WheelAction { WheelZoom, WheelZoomAndRecenter, WheelZoomToMouseCursor, WheelNothing };

//! Constructor
QgsMapCanvas(QWidget * parent = 0, const char *name = 0);
@@ -487,6 +487,11 @@
<string>Zoom and recenter</string>
</property>
</item>
<item>
<property name="text" >
<string>Zoom to mouse cursor</string>
</property>
</item>
<item>
<property name="text" >
<string>Nothing</string>

0 comments on commit 513a0ea

Please sign in to comment.