QGIS API Documentation  2.0.1-Dufour
 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 ), mDragging( false )
27 {
28  // set cursor
29  QBitmap panBmp = QBitmap::fromData( QSize( 16, 16 ), pan_bits );
30  QBitmap panBmpMask = QBitmap::fromData( QSize( 16, 16 ), pan_mask_bits );
31  mCursor = QCursor( panBmp, panBmpMask, 5, 5 );
32 }
33 
34 
35 void QgsMapToolPan::canvasMoveEvent( QMouseEvent * e )
36 {
37  if (( e->buttons() & Qt::LeftButton ) )
38  {
39  mDragging = true;
40  // move map and other canvas items
41  mCanvas->panAction( e );
42  }
43 }
44 
45 void QgsMapToolPan::canvasReleaseEvent( QMouseEvent * e )
46 {
47  if ( e->button() == Qt::LeftButton )
48  {
49  if ( mDragging )
50  {
51  mCanvas->panActionEnd( e->pos() );
52  mDragging = false;
53  }
54  else // add pan to mouse cursor
55  {
56  // transform the mouse pos to map coordinates
57  QgsPoint center = mCanvas->getCoordinateTransform()->toMapPoint( e->x(), e->y() );
58  mCanvas->setExtent( QgsRectangle( center, center ) );
59  mCanvas->refresh();
60  }
61  }
62 }