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

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_SHAPE_H
0007 #define LIBKIS_SHAPE_H
0008 
0009 #include <QObject>
0010 #include <KoShape.h>
0011 
0012 #include "kritalibkis_export.h"
0013 #include "libkis.h"
0014 #include <kis_types.h>
0015 
0016 /**
0017  * @brief The Shape class
0018  * The shape class is a wrapper around Krita's vector objects.
0019  *
0020  * Some example code to parse through interesting information in a given vector layer with shapes.
0021  * @code
0022 import sys
0023 from krita import *
0024 
0025 doc = Application.activeDocument()
0026 
0027 root = doc.rootNode()
0028 
0029 for layer in root.childNodes():
0030     print (str(layer.type())+" "+str(layer.name()))
0031     if (str(layer.type())=="vectorlayer"):
0032         for shape in layer.shapes():
0033             print(shape.name())
0034             print(shape.toSvg())
0035  * @endcode
0036  */
0037 class KRITALIBKIS_EXPORT Shape : public QObject
0038 {
0039     Q_OBJECT
0040     Q_DISABLE_COPY(Shape)
0041 
0042 public:
0043     explicit Shape(KoShape *shape, QObject *parent = 0);
0044     ~Shape();
0045 
0046     bool operator==(const Shape &other) const;
0047     bool operator!=(const Shape &other) const;
0048 
0049 public Q_SLOTS:
0050 
0051     /**
0052      * @brief name
0053      * @return the name of the shape
0054      */
0055     QString name() const;
0056 
0057     /**
0058      * @brief setName
0059      * @param name which name the shape should have.
0060      */
0061     void setName(const QString &name);
0062 
0063     /**
0064      * @brief type
0065      * @return the type of shape.
0066      */
0067     virtual QString type() const;
0068 
0069     /**
0070      * @brief zIndex
0071      * @return the zindex of the shape.
0072      */
0073     int zIndex() const;
0074 
0075     /**
0076      * @brief setZIndex
0077      * @param zindex set the shape zindex value.
0078      */
0079     void setZIndex(int zindex);
0080 
0081     /**
0082      * @brief selectable
0083      * @return whether the shape is user selectable.
0084      */
0085     bool selectable() const;
0086 
0087     /**
0088      * @brief setSelectable
0089      * @param selectable whether the shape should be user selectable.
0090      */
0091     void setSelectable(bool selectable);
0092 
0093     /**
0094      * @brief geometryProtected
0095      * @return whether the shape is protected from user changing the shape geometry.
0096      */
0097     bool geometryProtected() const;
0098 
0099     /**
0100      * @brief setGeometryProtected
0101      * @param protect whether the shape should be geometry protected from the user.
0102      */
0103     void setGeometryProtected(bool protect);
0104 
0105     /**
0106      * @brief visible
0107      * @return whether the shape is visible.
0108      */
0109     bool visible() const;
0110 
0111     /**
0112      * @brief setVisible
0113      * @param visible whether the shape should be visible.
0114      */
0115     void setVisible(bool visible);
0116 
0117     /**
0118      * @brief boundingBox the bounding box of the shape in points
0119      * @return RectF containing the bounding box.
0120      */
0121     QRectF boundingBox() const;
0122 
0123     /**
0124      * @brief position the position of the shape in points.
0125      * @return the position of the shape in points.
0126      */
0127     QPointF position() const;
0128 
0129     /**
0130      * @brief setPosition set the position of the shape.
0131      * @param point the new position in points
0132      */
0133     void setPosition(QPointF point);
0134 
0135     /**
0136      * @brief transformation the 2D transformation matrix of the shape.
0137      * @return the 2D transformation matrix.
0138      */
0139     QTransform transformation() const;
0140 
0141     /**
0142      * @brief setTransformation set the 2D transformation matrix of the shape.
0143      * @param matrix the new 2D transformation matrix.
0144      */
0145     void setTransformation(QTransform matrix);
0146 
0147     /**
0148      * @brief transformation the 2D transformation matrix of the shape including all grandparent transforms.
0149      * @return the 2D transformation matrix.
0150      */
0151     QTransform absoluteTransformation() const;
0152 
0153     /**
0154      * @brief remove delete the shape.
0155      */
0156     bool remove();
0157 
0158     /**
0159      * @brief update queue the shape update.
0160      */
0161     void update();
0162 
0163     /**
0164      * @brief updateAbsolute queue the shape update in the specified rectangle.
0165      * @param box the RectF rectangle to update.
0166      */
0167     void updateAbsolute(QRectF box);
0168 
0169     /**
0170      * @brief toSvg
0171      * convert the shape to svg, will not include style definitions.
0172      * @param prependStyles prepend the style data. Default: false
0173      * @param stripTextMode enable strip text mode. Default: true
0174      * @return the svg in a string.
0175      */
0176 
0177     QString toSvg(bool prependStyles = false, bool stripTextMode = true);
0178 
0179     /**
0180      * @brief select selects the shape.
0181      */
0182     void select();
0183 
0184     /**
0185      * @brief deselect deselects the shape.
0186      */
0187     void deselect();
0188 
0189     /**
0190      * @brief isSelected
0191      * @return whether the shape is selected.
0192      */
0193     bool isSelected();
0194 
0195     /**
0196      * @brief parentShape
0197      * @return the parent GroupShape of the current shape.
0198      */
0199     Shape* parentShape() const;
0200 
0201 private:
0202     friend class GroupShape;
0203     friend class VectorLayer;
0204 
0205     struct Private;
0206     Private *const d;
0207 
0208     KoShape *shape();
0209 };
0210 
0211 #endif // LIBKIS_SHAPE_H