Quantum GIS API Documentation  1.7.4
src/gui/qgsmaptoolpan.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002     qgsmaptoolpan.h  -  map tool for panning in map canvas
00003     ---------------------
00004     begin                : January 2006
00005     copyright            : (C) 2006 by Martin Dobias
00006     email                : wonder.sk at gmail dot com
00007  ***************************************************************************
00008  *                                                                         *
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU General Public License as published by  *
00011  *   the Free Software Foundation; either version 2 of the License, or     *
00012  *   (at your option) any later version.                                   *
00013  *                                                                         *
00014  ***************************************************************************/
00015 /* $Id$ */
00016 
00017 #include "qgsmaptoolpan.h"
00018 #include "qgsmapcanvas.h"
00019 #include "qgscursors.h"
00020 #include "qgsmaptopixel.h"
00021 #include <QBitmap>
00022 #include <QCursor>
00023 #include <QMouseEvent>
00024 
00025 
00026 QgsMapToolPan::QgsMapToolPan( QgsMapCanvas* canvas )
00027     : QgsMapTool( canvas ), mDragging( false )
00028 {
00029   // set cursor
00030   QBitmap panBmp = QBitmap::fromData( QSize( 16, 16 ), pan_bits );
00031   QBitmap panBmpMask = QBitmap::fromData( QSize( 16, 16 ), pan_mask_bits );
00032   mCursor = QCursor( panBmp, panBmpMask, 5, 5 );
00033 }
00034 
00035 
00036 void QgsMapToolPan::canvasMoveEvent( QMouseEvent * e )
00037 {
00038   if (( e->buttons() & Qt::LeftButton ) )
00039   {
00040     mDragging = true;
00041     // move map and other canvas items
00042     mCanvas->panAction( e );
00043   }
00044 }
00045 
00046 void QgsMapToolPan::canvasReleaseEvent( QMouseEvent * e )
00047 {
00048   if ( e->button() == Qt::LeftButton )
00049   {
00050     if ( mDragging )
00051     {
00052       mCanvas->panActionEnd( e->pos() );
00053       mDragging = false;
00054     }
00055     else // add pan to mouse cursor
00056     {
00057       // transform the mouse pos to map coordinates
00058       QgsPoint center = mCanvas->getCoordinateTransform()->toMapPoint( e->x(), e->y() );
00059       mCanvas->setExtent( QgsRectangle( center, center ) );
00060       mCanvas->refresh();
00061     }
00062   }
00063 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines