Krita Source Code Documentation
Loading...
Searching...
No Matches
KisPathEnclosingProducer.cpp
Go to the documentation of this file.
1/*
2 * KDE. Krita Project.
3 *
4 * SPDX-FileCopyrightText: 2022 Deif Lou <ginoba@gmail.com>
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9#include <kis_cursor.h>
10#include <KoPathShape.h>
11#include <KisViewManager.h>
12#include <canvas/kis_canvas2.h>
14#include <KoIcon.h>
15
17
19 : KoCreatePathTool(canvas)
20 , m_parentTool(parentTool)
21{}
22
23void KisToolPathLocalTool::paintPath(KoPathShape &pathShape, QPainter &painter, const KoViewConverter &converter)
24{
25 Q_UNUSED(converter);
26
27 QTransform matrix;
28 matrix.scale(m_parentTool->image()->xRes(), m_parentTool->image()->yRes());
29 matrix.translate(pathShape.position().x(), pathShape.position().y());
30 m_parentTool->paintToolOutline(&painter, m_parentTool->pixelToView(matrix.map(pathShape.outline())));
31}
32
37
42
47
50 KisCursor::load("tool_polygonal_selection_cursor.png", 6, 6),
51 new KisToolPathLocalTool(canvas, this))
52{
53 setObjectName("enclosing_tool_path");
54 setSupportOutline(true);
55 setOutlineEnabled(false);
56
57 KisCanvas2 *kritaCanvas = dynamic_cast<KisCanvas2*>(canvas);
58
59 connect(kritaCanvas->viewManager()->canvasResourceProvider(), SIGNAL(sigEffectiveCompositeOpChanged()), SLOT(resetCursorStyle()));
60}
61
64
66{
67 if (isEraser()) {
68 useCursor(KisCursor::load("tool_polygonal_selection_enclose_eraser_cursor.png", 6, 6));
69 } else {
70 KisDynamicDelegateTool::resetCursorStyle();
71 }
72
73 overrideCursorIfNotEditable();
74}
75
77{
78 KisDynamicDelegateTool::requestStrokeEnd();
79 localTool()->endPathWithoutLastPoint();
80}
81
83{
84 KisDynamicDelegateTool::requestStrokeCancellation();
85 localTool()->cancelPath();
86}
87
89{
90 return m_hasUserInteractionRunning ? nullptr : KisDynamicDelegateTool::popupWidget();
91}
92
94{
95 Q_UNUSED(event)
96}
97
98// Install an event filter to catch right-click events.
99// The simplest way to accommodate the popup palette binding.
100// This code is duplicated in kis_tool_select_path.cc
101bool KisPathEnclosingProducer::eventFilter(QObject *obj, QEvent *event)
102{
103 Q_UNUSED(obj);
105 return false;
106 }
107 if (event->type() == QEvent::MouseButtonPress ||
108 event->type() == QEvent::MouseButtonDblClick) {
109 QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
110 if (mouseEvent->button() == Qt::RightButton) {
111 localTool()->removeLastPoint();
112 return true;
113 }
114 } else if (event->type() == QEvent::TabletPress) {
115 QTabletEvent *tabletEvent = static_cast<QTabletEvent*>(event);
116 if (tabletEvent->button() == Qt::RightButton) {
117 localTool()->removeLastPoint();
118 return true;
119 }
120 }
121 return false;
122}
123
125 KisDynamicDelegateTool::beginAlternateAction(event, action);
126 if (!nodeEditable()) return;
127
128 if (nodePaintAbility() == KisDynamicDelegateTool::MYPAINTBRUSH_UNPAINTABLE) {
129 KisCanvas2 * kiscanvas = static_cast<KisCanvas2*>(canvas());
130 QString message = i18n("The MyPaint Brush Engine is not available for this colorspace");
131 kiscanvas->viewManager()->showFloatingMessage(message, koIcon("object-locked"));
132 event->ignore();
133 return;
134 }
135}
136
138{
139 if (!nodeEditable()) return;
140 KisDynamicDelegateTool::mousePressEvent(event);
141}
142
147
152
154{
155 KisDynamicDelegateTool::mouseDoubleClickEvent(event);
156}
157
159{
160 KisCanvas2 * kisCanvas = dynamic_cast<KisCanvas2*>(canvas());
161 if (!kisCanvas) {
162 return;
163 }
164
165 KisImageWSP image = kisCanvas->image();
166 KisPixelSelectionSP enclosingMask = new KisPixelSelection();
167
168 pathShape->normalize();
169 pathShape->close();
170
171 KisPainter painter(enclosingMask);
172 painter.setPaintColor(KoColor(Qt::white, enclosingMask->colorSpace()));
173 painter.setAntiAliasPolygonFill(false);
176
177 QTransform matrix;
178 matrix.scale(image->xRes(), image->yRes());
179 matrix.translate(pathShape->position().x(), pathShape->position().y());
180
181 QPainterPath path = matrix.map(pathShape->outline());
182 painter.fillPainterPath(path);
183 enclosingMask->setOutlineCache(path);
184
185 delete pathShape;
186
187 Q_EMIT enclosingMaskProduced(enclosingMask);
188}
189
194
199
KisDelegatedTool< KisToolShape, KisToolPathLocalTool, DeselectShapesActivationPolicy > DelegatedPathTool
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
KisImageWSP image() const
KisViewManager * viewManager() const
static QCursor load(const QString &cursorName, int hotspotX=-1, int hotspotY=-1)
void mouseMoveEvent(KoPointerEvent *event) override
void mouseReleaseEvent(KoPointerEvent *event) override
DelegateTool * localTool() const
double xRes() const
double yRes() const
const KoColorSpace * colorSpace() const
@ FillStyleForegroundColor
void setStrokeStyle(StrokeStyle strokeStyle)
Set the current brush stroke style.
void setFillStyle(FillStyle fillStyle)
Set the current style with which to fill.
void fillPainterPath(const QPainterPath &path)
void setPaintColor(const KoColor &color)
void setAntiAliasPolygonFill(bool antiAliasPolygonFill)
Set whether a polygon's filled area should be anti-aliased or not. The default is true.
void beginPrimaryDoubleClickAction(KoPointerEvent *event) override
KisPathEnclosingProducer(KoCanvasBase *canvas)
void addPathShape(KoPathShape *pathShape)
void endPrimaryAction(KoPointerEvent *event) override
void mousePressEvent(KoPointerEvent *event) override
void enclosingMaskProduced(KisPixelSelectionSP enclosingMask)
void beginPrimaryAction(KoPointerEvent *event) override
void continuePrimaryAction(KoPointerEvent *event) override
KisPopupWidgetInterface * popupWidget() override
void beginAlternateAction(KoPointerEvent *event, AlternateAction action) override
bool eventFilter(QObject *obj, QEvent *event) override
The PopupWidgetInterface abstract class defines the basic interface that will be used by all popup wi...
KisPathEnclosingProducer *const m_parentTool
void addPathShape(KoPathShape *pathShape) override
KisToolPathLocalTool(KoCanvasBase *canvas, KisPathEnclosingProducer *parentTool)
void paintPath(KoPathShape &pathShape, QPainter &painter, const KoViewConverter &converter) override
KisCanvasResourceProvider * canvasResourceProvider()
void showFloatingMessage(const QString &message, const QIcon &icon, int timeout=4500, KisFloatingMessage::Priority priority=KisFloatingMessage::Medium, int alignment=Qt::AlignCenter|Qt::TextWordWrap)
shows a floating message in the top right corner of the canvas
The position of a path point within a path shape.
Definition KoPathShape.h:63
virtual QPointF normalize()
Normalizes the path data.
void close()
Closes the current subpath.
QPainterPath outline() const override
reimplemented
QPointF position() const
Get the position of the shape in pt.
Definition KoShape.cpp:825
#define koIcon(name)
Use these macros for icons without any issues.
Definition kis_icon.h:25
void setOutlineCache(const QPainterPath &cache)