QGIS API Documentation 3.41.0-Master (cea29feecf2)
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#include "moc_qgslayoutviewtooltemporarykeyzoom.cpp"
19#include "qgslayoutview.h"
20#include <QScrollBar>
21#include <QApplication>
22
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
108void QgsLayoutViewToolTemporaryKeyZoom::updateCursor( Qt::KeyboardModifiers modifiers )
109{
110 view()->viewport()->setCursor( ( modifiers & Qt::AltModifier ) ? QgsApplication::getThemeCursor( QgsApplication::Cursor::ZoomOut ) : QgsApplication::getThemeCursor( QgsApplication::Cursor::ZoomIn ) );
111}
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 QgsLayoutViewMouseEvent is the result of a user interaction with the mouse on 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.
Layout view tool for zooming into and out of the layout.
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.
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