karbon

vcomposite.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001, 2002, 2003 The Karbon Developers
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef __VCOMPOSITE_H__
00021 #define __VCOMPOSITE_H__
00022 
00023 
00024 #include <qptrlist.h>
00025 
00026 #include <KoPoint.h>
00027 
00028 #include "vobject.h"
00029 #include "svgpathparser.h"
00030 #include "vfillrule.h"
00031 #include <koffice_export.h>
00032 
00033 class QDomElement;
00034 class VPainter;
00035 class VSegment;
00036 class VVisitor;
00037 class VSubpath;
00038 
00039 typedef QPtrList<VSubpath> VSubpathList;
00040 typedef QPtrListIterator<VSubpath> VSubpathListIterator;
00041 
00042 
00047 class KARBONBASE_EXPORT VPath : public VObject, SVGPathParser
00048 {
00049 public:
00050     VPath( VObject* parent, VState state = normal );
00051     VPath( const VPath& path );
00052     virtual ~VPath();
00053 
00054     virtual DCOPObject* dcopObject();
00055 
00059     const KoPoint& currentPoint() const;
00060 
00061 
00062     bool moveTo( const KoPoint& p );
00063     bool lineTo( const KoPoint& p );
00064 
00065     /*
00066     curveTo():
00067 
00068        p1          p2
00069         O   ____   O
00070         : _/    \_ :
00071         :/        \:
00072         x          x
00073     currP          p3
00074     */
00075 
00076     bool curveTo(
00077         const KoPoint& p1, const KoPoint& p2, const KoPoint& p3 );
00078 
00079     /*
00080     curve1To():
00081 
00082                    p2
00083              ____  O
00084           __/    \ :
00085          /        \:
00086         x          x
00087     currP          p3
00088     */
00089 
00090     bool curve1To( const KoPoint& p2, const KoPoint& p3 );
00091 
00092     /*
00093     curve2To():
00094 
00095        p1
00096         O  ____
00097         : /    \__
00098         :/        \
00099         x          x
00100     currP          p3
00101     */
00102 
00103     bool curve2To( const KoPoint& p1, const KoPoint& p3 );
00104 
00110     /*
00111     arcTo():
00112     
00113        p1 x....__--x....x p2
00114           :  _/
00115           : /
00116           :/
00117           |
00118           x
00119           |
00120           |
00121           x currP
00122      */
00123     bool arcTo( const KoPoint& p1, const KoPoint& p2, double r );
00124 
00128     void close();
00129 
00130     bool isClosed() const;
00135     void combine( const VPath& path );
00136 
00140     void combinePath( const VSubpath& path );
00141 
00142 
00146     bool pointIsInside( const KoPoint& p ) const;
00147 
00148 
00152     bool intersects( const VSegment& segment ) const;
00153 
00154 
00155     const VSubpathList& paths() const
00156     {
00157         return m_paths;
00158     }
00159 
00160     virtual const KoRect& boundingBox() const;
00161 
00162 
00163     VFillRule fillMode() const;
00164 
00165     // TODO remove these functions.
00166     VFillRule fillRule() const
00167     {
00168         return m_fillRule;
00169     }
00170 
00171     void setFillRule( VFillRule fillRule )
00172     {
00173         m_fillRule = fillRule;
00174     }
00175 
00176 
00177     virtual void draw( VPainter *painter, const KoRect* rect = 0L ) const;
00178 
00179     bool drawCenterNode() const
00180     {
00181         return m_drawCenterNode;
00182     }
00183 
00184     void setDrawCenterNode( bool drawCenterNode = true )
00185     {
00186         m_drawCenterNode = drawCenterNode;
00187     }
00188 
00189 
00190     virtual void save( QDomElement& element ) const;
00191     virtual void saveOasis( KoStore *store, KoXmlWriter *docWriter, KoGenStyles &mainStyles, int &index ) const;
00192     virtual void load( const QDomElement& element );
00193     virtual bool loadOasis( const QDomElement &element, KoOasisLoadingContext &context );
00194 
00195     virtual VPath* clone() const;
00196 
00197     virtual void accept( VVisitor& visitor );
00198 
00199     void transform( const QString &transform );
00200     void transformOasis( const QString &transform );
00201 
00202     static QWMatrix parseTransform( const QString &transform );
00203 
00204     void transform( const QWMatrix &mat )
00205     {
00206         m_matrix *= mat;
00207     }
00208 
00209 
00210     void loadSvgPath( const QString & );
00211     void saveSvgPath( QString & ) const;
00212 
00213 protected:
00214     QString buildSvgTransform() const;
00215     QString buildSvgTransform( const QWMatrix &mat ) const;
00216     QString buildOasisTransform() const;
00217     QString buildOasisTransform( const QWMatrix &mat ) const;
00218 
00219     void transformByViewbox( const QDomElement &element, QString viewbox );
00220 
00222     virtual void svgMoveTo( double x1, double y1, bool abs = true );
00223     virtual void svgLineTo( double x1, double y1, bool abs = true );
00224     virtual void svgCurveToCubic( double x1, double y1, double x2, double y2, double x, double y, bool abs = true );
00225     virtual void svgClosePath();
00226 
00227     virtual void saveOasisFill( KoGenStyles &mainStyles, KoGenStyle &stylesojectauto ) const;
00228     QWMatrix parseOasisTransform( const QString &transform );
00229 
00230 protected:
00231     QWMatrix m_matrix;
00232 
00233 private:
00237     VSubpathList m_paths;
00238 
00240     bool        m_drawCenterNode;
00241     VFillRule   m_fillRule  : 1;
00242 };
00243 
00244 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys