kspread

kspread_object.h
1/* This file is part of the KDE project
2 Copyright (C) 2006 Fredrik Edemar <f_edemar@linux.se>
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.
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#ifndef KSPREAD_OBJECT_H
21#define KSPREAD_OBJECT_H
22
23#include "kspread_sheet.h"
24
25#include <tdelocale.h>
26#include <KoBrush.h>
27#include <KoChild.h>
28#include <KoDom.h>
29#include <KoOasisLoadingContext.h>
30#include <KoPen.h>
31#include <KoPictureCollection.h>
32#include <KoRect.h>
33#include <KoSize.h>
34#include <KoStore.h>
35#include <KoStoreDevice.h>
36#include <KoXmlNS.h>
37
38namespace KoChart
39{
40class Part;
41}
42
43namespace KSpread
44{
45
46class Doc;
47class EmbeddedKOfficeObject;
48class EmbeddedObject;
49class View;
50class ChartBinding;
51
52enum ObjType {
53 OBJECT_GENERAL,
54 OBJECT_KOFFICE_PART,
55 OBJECT_CHART,
56 OBJECT_PICTURE
57};
58
59enum SelectionMode {
60 SM_NONE = 0,
61 SM_MOVERESIZE = 1,
62 SM_ROTATE = 2,
63 SM_PROTECT = 3
64};
65
66enum PictureMirrorType {
67 PM_NORMAL = 0,
68 PM_HORIZONTAL = 1,
69 PM_VERTICAL = 2,
70 PM_HORIZONTALANDVERTICAL = 3
71};
72
73enum ImageEffect {
74 IE_NONE = -1,
75 IE_CHANNEL_INTENSITY = 0,
76 IE_FADE = 1,
77 IE_FLATTEN = 2,
78 IE_INTENSITY = 3,
79 IE_DESATURATE = 4,
80 IE_CONTRAST = 5,
81 IE_NORMALIZE = 6,
82 IE_EQUALIZE = 7,
83 IE_THRESHOLD = 8,
84 IE_SOLARIZE = 9,
85 IE_EMBOSS = 10,
86 IE_DESPECKLE = 11,
87 IE_CHARCOAL = 12,
88 IE_NOISE = 13,
89 IE_BLUR = 14,
90 IE_EDGE = 15,
91 IE_IMPLODE = 16,
92 IE_OIL_PAINT = 17,
93 IE_SHARPEN = 18,
94 IE_SPREAD = 19,
95 IE_SHADE = 20,
96 IE_SWIRL = 21,
97 IE_WAVE = 22
98};
99
100enum AlignType {
101 AT_PAGE,
102 AT_CELL
103};
104
109{
110 public:
111 EmbeddedObject( Sheet *_sheet, const KoRect& _geometry );
112 virtual ~EmbeddedObject();
113 virtual ObjType getType() const { return OBJECT_GENERAL; }
114 virtual TQString getTypeString() const
115 { return TQString(); }
116
117 KoRect geometry();
118 void setGeometry( const KoRect &rect );
119 virtual void moveBy( const KoPoint &_point );
120 virtual void moveBy( double _dx, double _dy );
121 virtual void resizeBy( const KoSize & _size );
122 virtual void resizeBy( double _dx, double _dy );
123
124 Sheet* sheet() const { return m_sheet; }
125
126 void setSelected(bool s) { m_selected = s; }
127 bool isSelected() const { return m_selected; }
128
129 void setObjectName( const TQString &_objectName )
130 { m_objectName = _objectName; }
131 TQString getObjectName() const
132 { return m_objectName; }
133
134 virtual void setProtect( bool b ) { m_protect = b; }
135 bool isProtect() const { return m_protect; }
136
137 virtual void setKeepRatio( bool b ) { m_keepRatio = b; }
138 bool isKeepRatio() const { return m_keepRatio; }
139
140 virtual void rotate( float _angle ) { angle = _angle; }
141 virtual float getAngle() const { return angle; }
142
143 struct KSpreadOasisSaveContext
144 {
145 KSpreadOasisSaveContext( KoXmlWriter &_xmlWriter, KoGenStyles &_context,
146 int &_indexObj, int &_partIndexObj )
147 : xmlWriter( _xmlWriter )
148 , context( _context )
149 , indexObj( _indexObj )
150 , partIndexObj( _partIndexObj )
151 {};
152
153 KoXmlWriter &xmlWriter;
154 KoGenStyles &context;
155 int &indexObj;
156 int &partIndexObj;
157 };
158
159 virtual bool load( const TQDomElement& element );
160 virtual void loadOasis(const TQDomElement &element, KoOasisLoadingContext & context );
161 virtual TQDomElement save( TQDomDocument& doc );
162 virtual bool saveOasisObject( KSpreadOasisSaveContext &sc ) const;
163 virtual void draw( TQPainter *_painter );
164
172 TQPixmap toPixmap( TQSize size );
173
177 TQPixmap toPixmap();
178
182 virtual TQPixmap toPixmap( double xZoom , double yZoom );
183
184
185 void paintSelection( TQPainter *_painter, SelectionMode selectionMode );
186 virtual TQCursor getCursor( const TQPoint &_point, ModifyType &_modType, TQRect &geometry ) const;
187
188 virtual void removeFromObjList()
189 { inObjList = false; }
190 virtual void addToObjList()
191 { inObjList = true; }
192 virtual void incCmdRef()
193 { cmds++; }
194 virtual void decCmdRef()
195 { cmds--; doDelete(); }
196
197 //TEMP:
198 virtual TQBrush getBrush() const { return m_brush.getBrush(); }
199
200
201 protected:
205 virtual const char * getOasisElementName() const = 0;
206 virtual void saveOasisPosObject( KoXmlWriter &xmlWriter, int indexObj ) const;
207 virtual bool saveOasisObjectAttributes( KSpreadOasisSaveContext &sc ) const;
208
209 virtual void doDelete();
210
218 void calculateRequiredZoom( TQSize desiredSize , double& xZoom, double& yZoom );
219
220 KoRect m_geometry;
221 Sheet *m_sheet;
222 Canvas *m_canvas;
223 TQString m_objectName;
224 bool m_selected:1;
225 bool m_protect:1;
226 bool m_keepRatio:1;
227 bool inObjList:1;
228 int cmds;
229 float angle;
230
231 KoPen pen;
232 KoBrush m_brush;
233};
234
239{
240 public:
241 EmbeddedKOfficeObject( Doc *parent, Sheet *_sheet, KoDocument* doc, const KoRect& geometry );
242 EmbeddedKOfficeObject( Doc *parent, Sheet *_sheet );
243 virtual ~EmbeddedKOfficeObject();
244 virtual ObjType getType() const { return OBJECT_KOFFICE_PART; }
245 virtual TQString getTypeString() const
246 { return i18n("Embedded Object"); }
247
248 Doc* parent();
249 KoDocumentChild *embeddedObject();
250
251 bool load( const TQDomElement& element );
252 virtual void loadOasis(const TQDomElement &element, KoOasisLoadingContext & context );
253 TQDomElement save( TQDomDocument& doc );
254 virtual void draw( TQPainter *_painter );
255
259 virtual TQPixmap toPixmap(double xZoom , double yZoom);
260
261 void activate( View *_view, Canvas *_canvas );
262 void deactivate();
263
264 protected:
265 void updateChildGeometry();
266 virtual const char * getOasisElementName() const;
267 virtual bool saveOasisObjectAttributes( KSpreadOasisSaveContext &sc ) const;
268
269 KoDocumentChild *m_embeddedObject;
270 Doc *m_parent;
271};
272
273
278{
279 public:
280 EmbeddedChart( Doc *_spread, Sheet *_sheet, KoDocument* doc, const KoRect& _rect );
281 EmbeddedChart( Doc *_spread, Sheet *_sheet );
282 virtual ~EmbeddedChart();
283 virtual ObjType getType() const { return OBJECT_CHART; }
284 virtual TQString getTypeString() const
285 { return i18n("Chart"); }
286
287 void setDataArea( const TQRect& _data );
288 void update();
289
290 bool load( const TQDomElement& element );
291 virtual void loadOasis(const TQDomElement &element, KoOasisLoadingContext & context );
292 TQDomElement save( TQDomDocument& doc );
293 virtual void draw( TQPainter *_painter );
294
298 bool loadDocument( KoStore* _store );
299
300 KoChart::Part* chart();
301
302 protected:
303 virtual const char * getOasisElementName() const;
304 virtual bool saveOasisObjectAttributes( KSpreadOasisSaveContext &sc ) const;
305
306 private:
307 ChartBinding *m_pBinding;
308};
309
310
315{
316 public:
317 EmbeddedPictureObject(Sheet *_sheet, const KoRect& _geometry, KoPictureCollection *_imageCollection );
318 EmbeddedPictureObject(Sheet *_sheet, const KoRect& _geometry, KoPictureCollection *_imageCollection, const KoPictureKey & key );
319 EmbeddedPictureObject( Sheet *_sheet, KoPictureCollection *_imageCollection );
320 virtual ~EmbeddedPictureObject();
321 EmbeddedPictureObject &operator=( const EmbeddedPictureObject & );
322
323 virtual ObjType getType() const { return OBJECT_PICTURE; }
324 virtual TQString getTypeString() const
325 { return i18n("Picture"); }
326 bool load( const TQDomElement& element );
327 virtual void loadOasis(const TQDomElement &element, KoOasisLoadingContext & context );
328 TQDomElement save( TQDomDocument& doc );
329 virtual void draw( TQPainter *_painter );
330
334 virtual TQPixmap toPixmap(double xZoom , double yZoom);
335
340 TQString getFileName() const
341 { return image.getKey().filename(); }
342
343 KoPictureKey getKey() const
344 { return image.getKey(); }
345
346 TQSize originalSize() const
347 { return image.getOriginalSize(); }
348
349 void setPicture( const KoPictureKey & key );
350
351 void reload( void );
352
353 //virtual TQDomDocumentFragment save( TQDomDocument& doc, double offset );
354
355 //virtual double load(const TQDomElement &element);
356 //virtual void loadOasis(const TQDomElement &element, KoOasisLoadingContext & context, KPRLoadingInfo *info);
357
358// virtual void draw( TQPainter *_painter, KoZoomHandler*_zoomHandler,
359// int /* page */, SelectionMode selectionMode, bool drawContour = false );
360
361 TQPixmap getOriginalPixmap();
362 PictureMirrorType getPictureMirrorType() const { return mirrorType; }
363 int getPictureDepth() const { return depth; }
364 bool getPictureSwapRGB() const { return swapRGB; }
365 bool getPictureGrayscal() const { return grayscal; }
366 int getPictureBright() const { return bright; }
367
368 ImageEffect getImageEffect() const {return m_effect;}
369 TQVariant getIEParam1() const {return m_ie_par1;}
370 TQVariant getIEParam2() const {return m_ie_par2;}
371 TQVariant getIEParam3() const {return m_ie_par3;}
372 void setImageEffect(ImageEffect eff) { m_effect = eff; }
373 void setIEParams(TQVariant p1, TQVariant p2, TQVariant p3) {
374 m_ie_par1=p1;
375 m_ie_par2=p2;
376 m_ie_par3=p3;
377 }
378
379 void setPictureMirrorType(const PictureMirrorType &_mirrorType) { mirrorType = _mirrorType; }
380 void setPictureDepth(int _depth) { depth = _depth; }
381 void setPictureSwapRGB(bool _swapRGB) { swapRGB = _swapRGB; }
382 void setPictureGrayscal(bool _grayscal) { grayscal = _grayscal; }
383 void setPictureBright(int _bright) { bright = _bright; }
384
385 KoPicture picture() const { return image;}
386
387 void loadPicture( const TQString & fileName );
388
389 virtual void flip(bool horizontal );
390
391 protected:
392 virtual const char * getOasisElementName() const;
393 virtual bool saveOasisObjectAttributes( KSpreadOasisSaveContext &sc ) const;
394
395 TQPixmap changePictureSettings( TQPixmap _tmpPixmap );
396 virtual void saveOasisPictureElement( KoGenStyle &styleobjectauto ) const;
397 void loadOasisPictureEffect(KoOasisLoadingContext & context );
398 virtual void fillStyle( KoGenStyle& styleObjectAuto, KoGenStyles& mainStyles ) const;
399
404 void drawShadow( TQPainter* _painter, KoZoomHandler* _zoomHandler);
405
406 TQPixmap generatePixmap(KoZoomHandler*_zoomHandler);
407 TQString convertValueToPercent( int val ) const;
408
409 KoPictureCollection *imageCollection;
410 KoPicture image;
411
412 PictureMirrorType mirrorType, m_cachedMirrorType;
413 int depth, m_cachedDepth;
414 bool swapRGB, m_cachedSwapRGB;
415 bool grayscal, m_cachedGrayscal;
416 int bright, m_cachedBright;
417
418 //image effect and its params
419 ImageEffect m_effect, m_cachedEffect;
420 TQVariant m_ie_par1, m_cachedPar1;
421 TQVariant m_ie_par2, m_cachedPar2;
422 TQVariant m_ie_par3, m_cachedPar3;
423
424 TQPixmap m_cachedPixmap;
425 TQRect m_cachedRect;
426};
427
428 } // namespace KSpread
429#endif // KSPREAD_OBJECT_H
The canvas builds a part of the GUI of KSpread.
This class holds the data that makes up a spreadsheet.
Definition kspread_doc.h:98
Holds an embedded chart object.
virtual const char * getOasisElementName() const
Get the element name for saving the object.
bool loadDocument(KoStore *_store)
Holds an embedded koffice object.
virtual const char * getOasisElementName() const
Get the element name for saving the object.
Contains basic information for every object.
TQPixmap toPixmap()
Renders the embedded object to a pixmap at 100% scale.
virtual const char * getOasisElementName() const =0
Get the element name for saving the object.
void calculateRequiredZoom(TQSize desiredSize, double &xZoom, double &yZoom)
Calculates the X and Y zoom factors required to render the embedded object at the given size.
Holds a picture object.
virtual const char * getOasisElementName() const
Get the element name for saving the object.
TQString getFileName() const
Only used as a default value in the filedialog, in changePicture.
The View class displays a KSpread document.
The KSpread namespace.
Definition commands.h:39