QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsmodelviewtooltemporarykeyzoom.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmodelviewtooltemporarykeyzoom.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
18#include "qgsapplication.h"
21
22#include <QApplication>
23#include <QScrollBar>
24
25#include "moc_qgsmodelviewtooltemporarykeyzoom.cpp"
26
31
33{
35 if ( !event->isAccepted() )
36 return;
37
38 //end of temporary zoom tool
39 if ( mDeactivateOnMouseRelease )
40 view()->setTool( mPreviousViewTool );
41}
42
44{
45 if ( event->isAutoRepeat() )
46 {
47 event->ignore();
48 return;
49 }
50
51 //respond to changes in ctrl key status
52 if ( !( event->modifiers() & Qt::ControlModifier ) )
53 {
54 if ( !mMarqueeZoom )
55 {
56 //space pressed, but control key was released, end of temporary zoom tool
57 view()->setTool( mPreviousViewTool );
58 }
59 else
60 {
61 mDeactivateOnMouseRelease = true;
62 }
63 }
64 else
65 {
66 //both control and space pressed
67 //set cursor to zoom in/out depending on alt key status
68 updateCursor( event->modifiers() );
69 if ( event->key() == Qt::Key_Space )
70 {
71 mDeactivateOnMouseRelease = false;
72 }
73 }
74}
75
77{
78 if ( event->isAutoRepeat() )
79 {
80 event->ignore();
81 return;
82 }
83
84 if ( event->key() == Qt::Key_Space )
85 {
86 //temporary keyboard-based zoom tool is active and space key has been released
87 if ( !mMarqueeZoom )
88 {
89 //not mid-way through an operation, so immediately switch tool back
90 view()->setTool( mPreviousViewTool );
91 }
92 else
93 {
94 mDeactivateOnMouseRelease = true;
95 }
96 }
97 else
98 {
99 updateCursor( event->modifiers() );
100 event->ignore();
101 }
102}
103
105{
106 mDeactivateOnMouseRelease = false;
107 mPreviousViewTool = view()->tool();
109 updateCursor( QApplication::keyboardModifiers() );
110}
111
112void QgsModelViewToolTemporaryKeyZoom::updateCursor( Qt::KeyboardModifiers modifiers )
113{
115}
static QCursor getThemeCursor(Cursor cursor)
Helper to get a theme cursor.
@ ZoomOut
Zoom out.
A mouse event which is the result of a user interaction with a QgsModelGraphicsView.
void modelReleaseEvent(QgsModelViewMouseEvent *event) override
Mouse release event for overriding.
void keyReleaseEvent(QKeyEvent *event) override
Key release event for overriding.
void keyPressEvent(QKeyEvent *event) override
Key press event for overriding.
QgsModelViewToolTemporaryKeyZoom(QgsModelGraphicsView *view)
Constructor for QgsModelViewToolTemporaryKeyZoom.
void activate() override
Called when tool is set as the currently active model tool.
bool mMarqueeZoom
Will be true will marquee zoom operation is in progress.
void modelReleaseEvent(QgsModelViewMouseEvent *event) override
Mouse release event for overriding.
QgsModelViewToolZoom(QgsModelGraphicsView *view)
Constructor for QgsModelViewToolZoom.
QgsModelGraphicsView * view() const
Returns the view associated with the tool.
virtual void activate()
Called when tool is set as the currently active model tool.