QGIS API Documentation 3.41.0-Master (cea29feecf2)
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#include "moc_qgsmodelviewtooltemporarykeyzoom.cpp"
20#include "qgsapplication.h"
21#include <QScrollBar>
22#include <QApplication>
23
28
30{
32 if ( !event->isAccepted() )
33 return;
34
35 //end of temporary zoom tool
36 if ( mDeactivateOnMouseRelease )
37 view()->setTool( mPreviousViewTool );
38}
39
41{
42 if ( event->isAutoRepeat() )
43 {
44 event->ignore();
45 return;
46 }
47
48 //respond to changes in ctrl key status
49 if ( !( event->modifiers() & Qt::ControlModifier ) )
50 {
51 if ( !mMarqueeZoom )
52 {
53 //space pressed, but control key was released, end of temporary zoom tool
54 view()->setTool( mPreviousViewTool );
55 }
56 else
57 {
58 mDeactivateOnMouseRelease = true;
59 }
60 }
61 else
62 {
63 //both control and space pressed
64 //set cursor to zoom in/out depending on alt key status
65 updateCursor( event->modifiers() );
66 if ( event->key() == Qt::Key_Space )
67 {
68 mDeactivateOnMouseRelease = false;
69 }
70 }
71}
72
74{
75 if ( event->isAutoRepeat() )
76 {
77 event->ignore();
78 return;
79 }
80
81 if ( event->key() == Qt::Key_Space )
82 {
83 //temporary keyboard-based zoom tool is active and space key has been released
84 if ( !mMarqueeZoom )
85 {
86 //not mid-way through an operation, so immediately switch tool back
87 view()->setTool( mPreviousViewTool );
88 }
89 else
90 {
91 mDeactivateOnMouseRelease = true;
92 }
93 }
94 else
95 {
96 updateCursor( event->modifiers() );
97 event->ignore();
98 }
99}
100
102{
103 mDeactivateOnMouseRelease = false;
104 mPreviousViewTool = view()->tool();
106 updateCursor( QApplication::keyboardModifiers() );
107}
108
109void QgsModelViewToolTemporaryKeyZoom::updateCursor( Qt::KeyboardModifiers modifiers )
110{
111 view()->viewport()->setCursor( ( modifiers & Qt::AltModifier ) ? QgsApplication::getThemeCursor( QgsApplication::Cursor::ZoomOut ) : QgsApplication::getThemeCursor( QgsApplication::Cursor::ZoomIn ) );
112}
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.
A QgsModelViewMouseEvent is the result of a user interaction with the mouse on 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.
Model view tool for zooming into and out of the model.
bool mMarqueeZoom
Will be true will marquee zoom operation is in progress.
void modelReleaseEvent(QgsModelViewMouseEvent *event) override
Mouse release event for overriding.
QgsModelGraphicsView * view() const
Returns the view associated with the tool.
virtual void activate()
Called when tool is set as the currently active model tool.