Skip to content

Commit

Permalink
Merge pull request #491 from borysiasty/master
Browse files Browse the repository at this point in the history
[API] expose mouse wheel to map tools, use it for zoom only if no keyboard modifier pressed
  • Loading branch information
NathanW2 committed Mar 31, 2013
2 parents 7d9f444 + daeafcc commit 05506e3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions python/gui/qgsmaptool.sip
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class QgsMapTool : QObject
//! Mouse release event for overriding. Default implementation does nothing.
virtual void canvasReleaseEvent( QMouseEvent * e );

//! Mouse wheel event for overriding. Default implementation does nothing.
//! Added in version 2.0
virtual void wheelEvent( QWheelEvent * e );

//! Key event for overriding. Default implementation does nothing.
virtual void keyPressEvent( QKeyEvent* e );

Expand Down
12 changes: 12 additions & 0 deletions src/gui/qgsmapcanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ email : sherman at mrcc.com
#include <QWheelEvent>

#include "qgis.h"
#include "qgsapplication.h"
#include "qgslogger.h"
#include "qgsmapcanvas.h"
#include "qgsmapcanvasmap.h"
Expand Down Expand Up @@ -1093,6 +1094,17 @@ void QgsMapCanvas::wheelEvent( QWheelEvent *e )
return;
}

if ( mMapTool )
{
mMapTool->wheelEvent( e );
}

if ( QgsApplication::keyboardModifiers() )
{
// leave the wheel for map tools if any modifier pressed
return;
}

switch ( mWheelAction )
{
case WheelZoom:
Expand Down
5 changes: 5 additions & 0 deletions src/gui/qgsmaptool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ void QgsMapTool::canvasReleaseEvent( QMouseEvent *e )
Q_UNUSED( e );
}

void QgsMapTool::wheelEvent( QWheelEvent *e )
{
Q_UNUSED( e );
}

void QgsMapTool::keyPressEvent( QKeyEvent *e )
{
Q_UNUSED( e );
Expand Down
5 changes: 5 additions & 0 deletions src/gui/qgsmaptool.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class QgsMapLayer;
class QgsMapCanvas;
class QKeyEvent;
class QMouseEvent;
class QWheelEvent;
class QgsPoint;
class QgsRectangle;
class QPoint;
Expand Down Expand Up @@ -61,6 +62,10 @@ class GUI_EXPORT QgsMapTool : public QObject
//! Mouse release event for overriding. Default implementation does nothing.
virtual void canvasReleaseEvent( QMouseEvent * e );

//! Mouse wheel event for overriding. Default implementation does nothing.
//! Added in version 2.0
virtual void wheelEvent ( QWheelEvent* e );

//! Key event for overriding. Default implementation does nothing.
virtual void keyPressEvent( QKeyEvent* e );

Expand Down

0 comments on commit 05506e3

Please sign in to comment.