karbon

vclipgroup.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2001, The Karbon Developers
3 Copyright (C) 2002, The Karbon Developers
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#ifdef HAVE_CONFIG_H
22#include <config.h>
23#endif
24
25#include <tqdom.h>
26
27#include <kdebug.h>
28
29#include "vclipgroup.h"
30#include "vgroup.h"
31#include "vcomposite.h"
32#include "vsegment.h"
33#include <vpainter.h>
34#include "vtext.h"
35VClipGroup::VClipGroup( VObject* parent, VState state ) : VGroup( parent, state ) {}
36VClipGroup::VClipGroup( const VClipGroup& group ) : VGroup( group ) {}
37
38VClipGroup::~VClipGroup() { }
39
40void VClipGroup::draw( VPainter* painter, const KoRect* rect ) const
41{
42 return VGroup::draw( painter, rect );
43 if(
44 state() == deleted ||
45 state() == hidden ||
46 state() == hidden_locked )
47 {
48 return;
49 }
50
51 VObjectListIterator itr = m_objects;
52
53 painter->save();
54
55 PathRenderer renderer( painter );
56 kdDebug(38000) << "calling painter setClipPath" << endl;
57 painter->setClipPath();
58
59 VObject *obj = itr.current();
60 obj->accept( renderer );
61 ++itr;
62
63 for( ; itr.current(); ++itr )
64 itr.current()->draw( painter, rect );
65
66 painter->restore();
67}
68
69VClipGroup* VClipGroup::clone() const
70{
71 return new VClipGroup( *this );
72}
73
74
75void VClipGroup::save( TQDomElement& element ) const
76{
77 TQDomElement me = element.ownerDocument().createElement( "CLIP" );
78 element.appendChild( me );
79
80 // save objects:
81 VObjectListIterator itr = m_objects;
82
83 for( ; itr.current(); ++itr )
84 itr.current()->save( me );
85}
86
87void VClipGroup::load( const TQDomElement& element )
88{
89 m_objects.setAutoDelete( true );
90 m_objects.clear();
91 m_objects.setAutoDelete( false );
92
93 TQDomNodeList list = element.childNodes();
94 for( uint i = 0; i < list.count(); ++i )
95 {
96 if( list.item( i ).isElement() )
97 {
98 TQDomElement e = list.item( i ).toElement();
99
100 if( e.tagName() == "COMPOSITE" || e.tagName() == "PATH" ) // TODO : remove COMPOSITE later
101 {
102 VPath* composite = new VPath( this );
103 composite->load( e );
104 append( composite );
105 }
106 else if( e.tagName() == "GROUP" )
107 {
108 VGroup* group = new VGroup( this );
109 group->load( e );
110 append( group );
111 }
112 else if( e.tagName() == "CLIP" )
113 {
114 VClipGroup* clip = new VClipGroup( this );
115 clip->load( e );
116 append( clip );
117 }
118 else if( e.tagName() == "TEXT" )
119 {
120#ifdef HAVE_KARBONTEXT
121 VText *text = new VText( this );
122 text->load( e );
123 append( text );
124#endif
125 }
126 }
127 }
128}
129
130PathRenderer::PathRenderer( VPainter *p_painter ) : VVisitor()
131{
132 m_painter = p_painter;
133}
134
135PathRenderer::~PathRenderer() {}
136
137void PathRenderer::visitVSubpath( VSubpath& path )
138{
139 if(!m_painter) return;
140
141 if(path.isEmpty()) return;
142
143 for(path.first(); VSegment *segment = path.current(); path.next() )
144 {
145 KoPoint p1;
146 KoPoint p2;
147 KoPoint p3;
148
149 TQString buffer;
150
151 if(segment->state() != VSegment::deleted)
152 {
153 if (segment->isBegin()) {
154 p1 = segment->point( 0 );
155
156 kdDebug(38000) << "calling painter.moveTo with " << p1 << endl;
157 m_painter->moveTo( p1 );
158 } else if (segment->isCurve()) {
159 p1 = segment->point( 0 );
160 p2 = segment->point( 1 );
161 p3 = segment->point( 2 );
162
163 kdDebug(38000) << "calling painter.curveTo with " << p1 << " " << p2 << " " << p3 << endl;
164 m_painter->curveTo( p1, p2, p3 );
165
166 } else if (segment->isLine()) {
167 p1 = segment->point( 0 );
168 kdDebug(38000) << "calling painter.lineTo with " << p1 << endl;
169 m_painter->lineTo( p1 );
170 }
171 }
172 }
173
175
176// if( path.isClosed() ) m_painter->closePath();
177}
178
Base class for clipping conglomerates the first child element is used for clipping.
Definition vclipgroup.h:34
virtual void draw(VPainter *painter, const KoRect *rect=0L) const
Draw the object to a painting device.
virtual void save(TQDomElement &element) const
Save this object's state to xml.
virtual void load(const TQDomElement &element)
Load this object's state from xml and initialize this object accordingly.
virtual VClipGroup * clone() const
Create an exact copy of this object.
Base class for all sort of VObject conglomerats.
Definition vgroup.h:35
void append(VObject *object)
Appends a new child object.
Definition vgroup.cpp:372
VGroup(VObject *parent, VState state=normal)
Constructs a new group object that is child of parent and has the given state.
Definition vgroup.cpp:54
virtual void draw(VPainter *painter, const KoRect *rect=0L) const
Draw the object to a painting device.
Definition vgroup.cpp:83
VObjectList m_objects
the list of grouped objects
Definition vgroup.h:113
virtual void load(const TQDomElement &element)
Load this object's state from xml and initialize this object accordingly.
Definition vgroup.cpp:263
The base class for all karbon objects.
Definition vobject.h:50
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 void accept(VVisitor &)
Accept a VVisitor.
Definition vobject.h:236
@ hidden_locked
hidden and locked (r/o)
Definition vobject.h:57
@ deleted
deleted, nearly dead
Definition vobject.h:58
@ hidden
hidden
Definition vobject.h:56
VState state() const
Get the state the object is in.
Definition vobject.h:154
A composite path consists of one or many subpaths.
Definition vcomposite.h:48
virtual void load(const TQDomElement &element)
Load this object's state from xml and initialize this object accordingly.
VSubpath provides a sophisticated list of VSegment.
Definition vpath.h:43
bool isEmpty() const
Returns true if the current path is "emtpy".
Definition vpath.h:100
The abstract visitor class.
Definition vvisitor.h:51
virtual void visitVSubpath(VSubpath &path)
Visit method for a VSubpath.
Definition vvisitor.cpp:86