Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_tool_polyline.cc
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2004 Michael Thaler <michael.thaler@physik.tu-muenchen.de>
3 * SPDX-FileCopyrightText: 2008 Boudewijn Rempt <boud@valdyas.org>
4 * SPDX-FileCopyrightText: 2009 Lukáš Tvrdý <lukast.dev@gmail.com>
5 * SPDX-FileCopyrightText: 2010 Cyrille Berger <cberger@cberger.net>
6 *
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
9
10#include "kis_tool_polyline.h"
11
12#include <QVector>
13
14#include <KoCanvasBase.h>
15#include <KoPathShape.h>
16#include <KoShapeStroke.h>
17
20
22 : KisToolPolylineBase(canvas, KisToolPolylineBase::PAINT, KisCursor::load("tool_polyline_cursor.png", 6, 6))
23{
24 setObjectName("tool_polyline");
27}
28
32
34{
35 if (isEraser()) {
36 useCursor(KisCursor::load("tool_polyline_eraser_cursor.png", 6, 6));
37 } else {
39 }
40
42}
43
48
50{
53
54 if (!info.shouldAddShape || info.shouldAddSelectionShape) {
55 KisFigurePaintingToolHelper helper(kundo2_i18n("Draw Polyline"),
56 image(),
58 canvas()->resourceManager(),
60 fillStyle(),
62 helper.paintPolyline(points);
63 } else {
64 KoPathShape* path = new KoPathShape();
65 path->setShapeId(KoPathShapeId);
66
67 QTransform resolutionMatrix;
68 resolutionMatrix.scale(1 / currentImage()->xRes(), 1 / currentImage()->yRes());
69 path->moveTo(resolutionMatrix.map(points[0]));
70 for (int i = 1; i < points.count(); i++)
71 path->lineTo(resolutionMatrix.map(points[i]));
72 path->normalize();
73
74 addShape(path);
75 }
76}
77
79{
80 return true;
81}
#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
~KisToolPolyline() override
KisToolPolyline(KoCanvasBase *canvas)
QWidget * createOptionWidget() override
void finishPolyline(const QVector< QPointF > &points) override
bool supportsPaintingAssistants() const override
void resetCursorStyle() 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
virtual QWidget * createOptionWidget()
void setIsOpacityPresetMode(bool value)
void useCursor(const QCursor &cursor)
KUndo2MagicString kundo2_i18n(const char *text)
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