Warning, file /graphics/krita/plugins/tools/tool_enclose_and_fill/subtools/KisRectangleEnclosingProducer.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 "KisRectangleEnclosingProducer.h"
0014 
0015 KisRectangleEnclosingProducer::KisRectangleEnclosingProducer(KoCanvasBase * canvas)
0016     : KisDynamicDelegateTool<KisToolRectangleBase>(canvas, KisToolRectangleBase::PAINT, KisCursor::load("tool_rectangular_selection_cursor.png", 6, 6))
0017 {
0018     setObjectName("enclosing_tool_rectangle");
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 KisRectangleEnclosingProducer::~KisRectangleEnclosingProducer()
0028 {}
0029 
0030 void  KisRectangleEnclosingProducer::resetCursorStyle()
0031 {
0032     if (isEraser()) {
0033         useCursor(KisCursor::load("tool_rectangular_selection_enclose_eraser_cursor.png", 6, 6));
0034     } else {
0035         KisDynamicDelegateTool::resetCursorStyle();
0036     }
0037 
0038     overrideCursorIfNotEditable();
0039 }
0040 
0041 void KisRectangleEnclosingProducer::finishRect(const QRectF& rect, qreal roundCornersX, qreal roundCornersY)
0042 {
0043     QRect rc(rect.normalized().toRect());
0044     if (!rc.isValid()) {
0045         return;
0046     }
0047 
0048     KisPixelSelectionSP enclosingMask = KisPixelSelectionSP(new KisPixelSelection());
0049     QPainterPath path;
0050 
0051     if (roundCornersX > 0 || roundCornersY > 0) {
0052         path.addRoundedRect(rc, roundCornersX, roundCornersY);
0053     } else {
0054         path.addRect(rc);
0055     }
0056     getRotatedPath(path, rc.center(), getRotationAngle());
0057 
0058     KisPainter painter(enclosingMask);
0059     painter.setPaintColor(KoColor(Qt::white, enclosingMask->colorSpace()));
0060     painter.setAntiAliasPolygonFill(false);
0061     painter.setFillStyle(KisPainter::FillStyleForegroundColor);
0062     painter.setStrokeStyle(KisPainter::StrokeStyleNone);
0063 
0064     painter.paintPainterPath(path);
0065 
0066     emit enclosingMaskProduced(enclosingMask);
0067 }
0068 
0069 bool KisRectangleEnclosingProducer::hasUserInteractionRunning() const
0070 {
0071     return m_hasUserInteractionRunning;
0072 }
0073 
0074 void KisRectangleEnclosingProducer::beginShape()
0075 {
0076     m_hasUserInteractionRunning = true;
0077 }
0078 
0079 void KisRectangleEnclosingProducer::endShape()
0080 {
0081     m_hasUserInteractionRunning = false;
0082 }