Krita Source Code Documentation
Loading...
Searching...
No Matches
KoZoomTool.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 *
3 * SPDX-FileCopyrightText: 2006-2007 Thomas Zander <zander@kde.org>
4 * SPDX-FileCopyrightText: 2006 Thorsten Zachmann <zachmann@kde.org>
5 *
6 * SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8
9#include "KoZoomTool.h"
10
11#include <QKeyEvent>
12#include <QIcon>
13#include <QPixmap>
14#include <QWidget>
15
16#include "KoZoomStrategy.h"
17#include "KoZoomToolWidget.h"
18#include "KoPointerEvent.h"
19#include "KoCanvasBase.h"
20#include "KoCanvasController.h"
21
22#include <FlakeDebug.h>
23
25 : KoInteractionTool(canvas)
26 , m_controller(nullptr)
27 , m_zoomInMode(true)
28{
29 QPixmap inPixmap, outPixmap;
30 inPixmap = QIcon(":/zoom_in_cursor.svg").pixmap(32);
31 outPixmap = QIcon(":/zoom_out_cursor.svg").pixmap(32);
32 m_inCursor = QCursor(inPixmap, 4*inPixmap.devicePixelRatio(), 4*inPixmap.devicePixelRatio());
33 m_outCursor = QCursor(outPixmap, 4*outPixmap.devicePixelRatio(), 4*outPixmap.devicePixelRatio());
34}
35
40
42{
43 updateCursor(event->modifiers() == Qt::ControlModifier);
44
46}
47
48void KoZoomTool::keyPressEvent(QKeyEvent *event)
49{
50 event->ignore();
51 updateCursor(event->modifiers() == Qt::ControlModifier);
52
54}
55
56void KoZoomTool::keyReleaseEvent(QKeyEvent *event)
57{
58 event->ignore();
59 updateCursor(event->modifiers() == Qt::ControlModifier);
60
62}
63
64void KoZoomTool::activate(const QSet<KoShape*> &)
65{
66 updateCursor(false);
67}
68
73
75{
76 KoZoomStrategy *zs = new KoZoomStrategy(this, m_controller, event->point);
77 bool shouldZoomIn = m_zoomInMode;
78 if (event->modifiers() == Qt::ControlModifier) {
79 shouldZoomIn = !shouldZoomIn;
80 }
81
82 if (shouldZoomIn) {
83 zs->forceZoomIn();
84 } else {
85 zs->forceZoomOut();
86 }
87 return zs;
88}
89
91{
92 return new KoZoomToolWidget(this);
93}
94
96{
97 m_zoomInMode = zoomIn;
98 updateCursor(false);
99}
100
102{
103 bool setZoomInCursor = m_zoomInMode;
104 if (swap) {
105 setZoomInCursor = !setZoomInCursor;
106 }
107
108 if (KoZoomStrategy * strategy = dynamic_cast<KoZoomStrategy*>(currentStrategy())) {
109 setZoomInCursor = !strategy->isZoomOutMode();
110 }
111
112 if (setZoomInCursor) {
114 } else {
116 }
117}
void mouseReleaseEvent(KoPointerEvent *event) override
void mouseMoveEvent(KoPointerEvent *event) override
void mousePressEvent(KoPointerEvent *event) override
void keyReleaseEvent(QKeyEvent *event) override
void keyPressEvent(QKeyEvent *event) override
KoInteractionStrategy * currentStrategy()
Qt::KeyboardModifiers modifiers() const
QPointF point
The point in document coordinates.
void useCursor(const QCursor &cursor)
QWidget * createOptionWidget() override
KoCanvasController * m_controller
Definition KoZoomTool.h:49
void keyReleaseEvent(QKeyEvent *event) override
QCursor m_outCursor
Definition KoZoomTool.h:51
void mouseDoubleClickEvent(KoPointerEvent *event) override
QCursor m_inCursor
Definition KoZoomTool.h:50
void keyPressEvent(QKeyEvent *event) override
bool m_zoomInMode
Definition KoZoomTool.h:52
void activate(const QSet< KoShape * > &shapes) override
void mouseMoveEvent(KoPointerEvent *event) override
void updateCursor(bool swap)
void mouseReleaseEvent(KoPointerEvent *event) override
void setZoomInMode(bool zoomIn)
KoZoomTool(KoCanvasBase *canvas)
KoInteractionStrategy * createStrategy(KoPointerEvent *event) override