Skip to content

Commit 3f66520

Browse files
committedJul 11, 2017
Add layout panning tool
1 parent db62a74 commit 3f66520

File tree

9 files changed

+210
-2
lines changed

9 files changed

+210
-2
lines changed
 

‎python/gui/gui_auto.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@
281281
%Include layout/qgslayoutview.sip
282282
%Include layout/qgslayoutviewtool.sip
283283
%Include layout/qgslayoutviewtooladditem.sip
284+
%Include layout/qgslayoutviewtoolpan.sip
284285
%Include locator/qgslocator.sip
285286
%Include locator/qgslocatorfilter.sip
286287
%Include locator/qgslocatorwidget.sip
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/gui/layout/qgslayoutviewtoolpan.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
class QgsLayoutViewToolPan : QgsLayoutViewTool
12+
{
13+
%Docstring
14+
Layout view tool for panning the layout.
15+
.. versionadded:: 3.0
16+
%End
17+
18+
%TypeHeaderCode
19+
#include "qgslayoutviewtoolpan.h"
20+
%End
21+
public:
22+
23+
QgsLayoutViewToolPan( QgsLayoutView *view );
24+
%Docstring
25+
Constructor for QgsLayoutViewToolPan.
26+
%End
27+
28+
virtual void layoutPressEvent( QgsLayoutViewMouseEvent *event );
29+
30+
virtual void layoutMoveEvent( QgsLayoutViewMouseEvent *event );
31+
32+
virtual void layoutReleaseEvent( QgsLayoutViewMouseEvent *event );
33+
34+
35+
};
36+
37+
/************************************************************************
38+
* This file has been generated automatically from *
39+
* *
40+
* src/gui/layout/qgslayoutviewtoolpan.h *
41+
* *
42+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
43+
************************************************************************/

‎src/app/layout/qgslayoutdesignerdialog.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "qgslogger.h"
2323
#include "qgslayoutview.h"
2424
#include "qgslayoutviewtooladditem.h"
25+
#include "qgslayoutviewtoolpan.h"
2526

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

9293
mAddItemTool = new QgsLayoutViewToolAddItem( mView );
94+
mPanTool = new QgsLayoutViewToolPan( mView );
95+
mPanTool->setAction( mActionPan );
96+
mToolsActionGroup->addAction( mActionPan );
97+
connect( mActionPan, &QAction::triggered, mPanTool, [ = ] { mView->setTool( mPanTool ); } );
9398

9499
restoreWindowState();
95100
}

‎src/app/layout/qgslayoutdesignerdialog.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
class QgsLayoutDesignerDialog;
2424
class QgsLayoutView;
2525
class QgsLayoutViewToolAddItem;
26+
class QgsLayoutViewToolPan;
2627

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

115116
QgsLayoutViewToolAddItem *mAddItemTool = nullptr;
116117

118+
QgsLayoutViewToolPan *mPanTool = nullptr;
119+
117120

118121
//! Save window state
119122
void saveWindowState();

‎src/gui/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ SET(QGIS_GUI_SRCS
164164
layout/qgslayoutviewrubberband.cpp
165165
layout/qgslayoutviewtool.cpp
166166
layout/qgslayoutviewtooladditem.cpp
167+
layout/qgslayoutviewtoolpan.cpp
167168

168169
locator/qgslocator.cpp
169170
locator/qgslocatorfilter.cpp
@@ -630,6 +631,7 @@ SET(QGIS_GUI_MOC_HDRS
630631
layout/qgslayoutview.h
631632
layout/qgslayoutviewtool.h
632633
layout/qgslayoutviewtooladditem.h
634+
layout/qgslayoutviewtoolpan.h
633635

634636
locator/qgslocator.h
635637
locator/qgslocatorfilter.h

‎src/gui/layout/qgslayoutviewtooladditem.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ void QgsLayoutViewToolAddItem::layoutPressEvent( QgsLayoutViewMouseEvent *event
4646
return;
4747
}
4848

49+
mMousePressStartPos = event->pos();
4950
mRubberBand.reset( QgsApplication::layoutItemRegistry()->createItemRubberBand( mItemType, view() ) );
5051
if ( mRubberBand )
5152
{
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/***************************************************************************
2+
qgslayoutviewtoolpan.cpp
3+
------------------------
4+
Date : July 2017
5+
Copyright : (C) 2017 Nyall Dawson
6+
Email : nyall dot dawson at gmail dot com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include "qgslayoutviewtoolpan.h"
17+
#include "qgslayoutviewmouseevent.h"
18+
#include "qgslayoutview.h"
19+
#include <QScrollBar>
20+
21+
QgsLayoutViewToolPan::QgsLayoutViewToolPan( QgsLayoutView *view )
22+
: QgsLayoutViewTool( view, tr( "Pan" ) )
23+
{
24+
setCursor( Qt::OpenHandCursor );
25+
}
26+
27+
void QgsLayoutViewToolPan::layoutPressEvent( QgsLayoutViewMouseEvent *event )
28+
{
29+
if ( event->button() != Qt::LeftButton )
30+
{
31+
return;
32+
}
33+
34+
mIsPanning = true;
35+
mLastMousePos = event->pos();
36+
view()->setCursor( Qt::ClosedHandCursor );
37+
}
38+
39+
void QgsLayoutViewToolPan::layoutMoveEvent( QgsLayoutViewMouseEvent *event )
40+
{
41+
if ( !mIsPanning )
42+
return;
43+
44+
view()->horizontalScrollBar()->setValue( view()->horizontalScrollBar()->value() - ( event->x() - mLastMousePos.x() ) );
45+
view()->verticalScrollBar()->setValue( view()->verticalScrollBar()->value() - ( event->y() - mLastMousePos.y() ) );
46+
mLastMousePos = event->pos();
47+
}
48+
49+
void QgsLayoutViewToolPan::layoutReleaseEvent( QgsLayoutViewMouseEvent *event )
50+
{
51+
if ( !mIsPanning || event->button() != Qt::LeftButton )
52+
{
53+
return;
54+
}
55+
56+
mIsPanning = false;
57+
view()->setCursor( Qt::OpenHandCursor );
58+
}

‎src/gui/layout/qgslayoutviewtoolpan.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/***************************************************************************
2+
qgslayoutviewtoolpan.h
3+
----------------------
4+
Date : July 2017
5+
Copyright : (C) 2017 Nyall Dawson
6+
Email : nyall dot dawson at gmail dot com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#ifndef QGSLAYOUTVIEWTOOLPAN_H
17+
#define QGSLAYOUTVIEWTOOLPAN_H
18+
19+
#include "qgis.h"
20+
#include "qgis_gui.h"
21+
#include "qgslayoutviewtool.h"
22+
#include "qgslayoutviewrubberband.h"
23+
#include <memory>
24+
25+
/**
26+
* \ingroup gui
27+
* Layout view tool for panning the layout.
28+
* \since QGIS 3.0
29+
*/
30+
class GUI_EXPORT QgsLayoutViewToolPan : public QgsLayoutViewTool
31+
{
32+
33+
Q_OBJECT
34+
35+
public:
36+
37+
/**
38+
* Constructor for QgsLayoutViewToolPan.
39+
*/
40+
QgsLayoutViewToolPan( QgsLayoutView *view );
41+
42+
void layoutPressEvent( QgsLayoutViewMouseEvent *event ) override;
43+
void layoutMoveEvent( QgsLayoutViewMouseEvent *event ) override;
44+
void layoutReleaseEvent( QgsLayoutViewMouseEvent *event ) override;
45+
46+
private:
47+
48+
bool mIsPanning = false;
49+
QPoint mLastMousePos;
50+
51+
};
52+
53+
#endif // QGSLAYOUTVIEWTOOLPAN_H

‎src/ui/layout/qgslayoutdesignerbase.ui

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<attribute name="toolBarBreak">
6363
<bool>false</bool>
6464
</attribute>
65+
<addaction name="mActionPan"/>
6566
</widget>
6667
<widget class="QToolBar" name="mItemToolbar">
6768
<property name="windowTitle">
@@ -80,7 +81,7 @@
8081
<x>0</x>
8182
<y>0</y>
8283
<width>1083</width>
83-
<height>25</height>
84+
<height>42</height>
8485
</rect>
8586
</property>
8687
<widget class="QMenu" name="mLayoutMenu">
@@ -108,7 +109,48 @@
108109
<string>Ctrl+Q</string>
109110
</property>
110111
</action>
112+
<action name="mActionPan">
113+
<property name="checkable">
114+
<bool>true</bool>
115+
</property>
116+
<property name="icon">
117+
<iconset resource="../../../images/images.qrc">
118+
<normaloff>:/images/themes/default/mActionPan.svg</normaloff>:/images/themes/default/mActionPan.svg</iconset>
119+
</property>
120+
<property name="text">
121+
<string>Pan Layout</string>
122+
</property>
123+
<property name="shortcut">
124+
<string>P</string>
125+
</property>
126+
</action>
111127
</widget>
112-
<resources/>
128+
<resources>
129+
<include location="../../../images/images.qrc"/>
130+
<include location="../../../images/images.qrc"/>
131+
<include location="../../../images/images.qrc"/>
132+
<include location="../../../images/images.qrc"/>
133+
<include location="../../../images/images.qrc"/>
134+
<include location="../../../images/images.qrc"/>
135+
<include location="../../../images/images.qrc"/>
136+
<include location="../../../images/images.qrc"/>
137+
<include location="../../../images/images.qrc"/>
138+
<include location="../../../images/images.qrc"/>
139+
<include location="../../../images/images.qrc"/>
140+
<include location="../../../images/images.qrc"/>
141+
<include location="../../../images/images.qrc"/>
142+
<include location="../../../images/images.qrc"/>
143+
<include location="../../../images/images.qrc"/>
144+
<include location="../../../images/images.qrc"/>
145+
<include location="../../../images/images.qrc"/>
146+
<include location="../../../images/images.qrc"/>
147+
<include location="../../../images/images.qrc"/>
148+
<include location="../../../images/images.qrc"/>
149+
<include location="../../../images/images.qrc"/>
150+
<include location="../../../images/images.qrc"/>
151+
<include location="../../../images/images.qrc"/>
152+
<include location="../../../images/images.qrc"/>
153+
<include location="../../../images/images.qrc"/>
154+
</resources>
113155
<connections/>
114156
</ui>

0 commit comments

Comments
 (0)
Please sign in to comment.