Krita

Shape.h
1 /*
2  * SPDX-FileCopyrightText: 2017 Wolthera van Hövell tot Westerflier <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 #ifndef LIBKIS_SHAPE_H
7 #define LIBKIS_SHAPE_H
8 
9 #include <QObject>
10 #include <KoShape.h>
11 
12 #include "kritalibkis_export.h"
13 #include "libkis.h"
14 #include <kis_types.h>
15 
16 /**
17  * @brief The Shape class
18  * The shape class is a wrapper around Krita's vector objects.
19  *
20  * Some example code to parse through interesting information in a given vector layer with shapes.
21  * @code
22 import sys
23 from krita import *
24 
25 doc = Application.activeDocument()
26 
27 root = doc.rootNode()
28 
29 for layer in root.childNodes():
30  print (str(layer.type())+" "+str(layer.name()))
31  if (str(layer.type())=="vectorlayer"):
32  for shape in layer.shapes():
33  print(shape.name())
34  print(shape.toSvg())
35  * @endcode
36  */
37 class KRITALIBKIS_EXPORT Shape : public QObject
38 {
39  Q_OBJECT
41 
42 public:
43  explicit Shape(KoShape *shape, QObject *parent = 0);
44  ~Shape();
45 
46  bool operator==(const Shape &other) const;
47  bool operator!=(const Shape &other) const;
48 
49 public Q_SLOTS:
50 
51  /**
52  * @brief name
53  * @return the name of the shape
54  */
55  QString name() const;
56 
57  /**
58  * @brief setName
59  * @param name which name the shape should have.
60  */
61  void setName(const QString &name);
62 
63  /**
64  * @brief type
65  * @return the type of shape.
66  */
67  virtual QString type() const;
68 
69  /**
70  * @brief zIndex
71  * @return the zindex of the shape.
72  */
73  int zIndex() const;
74 
75  /**
76  * @brief setZIndex
77  * @param zindex set the shape zindex value.
78  */
79  void setZIndex(int zindex);
80 
81  /**
82  * @brief selectable
83  * @return whether the shape is user selectable.
84  */
85  bool selectable() const;
86 
87  /**
88  * @brief setSelectable
89  * @param selectable whether the shape should be user selectable.
90  */
91  void setSelectable(bool selectable);
92 
93  /**
94  * @brief geometryProtected
95  * @return whether the shape is protected from user changing the shape geometry.
96  */
97  bool geometryProtected() const;
98 
99  /**
100  * @brief setGeometryProtected
101  * @param protect whether the shape should be geometry protected from the user.
102  */
103  void setGeometryProtected(bool protect);
104 
105  /**
106  * @brief visible
107  * @return whether the shape is visible.
108  */
109  bool visible() const;
110 
111  /**
112  * @brief setVisible
113  * @param visible whether the shape should be visible.
114  */
115  void setVisible(bool visible);
116 
117  /**
118  * @brief boundingBox the bounding box of the shape in points
119  * @return RectF containing the bounding box.
120  */
121  QRectF boundingBox() const;
122 
123  /**
124  * @brief position the position of the shape in points.
125  * @return the position of the shape in points.
126  */
127  QPointF position() const;
128 
129  /**
130  * @brief setPosition set the position of the shape.
131  * @param point the new position in points
132  */
133  void setPosition(QPointF point);
134 
135  /**
136  * @brief transformation the 2D transformation matrix of the shape.
137  * @return the 2D transformation matrix.
138  */
139  QTransform transformation() const;
140 
141  /**
142  * @brief setTransformation set the 2D transformation matrix of the shape.
143  * @param matrix the new 2D transformation matrix.
144  */
145  void setTransformation(QTransform matrix);
146 
147  /**
148  * @brief transformation the 2D transformation matrix of the shape including all grandparent transforms.
149  * @return the 2D transformation matrix.
150  */
151  QTransform absoluteTransformation() const;
152 
153  /**
154  * @brief remove delete the shape.
155  */
156  bool remove();
157 
158  /**
159  * @brief update queue the shape update.
160  */
161  void update();
162 
163  /**
164  * @brief updateAbsolute queue the shape update in the specified rectangle.
165  * @param box the RectF rectangle to update.
166  */
167  void updateAbsolute(QRectF box);
168 
169  /**
170  * @brief toSvg
171  * convert the shape to svg, will not include style definitions.
172  * @param prependStyles prepend the style data. Default: false
173  * @param stripTextMode enable strip text mode. Default: true
174  * @return the svg in a string.
175  */
176 
177  QString toSvg(bool prependStyles = false, bool stripTextMode = true);
178 
179  /**
180  * @brief select selects the shape.
181  */
182  void select();
183 
184  /**
185  * @brief deselect deselects the shape.
186  */
187  void deselect();
188 
189  /**
190  * @brief isSelected
191  * @return whether the shape is selected.
192  */
193  bool isSelected();
194 
195  /**
196  * @brief parentShape
197  * @return the parent GroupShape of the current shape.
198  */
199  Shape* parentShape() const;
200 
201 private:
202  friend class GroupShape;
203  friend class VectorLayer;
204 
205  struct Private;
206  Private *const d;
207 
208  KoShape *shape();
209 };
210 
211 #endif // LIBKIS_SHAPE_H
Q_SLOTSQ_SLOTS
The Shape class The shape class is a wrapper around Krita's vector objects.
Definition: Shape.h:37
The GroupShape class A group shape is a vector object with child shapes.
Definition: GroupShape.h:20
The VectorLayer class A vector layer is a special layer that stores and shows vector shapes.
Definition: VectorLayer.h:31
Q_DISABLE_COPY(Class)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Fri Sep 22 2023 04:09:51 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.