QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 }
const unsigned char pan_bits[]
Definition: qgscursors.cpp:72
virtual void canvasReleaseEvent(QMouseEvent *e)
Overridden mouse release event.
void refresh()
Repaints the canvas map.
virtual void canvasMoveEvent(QMouseEvent *e)
Overridden mouse move event.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:104
QString mToolName
translated name of the map tool
Definition: qgsmaptool.h:202
QgsMapCanvas * mCanvas
pointer to map canvas
Definition: qgsmaptool.h:188
QCursor mCursor
cursor used in map tool
Definition: qgsmaptool.h:191
A class to represent a point.
Definition: qgspoint.h:63
Abstract base class for all map tools.
Definition: qgsmaptool.h:48
const unsigned char pan_mask_bits[]
Definition: qgscursors.cpp:79
void panAction(QMouseEvent *event)
Called when mouse is moving and pan is activated.
QgsMapToolPan(QgsMapCanvas *canvas)
constructor
const QgsMapToPixel * getCoordinateTransform()
Get the current coordinate transform.
void setCenter(const QgsPoint &center)
Set the center of the map canvas, in geographical coordinates.
QgsPoint toMapPoint(double x, double y) const
void panActionEnd(QPoint releasePoint)
Ends pan action and redraws the canvas.
#define tr(sourceText)