Skip to content
Permalink
Browse files

[composer] add some more navigation shortcuts - ctrl + scroll wheel =…

… fine zoom, middle button click = recenter composition
  • Loading branch information
nyalldawson committed Nov 3, 2013
1 parent a411e79 commit 37d365c0a146127379128db0376f80e8c7f3ba31
Showing with 33 additions and 0 deletions.
  1. +32 −0 src/gui/qgscomposerview.cpp
  2. +1 −0 src/gui/qgscomposerview.h
@@ -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 );
@@ -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 );

0 comments on commit 37d365c

Please sign in to comment.
You can’t perform that action at this time.