Quantum GIS API Documentation
1.8
|
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 00016 #include "qgsmaptoolpan.h" 00017 #include "qgsmapcanvas.h" 00018 #include "qgscursors.h" 00019 #include "qgsmaptopixel.h" 00020 #include <QBitmap> 00021 #include <QCursor> 00022 #include <QMouseEvent> 00023 00024 00025 QgsMapToolPan::QgsMapToolPan( QgsMapCanvas* canvas ) 00026 : QgsMapTool( canvas ), mDragging( false ) 00027 { 00028 // set cursor 00029 QBitmap panBmp = QBitmap::fromData( QSize( 16, 16 ), pan_bits ); 00030 QBitmap panBmpMask = QBitmap::fromData( QSize( 16, 16 ), pan_mask_bits ); 00031 mCursor = QCursor( panBmp, panBmpMask, 5, 5 ); 00032 } 00033 00034 00035 void QgsMapToolPan::canvasMoveEvent( QMouseEvent * e ) 00036 { 00037 if (( e->buttons() & Qt::LeftButton ) ) 00038 { 00039 mDragging = true; 00040 // move map and other canvas items 00041 mCanvas->panAction( e ); 00042 } 00043 } 00044 00045 void QgsMapToolPan::canvasReleaseEvent( QMouseEvent * e ) 00046 { 00047 if ( e->button() == Qt::LeftButton ) 00048 { 00049 if ( mDragging ) 00050 { 00051 mCanvas->panActionEnd( e->pos() ); 00052 mDragging = false; 00053 } 00054 else // add pan to mouse cursor 00055 { 00056 // transform the mouse pos to map coordinates 00057 QgsPoint center = mCanvas->getCoordinateTransform()->toMapPoint( e->x(), e->y() ); 00058 mCanvas->setExtent( QgsRectangle( center, center ) ); 00059 mCanvas->refresh(); 00060 } 00061 } 00062 }