00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef KOPATHSHAPE_H
00021 #define KOPATHSHAPE_H
00022
00023 #include <koffice_export.h>
00024
00025 #include <QFlags>
00026 #include <QPainterPath>
00027 #include <QSet>
00028 #include <QList>
00029
00030 #include "KoShape.h"
00031
00032 #define KoPathShapeId "KoPathShape"
00033
00034 class KoPathShape;
00035 class KoPointGroup;
00036 class KoPathPoint;
00037
00038 typedef QMap<KoPathShape *, QSet<KoPathPoint *> > KoPathShapePointMap;
00039 typedef QPair<int,int> KoPathPointIndex;
00040 typedef QMap<KoPathShape *, QSet<KoPathPointIndex> > KoPathShapePointIndexMap;
00041
00051 class KoPathPoint
00052 {
00053 public:
00054 enum KoPointProperty
00055 {
00056 Normal = 0,
00057 CanHaveControlPoint1 = 1,
00058 CanHaveControlPoint2 = 2,
00059 HasControlPoint1 = 4,
00060 HasControlPoint2 = 8,
00061 StartSubpath = 16,
00062 CloseSubpath = 32,
00063 IsSmooth = 64,
00064 IsSymmetric = 128
00065 };
00066 Q_DECLARE_FLAGS( KoPointProperties, KoPointProperty )
00067
00068
00069 enum KoPointType {
00070 Node,
00071 ControlPoint1,
00072 ControlPoint2
00073 };
00074
00082 KoPathPoint( KoPathShape * path, const QPointF & point, KoPointProperties properties = Normal )
00083 : m_shape( path )
00084 , m_point( point )
00085 , m_properties( properties )
00086 , m_pointGroup( 0 )
00087 {}
00088
00092 KoPathPoint( const KoPathPoint & pathPoint );
00093
00097 KoPathPoint& operator=( const KoPathPoint &rhs );
00098
00102 ~KoPathPoint() {}
00103
00109 QPointF point() const { return m_point; }
00110
00118 QPointF controlPoint1() const { return m_controlPoint1; }
00119
00127 QPointF controlPoint2() const { return m_controlPoint2; }
00128
00134 void setPoint( const QPointF & point );
00135
00141 void setControlPoint1( const QPointF & point );
00142
00148 void setControlPoint2( const QPointF & point );
00149
00150 void removeControlPoint1() { }
00151 void removeControlPoint2() { }
00152
00158 KoPointProperties properties() const { return m_properties; }
00159
00164 void setProperties( KoPointProperties properties );
00165
00170 void setProperty( KoPointProperty property );
00171
00176 void unsetProperty( KoPointProperty property );
00177
00184 bool activeControlPoint1() const;
00185
00192 bool activeControlPoint2() const;
00193
00203 void map( const QMatrix &matrix, bool mapGroup = false );
00204
00210 void paint(QPainter &painter, const QSizeF &size, bool selected );
00211
00216 void setParent( KoPathShape* parent );
00217
00222 KoPathShape * parent() const { return m_shape; }
00223
00231 QRectF boundingRect() const;
00232
00240 void reverse();
00241 protected:
00242 friend class KoPointGroup;
00243 friend class KoPathShape;
00244 void removeFromGroup();
00245 void addToGroup( KoPointGroup *pointGroup );
00246 KoPointGroup * group() { return m_pointGroup; }
00247 private:
00248 KoPathShape * m_shape;
00249 QPointF m_point;
00250 QPointF m_controlPoint1;
00251 QPointF m_controlPoint2;
00252 KoPointProperties m_properties;
00253 KoPointGroup * m_pointGroup;
00254 };
00255
00264 class KoPointGroup
00265 {
00266 public:
00267 KoPointGroup() {}
00268 ~KoPointGroup() {}
00269
00273 void add( KoPathPoint * point );
00281 void remove( KoPathPoint * point );
00282
00283 void map( const QMatrix &matrix );
00284
00290 const QSet<KoPathPoint *> & points() const { return m_points; }
00291
00292 private:
00293 QSet<KoPathPoint *> m_points;
00294 };
00295
00297 typedef QList<KoPathPoint *> KoSubpath;
00298 typedef QList<KoSubpath *> KoSubpathList;
00300 typedef QPair<KoPathPoint*,KoPathPoint*> KoPathSegment;
00302 typedef QPair<KoSubpath*, int> KoPointPosition;
00331 class FLAKE_EXPORT KoPathShape : public KoShape
00332 {
00333 public:
00337 KoPathShape();
00338
00342 virtual ~KoPathShape();
00343
00344 virtual void paint(QPainter &painter, const KoViewConverter &converter);
00345 virtual void paintPoints( QPainter &painter, const KoViewConverter &converter );
00346 virtual const QPainterPath outline() const;
00347 virtual QRectF boundingRect() const;
00348 virtual QSizeF size() const;
00349 virtual QPointF position() const;
00350 virtual void resize( const QSizeF &size );
00351
00359 KoPathPoint * moveTo( const QPointF &p );
00360
00368 KoPathPoint * lineTo( const QPointF &p );
00369
00381 KoPathPoint * curveTo( const QPointF &c1, const QPointF &c2, const QPointF &p );
00382
00395 KoPathPoint * arcTo( double rx, double ry, double startAngle, double sweepAngle );
00396
00400 void close();
00401
00411 void closeMerge();
00412
00419 void update();
00420
00429 virtual QPointF normalize();
00430
00436 QList<KoPathPoint*> pointsAt( const QRectF &r );
00437
00444 void insertPoint( KoPathPoint* point, KoSubpath* subpath, int position );
00445
00451 KoPointPosition removePoint( KoPathPoint *point );
00452
00459 KoPathPoint* splitAt( const KoPathSegment &segment, double t );
00460
00474 bool breakAt( KoPathPoint *breakPoint, KoPathPoint* &insertedPoint );
00475
00489 bool breakAt( const KoPathSegment &segment );
00490
00502 bool joinBetween( KoPathPoint *endPoint1, KoPathPoint *endPoint2 );
00503
00509 bool combine( KoPathShape *path );
00510
00516 bool separate( QList<KoPathShape*> & separatedPaths );
00517
00518 #if 0 // not used yet
00519
00525 bool insertPointAfter( KoPathPoint *point, KoPathPoint *prevPoint );
00526
00533 bool insertPointBefore( KoPathPoint *point, KoPathPoint *nextPoint );
00534
00543 KoPathPoint* prevPoint( KoPathPoint* point );
00544 #endif
00545
00554 KoPathPoint* nextPoint( KoPathPoint* point );
00555
00559 void debugPath();
00560
00568 QPointF shapeToDocument( const QPointF &point ) const;
00569
00577 QRectF shapeToDocument( const QRectF &rect ) const;
00578
00586 QPointF documentToShape( const QPointF &point ) const;
00587
00595 QRectF documentToShape( const QRectF &rect ) const;
00596
00597 private:
00598 void map( const QMatrix &matrix );
00599
00600 void updateLast( KoPathPoint ** lastPoint );
00601
00603 void closeSubpath( KoSubpath *subpath );
00605 void closeMergeSubpath( KoSubpath *subpath );
00607 KoPointPosition findPoint( KoPathPoint* point );
00609 void reverseSubpath( KoSubpath &subpath );
00610 #ifndef NDEBUG
00611 void paintDebug( QPainter &painter );
00612 #endif
00613
00614 protected:
00615 QRectF handleRect( const QPointF &p ) const;
00630 int arcToCurve( double rx, double ry, double startAngle, double sweepAngle, const QPointF & offset, QPointF * curvePoints ) const;
00631
00632 KoSubpathList m_subpaths;
00633 };
00634
00635 Q_DECLARE_OPERATORS_FOR_FLAGS( KoPathPoint::KoPointProperties )
00636
00637 #endif