QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsmaptoolpan.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmaptoolpan.h - map tool for panning in map canvas
3  ---------------------
4  begin : January 2006
5  copyright : (C) 2006 by Martin Dobias
6  email : wonder.sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgsmaptoolpan.h"
17 #include "qgsmapcanvas.h"
18 #include "qgscursors.h"
19 #include "qgsmaptopixel.h"
20 #include <QBitmap>
21 #include <QCursor>
22 #include <QMouseEvent>
23 
24 
26  : QgsMapTool( canvas )
27  , mDragging( false )
28 {
29  mToolName = tr( "Pan" );
30  // set cursor
31  QBitmap panBmp = QBitmap::fromData( QSize( 16, 16 ), pan_bits );
32  QBitmap panBmpMask = QBitmap::fromData( QSize( 16, 16 ), pan_mask_bits );
33  mCursor = QCursor( panBmp, panBmpMask, 5, 5 );
34 }
35 
36 
37 void QgsMapToolPan::canvasMoveEvent( QMouseEvent * e )
38 {
39  if (( e->buttons() & Qt::LeftButton ) )
40  {
41  mDragging = true;
42  // move map and other canvas items
43  mCanvas->panAction( e );
44  }
45 }
46 
47 void QgsMapToolPan::canvasReleaseEvent( QMouseEvent * e )
48 {
49  if ( e->button() == Qt::LeftButton )
50  {
51  if ( mDragging )
52  {
53  mCanvas->panActionEnd( e->pos() );
54  mDragging = false;
55  }
56  else // add pan to mouse cursor
57  {
58  // transform the mouse pos to map coordinates
59  QgsPoint center = mCanvas->getCoordinateTransform()->toMapPoint( e->x(), e->y() );
60  mCanvas->setCenter( center );
61  mCanvas->refresh();
62  }
63  }
64 }