enhancement_1004.txt

solution - anachronics -, 2008-03-19 01:03 PM

Download (2.2 KB)

 
1
Index: src/gui/qgsmapcanvas.cpp
2
===================================================================
3
--- src/gui/qgsmapcanvas.cpp	(revisión: 8248)
4
+++ src/gui/qgsmapcanvas.cpp	(copia de trabajo)
5
@@ -819,12 +819,30 @@
6
       // zoom without changing extent
7
       zoom(e->delta() > 0);
8
       break;
9
-      
10
+
11
     case WheelZoomAndRecenter:
12
       // zoom and don't change extent
13
       zoomWithCenter(e->x(), e->y(), e->delta() > 0);
14
       break;
15
-      
16
+
17
+    case WheelZoomToMouseCursor:
18
+    {
19
+      // zoom map to mouse cursor
20
+      double scaleFactor = e->delta() > 0 ? 1 / mWheelZoomFactor : mWheelZoomFactor;
21
+
22
+      QgsPoint oldCenter(mMapRender->extent().center());
23
+      QgsPoint mousePos(getCoordinateTransform()->toMapPoint(e->x(), e->y()));
24
+      QgsPoint newCenter(mousePos.x() + ((oldCenter.x() - mousePos.x()) * scaleFactor), 
25
+        mousePos.y() + ((oldCenter.y() - mousePos.y()) * scaleFactor));
26
+
27
+      // same as zoomWithCenter (no coordinate transformations are needed)
28
+      QgsRect extent = mMapRender->extent();
29
+      extent.scale(scaleFactor, &newCenter);
30
+      setExtent(extent);
31
+      refresh();
32
+      break;
33
+    }
34
+
35
     case WheelNothing:
36
       // well, nothing!
37
       break;
38
Index: src/gui/qgsmapcanvas.h
39
===================================================================
40
--- src/gui/qgsmapcanvas.h	(revisión: 8248)
41
+++ src/gui/qgsmapcanvas.h	(copia de trabajo)
42
@@ -95,7 +95,7 @@
43
 
44
   public:
45
     
46
-    enum WheelAction { WheelZoom, WheelZoomAndRecenter, WheelNothing };
47
+    enum WheelAction { WheelZoom, WheelZoomAndRecenter, WheelZoomToMouseCursor, WheelNothing };
48
         
49
     //! Constructor
50
     QgsMapCanvas(QWidget * parent = 0, const char *name = 0);
51
Index: src/ui/qgsoptionsbase.ui
52
===================================================================
53
--- src/ui/qgsoptionsbase.ui	(revisión: 8248)
54
+++ src/ui/qgsoptionsbase.ui	(copia de trabajo)
55
@@ -489,6 +489,11 @@
56
             </item>
57
             <item>
58
              <property name="text" >
59
+              <string>Zoom to mouse cursor</string>
60
+             </property>
61
+            </item>
62
+            <item>
63
+             <property name="text" >
64
               <string>Nothing</string>
65
              </property>
66
             </item>