QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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
30
32{
34 if ( !event->isAccepted() )
35 return;
36
37 //end of temporary zoom tool
38 if ( mDeactivateOnMouseRelease )
39 view()->setTool( mPreviousViewTool );
40}
41
43{
44 if ( event->isAutoRepeat() )
45 {
46 event->ignore();
47 return;
48 }
49
50 //respond to changes in ctrl key status
51 if ( !( event->modifiers() & Qt::ControlModifier ) )
52 {
53 if ( !mMarqueeZoom )
54 {
55 //space pressed, but control key was released, end of temporary zoom tool
56 view()->setTool( mPreviousViewTool );
57 }
58 else
59 {
60 mDeactivateOnMouseRelease = true;
61 }
62 }
63 else
64 {
65 //both control and space pressed
66 //set cursor to zoom in/out depending on alt key status
67 updateCursor( event->modifiers() );
68 if ( event->key() == Qt::Key_Space )
69 {
70 mDeactivateOnMouseRelease = false;
71 }
72 }
73}
74
76{
77 if ( event->isAutoRepeat() )
78 {
79 event->ignore();
80 return;
81 }
82
83 if ( event->key() == Qt::Key_Space )
84 {
85 //temporary keyboard-based zoom tool is active and space key has been released
86 if ( !mMarqueeZoom )
87 {
88 //not mid-way through an operation, so immediately switch tool back
89 view()->setTool( mPreviousViewTool );
90 }
91 else
92 {
93 mDeactivateOnMouseRelease = true;
94 }
95 }
96 else
97 {
98 updateCursor( event->modifiers() );
99 event->ignore();
100 }
101}
102
104{
105 mDeactivateOnMouseRelease = false;
106 mPreviousViewTool = view()->tool();
108 updateCursor( QApplication::keyboardModifiers() );
109}
110
111void QgsModelViewToolTemporaryKeyZoom::updateCursor( Qt::KeyboardModifiers modifiers )
112{
114}
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.