QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 }
QgsLayoutViewToolTemporaryKeyZoom::layoutReleaseEvent
void layoutReleaseEvent(QgsLayoutViewMouseEvent *event) override
Mouse release event for overriding.
Definition: qgslayoutviewtooltemporarykeyzoom.cpp:27
QgsApplication::getThemeCursor
static QCursor getThemeCursor(Cursor cursor)
Helper to get a theme cursor.
Definition: qgsapplication.cpp:635
qgslayoutview.h
QgsLayoutViewToolZoom::layoutReleaseEvent
void layoutReleaseEvent(QgsLayoutViewMouseEvent *event) override
Mouse release event for overriding.
Definition: qgslayoutviewtoolzoom.cpp:75
QgsLayoutViewToolTemporaryKeyZoom::QgsLayoutViewToolTemporaryKeyZoom
QgsLayoutViewToolTemporaryKeyZoom(QgsLayoutView *view)
Constructor for QgsLayoutViewToolTemporaryKeyZoom.
Definition: qgslayoutviewtooltemporarykeyzoom.cpp:22
qgslayoutviewmouseevent.h
QgsLayoutViewToolZoom::mMarqueeZoom
bool mMarqueeZoom
Will be true will marquee zoom operation is in progress.
Definition: qgslayoutviewtoolzoom.h:65
QgsLayoutViewToolTemporaryKeyZoom::keyReleaseEvent
void keyReleaseEvent(QKeyEvent *event) override
Key release event for overriding.
Definition: qgslayoutviewtooltemporarykeyzoom.cpp:71
QgsLayoutViewTool::view
QgsLayoutView * view() const
Returns the view associated with the tool.
Definition: qgslayoutviewtool.cpp:38
QgsLayoutView::setTool
void setTool(QgsLayoutViewTool *tool)
Sets the tool currently being used in the view.
Definition: qgslayoutview.cpp:132
QgsLayoutView::tool
QgsLayoutViewTool tool
Definition: qgslayoutview.h:64
QgsLayoutView
Definition: qgslayoutview.h:49
QgsLayoutViewToolTemporaryKeyZoom::keyPressEvent
void keyPressEvent(QKeyEvent *event) override
Key press event for overriding.
Definition: qgslayoutviewtooltemporarykeyzoom.cpp:38
QgsLayoutViewTool::activate
virtual void activate()
Called when tool is set as the currently active layout tool.
Definition: qgslayoutviewtool.cpp:120
QgsLayoutViewMouseEvent
Definition: qgslayoutviewmouseevent.h:35
QgsLayoutViewToolZoom
Definition: qgslayoutviewtoolzoom.h:30
qgslayoutviewtooltemporarykeyzoom.h
QgsLayoutViewToolTemporaryKeyZoom::activate
void activate() override
Called when tool is set as the currently active layout tool.
Definition: qgslayoutviewtooltemporarykeyzoom.cpp:99