@@ -38,7 +38,7 @@ QgsMapToolZoom::QgsMapToolZoom( QgsMapCanvas *canvas, bool zoomOut )
38
38
39
39
{
40
40
mToolName = tr ( " Zoom" );
41
- updateCursor ( );
41
+ setZoomMode ( mNativeZoomOut , true );
42
42
}
43
43
44
44
QgsMapToolZoom::~QgsMapToolZoom ()
@@ -52,6 +52,8 @@ void QgsMapToolZoom::canvasMoveEvent( QgsMapMouseEvent *e )
52
52
if ( !( e->buttons () & Qt::LeftButton ) )
53
53
return ;
54
54
55
+ setZoomMode ( e->modifiers ().testFlag ( Qt::AltModifier ) ^ mNativeZoomOut );
56
+
55
57
if ( !mDragging )
56
58
{
57
59
mDragging = true ;
@@ -62,6 +64,7 @@ void QgsMapToolZoom::canvasMoveEvent( QgsMapMouseEvent *e )
62
64
mRubberBand ->setColor ( color );
63
65
mZoomRect .setTopLeft ( e->pos () );
64
66
}
67
+
65
68
mZoomRect .setBottomRight ( e->pos () );
66
69
if ( mRubberBand )
67
70
{
@@ -85,6 +88,8 @@ void QgsMapToolZoom::canvasReleaseEvent( QgsMapMouseEvent *e )
85
88
if ( e->button () != Qt::LeftButton )
86
89
return ;
87
90
91
+ setZoomMode ( e->modifiers ().testFlag ( Qt::AltModifier ) ^ mNativeZoomOut );
92
+
88
93
// We are not really dragging in this case. This is sometimes caused by
89
94
// a pen based computer reporting a press, move, and release, all the
90
95
// one point.
@@ -136,30 +141,30 @@ void QgsMapToolZoom::deactivate()
136
141
QgsMapTool::deactivate ();
137
142
}
138
143
139
- void QgsMapToolZoom::updateCursor ( )
144
+ void QgsMapToolZoom::setZoomMode ( bool zoomOut, bool force )
140
145
{
146
+ if ( !force && zoomOut == mZoomOut )
147
+ return ;
148
+
149
+ mZoomOut = zoomOut;
141
150
setCursor ( mZoomOut ? mZoomOutCursor : mZoomInCursor );
142
151
}
143
152
144
153
void QgsMapToolZoom::keyPressEvent ( QKeyEvent *e )
145
154
{
146
155
if ( e->key () == Qt::Key_Alt )
147
156
{
148
- mZoomOut = !mZoomOut ;
149
- updateCursor ();
157
+ setZoomMode ( !mNativeZoomOut );
150
158
}
151
159
}
152
160
153
161
void QgsMapToolZoom::keyReleaseEvent ( QKeyEvent *e )
154
162
{
155
163
// key press events are not caught wile the mouse is pressed
156
- // so we can't mess if we are already dragging
157
- // we need to go back to native state, as it cannot be determine
158
- // (since the press event is not detected while mouse is pressed)
164
+ // this is detected in map canvas move event
159
165
160
166
if ( e->key () == Qt::Key_Alt )
161
167
{
162
- mZoomOut = mNativeZoomOut ;
163
- updateCursor ();
168
+ setZoomMode ( mNativeZoomOut );
164
169
}
165
170
}
0 commit comments