00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef KSPREAD_OBJECT_H
00021 #define KSPREAD_OBJECT_H
00022
00023 #include "kspread_sheet.h"
00024
00025 #include <klocale.h>
00026 #include <KoBrush.h>
00027 #include <KoChild.h>
00028 #include <KoDom.h>
00029 #include <KoOasisLoadingContext.h>
00030 #include <KoPen.h>
00031 #include <KoPictureCollection.h>
00032 #include <KoRect.h>
00033 #include <KoSize.h>
00034 #include <KoStore.h>
00035 #include <KoStoreDevice.h>
00036 #include <KoXmlNS.h>
00037
00038 namespace KoChart
00039 {
00040 class Part;
00041 }
00042
00043 namespace KSpread
00044 {
00045
00046 class Doc;
00047 class EmbeddedKOfficeObject;
00048 class EmbeddedObject;
00049 class View;
00050 class ChartBinding;
00051
00052 enum ObjType {
00053 OBJECT_GENERAL,
00054 OBJECT_KOFFICE_PART,
00055 OBJECT_CHART,
00056 OBJECT_PICTURE
00057 };
00058
00059 enum SelectionMode {
00060 SM_NONE = 0,
00061 SM_MOVERESIZE = 1,
00062 SM_ROTATE = 2,
00063 SM_PROTECT = 3
00064 };
00065
00066 enum PictureMirrorType {
00067 PM_NORMAL = 0,
00068 PM_HORIZONTAL = 1,
00069 PM_VERTICAL = 2,
00070 PM_HORIZONTALANDVERTICAL = 3
00071 };
00072
00073 enum ImageEffect {
00074 IE_NONE = -1,
00075 IE_CHANNEL_INTENSITY = 0,
00076 IE_FADE = 1,
00077 IE_FLATTEN = 2,
00078 IE_INTENSITY = 3,
00079 IE_DESATURATE = 4,
00080 IE_CONTRAST = 5,
00081 IE_NORMALIZE = 6,
00082 IE_EQUALIZE = 7,
00083 IE_THRESHOLD = 8,
00084 IE_SOLARIZE = 9,
00085 IE_EMBOSS = 10,
00086 IE_DESPECKLE = 11,
00087 IE_CHARCOAL = 12,
00088 IE_NOISE = 13,
00089 IE_BLUR = 14,
00090 IE_EDGE = 15,
00091 IE_IMPLODE = 16,
00092 IE_OIL_PAINT = 17,
00093 IE_SHARPEN = 18,
00094 IE_SPREAD = 19,
00095 IE_SHADE = 20,
00096 IE_SWIRL = 21,
00097 IE_WAVE = 22
00098 };
00099
00100 enum AlignType {
00101 AT_PAGE,
00102 AT_CELL
00103 };
00104
00108 class EmbeddedObject
00109 {
00110 public:
00111 EmbeddedObject( Sheet *_sheet, const KoRect& _geometry );
00112 virtual ~EmbeddedObject();
00113 virtual ObjType getType() const { return OBJECT_GENERAL; }
00114 virtual QString getTypeString() const
00115 { return QString(); }
00116
00117 KoRect geometry();
00118 void setGeometry( const KoRect &rect );
00119 virtual void moveBy( const KoPoint &_point );
00120 virtual void moveBy( double _dx, double _dy );
00121 virtual void resizeBy( const KoSize & _size );
00122 virtual void resizeBy( double _dx, double _dy );
00123
00124 Sheet* sheet() const { return m_sheet; }
00125
00126 void setSelected(bool s) { m_selected = s; }
00127 bool isSelected() const { return m_selected; }
00128
00129 void setObjectName( const QString &_objectName )
00130 { m_objectName = _objectName; }
00131 QString getObjectName() const
00132 { return m_objectName; }
00133
00134 virtual void setProtect( bool b ) { m_protect = b; }
00135 bool isProtect() const { return m_protect; }
00136
00137 virtual void setKeepRatio( bool b ) { m_keepRatio = b; }
00138 bool isKeepRatio() const { return m_keepRatio; }
00139
00140 virtual void rotate( float _angle ) { angle = _angle; }
00141 virtual float getAngle() const { return angle; }
00142
00143 struct KSpreadOasisSaveContext
00144 {
00145 KSpreadOasisSaveContext( KoXmlWriter &_xmlWriter, KoGenStyles &_context,
00146 int &_indexObj, int &_partIndexObj )
00147 : xmlWriter( _xmlWriter )
00148 , context( _context )
00149 , indexObj( _indexObj )
00150 , partIndexObj( _partIndexObj )
00151 {};
00152
00153 KoXmlWriter &xmlWriter;
00154 KoGenStyles &context;
00155 int &indexObj;
00156 int &partIndexObj;
00157 };
00158
00159 virtual bool load( const QDomElement& element );
00160 virtual void loadOasis(const QDomElement &element, KoOasisLoadingContext & context );
00161 virtual QDomElement save( QDomDocument& doc );
00162 virtual bool saveOasisObject( KSpreadOasisSaveContext &sc ) const;
00163 virtual void draw( QPainter *_painter );
00164
00172 QPixmap toPixmap( QSize size );
00173
00177 QPixmap toPixmap();
00178
00182 virtual QPixmap toPixmap( double xZoom , double yZoom );
00183
00184
00185 void paintSelection( QPainter *_painter, SelectionMode selectionMode );
00186 virtual QCursor getCursor( const QPoint &_point, ModifyType &_modType, QRect &geometry ) const;
00187
00188 virtual void removeFromObjList()
00189 { inObjList = false; }
00190 virtual void addToObjList()
00191 { inObjList = true; }
00192 virtual void incCmdRef()
00193 { cmds++; }
00194 virtual void decCmdRef()
00195 { cmds--; doDelete(); }
00196
00197
00198 virtual QBrush getBrush() const { return m_brush.getBrush(); }
00199
00200
00201 protected:
00205 virtual const char * getOasisElementName() const = 0;
00206 virtual void saveOasisPosObject( KoXmlWriter &xmlWriter, int indexObj ) const;
00207 virtual bool saveOasisObjectAttributes( KSpreadOasisSaveContext &sc ) const;
00208
00209 virtual void doDelete();
00210
00218 void calculateRequiredZoom( QSize desiredSize , double& xZoom, double& yZoom );
00219
00220 KoRect m_geometry;
00221 Sheet *m_sheet;
00222 Canvas *m_canvas;
00223 QString m_objectName;
00224 bool m_selected:1;
00225 bool m_protect:1;
00226 bool m_keepRatio:1;
00227 bool inObjList:1;
00228 int cmds;
00229 float angle;
00230
00231 KoPen pen;
00232 KoBrush m_brush;
00233 };
00234
00238 class EmbeddedKOfficeObject : public EmbeddedObject
00239 {
00240 public:
00241 EmbeddedKOfficeObject( Doc *parent, Sheet *_sheet, KoDocument* doc, const KoRect& geometry );
00242 EmbeddedKOfficeObject( Doc *parent, Sheet *_sheet );
00243 virtual ~EmbeddedKOfficeObject();
00244 virtual ObjType getType() const { return OBJECT_KOFFICE_PART; }
00245 virtual QString getTypeString() const
00246 { return i18n("Embedded Object"); }
00247
00248 Doc* parent();
00249 KoDocumentChild *embeddedObject();
00250
00251 bool load( const QDomElement& element );
00252 virtual void loadOasis(const QDomElement &element, KoOasisLoadingContext & context );
00253 QDomElement save( QDomDocument& doc );
00254 virtual void draw( QPainter *_painter );
00255
00259 virtual QPixmap toPixmap(double xZoom , double yZoom);
00260
00261 void activate( View *_view, Canvas *_canvas );
00262 void deactivate();
00263
00264 protected:
00265 void updateChildGeometry();
00266 virtual const char * getOasisElementName() const;
00267 virtual bool saveOasisObjectAttributes( KSpreadOasisSaveContext &sc ) const;
00268
00269 KoDocumentChild *m_embeddedObject;
00270 Doc *m_parent;
00271 };
00272
00273
00277 class EmbeddedChart : public EmbeddedKOfficeObject
00278 {
00279 public:
00280 EmbeddedChart( Doc *_spread, Sheet *_sheet, KoDocument* doc, const KoRect& _rect );
00281 EmbeddedChart( Doc *_spread, Sheet *_sheet );
00282 virtual ~EmbeddedChart();
00283 virtual ObjType getType() const { return OBJECT_CHART; }
00284 virtual QString getTypeString() const
00285 { return i18n("Chart"); }
00286
00287 void setDataArea( const QRect& _data );
00288 void update();
00289
00290 bool load( const QDomElement& element );
00291 virtual void loadOasis(const QDomElement &element, KoOasisLoadingContext & context );
00292 QDomElement save( QDomDocument& doc );
00293 virtual void draw( QPainter *_painter );
00294
00298 bool loadDocument( KoStore* _store );
00299
00300 KoChart::Part* chart();
00301
00302 protected:
00303 virtual const char * getOasisElementName() const;
00304 virtual bool saveOasisObjectAttributes( KSpreadOasisSaveContext &sc ) const;
00305
00306 private:
00307 ChartBinding *m_pBinding;
00308 };
00309
00310
00314 class EmbeddedPictureObject : public EmbeddedObject
00315 {
00316 public:
00317 EmbeddedPictureObject(Sheet *_sheet, const KoRect& _geometry, KoPictureCollection *_imageCollection );
00318 EmbeddedPictureObject(Sheet *_sheet, const KoRect& _geometry, KoPictureCollection *_imageCollection, const KoPictureKey & key );
00319 EmbeddedPictureObject( Sheet *_sheet, KoPictureCollection *_imageCollection );
00320 virtual ~EmbeddedPictureObject();
00321 EmbeddedPictureObject &operator=( const EmbeddedPictureObject & );
00322
00323 virtual ObjType getType() const { return OBJECT_PICTURE; }
00324 virtual QString getTypeString() const
00325 { return i18n("Picture"); }
00326 bool load( const QDomElement& element );
00327 virtual void loadOasis(const QDomElement &element, KoOasisLoadingContext & context );
00328 QDomElement save( QDomDocument& doc );
00329 virtual void draw( QPainter *_painter );
00330
00334 virtual QPixmap toPixmap(double xZoom , double yZoom);
00335
00340 QString getFileName() const
00341 { return image.getKey().filename(); }
00342
00343 KoPictureKey getKey() const
00344 { return image.getKey(); }
00345
00346 QSize originalSize() const
00347 { return image.getOriginalSize(); }
00348
00349 void setPicture( const KoPictureKey & key );
00350
00351 void reload( void );
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361 QPixmap getOriginalPixmap();
00362 PictureMirrorType getPictureMirrorType() const { return mirrorType; }
00363 int getPictureDepth() const { return depth; }
00364 bool getPictureSwapRGB() const { return swapRGB; }
00365 bool getPictureGrayscal() const { return grayscal; }
00366 int getPictureBright() const { return bright; }
00367
00368 ImageEffect getImageEffect() const {return m_effect;}
00369 QVariant getIEParam1() const {return m_ie_par1;}
00370 QVariant getIEParam2() const {return m_ie_par2;}
00371 QVariant getIEParam3() const {return m_ie_par3;}
00372 void setImageEffect(ImageEffect eff) { m_effect = eff; }
00373 void setIEParams(QVariant p1, QVariant p2, QVariant p3) {
00374 m_ie_par1=p1;
00375 m_ie_par2=p2;
00376 m_ie_par3=p3;
00377 }
00378
00379 void setPictureMirrorType(const PictureMirrorType &_mirrorType) { mirrorType = _mirrorType; }
00380 void setPictureDepth(int _depth) { depth = _depth; }
00381 void setPictureSwapRGB(bool _swapRGB) { swapRGB = _swapRGB; }
00382 void setPictureGrayscal(bool _grayscal) { grayscal = _grayscal; }
00383 void setPictureBright(int _bright) { bright = _bright; }
00384
00385 KoPicture picture() const { return image;}
00386
00387 void loadPicture( const QString & fileName );
00388
00389 virtual void flip(bool horizontal );
00390
00391 protected:
00392 virtual const char * getOasisElementName() const;
00393 virtual bool saveOasisObjectAttributes( KSpreadOasisSaveContext &sc ) const;
00394
00395 QPixmap changePictureSettings( QPixmap _tmpPixmap );
00396 virtual void saveOasisPictureElement( KoGenStyle &styleobjectauto ) const;
00397 void loadOasisPictureEffect(KoOasisLoadingContext & context );
00398 virtual void fillStyle( KoGenStyle& styleObjectAuto, KoGenStyles& mainStyles ) const;
00399
00404 void drawShadow( QPainter* _painter, KoZoomHandler* _zoomHandler);
00405
00406 QPixmap generatePixmap(KoZoomHandler*_zoomHandler);
00407 QString convertValueToPercent( int val ) const;
00408
00409 KoPictureCollection *imageCollection;
00410 KoPicture image;
00411
00412 PictureMirrorType mirrorType, m_cachedMirrorType;
00413 int depth, m_cachedDepth;
00414 bool swapRGB, m_cachedSwapRGB;
00415 bool grayscal, m_cachedGrayscal;
00416 int bright, m_cachedBright;
00417
00418
00419 ImageEffect m_effect, m_cachedEffect;
00420 QVariant m_ie_par1, m_cachedPar1;
00421 QVariant m_ie_par2, m_cachedPar2;
00422 QVariant m_ie_par3, m_cachedPar3;
00423
00424 QPixmap m_cachedPixmap;
00425 QRect m_cachedRect;
00426 };
00427
00428 }
00429 #endif // KSPREAD_OBJECT_H