QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsmodelviewtooltemporarykeypan.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmodelviewtooltemporarykeypan.cpp
3  ------------------------------------
4  Date : March 2020
5  Copyright : (C) 2020 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 
17 #include "qgsmodelviewmouseevent.h"
18 #include "qgsmodelgraphicsview.h"
19 #include <QScrollBar>
20 
22  : QgsModelViewTool( view, tr( "Pan" ) )
23 {
24  setCursor( Qt::ClosedHandCursor );
25 }
26 
28 {
29  view()->horizontalScrollBar()->setValue( view()->horizontalScrollBar()->value() - ( event->x() - mLastMousePos.x() ) );
30  view()->verticalScrollBar()->setValue( view()->verticalScrollBar()->value() - ( event->y() - mLastMousePos.y() ) );
31  mLastMousePos = event->pos();
32 }
33 
35 {
36  if ( event->key() == Qt::Key_Space && !event->isAutoRepeat() )
37  {
38  view()->setTool( mPreviousViewTool );
39  }
40 }
41 
43 {
44  mLastMousePos = view()->mapFromGlobal( QCursor::pos() );
45  mPreviousViewTool = view()->tool();
47 }
QgsModelViewTool::activate
virtual void activate()
Called when tool is set as the currently active model tool.
Definition: qgsmodelviewtool.cpp:120
QgsModelViewToolTemporaryKeyPan::QgsModelViewToolTemporaryKeyPan
QgsModelViewToolTemporaryKeyPan(QgsModelGraphicsView *view)
Constructor for QgsModelViewToolTemporaryKeyPan.
Definition: qgsmodelviewtooltemporarykeypan.cpp:21
QgsModelViewMouseEvent
A QgsModelViewMouseEvent is the result of a user interaction with the mouse on a QgsModelGraphicsView...
Definition: qgsmodelviewmouseevent.h:37
qgsmodelviewmouseevent.h
QgsModelViewToolTemporaryKeyPan::modelMoveEvent
void modelMoveEvent(QgsModelViewMouseEvent *event) override
Mouse move event for overriding.
Definition: qgsmodelviewtooltemporarykeypan.cpp:27
QgsModelViewToolTemporaryKeyPan::keyReleaseEvent
void keyReleaseEvent(QKeyEvent *event) override
Key release event for overriding.
Definition: qgsmodelviewtooltemporarykeypan.cpp:34
qgsmodelgraphicsview.h
QgsModelViewToolTemporaryKeyPan::activate
void activate() override
Called when tool is set as the currently active model tool.
Definition: qgsmodelviewtooltemporarykeypan.cpp:42
QgsModelViewTool::view
QgsModelGraphicsView * view() const
Returns the view associated with the tool.
Definition: qgsmodelviewtool.cpp:39
qgsmodelviewtooltemporarykeypan.h
QgsModelViewTool
Abstract base class for all model designer view tools.
Definition: qgsmodelviewtool.h:44
QgsModelViewTool::setCursor
void setCursor(const QCursor &cursor)
Sets a user defined cursor for use when the tool is active.
Definition: qgsmodelviewtool.cpp:115