Skip to content
Permalink
Browse files

Add layout panning tool

  • Loading branch information
nyalldawson committed Jul 11, 2017
1 parent db62a74 commit 3f66520828f2f443154ef63b59db87bb160e251f
@@ -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
@@ -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 *
************************************************************************/
@@ -22,6 +22,7 @@
#include "qgslogger.h"
#include "qgslayoutview.h"
#include "qgslayoutviewtooladditem.h"
#include "qgslayoutviewtoolpan.h"

QgsAppLayoutDesignerInterface::QgsAppLayoutDesignerInterface( QgsLayoutDesignerDialog *dialog )
: QgsLayoutDesignerInterface( dialog )
@@ -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();
}
@@ -23,6 +23,7 @@
class QgsLayoutDesignerDialog;
class QgsLayoutView;
class QgsLayoutViewToolAddItem;
class QgsLayoutViewToolPan;

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

QgsLayoutViewToolAddItem *mAddItemTool = nullptr;

QgsLayoutViewToolPan *mPanTool = nullptr;


//! Save window state
void saveWindowState();
@@ -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
@@ -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
@@ -46,6 +46,7 @@ void QgsLayoutViewToolAddItem::layoutPressEvent( QgsLayoutViewMouseEvent *event
return;
}

mMousePressStartPos = event->pos();
mRubberBand.reset( QgsApplication::layoutItemRegistry()->createItemRubberBand( mItemType, view() ) );
if ( mRubberBand )
{
@@ -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 );
}
@@ -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
@@ -62,6 +62,7 @@
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="mActionPan"/>
</widget>
<widget class="QToolBar" name="mItemToolbar">
<property name="windowTitle">
@@ -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">
@@ -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.
You can’t perform that action at this time.