Skip to content
Permalink
Browse files

[layouts] Middle mouse click in pan tool should recenter view

Port missing functionality from composer
  • Loading branch information
nyalldawson committed Jan 10, 2018
1 parent 322f2e8 commit fa2aff18e50ff0f2439b1d13815db9d0a0140e90
Showing with 26 additions and 0 deletions.
  1. +24 −0 src/gui/layout/qgslayoutviewtoolpan.cpp
  2. +2 −0 src/gui/layout/qgslayoutviewtoolpan.h
@@ -26,6 +26,8 @@ QgsLayoutViewToolPan::QgsLayoutViewToolPan( QgsLayoutView *view )

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

if ( event->button() != Qt::LeftButton )
{
event->ignore();
@@ -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;
}
@@ -46,6 +46,8 @@ class GUI_EXPORT QgsLayoutViewToolPan : public QgsLayoutViewTool

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

};

0 comments on commit fa2aff1

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