QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
Loading...
Searching...
No Matches
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
17
18#include "qgslayoutview.h"
20
21#include <QApplication>
22#include <QScrollBar>
23
24#include "moc_qgslayoutviewtooltemporarykeyzoom.cpp"
25
29
31{
33 if ( !event->isAccepted() )
34 return;
35
36 //end of temporary zoom tool
37 if ( mDeactivateOnMouseRelease )
38 view()->setTool( mPreviousViewTool );
39}
40
42{
43 if ( event->isAutoRepeat() )
44 {
45 event->ignore();
46 return;
47 }
48
49 //respond to changes in ctrl key status
50 if ( !( event->modifiers() & Qt::ControlModifier ) )
51 {
52 if ( !mMarqueeZoom )
53 {
54 //space pressed, but control key was released, end of temporary zoom tool
55 view()->setTool( mPreviousViewTool );
56 }
57 else
58 {
59 mDeactivateOnMouseRelease = true;
60 }
61 }
62 else
63 {
64 //both control and space pressed
65 //set cursor to zoom in/out depending on alt key status
66 updateCursor( event->modifiers() );
67 if ( event->key() == Qt::Key_Space )
68 {
69 mDeactivateOnMouseRelease = false;
70 }
71 }
72}
73
75{
76 if ( event->isAutoRepeat() )
77 {
78 event->ignore();
79 return;
80 }
81
82 if ( event->key() == Qt::Key_Space )
83 {
84 //temporary keyboard-based zoom tool is active and space key has been released
85 if ( !mMarqueeZoom )
86 {
87 //not mid-way through an operation, so immediately switch tool back
88 view()->setTool( mPreviousViewTool );
89 }
90 else
91 {
92 mDeactivateOnMouseRelease = true;
93 }
94 }
95 else
96 {
97 updateCursor( event->modifiers() );
98 event->ignore();
99 }
100}
101
103{
104 mDeactivateOnMouseRelease = false;
105 mPreviousViewTool = view()->tool();
107 updateCursor( QApplication::keyboardModifiers() );
108}
109
110void QgsLayoutViewToolTemporaryKeyZoom::updateCursor( Qt::KeyboardModifiers modifiers )
111{
113}
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 QgsLayoutView.
void layoutReleaseEvent(QgsLayoutViewMouseEvent *event) override
Mouse release event for overriding.
void keyPressEvent(QKeyEvent *event) override
Key press event for overriding.
void keyReleaseEvent(QKeyEvent *event) override
Key release event for overriding.
QgsLayoutViewToolTemporaryKeyZoom(QgsLayoutView *view)
Constructor for QgsLayoutViewToolTemporaryKeyZoom.
void activate() override
Called when tool is set as the currently active layout tool.
void layoutReleaseEvent(QgsLayoutViewMouseEvent *event) override
Mouse release event for overriding.
QgsLayoutViewToolZoom(QgsLayoutView *view)
Constructor for QgsLayoutViewToolZoom.
bool mMarqueeZoom
Will be true will marquee zoom operation is in progress.
QgsLayoutView * view() const
Returns the view associated with the tool.
virtual void activate()
Called when tool is set as the currently active layout tool.
A graphical widget to display and interact with QgsLayouts.
void setTool(QgsLayoutViewTool *tool)
Sets the tool currently being used in the view.
QgsLayoutViewTool * tool