QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
20#include "qgsapplication.h"
21#include "qgsplotcanvas.h"
22#include "qgsplotmouseevent.h"
23
24#include <QApplication>
25#include <QKeyEvent>
26
27#include "moc_qgsplottransienttools.cpp"
28
29//
30// QgsPlotToolTemporaryKeyPan
31//
32
38
40{
41 canvas()->panContentsBy( event->x() - mLastMousePos.x(), event->y() - mLastMousePos.y() );
42 mLastMousePos = event->pos();
43}
44
46{
47 if ( event->key() == Qt::Key_Space && !event->isAutoRepeat() )
48 {
49 canvas()->setTool( mPreviousTool );
50 }
51}
52
54{
55 mLastMousePos = canvas()->mapFromGlobal( QCursor::pos() );
56 mPreviousTool = canvas()->tool();
58}
59
60
61//
62// QgsPlotToolTemporaryMousePan
63//
64
70
72{
73 canvas()->panContentsBy( event->x() - mLastMousePos.x(), 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{
185}
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 mouse event which is the result of a user interaction with 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.
void plotReleaseEvent(QgsPlotMouseEvent *event) override
Mouse release event for overriding.
bool mMarqueeZoom
Will be true will marquee zoom operation is in progress.
QgsPlotToolZoom(QgsPlotCanvas *canvas)
Constructor for QgsPlotToolZoom, with the associated canvas.
QgsPlotCanvas * canvas() const
Returns the tool's plot canvas.
QgsPlotTool(QgsPlotCanvas *canvas, const QString &name)
Constructor takes a plot canvas as a parameter.
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.