QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgsplottransienttools.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsplottransienttools.cpp
3 ---------------
4 begin : March 2022
5 copyright : (C) 2022 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19#include "moc_qgsplottransienttools.cpp"
20#include "qgsplotcanvas.h"
21#include "qgsplotmouseevent.h"
22#include "qgsapplication.h"
23
24#include <QKeyEvent>
25#include <QApplication>
26
27//
28// QgsPlotToolTemporaryKeyPan
29//
30
32 : QgsPlotTool( canvas, tr( "Pan" ) )
33{
34 setCursor( Qt::ClosedHandCursor );
35}
36
38{
39 canvas()->panContentsBy( event->x() - mLastMousePos.x(),
40 event->y() - mLastMousePos.y() );
41 mLastMousePos = event->pos();
42}
43
45{
46 if ( event->key() == Qt::Key_Space && !event->isAutoRepeat() )
47 {
48 canvas()->setTool( mPreviousTool );
49 }
50}
51
53{
54 mLastMousePos = canvas()->mapFromGlobal( QCursor::pos() );
55 mPreviousTool = canvas()->tool();
57}
58
59
60//
61// QgsPlotToolTemporaryMousePan
62//
63
65 : QgsPlotTool( canvas, tr( "Pan" ) )
66{
67 setCursor( Qt::ClosedHandCursor );
68}
69
71{
72 canvas()->panContentsBy( event->x() - mLastMousePos.x(),
73 event->y() - mLastMousePos.y() );
74 mLastMousePos = event->pos();
75}
76
78{
79 if ( event->button() == Qt::MiddleButton )
80 {
81 canvas()->setTool( mPreviousTool );
82 }
83}
84
86{
87 mLastMousePos = canvas()->mapFromGlobal( QCursor::pos() );
88 mPreviousTool = canvas()->tool();
90}
91
92
93//
94// QgsPlotToolTemporaryKeyZoom
95//
96
101
103{
105 if ( !event->isAccepted() )
106 return;
107
108 //end of temporary zoom tool
109 if ( mDeactivateOnMouseRelease )
110 canvas()->setTool( mPreviousViewTool );
111}
112
114{
115 if ( event->isAutoRepeat() )
116 {
117 event->ignore();
118 return;
119 }
120
121 //respond to changes in ctrl key status
122 if ( !( event->modifiers() & Qt::ControlModifier ) )
123 {
124 if ( !mMarqueeZoom )
125 {
126 //space pressed, but control key was released, end of temporary zoom tool
127 canvas()->setTool( mPreviousViewTool );
128 }
129 else
130 {
131 mDeactivateOnMouseRelease = true;
132 }
133 }
134 else
135 {
136 //both control and space pressed
137 //set cursor to zoom in/out depending on alt key status
138 updateCursor( event->modifiers() );
139 if ( event->key() == Qt::Key_Space )
140 {
141 mDeactivateOnMouseRelease = false;
142 }
143 }
144}
145
147{
148 if ( event->isAutoRepeat() )
149 {
150 event->ignore();
151 return;
152 }
153
154 if ( event->key() == Qt::Key_Space )
155 {
156 //temporary keyboard-based zoom tool is active and space key has been released
157 if ( !mMarqueeZoom )
158 {
159 //not mid-way through an operation, so immediately switch tool back
160 canvas()->setTool( mPreviousViewTool );
161 }
162 else
163 {
164 mDeactivateOnMouseRelease = true;
165 }
166 }
167 else
168 {
169 updateCursor( event->modifiers() );
170 event->ignore();
171 }
172}
173
175{
176 mDeactivateOnMouseRelease = false;
177 mPreviousViewTool = canvas()->tool();
179 updateCursor( QApplication::keyboardModifiers() );
180}
181
182void QgsPlotToolTemporaryKeyZoom::updateCursor( Qt::KeyboardModifiers modifiers )
183{
184 canvas()->viewport()->setCursor( ( modifiers & Qt::AltModifier ) ?
186 QgsApplication::getThemeCursor( QgsApplication::Cursor::ZoomIn ) );
187}
Extends QApplication to provide access to QGIS specific resources such as theme paths,...
static QCursor getThemeCursor(Cursor cursor)
Helper to get a theme cursor.
@ ZoomOut
Zoom out.
Plot canvas is a class for displaying interactive 2d charts and plots.
void setTool(QgsPlotTool *tool)
Sets the interactive tool currently being used on the canvas.
virtual void panContentsBy(double dx, double dy)
Pans the plot contents by dx, dy in canvas units.
QgsPlotTool * tool()
Returns the currently active tool.
A QgsPlotMouseEvent is the result of a user interaction with the mouse on a QgsPlotCanvas.
void plotMoveEvent(QgsPlotMouseEvent *event) override
Mouse move event for overriding.
void activate() override
Called when the tool is set as the currently active plot tool.
void keyReleaseEvent(QKeyEvent *event) override
Key release event for overriding.
QgsPlotToolTemporaryKeyPan(QgsPlotCanvas *canvas)
Constructor for QgsPlotToolTemporaryKeyPan.
void keyReleaseEvent(QKeyEvent *event) override
Key release event for overriding.
void keyPressEvent(QKeyEvent *event) override
Key press event for overriding.
void plotReleaseEvent(QgsPlotMouseEvent *event) override
Mouse release event for overriding.
QgsPlotToolTemporaryKeyZoom(QgsPlotCanvas *canvas)
Constructor for QgsPlotToolTemporaryKeyZoom.
void activate() override
Called when the tool is set as the currently active plot tool.
void plotMoveEvent(QgsPlotMouseEvent *event) override
Mouse move event for overriding.
void activate() override
Called when the tool is set as the currently active plot tool.
void plotReleaseEvent(QgsPlotMouseEvent *event) override
Mouse release event for overriding.
QgsPlotToolTemporaryMousePan(QgsPlotCanvas *canvas)
Constructor for QgsPlotToolTemporaryMousePan.
Plot tool for zooming into and out of the plot.
void plotReleaseEvent(QgsPlotMouseEvent *event) override
Mouse release event for overriding.
bool mMarqueeZoom
Will be true will marquee zoom operation is in progress.
Abstract base class for all interactive plot tools.
Definition qgsplottool.h:58
QgsPlotCanvas * canvas() const
Returns the tool's plot canvas.
void setCursor(const QCursor &cursor)
Sets a user defined cursor for use when the tool is active.
virtual void activate()
Called when the tool is set as the currently active plot tool.