diff --git a/src/gui/qgscomposerview.cpp b/src/gui/qgscomposerview.cpp index f66dd5e5795..26f48c9093b 100644 --- a/src/gui/qgscomposerview.cpp +++ b/src/gui/qgscomposerview.cpp @@ -106,6 +106,7 @@ void QgsComposerView::mousePressEvent( QMouseEvent* e ) QPointF scenePoint = mapToScene( e->pos() ); QPointF snappedScenePoint = composition()->snapPointToGrid( scenePoint ); + mMousePressStartPos = e->pos(); //lock/unlock position of item with right click if ( e->button() == Qt::RightButton ) @@ -576,12 +577,37 @@ void QgsComposerView::mouseReleaseEvent( QMouseEvent* e ) return; } + QPoint mousePressStopPoint = e->pos(); + int diffX = mousePressStopPoint.x() - mMousePressStartPos.x(); + int diffY = mousePressStopPoint.y() - mMousePressStartPos.y(); + + //was this just a click? or a click and drag? + bool clickOnly = false; + if ( qAbs( diffX ) < 2 && qAbs( diffY ) < 2 ) + { + clickOnly = true; + } + QPointF scenePoint = mapToScene( e->pos() ); if ( mPanning ) { mPanning = false; + if ( clickOnly && e->button() == Qt::MidButton ) + { + //middle mouse button click = recenter on point + + //get current visible part of scene + QRect viewportRect( 0, 0, viewport()->width(), viewport()->height() ); + QgsRectangle visibleRect = QgsRectangle( mapToScene( viewportRect ).boundingRect() ); + visibleRect.scale( 1, scenePoint.x(), scenePoint.y() ); + QRectF boundsRect = visibleRect.toRectF(); + + //zoom view to fit desired bounds + fitInView( boundsRect, Qt::KeepAspectRatio ); + } + //set new cursor if ( mCurrentTool == Pan ) { @@ -1232,6 +1258,12 @@ void QgsComposerView::wheelZoom( QWheelEvent * event ) int wheelAction = mySettings.value( "/qgis/wheel_action", 2 ).toInt(); double zoomFactor = mySettings.value( "/qgis/zoom_factor", 2 ).toDouble(); + if ( event->modifiers() & Qt::ControlModifier ) + { + //holding ctrl while wheel zooming results in a finer zoom + zoomFactor = 1.0 + ( zoomFactor - 1.0 ) / 10.0; + } + //caculate zoom scale factor bool zoomIn = event->delta() > 0; double scaleFactor = ( zoomIn ? 1 / zoomFactor : zoomFactor ); diff --git a/src/gui/qgscomposerview.h b/src/gui/qgscomposerview.h index 580ce5c9903..880704e726e 100644 --- a/src/gui/qgscomposerview.h +++ b/src/gui/qgscomposerview.h @@ -190,6 +190,7 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView bool mPanning; QPoint mMouseLastXY; QPoint mMouseCurrentXY; + QPoint mMousePressStartPos; /**Zoom composition from a mouse wheel event*/ void wheelZoom( QWheelEvent * event );