Skip to content
Permalink
Browse files

allow switching in/out mode while drawing zooming rect (#8261)

  • Loading branch information
3nids committed Oct 22, 2018
1 parent 8d7c54e commit adec719893c16dffe22a3393b6a1be7ea24a045a
Showing with 15 additions and 10 deletions.
  1. +14 −9 src/gui/qgsmaptoolzoom.cpp
  2. +1 −1 src/gui/qgsmaptoolzoom.h
@@ -38,7 +38,7 @@ QgsMapToolZoom::QgsMapToolZoom( QgsMapCanvas *canvas, bool zoomOut )

{
mToolName = tr( "Zoom" );
updateCursor();
setZoomMode( mNativeZoomOut, true );
}

QgsMapToolZoom::~QgsMapToolZoom()
@@ -52,6 +52,8 @@ void QgsMapToolZoom::canvasMoveEvent( QgsMapMouseEvent *e )
if ( !( e->buttons() & Qt::LeftButton ) )
return;

setZoomMode( e->modifiers().testFlag( Qt::AltModifier ) ^ mNativeZoomOut );

if ( !mDragging )
{
mDragging = true;
@@ -62,6 +64,7 @@ void QgsMapToolZoom::canvasMoveEvent( QgsMapMouseEvent *e )
mRubberBand->setColor( color );
mZoomRect.setTopLeft( e->pos() );
}

mZoomRect.setBottomRight( e->pos() );
if ( mRubberBand )
{
@@ -85,6 +88,8 @@ void QgsMapToolZoom::canvasReleaseEvent( QgsMapMouseEvent *e )
if ( e->button() != Qt::LeftButton )
return;

setZoomMode( e->modifiers().testFlag( Qt::AltModifier ) ^ mNativeZoomOut );

// We are not really dragging in this case. This is sometimes caused by
// a pen based computer reporting a press, move, and release, all the
// one point.
@@ -136,30 +141,30 @@ void QgsMapToolZoom::deactivate()
QgsMapTool::deactivate();
}

void QgsMapToolZoom::updateCursor()
void QgsMapToolZoom::setZoomMode( bool zoomOut, bool force )
{
if ( !force && zoomOut == mZoomOut )
return;

mZoomOut = zoomOut;
setCursor( mZoomOut ? mZoomOutCursor : mZoomInCursor );
}

void QgsMapToolZoom::keyPressEvent( QKeyEvent *e )
{
if ( e->key() == Qt::Key_Alt )
{
mZoomOut = !mZoomOut;
updateCursor();
setZoomMode( !mNativeZoomOut );
}
}

void QgsMapToolZoom::keyReleaseEvent( QKeyEvent *e )
{
// key press events are not caught wile the mouse is pressed
// so we can't mess if we are already dragging
// we need to go back to native state, as it cannot be determine
// (since the press event is not detected while mouse is pressed)
// this is detected in map canvas move event

if ( e->key() == Qt::Key_Alt )
{
mZoomOut = mNativeZoomOut;
updateCursor();
setZoomMode( mNativeZoomOut );
}
}
@@ -64,7 +64,7 @@ class GUI_EXPORT QgsMapToolZoom : public QgsMapTool
QCursor mZoomInCursor;

private:
void updateCursor();
void setZoomMode( bool zoomOut, bool force = false );
};

#endif

0 comments on commit adec719

Please sign in to comment.
You can’t perform that action at this time.