KoPathShape Class Reference

This is the base for all graphical objects. More...

#include <KoPathShape.h>

Inheritance diagram for KoPathShape:

KoShape KoParameterShape List of all members.

Public Member Functions

 KoPathShape ()
 constructor
virtual void paint (QPainter &painter, const KoViewConverter &converter)
 reimplemented
virtual void paintPoints (QPainter &painter, const KoViewConverter &converter, int handleRadius)
virtual const QPainterPath outline () const
 reimplemented
virtual QRectF boundingRect () const
 reimplemented
virtual QSizeF size () const
 reimplemented
virtual void setSize (const QSizeF &size)
 reimplemented
virtual void saveOdf (KoShapeSavingContext &context) const
 store the shape data as ODF XML.
virtual bool loadOdf (const KoXmlElement &element, KoShapeLoadingContext &context)
 Load a shape from odf.
void clear ()
 Removes all subpaths and their points from the path.
KoPathPointmoveTo (const QPointF &p)
 Start a new Subpath.
KoPathPointlineTo (const QPointF &p)
 add a line
KoPathPointcurveTo (const QPointF &c1, const QPointF &c2, const QPointF &p)
 add a cubic Bezier curve.
KoPathPointcurveTo (const QPointF &c, const QPointF &p)
 add a quadratic Bezier curve.
KoPathPointarcTo (double rx, double ry, double startAngle, double sweepAngle)
 add a arc.
void close ()
 close the current subpath
void closeMerge ()
 close the current subpath
virtual QPointF normalize ()
 Normalizes the path data.
QList< KoPathPoint * > pointsAt (const QRectF &r)
 Returns the path points within the given rectangle.
QList< KoPathSegmentsegmentsAt (const QRectF &r)
 Returns the list of path segments within the given rectangle.
KoPathPointIndex pathPointIndex (const KoPathPoint *point) const
 Get the path point index of a point.
KoPathPointpointByIndex (const KoPathPointIndex &pointIndex) const
 Get the point defined by a path point index.
KoPathSegment segmentByIndex (const KoPathPointIndex &pointIndex) const
 Get the segment defined by a path point index.
int pointCount () const
 Get the number of points in the path.
int subpathCount () const
 Get the number of subpaths in the path.
int pointCountSubpath (int subpathIndex) const
 Get the number of points in a subpath.
bool isClosedSubpath (int subpathIndex)
 Check if subpath is closed.
bool insertPoint (KoPathPoint *point, const KoPathPointIndex &pointIndex)
 Inserts a new point into the given subpath at the specified position.
KoPathPointremovePoint (const KoPathPointIndex &pointIndex)
 Removes point from the path.
bool breakAfter (const KoPathPointIndex &pointIndex)
 Breaks the path after the point index.
bool join (int subpathIndex)
 Joins the given subpath with the following one.
bool moveSubpath (int oldSubpathIndex, int newSubpathIndex)
 Move the position of a subpath within a path.
KoPathPointIndex openSubpath (const KoPathPointIndex &pointIndex)
 Open a closed subpath.
KoPathPointIndex closeSubpath (const KoPathPointIndex &pointIndex)
 Close a open subpath.
bool reverseSubpath (int subpathIndex)
 Reverse subpath.
KoSubpath * removeSubpath (int subpathIndex)
 Remove subpath from path.
bool addSubpath (KoSubpath *subpath, int subpathIndex)
 Add a Subpath at the given index to the path.
bool combine (KoPathShape *path)
 Combines two path by appending the data of the specified path.
bool separate (QList< KoPathShape * > &separatedPaths)
 Creates separate path shapes, one for each existing subpath.
void debugPath ()
 print debug information about a the points of the path
virtual QString pathShapeId () const
 Returns the specific path shape id.
QString toString (const QMatrix &matrix) const
 Returns a odf/svg string represenatation of the path data with the given matrix applied.
Qt::FillRule fillRule () const
 Returns the fill rule for the path object.
void setFillRule (Qt::FillRule fillRule)
 Sets the fill rule to be used for painting the background.

Static Public Member Functions

static KoPathShapefromQPainterPath (const QPainterPath &path)
 Creates path shape from given QPainterPath.

Protected Member Functions

QRectF handleRect (const QPointF &p, double radius) const
int arcToCurve (double rx, double ry, double startAngle, double sweepAngle, const QPointF &offset, QPointF *curvePoints) const
 add a arc.
QRectF loadOdfViewbox (const KoXmlElement &element) const
 Returns the viewbox from the given xml element.
void applyViewboxTransformation (const KoXmlElement &element)
 Applies the viewbox transformation defined in the given element.

Protected Attributes

KoSubpathList m_subpaths

Detailed Description

This is the base for all graphical objects.

All graphical objects are based on this object e.g. lines, rectangulars, pies and so on.

The KoPathShape uses KoPathPoint's to describe the path of the shape.

Here a short example: 3 points connected by a curveTo's described by the following svg: M 100,200 C 100,100 250,100 250,200 C 250,200 400,300 400,200.

This will be stored in 3 KoPathPoint's as The first point contains in point 100,200 controlPoint2 100,100 The second point contains in point 250,200 controlPoint1 250,100 controlPoint2 250,300 The third point contains in point 400,300 controlPoint1 400,200

Not the segments are stored but the points. Out of the points the segments are generated. See the outline method. The reason for storing it like that is that it is the points that are modified by the user and not the segments.


Member Function Documentation

bool KoPathShape::addSubpath ( KoSubpath *  subpath,
int  subpathIndex 
)

Add a Subpath at the given index to the path.

Returns:
true on success, false otherwise e.g. subpathIndex out of bounds

KoPathPoint * KoPathShape::arcTo ( double  rx,
double  ry,
double  startAngle,
double  sweepAngle 
)

add a arc.

Adds an arc starting at the current point. The arc will be converted to bezier curves.

Parameters:
rx x radius of the ellipse
ry y radius of the ellipse
startAngle the angle where the arc will be started
sweepAngle the length of the angle TODO add param to have angle of the ellipse
Returns:
The newly created point

int KoPathShape::arcToCurve ( double  rx,
double  ry,
double  startAngle,
double  sweepAngle,
const QPointF &  offset,
QPointF *  curvePoints 
) const [protected]

add a arc.

Adds an arc starting at the current point. The arc will be converted to bezier curves.

Parameters:
rx x radius of the ellipse
ry y radius of the ellipse
startAngle the angle where the arc will be started
sweepAngle the length of the angle TODO add param to have angle of the ellipse
offset to the first point in the arc
curvePoints a array which take the cuve points, pass a 'QPointF curvePoins[12]';
Returns:
number of points created by the curve

bool KoPathShape::breakAfter ( const KoPathPointIndex &  pointIndex  ) 

Breaks the path after the point index.

The new subpath will be behind the one that was broken. The segment between the given point and the one behind will be removed. If you want to split at one point insert first a copy of the point behind it. This does not work when the subpath is closed. Use openSubpath for this. It does not break at the last position of a subpath or if there is only one point in the subpath.

Parameters:
pointIndex after which the path should be broken
Returns:
true if the subpath was broken, otherwise false

void KoPathShape::closeMerge (  ) 

close the current subpath

It tries to merge the last and first point of the subpath to one point and then closes the subpath. If merging is not possible as the two point are to far from each other a close will be done. TODO define a maximum distance between the two points until this is working

KoPathPointIndex KoPathShape::closeSubpath ( const KoPathPointIndex &  pointIndex  ) 

Close a open subpath.

The subpath is closed be inserting a segment between the start and end point, making the given point the new start point of the subpath.

Returns:
the new position of the old first point in the subpath otherwise KoPathPointIndex( -1, -1 )

bool KoPathShape::combine ( KoPathShape path  ) 

Combines two path by appending the data of the specified path.

Parameters:
path the path to combine with
Returns:
true if combining was successful, else false

KoPathPoint * KoPathShape::curveTo ( const QPointF &  c,
const QPointF &  p 
)

add a quadratic Bezier curve.

Adds a quadratic Bezier curve between the last point and the given p, using the control point specified by c.

Parameters:
c control point
p The endpoint of this curve-part
Returns:
The newly created point

KoPathPoint * KoPathShape::curveTo ( const QPointF &  c1,
const QPointF &  c2,
const QPointF &  p 
)

add a cubic Bezier curve.

Adds a cubic Bezier curve between the last point and the given p, using the control points specified by c1, and c2.

Parameters:
c1 control point1
c2 control point2
p The endpoint of this curve-part
Returns:
The newly created point

bool KoPathShape::insertPoint ( KoPathPoint point,
const KoPathPointIndex &  pointIndex 
)

Inserts a new point into the given subpath at the specified position.

This method keeps the subpath closed if it is closed, and open when it was open. So it can change the properties of the point inserted. You might need to update the point before/after to get the wanted result e.g. when you insert the point into a curve.

Parameters:
point to insert
pointIndex where the point should be inserted
Returns:
true on success, false when pointIndex is out of bounds

bool KoPathShape::isClosedSubpath ( int  subpathIndex  ) 

Check if subpath is closed.

Parameters:
subpathIndex of the subpath to check
Returns:
true when the subpath is closed, false otherwise

bool KoPathShape::join ( int  subpathIndex  ) 

Joins the given subpath with the following one.

Joins the given subpath with the following one by inserting a segment between the two subpathes. This does nothing if the given ot the following subpath is closed or on the last subpath of the path.

Parameters:
subpathIndex of the subpath which will be joined with its following one
Returns:
true if the subpath was joined, otherwise false

KoPathPoint * KoPathShape::lineTo ( const QPointF &  p  ) 

add a line

Adds a straight line between the last point and the given p.

Returns:
The newly created point

bool KoPathShape::loadOdf ( const KoXmlElement element,
KoShapeLoadingContext context 
) [virtual]

Load a shape from odf.

Parameters:
context the KoShapeLoadingContext used for loading
element element which represents the shape in odf
Returns:
false if loading failed

Implements KoShape.

bool KoPathShape::moveSubpath ( int  oldSubpathIndex,
int  newSubpathIndex 
)

Move the position of a subpath within a path.

Parameters:
oldSubpathIndex old index of the subpath
newSubpathIndex new index of the subpath
Returns:
true if the subpath was moved, otherwise false e.g. if an index is out of bounds

KoPathPoint * KoPathShape::moveTo ( const QPointF &  p  ) 

Start a new Subpath.

Moves the pen to p and starts a new subpath.

Returns:
The newly created point

QPointF KoPathShape::normalize (  )  [virtual]

Normalizes the path data.

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

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

Reimplemented in KoParameterShape.

KoPathPointIndex KoPathShape::openSubpath ( const KoPathPointIndex &  pointIndex  ) 

Open a closed subpath.

The subpath is opened by removing the segment before the given point, makeing the given point the new start point of the subpath.

Parameters:
pointIndex to where to open the closed subpath
Returns:
the new position of the old first point in the subpath otherwise KoPathPointIndex( -1, -1 )

KoPathPointIndex KoPathShape::pathPointIndex ( const KoPathPoint point  )  const

Get the path point index of a point.

Parameters:
point for which you want to get the info
Returns:
path point index of the point if it exists otherwise KoPathPointIndex( -1, -1 )

QString KoPathShape::pathShapeId (  )  const [virtual]

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

KoPathPoint * KoPathShape::pointByIndex ( const KoPathPointIndex &  pointIndex  )  const

Get the point defined by a path point index.

Parameters:
pointIndex of the point to get
Returns:
KoPathPoint on success, 0 otherwise e.g. out of bounds

int KoPathShape::pointCount (  )  const

Get the number of points in the path.

Returns:
The number of points in the path

int KoPathShape::pointCountSubpath ( int  subpathIndex  )  const

Get the number of points in a subpath.

Returns:
The number of points in the subpath or -1 if subpath out of bounds

QList< KoPathPoint * > KoPathShape::pointsAt ( const QRectF &  r  ) 

Returns the path points within the given rectangle.

Parameters:
r the rectangle the requested points are in
Returns:
list of points within the rectangle

KoPathPoint * KoPathShape::removePoint ( const KoPathPointIndex &  pointIndex  ) 

Removes point from the path.

Note that the ownership of the point will pass to the caller.

Parameters:
pointIndex of the point which should be removed
Returns:
The removed point on success, otherwise 0

KoSubpath * KoPathShape::removeSubpath ( int  subpathIndex  ) 

Remove subpath from path.

Returns:
The removed subpath on succes, 0 otherwise.

bool KoPathShape::reverseSubpath ( int  subpathIndex  ) 

Reverse subpath.

The last point becomes the first point and the first one becomes the last one.

Parameters:
subpathIndex the pointIndex of the subpath to reverse

void KoPathShape::saveOdf ( KoShapeSavingContext context  )  const [virtual]

store the shape data as ODF XML.

This is the method that will be called when saving a shape as a described in¬ OpenDocument 9.2 Drawing Shapes.

See also:
saveOdfAttributes

Implements KoShape.

KoPathSegment KoPathShape::segmentByIndex ( const KoPathPointIndex &  pointIndex  )  const

Get the segment defined by a path point index.

A semgent is defined by the point index of the first point in the segment. A segment contains the defined point and its following point. If the subpath is closed and the and the pointIndex point to the last point in the subpath, the following point is the first point in the subpath.

Parameters:
pointIndex of the first point of the segment
Returns:
Segment containing both points of the segment or KoPathSegment( 0, 0 ) on error e.g. out of bounds

QList< KoPathSegment > KoPathShape::segmentsAt ( const QRectF &  r  ) 

Returns the list of path segments within the given rectangle.

Parameters:
r the rectangle the requested segments are in
Returns:
list of segments within the rectangle

bool KoPathShape::separate ( QList< KoPathShape * > &  separatedPaths  ) 

Creates separate path shapes, one for each existing subpath.

Parameters:
separatedPaths the list which contains the separated path shapes
Returns:
true if separating the path was successful, false otherwise

int KoPathShape::subpathCount (  )  const

Get the number of subpaths in the path.

Returns:
The number of subpaths in the path


The documentation for this class was generated from the following files:
Generated on Sun Jul 20 22:37:16 2008 for libs/flake by  doxygen 1.4.7