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