Skip to content

Commit

Permalink
[composer] add some more navigation shortcuts - ctrl + scroll wheel =…
Browse files Browse the repository at this point in the history
… fine zoom, middle button click = recenter composition
  • Loading branch information
nyalldawson committed Nov 3, 2013
1 parent a411e79 commit 37d365c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/gui/qgscomposerview.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 );
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgscomposerview.h
Expand Up @@ -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 );
Expand Down

0 comments on commit 37d365c

Please sign in to comment.