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

#include <StarShape.h>

+ Inheritance diagram for StarShape:

Public Member Functions

qreal baseRadius () const
 Returns the base radius.
 
KoShapecloneShape () const override
 creates a deep copy of the shape or shape's subtree
 
bool convex () const
 Returns if the star represents a regular polygon.
 
uint cornerCount () const
 Returns the number of corners.
 
QString pathShapeId () const override
 reimplemented
 
void setBaseRadius (qreal baseRadius)
 
void setBaseRoundness (qreal baseRoundness)
 
void setConvex (bool convex)
 
void setCornerCount (uint cornerCount)
 
void setSize (const QSizeF &newSize) override
 reimplemented
 
void setTipRadius (qreal tipRadius)
 
void setTipRoundness (qreal tipRoundness)
 
QPointF starCenter () const
 
 StarShape ()
 
qreal tipRadius () const
 Returns the tip radius.
 
 ~StarShape () 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.
 
 ~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.
 
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)
 
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.
 

Protected Member Functions

void createPoints (int requiredPointCount)
 recreates the path points when the corner count or convexity changes
 
void moveHandleAction (int handleId, const QPointF &point, Qt::KeyboardModifiers modifiers=Qt::NoModifier) override
 Updates the internal state of a KoParameterShape.
 
 StarShape (const StarShape &rhs)
 
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 Types

enum  Handles { tip = 0 , base = 1 }
 the handle types More...
 

Private Member Functions

QPointF computeCenter () const
 Computes the star center point from the inner points.
 
double defaultAngleRadian () const
 Returns the default offset angle in radian.
 

Private Attributes

std::array< qreal, 2 > m_angles
 the offset angles
 
QPointF m_center
 the star center point
 
bool m_convex
 controls if the star is convex
 
uint m_cornerCount
 number of corners
 
std::array< qreal, 2 > m_radius
 the different radii
 
std::array< qreal, 2 > m_roundness
 the roundness at the handles
 
qreal m_zoomX
 scaling in x
 
qreal m_zoomY
 scaling in y
 

Additional Inherited Members

- 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...
 
- 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

The star shape is a shape that can represent a star or a regular polygon. There a some properties which can be changed to control the appearance of the shape like the number of corners, the inner/outer radius and the corner roundness.

Definition at line 22 of file StarShape.h.

Member Enumeration Documentation

◆ Handles

enum StarShape::Handles
private

the handle types

Enumerator
tip 
base 

Definition at line 120 of file StarShape.h.

120{ tip = 0, base = 1 };

Constructor & Destructor Documentation

◆ StarShape() [1/2]

StarShape::StarShape ( )

Definition at line 19 of file StarShape.cpp.

20 : m_cornerCount(5)
21 , m_zoomX(1.0)
22 , m_zoomY(1.0)
23 , m_convex(false)
24{
25 m_radius[base] = 25.0;
26 m_radius[tip] = 50.0;
29
30 m_center = QPointF(50, 50);
31 updatePath(QSize(100, 100));
32}
qreal m_zoomY
scaling in y
Definition StarShape.h:126
bool m_convex
controls if the star is convex
Definition StarShape.h:129
uint m_cornerCount
number of corners
Definition StarShape.h:122
std::array< qreal, 2 > m_radius
the different radii
Definition StarShape.h:123
qreal m_zoomX
scaling in x
Definition StarShape.h:125
double defaultAngleRadian() const
Returns the default offset angle in radian.
std::array< qreal, 2 > m_roundness
the roundness at the handles
Definition StarShape.h:127
std::array< qreal, 2 > m_angles
the offset angles
Definition StarShape.h:124
void updatePath(const QSizeF &size) override
Update the path of the parameter shape.
QPointF m_center
the star center point
Definition StarShape.h:128

References base, defaultAngleRadian(), m_angles, m_center, m_radius, m_roundness, tip, and updatePath().

◆ ~StarShape()

StarShape::~StarShape ( )
override

Definition at line 47 of file StarShape.cpp.

48{
49}

◆ StarShape() [2/2]

StarShape::StarShape ( const StarShape & rhs)
protected

Definition at line 34 of file StarShape.cpp.

Member Function Documentation

◆ baseRadius()

qreal StarShape::baseRadius ( ) const

Returns the base radius.

Definition at line 81 of file StarShape.cpp.

82{
83 return m_radius[base];
84}

References base, and m_radius.

◆ cloneShape()

KoShape * StarShape::cloneShape ( ) const
overridevirtual

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

Returns
a cloned shape

Reimplemented from KoPathShape.

Definition at line 51 of file StarShape.cpp.

52{
53 return new StarShape(*this);
54}

References StarShape().

◆ computeCenter()

QPointF StarShape::computeCenter ( ) const
private

Computes the star center point from the inner points.

Definition at line 259 of file StarShape.cpp.

260{
261 KoSubpath &points = *subpaths()[0];
262
263 QPointF center(0, 0);
264 for (uint i = 0; i < m_cornerCount; ++i) {
265 if (m_convex) {
266 center += points[i]->point();
267 } else {
268 center += points[2 * i]->point();
269 }
270 }
271 if (m_cornerCount > 0) {
272 return center / static_cast<qreal>(m_cornerCount);
273 }
274 return center;
275
276}
unsigned int uint
const KoSubpathList & subpaths() const

References m_convex, m_cornerCount, and KoPathShape::subpaths().

◆ convex()

bool StarShape::convex ( ) const

Returns if the star represents a regular polygon.

Definition at line 115 of file StarShape.cpp.

116{
117 return m_convex;
118}

References m_convex.

◆ cornerCount()

uint StarShape::cornerCount ( ) const

Returns the number of corners.

Definition at line 70 of file StarShape.cpp.

71{
72 return m_cornerCount;
73}

References m_cornerCount.

◆ createPoints()

void StarShape::createPoints ( int requiredPointCount)
protected

recreates the path points when the corner count or convexity changes

Definition at line 226 of file StarShape.cpp.

227{
228 if (subpaths().count() != 1) {
229 clear();
230 subpaths().append(new KoSubpath());
231 }
232 int currentPointCount = subpaths()[0]->count();
233 if (currentPointCount > requiredPointCount) {
234 for (int i = 0; i < currentPointCount - requiredPointCount; ++i) {
235 delete subpaths()[0]->front();
236 subpaths()[0]->pop_front();
237 }
238 } else if (requiredPointCount > currentPointCount) {
239 for (int i = 0; i < requiredPointCount - currentPointCount; ++i) {
240 subpaths()[0]->append(new KoPathPoint(this, QPointF()));
241 }
242 }
243
245}
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.
void notifyPointsChanged()
void clear()
Removes all subpaths and their points from the path.

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

◆ defaultAngleRadian()

double StarShape::defaultAngleRadian ( ) const
private

Returns the default offset angle in radian.

Definition at line 283 of file StarShape.cpp.

284{
285 qreal radianStep = M_PI / static_cast<qreal>(m_cornerCount);
286
287 return M_PI_2 - 2 * radianStep;
288}
#define M_PI
Definition kis_global.h:111

References m_cornerCount, and M_PI.

◆ moveHandleAction()

void StarShape::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 125 of file StarShape.cpp.

126{
127 if (modifiers & Qt::ShiftModifier) {
128 QPointF handle = handles()[handleId];
129 QPointF tangentVector = point - handle;
130 qreal distance = sqrt(tangentVector.x() * tangentVector.x() + tangentVector.y() * tangentVector.y());
131 QPointF radialVector = handle - m_center;
132 // cross product to determine in which direction the user is dragging
133 qreal moveDirection = radialVector.x() * tangentVector.y() - radialVector.y() * tangentVector.x();
134 // make the roundness stick to zero if distance is under a certain value
135 float snapDistance = 3.0;
136 if (distance >= 0.0) {
137 distance = distance < snapDistance ? 0.0 : distance - snapDistance;
138 } else {
139 distance = distance > -snapDistance ? 0.0 : distance + snapDistance;
140 }
141 // control changes roundness on both handles, else only the actual handle roundness is changed
142 if (modifiers & Qt::ControlModifier) {
143 m_roundness[handleId] = moveDirection < 0.0f ? distance : -distance;
144 } else {
145 m_roundness[base] = m_roundness[tip] = moveDirection < 0.0f ? distance : -distance;
146 }
147 } else {
148 QPointF distVector = point - m_center;
149 // unapply scaling
150 distVector.rx() /= m_zoomX;
151 distVector.ry() /= m_zoomY;
152 m_radius[handleId] = sqrt(distVector.x() * distVector.x() + distVector.y() * distVector.y());
153
154 qreal angle = atan2(distVector.y(), distVector.x());
155 if (angle < 0.0) {
156 angle += 2.0 * M_PI;
157 }
158 qreal diffAngle = angle - m_angles[handleId];
159 qreal radianStep = M_PI / static_cast<qreal>(m_cornerCount);
160 if (handleId == tip) {
161 m_angles[tip] += diffAngle - radianStep;
162 m_angles[base] += diffAngle - radianStep;
163 } else {
164 // control make the base point move freely
165 if (modifiers & Qt::ControlModifier) {
166 m_angles[base] += diffAngle - 2 * radianStep;
167 } else {
169 }
170 }
171 }
172}
qreal distance(const QPointF &p1, const QPointF &p2)
QList< QPointF > handles
the handles that the user can grab and change
KRITAIMAGE_EXPORT qreal atan2(qreal y, qreal x)
atan2 replacement

References base, distance(), KoParameterShape::handles, m_angles, m_center, m_cornerCount, M_PI, m_radius, m_roundness, m_zoomX, m_zoomY, and tip.

◆ pathShapeId()

QString StarShape::pathShapeId ( ) const
overridevirtual

reimplemented

Reimplemented from KoPathShape.

Definition at line 278 of file StarShape.cpp.

279{
280 return StarShapeId;
281}
#define StarShapeId
Definition StarShape.h:13

References StarShapeId.

◆ setBaseRadius()

void StarShape::setBaseRadius ( qreal baseRadius)

Sets the radius of the base points. The base radius has no meaning if the star is set convex.

Parameters
baseRadiusthe new base radius

Definition at line 75 of file StarShape.cpp.

76{
77 m_radius[base] = fabs(baseRadius);
78 updatePath(QSize());
79}
qreal baseRadius() const
Returns the base radius.
Definition StarShape.cpp:81

References base, baseRadius(), m_radius, and updatePath().

◆ setBaseRoundness()

void StarShape::setBaseRoundness ( qreal baseRoundness)

Sets the roundness at the base points.

A roundness value of zero disables the roundness.

Parameters
baseRoundnessthe new base roundness

Definition at line 97 of file StarShape.cpp.

98{
99 m_roundness[base] = baseRoundness;
100 updatePath(QSize());
101}

References base, m_roundness, and updatePath().

◆ setConvex()

void StarShape::setConvex ( bool convex)

Sets the star to be convex, looking like a polygon.

Parameters
convexif true makes shape behave like regular polygon

Definition at line 109 of file StarShape.cpp.

110{
112 updatePath(QSize());
113}
bool convex() const
Returns if the star represents a regular polygon.

References convex(), m_convex, and updatePath().

◆ setCornerCount()

void StarShape::setCornerCount ( uint cornerCount)

Sets the number of corners.

The minimum accepted number of corners is 3. If the star is set to be convex (like a regular polygon), the corner count equals the number of polygon points. For a real star it represents the number of legs the star has.

Parameters
cornerCountthe new number of corners

Definition at line 57 of file StarShape.cpp.

58{
59 if (cornerCount >= 3) {
60 double oldDefaultAngle = defaultAngleRadian();
62 double newDefaultAngle = defaultAngleRadian();
63 m_angles[base] += newDefaultAngle - oldDefaultAngle;
64 m_angles[tip] += newDefaultAngle - oldDefaultAngle;
65
66 updatePath(QSize());
67 }
68}
uint cornerCount() const
Returns the number of corners.
Definition StarShape.cpp:70

References base, cornerCount(), defaultAngleRadian(), m_angles, m_cornerCount, tip, and updatePath().

◆ setSize()

void StarShape::setSize ( const QSizeF & newSize)
overridevirtual

reimplemented

Reimplemented from KoParameterShape.

Definition at line 247 of file StarShape.cpp.

248{
249 QTransform matrix(resizeMatrix(newSize));
250 m_zoomX *= matrix.m11();
251 m_zoomY *= matrix.m22();
252
253 // this transforms the handles
255
257}
void setSize(const QSizeF &size) override
reimplemented from KoShape
QTransform resizeMatrix(const QSizeF &newSize) const
QPointF computeCenter() const
Computes the star center point from the inner points.

References computeCenter(), m_center, m_zoomX, m_zoomY, KoPathShape::resizeMatrix(), and KoParameterShape::setSize().

◆ setTipRadius()

void StarShape::setTipRadius ( qreal tipRadius)

Sets the radius of the tip points.

Parameters
tipRadiusthe new tip radius

Definition at line 86 of file StarShape.cpp.

87{
88 m_radius[tip] = fabs(tipRadius);
89 updatePath(QSize());
90}
qreal tipRadius() const
Returns the tip radius.
Definition StarShape.cpp:92

References m_radius, tip, tipRadius(), and updatePath().

◆ setTipRoundness()

void StarShape::setTipRoundness ( qreal tipRoundness)

Sets the roundness at the tip points.

A roundness value of zero disables the roundness.

Parameters
tipRoundnessthe new base roundness

Definition at line 103 of file StarShape.cpp.

104{
105 m_roundness[tip] = tipRoundness;
106 updatePath(QSize());
107}

References m_roundness, tip, and updatePath().

◆ starCenter()

QPointF StarShape::starCenter ( ) const

Returns the star center point in shape coordinates.

The star center is the weight center of the star and not necessarily coincident with the shape center point.

Definition at line 120 of file StarShape.cpp.

121{
122 return m_center;
123}

References m_center.

◆ tipRadius()

qreal StarShape::tipRadius ( ) const

Returns the tip radius.

Definition at line 92 of file StarShape.cpp.

93{
94 return m_radius[tip];
95}

References m_radius, and tip.

◆ updatePath()

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

Update the path of the parameter shape.

Parameters
sizeof the shape

Implements KoParameterShape.

Definition at line 174 of file StarShape.cpp.

175{
176 Q_UNUSED(size);
177 qreal radianStep = M_PI / static_cast<qreal>(m_cornerCount);
178
180
181 KoSubpath &points = *subpaths()[0];
182
183 uint index = 0;
184 for (uint i = 0; i < 2 * m_cornerCount; ++i) {
185 uint cornerType = i % 2;
186 if (cornerType == base && m_convex) {
187 continue;
188 }
189 qreal radian = static_cast<qreal>((i + 1) * radianStep) + m_angles[cornerType];
190 QPointF cornerPoint = QPointF(m_zoomX * m_radius[cornerType] * cos(radian), m_zoomY * m_radius[cornerType] * sin(radian));
191
192 points[index]->setPoint(m_center + cornerPoint);
193 points[index]->unsetProperty(KoPathPoint::StopSubpath);
194 points[index]->unsetProperty(KoPathPoint::CloseSubpath);
195 if (m_roundness[cornerType] > 1e-10 || m_roundness[cornerType] < -1e-10) {
196 // normalized cross product to compute tangential vector for handle point
197 QPointF tangentVector(cornerPoint.y() / m_radius[cornerType], -cornerPoint.x() / m_radius[cornerType]);
198 points[index]->setControlPoint2(points[index]->point() - m_roundness[cornerType] * tangentVector);
199 points[index]->setControlPoint1(points[index]->point() + m_roundness[cornerType] * tangentVector);
200 } else {
201 points[index]->removeControlPoint1();
202 points[index]->removeControlPoint2();
203 }
204 index++;
205 }
206
207 // first path starts and closes path
208 points[0]->setProperty(KoPathPoint::StartSubpath);
209 points[0]->setProperty(KoPathPoint::CloseSubpath);
210 // last point stops and closes path
211 points.last()->setProperty(KoPathPoint::StopSubpath);
212 points.last()->setProperty(KoPathPoint::CloseSubpath);
213
214 normalize();
215
217 handles.push_back(points.at(tip)->point());
218 if (!m_convex) {
219 handles.push_back(points.at(base)->point());
220 }
222
224}
QPointF normalize() override
Normalizes the path data.
void setHandles(const QList< QPointF > &handles)
@ 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
QSizeF size() const override
reimplemented
void createPoints(int requiredPointCount)
recreates the path points when the corner count or convexity changes

References base, KoPathPoint::CloseSubpath, computeCenter(), createPoints(), KoParameterShape::handles, m_angles, m_center, m_convex, m_cornerCount, M_PI, m_radius, m_roundness, m_zoomX, m_zoomY, KoParameterShape::normalize(), KoParameterShape::setHandles(), KoPathShape::size(), KoPathPoint::StartSubpath, KoPathPoint::StopSubpath, KoPathShape::subpaths(), and tip.

Member Data Documentation

◆ m_angles

std::array<qreal, 2> StarShape::m_angles
private

the offset angles

Definition at line 124 of file StarShape.h.

◆ m_center

QPointF StarShape::m_center
private

the star center point

Definition at line 128 of file StarShape.h.

◆ m_convex

bool StarShape::m_convex
private

controls if the star is convex

Definition at line 129 of file StarShape.h.

◆ m_cornerCount

uint StarShape::m_cornerCount
private

number of corners

Definition at line 122 of file StarShape.h.

◆ m_radius

std::array<qreal, 2> StarShape::m_radius
private

the different radii

Definition at line 123 of file StarShape.h.

◆ m_roundness

std::array<qreal, 2> StarShape::m_roundness
private

the roundness at the handles

Definition at line 127 of file StarShape.h.

◆ m_zoomX

qreal StarShape::m_zoomX
private

scaling in x

Definition at line 125 of file StarShape.h.

◆ m_zoomY

qreal StarShape::m_zoomY
private

scaling in y

Definition at line 126 of file StarShape.h.


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