karbon

vpath.h
1/* This file is part of the KDE project
2 Copyright (C) 2002, 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 __VPATH_H__
21#define __VPATH_H__
22
23
24#include <KoPoint.h>
25
26#include "vobject.h"
27#include <koffice_export.h>
28
29class TQDomElement;
30class TQWMatrix;
31class VSubpathIteratorList;
32class VSegment;
33class VVisitor;
34
35
41
42class KARBONBASE_EXPORT VSubpath : public VObject
43{
44 friend class VSubpathIterator;
45
46public:
47 VSubpath( VObject* parent );
48 VSubpath( const VSubpath& list );
49 VSubpath( const VSegment& segment );
50 virtual ~VSubpath();
51
52 const KoPoint& currentPoint() const;
53
54 bool moveTo( const KoPoint& p );
55 bool lineTo( const KoPoint& p );
56 bool curveTo(
57 const KoPoint& p1, const KoPoint& p2, const KoPoint& p3 );
58 bool curve1To(
59 const KoPoint& p2, const KoPoint& p3 );
60 bool curve2To(
61 const KoPoint& p1, const KoPoint& p3 );
62 bool arcTo(
63 const KoPoint& p1, const KoPoint& p2, const double r );
64
65 bool isClosed() const
66 {
67 return m_isClosed;
68 }
69
70 void close();
71
72
77 bool pointIsInside( const KoPoint& p ) const;
78
82 bool intersects( const VSegment& segment ) const;
83
84
88 bool counterClockwise() const;
89
93 void revert();
94
95
100 bool isEmpty() const
101 {
102 return count() <= 1;
103 }
104
105
106 virtual const KoRect& boundingBox() const;
107
108
109 virtual void save( TQDomElement& /*element*/) const
110 { } // VSubpaths cant be saved.
111
112 // TODO: remove this backward compatibility function after koffice 1.3.x
113 virtual void load( const TQDomElement& element );
114
115 void saveSvgPath( TQString & ) const;
116
117
118 virtual VSubpath* clone() const;
119
120 virtual void accept( VVisitor& visitor );
121
122
123 // General list stuff.
124 VSubpath& operator=( const VSubpath& list );
125
126 bool insert( const VSegment* segment );
127 bool insert( uint i, const VSegment* segment );
128 void prepend( const VSegment* segment );
129 void append( const VSegment* segment );
130 void clear();
131
132 uint count() const
133 {
134 return m_number;
135 }
136
137 VSegment* current() const
138 {
139 return m_current;
140 }
141
142 VSegment* getFirst() const
143 {
144 return m_first;
145 }
146
147 VSegment* getLast() const
148 {
149 return m_last;
150 }
151
152 VSegment* first();
153 VSegment* last();
154 VSegment* prev();
155 VSegment* next();
156
157private:
158 VSegment* locate( uint index );
159
160 VSegment* m_first;
161 VSegment* m_last;
162 VSegment* m_current;
163
164 int m_currentIndex;
165 uint m_number : 31;
166
167 bool m_isClosed : 1;
168
169 VSubpathIteratorList* m_iteratorList;
170};
171
172
178
179class KARBONBASE_EXPORT VSubpathIterator
180{
181 friend class VSubpathIteratorList;
182
183public:
184 VSubpathIterator( const VSubpath& list );
185 VSubpathIterator( const VSubpathIterator& itr );
186 ~VSubpathIterator();
187
188 VSubpathIterator& operator=( const VSubpathIterator& itr );
189
190 VSegment* current() const;
191 VSegment* operator()();
192 VSegment* operator++();
193 VSegment* operator+=( uint i );
194 VSegment* operator--();
195 VSegment* operator-=( uint i );
196
197private:
198 VSubpath* m_list;
199 VSegment* m_current;
200};
201
202#endif
203
VObject(VObject *parent, VState state=edit)
Constructs a new object that is child of parent and has the given state.
Definition vobject.cpp:36
virtual VObject * clone() const =0
Create an exact copy of this object.
VObject * parent() const
Returns pointer to current parent object.
Definition vobject.h:147
virtual void accept(VVisitor &)
Accept a VVisitor.
Definition vobject.h:236
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
A class representing lines and beziers.
Definition vsegment.h:43
VSubpath provides a sophisticated list of VSegment.
Definition vpath.h:43
virtual void save(TQDomElement &) const
Save this object's state to xml.
Definition vpath.h:109
bool counterClockwise() const
Returns false if segmentlist is oriented clockwise.
Definition vpath.cpp:590
void revert()
Reverts the winding orientation.
Definition vpath.cpp:650
bool pointIsInside(const KoPoint &p) const
Returns true if point p is located inside the path.
Definition vpath.cpp:416
bool isEmpty() const
Returns true if the current path is "emtpy".
Definition vpath.h:100
bool intersects(const VSegment &segment) const
Returns true if the segment intersects this path.
Definition vpath.cpp:562
The abstract visitor class.
Definition vvisitor.h:51