~ubuntu-branches/ubuntu/breezy/koffice/breezy

« back to all changes in this revision

Viewing changes to karbon/core/vdocument.cc

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

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
#include <qdom.h>
 
21
 
 
22
#include "vdocument.h"
 
23
#include "vselection.h"
 
24
#include "vvisitor.h"
 
25
#include "vpainter.h"
 
26
#include "vlayer.h"
 
27
 
 
28
#include <kdebug.h>
 
29
 
 
30
VDocument::VDocument()
 
31
        : VObject( 0L ),
 
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" )
 
37
{
 
38
        m_selection = new VSelection( this );
 
39
 
 
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();
 
44
 
 
45
        m_saveAsPath = true;
 
46
}
 
47
 
 
48
VDocument::VDocument( const VDocument& document )
 
49
        : VObject( document )
 
50
{
 
51
        m_selection = new VSelection( this );
 
52
// TODO
 
53
}
 
54
 
 
55
VDocument::~VDocument()
 
56
{
 
57
        delete( m_selection );
 
58
}
 
59
 
 
60
void
 
61
VDocument::drawPage( VPainter *p ) const
 
62
{
 
63
        p->setPen( Qt::black );
 
64
        p->setBrush( Qt::white );
 
65
        p->drawRect( 0, 0, m_width, m_height );
 
66
 
 
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 );
 
72
}
 
73
 
 
74
void
 
75
VDocument::draw( VPainter *painter, const KoRect* rect ) const
 
76
{
 
77
        QPtrListIterator<VLayer> itr = m_layers;
 
78
 
 
79
        for ( ; itr.current(); ++itr )
 
80
        {
 
81
                itr.current()->draw( painter, rect );
 
82
        }
 
83
}
 
84
 
 
85
void
 
86
VDocument::insertLayer( VLayer* layer )
 
87
{
 
88
//      if ( pos == -1 || !m_layers.insert( layer, pos ))
 
89
                m_layers.append( layer );
 
90
        m_activeLayer = layer;
 
91
} // VDocument::insertLayer
 
92
 
 
93
void
 
94
VDocument::removeLayer( VLayer* layer )
 
95
{
 
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
 
101
 
 
102
bool VDocument::canRaiseLayer( VLayer* layer )
 
103
{
 
104
    int pos = m_layers.find( layer );
 
105
    return (pos != int( m_layers.count() ) - 1 && pos >= 0 );
 
106
}
 
107
 
 
108
bool VDocument::canLowerLayer( VLayer* layer )
 
109
{
 
110
    int pos = m_layers.find( layer );
 
111
    return (pos>0);
 
112
}
 
113
 
 
114
void
 
115
VDocument::raiseLayer( VLayer* layer )
 
116
{
 
117
        int pos = m_layers.find( layer );
 
118
        if( pos != int( m_layers.count() ) - 1 && pos >= 0 )
 
119
        {
 
120
                VLayer* layer = m_layers.take( pos );
 
121
                m_layers.insert( pos + 1, layer );
 
122
        }
 
123
} // VDocument::raiseLayer
 
124
 
 
125
void
 
126
VDocument::lowerLayer( VLayer* layer )
 
127
{
 
128
        int pos = m_layers.find( layer );
 
129
        if ( pos > 0 )
 
130
        {
 
131
                VLayer* layer = m_layers.take( pos );
 
132
                m_layers.insert( pos - 1, layer );
 
133
        }
 
134
} // VDocument::lowerLayer
 
135
 
 
136
int
 
137
VDocument::layerPos( VLayer* layer )
 
138
{
 
139
        return m_layers.find( layer );
 
140
} // VDocument::layerPos
 
141
 
 
142
void
 
143
VDocument::setActiveLayer( VLayer* layer )
 
144
{
 
145
        if ( m_layers.find( layer ) != -1 )
 
146
                m_activeLayer = layer;
 
147
} // VDocument::setActiveLayer
 
148
 
 
149
void
 
150
VDocument::append( VObject* object )
 
151
{
 
152
        m_activeLayer->append( object );
 
153
}
 
154
 
 
155
QDomDocument
 
156
VDocument::saveXML() const
 
157
{
 
158
        QDomDocument doc;
 
159
        QDomElement me = doc.createElement( "DOC" );
 
160
        doc.appendChild( me );
 
161
 
 
162
        // TODO : add paper size/orientation storing code here
 
163
        // maybe we need to provide it as param or member var? (Rob)
 
164
        save( me );
 
165
        return doc;
 
166
}
 
167
 
 
168
void
 
169
VDocument::save( QDomElement& me ) const
 
170
{
 
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 ) );
 
178
 
 
179
        // save objects:
 
180
        VLayerListIterator itr( m_layers );
 
181
 
 
182
        for ( ; itr.current(); ++itr )
 
183
                itr.current()->save( me );
 
184
}
 
185
 
 
186
 
 
187
VDocument*
 
188
VDocument::clone() const
 
189
{
 
190
        return new VDocument( *this );
 
191
}
 
192
 
 
193
void
 
194
VDocument::load( const QDomElement& doc )
 
195
{
 
196
        loadXML( doc );
 
197
}
 
198
 
 
199
bool
 
200
VDocument::loadXML( const QDomElement& doc )
 
201
{
 
202
    if( doc.attribute( "mime" ) != "application/x-karbon" ||
 
203
                doc.attribute( "syntaxVersion" ) != "0.1" )
 
204
        {
 
205
                return false;
 
206
        }
 
207
 
 
208
        m_layers.clear();
 
209
 
 
210
        m_mime = doc.attribute( "mime" );
 
211
        m_version = doc.attribute( "version" );
 
212
        m_editor = doc.attribute( "editor" );
 
213
        m_syntaxVersion = doc.attribute( "syntaxVersion" );
 
214
 
 
215
        m_width  = doc.attribute( "width", "800.0" ).toDouble();
 
216
        m_height = doc.attribute( "height", "550.0" ).toDouble();
 
217
 
 
218
        m_unit = KoUnit::unit( doc.attribute( "unit", "mm" ) );
 
219
 
 
220
        loadDocumentContent( doc );
 
221
        return true;
 
222
}
 
223
 
 
224
void
 
225
VDocument::loadDocumentContent( const QDomElement& doc )
 
226
{
 
227
        QDomNodeList list = doc.childNodes();
 
228
        for( uint i = 0; i < list.count(); ++i )
 
229
        {
 
230
                if( list.item( i ).isElement() )
 
231
                {
 
232
                        QDomElement e = list.item( i ).toElement();
 
233
 
 
234
                        if( e.tagName() == "LAYER" )
 
235
                        {
 
236
                                VLayer* layer = new VLayer( this );
 
237
                                layer->load( e );
 
238
                                insertLayer( layer );
 
239
                        }
 
240
                }
 
241
        }
 
242
}
 
243
 
 
244
void
 
245
VDocument::accept( VVisitor& visitor )
 
246
{
 
247
        visitor.visitVDocument( *this );
 
248
}
 
249
 
 
250
QString
 
251
VDocument::objectName( const VObject *obj ) const
 
252
{
 
253
        QMap<const VObject *, QString>::ConstIterator it = m_objectNames.find( obj );
 
254
        return it == m_objectNames.end() ? 0L : it.data();
 
255
}