karbon

vlayer.cpp
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#include <tqdom.h>
21
22#include <tdelocale.h>
23#include <KoRect.h>
24
25#include "vcomposite.h"
26#include "vdocument.h"
27#include "vgroup.h"
28#include "vlayer.h"
29#include "vobject.h"
30#include "vtext.h"
31#include "vvisitor.h"
32#include "vlayer_iface.h"
33#include <kdebug.h>
34#include "vclipgroup.h"
35#include "vfill.h"
36#include "vstroke.h"
37
39 : VGroup( parent, state )
40{
41 setName( "Layer" );
42 // HACK : vlayer just shouldn't have fill/stroke at all
43 delete m_fill;
44 m_fill = 0L;
45 delete m_stroke;
46 m_stroke = 0L;
47}
48
49VLayer::VLayer( const VLayer& layer )
50 : VGroup( layer )
51{
52}
53
54VLayer::~VLayer()
55{
56}
57
58DCOPObject* VLayer::dcopObject()
59{
60 if ( !m_dcop )
61 m_dcop = new VLayerIface( this );
62
63 return m_dcop;
64}
65
66void
67VLayer::draw( VPainter* painter, const KoRect* rect ) const
68{
69 if(
70 state() == deleted ||
71 state() == hidden ||
72 state() == hidden_locked )
73 {
74 return;
75 }
76
77 VObjectListIterator itr = m_objects;
78
79 for ( ; itr.current(); ++itr )
80 itr.current()->draw( painter, rect );
81}
82
83void
85{
86 if( m_objects.getLast() == &object ) return;
87
88 m_objects.remove( &object );
89
90 m_objects.append( &object );
91}
92
93void
94VLayer::upwards( const VObject& object )
95{
96 if( m_objects.getLast() == &object ) return;
97
98 m_objects.remove( &object );
99
100 if( m_objects.current() != m_objects.getLast() )
101 {
102 m_objects.next();
103 m_objects.insert( m_objects.at(), &object );
104 }
105 else
106 m_objects.append( &object );
107}
108
109void
111{
112 if( m_objects.getFirst() == &object ) return;
113
114 int index = m_objects.find( &object );
115 bool bLast = m_objects.getLast() == &object;
116 m_objects.remove( index );
117
118 if( !bLast ) m_objects.prev();
119
120 m_objects.insert( m_objects.at(), &object );
121}
122
123void
125{
126 if( m_objects.getFirst() == &object ) return;
127
128 m_objects.remove( &object );
129
130 m_objects.prepend( &object );
131}
132
133void
134VLayer::save( TQDomElement& element ) const
135{
136 if( state() != deleted )
137 {
138 TQDomElement me = element.ownerDocument().createElement( "LAYER" );
139 element.appendChild( me );
140
141 if( state() == normal || state() == normal_locked || state() == VObject::selected )
142 me.setAttribute( "visible", 1 );
143
144 // save objects:
145 VObjectListIterator itr = m_objects;
146 for ( ; itr.current(); ++itr )
147 itr.current()->save( me );
148
149 VObject::save( me );
150 }
151}
152
153void
154VLayer::saveOasis( KoStore *store, KoXmlWriter *docWriter, KoGenStyles &mainStyles, int &index ) const
155{
156 // do not save deleted objects
157 if( state() == deleted )
158 return;
159
160 // save objects:
161 VObjectListIterator itr = m_objects;
162
163 for ( ; itr.current(); ++itr )
164 itr.current()->saveOasis( store, docWriter, mainStyles, ++index );
165}
166
167void
168VLayer::load( const TQDomElement& element )
169{
170 setState( element.attribute( "visible" ) == 0 ? hidden : normal );
171 VGroup::load( element );
172}
173
174
175VLayer*
177{
178 return new VLayer( *this );
179}
180
181void
183{
184 visitor.visitVLayer( *this );
185}
186
virtual void setState(const VState state)
Sets the state to a specified new state.
Definition vgroup.cpp:148
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
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
VLayer manages a set of vobjects.
Definition vlayer.h:37
virtual void load(const TQDomElement &element)
Load this object's state from xml and initialize this object accordingly.
Definition vlayer.cpp:168
VLayer(VObject *parent, VState state=normal)
Constructs a new layer object that is child of parent and has the given state.
Definition vlayer.cpp:38
void upwards(const VObject &object)
Moves the object one step up the list.
Definition vlayer.cpp:94
virtual void draw(VPainter *painter, const KoRect *rect=0L) const
Draw the object to a painting device.
Definition vlayer.cpp:67
virtual VLayer * clone() const
Create an exact copy of this object.
Definition vlayer.cpp:176
virtual DCOPObject * dcopObject()
Returns pointer to internal DCOP object.
Definition vlayer.cpp:58
void downwards(const VObject &object)
Moves the object one step down the list.
Definition vlayer.cpp:110
void bringToFront(const VObject &object)
Moves the object to the top of the list.
Definition vlayer.cpp:84
virtual void saveOasis(KoStore *store, KoXmlWriter *docWriter, KoGenStyles &mainStyles, int &index) const
Save this object's state to OpenDocument.
Definition vlayer.cpp:154
void sendToBack(const VObject &object)
Moves the object to the end of the list.
Definition vlayer.cpp:124
virtual void accept(VVisitor &visitor)
Accept a VVisitor.
Definition vlayer.cpp:182
virtual void save(TQDomElement &element) const
Save this object's state to xml.
Definition vlayer.cpp:134
DCOPObject * m_dcop
the object's DCOP object
Definition vobject.h:292
VObject(VObject *parent, VState state=edit)
Constructs a new object that is child of parent and has the given state.
Definition vobject.cpp:36
VObject * parent() const
Returns pointer to current parent object.
Definition vobject.h:147
@ normal_locked
visible, but locked (r/o)
Definition vobject.h:55
@ hidden_locked
hidden and locked (r/o)
Definition vobject.h:57
@ selected
visible, active and can be manipulated by tools
Definition vobject.h:61
@ deleted
deleted, nearly dead
Definition vobject.h:58
@ normal
visible, not active
Definition vobject.h:54
@ hidden
hidden
Definition vobject.h:56
VStroke * m_stroke
the object's stroke
Definition vobject.h:289
VFill * m_fill
the object's fill
Definition vobject.h:290
void setName(const TQString &s)
Sets the object's name to a given new name.
Definition vobject.cpp:231
virtual void save(TQDomElement &element) const
Save this object's state to xml.
Definition vobject.cpp:102
VState state() const
Get the state the object is in.
Definition vobject.h:154
The abstract visitor class.
Definition vvisitor.h:51
virtual void visitVLayer(VLayer &layer)
Visit method for a VLayer.
Definition vvisitor.cpp:63