summaryrefslogtreecommitdiffstats
path: root/karbon/core/vdocument.h
blob: 45270d2e6a12a30fcdfd7ffc66cb9ce979a81def (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
/* This file is part of the KDE project
   Copyright (C) 2001, The Karbon Developers
   Copyright (C) 2002, The Karbon Developers

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#ifndef VDOCUMENT_H
#define VDOCUMENT_H

#include <KoUnit.h>

#include <tqstring.h>
#include <tqptrlist.h>
#include <tqptrdict.h>

#include "vobject.h"

#include "karbon_grid_data.h"
#include <koffice_export.h>

class TQDomDocument;
class TQDomElement;
class VSelection;
class VLayer;
class KoPageLayout;

typedef TQPtrList<VLayer> VLayerList;
typedef TQPtrListIterator<VLayer> VLayerListIterator;


/**
 * All non-visual, static doc info is in here.
 * The karbon part uses this class.
 * Filters can use this class as well instead of
 * the visually oriented karbon part.
 */

class KARBONBASE_EXPORT VDocument : public VObject
{
public:
	/** The different selection modes */
	enum VSelectionMode {
		ActiveLayer,	/**< selection within the active layer */
		VisibleLayers,	/**< selection within all visible layers */
		SelectedLayers,	/**< selection within all selected layers */
		AllLayers		/**< selection within all layers */
	};

	/**
	 * Constructs a new document.
	 */
	VDocument();

	/**
	 * Copy constructor.
	 *
	 * @param document the document to copy properties from
	 */
	VDocument( const VDocument& document );

	/** 
	 * Destroys the document and all of the layers.
	 */
	virtual ~VDocument();

	virtual void draw( VPainter* painter, const KoRect* rect ) const;
	
	/**
	 * Draw the document frame to a painting device.
	 *
	 * @param painter abstraction that is used to render to a painting device.
	 * @param pl tqlayout describing the page to draw on (restricting the painter)
	 * @param drawPageMargins if @c true, also draw the crop marks for the page margins,
	 *        otherwise, don't draw them.
	 */
	void drawPage( VPainter *painter, const KoPageLayout &pl, bool drawPageMargins ) const;

	/**
	 * Returns document width.
	 *
	 * @return the document's width
	 */
	double width() const { return m_width; }

	/**
	 * Returns document height.
	 *
	 * @return the document's height
	 */
	double height() const { return m_height; }

	/**
	 * Sets document width.
	 *
	 * @param width the new document width
	 */
	void setWidth( double width ) { m_width = width; m_boundingBox.setWidth( width ); }

	/**
	 * Sets document height.
	 *
	 * @param height the new document height
	 */
	void setHeight( double height ) { m_height = height; m_boundingBox.setHeight( height ); }

	/**
	 * Returns document unit.
	 *
	 * @return the document's unit
	 */
	KoUnit::Unit unit() const
		{ return m_unit; }

	/**
	 * Sets document unit.
	 *
	 * @param unit the new document unit
	 */
	void setUnit( KoUnit::Unit unit )
		{ m_unit = unit; }

	/**
	 * Checks if specified layer can be raised. 
	 *
	 * A layer can be raised if there is more than one layer and the specified layer
	 * is not already at the top.
	 *
	 * @param layer the layer to check
	 * @return true if layer can be raised, else false
	 */
	bool canRaiseLayer( VLayer* layer );

	/**
	 * Checks if specified layer can be lowered. 
	 *
	 * A layer can be lowered if there is more than one layer and the specified layer
	 * is not already at the bottom.
	 *
	 * @param layer the layer to check
	 * @return true if layer can be lowered, else false
	 */
	bool canLowerLayer( VLayer* layer );

	/**
	 * Raises the layer.
	 * 
	 * @param layer the layer to raise
	 */
	void raiseLayer( VLayer* layer );

	/**
	 * Lowers the layer.
	 * 
	 * @param layer the layer to lower
	 */
	void lowerLayer( VLayer* layer );

	/**
	 * Returns the position of the specified layer.
	 *
	 * @param layer the layer to retrieve the position for
	 * @return the layer position
	 */
	int layerPos( VLayer* layer );

	/**
	 * Inserts a new layer.
	 * 
	 * The layer is appended at the end, on top of all other layers, and is activated.
	 *
	 * @param layer the layer to insert
	 */
	void insertLayer( VLayer* layer );

	/**
	 * Removes the layer.
	 *
	 * If there is no layer left, a new layer is created, inserted and activated.
	 *
	 * @param layer the layer to remove
	 */
	void removeLayer( VLayer* layer );

	/**
	 * Sets the active layer.
	 *
	 * The specified layer is set active, if it is found in the layer list.
	 *
	 * @param layer the layer to set active
	 */
	void setActiveLayer( VLayer* layer );

	/**
	 * Returns a pointer to the active layer.
	 *
	 * @return the currently active layer
	 */
	VLayer* activeLayer() const { return m_activeLayer; }

	/**
	 * Returns the list of layers.
	 */
	const VLayerList& layers() const { return m_layers; }

	TQDomDocument saveXML() const;
	virtual void saveOasis( KoStore *store, KoXmlWriter *docWriter, KoGenStyles &mainStyles ) const;
	enum { STYLE_GRAPHICAUTO = 20, STYLE_LINEAR_GRADIENT, STYLE_RADIAL_GRADIENT, STYLE_STROKE };
	bool loadXML( const TQDomElement& doc );
	virtual bool loadOasis( const TQDomElement &element, KoOasisLoadingContext &context );
	virtual void save( TQDomElement& element ) const;
	virtual void load( const TQDomElement& element );
	void loadDocumentContent( const TQDomElement& doc );

	virtual VDocument* clone() const;

	virtual void accept( VVisitor& visitor );


	/**
	 * Returns a pointer to the selection.
	 *
	 * @return the document's selection
	 */
	VSelection* selection() const
		{ return m_selection; }

	/**
	 * Returns the selection mode.
	 * 
	 * @return the actual selection mode
	 */
	VSelectionMode selectionMode() { return m_selectionMode; }

	/**
	 * Sets the selection mode.
	 *
	 * @param mode the new selection mode
	 */
	void setSelectionMode( VSelectionMode mode ) { m_selectionMode = mode; }

	/**
	 * Appends a new object to the active layer.
	 *
	 * @param object the object to append
	 */
	void append( VObject* object );

	/**
	 * Returns custom name of specified object.
	 *
	 * @param obj the object to retrieve name for
	 * @return the custom name of the object or an empty string if no custom name is set
	 */
	TQString objectName( const VObject *obj ) const;

	/**
	 * Sets custom name of specified object.
	 *
	 * By default all object have generic names like path, rectangle or text that
	 * is defined within the object's class.
	 * 
	 * @param obj the object to set custom name for
	 * @param name the the custom name to set
	 */
	void setObjectName( const VObject *obj, const TQString name ) { m_objectNames.insert( obj, name ); }

	bool saveAsPath() const { return m_saveAsPath; }
	void saveAsPath( bool b ) { m_saveAsPath = b; }

	/**
	 * Returns the document's grid.
	 *
	 * @return the doument's grid 
	 */
	KarbonGridData &grid() { return m_gridData; }

private:
	/**
	 * Document width.
	 */
	double m_width;

	/**
	 * Document height.
	 */
	double m_height;


	/// The layers in this document.
	VLayerList m_layers;
	/// The active layer.
	VLayer* m_activeLayer;

	/// The selection. A list of selected objects.
	VSelection* m_selection;
	/// The selectionMode
	VSelectionMode m_selectionMode;

	/**
	 * The unit.
	 */
	KoUnit::Unit m_unit;

	TQMap<const VObject *, TQString>	m_objectNames;

	// TODO this flag is used nowhere, can we remove it?
	bool m_saveAsPath;

	KarbonGridData m_gridData;
};

#endif