1 /* This file is part of the KDE project 2 Copyright (C) 2006-2007 Thorsten Zachmann <zachmann@kde.org> 3 Copyright (C) 2006 Jan Hambrecht <jaham@gmx.net> 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Library General Public 7 License as published by the Free Software Foundation; either 8 version 2 of the License, or (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Library General Public License for more details. 14 15 You should have received a copy of the GNU Library General Public License 16 along with this library; see the file COPYING.LIB. If not, write to 17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 */ 20 21 #ifndef KOELLIPSESHAPE_H 22 #define KOELLIPSESHAPE_H 23 24 #include "KoParameterShape.h" 25 #include <SvgShape.h> 26 27 #define EllipseShapeId "EllipseShape" 28 29 /** 30 * This class adds support for arc, pie, chord, circle and ellipse 31 * shapes. The ellipse/circle radii are defined by the actual size 32 * of the ellipse shape which can be changed with the setSize 33 * method. 34 */ 35 class EllipseShape : public KoParameterShape, public SvgShape 36 { 37 public: 38 /// the possible ellipse types 39 enum EllipseType 40 { 41 Arc = 0, ///< an ellipse arc 42 Pie = 1, ///< an ellipse pie 43 Chord = 2 ///< an ellipse chord 44 }; 45 46 EllipseShape(); 47 ~EllipseShape() override; 48 49 void setSize(const QSizeF &newSize) override; 50 QPointF normalize() override; 51 52 /** 53 * Sets the type of the ellipse. 54 * @param type the new ellipse type 55 */ 56 void setType(EllipseType type); 57 58 /// Returns the actual ellipse type 59 EllipseType type() const; 60 61 /** 62 * Sets the start angle of the ellipse. 63 * @param angle the new start angle in degree 64 */ 65 void setStartAngle(qreal angle); 66 67 /// Returns the actual ellipse start angle in degree 68 qreal startAngle() const; 69 70 /** 71 * Sets the end angle of the ellipse. 72 * @param angle the new end angle in degree 73 */ 74 void setEndAngle(qreal angle); 75 76 /// Returns the actual ellipse end angle in degree 77 qreal endAngle() const; 78 79 /// reimplemented 80 QString pathShapeId() const override; 81 82 /// reimplemented from SvgShape 83 bool saveSvg(SvgSavingContext &context) override; 84 85 /// reimplemented from SvgShape 86 bool loadSvg(const KoXmlElement &element, SvgLoadingContext &context) override; 87 88 protected: 89 // reimplemented 90 void saveOdf(KoShapeSavingContext &context) const override; 91 // reimplemented 92 bool loadOdf(const KoXmlElement &element, KoShapeLoadingContext &context) override; 93 94 void moveHandleAction(int handleId, const QPointF &point, Qt::KeyboardModifiers modifiers = Qt::NoModifier) override; 95 void updatePath(const QSizeF &size) override; 96 void createPoints(int requiredPointCount); 97 98 private: 99 qreal sweepAngle() const; 100 101 void updateKindHandle(); 102 void updateAngleHandles(); 103 104 // start angle in degree 105 qreal m_startAngle; 106 // end angle in degree 107 qreal m_endAngle; 108 // angle for modifying the kind in radiant 109 qreal m_kindAngle; 110 // the center of the ellipse 111 QPointF m_center; 112 // the radii of the ellipse 113 QPointF m_radii; 114 // the actual ellipse type 115 EllipseType m_type; 116 }; 117 118 #endif /* KOELLIPSESHAPE_H */ 119 120