Skip to content
Permalink
Browse files

Port ability to pan layouts with middle mouse button depressed

  • Loading branch information
nyalldawson committed Jul 11, 2017
1 parent b9bbd91 commit 0307cac325a2686980d288957b4ccc72f252a5d7
@@ -285,6 +285,7 @@
%Include layout/qgslayoutviewtoolselect.sip
%Include layout/qgslayoutviewtooltemporarykeypan.sip
%Include layout/qgslayoutviewtooltemporarykeyzoom.sip
%Include layout/qgslayoutviewtooltemporarymousepan.sip
%Include layout/qgslayoutviewtoolzoom.sip
%Include locator/qgslocator.sip
%Include locator/qgslocatorfilter.sip
@@ -0,0 +1,43 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/layout/qgslayoutviewtooltemporarymousepan.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



class QgsLayoutViewToolTemporaryMousePan : QgsLayoutViewTool
{
%Docstring
Layout view tool for temporarily panning a layout while a mouse button is depressed.
.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgslayoutviewtooltemporarymousepan.h"
%End
public:

QgsLayoutViewToolTemporaryMousePan( QgsLayoutView *view /TransferThis/ );
%Docstring
Constructor for QgsLayoutViewToolTemporaryMousePan.
%End

virtual void layoutMoveEvent( QgsLayoutViewMouseEvent *event );

virtual void layoutReleaseEvent( QgsLayoutViewMouseEvent *event );

virtual void activate();


};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/layout/qgslayoutviewtooltemporarymousepan.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -168,6 +168,7 @@ SET(QGIS_GUI_SRCS
layout/qgslayoutviewtoolselect.cpp
layout/qgslayoutviewtooltemporarykeypan.cpp
layout/qgslayoutviewtooltemporarykeyzoom.cpp
layout/qgslayoutviewtooltemporarymousepan.cpp
layout/qgslayoutviewtoolzoom.cpp

locator/qgslocator.cpp
@@ -639,6 +640,7 @@ SET(QGIS_GUI_MOC_HDRS
layout/qgslayoutviewtoolselect.h
layout/qgslayoutviewtooltemporarykeypan.h
layout/qgslayoutviewtooltemporarykeyzoom.h
layout/qgslayoutviewtooltemporarymousepan.h
layout/qgslayoutviewtoolzoom.h

locator/qgslocator.h
@@ -21,6 +21,7 @@
#include "qgslayoutviewmouseevent.h"
#include "qgslayoutviewtooltemporarykeypan.h"
#include "qgslayoutviewtooltemporarykeyzoom.h"
#include "qgslayoutviewtooltemporarymousepan.h"
#include "qgssettings.h"
#include "qgsrectangle.h"
#include <memory>
@@ -36,6 +37,7 @@ QgsLayoutView::QgsLayoutView( QWidget *parent )
viewport()->setMouseTracking( true );

mSpacePanTool = new QgsLayoutViewToolTemporaryKeyPan( this );
mMidMouseButtonPanTool = new QgsLayoutViewToolTemporaryMousePan( this );
mSpaceZoomTool = new QgsLayoutViewToolTemporaryKeyZoom( this );
}

@@ -103,7 +105,22 @@ void QgsLayoutView::mousePressEvent( QMouseEvent *event )
}

if ( !mTool || !event->isAccepted() )
{
if ( event->button() == Qt::MidButton )
{
// Pan layout with middle mouse button
setTool( mMidMouseButtonPanTool );
event->accept();
}
else
{
QGraphicsView::mousePressEvent( event );
}
}
else
{
QGraphicsView::mousePressEvent( event );
}
}

void QgsLayoutView::mouseReleaseEvent( QMouseEvent *event )
@@ -27,6 +27,7 @@ class QgsLayout;
class QgsLayoutViewTool;
class QgsLayoutViewToolTemporaryKeyPan;
class QgsLayoutViewToolTemporaryKeyZoom;
class QgsLayoutViewToolTemporaryMousePan;

/**
* \ingroup gui
@@ -125,6 +126,7 @@ class GUI_EXPORT QgsLayoutView: public QGraphicsView
QPointer< QgsLayoutViewTool > mTool;

QgsLayoutViewToolTemporaryKeyPan *mSpacePanTool = nullptr;
QgsLayoutViewToolTemporaryMousePan *mMidMouseButtonPanTool = nullptr;
QgsLayoutViewToolTemporaryKeyZoom *mSpaceZoomTool = nullptr;

QPoint mMouseCurrentXY;
@@ -0,0 +1,47 @@
/***************************************************************************
qgslayoutviewtooltemporarymousepan.cpp
--------------------------------------
Date : July 2017
Copyright : (C) 2017 Nyall Dawson
Email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgslayoutviewtooltemporarymousepan.h"
#include "qgslayoutviewmouseevent.h"
#include "qgslayoutview.h"
#include <QScrollBar>

QgsLayoutViewToolTemporaryMousePan::QgsLayoutViewToolTemporaryMousePan( QgsLayoutView *view )
: QgsLayoutViewTool( view, tr( "Pan" ) )
{
setCursor( Qt::ClosedHandCursor );
}

void QgsLayoutViewToolTemporaryMousePan::layoutMoveEvent( QgsLayoutViewMouseEvent *event )
{
view()->horizontalScrollBar()->setValue( view()->horizontalScrollBar()->value() - ( event->x() - mLastMousePos.x() ) );
view()->verticalScrollBar()->setValue( view()->verticalScrollBar()->value() - ( event->y() - mLastMousePos.y() ) );
mLastMousePos = event->pos();
}

void QgsLayoutViewToolTemporaryMousePan::layoutReleaseEvent( QgsLayoutViewMouseEvent *event )
{
if ( event->button() == Qt::MidButton )
{
view()->setTool( mPreviousViewTool );
}
}

void QgsLayoutViewToolTemporaryMousePan::activate()
{
mLastMousePos = view()->mapFromGlobal( QCursor::pos() );
mPreviousViewTool = view()->tool();
QgsLayoutViewTool::activate();
}
@@ -0,0 +1,51 @@
/***************************************************************************
qgslayoutviewtooltemporarymousepan.h
------------------------------------
Date : July 2017
Copyright : (C) 2017 Nyall Dawson
Email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSLAYOUTVIEWTOOLTEMPORARYMOUSEPAN_H
#define QGSLAYOUTVIEWTOOLTEMPORARYMOUSEPAN_H

#include "qgis.h"
#include "qgis_gui.h"
#include "qgslayoutviewtool.h"

/**
* \ingroup gui
* Layout view tool for temporarily panning a layout while a mouse button is depressed.
* \since QGIS 3.0
*/
class GUI_EXPORT QgsLayoutViewToolTemporaryMousePan : public QgsLayoutViewTool
{

Q_OBJECT

public:

/**
* Constructor for QgsLayoutViewToolTemporaryMousePan.
*/
QgsLayoutViewToolTemporaryMousePan( QgsLayoutView *view SIP_TRANSFERTHIS );

void layoutMoveEvent( QgsLayoutViewMouseEvent *event ) override;
void layoutReleaseEvent( QgsLayoutViewMouseEvent *event ) override;
void activate() override;

private:

QPoint mLastMousePos;
QPointer< QgsLayoutViewTool > mPreviousViewTool;

};

#endif // QGSLAYOUTVIEWTOOLTEMPORARYMOUSEPAN_H

0 comments on commit 0307cac

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