karbon

vcomposite.h
1/* This file is part of the KDE project
2 Copyright (C) 2001, 2002, 2003 The Karbon Developers
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#ifndef __VCOMPOSITE_H__
21#define __VCOMPOSITE_H__
22
23
24#include <tqptrlist.h>
25
26#include <KoPoint.h>
27
28#include "vobject.h"
29#include "svgpathparser.h"
30#include "vfillrule.h"
31#include <koffice_export.h>
32
33class TQDomElement;
34class VPainter;
35class VSegment;
36class VVisitor;
37class VSubpath;
38
39typedef TQPtrList<VSubpath> VSubpathList;
40typedef TQPtrListIterator<VSubpath> VSubpathListIterator;
41
42
47class KARBONBASE_EXPORT VPath : public VObject, SVGPathParser
48{
49public:
50 VPath( VObject* parent, VState state = normal );
51 VPath( const VPath& path );
52 virtual ~VPath();
53
54 virtual DCOPObject* dcopObject();
55
59 const KoPoint& currentPoint() const;
60
61
62 bool moveTo( const KoPoint& p );
63 bool lineTo( const KoPoint& p );
64
65 /*
66 curveTo():
67
68 p1 p2
69 O ____ O
70 : _/ \_ :
71 :/ \:
72 x x
73 currP p3
74 */
75
76 bool curveTo(
77 const KoPoint& p1, const KoPoint& p2, const KoPoint& p3 );
78
79 /*
80 curve1To():
81
82 p2
83 ____ O
84 __/ \ :
85 / \:
86 x x
87 currP p3
88 */
89
90 bool curve1To( const KoPoint& p2, const KoPoint& p3 );
91
92 /*
93 curve2To():
94
95 p1
96 O ____
97 : / \__
98 :/ \
99 x x
100 currP p3
101 */
102
103 bool curve2To( const KoPoint& p1, const KoPoint& p3 );
104
110 /*
111 arcTo():
112
113 p1 x....__--x....x p2
114 : _/
115 : /
116 :/
117 |
118 x
119 |
120 |
121 x currP
122 */
123 bool arcTo( const KoPoint& p1, const KoPoint& p2, double r );
124
128 void close();
129
130 bool isClosed() const;
135 void combine( const VPath& path );
136
140 void combinePath( const VSubpath& path );
141
142
146 bool pointIsInside( const KoPoint& p ) const;
147
148
152 bool intersects( const VSegment& segment ) const;
153
154
155 const VSubpathList& paths() const
156 {
157 return m_paths;
158 }
159
160 virtual const KoRect& boundingBox() const;
161
162
163 VFillRule fillMode() const;
164
165 // TODO remove these functions.
166 VFillRule fillRule() const
167 {
168 return m_fillRule;
169 }
170
171 void setFillRule( VFillRule fillRule )
172 {
173 m_fillRule = fillRule;
174 }
175
176
177 virtual void draw( VPainter *painter, const KoRect* rect = 0L ) const;
178
179 bool drawCenterNode() const
180 {
181 return m_drawCenterNode;
182 }
183
184 void setDrawCenterNode( bool drawCenterNode = true )
185 {
186 m_drawCenterNode = drawCenterNode;
187 }
188
189
190 virtual void save( TQDomElement& element ) const;
191 virtual void saveOasis( KoStore *store, KoXmlWriter *docWriter, KoGenStyles &mainStyles, int &index ) const;
192 virtual void load( const TQDomElement& element );
193 virtual bool loadOasis( const TQDomElement &element, KoOasisLoadingContext &context );
194
195 virtual VPath* clone() const;
196
197 virtual void accept( VVisitor& visitor );
198
199 void transform( const TQString &transform );
200 void transformOasis( const TQString &transform );
201
202 static TQWMatrix parseTransform( const TQString &transform );
203
204 void transform( const TQWMatrix &mat )
205 {
206 m_matrix *= mat;
207 }
208
209
210 void loadSvgPath( const TQString & );
211 void saveSvgPath( TQString & ) const;
212
213protected:
214 TQString buildSvgTransform() const;
215 TQString buildSvgTransform( const TQWMatrix &mat ) const;
216 TQString buildOasisTransform() const;
217 TQString buildOasisTransform( const TQWMatrix &mat ) const;
218
219 void transformByViewbox( const TQDomElement &element, TQString viewbox );
220
222 virtual void svgMoveTo( double x1, double y1, bool abs = true );
223 virtual void svgLineTo( double x1, double y1, bool abs = true );
224 virtual void svgCurveToCubic( double x1, double y1, double x2, double y2, double x, double y, bool abs = true );
225 virtual void svgClosePath();
226
227 virtual void saveOasisFill( KoGenStyles &mainStyles, KoGenStyle &stylesojectauto ) const;
228 TQWMatrix parseOasisTransform( const TQString &transform );
229
230protected:
231 TQWMatrix m_matrix;
232
233private:
237 VSubpathList m_paths;
238
240 bool m_drawCenterNode;
241 VFillRule m_fillRule : 1;
242};
243
244#endif
The base class for all karbon objects.
Definition vobject.h:50
virtual VObject * clone() const =0
Create an exact copy of this object.
virtual void accept(VVisitor &)
Accept a VVisitor.
Definition vobject.h:236
virtual void saveOasis(KoStore *store, KoXmlWriter *docWriter, KoGenStyles &mainStyles, int &index) const
Save this object's state to OpenDocument.
Definition vobject.cpp:116
virtual DCOPObject * dcopObject()
Returns pointer to internal DCOP object.
Definition vobject.cpp:75
virtual const KoRect & boundingBox() const
Calculates the tightest bounding box around the object.
Definition vobject.h:111
virtual void load(const TQDomElement &element)
Load this object's state from xml and initialize this object accordingly.
Definition vobject.cpp:157
virtual void save(TQDomElement &element) const
Save this object's state to xml.
Definition vobject.cpp:102
virtual bool loadOasis(const TQDomElement &element, KoOasisLoadingContext &context)
Load this object's state from OpenDocument and initialize this object accordingly.
Definition vobject.cpp:181
virtual void draw(VPainter *painter, const KoRect *rect=0L) const
Draw the object to a painting device.
Definition vobject.h:100
A composite path consists of one or many subpaths.
Definition vcomposite.h:48
A class representing lines and beziers.
Definition vsegment.h:43
VSubpath provides a sophisticated list of VSegment.
Definition vpath.h:43
The abstract visitor class.
Definition vvisitor.h:51