Warning, file /office/calligra/libs/flake/KoPathPoint.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 Copyright (C) 2006 Thorsten Zachmann <zachmann@kde.org> 0003 Copyright (C) 2007 Thomas Zander <zander@kde.org> 0004 Copyright (C) 2006-2008 Jan Hambrecht <jaham@gmx.net> 0005 0006 This library is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU Library General Public 0008 License as published by the Free Software Foundation; either 0009 version 2 of the License, or (at your option) any later version. 0010 0011 This library is distributed in the hope that it will be useful, 0012 but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 Library General Public License for more details. 0015 0016 You should have received a copy of the GNU Library General Public License 0017 along with this library; see the file COPYING.LIB. If not, write to 0018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0019 * Boston, MA 02110-1301, USA. 0020 */ 0021 0022 #ifndef KOPATHPOINT_H 0023 #define KOPATHPOINT_H 0024 0025 #include "flake_export.h" 0026 0027 #include <QFlags> 0028 0029 class KoPathShape; 0030 class QPointF; 0031 class QTransform; 0032 class QRectF; 0033 class QPainter; 0034 0035 /** 0036 * @brief A KoPathPoint represents a point in a path. 0037 * 0038 * A KoPathPoint stores a point in a path. Additional to this point 0039 * 2 control points are stored. 0040 * controlPoint1 is used to describe the second point of a cubic 0041 * bezier ending at the point. controlPoint2 is used to describe the 0042 * first point of a cubic bezier curve starting at the point. 0043 */ 0044 class FLAKE_EXPORT KoPathPoint 0045 { 0046 public: 0047 /// property enum 0048 enum PointProperty { 0049 Normal = 0, ///< it has no control points 0050 StartSubpath = 1, ///< it starts a new subpath by a moveTo command 0051 StopSubpath = 2, ///< it stops a subpath (last point of subpath) 0052 CloseSubpath = 8, ///< it closes a subpath (only applicable on StartSubpath and StopSubpath) 0053 IsSmooth = 16, ///< it is smooth, both control points on a line through the point 0054 IsSymmetric = 32 ///< it is symmetric, like smooth but control points have same distance to point 0055 }; 0056 Q_DECLARE_FLAGS(PointProperties, PointProperty) 0057 0058 /// the type for identifying part of a KoPathPoint 0059 enum PointType { 0060 Node = 1, ///< the node point 0061 ControlPoint1 = 2, ///< the first control point 0062 ControlPoint2 = 4, ///< the second control point 0063 All = 7 0064 }; 0065 Q_DECLARE_FLAGS(PointTypes, PointType) 0066 0067 /// Default constructor 0068 KoPathPoint(); 0069 0070 /** 0071 * @brief Constructor 0072 * 0073 * @param path is a pointer to the path shape this point is used in 0074 * @param point the position relative to the shape origin 0075 * @param properties describing the point 0076 */ 0077 KoPathPoint(KoPathShape *path, const QPointF &point, PointProperties properties = Normal); 0078 0079 /** 0080 * @brief Copy Constructor 0081 */ 0082 KoPathPoint(const KoPathPoint &pathPoint); 0083 0084 /** 0085 * @brief Assignment operator. 0086 */ 0087 KoPathPoint& operator=(const KoPathPoint &other); 0088 0089 /// Compare operator 0090 bool operator == (const KoPathPoint &other) const; 0091 0092 /** 0093 * @brief Destructor 0094 */ 0095 ~KoPathPoint(); 0096 0097 /** 0098 * @brief return the position relative to the shape origin 0099 * 0100 * @return point 0101 */ 0102 QPointF point() const; 0103 0104 /** 0105 * @brief get the control point 1 0106 * 0107 * This points is used for controlling a curve ending at this point 0108 * 0109 * @return control point 1 of this point 0110 */ 0111 QPointF controlPoint1() const; 0112 0113 /** 0114 * @brief get the second control point 0115 * 0116 * This points is used for controlling a curve starting at this point 0117 * 0118 * @return control point 2 of this point 0119 */ 0120 QPointF controlPoint2() const; 0121 0122 /** 0123 * @brief alter the point 0124 * 0125 * @param point to set 0126 */ 0127 void setPoint(const QPointF &point); 0128 0129 /** 0130 * @brief Set the control point 1 0131 * 0132 * @param point to set 0133 */ 0134 void setControlPoint1(const QPointF &point); 0135 0136 /** 0137 * @brief Set the control point 2 0138 * 0139 * @param point to set 0140 */ 0141 void setControlPoint2(const QPointF &point); 0142 0143 /// Removes the first control point 0144 void removeControlPoint1(); 0145 0146 /// Removes the second control point 0147 void removeControlPoint2(); 0148 0149 /** 0150 * @brief Get the properties of a point 0151 * 0152 * @return properties of the point 0153 */ 0154 PointProperties properties() const; 0155 0156 /** 0157 * @brief Set the properties of a point 0158 * @param properties the new properties 0159 */ 0160 void setProperties(PointProperties properties); 0161 0162 /** 0163 * @brief Sets a single property of a point. 0164 * @param property the property to set 0165 */ 0166 void setProperty(PointProperty property); 0167 0168 /** 0169 * @brief Removes a property from the point. 0170 * @param property the property to remove 0171 */ 0172 void unsetProperty(PointProperty property); 0173 0174 /** 0175 * @brief Checks if there is a controlPoint1 0176 * 0177 * The control point is active if a control point was set by 0178 * calling setControlPoint1. However a start point of a subpath 0179 * (StartSubpath) can only have an active control 1 if the 0180 * subpath is closed (CloseSubpath on first and last point). 0181 * 0182 * @return true if control point is active, false otherwise 0183 */ 0184 bool activeControlPoint1() const; 0185 0186 /** 0187 * @brief Checks if there is a controlPoint2 0188 * 0189 * The control point is active if a control point was set by 0190 * calling setControlPoint2. However a end point of a subpath 0191 * (StopSubpath) can only have an active control point 2 if there 0192 * subpath is closed (CloseSubpath on first and last point). 0193 * 0194 * @return true if control point is active, false otherwise 0195 */ 0196 bool activeControlPoint2() const; 0197 0198 /** 0199 * @brief apply matrix on the point 0200 * 0201 * This does a matrix multiplication on all points of the point 0202 * 0203 * @param matrix which will be applied to all points 0204 */ 0205 void map(const QTransform &matrix); 0206 0207 /** 0208 * Paints the path point with the actual brush and pen 0209 * @param painter used for painting the shape point 0210 * @param handleRadius size of point handles in pixel 0211 * @param types the points which should be painted 0212 * @param active If true only the given active points are painted 0213 * If false all given points are used. 0214 */ 0215 void paint(QPainter &painter, int handleRadius, PointTypes types, bool active = true); 0216 0217 /** 0218 * @brief Sets the parent path shape. 0219 * @param parent the new parent path shape 0220 */ 0221 void setParent(KoPathShape* parent); 0222 0223 /** 0224 * @brief Get the path shape the point belongs to 0225 * @return the path shape the point belongs to 0226 */ 0227 KoPathShape *parent() const; 0228 0229 /** 0230 * @brief Get the bounding rect of the point. 0231 * 0232 * This takes into account if there are controlpoints 0233 * 0234 * @param active If true only the active points are used in calculation 0235 * of the bounding rectangle. If false all points are used. 0236 * 0237 * @return bounding rect in document coordinates 0238 */ 0239 QRectF boundingRect(bool active = true) const; 0240 0241 /** 0242 * @brief Reverses the path point. 0243 * 0244 * The control points are swapped and the point properties are adjusted. 0245 * The position dependent properties like StartSubpath and CloseSubpath 0246 * are not changed. 0247 */ 0248 void reverse(); 0249 0250 /** 0251 * Returns if this point is a smooth join of adjacent path segments. 0252 * 0253 * The smoothess is defined by the parallelness of the tangents emanating 0254 * from the knot point, i.e. the normalized vectors from the knot to the 0255 * first and second control point. 0256 * The previous and next path points are used to determine the smoothness 0257 * in case this path point has not two control points. 0258 * 0259 * @param previous the previous path point 0260 * @param next the next path point 0261 */ 0262 bool isSmooth(KoPathPoint *previous, KoPathPoint *next) const; 0263 0264 protected: 0265 friend class KoPathShapePrivate; 0266 private: 0267 class Private; 0268 Private * const d; 0269 }; 0270 0271 // /// a KoSubpath contains a path from a moveTo until a close or a new moveTo 0272 // typedef QList<KoPathPoint *> KoSubpath; 0273 // typedef QList<KoSubpath *> KoSubpathList; 0274 // /// A KoPathSegment is a pair two neighboring KoPathPoints 0275 // typedef QPair<KoPathPoint*,KoPathPoint*> KoPathSegment; 0276 // /// The position of a path point within a path shape 0277 // typedef QPair<KoSubpath*, int> KoPointPosition; 0278 0279 Q_DECLARE_OPERATORS_FOR_FLAGS(KoPathPoint::PointProperties) 0280 Q_DECLARE_OPERATORS_FOR_FLAGS(KoPathPoint::PointTypes) 0281 0282 #endif