Skip to content

Commit

Permalink
[layouts] Middle mouse click in pan tool should recenter view
Browse files Browse the repository at this point in the history
Port missing functionality from composer
  • Loading branch information
nyalldawson committed Jan 10, 2018
1 parent 322f2e8 commit fa2aff1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/gui/layout/qgslayoutviewtoolpan.cpp
Expand Up @@ -26,6 +26,8 @@ QgsLayoutViewToolPan::QgsLayoutViewToolPan( QgsLayoutView *view )

void QgsLayoutViewToolPan::layoutPressEvent( QgsLayoutViewMouseEvent *event )
{
mMousePressStartPos = event->pos();

if ( event->button() != Qt::LeftButton )
{
event->ignore();
Expand Down Expand Up @@ -53,8 +55,30 @@ void QgsLayoutViewToolPan::layoutMoveEvent( QgsLayoutViewMouseEvent *event )

void QgsLayoutViewToolPan::layoutReleaseEvent( QgsLayoutViewMouseEvent *event )
{
bool clickOnly = !isClickAndDrag( mMousePressStartPos, event->pos() );

if ( event->button() == Qt::MiddleButton && clickOnly )
{
//middle mouse button click = recenter on point

//get current visible part of scene
QRect viewportRect( 0, 0, view()->viewport()->width(), view()->viewport()->height() );
QgsRectangle visibleRect = QgsRectangle( view()->mapToScene( viewportRect ).boundingRect() );
QPointF scenePoint = event->layoutPoint();
visibleRect.scale( 1, scenePoint.x(), scenePoint.y() );
QRectF boundsRect = visibleRect.toRectF();

//zoom view to fit desired bounds
view()->fitInView( boundsRect, Qt::KeepAspectRatio );
view()->emitZoomLevelChanged();
view()->viewChanged();
return;
}

if ( !mIsPanning || event->button() != Qt::LeftButton )
{
view()->emitZoomLevelChanged();
view()->viewChanged();
event->ignore();
return;
}
Expand Down
2 changes: 2 additions & 0 deletions src/gui/layout/qgslayoutviewtoolpan.h
Expand Up @@ -46,6 +46,8 @@ class GUI_EXPORT QgsLayoutViewToolPan : public QgsLayoutViewTool

bool mIsPanning = false;
QPoint mLastMousePos;
//! Start position for mouse press
QPoint mMousePressStartPos;

};

Expand Down

0 comments on commit fa2aff1

Please sign in to comment.