QGIS API Documentation  2.4.0-Chugiak
 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 }
A rectangle specified with double values.
Definition: qgsrectangle.h:35
const unsigned char pan_bits[]
Definition: qgscursors.cpp:72
virtual void canvasReleaseEvent(QMouseEvent *e)
Overridden mouse release event.
void setExtent(const QgsRectangle &r)
Set the extent of the map canvas.
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
QgsMapCanvas * mCanvas
pointer to map canvas
Definition: qgsmaptool.h:184
QCursor mCursor
cursor used in map tool
Definition: qgsmaptool.h:187
bool mDragging
Flag to indicate a map canvas drag operation is taking place.
Definition: qgsmaptoolpan.h:44
A class to represent a point geometry.
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.
QgsPoint toMapPoint(double x, double y) const
void panActionEnd(QPoint releasePoint)
Ends pan action and redraws the canvas.