Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 /* $Id$ */
16 
17 #include "qgsmaptoolpan.h"
18 #include "qgsmapcanvas.h"
19 #include "qgscursors.h"
20 #include "qgsmaptopixel.h"
21 #include <QBitmap>
22 #include <QCursor>
23 #include <QMouseEvent>
24 
25 
27  : QgsMapTool( canvas ), mDragging( false )
28 {
29  // set cursor
30  QBitmap panBmp = QBitmap::fromData( QSize( 16, 16 ), pan_bits );
31  QBitmap panBmpMask = QBitmap::fromData( QSize( 16, 16 ), pan_mask_bits );
32  mCursor = QCursor( panBmp, panBmpMask, 5, 5 );
33 }
34 
35 
36 void QgsMapToolPan::canvasMoveEvent( QMouseEvent * e )
37 {
38  if (( e->buttons() & Qt::LeftButton ) )
39  {
40  mDragging = true;
41  // move map and other canvas items
42  mCanvas->panAction( e );
43  }
44 }
45 
46 void QgsMapToolPan::canvasReleaseEvent( QMouseEvent * e )
47 {
48  if ( e->button() == Qt::LeftButton )
49  {
50  if ( mDragging )
51  {
52  mCanvas->panActionEnd( e->pos() );
53  mDragging = false;
54  }
55  else // add pan to mouse cursor
56  {
57  // transform the mouse pos to map coordinates
58  QgsPoint center = mCanvas->getCoordinateTransform()->toMapPoint( e->x(), e->y() );
59  mCanvas->setExtent( QgsRectangle( center, center ) );
60  mCanvas->refresh();
61  }
62  }
63 }