patch-QgsMapToolPan-20091211.txt

Steven Mizuno, 2009-12-13 12:47 PM

Download (1.45 KB)

 
1
Index: src/gui/qgsmaptoolpan.cpp
2
===================================================================
3
--- src/gui/qgsmaptoolpan.cpp	(revision 12391)
4
+++ src/gui/qgsmaptoolpan.cpp	(working copy)
5
@@ -17,6 +17,7 @@
6
 #include "qgsmaptoolpan.h"
7
 #include "qgsmapcanvas.h"
8
 #include "qgscursors.h"
9
+#include "qgsmaptopixel.h"
10
 #include <QBitmap>
11
 #include <QCursor>
12
 #include <QMouseEvent>
13
@@ -34,8 +35,12 @@
14
 
15
 void QgsMapToolPan::canvasMoveEvent( QMouseEvent * e )
16
 {
17
-  if ( mDragging && ( e->buttons() & Qt::LeftButton ) )
18
+  if ( ( e->buttons() & Qt::LeftButton ) )
19
   {
20
+    if ( !mDragging )
21
+    {
22
+      mDragging = true;
23
+    }
24
     // move map and other canvas items
25
     mCanvas->panAction( e );
26
   }
27
@@ -46,16 +51,25 @@
28
 {
29
   if ( e->button() == Qt::LeftButton )
30
   {
31
-    mDragging = TRUE;
32
   }
33
 }
34
 
35
 
36
 void QgsMapToolPan::canvasReleaseEvent( QMouseEvent * e )
37
 {
38
-  if ( mDragging && e->button() == Qt::LeftButton )
39
+  if ( e->button() == Qt::LeftButton )
40
   {
41
-    mCanvas->panActionEnd( e->pos() );
42
-    mDragging = FALSE;
43
+    if ( mDragging )
44
+    {
45
+      mCanvas->panActionEnd( e->pos() );
46
+      mDragging = FALSE;
47
+    }
48
+    else	// add pan to mouse cursor
49
+    {
50
+      // transform the mouse pos to map coordinates
51
+      QgsPoint center = mCanvas->getCoordinateTransform()->toMapPoint( e->x(), e->y() );
52
+      mCanvas->setExtent( QgsRectangle( center, center ) );
53
+      mCanvas->refresh();
54
+    }
55
   }
56
 }