QGIS API Documentation 3.41.0-Master (cea29feecf2)
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(), event->y() - mLastMousePos.y() );
40 mLastMousePos = event->pos();
41}
42
44{
45 if ( event->key() == Qt::Key_Space && !event->isAutoRepeat() )
46 {
47 canvas()->setTool( mPreviousTool );
48 }
49}
50
52{
53 mLastMousePos = canvas()->mapFromGlobal( QCursor::pos() );
54 mPreviousTool = canvas()->tool();
56}
57
58
59//
60// QgsPlotToolTemporaryMousePan
61//
62
64 : QgsPlotTool( canvas, tr( "Pan" ) )
65{
66 setCursor( Qt::ClosedHandCursor );
67}
68
70{
71 canvas()->panContentsBy( event->x() - mLastMousePos.x(), event->y() - mLastMousePos.y() );
72 mLastMousePos = event->pos();
73}
74
76{
77 if ( event->button() == Qt::MiddleButton )
78 {
79 canvas()->setTool( mPreviousTool );
80 }
81}
82
84{
85 mLastMousePos = canvas()->mapFromGlobal( QCursor::pos() );
86 mPreviousTool = canvas()->tool();
88}
89
90
91//
92// QgsPlotToolTemporaryKeyZoom
93//
94
99
101{
103 if ( !event->isAccepted() )
104 return;
105
106 //end of temporary zoom tool
107 if ( mDeactivateOnMouseRelease )
108 canvas()->setTool( mPreviousViewTool );
109}
110
112{
113 if ( event->isAutoRepeat() )
114 {
115 event->ignore();
116 return;
117 }
118
119 //respond to changes in ctrl key status
120 if ( !( event->modifiers() & Qt::ControlModifier ) )
121 {
122 if ( !mMarqueeZoom )
123 {
124 //space pressed, but control key was released, end of temporary zoom tool
125 canvas()->setTool( mPreviousViewTool );
126 }
127 else
128 {
129 mDeactivateOnMouseRelease = true;
130 }
131 }
132 else
133 {
134 //both control and space pressed
135 //set cursor to zoom in/out depending on alt key status
136 updateCursor( event->modifiers() );
137 if ( event->key() == Qt::Key_Space )
138 {
139 mDeactivateOnMouseRelease = false;
140 }
141 }
142}
143
145{
146 if ( event->isAutoRepeat() )
147 {
148 event->ignore();
149 return;
150 }
151
152 if ( event->key() == Qt::Key_Space )
153 {
154 //temporary keyboard-based zoom tool is active and space key has been released
155 if ( !mMarqueeZoom )
156 {
157 //not mid-way through an operation, so immediately switch tool back
158 canvas()->setTool( mPreviousViewTool );
159 }
160 else
161 {
162 mDeactivateOnMouseRelease = true;
163 }
164 }
165 else
166 {
167 updateCursor( event->modifiers() );
168 event->ignore();
169 }
170}
171
173{
174 mDeactivateOnMouseRelease = false;
175 mPreviousViewTool = canvas()->tool();
177 updateCursor( QApplication::keyboardModifiers() );
178}
179
180void QgsPlotToolTemporaryKeyZoom::updateCursor( Qt::KeyboardModifiers modifiers )
181{
182 canvas()->viewport()->setCursor( ( modifiers & Qt::AltModifier ) ? QgsApplication::getThemeCursor( QgsApplication::Cursor::ZoomOut ) : QgsApplication::getThemeCursor( QgsApplication::Cursor::ZoomIn ) );
183}
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.