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
13#include "KoZoomStrategy.h"
14#include "KoZoomToolWidget.h"
15#include "KoPointerEvent.h"
16#include "KoCanvasBase.h"
17#include "KoCanvasController.h"
18
19#include <FlakeDebug.h>
20
22 : KoInteractionTool(canvas)
23 , m_controller(nullptr)
24 , m_zoomInMode(true)
25{
26 QPixmap inPixmap, outPixmap;
27 inPixmap.load(":/zoom_in_cursor.png");
28 outPixmap.load(":/zoom_out_cursor.png");
29 m_inCursor = QCursor(inPixmap, 4, 4);
30 m_outCursor = QCursor(outPixmap, 4, 4);
31}
32
37
39{
40 updateCursor(event->modifiers() & Qt::ControlModifier);
41
43}
44
45void KoZoomTool::keyPressEvent(QKeyEvent *event)
46{
47 event->ignore();
48 updateCursor(event->modifiers() & Qt::ControlModifier);
49
51}
52
53void KoZoomTool::keyReleaseEvent(QKeyEvent *event)
54{
55 event->ignore();
56 updateCursor(event->modifiers() & Qt::ControlModifier);
57
59}
60
61void KoZoomTool::activate(const QSet<KoShape*> &)
62{
63 updateCursor(false);
64}
65
70
72{
73 KoZoomStrategy *zs = new KoZoomStrategy(this, m_controller, event->point);
74 bool shouldZoomIn = m_zoomInMode;
75 if (event->button() == Qt::RightButton ||
76 event->modifiers() == Qt::ControlModifier) {
77 shouldZoomIn = !shouldZoomIn;
78 }
79
80 if (shouldZoomIn) {
81 zs->forceZoomIn();
82 } else {
83 zs->forceZoomOut();
84 }
85 return zs;
86}
87
89{
90 return new KoZoomToolWidget(this);
91}
92
94{
95 m_zoomInMode = zoomIn;
96 updateCursor(false);
97}
98
100{
101 bool setZoomInCursor = m_zoomInMode;
102 if (swap) {
103 setZoomInCursor = !setZoomInCursor;
104 }
105
106 if (setZoomInCursor) {
108 } else {
110 }
111}
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
Qt::MouseButton button() const
return button pressed (see QMouseEvent::button());
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