Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_tool_polygon.cc
Go to the documentation of this file.
1/*
2 * kis_tool_polygon.cc -- part of Krita
3 *
4 * SPDX-FileCopyrightText: 2004 Michael Thaler <michael.thaler@physik.tu-muenchen.de>
5 * SPDX-FileCopyrightText: 2009 Lukáš Tvrdý <lukast.dev@gmail.com>
6 * SPDX-FileCopyrightText: 2010 Cyrille Berger <cberger@cberger.net>
7 * SPDX-FileCopyrightText: 2010 Boudewijn Rempt <boud@valdyas.org>
8 *
9 * SPDX-License-Identifier: GPL-2.0-or-later
10 */
11
12#include "kis_tool_polygon.h"
13
14#include <KoPointerEvent.h>
15#include <KoCanvasBase.h>
16#include <KoPathShape.h>
17#include <KoShapeStroke.h>
18
21
23 : KisToolPolylineBase(canvas, KisToolPolylineBase::PAINT, KisCursor::load("tool_polygon_cursor.png", 6, 6))
24{
25 setObjectName("tool_polygon");
28}
29
33
35{
36 if (isEraser()) {
37 useCursor(KisCursor::load("tool_polygon_eraser_cursor.png", 6, 6));
38 } else {
40 }
41
43}
44
46{
49
50 if (!info.shouldAddShape) {
51 KisFigurePaintingToolHelper helper(kundo2_i18n("Draw Polygon"),
52 image(),
54 canvas()->resourceManager(),
56 fillStyle(),
58 helper.paintPolygon(points);
59 } else {
60 // remove the last point if it overlaps with the first
61 QVector<QPointF> newPoints = points;
62 if (newPoints.size() > 1 && newPoints.first() == newPoints.last()) {
63 newPoints.removeLast();
64 }
65 KoPathShape* path = new KoPathShape();
66 path->setShapeId(KoPathShapeId);
67
68 QTransform resolutionMatrix;
69 resolutionMatrix.scale(1 / currentImage()->xRes(), 1 / currentImage()->yRes());
70 path->moveTo(resolutionMatrix.map(newPoints[0]));
71 for (int i = 1; i < newPoints.size(); i++)
72 path->lineTo(resolutionMatrix.map(newPoints[i]));
73 path->close();
74 path->normalize();
75
77
78 addShape(path);
79 }
80}
81
83{
84 return true;
85}
#define KoPathShapeId
Definition KoPathShape.h:20
static QCursor load(const QString &cursorName, int hotspotX=-1, int hotspotY=-1)
void setSupportOutline(bool supportOutline)
bool isEraser() const
void finishPolyline(const QVector< QPointF > &points) override
void resetCursorStyle() override
KisToolPolygon(KoCanvasBase *canvas)
~KisToolPolygon() override
bool supportsPaintingAssistants() const override
KisToolShapeUtils::StrokeStyle strokeStyle()
ShapeAddInfo shouldAddShape(KisNodeSP currentNode) const
QTransform fillTransform()
void addShape(KoShape *shape)
KisToolShapeUtils::FillStyle fillStyle()
The position of a path point within a path shape.
Definition KoPathShape.h:63
void setIsOpacityPresetMode(bool value)
void useCursor(const QCursor &cursor)
KUndo2MagicString kundo2_i18n(const char *text)
void markAsSelectionShapeIfNeeded(KoShape *shape) const
KisImageWSP currentImage()
Definition kis_tool.cc:393
virtual void resetCursorStyle()
Definition kis_tool.cc:613
KisNodeSP currentNode() const
Definition kis_tool.cc:370
bool overrideCursorIfNotEditable()
Override the cursor appropriately if current node is not editable.
Definition kis_tool.cc:618
KisImageWSP image() const
Definition kis_tool.cc:332
KisCanvas2 * canvas