libs/flake

KoPathShape.h

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2006 Thorsten Zachmann <zachmann@kde.org>
00003    Copyright (C) 2007,2009 Thomas Zander <zander@kde.org>
00004    Copyright (C) 2006-2008 Jan Hambrecht <jaham@gmx.net>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #ifndef KOPATHSHAPE_H
00023 #define KOPATHSHAPE_H
00024 
00025 #include "flake_export.h"
00026 
00027 #include <QMap>
00028 
00029 #include "KoShape.h"
00030 #include "KoPathSegment.h"
00031 
00032 #define KoPathShapeId "KoPathShape"
00033 
00034 class KoPathShape;
00035 class KoPathPoint;
00036 class KoPathShapePrivate;
00037 
00038 typedef QPair<int, int> KoPathPointIndex;
00039 typedef QMap<KoPathShape *, QSet<KoPathPointIndex> > KoPathShapePointIndexMap;
00040 
00042 typedef QList<KoPathPoint *> KoSubpath;
00043 typedef QList<KoSubpath *> KoSubpathList;
00045 typedef QPair<KoSubpath*, int> KoPointPosition;
00074 class FLAKE_EXPORT KoPathShape : public KoShape
00075 {
00076 public:
00080     KoPathShape();
00081 
00085     virtual ~KoPathShape();
00086 
00088     virtual void paint(QPainter &painter, const KoViewConverter &converter);
00089     virtual void paintPoints(QPainter &painter, const KoViewConverter &converter, int handleRadius);
00091     virtual QPainterPath outline() const;
00093     virtual QRectF boundingRect() const;
00095     virtual QSizeF size() const;
00107     virtual void setSize(const QSizeF &size);
00109     virtual bool hitTest(const QPointF &position) const;
00110 
00111     // reimplemented
00112     virtual void saveOdf(KoShapeSavingContext & context) const;
00113     // reimplemented
00114     virtual bool loadOdf(const KoXmlElement & element, KoShapeLoadingContext &context);
00115 
00117     void clear();
00125     KoPathPoint * moveTo(const QPointF &p);
00126 
00134     KoPathPoint * lineTo(const QPointF &p);
00135 
00148     KoPathPoint * curveTo(const QPointF &c1, const QPointF &c2, const QPointF &p);
00149 
00161     KoPathPoint * curveTo(const QPointF &c, const QPointF &p);
00162 
00176     KoPathPoint * arcTo(qreal rx, qreal ry, qreal startAngle, qreal sweepAngle);
00177 
00178 
00182     void close();
00183 
00193     void closeMerge();
00194 
00204     virtual QPointF normalize();
00205 
00211     QList<KoPathPoint*> pointsAt(const QRectF &r);
00212 
00218     QList<KoPathSegment> segmentsAt(const QRectF &r);
00219 
00227     KoPathPointIndex pathPointIndex(const KoPathPoint *point) const;
00228 
00236     KoPathPoint * pointByIndex(const KoPathPointIndex &pointIndex) const;
00237 
00250     KoPathSegment segmentByIndex(const KoPathPointIndex &pointIndex) const;
00251 
00257     int pointCount() const;
00258 
00264     int subpathCount() const;
00265 
00271     int pointCountSubpath(int subpathIndex) const;
00272 
00280     bool isClosedSubpath(int subpathIndex);
00281 
00296     bool insertPoint(KoPathPoint* point, const KoPathPointIndex &pointIndex);
00297 
00308     KoPathPoint * removePoint(const KoPathPointIndex &pointIndex);
00309 
00324     bool breakAfter(const KoPathPointIndex &pointIndex);
00325 
00338     bool join(int subpathIndex);
00339 
00348     bool moveSubpath(int oldSubpathIndex, int newSubpathIndex);
00349 
00360     KoPathPointIndex openSubpath(const KoPathPointIndex &pointIndex);
00361 
00371     KoPathPointIndex closeSubpath(const KoPathPointIndex &pointIndex);
00372 
00380     bool reverseSubpath(int subpathIndex);
00381 
00387     KoSubpath * removeSubpath(int subpathIndex);
00388 
00395     bool addSubpath(KoSubpath * subpath, int subpathIndex);
00396 
00402     bool combine(KoPathShape *path);
00403 
00409     bool separate(QList<KoPathShape*> & separatedPaths);
00410 
00411 #ifndef NDEBUG
00412 
00415     void debugPath();
00416 #endif
00417 
00431     virtual QString pathShapeId() const;
00432 
00434     QString toString(const QMatrix &matrix) const;
00435 
00437     Qt::FillRule fillRule() const;
00438 
00440     void setFillRule(Qt::FillRule fillRule);
00441 
00443     static KoPathShape * fromQPainterPath(const QPainterPath &path);
00444 
00445 protected:
00447     KoPathShape(KoPathShapePrivate &);
00448 
00449 private:
00450     // TODO move all the private methods to live on the d pointer object
00451     void map(const QMatrix &matrix);
00452 
00453     void updateLast(KoPathPoint ** lastPoint);
00454 
00456     void closeSubpath(KoSubpath *subpath);
00458     void closeMergeSubpath(KoSubpath *subpath);
00459 
00465     KoSubpath * subPath(int subpathIndex) const;
00466 #ifndef NDEBUG
00467     void paintDebug(QPainter &painter);
00468 #endif
00470     virtual QString saveStyle(KoGenStyle &style, KoShapeSavingContext &context) const;
00472     virtual void loadStyle(const KoXmlElement & element, KoShapeLoadingContext &context);
00473 
00474 protected:
00475     QRectF handleRect(const QPointF &p, qreal radius) const;
00490     int arcToCurve(qreal rx, qreal ry, qreal startAngle, qreal sweepAngle, const QPointF & offset, QPointF * curvePoints) const;
00491 
00493     QRectF loadOdfViewbox(const KoXmlElement & element) const;
00495     void applyViewboxTransformation(const KoXmlElement & element);
00496 
00520     QString nodeTypes() const;
00521 
00525     void loadNodeTypes(const KoXmlElement & element);
00526 
00533     QMatrix resizeMatrix( const QSizeF & newSize ) const;
00534 
00535     KoSubpathList m_subpaths;
00536 
00537 private:
00538     Q_DECLARE_PRIVATE(KoPathShape)
00539 };
00540 
00541 #endif /* KOPATHSHAPE_H */