File indexing completed on 2024-06-23 04:27:04
0001 /* This file is part of the KDE project 0002 SPDX-FileCopyrightText: 2006-2008 Jan Hambrecht <jaham@gmx.net> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KOSTARSHAPE_H 0008 #define KOSTARSHAPE_H 0009 0010 #include <array> 0011 #include <KoParameterShape.h> 0012 0013 #define StarShapeId "StarShape" 0014 0015 /** 0016 * The star shape is a shape that can represent a star or 0017 * a regular polygon. There a some properties which can 0018 * be changed to control the appearance of the shape 0019 * like the number of corners, the inner/outer radius 0020 * and the corner roundness. 0021 */ 0022 class StarShape : public KoParameterShape 0023 { 0024 public: 0025 StarShape(); 0026 ~StarShape() override; 0027 0028 KoShape* cloneShape() const override; 0029 0030 /** 0031 * Sets the number of corners. 0032 * 0033 * The minimum accepted number of corners is 3. 0034 * If the star is set to be convex (like a regular polygon), 0035 * the corner count equals the number of polygon points. 0036 * For a real star it represents the number of legs the star has. 0037 * 0038 * @param cornerCount the new number of corners 0039 */ 0040 void setCornerCount(uint cornerCount); 0041 0042 /// Returns the number of corners 0043 uint cornerCount() const; 0044 0045 /** 0046 * Sets the radius of the base points. 0047 * The base radius has no meaning if the star is set convex. 0048 * @param baseRadius the new base radius 0049 */ 0050 void setBaseRadius(qreal baseRadius); 0051 0052 /// Returns the base radius 0053 qreal baseRadius() const; 0054 0055 /** 0056 * Sets the radius of the tip points. 0057 * @param tipRadius the new tip radius 0058 */ 0059 void setTipRadius(qreal tipRadius); 0060 0061 /// Returns the tip radius 0062 qreal tipRadius() const; 0063 0064 /** 0065 * Sets the roundness at the base points. 0066 * 0067 * A roundness value of zero disables the roundness. 0068 * 0069 * @param baseRoundness the new base roundness 0070 */ 0071 void setBaseRoundness(qreal baseRoundness); 0072 0073 /** 0074 * Sets the roundness at the tip points. 0075 * 0076 * A roundness value of zero disables the roundness. 0077 * 0078 * @param tipRoundness the new base roundness 0079 */ 0080 void setTipRoundness(qreal tipRoundness); 0081 0082 /** 0083 * Sets the star to be convex, looking like a polygon. 0084 * @param convex if true makes shape behave like regular polygon 0085 */ 0086 void setConvex(bool convex); 0087 0088 /// Returns if the star represents a regular polygon. 0089 bool convex() const; 0090 0091 /** 0092 * Returns the star center point in shape coordinates. 0093 * 0094 * The star center is the weight center of the star and not necessarily 0095 * coincident with the shape center point. 0096 */ 0097 QPointF starCenter() const; 0098 0099 /// reimplemented 0100 void setSize(const QSizeF &newSize) override; 0101 /// reimplemented 0102 QString pathShapeId() const override; 0103 0104 protected: 0105 StarShape(const StarShape &rhs); 0106 0107 void moveHandleAction(int handleId, const QPointF &point, Qt::KeyboardModifiers modifiers = Qt::NoModifier) override; 0108 void updatePath(const QSizeF &size) override; 0109 /// recreates the path points when the corner count or convexity changes 0110 void createPoints(int requiredPointCount); 0111 0112 private: 0113 /// Computes the star center point from the inner points 0114 QPointF computeCenter() const; 0115 0116 /// Returns the default offset angle in radian 0117 double defaultAngleRadian() const; 0118 0119 /// the handle types 0120 enum Handles { tip = 0, base = 1 }; 0121 0122 uint m_cornerCount; ///< number of corners 0123 std::array<qreal, 2> m_radius; ///< the different radii 0124 std::array<qreal, 2> m_angles; ///< the offset angles 0125 qreal m_zoomX; ///< scaling in x 0126 qreal m_zoomY; ///< scaling in y 0127 std::array<qreal, 2> m_roundness; ///< the roundness at the handles 0128 QPointF m_center; ///< the star center point 0129 bool m_convex; ///< controls if the star is convex 0130 }; 0131 0132 #endif /* KOSTARSHAPE_H */ 0133