File indexing completed on 2024-05-19 04:26:58

0001 /*
0002  *  SPDX-FileCopyrightText: 2017 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 #ifndef LIBKIS_VECTORLAYER_H
0007 #define LIBKIS_VECTORLAYER_H
0008 
0009 #include <QObject>
0010 
0011 #include <kis_types.h>
0012 
0013 #include "kritalibkis_export.h"
0014 #include "libkis.h"
0015 
0016 #include <KoShapeControllerBase.h>
0017 
0018 #include "Node.h"
0019 #include "Shape.h"
0020 
0021 /**
0022  * @brief The VectorLayer class
0023  * A vector layer is a special layer that stores
0024  * and shows vector shapes.
0025  *
0026  * Vector shapes all have their coordinates in points, which
0027  * is a unit that represents 1/72th of an inch. Keep this in
0028  * mind wen parsing the bounding box and position data.
0029  */
0030 
0031 class KRITALIBKIS_EXPORT VectorLayer : public Node
0032 {
0033     Q_OBJECT
0034     Q_DISABLE_COPY(VectorLayer)
0035 
0036 public:
0037     explicit VectorLayer(KoShapeControllerBase* shapeController, KisImageSP image, QString name, QObject *parent = 0);
0038     explicit VectorLayer(KisShapeLayerSP layer, QObject *parent = 0);
0039     ~VectorLayer() override;
0040 public Q_SLOTS:
0041 
0042     /**
0043      * @brief type Krita has several types of nodes, split in layers and masks. Group
0044      * layers can contain other layers, any layer can contain masks.
0045      *
0046      * @return vectorlayer
0047      */
0048     virtual QString type() const override;
0049 
0050     /**
0051      * @brief shapes
0052      * @return the list of top-level shapes in this vector layer.
0053      */
0054     QList<Shape *> shapes() const;
0055 
0056     /**
0057      * @brief toSvg
0058      * convert the shapes in the layer to svg.
0059      * @return the svg in a string.
0060      */
0061     QString toSvg();
0062 
0063     /**
0064      * @brief addShapesFromSvg
0065      * add shapes to the layer from a valid svg.
0066      * @param svg valid svg string.
0067      * @return the list of shapes added to the layer from the svg.
0068      */
0069     QList<Shape *> addShapesFromSvg(const QString &svg);
0070 
0071     /**
0072      * @brief shapeAtPoint
0073      * check if the position is located within any non-group shape's boundingBox() on the current layer.
0074      * @param position a QPointF of the position.
0075      * @return the shape at the position, or None if no shape is found.
0076      */
0077     Shape* shapeAtPosition(const QPointF &position) const;
0078 
0079     /**
0080      * @brief shapeInRect
0081      * get all non-group shapes that the shape's boundingBox() intersects or is contained within a given rectangle on the current layer.
0082      * @param rect a QRectF
0083      * @param omitHiddenShapes true if non-visible() shapes should be omitted, false if they should be included. \p omitHiddenShapes defaults to true.
0084      * @param containedMode false if only shapes that are within or intersect with the outline should be included, true if only shapes that are fully contained within the outline should be included. \p containedMode defaults to false
0085      * @return returns a list of shapes.
0086      */
0087     QList<Shape *> shapesInRect(const QRectF &rect, bool omitHiddenShapes = true, bool containedMode = false) const;
0088 
0089     /**
0090      * @brief createGroupShape
0091      * combine a list of top level shapes into a group.
0092      * @param name the name of the shape.
0093      * @param shapes list of top level shapes.
0094      * @return if successful, a GroupShape object will be returned.
0095      */
0096     Shape* createGroupShape(const QString &name, QList<Shape *> shapes) const;
0097 
0098 };
0099 
0100 #endif // LIBKIS_VECTORLAYER_H
0101