~ubuntu-branches/ubuntu/edgy/koffice/edgy-updates

« back to all changes in this revision

Viewing changes to karbon/core/vcomposite.h

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20040509113300-xi5t1z4yxe7n03x7
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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., 59 Temple Place - Suite 330,
 
17
   Boston, MA 02111-1307, USA.
 
18
*/
 
19
 
 
20
#ifndef __VCOMPOSITE_H__
 
21
#define __VCOMPOSITE_H__
 
22
 
 
23
 
 
24
#include <qptrlist.h>
 
25
 
 
26
#include <koPoint.h>
 
27
 
 
28
#include "vobject.h"
 
29
#include "svgpathparser.h"
 
30
#include "vfillrule.h"
 
31
 
 
32
 
 
33
class QDomElement;
 
34
class VPainter;
 
35
class VSegment;
 
36
class VVisitor;
 
37
class VSubpath;
 
38
 
 
39
typedef QPtrList<VSubpath> VSubpathList;
 
40
typedef QPtrListIterator<VSubpath> VSubpathListIterator;
 
41
 
 
42
 
 
43
/**
 
44
 * A composite path consists of one or many subpaths.
 
45
 */
 
46
 
 
47
class VPath : public VObject, SVGPathParser
 
48
{
 
49
public:
 
50
        VPath( VObject* parent, VState state = normal );
 
51
        VPath( const VPath& path );
 
52
        virtual ~VPath();
 
53
 
 
54
        virtual DCOPObject* dcopObject();
 
55
 
 
56
        /**
 
57
         * Returns the knot of the last segment of the last subpath.
 
58
         */
 
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
 
 
105
        /**
 
106
         * A convenience function to aproximate a circular arc with a
 
107
         * bezier curve. Input: 2 tangent vectors and a radius (same as in PostScript).
 
108
         */
 
109
 
 
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
 
 
125
        /**
 
126
         * Closes the current subpath.
 
127
         */
 
128
        void close();
 
129
 
 
130
        /**
 
131
         * Combines two composite paths. For example, the letter "O" is a combination
 
132
         * of a larger and a smaller ellipitical path.
 
133
         */
 
134
        void combine( const VPath& path );
 
135
 
 
136
        /**
 
137
         * Adds a path to the composite path.
 
138
         */
 
139
        void combinePath( const VSubpath& path );
 
140
 
 
141
 
 
142
        /**
 
143
         * Returns true if point p is located inside the composite.
 
144
         */
 
145
        bool pointIsInside( const KoPoint& p ) const;
 
146
 
 
147
 
 
148
        /**
 
149
         * Returns true if the segment intersects this composite.
 
150
         */
 
151
        bool intersects( const VSegment& segment ) const;
 
152
 
 
153
 
 
154
        const VSubpathList& paths() const
 
155
        {
 
156
                return m_paths;
 
157
        }
 
158
 
 
159
        virtual const KoRect& boundingBox() const;
 
160
 
 
161
 
 
162
        VFillRule fillMode() const;
 
163
 
 
164
        // TODO remove these functions.
 
165
        VFillRule fillRule() const
 
166
        {
 
167
                return m_fillRule;
 
168
        }
 
169
 
 
170
        void setFillRule( VFillRule fillRule )
 
171
        {
 
172
                m_fillRule = fillRule;
 
173
        }
 
174
 
 
175
 
 
176
        virtual void draw( VPainter *painter, const KoRect* rect = 0L ) const;
 
177
 
 
178
        bool drawCenterNode() const
 
179
        {
 
180
                return m_drawCenterNode;
 
181
        }
 
182
 
 
183
        void setDrawCenterNode( bool drawCenterNode = true )
 
184
        {
 
185
                m_drawCenterNode = drawCenterNode;
 
186
        }
 
187
 
 
188
 
 
189
        virtual void save( QDomElement& element ) const;
 
190
        virtual void load( const QDomElement& element );
 
191
 
 
192
        virtual VPath* clone() const;
 
193
 
 
194
        virtual void accept( VVisitor& visitor );
 
195
 
 
196
        void transform( const QString &transform );
 
197
        static QWMatrix parseTransform( const QString &transform );
 
198
 
 
199
        void transform( const QWMatrix &mat )
 
200
        {
 
201
                m_matrix *= mat;
 
202
        }
 
203
 
 
204
 
 
205
        void loadSvgPath( const QString & );
 
206
        void saveSvgPath( QString & ) const;
 
207
 
 
208
protected:
 
209
        void writeTransform( QDomElement & ) const;
 
210
 
 
211
        /// For svg path data parsing.
 
212
        virtual void svgMoveTo( double x1, double y1, bool abs = true );
 
213
        virtual void svgLineTo( double x1, double y1, bool abs = true );
 
214
        virtual void svgCurveToCubic( double x1, double y1, double x2, double y2, double x, double y, bool abs = true );
 
215
        virtual void svgClosePath();
 
216
 
 
217
protected:
 
218
        QWMatrix m_matrix;
 
219
 
 
220
private:
 
221
        /**
 
222
         * List of subpaths.
 
223
         */
 
224
        VSubpathList m_paths;
 
225
 
 
226
        /// Should a center node be drawn?
 
227
        bool            m_drawCenterNode;
 
228
        VFillRule       m_fillRule      : 1;
 
229
};
 
230
 
 
231
#endif