Skip to content

Commit

Permalink
Add layout panning tool
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 11, 2017
1 parent db62a74 commit 3f66520
Show file tree
Hide file tree
Showing 9 changed files with 210 additions and 2 deletions.
1 change: 1 addition & 0 deletions python/gui/gui_auto.sip
Expand Up @@ -281,6 +281,7 @@
%Include layout/qgslayoutview.sip
%Include layout/qgslayoutviewtool.sip
%Include layout/qgslayoutviewtooladditem.sip
%Include layout/qgslayoutviewtoolpan.sip
%Include locator/qgslocator.sip
%Include locator/qgslocatorfilter.sip
%Include locator/qgslocatorwidget.sip
Expand Down
43 changes: 43 additions & 0 deletions python/gui/layout/qgslayoutviewtoolpan.sip
@@ -0,0 +1,43 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/layout/qgslayoutviewtoolpan.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



class QgsLayoutViewToolPan : QgsLayoutViewTool
{
%Docstring
Layout view tool for panning the layout.
.. versionadded:: 3.0
%End

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

QgsLayoutViewToolPan( QgsLayoutView *view );
%Docstring
Constructor for QgsLayoutViewToolPan.
%End

virtual void layoutPressEvent( QgsLayoutViewMouseEvent *event );

virtual void layoutMoveEvent( QgsLayoutViewMouseEvent *event );

virtual void layoutReleaseEvent( QgsLayoutViewMouseEvent *event );


};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/layout/qgslayoutviewtoolpan.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
5 changes: 5 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Expand Up @@ -22,6 +22,7 @@
#include "qgslogger.h"
#include "qgslayoutview.h"
#include "qgslayoutviewtooladditem.h"
#include "qgslayoutviewtoolpan.h"

QgsAppLayoutDesignerInterface::QgsAppLayoutDesignerInterface( QgsLayoutDesignerDialog *dialog )
: QgsLayoutDesignerInterface( dialog )
Expand Down Expand Up @@ -90,6 +91,10 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
connect( QgsApplication::layoutItemRegistry(), &QgsLayoutItemRegistry::typeAdded, this, &QgsLayoutDesignerDialog::itemTypeAdded );

mAddItemTool = new QgsLayoutViewToolAddItem( mView );
mPanTool = new QgsLayoutViewToolPan( mView );
mPanTool->setAction( mActionPan );
mToolsActionGroup->addAction( mActionPan );
connect( mActionPan, &QAction::triggered, mPanTool, [ = ] { mView->setTool( mPanTool ); } );

restoreWindowState();
}
Expand Down
3 changes: 3 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.h
Expand Up @@ -23,6 +23,7 @@
class QgsLayoutDesignerDialog;
class QgsLayoutView;
class QgsLayoutViewToolAddItem;
class QgsLayoutViewToolPan;

class QgsAppLayoutDesignerInterface : public QgsLayoutDesignerInterface
{
Expand Down Expand Up @@ -114,6 +115,8 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner

QgsLayoutViewToolAddItem *mAddItemTool = nullptr;

QgsLayoutViewToolPan *mPanTool = nullptr;


//! Save window state
void saveWindowState();
Expand Down
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -164,6 +164,7 @@ SET(QGIS_GUI_SRCS
layout/qgslayoutviewrubberband.cpp
layout/qgslayoutviewtool.cpp
layout/qgslayoutviewtooladditem.cpp
layout/qgslayoutviewtoolpan.cpp

locator/qgslocator.cpp
locator/qgslocatorfilter.cpp
Expand Down Expand Up @@ -630,6 +631,7 @@ SET(QGIS_GUI_MOC_HDRS
layout/qgslayoutview.h
layout/qgslayoutviewtool.h
layout/qgslayoutviewtooladditem.h
layout/qgslayoutviewtoolpan.h

locator/qgslocator.h
locator/qgslocatorfilter.h
Expand Down
1 change: 1 addition & 0 deletions src/gui/layout/qgslayoutviewtooladditem.cpp
Expand Up @@ -46,6 +46,7 @@ void QgsLayoutViewToolAddItem::layoutPressEvent( QgsLayoutViewMouseEvent *event
return;
}

mMousePressStartPos = event->pos();
mRubberBand.reset( QgsApplication::layoutItemRegistry()->createItemRubberBand( mItemType, view() ) );
if ( mRubberBand )
{
Expand Down
58 changes: 58 additions & 0 deletions src/gui/layout/qgslayoutviewtoolpan.cpp
@@ -0,0 +1,58 @@
/***************************************************************************
qgslayoutviewtoolpan.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 "qgslayoutviewtoolpan.h"
#include "qgslayoutviewmouseevent.h"
#include "qgslayoutview.h"
#include <QScrollBar>

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

void QgsLayoutViewToolPan::layoutPressEvent( QgsLayoutViewMouseEvent *event )
{
if ( event->button() != Qt::LeftButton )
{
return;
}

mIsPanning = true;
mLastMousePos = event->pos();
view()->setCursor( Qt::ClosedHandCursor );
}

void QgsLayoutViewToolPan::layoutMoveEvent( QgsLayoutViewMouseEvent *event )
{
if ( !mIsPanning )
return;

view()->horizontalScrollBar()->setValue( view()->horizontalScrollBar()->value() - ( event->x() - mLastMousePos.x() ) );
view()->verticalScrollBar()->setValue( view()->verticalScrollBar()->value() - ( event->y() - mLastMousePos.y() ) );
mLastMousePos = event->pos();
}

void QgsLayoutViewToolPan::layoutReleaseEvent( QgsLayoutViewMouseEvent *event )
{
if ( !mIsPanning || event->button() != Qt::LeftButton )
{
return;
}

mIsPanning = false;
view()->setCursor( Qt::OpenHandCursor );
}
53 changes: 53 additions & 0 deletions src/gui/layout/qgslayoutviewtoolpan.h
@@ -0,0 +1,53 @@
/***************************************************************************
qgslayoutviewtoolpan.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 QGSLAYOUTVIEWTOOLPAN_H
#define QGSLAYOUTVIEWTOOLPAN_H

#include "qgis.h"
#include "qgis_gui.h"
#include "qgslayoutviewtool.h"
#include "qgslayoutviewrubberband.h"
#include <memory>

/**
* \ingroup gui
* Layout view tool for panning the layout.
* \since QGIS 3.0
*/
class GUI_EXPORT QgsLayoutViewToolPan : public QgsLayoutViewTool
{

Q_OBJECT

public:

/**
* Constructor for QgsLayoutViewToolPan.
*/
QgsLayoutViewToolPan( QgsLayoutView *view );

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

private:

bool mIsPanning = false;
QPoint mLastMousePos;

};

#endif // QGSLAYOUTVIEWTOOLPAN_H
46 changes: 44 additions & 2 deletions src/ui/layout/qgslayoutdesignerbase.ui
Expand Up @@ -62,6 +62,7 @@
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="mActionPan"/>
</widget>
<widget class="QToolBar" name="mItemToolbar">
<property name="windowTitle">
Expand All @@ -80,7 +81,7 @@
<x>0</x>
<y>0</y>
<width>1083</width>
<height>25</height>
<height>42</height>
</rect>
</property>
<widget class="QMenu" name="mLayoutMenu">
Expand Down Expand Up @@ -108,7 +109,48 @@
<string>Ctrl+Q</string>
</property>
</action>
<action name="mActionPan">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../../../images/images.qrc">
<normaloff>:/images/themes/default/mActionPan.svg</normaloff>:/images/themes/default/mActionPan.svg</iconset>
</property>
<property name="text">
<string>Pan Layout</string>
</property>
<property name="shortcut">
<string>P</string>
</property>
</action>
</widget>
<resources/>
<resources>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
</resources>
<connections/>
</ui>

0 comments on commit 3f66520

Please sign in to comment.