@@ -62,6 +62,7 @@ email : sherman at mrcc.com
62
62
#include " qgsproject.h"
63
63
#include " qgsrubberband.h"
64
64
#include " qgsvectorlayer.h"
65
+ #include " qgscursors.h"
65
66
#include < math.h>
66
67
67
68
@@ -212,6 +213,7 @@ QgsMapCanvas::QgsMapCanvas( QWidget * parent, const char *name )
212
213
, mSnappingUtils( nullptr )
213
214
, mScaleLocked( false )
214
215
, mExpressionContextScope( tr( " Map Canvas" ) )
216
+ , mZoomDragging( false )
215
217
{
216
218
setObjectName ( name );
217
219
mScene = new QGraphicsScene ();
@@ -273,6 +275,9 @@ QgsMapCanvas::QgsMapCanvas( QWidget * parent, const char *name )
273
275
mPreviewEffect = new QgsPreviewEffect ( this );
274
276
viewport ()->setGraphicsEffect ( mPreviewEffect );
275
277
278
+ QPixmap zoomPixmap = QPixmap (( const char ** )( zoom_in ) );
279
+ mZoomCursor = QCursor ( zoomPixmap, 7 , 7 );
280
+
276
281
setInteractive ( false );
277
282
278
283
refresh ();
@@ -1342,6 +1347,50 @@ void QgsMapCanvas::mouseDoubleClickEvent( QMouseEvent* e )
1342
1347
}// mouseDoubleClickEvent
1343
1348
1344
1349
1350
+ void QgsMapCanvas::beginZoomRect ( QPoint pos )
1351
+ {
1352
+ mZoomRect .setRect ( 0 , 0 , 0 , 0 );
1353
+ QApplication::setOverrideCursor ( mZoomCursor );
1354
+ mZoomDragging = true ;
1355
+ mZoomRubberBand .reset ( new QgsRubberBand ( this , QGis::Polygon ) );
1356
+ QColor color ( Qt::blue );
1357
+ color.setAlpha ( 63 );
1358
+ mZoomRubberBand ->setColor ( color );
1359
+ mZoomRect .setTopLeft ( pos );
1360
+ }
1361
+
1362
+ void QgsMapCanvas::endZoomRect ( QPoint pos )
1363
+ {
1364
+ mZoomDragging = false ;
1365
+ mZoomRubberBand .reset ( nullptr );
1366
+ QApplication::restoreOverrideCursor ();
1367
+
1368
+ // store the rectangle
1369
+ mZoomRect .setRight ( pos.x () );
1370
+ mZoomRect .setBottom ( pos.y () );
1371
+
1372
+ if ( mZoomRect .width () < 5 && mZoomRect .height () < 5 )
1373
+ {
1374
+ // probably a mistake - would result in huge zoom!
1375
+ return ;
1376
+ }
1377
+
1378
+ // account for bottom right -> top left dragging
1379
+ mZoomRect = mZoomRect .normalized ();
1380
+
1381
+ // set center and zoom
1382
+ const QSize& zoomRectSize = mZoomRect .size ();
1383
+ const QSize& canvasSize = mSettings .outputSize ();
1384
+ double sfx = ( double )zoomRectSize.width () / canvasSize.width ();
1385
+ double sfy = ( double )zoomRectSize.height () / canvasSize.height ();
1386
+ double sf = qMax ( sfx, sfy );
1387
+
1388
+ QgsPoint c = mSettings .mapToPixel ().toMapCoordinates ( mZoomRect .center () );
1389
+
1390
+ zoomByFactor ( sf, &c );
1391
+ refresh ();
1392
+ }
1393
+
1345
1394
void QgsMapCanvas::mousePressEvent ( QMouseEvent* e )
1346
1395
{
1347
1396
// use middle mouse button for panning, map tools won't receive any events in that case
@@ -1352,12 +1401,20 @@ void QgsMapCanvas::mousePressEvent( QMouseEvent* e )
1352
1401
}
1353
1402
else
1354
1403
{
1355
-
1356
1404
// call handler of current map tool
1357
1405
if ( mMapTool )
1358
1406
{
1359
- QScopedPointer<QgsMapMouseEvent> me ( new QgsMapMouseEvent ( this , e ) );
1360
- mMapTool ->canvasPressEvent ( me.data () );
1407
+ if ( mMapTool ->flags () & QgsMapTool::AllowZoomRect && e->button () == Qt::LeftButton
1408
+ && e->modifiers () & Qt::ShiftModifier )
1409
+ {
1410
+ beginZoomRect ( e->pos () );
1411
+ return ;
1412
+ }
1413
+ else
1414
+ {
1415
+ QScopedPointer<QgsMapMouseEvent> me ( new QgsMapMouseEvent ( this , e ) );
1416
+ mMapTool ->canvasPressEvent ( me.data () );
1417
+ }
1361
1418
}
1362
1419
}
1363
1420
@@ -1382,6 +1439,12 @@ void QgsMapCanvas::mouseReleaseEvent( QMouseEvent* e )
1382
1439
}
1383
1440
else
1384
1441
{
1442
+ if ( mZoomDragging && e->button () == Qt::LeftButton )
1443
+ {
1444
+ endZoomRect ( e->pos () );
1445
+ return ;
1446
+ }
1447
+
1385
1448
// call handler of current map tool
1386
1449
if ( mMapTool )
1387
1450
{
@@ -1572,6 +1635,12 @@ void QgsMapCanvas::mouseMoveEvent( QMouseEvent * e )
1572
1635
{
1573
1636
panAction ( e );
1574
1637
}
1638
+ else if ( mZoomDragging )
1639
+ {
1640
+ mZoomRect .setBottomRight ( e->pos () );
1641
+ mZoomRubberBand ->setToCanvasRectangle ( mZoomRect );
1642
+ mZoomRubberBand ->show ();
1643
+ }
1575
1644
else
1576
1645
{
1577
1646
// call handler of current map tool
0 commit comments