File indexing completed on 2024-05-12 15:59:08
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 public Q_SLOTS: 0046 0047 /** 0048 * @brief name 0049 * @return the name of the shape 0050 */ 0051 QString name() const; 0052 0053 /** 0054 * @brief setName 0055 * @param name which name the shape should have. 0056 */ 0057 void setName(const QString &name); 0058 0059 /** 0060 * @brief type 0061 * @return the type of shape. 0062 */ 0063 virtual QString type() const; 0064 0065 /** 0066 * @brief zIndex 0067 * @return the zindex of the shape. 0068 */ 0069 int zIndex() const; 0070 0071 /** 0072 * @brief setZIndex 0073 * @param zindex set the shape zindex value. 0074 */ 0075 void setZIndex(int zindex); 0076 0077 /** 0078 * @brief selectable 0079 * @return whether the shape is user selectable. 0080 */ 0081 bool selectable() const; 0082 0083 /** 0084 * @brief setSelectable 0085 * @param selectable whether the shape should be user selectable. 0086 */ 0087 void setSelectable(bool selectable); 0088 0089 /** 0090 * @brief geometryProtected 0091 * @return whether the shape is protected from user changing the shape geometry. 0092 */ 0093 bool geometryProtected() const; 0094 0095 /** 0096 * @brief setGeometryProtected 0097 * @param protect whether the shape should be geometry protected from the user. 0098 */ 0099 void setGeometryProtected(bool protect); 0100 0101 /** 0102 * @brief visible 0103 * @return whether the shape is visible. 0104 */ 0105 bool visible() const; 0106 0107 /** 0108 * @brief setVisible 0109 * @param visible whether the shape should be visible. 0110 */ 0111 void setVisible(bool visible); 0112 0113 /** 0114 * @brief boundingBox the bounding box of the shape in points 0115 * @return RectF containing the bounding box. 0116 */ 0117 QRectF boundingBox() const; 0118 0119 /** 0120 * @brief position the position of the shape in points. 0121 * @return the position of the shape in points. 0122 */ 0123 QPointF position() const; 0124 0125 /** 0126 * @brief setPosition set the position of the shape. 0127 * @param point the new position in points 0128 */ 0129 void setPosition(QPointF point); 0130 0131 /** 0132 * @brief transformation the 2D transformation matrix of the shape. 0133 * @return the 2D transformation matrix. 0134 */ 0135 QTransform transformation() const; 0136 0137 /** 0138 * @brief setTransformation set the 2D transformation matrix of the shape. 0139 * @param matrix the new 2D transformation matrix. 0140 */ 0141 void setTransformation(QTransform matrix); 0142 0143 /** 0144 * @brief remove delete the shape. 0145 */ 0146 bool remove(); 0147 0148 /** 0149 * @brief update queue the shape update. 0150 */ 0151 void update(); 0152 0153 /** 0154 * @brief updateAbsolute queue the shape update in the specified rectangle. 0155 * @param box the RectF rectangle to update. 0156 */ 0157 void updateAbsolute(QRectF box); 0158 0159 /** 0160 * @brief toSvg 0161 * convert the shape to svg, will not include style definitions. 0162 * @param prependStyles prepend the style data. Default: false 0163 * @param stripTextMode enable strip text mode. Default: true 0164 * @return the svg in a string. 0165 */ 0166 0167 QString toSvg(bool prependStyles = false, bool stripTextMode = true); 0168 0169 /** 0170 * @brief select selects the shape. 0171 */ 0172 void select(); 0173 0174 /** 0175 * @brief deselect deselects the shape. 0176 */ 0177 void deselect(); 0178 0179 /** 0180 * @brief isSelected 0181 * @return whether the shape is selected. 0182 */ 0183 bool isSelected(); 0184 0185 private: 0186 friend class GroupShape; 0187 friend class VectorLayer; 0188 0189 struct Private; 0190 Private *const d; 0191 0192 KoShape *shape(); 0193 }; 0194 0195 #endif // LIBKIS_SHAPE_H