Skip to content
Permalink
Browse files

Port ability to navigate layouts using space-pan and ctrl-space zoom

  • Loading branch information
nyalldawson committed Jul 11, 2017
1 parent 179c51c commit b9bbd9175488d3978eeba33b6969a0a3750116e4
@@ -283,6 +283,8 @@
%Include layout/qgslayoutviewtooladditem.sip
%Include layout/qgslayoutviewtoolpan.sip
%Include layout/qgslayoutviewtoolselect.sip
%Include layout/qgslayoutviewtooltemporarykeypan.sip
%Include layout/qgslayoutviewtooltemporarykeyzoom.sip
%Include layout/qgslayoutviewtoolzoom.sip
%Include locator/qgslocator.sip
%Include locator/qgslocatorfilter.sip
@@ -20,7 +20,7 @@ class QgsLayoutViewToolAddItem : QgsLayoutViewTool
%End
public:

QgsLayoutViewToolAddItem( QgsLayoutView *view );
QgsLayoutViewToolAddItem( QgsLayoutView *view /TransferThis/ );

int itemType() const;
%Docstring
@@ -20,7 +20,7 @@ class QgsLayoutViewToolPan : QgsLayoutViewTool
%End
public:

QgsLayoutViewToolPan( QgsLayoutView *view );
QgsLayoutViewToolPan( QgsLayoutView *view /TransferThis/ );
%Docstring
Constructor for QgsLayoutViewToolPan.
%End
@@ -20,7 +20,7 @@ class QgsLayoutViewToolSelect : QgsLayoutViewTool
%End
public:

QgsLayoutViewToolSelect( QgsLayoutView *view );
QgsLayoutViewToolSelect( QgsLayoutView *view /TransferThis/ );
%Docstring
Constructor for QgsLayoutViewToolSelect.
%End
@@ -0,0 +1,43 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/layout/qgslayoutviewtooltemporarykeypan.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



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

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

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

virtual void layoutMoveEvent( QgsLayoutViewMouseEvent *event );

virtual void keyReleaseEvent( QKeyEvent *event );

virtual void activate();


};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/layout/qgslayoutviewtooltemporarykeypan.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -0,0 +1,45 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/layout/qgslayoutviewtooltemporarykeyzoom.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



class QgsLayoutViewToolTemporaryKeyZoom : QgsLayoutViewToolZoom
{
%Docstring
Layout view tool for temporarily zooming a layout while a key is depressed.
.. versionadded:: 3.0
%End

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

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

virtual void layoutReleaseEvent( QgsLayoutViewMouseEvent *event );

virtual void keyPressEvent( QKeyEvent *event );

virtual void keyReleaseEvent( QKeyEvent *event );

virtual void activate();


};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/layout/qgslayoutviewtooltemporarykeyzoom.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -20,7 +20,7 @@ class QgsLayoutViewToolZoom : QgsLayoutViewTool
%End
public:

QgsLayoutViewToolZoom( QgsLayoutView *view );
QgsLayoutViewToolZoom( QgsLayoutView *view /TransferThis/ );
%Docstring
Constructor for QgsLayoutViewToolZoom.
%End
@@ -38,6 +38,9 @@ class QgsLayoutViewToolZoom : QgsLayoutViewTool
virtual void deactivate();


protected:


};

/************************************************************************
@@ -112,6 +112,8 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
mToolsActionGroup->addAction( mActionSelectMoveItem );
connect( mActionSelectMoveItem, &QAction::triggered, mSelectTool, [ = ] { mView->setTool( mSelectTool ); } );

mView->setTool( mSelectTool );
mView->setFocus();

restoreWindowState();
}
@@ -166,6 +166,8 @@ SET(QGIS_GUI_SRCS
layout/qgslayoutviewtooladditem.cpp
layout/qgslayoutviewtoolpan.cpp
layout/qgslayoutviewtoolselect.cpp
layout/qgslayoutviewtooltemporarykeypan.cpp
layout/qgslayoutviewtooltemporarykeyzoom.cpp
layout/qgslayoutviewtoolzoom.cpp

locator/qgslocator.cpp
@@ -635,6 +637,8 @@ SET(QGIS_GUI_MOC_HDRS
layout/qgslayoutviewtooladditem.h
layout/qgslayoutviewtoolpan.h
layout/qgslayoutviewtoolselect.h
layout/qgslayoutviewtooltemporarykeypan.h
layout/qgslayoutviewtooltemporarykeyzoom.h
layout/qgslayoutviewtoolzoom.h

locator/qgslocator.h
@@ -19,6 +19,8 @@
#include "qgslayout.h"
#include "qgslayoutviewtool.h"
#include "qgslayoutviewmouseevent.h"
#include "qgslayoutviewtooltemporarykeypan.h"
#include "qgslayoutviewtooltemporarykeyzoom.h"
#include "qgssettings.h"
#include "qgsrectangle.h"
#include <memory>
@@ -32,6 +34,9 @@ QgsLayoutView::QgsLayoutView( QWidget *parent )
setResizeAnchor( QGraphicsView::AnchorViewCenter );
setMouseTracking( true );
viewport()->setMouseTracking( true );

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

QgsLayout *QgsLayoutView::currentLayout()
@@ -62,9 +67,10 @@ void QgsLayoutView::setTool( QgsLayoutViewTool *tool )
mTool->deactivate();
}

// set new tool and activate it
// activate new tool before setting it - gives tools a chance
// to respond to whatever the current tool is
tool->activate();
mTool = tool;
mTool->activate();

emit toolSet( mTool );
}
@@ -115,6 +121,8 @@ void QgsLayoutView::mouseReleaseEvent( QMouseEvent *event )

void QgsLayoutView::mouseMoveEvent( QMouseEvent *event )
{
mMouseCurrentXY = event->pos();

if ( mTool )
{
std::unique_ptr<QgsLayoutViewMouseEvent> me( new QgsLayoutViewMouseEvent( this, event ) );
@@ -161,7 +169,22 @@ void QgsLayoutView::keyPressEvent( QKeyEvent *event )
}

if ( !mTool || !event->isAccepted() )
QGraphicsView::keyPressEvent( event );
{
if ( event->key() == Qt::Key_Space && ! event->isAutoRepeat() )
{
if ( !( event->modifiers() & Qt::ControlModifier ) )
{
// Pan layout with space bar
setTool( mSpacePanTool );
}
else
{
//ctrl+space pressed, so switch to temporary keyboard based zoom tool
setTool( mSpaceZoomTool );
}
event->accept();
}
}
}

void QgsLayoutView::keyReleaseEvent( QKeyEvent *event )
@@ -25,6 +25,8 @@

class QgsLayout;
class QgsLayoutViewTool;
class QgsLayoutViewToolTemporaryKeyPan;
class QgsLayoutViewToolTemporaryKeyZoom;

/**
* \ingroup gui
@@ -122,6 +124,11 @@ class GUI_EXPORT QgsLayoutView: public QGraphicsView

QPointer< QgsLayoutViewTool > mTool;

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

QPoint mMouseCurrentXY;

friend class TestQgsLayoutView;

};
@@ -15,6 +15,7 @@

#include "qgslayoutviewtool.h"
#include "qgslayoutview.h"
#include "qgslayoutviewmouseevent.h"

QgsLayoutViewTool::QgsLayoutViewTool( QgsLayoutView *view, const QString &name )
: QObject( view )
@@ -51,39 +52,39 @@ QgsLayoutViewTool::~QgsLayoutViewTool()
mView->unsetTool( this );
}

void QgsLayoutViewTool::layoutMoveEvent( QgsLayoutViewMouseEvent * )
void QgsLayoutViewTool::layoutMoveEvent( QgsLayoutViewMouseEvent *event )
{

event->ignore();
}

void QgsLayoutViewTool::layoutDoubleClickEvent( QgsLayoutViewMouseEvent * )
void QgsLayoutViewTool::layoutDoubleClickEvent( QgsLayoutViewMouseEvent *event )
{

event->ignore();
}

void QgsLayoutViewTool::layoutPressEvent( QgsLayoutViewMouseEvent * )
void QgsLayoutViewTool::layoutPressEvent( QgsLayoutViewMouseEvent *event )
{

event->ignore();
}

void QgsLayoutViewTool::layoutReleaseEvent( QgsLayoutViewMouseEvent * )
void QgsLayoutViewTool::layoutReleaseEvent( QgsLayoutViewMouseEvent *event )
{

event->ignore();
}

void QgsLayoutViewTool::wheelEvent( QWheelEvent * )
void QgsLayoutViewTool::wheelEvent( QWheelEvent *event )
{

event->ignore();
}

void QgsLayoutViewTool::keyPressEvent( QKeyEvent * )
void QgsLayoutViewTool::keyPressEvent( QKeyEvent *event )
{

event->ignore();
}

void QgsLayoutViewTool::keyReleaseEvent( QKeyEvent * )
void QgsLayoutViewTool::keyReleaseEvent( QKeyEvent *event )
{

event->ignore();
}

void QgsLayoutViewTool::setAction( QAction *action )
@@ -34,7 +34,7 @@ class GUI_EXPORT QgsLayoutViewToolAddItem : public QgsLayoutViewTool

public:

QgsLayoutViewToolAddItem( QgsLayoutView *view );
QgsLayoutViewToolAddItem( QgsLayoutView *view SIP_TRANSFERTHIS );

/**
* Returns the item type for items created by the tool.
@@ -35,7 +35,7 @@ class GUI_EXPORT QgsLayoutViewToolPan : public QgsLayoutViewTool
/**
* Constructor for QgsLayoutViewToolPan.
*/
QgsLayoutViewToolPan( QgsLayoutView *view );
QgsLayoutViewToolPan( QgsLayoutView *view SIP_TRANSFERTHIS );

void layoutPressEvent( QgsLayoutViewMouseEvent *event ) override;
void layoutMoveEvent( QgsLayoutViewMouseEvent *event ) override;
@@ -37,7 +37,7 @@ class GUI_EXPORT QgsLayoutViewToolSelect : public QgsLayoutViewTool
/**
* Constructor for QgsLayoutViewToolSelect.
*/
QgsLayoutViewToolSelect( QgsLayoutView *view );
QgsLayoutViewToolSelect( QgsLayoutView *view SIP_TRANSFERTHIS );

void layoutPressEvent( QgsLayoutViewMouseEvent *event ) override;
void layoutMoveEvent( QgsLayoutViewMouseEvent *event ) override;
@@ -0,0 +1,47 @@
/***************************************************************************
qgslayoutviewtooltemporarykeypan.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 "qgslayoutviewtooltemporarykeypan.h"
#include "qgslayoutviewmouseevent.h"
#include "qgslayoutview.h"
#include <QScrollBar>

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

void QgsLayoutViewToolTemporaryKeyPan::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 QgsLayoutViewToolTemporaryKeyPan::keyReleaseEvent( QKeyEvent *event )
{
if ( event->key() == Qt::Key_Space && !event->isAutoRepeat() )
{
view()->setTool( mPreviousViewTool );
}
}

void QgsLayoutViewToolTemporaryKeyPan::activate()
{
mLastMousePos = view()->mapFromGlobal( QCursor::pos() );
mPreviousViewTool = view()->tool();
QgsLayoutViewTool::activate();
}

0 comments on commit b9bbd91

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