QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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 "qgsplotcanvas.h"
20#include "qgsplotmouseevent.h"
21#include "qgsapplication.h"
22
23#include <QKeyEvent>
24#include <QApplication>
25
26//
27// QgsPlotToolTemporaryKeyPan
28//
29
31 : QgsPlotTool( canvas, tr( "Pan" ) )
32{
33 setCursor( Qt::ClosedHandCursor );
34}
35
37{
38 canvas()->panContentsBy( event->x() - mLastMousePos.x(),
39 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(),
72 event->y() - mLastMousePos.y() );
73 mLastMousePos = event->pos();
74}
75
77{
78 if ( event->button() == Qt::MiddleButton )
79 {
80 canvas()->setTool( mPreviousTool );
81 }
82}
83
85{
86 mLastMousePos = canvas()->mapFromGlobal( QCursor::pos() );
87 mPreviousTool = canvas()->tool();
89}
90
91
92//
93// QgsPlotToolTemporaryKeyZoom
94//
95
100
102{
104 if ( !event->isAccepted() )
105 return;
106
107 //end of temporary zoom tool
108 if ( mDeactivateOnMouseRelease )
109 canvas()->setTool( mPreviousViewTool );
110}
111
113{
114 if ( event->isAutoRepeat() )
115 {
116 event->ignore();
117 return;
118 }
119
120 //respond to changes in ctrl key status
121 if ( !( event->modifiers() & Qt::ControlModifier ) )
122 {
123 if ( !mMarqueeZoom )
124 {
125 //space pressed, but control key was released, end of temporary zoom tool
126 canvas()->setTool( mPreviousViewTool );
127 }
128 else
129 {
130 mDeactivateOnMouseRelease = true;
131 }
132 }
133 else
134 {
135 //both control and space pressed
136 //set cursor to zoom in/out depending on alt key status
137 updateCursor( event->modifiers() );
138 if ( event->key() == Qt::Key_Space )
139 {
140 mDeactivateOnMouseRelease = false;
141 }
142 }
143}
144
146{
147 if ( event->isAutoRepeat() )
148 {
149 event->ignore();
150 return;
151 }
152
153 if ( event->key() == Qt::Key_Space )
154 {
155 //temporary keyboard-based zoom tool is active and space key has been released
156 if ( !mMarqueeZoom )
157 {
158 //not mid-way through an operation, so immediately switch tool back
159 canvas()->setTool( mPreviousViewTool );
160 }
161 else
162 {
163 mDeactivateOnMouseRelease = true;
164 }
165 }
166 else
167 {
168 updateCursor( event->modifiers() );
169 event->ignore();
170 }
171}
172
174{
175 mDeactivateOnMouseRelease = false;
176 mPreviousViewTool = canvas()->tool();
178 updateCursor( QApplication::keyboardModifiers() );
179}
180
181void QgsPlotToolTemporaryKeyZoom::updateCursor( Qt::KeyboardModifiers modifiers )
182{
183 canvas()->viewport()->setCursor( ( modifiers & Qt::AltModifier ) ?
185 QgsApplication::getThemeCursor( QgsApplication::Cursor::ZoomIn ) );
186}
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.