1
/* This file is part of the KDE project
2
Copyright (C) 2001, 2002, 2003 The Karbon Developers
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.
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.
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.
22
#include "vdocument.h"
23
#include "vselection.h"
30
VDocument::VDocument()
32
m_selectionMode( VDocument::ActiveLayer ),
33
m_unit( KoUnit::U_MM ),
34
m_mime( "application/x-karbon" ),
35
m_version( "0.1" ), m_editor( "karbon14 0.0.1" ),
36
m_syntaxVersion( "0.1" )
38
m_selection = new VSelection( this );
40
// create a layer. we need at least one:
41
m_layers.setAutoDelete( true );
42
m_layers.append( new VLayer( this ) );
43
m_activeLayer = m_layers.getLast();
48
VDocument::VDocument( const VDocument& document )
51
m_selection = new VSelection( this );
55
VDocument::~VDocument()
57
delete( m_selection );
61
VDocument::drawPage( VPainter *p ) const
63
p->setPen( Qt::black );
64
p->setBrush( Qt::white );
65
p->drawRect( 0, 0, m_width, m_height );
67
p->setPen( Qt::NoPen );
68
p->setBrush( Qt::black );
69
p->drawRect( m_width, - 2, 2, m_height );
70
p->drawRect( 0, - 2, m_width, 2 );
71
//p->drawRect( 0, m_height - 1, m_width, 1 );
75
VDocument::draw( VPainter *painter, const KoRect* rect ) const
77
QPtrListIterator<VLayer> itr = m_layers;
79
for ( ; itr.current(); ++itr )
81
itr.current()->draw( painter, rect );
86
VDocument::insertLayer( VLayer* layer )
88
// if ( pos == -1 || !m_layers.insert( layer, pos ))
89
m_layers.append( layer );
90
m_activeLayer = layer;
91
} // VDocument::insertLayer
94
VDocument::removeLayer( VLayer* layer )
96
m_layers.remove( layer );
97
if ( m_layers.count() == 0 )
98
m_layers.append( new VLayer( this ) );
99
m_activeLayer = m_layers.getLast();
100
} // VDocument::removeLayer
102
bool VDocument::canRaiseLayer( VLayer* layer )
104
int pos = m_layers.find( layer );
105
return (pos != int( m_layers.count() ) - 1 && pos >= 0 );
108
bool VDocument::canLowerLayer( VLayer* layer )
110
int pos = m_layers.find( layer );
115
VDocument::raiseLayer( VLayer* layer )
117
int pos = m_layers.find( layer );
118
if( pos != int( m_layers.count() ) - 1 && pos >= 0 )
120
VLayer* layer = m_layers.take( pos );
121
m_layers.insert( pos + 1, layer );
123
} // VDocument::raiseLayer
126
VDocument::lowerLayer( VLayer* layer )
128
int pos = m_layers.find( layer );
131
VLayer* layer = m_layers.take( pos );
132
m_layers.insert( pos - 1, layer );
134
} // VDocument::lowerLayer
137
VDocument::layerPos( VLayer* layer )
139
return m_layers.find( layer );
140
} // VDocument::layerPos
143
VDocument::setActiveLayer( VLayer* layer )
145
if ( m_layers.find( layer ) != -1 )
146
m_activeLayer = layer;
147
} // VDocument::setActiveLayer
150
VDocument::append( VObject* object )
152
m_activeLayer->append( object );
156
VDocument::saveXML() const
159
QDomElement me = doc.createElement( "DOC" );
160
doc.appendChild( me );
162
// TODO : add paper size/orientation storing code here
163
// maybe we need to provide it as param or member var? (Rob)
169
VDocument::save( QDomElement& me ) const
171
me.setAttribute( "mime", m_mime );
172
me.setAttribute( "version", m_version );
173
me.setAttribute( "editor", m_editor );
174
me.setAttribute( "syntaxVersion", m_syntaxVersion );
175
me.setAttribute( "width", m_width );
176
me.setAttribute( "height", m_height );
177
me.setAttribute( "unit", KoUnit::unitName( m_unit ) );
180
VLayerListIterator itr( m_layers );
182
for ( ; itr.current(); ++itr )
183
itr.current()->save( me );
188
VDocument::clone() const
190
return new VDocument( *this );
194
VDocument::load( const QDomElement& doc )
200
VDocument::loadXML( const QDomElement& doc )
202
if( doc.attribute( "mime" ) != "application/x-karbon" ||
203
doc.attribute( "syntaxVersion" ) != "0.1" )
210
m_mime = doc.attribute( "mime" );
211
m_version = doc.attribute( "version" );
212
m_editor = doc.attribute( "editor" );
213
m_syntaxVersion = doc.attribute( "syntaxVersion" );
215
m_width = doc.attribute( "width", "800.0" ).toDouble();
216
m_height = doc.attribute( "height", "550.0" ).toDouble();
218
m_unit = KoUnit::unit( doc.attribute( "unit", "mm" ) );
220
loadDocumentContent( doc );
225
VDocument::loadDocumentContent( const QDomElement& doc )
227
QDomNodeList list = doc.childNodes();
228
for( uint i = 0; i < list.count(); ++i )
230
if( list.item( i ).isElement() )
232
QDomElement e = list.item( i ).toElement();
234
if( e.tagName() == "LAYER" )
236
VLayer* layer = new VLayer( this );
238
insertLayer( layer );
245
VDocument::accept( VVisitor& visitor )
247
visitor.visitVDocument( *this );
251
VDocument::objectName( const VObject *obj ) const
253
QMap<const VObject *, QString>::ConstIterator it = m_objectNames.find( obj );
254
return it == m_objectNames.end() ? 0L : it.data();