Krita Source Code Documentation
Loading...
Searching...
No Matches
EllipseShape Class Reference

#include <EllipseShape.h>

+ Inheritance diagram for EllipseShape:

Public Types

enum  EllipseType { Arc = 0 , Pie = 1 , Chord = 2 }
 the possible ellipse types More...
 
- Public Types inherited from KoTosContainer
enum  ResizeBehavior { TextFollowsSize , FollowTextSize , IndependentSizes , TextFollowsPreferredTextRect }
 different kinds of resizing behavior to determine how to treat text overflow More...
 
- Public Types inherited from KoShape
enum  ChangeType {
  PositionChanged , RotationChanged , ScaleChanged , ShearChanged ,
  SizeChanged , GenericMatrixChange , KeepAspectRatioChange , ParentChanged ,
  Deleted , StrokeChanged , BackgroundChanged , ShadowChanged ,
  BorderChanged , ParameterChanged , ContentChanged , TextRunAroundChanged ,
  ChildChanged , ConnectionPointChanged , ClipPathChanged , ClipMaskChanged ,
  TransparencyChanged
}
 Used by shapeChanged() to select which change was made. More...
 
enum  ChildZOrderPolicy { ChildZDefault , ChildZParentChild = ChildZDefault , ChildZPassThrough }
 Used by compareShapeZIndex() to order shapes. More...
 
enum  PaintOrder { Fill , Stroke , Markers }
 
enum  RunThroughLevel { Background , Foreground }
 
enum  TextRunAroundContour { ContourBox , ContourFull , ContourOutside }
 The behavior text should do when intersecting this shape. More...
 
enum  TextRunAroundSide {
  BiggestRunAroundSide , LeftRunAroundSide , RightRunAroundSide , EnoughRunAroundSide ,
  BothRunAroundSide , NoRunAround , RunThrough
}
 The behavior text should do when intersecting this shape. More...
 

Public Member Functions

KoShapecloneShape () const override
 creates a deep copy of the shape or shape's subtree
 
 EllipseShape ()
 
qreal endAngle () const
 Returns the actual ellipse end angle in degree.
 
bool loadSvg (const QDomElement &element, SvgLoadingContext &context) override
 reimplemented from SvgShape
 
QPointF normalize () override
 Normalizes the path data.
 
QString pathShapeId () const override
 reimplemented
 
bool saveSvg (SvgSavingContext &context) override
 reimplemented from SvgShape
 
void setEndAngle (qreal angle)
 
void setSize (const QSizeF &newSize) override
 Resize the shape.
 
void setStartAngle (qreal angle)
 
void setType (EllipseType type)
 
qreal startAngle () const
 Returns the actual ellipse start angle in degree.
 
EllipseType type () const
 Returns the actual ellipse type.
 
 ~EllipseShape () override
 
- Public Member Functions inherited from KoParameterShape
int handleCount () const
 return the number of handles set on the shape
 
int handleIdAt (const QRectF &rect) const
 Get the id of the handle within the given rect.
 
QPointF handlePosition (int handleId) const
 Get the handle position.
 
bool isParametricShape () const
 Check if object is a parametric shape.
 
 KoParameterShape ()
 
void moveHandle (int handleId, const QPointF &point, Qt::KeyboardModifiers modifiers=Qt::NoModifier)
 Move handle to point.
 
QPointF normalize () override
 Normalizes the path data.
 
void paintHandle (KisHandlePainterHelper &handlesHelper, int handleId)
 Paint the given handles.
 
void paintHandles (KisHandlePainterHelper &handlesHelper)
 Paint the handles.
 
 Private ()
 
 Private (const KoParameterShape::Private &rhs)
 
void setParametricShape (bool parametric)
 Set if the shape can be modified using parameters.
 
void setSize (const QSizeF &size) override
 reimplemented from KoShape
 
 ~KoParameterShape () override
 
virtual ~Private ()=default
 
- Public Member Functions inherited from KoPathShape
bool addSubpath (KoSubpath *subpath, int subpathIndex)
 Adds a subpath at the given index to the path.
 
KoPathPointarcTo (qreal rx, qreal ry, qreal startAngle, qreal sweepAngle)
 Add an arc.
 
bool autoFillMarkers () const
 
QRectF boundingRect () const override
 reimplemented
 
bool breakAfter (const KoPathPointIndex &pointIndex)
 Breaks the path after the point index.
 
void clear ()
 Removes all subpaths and their points from the path.
 
KoShapecloneShape () const override
 creates a deep copy of the shape or shape's subtree
 
void close ()
 Closes the current subpath.
 
void closeMerge ()
 Closes the current subpath.
 
KoPathPointIndex closeSubpath (const KoPathPointIndex &pointIndex)
 Close a open subpath.
 
int combine (KoPathShape *path)
 Combines two path shapes by appending the data of the specified path.
 
KoPathPointcurveTo (const QPointF &c, const QPointF &p)
 Adds a new quadratic Bezier curve segment.
 
KoPathPointcurveTo (const QPointF &c1, const QPointF &c2, const QPointF &p)
 Adds a new cubic Bezier curve segment.
 
Qt::FillRule fillRule () const
 Returns the fill rule for the path object.
 
bool hasMarkers () const
 
bool hitTest (const QPointF &position) const override
 reimplemented
 
bool insertPoint (KoPathPoint *point, const KoPathPointIndex &pointIndex)
 Inserts a new point into the given subpath at the specified position.
 
bool isClosedSubpath (int subpathIndex) const
 Checks if a subpath is closed.
 
bool join (int subpathIndex)
 Joins the given subpath with the following one.
 
 KoPathShape ()
 constructor
 
KoPathPointlineTo (const QPointF &p)
 Adds a new line segment.
 
void loadNodeTypes (const QString &nodeTypes)
 Loads node types.
 
KoMarkermarker (KoFlake::MarkerPosition pos) const
 
bool moveSubpath (int oldSubpathIndex, int newSubpathIndex)
 Moves the position of a subpath within a path.
 
KoPathPointmoveTo (const QPointF &p)
 Starts a new Subpath.
 
QString nodeTypes () const
 Saves the node types.
 
KoPathPointIndex openSubpath (const KoPathPointIndex &pointIndex)
 Opens a closed subpath.
 
QPainterPath outline () const override
 reimplemented
 
QRectF outlineRect () const override
 reimplemented
 
void paint (QPainter &painter) const override
 reimplemented
 
virtual void paintPoints (KisHandlePainterHelper &handlesHelper)
 
KoPathPointIndex pathPointIndex (const KoPathPoint *point) const
 Returns the path point index of a given path point.
 
QPainterPath pathStroke (const QPen &pen) const
 
KoPathPointpointByIndex (const KoPathPointIndex &pointIndex) const
 Returns the path point specified by a path point index.
 
int pointCount () const
 Returns the number of points in the path.
 
QList< KoPathPoint * > pointsAt (const QRectF &rect, const bool useControlPoints=false) const
 Returns the path points within the given rectangle.
 
void recommendPointSelectionChange (const QList< KoPathPointIndex > &newSelection)
 
KoPathPointremovePoint (const KoPathPointIndex &pointIndex)
 Removes a point from the path.
 
KoSubpathremoveSubpath (int subpathIndex)
 Removes subpath from the path.
 
bool reverseSubpath (int subpathIndex)
 Reverse subpath.
 
KoPathSegment segmentByIndex (const KoPathPointIndex &pointIndex) const
 Returns the segment specified by a path point index.
 
QList< KoPathSegmentsegmentsAt (const QRectF &rect) const
 Returns the list of path segments within the given rectangle.
 
bool separate (QList< KoPathShape * > &separatedPaths)
 Creates separate path shapes, one for each existing subpath.
 
void setAutoFillMarkers (bool value)
 
void setFillRule (Qt::FillRule fillRule)
 Sets the fill rule to be used for painting the background.
 
void setMarker (KoMarker *marker, KoFlake::MarkerPosition pos)
 
void setSize (const QSizeF &size) override
 
QSizeF size () const override
 reimplemented
 
int subpathCount () const
 Returns the number of subpaths in the path.
 
int subpathPointCount (int subpathIndex) const
 Returns the number of points in a subpath.
 
QString toString (const QTransform &matrix=QTransform()) const
 Returns a odf/svg string representation of the path data with the given matrix applied.
 
 ~KoPathShape () override
 
- Public Member Functions inherited from KoTosContainer
KoShapecreateTextShape (KoDocumentResourceManager *documentResources=0)
 
 KoTosContainer ()
 
virtual bool loadText (const QDomElement &element)
 
void paintComponent (QPainter &painter) const override
 Paint the component Implement this method to allow the shape to paint itself, just like the KoShape::paint() method does.
 
ResizeBehavior resizeBehavior () const
 
void setPlainText (const QString &text)
 
void setResizeBehavior (ResizeBehavior resizeBehavior)
 
void setRunThrough (short int runThrough) override
 
void setTextAlignment (Qt::Alignment alignment)
 
Qt::Alignment textAlignment () const
 
 ~KoTosContainer () override
 
- Public Member Functions inherited from KoShapeContainer
void addShape (KoShape *shape)
 
bool inheritsTransform (const KoShape *shape) const
 
bool isClipped (const KoShape *child) const
 
 KoShapeContainer (KoShapeContainerModel *model=0)
 
KoShapeContainerModelmodel () const
 
void paint (QPainter &painter) const override
 reimplemented
 
 Private (const Private &rhs, KoShapeContainer *q)
 
 Private (KoShapeContainer *q)
 
void removeShape (KoShape *shape)
 
void setClipped (const KoShape *child, bool clipping)
 
void setInheritsTransform (const KoShape *shape, bool inherit)
 
int shapeCount () const
 
ShapeInterfaceshapeInterface ()
 
QList< KoShape * > shapes () const
 
virtual void update () const
 
void update () const override
 reimplemented
 
 ~KoShapeContainer () override
 
- Public Member Functions inherited from KoShape
QRectF absoluteOutlineRect () const
 
QPointF absolutePosition (KoFlake::AnchorPosition anchor=KoFlake::Center) const
 
QTransform absoluteTransformation () const
 
bool addDependee (KoShape *shape)
 
QString additionalAttribute (const QString &name) const
 
void addShapeChangeListener (ShapeChangeListener *listener)
 
KoShapeAnchoranchor () const
 
void applyAbsoluteTransformation (const QTransform &matrix)
 
void applyTransformation (const QTransform &matrix)
 
virtual QSharedPointer< KoShapeBackgroundbackground () const
 
virtual ChildZOrderPolicy childZOrderPolicy ()
 
KoClipMaskclipMask () const
 Returns the currently set clip mask or 0 if there is no clip mask set.
 
KoClipPathclipPath () const
 Returns the currently set clip path or 0 if there is no clip path set.
 
KoShapecloneShapeAndBakeAbsoluteTransform () const
 creates a deep copy of the shape/shapes tree and bakes the absolute transform of this into the resulting shape.
 
void copySettings (const KoShape *shape)
 
QList< KoShape * > dependees () const
 Returns list of shapes depending on this shape.
 
QPointF documentToShape (const QPointF &point) const
 Transforms point from document coordinates to shape coordinates.
 
QRectF documentToShape (const QRectF &rect) const
 Transform rect from document coordinates to shape coordinates.
 
KoFilterEffectStackfilterEffectStack () const
 
bool hasAdditionalAttribute (const QString &name) const
 
bool hasCommonParent (const KoShape *shape) const
 
bool hasDependee (KoShape *shape) const
 Returns if the given shape is dependent on this shape.
 
virtual bool hasTransparency () const
 
QString hyperLink () const
 
bool inheritBackground () const
 inheritBackground shows if the shape inherits background from its parent
 
bool inheritPaintOrder () const
 inheritPaintOrder
 
bool inheritsTransformFromAny (const QList< KoShape * > ancestorsInQuestion) const
 inheritsTransformFromAny checks if the shape inherits transformation from any of the shapes listed in ancestorsInQuestion. The inheritance is checked in recursive way.
 
bool inheritStroke () const
 inheritStroke shows if the shape inherits the stroke from its parent
 
bool isContentProtected () const
 
bool isGeometryProtected () const
 
bool isPrintable () const
 
bool isSelectable () const
 
virtual bool isShapeEditable (bool recursive=true) const
 checks recursively if the shape or one of its parents is not visible or locked
 
bool isVisible (bool recursive=true) const
 
bool keepAspectRatio () const
 
 KoShape ()
 Constructor.
 
qreal minimumHeight () const
 
QString name () const
 
void notifyChanged ()
 
virtual void paintMarkers (QPainter &painter) const
 paintStroke paints the shape's markers
 
virtual QVector< PaintOrderpaintOrder () const
 paintOrder
 
virtual void paintStroke (QPainter &painter) const
 paintStroke paints the shape's stroked outline
 
KoShapeContainerparent () const
 
QPointF position () const
 Get the position of the shape in pt.
 
void removeAdditionalAttribute (const QString &name)
 
void removeAdditionalStyleAttribute (const char *name)
 
void removeDependee (KoShape *shape)
 
void removeShapeChangeListener (ShapeChangeListener *listener)
 
void rotate (qreal angle)
 Rotate the shape (relative)
 
qreal rotation () const
 
int runThrough () const
 
void scale (qreal sx, qreal sy)
 Scale the shape using the zero-point which is the top-left corner.
 
void setAbsolutePosition (const QPointF &newPosition, KoFlake::AnchorPosition anchor=KoFlake::Center)
 
void setAdditionalAttribute (const QString &name, const QString &value)
 
void setAdditionalStyleAttribute (const char *name, const QString &value)
 
void setAnchor (KoShapeAnchor *anchor)
 
virtual void setBackground (QSharedPointer< KoShapeBackground > background)
 
void setClipMask (KoClipMask *clipMask)
 Sets a new clip mask, removing the old one. The mask is owned by the shape.
 
void setClipPath (KoClipPath *clipPath)
 Sets a new clip path, removing the old one.
 
void setContentProtected (bool protect)
 
void setFilterEffectStack (KoFilterEffectStack *filterEffectStack)
 Sets the new filter effect stack, removing the old one.
 
void setGeometryProtected (bool on)
 
void setHyperLink (const QString &hyperLink)
 
void setInheritBackground (bool value)
 setInheritBackground marks a shape as inheriting the background from the parent shape. NOTE: The currently selected background is destroyed.
 
void setInheritPaintOrder (bool value)
 setInheritPaintOrder set inherit paint order.
 
void setInheritStroke (bool value)
 setInheritStroke marks a shape as inheriting the stroke from the parent shape. NOTE: The currently selected stroke is destroyed.
 
void setKeepAspectRatio (bool keepAspect)
 
void setMinimumHeight (qreal height)
 
void setName (const QString &name)
 
virtual void setPaintOrder (PaintOrder first, PaintOrder second)
 setPaintOrder set the paint order. As there's only three entries in any given paintorder, you only need to have the first and second entry to set it.
 
void setParent (KoShapeContainer *parent)
 
virtual void setPosition (const QPointF &position)
 Set the position of the shape in pt.
 
void setPrintable (bool on)
 
virtual void setResolution (qreal xRes, qreal yRes)
 
void setSelectable (bool selectable)
 
void setShadow (KoShapeShadow *shadow)
 Sets the new shadow, removing the old one.
 
void setShapeId (const QString &id)
 
virtual void setStroke (KoShapeStrokeModelSP stroke)
 
void setTextRunAroundContour (TextRunAroundContour contour)
 
void setTextRunAroundDistanceBottom (qreal distance)
 
void setTextRunAroundDistanceLeft (qreal distance)
 
void setTextRunAroundDistanceRight (qreal distance)
 
void setTextRunAroundDistanceTop (qreal distance)
 
void setTextRunAroundSide (TextRunAroundSide side, RunThroughLevel runThrough=Background)
 
void setTextRunAroundThreshold (qreal threshold)
 
void setToolDelegates (const QSet< KoShape * > &delegates)
 
void setTransformation (const QTransform &matrix)
 
void setTransparency (qreal transparency)
 
void setUserData (KoShapeUserData *userData)
 
void setVisible (bool on)
 
void setZIndex (qint16 zIndex)
 
KoShapeShadowshadow () const
 Returns the currently set shadow or 0 if there is no shadow set.
 
virtual QPainterPath shadowOutline () const
 
QString shapeId () const
 
QPointF shapeToDocument (const QPointF &point) const
 Transforms point from shape coordinates to document coordinates.
 
QRectF shapeToDocument (const QRectF &rect) const
 Transforms rect from shape coordinates to document coordinates.
 
void shear (qreal sx, qreal sy)
 Shear the shape The shape will be sheared using the zero-point which is the top-left corner.
 
virtual KoSnapData snapData () const
 Returns additional snap data the shape wants to have snapping to.
 
virtual KoShapeStrokeModelSP stroke () const
 
KoInsets strokeInsets () const
 
TextRunAroundContour textRunAroundContour () const
 
qreal textRunAroundDistanceBottom () const
 
qreal textRunAroundDistanceLeft () const
 
qreal textRunAroundDistanceRight () const
 
qreal textRunAroundDistanceTop () const
 
TextRunAroundSide textRunAroundSide () const
 
qreal textRunAroundThreshold () const
 
QSet< KoShape * > toolDelegates () const
 
QTransform transformation () const
 Returns the shapes local transformation matrix.
 
qreal transparency (bool recursive=false) const
 
virtual void updateAbsolute (const QRectF &rect) const
 
KoShapeUserDatauserData () const
 
virtual void waitUntilReady (bool asynchronous=true) const
 
qint16 zIndex () const
 
virtual ~KoShape ()
 Destructor.
 
- Public Member Functions inherited from SvgShape
void saveMetadata (SvgSavingContext &context)
 
virtual ~SvgShape ()
 

Protected Member Functions

void createPoints (int requiredPointCount)
 
void moveHandleAction (int handleId, const QPointF &point, Qt::KeyboardModifiers modifiers=Qt::NoModifier) override
 Updates the internal state of a KoParameterShape.
 
void updatePath (const QSizeF &size) override
 Update the path of the parameter shape.
 
- Protected Member Functions inherited from KoParameterShape
QList< QPointF > handles () const
 
 KoParameterShape (const KoParameterShape &rhs)
 constructor
 
void setHandles (const QList< QPointF > &handles)
 
- Protected Member Functions inherited from KoPathShape
int arcToCurve (qreal rx, qreal ry, qreal startAngle, qreal sweepAngle, const QPointF &offset, QPointF *curvePoints) const
 Add an arc.
 
 KoPathShape (const KoPathShape &rhs)
 
void map (const QTransform &matrix)
 
void notifyPointsChanged ()
 
QTransform resizeMatrix (const QSizeF &newSize) const
 
KoSubpathListsubpaths ()
 XXX: refactor this using setter?
 
const KoSubpathListsubpaths () const
 
- Protected Member Functions inherited from KoTosContainer
 KoTosContainer (const KoTosContainer &rhs)
 
QRectF preferredTextRect () const
 
void setPreferredTextRect (const QRectF &rect)
 
void shapeChanged (ChangeType type, KoShape *shape=0) override
 
KoShapetextShape () const
 
- Protected Member Functions inherited from KoShapeContainer
 KoShapeContainer (const KoShapeContainer &rhs)
 
void setModel (KoShapeContainerModel *model)
 
void setModelInit (KoShapeContainerModel *model)
 
virtual void shapeCountChanged ()
 
- Protected Member Functions inherited from KoShape
 KoShape (const KoShape &rhs)
 
QList< ShapeChangeListener * > listeners () const
 
void setSizeImpl (const QSizeF &size) const
 
void shapeChangedPriv (KoShape::ChangeType type)
 
QTransform transform () const
 return the current matrix that contains the rotation/scale/position of this shape
 

Private Member Functions

 EllipseShape (const EllipseShape &rhs)
 
qreal sweepAngle () const
 
void updateAngleHandles ()
 
void updateKindHandle ()
 

Private Attributes

QPointF m_center
 
qreal m_endAngle
 
qreal m_kindAngle
 
QPointF m_radii
 
qreal m_startAngle
 
EllipseType m_type
 

Additional Inherited Members

- Static Public Member Functions inherited from KoPathShape
static KoPathShapecreateShapeFromPainterPath (const QPainterPath &path)
 Creates path shape from given QPainterPath.
 
- Static Public Member Functions inherited from KoShape
static QRectF absoluteOutlineRect (const QList< KoShape * > &shapes)
 
static QRectF boundingRect (const QList< KoShape * > &shapes)
 
static bool compareShapeZIndex (KoShape *s1, KoShape *s2)
 
static KisHandlePainterHelper createHandlePainterHelperDocument (QPainter *painter, KoShape *shape, qreal handleRadius, int decorationThickness)
 
static KisHandlePainterHelper createHandlePainterHelperView (QPainter *painter, KoShape *shape, const KoViewConverter &converter, qreal handleRadius=0.0, int decorationThickness=1)
 
static QVector< PaintOrderdefaultPaintOrder ()
 default paint order as per SVG specification
 
static QList< KoShape * > linearizeSubtree (const QList< KoShape * > &shapes)
 
static QList< KoShape * > linearizeSubtreeSorted (const QList< KoShape * > &shapes)
 
- Public Attributes inherited from KoParameterShape
QList< QPointF > handles
 the handles that the user can grab and change
 
bool parametric
 
- Public Attributes inherited from KoShapeContainer
KoShapeContainerModelmodel
 
KoShapeContainer::ShapeInterface shapeInterface
 
- Static Public Attributes inherited from KoShape
static const qint16 maxZIndex = std::numeric_limits<qint16>::max()
 
static const qint16 minZIndex = std::numeric_limits<qint16>::min()
 

Detailed Description

This class adds support for arc, pie, chord, circle and ellipse shapes. The ellipse/circle radii are defined by the actual size of the ellipse shape which can be changed with the setSize method.

Definition at line 22 of file EllipseShape.h.

Member Enumeration Documentation

◆ EllipseType

the possible ellipse types

Enumerator
Arc 

an ellipse arc

Pie 

an ellipse pie

Chord 

an ellipse chord

Definition at line 26 of file EllipseShape.h.

26 {
27 Arc = 0,
28 Pie = 1,
29 Chord = 2
30 };
@ Pie
an ellipse pie
@ Chord
an ellipse chord
@ Arc
an ellipse arc

Constructor & Destructor Documentation

◆ EllipseShape() [1/2]

EllipseShape::EllipseShape ( )

Definition at line 26 of file EllipseShape.cpp.

27 : m_startAngle(0)
28 , m_endAngle(0)
30 , m_type(Arc)
31{
33 handles.push_back(QPointF(100, 50));
34 handles.push_back(QPointF(100, 50));
35 handles.push_back(QPointF(0, 50));
37 QSizeF size(100, 100);
38 m_radii = QPointF(size.width() / 2.0, size.height() / 2.0);
39 m_center = QPointF(m_radii.x(), m_radii.y());
41}
void updatePath(const QSizeF &size) override
Update the path of the parameter shape.
qreal m_startAngle
QPointF m_radii
EllipseType m_type
QPointF m_center
qreal m_kindAngle
QList< QPointF > handles
the handles that the user can grab and change
void setHandles(const QList< QPointF > &handles)
QSizeF size() const override
reimplemented
#define M_PI
Definition kis_global.h:111

References KoParameterShape::handles, m_center, m_radii, KoParameterShape::setHandles(), KoPathShape::size(), and updatePath().

◆ ~EllipseShape()

EllipseShape::~EllipseShape ( )
override

Definition at line 54 of file EllipseShape.cpp.

55{
56}

◆ EllipseShape() [2/2]

EllipseShape::EllipseShape ( const EllipseShape & rhs)
private

Definition at line 43 of file EllipseShape.cpp.

Member Function Documentation

◆ cloneShape()

KoShape * EllipseShape::cloneShape ( ) const
overridevirtual

creates a deep copy of the shape or shape's subtree

Returns
a cloned shape

Reimplemented from KoShape.

Definition at line 58 of file EllipseShape.cpp.

59{
60 return new EllipseShape(*this);
61}

References EllipseShape().

◆ createPoints()

void EllipseShape::createPoints ( int requiredPointCount)
protected

Definition at line 204 of file EllipseShape.cpp.

205{
206 if (subpaths().count() != 1) {
207 clear();
208 subpaths().append(new KoSubpath());
209 }
210 int currentPointCount = subpaths()[0]->count();
211 if (currentPointCount > requiredPointCount) {
212 for (int i = 0; i < currentPointCount - requiredPointCount; ++i) {
213 delete subpaths()[0]->front();
214 subpaths()[0]->pop_front();
215 }
216 } else if (requiredPointCount > currentPointCount) {
217 for (int i = 0; i < requiredPointCount - currentPointCount; ++i) {
218 subpaths()[0]->append(new KoPathPoint(this, QPointF()));
219 }
220 }
221
223}
QList< KoPathPoint * > KoSubpath
a KoSubpath contains a path from a moveTo until a close or a new moveTo
Definition KoPathShape.h:31
A KoPathPoint represents a point in a path.
const KoSubpathList & subpaths() const
void notifyPointsChanged()
void clear()
Removes all subpaths and their points from the path.

References KoPathShape::clear(), KoPathShape::notifyPointsChanged(), and KoPathShape::subpaths().

◆ endAngle()

qreal EllipseShape::endAngle ( ) const

Returns the actual ellipse end angle in degree.

Definition at line 310 of file EllipseShape.cpp.

311{
312 return m_endAngle;
313}

References m_endAngle.

◆ loadSvg()

bool EllipseShape::loadSvg ( const QDomElement & element,
SvgLoadingContext & context )
overridevirtual

reimplemented from SvgShape

Reimplemented from SvgShape.

Definition at line 383 of file EllipseShape.cpp.

384{
385 qreal rx = 0, ry = 0;
386 qreal cx = 0;
387 qreal cy = 0;
388 qreal start = 0;
389 qreal end = 0;
391
392 const QString extendedNamespace =
393 element.attribute("sodipodi:type") == "arc" ? "sodipodi" :
394 element.attribute("krita:type") == "arc" ? "krita" : "";
395
396 if (element.tagName() == "ellipse") {
397 rx = SvgUtil::parseUnitX(context.currentGC(), context.resolvedProperties(), element.attribute("rx"));
398 ry = SvgUtil::parseUnitY(context.currentGC(), context.resolvedProperties(), element.attribute("ry"));
399 cx = SvgUtil::parseUnitX(context.currentGC(), context.resolvedProperties(), element.attribute("cx", "0"));
400 cy = SvgUtil::parseUnitY(context.currentGC(), context.resolvedProperties(), element.attribute("cy", "0"));
401 } else if (element.tagName() == "circle") {
402 rx = ry = SvgUtil::parseUnitXY(context.currentGC(), context.resolvedProperties(), element.attribute("r"));
403 cx = SvgUtil::parseUnitX(context.currentGC(), context.resolvedProperties(), element.attribute("cx", "0"));
404 cy = SvgUtil::parseUnitY(context.currentGC(), context.resolvedProperties(), element.attribute("cy", "0"));
405
406 } else if (element.tagName() == "path" && !extendedNamespace.isEmpty()) {
407 rx = SvgUtil::parseUnitX(context.currentGC(), context.resolvedProperties(), element.attribute(extendedNamespace + ":rx"));
408 ry = SvgUtil::parseUnitY(context.currentGC(), context.resolvedProperties(), element.attribute(extendedNamespace + ":ry"));
409 cx = SvgUtil::parseUnitX(context.currentGC(), context.resolvedProperties(), element.attribute(extendedNamespace + ":cx", "0"));
410 cy = SvgUtil::parseUnitY(context.currentGC(), context.resolvedProperties(), element.attribute(extendedNamespace + ":cy", "0"));
411 start = 2 * M_PI - SvgUtil::parseNumber(element.attribute(extendedNamespace + ":end"));
412 end = 2 * M_PI - SvgUtil::parseNumber(element.attribute(extendedNamespace + ":start"));
413
414 const QString kritaArcType =
415 element.attribute("sodipodi:arc-type", element.attribute("krita:arcType"));
416
417 if (kritaArcType.isEmpty()) {
418 if (element.attribute("sodipodi:open", "false") == "false") {
419 type = Pie;
420 }
421 } else if (kritaArcType == "pie") {
422 type = Pie;
423 } else if (kritaArcType == "chord") {
424 type = Chord;
425 }
426 } else {
427 return false;
428 }
429
430 setSize(QSizeF(2 * rx, 2 * ry));
431 setPosition(QPointF(cx - rx, cy - ry));
432 if (rx == 0.0 || ry == 0.0) {
433 setVisible(false);
434 }
435
436 if (start != 0 || start != end) {
439 setType(type);
440 }
441
442 return true;
443}
void setType(EllipseType type)
void setStartAngle(qreal angle)
void setEndAngle(qreal angle)
EllipseType type() const
Returns the actual ellipse type.
void setSize(const QSizeF &newSize) override
Resize the shape.
EllipseType
the possible ellipse types
virtual void setPosition(const QPointF &position)
Set the position of the shape in pt.
Definition KoShape.cpp:295
void setVisible(bool on)
Definition KoShape.cpp:972
SvgGraphicsContext * currentGC() const
Returns the current graphics context.
KoSvgTextProperties resolvedProperties() const
These are the text properties, completely resolved, ensuring that everything is inherited and the siz...
static qreal parseUnitX(SvgGraphicsContext *gc, const KoSvgTextProperties &resolved, const QString &unit)
parses a length attribute in x-direction
Definition SvgUtil.cpp:304
static const char * parseNumber(const char *ptr, qreal &number)
parses the number into parameter number
Definition SvgUtil.cpp:378
static qreal parseUnitXY(SvgGraphicsContext *gc, const KoSvgTextProperties &resolved, const QString &unit)
parses a length attribute in xy-direction
Definition SvgUtil.cpp:322
static qreal parseUnitY(SvgGraphicsContext *gc, const KoSvgTextProperties &resolved, const QString &unit)
parses a length attribute in y-direction
Definition SvgUtil.cpp:313
T kisRadiansToDegrees(T radians)
Definition kis_global.h:181

References Arc, Chord, SvgLoadingContext::currentGC(), kisRadiansToDegrees(), M_PI, SvgUtil::parseNumber(), SvgUtil::parseUnitX(), SvgUtil::parseUnitXY(), SvgUtil::parseUnitY(), Pie, SvgLoadingContext::resolvedProperties(), setEndAngle(), KoShape::setPosition(), setSize(), setStartAngle(), setType(), KoShape::setVisible(), and type().

◆ moveHandleAction()

void EllipseShape::moveHandleAction ( int handleId,
const QPointF & point,
Qt::KeyboardModifiers modifiers = Qt::NoModifier )
overrideprotectedvirtual

Updates the internal state of a KoParameterShape.

This method is called from moveHandle.

Parameters
handleIdof the handle
pointto move the handle to in shape coordinates
modifiersused during move to point

Implements KoParameterShape.

Definition at line 80 of file EllipseShape.cpp.

81{
82 Q_UNUSED(modifiers);
83 QPointF p(point);
84
85 QPointF diff(m_center - point);
86 diff.setX(-diff.x());
87 qreal angle = 0;
88 if (diff.x() == 0) {
89 angle = (diff.y() < 0 ? 270 : 90) * M_PI / 180.0;
90 } else {
91 diff.setY(diff.y() * m_radii.x() / m_radii.y());
92 angle = atan(diff.y() / diff.x());
93 if (angle < 0) {
94 angle += M_PI;
95 }
96
97 if (diff.y() < 0) {
98 angle += M_PI;
99 }
100 }
101
103 switch (handleId) {
104 case 0:
105 p = QPointF(m_center + QPointF(cos(angle) * m_radii.x(), -sin(angle) * m_radii.y()));
107 handles[handleId] = p;
108 break;
109 case 1:
110 p = QPointF(m_center + QPointF(cos(angle) * m_radii.x(), -sin(angle) * m_radii.y()));
112 handles[handleId] = p;
113 break;
114 case 2: {
115 QList<QPointF> kindHandlePositions;
116 kindHandlePositions.push_back(QPointF(m_center + QPointF(cos(m_kindAngle) * m_radii.x(), -sin(m_kindAngle) * m_radii.y())));
117 kindHandlePositions.push_back(m_center);
118 kindHandlePositions.push_back((handles[0] + handles[1]) / 2.0);
119
120 QPointF diff = m_center * 2.0;
121 int handlePos = 0;
122 for (int i = 0; i < kindHandlePositions.size(); ++i) {
123 QPointF pointDiff(p - kindHandlePositions[i]);
124 if (i == 0 || qAbs(pointDiff.x()) + qAbs(pointDiff.y()) < qAbs(diff.x()) + qAbs(diff.y())) {
125 diff = pointDiff;
126 handlePos = i;
127 }
128 }
129 handles[handleId] = kindHandlePositions[handlePos];
130 m_type = EllipseType(handlePos);
131 }
132 break;
133 }
135
136 if (handleId != 2) {
138 }
139}
const Params2D p
void updateKindHandle()

References KoParameterShape::handles, kisRadiansToDegrees(), m_center, m_endAngle, m_kindAngle, M_PI, m_radii, m_startAngle, m_type, p, KoParameterShape::setHandles(), and updateKindHandle().

◆ normalize()

QPointF EllipseShape::normalize ( )
overridevirtual

Normalizes the path data.

The path points are transformed so that the top-left corner of the bounding rect is at (0,0). This should be called after adding points to the path or changing positions of path points.

Returns
the offset by which the points are moved in shape coordinates.

Reimplemented from KoPathShape.

Definition at line 71 of file EllipseShape.cpp.

72{
73 QPointF offset(KoParameterShape::normalize());
74 QTransform matrix;
75 matrix.translate(-offset.x(), -offset.y());
76 m_center = matrix.map(m_center);
77 return offset;
78}
QPointF normalize() override
Normalizes the path data.

References m_center, and KoParameterShape::normalize().

◆ pathShapeId()

QString EllipseShape::pathShapeId ( ) const
overridevirtual

reimplemented

Reimplemented from KoPathShape.

Definition at line 315 of file EllipseShape.cpp.

316{
317 return EllipseShapeId;
318}
#define EllipseShapeId

References EllipseShapeId.

◆ saveSvg()

bool EllipseShape::saveSvg ( SvgSavingContext & context)
overridevirtual

reimplemented from SvgShape

Reimplemented from SvgShape.

Definition at line 320 of file EllipseShape.cpp.

321{
322 // let basic path saiving code handle our saving
323 if (!isParametricShape()) return false;
324
325 if (type() == EllipseShape::Arc && startAngle() == endAngle()) {
326 const QSizeF size = this->size();
327 const bool isCircle = size.width() == size.height();
328 context.shapeWriter().startElement(isCircle ? "circle" : "ellipse");
329 context.shapeWriter().addAttribute("id", context.getID(this));
331 SvgStyleWriter::saveMetadata(this, context);
332
333 if (isCircle) {
334 context.shapeWriter().addAttribute("r", 0.5 * size.width());
335 } else {
336 context.shapeWriter().addAttribute("rx", 0.5 * size.width());
337 context.shapeWriter().addAttribute("ry", 0.5 * size.height());
338 }
339 context.shapeWriter().addAttribute("cx", 0.5 * size.width());
340 context.shapeWriter().addAttribute("cy", 0.5 * size.height());
341
342 SvgStyleWriter::saveSvgStyle(this, context);
343
344 context.shapeWriter().endElement();
345 } else {
346 context.shapeWriter().startElement("path");
347 context.shapeWriter().addAttribute("id", context.getID(this));
349
350 context.shapeWriter().addAttribute("sodipodi:type", "arc");
351
352 context.shapeWriter().addAttribute("sodipodi:rx", m_radii.x());
353 context.shapeWriter().addAttribute("sodipodi:ry", m_radii.y());
354
355 context.shapeWriter().addAttribute("sodipodi:cx", m_center.x());
356 context.shapeWriter().addAttribute("sodipodi:cy", m_center.y());
357
358 context.shapeWriter().addAttribute("sodipodi:start", 2 * M_PI - kisDegreesToRadians(endAngle()));
359 context.shapeWriter().addAttribute("sodipodi:end", 2 * M_PI - kisDegreesToRadians(startAngle()));
360
361 switch (type()) {
362 case Pie:
363 // noop
364 break;
365 case Chord:
366 context.shapeWriter().addAttribute("sodipodi:arc-type", "chord");
367 break;
368 case Arc:
369 context.shapeWriter().addAttribute("sodipodi:open", "true");
370 break;
371 }
372
373 context.shapeWriter().addAttribute("d", this->toString(context.userSpaceTransform()));
374
375 SvgStyleWriter::saveSvgStyle(this, context);
376
377 context.shapeWriter().endElement();
378 }
379
380 return true;
381}
qreal startAngle() const
Returns the actual ellipse start angle in degree.
qreal endAngle() const
Returns the actual ellipse end angle in degree.
bool isParametricShape() const
Check if object is a parametric shape.
QString toString(const QTransform &matrix=QTransform()) const
Returns a odf/svg string representation of the path data with the given matrix applied.
QTransform transformation() const
Returns the shapes local transformation matrix.
Definition KoShape.cpp:424
QTransform userSpaceTransform() const
Returns the transformation used to transform into user space.
QScopedPointer< KoXmlWriter > shapeWriter
QString getID(const KoShape *obj)
Returns the unique id for the given shape.
static void saveSvgStyle(KoShape *shape, SvgSavingContext &context)
Saves the style of the specified shape.
static void saveMetadata(const KoShape *shape, SvgSavingContext &context)
static void writeTransformAttributeLazy(const QString &name, const QTransform &transform, KoXmlWriter &shapeWriter)
Writes a transform as an attribute name iff the transform is not empty.
Definition SvgUtil.cpp:124
T kisDegreesToRadians(T degrees)
Definition kis_global.h:176

References Arc, Chord, endAngle(), SvgSavingContext::getID(), KoParameterShape::isParametricShape(), kisDegreesToRadians(), m_center, M_PI, m_radii, Pie, SvgStyleWriter::saveMetadata(), SvgStyleWriter::saveSvgStyle(), SvgSavingContext::shapeWriter, KoPathShape::size(), startAngle(), KoPathShape::toString(), KoShape::transformation(), type(), SvgSavingContext::userSpaceTransform(), and SvgUtil::writeTransformAttributeLazy().

◆ setEndAngle()

void EllipseShape::setEndAngle ( qreal angle)

Sets the end angle of the ellipse.

Parameters
anglethe new end angle in degree

Definition at line 302 of file EllipseShape.cpp.

303{
304 m_endAngle = angle;
307 updatePath(size());
308}
void updateAngleHandles()

References m_endAngle, KoPathShape::size(), updateAngleHandles(), updateKindHandle(), and updatePath().

◆ setSize()

void EllipseShape::setSize ( const QSizeF & size)
overridevirtual

Resize the shape.

Parameters
sizethe new size of the shape. This is different from scaling as scaling is a so called secondary operation which is comparable to zooming in instead of changing the size of the basic shape. Easiest example of this difference is that using this method will not distort the size of pattern-fills and strokes.

Reimplemented from KoShape.

Definition at line 63 of file EllipseShape.cpp.

64{
65 QTransform matrix(resizeMatrix(newSize));
66 m_center = matrix.map(m_center);
67 m_radii = matrix.map(m_radii);
69}
void setSize(const QSizeF &size) override
reimplemented from KoShape
QTransform resizeMatrix(const QSizeF &newSize) const

References m_center, m_radii, KoPathShape::resizeMatrix(), and KoParameterShape::setSize().

◆ setStartAngle()

void EllipseShape::setStartAngle ( qreal angle)

Sets the start angle of the ellipse.

Parameters
anglethe new start angle in degree

Definition at line 289 of file EllipseShape.cpp.

290{
291 m_startAngle = angle;
294 updatePath(size());
295}

References m_startAngle, KoPathShape::size(), updateAngleHandles(), updateKindHandle(), and updatePath().

◆ setType()

void EllipseShape::setType ( EllipseType type)

Sets the type of the ellipse.

Parameters
typethe new ellipse type

Definition at line 277 of file EllipseShape.cpp.

278{
279 m_type = type;
281 updatePath(size());
282}

References m_type, KoPathShape::size(), type(), updateKindHandle(), and updatePath().

◆ startAngle()

qreal EllipseShape::startAngle ( ) const

Returns the actual ellipse start angle in degree.

Definition at line 297 of file EllipseShape.cpp.

298{
299 return m_startAngle;
300}

References m_startAngle.

◆ sweepAngle()

qreal EllipseShape::sweepAngle ( ) const
private

Definition at line 259 of file EllipseShape.cpp.

260{
263
264 qreal sAngle = a2 - a1;
265
266 if (a1 > a2) {
267 sAngle = 2 * M_PI + sAngle;
268 }
269
270 if (qAbs(a1 - a2) < 0.05 / M_PI) {
271 sAngle = 2 * M_PI;
272 }
273
274 return kisRadiansToDegrees(sAngle);
275}
std::enable_if< std::is_floating_point< T >::value, T >::type normalizeAngle(T a)
Definition kis_global.h:121

References kisDegreesToRadians(), kisRadiansToDegrees(), m_endAngle, M_PI, m_startAngle, and normalizeAngle().

◆ type()

EllipseShape::EllipseType EllipseShape::type ( ) const

Returns the actual ellipse type.

Definition at line 284 of file EllipseShape.cpp.

285{
286 return m_type;
287}

References m_type.

◆ updateAngleHandles()

void EllipseShape::updateAngleHandles ( )
private

Definition at line 249 of file EllipseShape.cpp.

250{
254 handles[0] = m_center + QPointF(cos(startRadian) * m_radii.x(), -sin(startRadian) * m_radii.y());
255 handles[1] = m_center + QPointF(cos(endRadian) * m_radii.x(), -sin(endRadian) * m_radii.y());
257}
std::enable_if< std::is_floating_point< T >::value, T >::type normalizeAngleDegrees(T a)
Definition kis_global.h:132

References KoParameterShape::handles, kisDegreesToRadians(), m_center, m_endAngle, m_radii, m_startAngle, normalizeAngleDegrees(), and KoParameterShape::setHandles().

◆ updateKindHandle()

void EllipseShape::updateKindHandle ( )
private

Definition at line 225 of file EllipseShape.cpp.

226{
227 qreal angle = 0.5 * (m_startAngle + m_endAngle);
228 if (m_startAngle > m_endAngle) {
229 angle += 180.0;
230 }
231
233
235 switch (m_type) {
236 case Arc:
237 handles[2] = m_center + QPointF(cos(m_kindAngle) * m_radii.x(), -sin(m_kindAngle) * m_radii.y());
238 break;
239 case Pie:
240 handles[2] = m_center;
241 break;
242 case Chord:
243 handles[2] = (handles[0] + handles[1]) / 2.0;
244 break;
245 }
247}

References Arc, Chord, KoParameterShape::handles, kisDegreesToRadians(), m_center, m_endAngle, m_kindAngle, m_radii, m_startAngle, m_type, normalizeAngle(), Pie, and KoParameterShape::setHandles().

◆ updatePath()

void EllipseShape::updatePath ( const QSizeF & size)
overrideprotectedvirtual

Update the path of the parameter shape.

Parameters
sizeof the shape

Implements KoParameterShape.

Definition at line 141 of file EllipseShape.cpp.

142{
143 Q_UNUSED(size);
144 QPointF startpoint(handles()[0]);
145
146 QPointF curvePoints[12];
147 const qreal distance = sweepAngle();
148
149 const bool sameAngles = distance > 359.9;
150 int pointCnt = arcToCurve(m_radii.x(), m_radii.y(), m_startAngle, distance, startpoint, curvePoints);
152
153 int curvePointCount = 1 + pointCnt / 3;
154 int requiredPointCount = curvePointCount;
155 if (m_type == Pie) {
156 requiredPointCount++;
157 } else if (m_type == Arc && sameAngles) {
158 curvePointCount--;
159 requiredPointCount--;
160 }
161
162 createPoints(requiredPointCount);
163
164 KoSubpath &points = *subpaths()[0];
165
166 int curveIndex = 0;
167 points[0]->setPoint(startpoint);
168 points[0]->removeControlPoint1();
169 points[0]->setProperty(KoPathPoint::StartSubpath);
170 for (int i = 1; i < curvePointCount; ++i) {
171 points[i - 1]->setControlPoint2(curvePoints[curveIndex++]);
172 points[i]->setControlPoint1(curvePoints[curveIndex++]);
173 points[i]->setPoint(curvePoints[curveIndex++]);
174 points[i]->removeControlPoint2();
175 }
176
177 if (m_type == Pie) {
178 points[requiredPointCount - 1]->setPoint(m_center);
179 points[requiredPointCount - 1]->removeControlPoint1();
180 points[requiredPointCount - 1]->removeControlPoint2();
181 } else if (m_type == Arc && sameAngles) {
182 points[curvePointCount - 1]->setControlPoint2(curvePoints[curveIndex]);
183 points[0]->setControlPoint1(curvePoints[++curveIndex]);
184 }
185
186 for (int i = 0; i < requiredPointCount; ++i) {
187 points[i]->unsetProperty(KoPathPoint::StopSubpath);
188 points[i]->unsetProperty(KoPathPoint::CloseSubpath);
189 }
190 subpaths()[0]->last()->setProperty(KoPathPoint::StopSubpath);
191 if (m_type == Arc && !sameAngles) {
192 subpaths()[0]->first()->unsetProperty(KoPathPoint::CloseSubpath);
193 subpaths()[0]->last()->unsetProperty(KoPathPoint::CloseSubpath);
194 } else {
195 subpaths()[0]->first()->setProperty(KoPathPoint::CloseSubpath);
196 subpaths()[0]->last()->setProperty(KoPathPoint::CloseSubpath);
197 }
198
200
201 normalize();
202}
qreal distance(const QPointF &p1, const QPointF &p2)
QPointF normalize() override
Normalizes the path data.
void createPoints(int requiredPointCount)
qreal sweepAngle() const
@ StartSubpath
it starts a new subpath by a moveTo command
Definition KoPathPoint.h:38
@ CloseSubpath
it closes a subpath (only applicable on StartSubpath and StopSubpath)
Definition KoPathPoint.h:40
@ StopSubpath
it stops a subpath (last point of subpath)
Definition KoPathPoint.h:39
int arcToCurve(qreal rx, qreal ry, qreal startAngle, qreal sweepAngle, const QPointF &offset, QPointF *curvePoints) const
Add an arc.
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128

References Arc, KoPathShape::arcToCurve(), KoPathPoint::CloseSubpath, createPoints(), distance(), KoParameterShape::handles, KIS_SAFE_ASSERT_RECOVER_RETURN, m_center, m_radii, m_startAngle, m_type, normalize(), KoPathShape::notifyPointsChanged(), Pie, KoPathShape::size(), KoPathPoint::StartSubpath, KoPathPoint::StopSubpath, KoPathShape::subpaths(), and sweepAngle().

Member Data Documentation

◆ m_center

QPointF EllipseShape::m_center
private

Definition at line 97 of file EllipseShape.h.

◆ m_endAngle

qreal EllipseShape::m_endAngle
private

Definition at line 93 of file EllipseShape.h.

◆ m_kindAngle

qreal EllipseShape::m_kindAngle
private

Definition at line 95 of file EllipseShape.h.

◆ m_radii

QPointF EllipseShape::m_radii
private

Definition at line 99 of file EllipseShape.h.

◆ m_startAngle

qreal EllipseShape::m_startAngle
private

Definition at line 91 of file EllipseShape.h.

◆ m_type

EllipseType EllipseShape::m_type
private

Definition at line 101 of file EllipseShape.h.


The documentation for this class was generated from the following files: