QGIS API Documentation  3.4.15-Madeira (e83d02e274)
qgslayoutviewtooltemporarykeyzoom.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayoutviewtooltemporarykeyzoom.cpp
3  -------------------------------------
4  Date : July 2017
5  Copyright : (C) 2017 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 
18 #include "qgslayoutview.h"
19 #include <QScrollBar>
20 #include <QApplication>
21 
23  : QgsLayoutViewToolZoom( view )
24 {
25 }
26 
28 {
30  if ( !event->isAccepted() )
31  return;
32 
33  //end of temporary zoom tool
34  if ( mDeactivateOnMouseRelease )
35  view()->setTool( mPreviousViewTool );
36 }
37 
39 {
40  if ( event->isAutoRepeat() )
41  {
42  event->ignore();
43  return;
44  }
45 
46  //respond to changes in ctrl key status
47  if ( !( event->modifiers() & Qt::ControlModifier ) )
48  {
49  if ( !mMarqueeZoom )
50  {
51  //space pressed, but control key was released, end of temporary zoom tool
52  view()->setTool( mPreviousViewTool );
53  }
54  else
55  {
56  mDeactivateOnMouseRelease = true;
57  }
58  }
59  else
60  {
61  //both control and space pressed
62  //set cursor to zoom in/out depending on alt key status
63  updateCursor( event->modifiers() );
64  if ( event->key() == Qt::Key_Space )
65  {
66  mDeactivateOnMouseRelease = false;
67  }
68  }
69 }
70 
72 {
73  if ( event->isAutoRepeat() )
74  {
75  event->ignore();
76  return;
77  }
78 
79  if ( event->key() == Qt::Key_Space )
80  {
81  //temporary keyboard-based zoom tool is active and space key has been released
82  if ( !mMarqueeZoom )
83  {
84  //not mid-way through an operation, so immediately switch tool back
85  view()->setTool( mPreviousViewTool );
86  }
87  else
88  {
89  mDeactivateOnMouseRelease = true;
90  }
91  }
92  else
93  {
94  updateCursor( event->modifiers() );
95  event->ignore();
96  }
97 }
98 
100 {
101  mDeactivateOnMouseRelease = false;
102  mPreviousViewTool = view()->tool();
104  updateCursor( QApplication::keyboardModifiers() );
105 }
106 
107 void QgsLayoutViewToolTemporaryKeyZoom::updateCursor( Qt::KeyboardModifiers modifiers )
108 {
109  view()->viewport()->setCursor( ( modifiers & Qt::AltModifier ) ?
110  QgsApplication::getThemeCursor( QgsApplication::Cursor::ZoomOut ) :
111  QgsApplication::getThemeCursor( QgsApplication::Cursor::ZoomIn ) );
112 }
void activate() override
Called when tool is set as the currently active layout tool.
A graphical widget to display and interact with QgsLayouts.
Definition: qgslayoutview.h:49
virtual void activate()
Called when tool is set as the currently active layout tool.
void setTool(QgsLayoutViewTool *tool)
Sets the tool currently being used in the view.
void layoutReleaseEvent(QgsLayoutViewMouseEvent *event) override
Mouse release event for overriding.
QgsLayoutViewToolTemporaryKeyZoom(QgsLayoutView *view)
Constructor for QgsLayoutViewToolTemporaryKeyZoom.
void layoutReleaseEvent(QgsLayoutViewMouseEvent *event) override
Mouse release event for overriding.
bool mMarqueeZoom
Will be true will marquee zoom operation is in progress.
QgsLayoutView * view() const
Returns the view associated with the tool.
Layout view tool for zooming into and out of the layout.
void keyPressEvent(QKeyEvent *event) override
Key press event for overriding.
A QgsLayoutViewMouseEvent is the result of a user interaction with the mouse on a QgsLayoutView...
QgsLayoutViewTool tool
Definition: qgslayoutview.h:64
static QCursor getThemeCursor(Cursor cursor)
Helper to get a theme cursor.
void keyReleaseEvent(QKeyEvent *event) override
Key release event for overriding.