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

#include <KarbonCalligraphicShape.h>

+ Inheritance diagram for KarbonCalligraphicShape:

Classes

struct  Private
 

Public Member Functions

void appendPoint (const QPointF &p1, qreal angle, qreal width)
 
void appendPointToPath (const KarbonCalligraphicPoint &p)
 
KoShapecloneShape () const override
 creates a deep copy of the shape or shape's subtree
 
 KarbonCalligraphicShape (qreal caps=0.0)
 
const QRectF lastPieceBoundingRect ()
 
QPointF normalize () override
 Normalizes the path data.
 
QString pathShapeId () const override
 
void setSize (const QSizeF &newSize) override
 Resize the shape.
 
void simplifyGuidePath ()
 
void simplifyPath ()
 
 ~KarbonCalligraphicShape () 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.
 

Protected Member Functions

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

void addCap (int index1, int index2, int pointIndex, bool inverted=false)
 
void appendPointsToPathAux (const QPointF &p1, const QPointF &p2)
 
bool flipDetected (const QPointF &p1, const QPointF &p2)
 
 KarbonCalligraphicShape (const KarbonCalligraphicShape &rhs)
 
void smoothLastPoints ()
 
void smoothPoint (const int index)
 

Static Private Member Functions

static int ccw (const QPointF &p1, const QPointF &p2, const QPointF &p3)
 

Private Attributes

QSharedDataPointer< Privates
 

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

Definition at line 89 of file KarbonCalligraphicShape.h.

Constructor & Destructor Documentation

◆ KarbonCalligraphicShape() [1/2]

KarbonCalligraphicShape::KarbonCalligraphicShape ( qreal caps = 0.0)
explicit

Definition at line 43 of file KarbonCalligraphicShape.cpp.

44 : s(new Private(caps))
45{
47 setFillRule(Qt::WindingFill);
50}
QSharedPointer< KoShapeStrokeModel > KoShapeStrokeModelSP
#define KoPathShapeId
Definition KoPathShape.h:20
QSharedDataPointer< Private > s
A simple solid color shape background.
void setFillRule(Qt::FillRule fillRule)
Sets the fill rule to be used for painting the background.
virtual void setStroke(KoShapeStrokeModelSP stroke)
Definition KoShape.cpp:1081
virtual void setBackground(QSharedPointer< KoShapeBackground > background)
Definition KoShape.cpp:918
void setShapeId(const QString &id)
Definition KoShape.cpp:1062

References KoPathShapeId, KoShape::setBackground(), KoPathShape::setFillRule(), KoShape::setShapeId(), and KoShape::setStroke().

◆ ~KarbonCalligraphicShape()

KarbonCalligraphicShape::~KarbonCalligraphicShape ( )
override

Definition at line 58 of file KarbonCalligraphicShape.cpp.

59{
60}

◆ KarbonCalligraphicShape() [2/2]

KarbonCalligraphicShape::KarbonCalligraphicShape ( const KarbonCalligraphicShape & rhs)
private

Definition at line 52 of file KarbonCalligraphicShape.cpp.

53 : KoParameterShape(rhs),
54 s(rhs.s)
55{
56}

Member Function Documentation

◆ addCap()

void KarbonCalligraphicShape::addCap ( int index1,
int index2,
int pointIndex,
bool inverted = false )
private

Definition at line 345 of file KarbonCalligraphicShape.cpp.

346{
347 QPointF p1 = s->points[index1].point();
348 QPointF p2 = s->points[index2].point();
349
350 // TODO: review why spikes can appear with a lower limit
351 QPointF delta = p2 - p1;
352 if (delta.manhattanLength() < 1.0) {
353 return;
354 }
355
356 QPointF direction = QLineF(QPointF(0, 0), delta).unitVector().p2();
357 qreal width = s->points[index2].width();
358 QPointF p = p2 + direction * s->caps * width;
359
360 KoPathPoint *newPoint = new KoPathPoint(this, p);
361
362 qreal angle = s->points[index2].angle();
363 if (inverted) {
364 angle += M_PI;
365 }
366
367 qreal dx = std::cos(angle) * width;
368 qreal dy = std::sin(angle) * width;
369 newPoint->setControlPoint1(QPointF(p.x() - dx / 2, p.y() - dy / 2));
370 newPoint->setControlPoint2(QPointF(p.x() + dx / 2, p.y() + dy / 2));
371
372 insertPoint(newPoint, KoPathPointIndex(0, pointIndex));
373}
const Params2D p
QPointF p2
QPointF p1
QPair< int, int > KoPathPointIndex
Definition KoPathShape.h:28
A KoPathPoint represents a point in a path.
void setControlPoint1(const QPointF &point)
Set the control point 1.
void setControlPoint2(const QPointF &point)
Set the control point 2.
bool insertPoint(KoPathPoint *point, const KoPathPointIndex &pointIndex)
Inserts a new point into the given subpath at the specified position.
#define M_PI
Definition kis_global.h:111

References KoPathShape::insertPoint(), M_PI, p, p1, p2, s, KoPathPoint::setControlPoint1(), and KoPathPoint::setControlPoint2().

◆ appendPoint()

void KarbonCalligraphicShape::appendPoint ( const QPointF & p1,
qreal angle,
qreal width )

Definition at line 67 of file KarbonCalligraphicShape.cpp.

68{
69 // convert the point from canvas to shape coordinates
70 QPointF p = point - position();
71 KarbonCalligraphicPoint calligraphicPoint(p, angle, width);
72
74 handles.append(p);
76 s->points.append(calligraphicPoint);
77 appendPointToPath(calligraphicPoint);
78
79 // make the angle of the first point more in line with the actual
80 // direction
81 if (s->points.count() == 4) {
82 s->points[0].setAngle(angle);
83 s->points[1].setAngle(angle);
84 s->points[2].setAngle(angle);
85 }
86
87 normalize();
88}
void appendPointToPath(const KarbonCalligraphicPoint &p)
QPointF normalize() override
Normalizes the path data.
QList< QPointF > handles
the handles that the user can grab and change
void setHandles(const QList< QPointF > &handles)
QPointF position() const
Get the position of the shape in pt.
Definition KoShape.cpp:825

References appendPointToPath(), KoParameterShape::handles, normalize(), p, KoShape::position(), s, and KoParameterShape::setHandles().

◆ appendPointsToPathAux()

void KarbonCalligraphicShape::appendPointsToPathAux ( const QPointF & p1,
const QPointF & p2 )
private

Definition at line 168 of file KarbonCalligraphicShape.cpp.

169{
170 KoPathPoint *pathPoint1 = new KoPathPoint(this, p1);
171 KoPathPoint *pathPoint2 = new KoPathPoint(this, p2);
172
173 // calculate the index of the insertion position
174 int index = pointCount() / 2;
175
176 insertPoint(pathPoint2, KoPathPointIndex(0, index));
177 insertPoint(pathPoint1, KoPathPointIndex(0, index));
178}
int pointCount() const
Returns the number of points in the path.

References KoPathShape::insertPoint(), p1, p2, and KoPathShape::pointCount().

◆ appendPointToPath()

void KarbonCalligraphicShape::appendPointToPath ( const KarbonCalligraphicPoint & p)

Definition at line 90 of file KarbonCalligraphicShape.cpp.

91{
92 qreal dx = std::cos(p.angle()) * p.width();
93 qreal dy = std::sin(p.angle()) * p.width();
94
95 // find the outline points
96 QPointF p1 = p.point() - QPointF(dx / 2, dy / 2);
97 QPointF p2 = p.point() + QPointF(dx / 2, dy / 2);
98
99 if (pointCount() == 0) {
100 moveTo(p1);
101 lineTo(p2);
102 return;
103 }
104 // pointCount > 0
105
106 bool flip = (pointCount() >= 2) ? flipDetected(p1, p2) : false;
107
108 // if there was a flip add additional points
109 if (flip) {
111 if (pointCount() > 4) {
113 }
114 }
115
117
118 if (pointCount() > 4) {
120
121 if (flip) {
122 int index = pointCount() / 2;
123 // find the last two points
124 KoPathPoint *last1 = pointByIndex(KoPathPointIndex(0, index - 1));
125 KoPathPoint *last2 = pointByIndex(KoPathPointIndex(0, index));
126
127 last1->removeControlPoint1();
128 last1->removeControlPoint2();
129 last2->removeControlPoint1();
130 last2->removeControlPoint2();
131 s->lastWasFlip = true;
132 }
133
134 if (s->lastWasFlip) {
135 int index = pointCount() / 2;
136 // find the previous two points
137 KoPathPoint *prev1 = pointByIndex(KoPathPointIndex(0, index - 2));
138 KoPathPoint *prev2 = pointByIndex(KoPathPointIndex(0, index + 1));
139
140 prev1->removeControlPoint1();
141 prev1->removeControlPoint2();
142 prev2->removeControlPoint1();
143 prev2->removeControlPoint2();
144
145 if (!flip) {
146 s->lastWasFlip = false;
147 }
148 }
149 }
150
151 // add initial cap if it's the fourth added point
152 // this code is here because this function is called from different places
153 // pointCount() == 8 may causes crashes because it doesn't take possible
154 // flips into account
155
156 if (s->points.count() >= 4 && p == s->points[3]) {
157 addCap(3, 0, 0, true);
158 // duplicate the last point to make the points remain "balanced"
159 // needed to keep all indexes code (else I would need to change
160 // everything in the code...)
162 KoPathPoint *newPoint = new KoPathPoint(this, last->point());
163 insertPoint(newPoint, KoPathPointIndex(0, pointCount()));
164 close();
165 }
166}
void appendPointsToPathAux(const QPointF &p1, const QPointF &p2)
bool flipDetected(const QPointF &p1, const QPointF &p2)
void addCap(int index1, int index2, int pointIndex, bool inverted=false)
QPointF point
void removeControlPoint1()
Removes the first control point.
void removeControlPoint2()
Removes the second control point.
KoPathPoint * lineTo(const QPointF &p)
Adds a new line segment.
void close()
Closes the current subpath.
KoPathPoint * moveTo(const QPointF &p)
Starts a new Subpath.
KoPathPoint * pointByIndex(const KoPathPointIndex &pointIndex) const
Returns the path point specified by a path point index.

References addCap(), appendPointsToPathAux(), KoPathShape::close(), flipDetected(), KoPathShape::insertPoint(), KoPathShape::lineTo(), KoPathShape::moveTo(), p, p1, p2, KoPathPoint::point, KoPathShape::pointByIndex(), KoPathShape::pointCount(), KoPathPoint::removeControlPoint1(), KoPathPoint::removeControlPoint2(), s, and smoothLastPoints().

◆ ccw()

int KarbonCalligraphicShape::ccw ( const QPointF & p1,
const QPointF & p2,
const QPointF & p3 )
staticprivate

Definition at line 263 of file KarbonCalligraphicShape.cpp.

264{
265 // calculate two times the area of the triangle formed by the points given
266 qreal area2 = (p2.x() - p1.x()) * (p3.y() - p1.y()) -
267 (p2.y() - p1.y()) * (p3.x() - p1.x());
268 if (area2 > 0) {
269 return +1; // the points are given in counterclockwise order
270 } else if (area2 < 0) {
271 return -1; // the points are given in clockwise order
272 } else {
273 return 0; // the points form a degenerate triangle
274 }
275}
QPointF p3

References p1, p2, and p3.

◆ cloneShape()

KoShape * KarbonCalligraphicShape::cloneShape ( ) const
overridevirtual

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

Returns
a cloned shape

Reimplemented from KoShape.

Definition at line 62 of file KarbonCalligraphicShape.cpp.

63{
64 return new KarbonCalligraphicShape(*this);
65}

References KarbonCalligraphicShape().

◆ flipDetected()

bool KarbonCalligraphicShape::flipDetected ( const QPointF & p1,
const QPointF & p2 )
private

Definition at line 249 of file KarbonCalligraphicShape.cpp.

250{
251 // detect the flip caused by the angle changing 180 degrees
252 // thus detect the boundary crossing
253 int index = pointCount() / 2;
254 QPointF last1 = pointByIndex(KoPathPointIndex(0, index - 1))->point();
255 QPointF last2 = pointByIndex(KoPathPointIndex(0, index))->point();
256
257 int sum1 = std::abs(ccw(p1, p2, last1) + ccw(p1, last2, last1));
258 int sum2 = std::abs(ccw(p2, p1, last2) + ccw(p2, last1, last2));
259 // if there was a flip
260 return sum1 < 2 && sum2 < 2;
261}
static int ccw(const QPointF &p1, const QPointF &p2, const QPointF &p3)

References ccw(), p1, p2, KoPathPoint::point, KoPathShape::pointByIndex(), and KoPathShape::pointCount().

◆ lastPieceBoundingRect()

const QRectF KarbonCalligraphicShape::lastPieceBoundingRect ( )

Definition at line 222 of file KarbonCalligraphicShape.cpp.

223{
224 if (pointCount() < 6) {
225 return QRectF();
226 }
227
228 int index = pointCount() / 2;
229
230 QPointF p1 = pointByIndex(KoPathPointIndex(0, index - 3))->point();
231 QPointF p2 = pointByIndex(KoPathPointIndex(0, index - 2))->point();
232 QPointF p3 = pointByIndex(KoPathPointIndex(0, index - 1))->point();
233 QPointF p4 = pointByIndex(KoPathPointIndex(0, index))->point();
234 QPointF p5 = pointByIndex(KoPathPointIndex(0, index + 1))->point();
235 QPointF p6 = pointByIndex(KoPathPointIndex(0, index + 2))->point();
236
237 // TODO: also take the control points into account
238 QPainterPath p;
239 p.moveTo(p1);
240 p.lineTo(p2);
241 p.lineTo(p3);
242 p.lineTo(p4);
243 p.lineTo(p5);
244 p.lineTo(p6);
245
246 return p.boundingRect().translated(position());
247}

References p, p1, p2, p3, KoPathPoint::point, KoPathShape::pointByIndex(), KoPathShape::pointCount(), and KoShape::position().

◆ moveHandleAction()

void KarbonCalligraphicShape::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 297 of file KarbonCalligraphicShape.cpp.

300{
301 Q_UNUSED(modifiers);
302 s->points[handleId].setPoint(point);
303}

References s.

◆ normalize()

QPointF KarbonCalligraphicShape::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 284 of file KarbonCalligraphicShape.cpp.

285{
286 QPointF offset(KoParameterShape::normalize());
287 QTransform matrix;
288 matrix.translate(-offset.x(), -offset.y());
289
290 for (int i = 0; i < s->points.size(); ++i) {
291 s->points[i].setPoint(matrix.map(s->points[i].point()));
292 }
293
294 return offset;
295}
QPointF normalize() override
Normalizes the path data.

References KoParameterShape::normalize(), and s.

◆ pathShapeId()

QString KarbonCalligraphicShape::pathShapeId ( ) const
overridevirtual

Returns the specific path shape id.

Path shape derived shapes have a different shape id which link them to their respective shape factories. In most cases they do not have a special tool for editing them. This function returns the specific shape id for finding the shape factory from KoShapeRegistry. The default KoPathShapeId is returned from KoShape::shapeId() so that the generic path editing tool gets activated when the shape is selected.

Returns
the specific shape id

Reimplemented from KoPathShape.

Definition at line 375 of file KarbonCalligraphicShape.cpp.

376{
378}
#define KarbonCalligraphicShapeId

References KarbonCalligraphicShapeId.

◆ setSize()

void KarbonCalligraphicShape::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 277 of file KarbonCalligraphicShape.cpp.

278{
279 // QSizeF oldSize = size();
280 // TODO: check
282}
void setSize(const QSizeF &size) override
reimplemented from KoShape

References KoParameterShape::setSize().

◆ simplifyGuidePath()

void KarbonCalligraphicShape::simplifyGuidePath ( )

Definition at line 380 of file KarbonCalligraphicShape.cpp.

381{
382 // do not attempt to simplify if there are too few points
383 if (s->points.count() < 3) {
384 return;
385 }
386
387 QList<QPointF> points;
388 Q_FOREACH (const KarbonCalligraphicPoint &p, s->points) {
389 points.append(p.point());
390 }
391
392 // cumulative data used to determine if the point can be removed
393 qreal widthChange = 0;
394 qreal directionChange = 0;
395 QList<KarbonCalligraphicPoint>::iterator i = s->points.begin() + 2;
396
397 while (i != std::prev(s->points.end())) {
398 QPointF point = i->point();
399
400 qreal width = i->width();
401 qreal prevWidth = std::prev(i)->width();
402 qreal widthDiff = width - prevWidth;
403 widthDiff /= qMax(width, prevWidth);
404
405 qreal directionDiff = 0;
406 if (std::next(i) != s->points.end()) {
407 QPointF prev = std::prev(i)->point();
408 QPointF next = std::next(i)->point();
409
410 directionDiff = QLineF(prev, point).angleTo(QLineF(point, next));
411 if (directionDiff > 180) {
412 directionDiff -= 360;
413 }
414 }
415
416 if (directionChange * directionDiff >= 0 &&
417 qAbs(directionChange + directionDiff) < 20 &&
418 widthChange * widthDiff >= 0 &&
419 qAbs(widthChange + widthDiff) < 0.1) {
420 // deleted point
421 i = s->points.erase(i);
422 directionChange += directionDiff;
423 widthChange += widthDiff;
424 } else {
425 // keep point
426 directionChange = 0;
427 widthChange = 0;
428 ++i;
429 }
430 }
431
432 updatePath(QSizeF());
433}
void updatePath(const QSizeF &size) override
Update the path of the parameter shape.
QAction * next(const QObject *recvr, const char *slot, QObject *parent)

References p, s, and updatePath().

◆ simplifyPath()

void KarbonCalligraphicShape::simplifyPath ( )

Definition at line 329 of file KarbonCalligraphicShape.cpp.

330{
331 if (s->points.count() < 2) {
332 return;
333 }
334
335 close();
336
337 // add final cap
338 addCap(s->points.count() - 2, s->points.count() - 1, pointCount() / 2);
339
340 // TODO: the error should be proportional to the width
341 // and it shouldn't be a magic number
342 karbonSimplifyPath(this, 0.3);
343}
void karbonSimplifyPath(KoPathShape *path, qreal error)

References addCap(), KoPathShape::close(), karbonSimplifyPath(), KoPathShape::pointCount(), and s.

◆ smoothLastPoints()

void KarbonCalligraphicShape::smoothLastPoints ( )
private

Definition at line 180 of file KarbonCalligraphicShape.cpp.

181{
182 int index = pointCount() / 2;
183 smoothPoint(index - 2);
184 smoothPoint(index + 1);
185}

References KoPathShape::pointCount(), and smoothPoint().

◆ smoothPoint()

void KarbonCalligraphicShape::smoothPoint ( const int index)
private

Definition at line 187 of file KarbonCalligraphicShape.cpp.

188{
189 if (pointCount() < index + 2) {
190 return;
191 } else if (index < 1) {
192 return;
193 }
194
195 const KoPathPointIndex PREV(0, index - 1);
196 const KoPathPointIndex INDEX(0, index);
197 const KoPathPointIndex NEXT(0, index + 1);
198
199 QPointF prev = pointByIndex(PREV)->point();
200 QPointF point = pointByIndex(INDEX)->point();
201 QPointF next = pointByIndex(NEXT)->point();
202
203 QPointF vector = next - prev;
204 qreal dist = (QLineF(prev, next)).length();
205 // normalize the vector (make it's size equal to 1)
206 if (!qFuzzyCompare(dist + 1, 1)) {
207 vector /= dist;
208 }
209 qreal mult = 0.35; // found by trial and error, might not be perfect...
210 // distance of the control points from the point
211 qreal dist1 = (QLineF(point, prev)).length() * mult;
212 qreal dist2 = (QLineF(point, next)).length() * mult;
213 QPointF vector1 = vector * dist1;
214 QPointF vector2 = vector * dist2;
215 QPointF controlPoint1 = point - vector1;
216 QPointF controlPoint2 = point + vector2;
217
218 pointByIndex(INDEX)->setControlPoint1(controlPoint1);
219 pointByIndex(INDEX)->setControlPoint2(controlPoint2);
220}
qreal length(const QPointF &vec)
Definition Ellipse.cc:82
static bool qFuzzyCompare(half p1, half p2)

References length(), KoPathPoint::point, KoPathShape::pointByIndex(), KoPathShape::pointCount(), qFuzzyCompare(), KoPathPoint::setControlPoint1(), and KoPathPoint::setControlPoint2().

◆ updatePath()

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

Update the path of the parameter shape.

Parameters
sizeof the shape

Implements KoParameterShape.

Definition at line 305 of file KarbonCalligraphicShape.cpp.

306{
307 Q_UNUSED(size);
308
309 QPointF pos = position();
310
311 // remove all points
312 clear();
313 setPosition(QPoint(0, 0));
314
315 Q_FOREACH (const KarbonCalligraphicPoint &p, s->points) {
317 }
318
320 Q_FOREACH (const KarbonCalligraphicPoint &p, s->points) {
321 handles.append(p.point());
322 }
324
325 setPosition(pos);
326 normalize();
327}
QSizeF size() const override
reimplemented
void clear()
Removes all subpaths and their points from the path.
virtual void setPosition(const QPointF &position)
Set the position of the shape in pt.
Definition KoShape.cpp:295

References appendPointToPath(), KoPathShape::clear(), KoParameterShape::handles, normalize(), p, KoShape::position(), s, KoParameterShape::setHandles(), KoShape::setPosition(), and KoPathShape::size().

Member Data Documentation

◆ s

QSharedDataPointer<Private> KarbonCalligraphicShape::s
private

Definition at line 148 of file KarbonCalligraphicShape.h.


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