21 #include <QMouseEvent> 30 mCursor = QCursor( Qt::OpenHandCursor );
35 mCanvas->ungrabGesture( Qt::PinchGesture );
40 mCanvas->grabGesture( Qt::PinchGesture );
46 mCanvas->ungrabGesture( Qt::PinchGesture );
52 if ( e->button() == Qt::LeftButton )
53 mCanvas->setCursor( QCursor( Qt::ClosedHandCursor ) );
61 if ( ( e->buttons() & Qt::LeftButton ) )
74 if ( e->button() == Qt::LeftButton )
95 if ( !QTouchDevice::devices().isEmpty() && !mPinching )
103 if ( QTouchDevice::devices().isEmpty() )
106 qDebug() <<
"gesture " << event;
107 if ( QGesture *gesture = event->gesture( Qt::PinchGesture ) )
110 pinchTriggered( static_cast<QPinchGesture *>( gesture ) );
115 void QgsMapToolPan::pinchTriggered( QPinchGesture *gesture )
117 if ( gesture->state() == Qt::GestureFinished )
120 if ( 0.98 < gesture->totalScaleFactor() && gesture->totalScaleFactor() < 1.02 )
127 QPoint pos = gesture->centerPoint().toPoint();
128 pos =
mCanvas->mapFromGlobal( pos );
132 r.
scale( 1 / gesture->totalScaleFactor(), ¢er );
A rectangle specified with double values.
void zoomWithCenter(int x, int y, bool zoomIn)
Zooms in/out with a given center.
void setCenter(const QgsPointXY ¢er)
Set the center of the map canvas, in geographical coordinates.
A class to represent a 2D point.
void scale(double scaleFactor, const QgsPointXY *c=nullptr)
Scale the rectangle around its center point.
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
void refresh()
Repaints the canvas map.
Map canvas is a class for displaying all GIS data types on a canvas.
QgsRectangle extent() const
Returns the current zoom extent of the map canvas.
void zoomOut()
Zoom out with fixed factor.
QgsPointXY toMapPoint(double x, double y) const
void panAction(QMouseEvent *event)
Called when mouse is moving and pan is activated.
void setExtent(const QgsRectangle &r, bool magnified=false)
Sets the extent of the map canvas.
const QgsMapToPixel * getCoordinateTransform()
Gets the current coordinate transform.
void panActionEnd(QPoint releasePoint)
Ends pan action and redraws the canvas.