6#include "VectorLayer.h"
7#include <kis_shape_layer.h>
12#include <commands/KoShapeCreateCommand.h>
13#include <commands/KoShapeGroupCommand.h>
14#include <KoShapeGroup.h>
15#include <KisDocument.h>
16#include <kis_processing_applicator.h>
17#include <kis_group_layer.h>
20#include "GroupShape.h"
21#include "LibKisUtils.h"
24VectorLayer::VectorLayer(KoShapeControllerBase* shapeController, KisImageSP image,
QString name,
QObject *parent) :
25 Node(image, new KisShapeLayer(shapeController, image,
name, OPACITY_OPAQUE_U8), parent)
30VectorLayer::VectorLayer(KisShapeLayerSP layer,
QObject *parent):
31 Node(layer->image(), layer, parent)
36VectorLayer::~VectorLayer()
49 KisShapeLayerSP vector = KisShapeLayerSP(
dynamic_cast<KisShapeLayer*
>(this->node().data()));
52 std::sort(originalShapes.
begin(), originalShapes.
end(), KoShape::compareShapeZIndex);
53 for (
int i=0; i<vector->shapeCount(); i++) {
54 if (
dynamic_cast<KoShapeGroup*
>(originalShapes.
at(i))) {
67 KisShapeLayerSP vector = KisShapeLayerSP(
dynamic_cast<KisShapeLayer*
>(this->node().data()));
73 std::sort(originalShapes.
begin(), originalShapes.
end(), KoShape::compareShapeZIndex);
75 const QSizeF sizeInPx = this->node()->image()->bounds().size();
76 const QSizeF pageSize(sizeInPx.
width() / this->node()->image()->xRes(),
77 sizeInPx.
height() / this->node()->image()->yRes());
81 SvgWriter writer(originalShapes);
83 writer.save(buffer, pageSize);
102 KoShapeContainer *container =
dynamic_cast<KoShapeContainer*
>(this->node().data());
110 QDomDocument dom = SvgParser::createDocumentFromSvg(svgData, &errorMsg, &errorLine, &errorColumn);
113 qWarning() <<
"Failed to process an SVG string at"
114 << errorLine <<
":" << errorColumn <<
"->" << errorMsg;
121 document = LibKisUtils::findNodeInDocuments(this->node());
127 SvgParser parser(document->document()->shapeController()->resourceManager());
129 parser.setResolution(this->node()->image()->
bounds(), this->node()->image()->xRes() * 72.0);
131 originalShapes = parser.parseSvg(dom.
documentElement(), &fragmentSize);
133 KUndo2Command *cmd =
new KoShapeCreateCommand(document->document()->shapeController(), originalShapes, container);
135 KisProcessingApplicator::runSingleCommandStroke(this->node()->image(), cmd);
136 this->node()->image()->waitForDone();
139 std::sort(originalShapes.
begin(), originalShapes.
end(), KoShape::compareShapeZIndex);
140 for (
int i=0; i<originalShapes.
size(); i++) {
141 if (
dynamic_cast<KoShapeGroup*
>(originalShapes.
at(i))) {
155 KisShapeLayerSP vector = KisShapeLayerSP(
dynamic_cast<KisShapeLayer*
>(this->node().data()));
157 if (!vector)
return 0;
159 KoShape* shape = vector->shapeManager()->shapeAt(
position);
161 if (!shape)
return 0;
163 if (
dynamic_cast<KoShapeGroup*
>(shape)) {
164 return new GroupShape(
dynamic_cast<KoShapeGroup*
>(shape));
166 return new Shape(shape);
173 KisShapeLayerSP vector = KisShapeLayerSP(
dynamic_cast<KisShapeLayer*
>(this->node().data()));
176 QList<KoShape *> originalShapes = vector->shapeManager()->shapesAt(rect, omitHiddenShapes, containedMode);
178 std::sort(originalShapes.
begin(), originalShapes.
end(), KoShape::compareShapeZIndex);
179 for (
int i=0; i<originalShapes.
size(); i++) {
180 if (
dynamic_cast<KoShapeGroup*
>(originalShapes.
at(i))) {
192 if (
shapes.isEmpty())
return 0;
195 KoShapeContainer *container =
dynamic_cast<KoShapeContainer*
>(this->node().data());
197 if (!container)
return 0;
200 KoShape *originalShape = shape->shape();
202 if (originalShape && originalShape->parent() == container) {
203 originalShapes << originalShape;
205 qWarning() <<
"Attempt to add an invalid shape.";
210 if (originalShapes.
isEmpty())
return 0;
215 document = LibKisUtils::findNodeInDocuments(this->node());
216 if (!document)
return 0;
219 KoShapeGroup *group =
new KoShapeGroup();
220 const int groupZIndex = originalShapes.
last()->zIndex();
222 group->setZIndex(groupZIndex);
223 group->setName(
name);
225 KUndo2Command *cmd =
new KUndo2Command(kundo2_i18n(
"Group shapes"));
226 new KoShapeCreateCommand(document->document()->shapeController(), group, container, cmd);
227 new KoShapeGroupCommand(group, originalShapes,
true, cmd);
229 KisProcessingApplicator::runSingleCommandStroke(this->node()->image(), cmd);
230 this->node()->image()->waitForDone();
239 KisShapeLayerSP vectorLayer = KisShapeLayerSP(
dynamic_cast<KisShapeLayer*
>(this->node().data()));
240 return vectorLayer->antialiased();
245 KisShapeLayerSP vectorLayer = KisShapeLayerSP(
dynamic_cast<KisShapeLayer*
>(this->node().data()));
246 vectorLayer->setAntialiased(antialiased);
The Document class encapsulates a Krita Document/Image.
The GroupShape class A group shape is a vector object with child shapes.
Document * activeDocument() const
static Krita * instance()
instance retrieve the singleton instance of the Application object.
Node represents a layer or mask in a Krita image's Node hierarchy.
QPoint position() const
position returns the position of the paint device of this node.
QRect bounds() const
bounds return the exact bounds of the node's paint device
The Shape class The shape class is a wrapper around Krita's vector objects.
bool isAntialiased() const
return antialiasing status for the Vector layer
virtual QString type() const override
type Krita has several types of nodes, split in layers and masks.
QList< Shape * > addShapesFromSvg(const QString &svg)
addShapesFromSvg add shapes to the layer from a valid svg.
QList< Shape * > shapesInRect(const QRectF &rect, bool omitHiddenShapes=true, bool containedMode=false) const
shapeInRect get all non-group shapes that the shape's boundingBox() intersects or is contained within...
QList< Shape * > shapes() const
shapes
QString toSvg()
toSvg convert the shapes in the layer to svg.
Shape * createGroupShape(const QString &name, QList< Shape * > shapes) const
createGroupShape combine a list of top level shapes into a group.
void setAntialiased(const bool antialiased)
set antialiasing status for the Vector layer
Shape * shapeAtPosition(const QPointF &position) const
shapeAtPoint check if the position is located within any non-group shape's boundingBox() on the curre...
QString name(GameStandardAction id)
virtual void close() override
const QByteArray & data() const const
virtual bool open(OpenMode flags) override
QDomElement documentElement() const const
bool isNull() const const
const_reference at(qsizetype i) const const
bool isEmpty() const const
qsizetype size() const const
qreal height() const const
qreal width() const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
QString fromUtf8(QByteArrayView str)
bool isEmpty() const const