QGIS API Documentation
4.3.0-Master (52aa6503bed)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
layout
qgslayoutviewtoolpan.cpp
Go to the documentation of this file.
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
18
#include "
qgslayoutview.h
"
19
#include "
qgslayoutviewmouseevent.h
"
20
21
#include <QScrollBar>
22
23
#include "moc_qgslayoutviewtoolpan.cpp"
24
25
QgsLayoutViewToolPan::QgsLayoutViewToolPan
(
QgsLayoutView
*
view
)
26
:
QgsLayoutViewTool
(
view
, tr(
"Pan"
) )
27
{
28
setCursor
( Qt::OpenHandCursor );
29
}
30
31
void
QgsLayoutViewToolPan::layoutPressEvent
(
QgsLayoutViewMouseEvent
*event )
32
{
33
mMousePressStartPos =
event
->pos();
34
35
if
( event->button() != Qt::LeftButton )
36
{
37
event
->ignore();
38
return
;
39
}
40
41
mIsPanning =
true
;
42
mLastMousePos =
event
->pos();
43
view
()->viewport()->setCursor( Qt::ClosedHandCursor );
44
}
45
46
void
QgsLayoutViewToolPan::layoutMoveEvent
(
QgsLayoutViewMouseEvent
*event )
47
{
48
if
( !mIsPanning )
49
{
50
event
->ignore();
51
return
;
52
}
53
54
view
()->horizontalScrollBar()->setValue(
view
()->horizontalScrollBar()->value() - ( event->x() - mLastMousePos.x() ) );
55
view
()->verticalScrollBar()->setValue(
view
()->verticalScrollBar()->value() - ( event->y() - mLastMousePos.y() ) );
56
mLastMousePos =
event
->pos();
57
view
()->
viewChanged
();
58
}
59
60
void
QgsLayoutViewToolPan::layoutReleaseEvent
(
QgsLayoutViewMouseEvent
*event )
61
{
62
const
bool
clickOnly = !
isClickAndDrag
( mMousePressStartPos, event->pos() );
63
64
if
( event->button() == Qt::MiddleButton && clickOnly )
65
{
66
//middle mouse button click = recenter on point
67
68
//get current visible part of scene
69
const
QRect viewportRect( 0, 0,
view
()->viewport()->width(),
view
()->viewport()->height() );
70
QgsRectangle
visibleRect =
QgsRectangle
(
view
()->mapToScene( viewportRect ).boundingRect() );
71
const
QPointF scenePoint =
event
->layoutPoint();
72
visibleRect.
scale
( 1, scenePoint.x(), scenePoint.y() );
73
const
QRectF boundsRect = visibleRect.
toRectF
();
74
75
//zoom view to fit desired bounds
76
view
()->fitInView( boundsRect, Qt::KeepAspectRatio );
77
view
()->
emitZoomLevelChanged
();
78
view
()->
viewChanged
();
79
return
;
80
}
81
82
if
( !mIsPanning || event->button() != Qt::LeftButton )
83
{
84
view
()->
emitZoomLevelChanged
();
85
view
()->
viewChanged
();
86
event
->ignore();
87
return
;
88
}
89
90
mIsPanning =
false
;
91
view
()->viewport()->setCursor( Qt::OpenHandCursor );
92
}
93
94
void
QgsLayoutViewToolPan::deactivate
()
95
{
96
mIsPanning =
false
;
97
QgsLayoutViewTool::deactivate
();
98
}
QgsLayoutViewMouseEvent
A mouse event which is the result of a user interaction with a QgsLayoutView.
Definition
qgslayoutviewmouseevent.h:35
QgsLayoutViewToolPan::layoutPressEvent
void layoutPressEvent(QgsLayoutViewMouseEvent *event) override
Mouse press event for overriding.
Definition
qgslayoutviewtoolpan.cpp:31
QgsLayoutViewToolPan::deactivate
void deactivate() override
Called when tool is deactivated.
Definition
qgslayoutviewtoolpan.cpp:94
QgsLayoutViewToolPan::layoutReleaseEvent
void layoutReleaseEvent(QgsLayoutViewMouseEvent *event) override
Mouse release event for overriding.
Definition
qgslayoutviewtoolpan.cpp:60
QgsLayoutViewToolPan::QgsLayoutViewToolPan
QgsLayoutViewToolPan(QgsLayoutView *view)
Constructor for QgsLayoutViewToolPan.
Definition
qgslayoutviewtoolpan.cpp:25
QgsLayoutViewToolPan::layoutMoveEvent
void layoutMoveEvent(QgsLayoutViewMouseEvent *event) override
Mouse move event for overriding.
Definition
qgslayoutviewtoolpan.cpp:46
QgsLayoutViewTool::setCursor
void setCursor(const QCursor &cursor)
Sets a user defined cursor for use when the tool is active.
Definition
qgslayoutviewtool.cpp:114
QgsLayoutViewTool::view
QgsLayoutView * view() const
Returns the view associated with the tool.
Definition
qgslayoutviewtool.cpp:38
QgsLayoutViewTool::deactivate
virtual void deactivate()
Called when tool is deactivated.
Definition
qgslayoutviewtool.cpp:129
QgsLayoutViewTool::isClickAndDrag
bool isClickAndDrag(QPoint startViewPoint, QPoint endViewPoint) const
Returns true if a mouse press/release operation which started at startViewPoint and ended at endViewP...
Definition
qgslayoutviewtool.cpp:31
QgsLayoutViewTool::QgsLayoutViewTool
QgsLayoutViewTool(QgsLayoutView *view, const QString &name)
Constructor for QgsLayoutViewTool, taking a layout view and tool name as parameters.
Definition
qgslayoutviewtool.cpp:23
QgsLayoutView
A graphical widget to display and interact with QgsLayouts.
Definition
qgslayoutview.h:52
QgsLayoutView::viewChanged
void viewChanged()
Updates associated rulers and other widgets after view extent or zoom has changed.
Definition
qgslayoutview.cpp:1182
QgsLayoutView::emitZoomLevelChanged
void emitZoomLevelChanged()
Emits the zoomLevelChanged() signal.
Definition
qgslayoutview.cpp:600
QgsRectangle
A rectangle specified with double values.
Definition
qgsrectangle.h:47
QgsRectangle::scale
void scale(double scaleFactor, const QgsPointXY *c=nullptr)
Scale the rectangle around its center point.
Definition
qgsrectangle.h:372
QgsRectangle::toRectF
QRectF toRectF() const
Returns a QRectF with same coordinates as the rectangle.
Definition
qgsrectangle.h:677
qgslayoutview.h
qgslayoutviewmouseevent.h
qgslayoutviewtoolpan.h
Generated on
for QGIS API Documentation by
1.17.0