File indexing completed on 2024-05-12 15:56:42
0001 /* This file is part of the KDE project 0002 SPDX-FileCopyrightText: 2006 Thorsten Zachmann <zachmann@kde.org> 0003 SPDX-FileCopyrightText: 2007 Thomas Zander <zander@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef KOPARAMETERSHAPE_H 0009 #define KOPARAMETERSHAPE_H 0010 0011 #include "KoPathShape.h" 0012 #include "kritaflake_export.h" 0013 0014 class KoParameterShapePrivate; 0015 class KisHandlePainterHelper; 0016 0017 /** 0018 * KoParameterShape is the base class for all parametric shapes 0019 * in flake. 0020 * Parametric shapes are those whose appearance can be completely 0021 * defined by a few numerical parameters. Rectangle, ellipse and star 0022 * are examples of parametric shapes. 0023 * In flake, these shape parameters can be manipulated visually by means 0024 * of control points. These control points can be moved with the mouse 0025 * on the canvas which changes the shapes parameter values and hence the 0026 * shapes appearance in realtime. 0027 * KoParameterShape is derived from the KoPathShape class that means 0028 * by changing the shape parameters, the underlying path is manipulated. 0029 * A parametric shape can be converted into a path shape by simply calling 0030 * the setModified method. This makes the path tool know that it can handle 0031 * the shape like a path shape, so that modifying the single path points 0032 * is possible. 0033 */ 0034 class KRITAFLAKE_EXPORT KoParameterShape : public KoPathShape 0035 { 0036 public: 0037 KoParameterShape(); 0038 ~KoParameterShape() override; 0039 0040 /** 0041 * @brief Move handle to point 0042 * 0043 * This method calls moveHandleAction. Overload moveHandleAction to get the behaviour you want. 0044 * After that updatePath and a repaint is called. 0045 * 0046 * @param handleId the id of the handle to move 0047 * @param point the point to move the handle to in document coordinates 0048 * @param modifiers the keyboard modifiers used during moving the handle 0049 */ 0050 void moveHandle(int handleId, const QPointF &point, Qt::KeyboardModifiers modifiers = Qt::NoModifier); 0051 0052 /** 0053 * @brief Get the id of the handle within the given rect 0054 * 0055 * @param rect the rect in shape coordinates 0056 * @return id of the found handle or -1 if none was found 0057 */ 0058 int handleIdAt(const QRectF &rect) const; 0059 0060 /** 0061 * @brief Get the handle position 0062 * 0063 * @param handleId the id of the handle for which to get the position in shape coordinates 0064 */ 0065 QPointF handlePosition(int handleId) const; 0066 0067 /** 0068 * @brief Paint the handles 0069 * 0070 * @param handlesHelper the helper of the handles used for painting 0071 * @sa KisHandlePainterHelper 0072 */ 0073 void paintHandles(KisHandlePainterHelper &handlesHelper); 0074 0075 /** 0076 * @brief Paint the given handles 0077 * 0078 * @param handlesHelper the helper of the handle used for painting 0079 * @param handleId of the handle which should be repainted 0080 */ 0081 void paintHandle(KisHandlePainterHelper &handlesHelper, int handleId); 0082 0083 /// reimplemented from KoShape 0084 void setSize(const QSizeF &size) override; 0085 0086 /** 0087 * @brief Check if object is a parametric shape 0088 * 0089 * It is no longer a parametric shape when the path was manipulated 0090 * 0091 * @return true if it is a parametric shape, false otherwise 0092 */ 0093 bool isParametricShape() const; 0094 0095 /** 0096 * @brief Set if the shape can be modified using parameters 0097 * 0098 * After the state is set to false it is no longer possible to work 0099 * with parameters on this shape. 0100 * 0101 * @param parametric the new state 0102 * @see isParametricShape 0103 */ 0104 void setParametricShape(bool parametric); 0105 0106 QPointF normalize() override; 0107 0108 /// return the number of handles set on the shape 0109 int handleCount() const; 0110 0111 protected: 0112 /** 0113 * Get the handle positions for manipulating the parameters. 0114 * @see setHandles, handleCount() 0115 */ 0116 QList<QPointF> handles() const; 0117 0118 /** 0119 * Set the new handle positions which are used by the user to manipulate the parameters. 0120 * @see handles(), handleCount() 0121 */ 0122 void setHandles(const QList<QPointF> &handles); 0123 0124 /// constructor 0125 KoParameterShape(const KoParameterShape &rhs); 0126 0127 /** 0128 * @brief Updates the internal state of a KoParameterShape. 0129 * 0130 * This method is called from moveHandle. 0131 * 0132 * @param handleId of the handle 0133 * @param point to move the handle to in shape coordinates 0134 * @param modifiers used during move to point 0135 */ 0136 virtual void moveHandleAction(int handleId, const QPointF & point, Qt::KeyboardModifiers modifiers = Qt::NoModifier) = 0; 0137 0138 /** 0139 * @brief Update the path of the parameter shape 0140 * 0141 * @param size of the shape 0142 */ 0143 virtual void updatePath(const QSizeF &size) = 0; 0144 0145 private: 0146 class Private; 0147 QSharedDataPointer<Private> d; 0148 }; 0149 0150 #endif /* KOPARAMETERSHAPE_H */