File indexing completed on 2024-12-22 04:16:47

0001 /*
0002  * KDE. Krita Project.
0003  *
0004  * SPDX-FileCopyrightText: 2022 Deif Lou <ginoba@gmail.com>
0005  *
0006  * SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 #include <KisViewManager.h>
0010 #include <canvas/kis_canvas2.h>
0011 #include <kis_canvas_resource_provider.h>
0012 
0013 #include "KisLassoEnclosingProducer.h"
0014 
0015 KisLassoEnclosingProducer::KisLassoEnclosingProducer(KoCanvasBase * canvas)
0016     : KisDynamicDelegateTool<KisToolOutlineBase>(canvas, KisToolOutlineBase::PAINT, KisCursor::load("tool_outline_selection_cursor.png", 5, 5))
0017 {
0018     setObjectName("enclosing_tool_lasso");
0019     setSupportOutline(true);
0020     setOutlineEnabled(false);
0021 
0022     KisCanvas2 *kritaCanvas = dynamic_cast<KisCanvas2*>(canvas);
0023 
0024     connect(kritaCanvas->viewManager()->canvasResourceProvider(), SIGNAL(sigEffectiveCompositeOpChanged()), SLOT(resetCursorStyle()));
0025 }
0026 
0027 KisLassoEnclosingProducer::~KisLassoEnclosingProducer()
0028 {}
0029 
0030 void  KisLassoEnclosingProducer::resetCursorStyle()
0031 {
0032     if (isEraser()) {
0033         useCursor(KisCursor::load("tool_outline_selection_enclose_eraser_cursor.png", 5, 5));
0034     } else {
0035         KisDynamicDelegateTool::resetCursorStyle();
0036     }
0037 
0038     overrideCursorIfNotEditable();
0039 }
0040 
0041 void KisLassoEnclosingProducer::finishOutline(const QVector<QPointF> &points)
0042 {
0043     if (points.size() < 3) {
0044         return;
0045     }
0046     
0047     KisPixelSelectionSP enclosingMask = new KisPixelSelection();
0048 
0049     KisPainter painter(enclosingMask);
0050     painter.setPaintColor(KoColor(Qt::white, enclosingMask->colorSpace()));
0051     painter.setAntiAliasPolygonFill(false);
0052     painter.setFillStyle(KisPainter::FillStyleForegroundColor);
0053     painter.setStrokeStyle(KisPainter::StrokeStyleNone);
0054 
0055     painter.paintPolygon(points);
0056 
0057     emit enclosingMaskProduced(enclosingMask);
0058 }
0059 
0060 bool KisLassoEnclosingProducer::hasUserInteractionRunning() const
0061 {
0062     return m_hasUserInteractionRunning;
0063 }
0064 
0065 void KisLassoEnclosingProducer::beginShape()
0066 {
0067     m_hasUserInteractionRunning = true;
0068 }
0069 
0070 void KisLassoEnclosingProducer::endShape()
0071 {
0072     m_hasUserInteractionRunning = false;
0073 }