KOffice – TDE office suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

430 lines
13KB

  1. /* This file is part of the KDE project
  2. Copyright (C) 2006 Fredrik Edemar <f_edemar@linux.se>
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either
  6. version 2 of the License.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public License
  12. along with this library; see the file COPYING.LIB. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  14. Boston, MA 02110-1301, USA.
  15. */
  16. #ifndef KSPREAD_OBJECT_H
  17. #define KSPREAD_OBJECT_H
  18. #include "kspread_sheet.h"
  19. #include <tdelocale.h>
  20. #include <KoBrush.h>
  21. #include <KoChild.h>
  22. #include <KoDom.h>
  23. #include <KoOasisLoadingContext.h>
  24. #include <KoPen.h>
  25. #include <KoPictureCollection.h>
  26. #include <KoRect.h>
  27. #include <KoSize.h>
  28. #include <KoStore.h>
  29. #include <KoStoreDevice.h>
  30. #include <KoXmlNS.h>
  31. namespace KoChart
  32. {
  33. class Part;
  34. }
  35. namespace KSpread
  36. {
  37. class Doc;
  38. class EmbeddedKOfficeObject;
  39. class EmbeddedObject;
  40. class View;
  41. class ChartBinding;
  42. enum ObjType {
  43. OBJECT_GENERAL,
  44. OBJECT_KOFFICE_PART,
  45. OBJECT_CHART,
  46. OBJECT_PICTURE
  47. };
  48. enum SelectionMode {
  49. SM_NONE = 0,
  50. SM_MOVERESIZE = 1,
  51. SM_ROTATE = 2,
  52. SM_PROTECT = 3
  53. };
  54. enum PictureMirrorType {
  55. PM_NORMAL = 0,
  56. PM_HORIZONTAL = 1,
  57. PM_VERTICAL = 2,
  58. PM_HORIZONTALANDVERTICAL = 3
  59. };
  60. enum ImageEffect {
  61. IE_NONE = -1,
  62. IE_CHANNEL_INTENSITY = 0,
  63. IE_FADE = 1,
  64. IE_FLATTEN = 2,
  65. IE_INTENSITY = 3,
  66. IE_DESATURATE = 4,
  67. IE_CONTRAST = 5,
  68. IE_NORMALIZE = 6,
  69. IE_EQUALIZE = 7,
  70. IE_THRESHOLD = 8,
  71. IE_SOLARIZE = 9,
  72. IE_EMBOSS = 10,
  73. IE_DESPECKLE = 11,
  74. IE_CHARCOAL = 12,
  75. IE_NOISE = 13,
  76. IE_BLUR = 14,
  77. IE_EDGE = 15,
  78. IE_IMPLODE = 16,
  79. IE_OIL_PAINT = 17,
  80. IE_SHARPEN = 18,
  81. IE_SPREAD = 19,
  82. IE_SHADE = 20,
  83. IE_SWIRL = 21,
  84. IE_WAVE = 22
  85. };
  86. enum AlignType {
  87. AT_PAGE,
  88. AT_CELL
  89. };
  90. /**
  91. * Contains basic information for every object.
  92. */
  93. class EmbeddedObject
  94. {
  95. public:
  96. EmbeddedObject( Sheet *_sheet, const KoRect& _geometry );
  97. virtual ~EmbeddedObject();
  98. virtual ObjType getType() const { return OBJECT_GENERAL; }
  99. virtual TQString getTypeString() const
  100. { return TQString(); }
  101. KoRect geometry();
  102. void setGeometry( const KoRect &rect );
  103. virtual void moveBy( const KoPoint &_point );
  104. virtual void moveBy( double _dx, double _dy );
  105. virtual void resizeBy( const KoSize & _size );
  106. virtual void resizeBy( double _dx, double _dy );
  107. Sheet* sheet() const { return m_sheet; }
  108. void setSelected(bool s) { m_selected = s; }
  109. bool isSelected() const { return m_selected; }
  110. void setObjectName( const TQString &_objectName )
  111. { m_objectName = _objectName; }
  112. TQString getObjectName() const
  113. { return m_objectName; }
  114. virtual void setProtect( bool b ) { m_protect = b; }
  115. bool isProtect() const { return m_protect; }
  116. virtual void setKeepRatio( bool b ) { m_keepRatio = b; }
  117. bool isKeepRatio() const { return m_keepRatio; }
  118. virtual void rotate( float _angle ) { angle = _angle; }
  119. virtual float getAngle() const { return angle; }
  120. struct KSpreadOasisSaveContext
  121. {
  122. KSpreadOasisSaveContext( KoXmlWriter &_xmlWriter, KoGenStyles &_context,
  123. int &_indexObj, int &_partIndexObj )
  124. : xmlWriter( _xmlWriter )
  125. , context( _context )
  126. , indexObj( _indexObj )
  127. , partIndexObj( _partIndexObj )
  128. {};
  129. KoXmlWriter &xmlWriter;
  130. KoGenStyles &context;
  131. int &indexObj;
  132. int &partIndexObj;
  133. };
  134. virtual bool load( const TQDomElement& element );
  135. virtual void loadOasis(const TQDomElement &element, KoOasisLoadingContext & context );
  136. virtual TQDomElement save( TQDomDocument& doc );
  137. virtual bool saveOasisObject( KSpreadOasisSaveContext &sc ) const;
  138. virtual void draw( TQPainter *_painter );
  139. /**
  140. * Renders the embedded object to a pixmap and returns the result.
  141. * This is a convenience function which calculates the necessary x and y zoom factors to render
  142. * the pixmap at the given size and calls toPixmap(double,double)
  143. *
  144. * @param size Specifies the desired size of the returned pixmap.
  145. */
  146. TQPixmap toPixmap( TQSize size );
  147. /**
  148. * Renders the embedded object to a pixmap at 100% scale. Equivalent to calling toPixmap( 1.0, 1.0 )
  149. */
  150. TQPixmap toPixmap();
  151. /**
  152. * Renders the embedded object to a pixmap at the specified x and y scale and returns the result.
  153. */
  154. virtual TQPixmap toPixmap( double xZoom , double yZoom );
  155. void paintSelection( TQPainter *_painter, SelectionMode selectionMode );
  156. virtual TQCursor getCursor( const TQPoint &_point, ModifyType &_modType, TQRect &geometry ) const;
  157. virtual void removeFromObjList()
  158. { inObjList = false; }
  159. virtual void addToObjList()
  160. { inObjList = true; }
  161. virtual void incCmdRef()
  162. { cmds++; }
  163. virtual void decCmdRef()
  164. { cmds--; doDelete(); }
  165. //TEMP:
  166. virtual TQBrush getBrush() const { return m_brush.getBrush(); }
  167. protected:
  168. /**
  169. * Get the element name for saving the object
  170. */
  171. virtual const char * getOasisElementName() const = 0;
  172. virtual void saveOasisPosObject( KoXmlWriter &xmlWriter, int indexObj ) const;
  173. virtual bool saveOasisObjectAttributes( KSpreadOasisSaveContext &sc ) const;
  174. virtual void doDelete();
  175. /**
  176. * Calculates the X and Y zoom factors required to render the embedded object at the given size
  177. *
  178. * @param desiredSize The desired size for the embedded object to be drawn at
  179. * @param xZoom This will be set to the required X zoom factor
  180. * @param yZoom This will be set to the required Y zoom factor
  181. */
  182. void calculateRequiredZoom( TQSize desiredSize , double& xZoom, double& yZoom );
  183. KoRect m_geometry;
  184. Sheet *m_sheet;
  185. Canvas *m_canvas;
  186. TQString m_objectName;
  187. bool m_selected:1;
  188. bool m_protect:1;
  189. bool m_keepRatio:1;
  190. bool inObjList:1;
  191. int cmds;
  192. float angle;
  193. KoPen pen;
  194. KoBrush m_brush;
  195. };
  196. /**
  197. * Holds an embedded koffice object.
  198. */
  199. class EmbeddedKOfficeObject : public EmbeddedObject
  200. {
  201. public:
  202. EmbeddedKOfficeObject( Doc *parent, Sheet *_sheet, KoDocument* doc, const KoRect& geometry );
  203. EmbeddedKOfficeObject( Doc *parent, Sheet *_sheet );
  204. virtual ~EmbeddedKOfficeObject();
  205. virtual ObjType getType() const { return OBJECT_KOFFICE_PART; }
  206. virtual TQString getTypeString() const
  207. { return i18n("Embedded Object"); }
  208. Doc* parent();
  209. KoDocumentChild *embeddedObject();
  210. bool load( const TQDomElement& element );
  211. virtual void loadOasis(const TQDomElement &element, KoOasisLoadingContext & context );
  212. TQDomElement save( TQDomDocument& doc );
  213. virtual void draw( TQPainter *_painter );
  214. /**
  215. * See EmbeddedObject::toPixmap(double,double)
  216. */
  217. virtual TQPixmap toPixmap(double xZoom , double yZoom);
  218. void activate( View *_view, Canvas *_canvas );
  219. void deactivate();
  220. protected:
  221. void updateChildGeometry();
  222. virtual const char * getOasisElementName() const;
  223. virtual bool saveOasisObjectAttributes( KSpreadOasisSaveContext &sc ) const;
  224. KoDocumentChild *m_embeddedObject;
  225. Doc *m_parent;
  226. };
  227. /**
  228. * Holds an embedded chart object.
  229. */
  230. class EmbeddedChart : public EmbeddedKOfficeObject
  231. {
  232. public:
  233. EmbeddedChart( Doc *_spread, Sheet *_sheet, KoDocument* doc, const KoRect& _rect );
  234. EmbeddedChart( Doc *_spread, Sheet *_sheet );
  235. virtual ~EmbeddedChart();
  236. virtual ObjType getType() const { return OBJECT_CHART; }
  237. virtual TQString getTypeString() const
  238. { return i18n("Chart"); }
  239. void setDataArea( const TQRect& _data );
  240. void update();
  241. bool load( const TQDomElement& element );
  242. virtual void loadOasis(const TQDomElement &element, KoOasisLoadingContext & context );
  243. TQDomElement save( TQDomDocument& doc );
  244. virtual void draw( TQPainter *_painter );
  245. /**
  246. * @reimp
  247. */
  248. bool loadDocument( KoStore* _store );
  249. KoChart::Part* chart();
  250. protected:
  251. virtual const char * getOasisElementName() const;
  252. virtual bool saveOasisObjectAttributes( KSpreadOasisSaveContext &sc ) const;
  253. private:
  254. ChartBinding *m_pBinding;
  255. };
  256. /**
  257. * Holds a picture object.
  258. */
  259. class EmbeddedPictureObject : public EmbeddedObject
  260. {
  261. public:
  262. EmbeddedPictureObject(Sheet *_sheet, const KoRect& _geometry, KoPictureCollection *_imageCollection );
  263. EmbeddedPictureObject(Sheet *_sheet, const KoRect& _geometry, KoPictureCollection *_imageCollection, const KoPictureKey & key );
  264. EmbeddedPictureObject( Sheet *_sheet, KoPictureCollection *_imageCollection );
  265. virtual ~EmbeddedPictureObject();
  266. EmbeddedPictureObject &operator=( const EmbeddedPictureObject & );
  267. virtual ObjType getType() const { return OBJECT_PICTURE; }
  268. virtual TQString getTypeString() const
  269. { return i18n("Picture"); }
  270. bool load( const TQDomElement& element );
  271. virtual void loadOasis(const TQDomElement &element, KoOasisLoadingContext & context );
  272. TQDomElement save( TQDomDocument& doc );
  273. virtual void draw( TQPainter *_painter );
  274. /**
  275. * See EmbeddedObject::toPixmap(double,double)
  276. */
  277. virtual TQPixmap toPixmap(double xZoom , double yZoom);
  278. /**
  279. * Only used as a default value in the filedialog, in changePicture
  280. * \warning Do not use for anything else
  281. */
  282. TQString getFileName() const
  283. { return image.getKey().filename(); }
  284. KoPictureKey getKey() const
  285. { return image.getKey(); }
  286. TQSize originalSize() const
  287. { return image.getOriginalSize(); }
  288. void setPicture( const KoPictureKey & key );
  289. void reload( void );
  290. //virtual TQDomDocumentFragment save( TQDomDocument& doc, double offset );
  291. //virtual double load(const TQDomElement &element);
  292. //virtual void loadOasis(const TQDomElement &element, KoOasisLoadingContext & context, KPRLoadingInfo *info);
  293. // virtual void draw( TQPainter *_painter, KoZoomHandler*_zoomHandler,
  294. // int /* page */, SelectionMode selectionMode, bool drawContour = FALSE );
  295. TQPixmap getOriginalPixmap();
  296. PictureMirrorType getPictureMirrorType() const { return mirrorType; }
  297. int getPictureDepth() const { return depth; }
  298. bool getPictureSwapRGB() const { return swapRGB; }
  299. bool getPictureGrayscal() const { return grayscal; }
  300. int getPictureBright() const { return bright; }
  301. ImageEffect getImageEffect() const {return m_effect;}
  302. TQVariant getIEParam1() const {return m_ie_par1;}
  303. TQVariant getIEParam2() const {return m_ie_par2;}
  304. TQVariant getIEParam3() const {return m_ie_par3;}
  305. void setImageEffect(ImageEffect eff) { m_effect = eff; }
  306. void setIEParams(TQVariant p1, TQVariant p2, TQVariant p3) {
  307. m_ie_par1=p1;
  308. m_ie_par2=p2;
  309. m_ie_par3=p3;
  310. }
  311. void setPictureMirrorType(const PictureMirrorType &_mirrorType) { mirrorType = _mirrorType; }
  312. void setPictureDepth(int _depth) { depth = _depth; }
  313. void setPictureSwapRGB(bool _swapRGB) { swapRGB = _swapRGB; }
  314. void setPictureGrayscal(bool _grayscal) { grayscal = _grayscal; }
  315. void setPictureBright(int _bright) { bright = _bright; }
  316. KoPicture picture() const { return image;}
  317. void loadPicture( const TQString & fileName );
  318. virtual void flip(bool horizontal );
  319. protected:
  320. virtual const char * getOasisElementName() const;
  321. virtual bool saveOasisObjectAttributes( KSpreadOasisSaveContext &sc ) const;
  322. TQPixmap changePictureSettings( TQPixmap _tmpPixmap );
  323. virtual void saveOasisPictureElement( KoGenStyle &styleobjectauto ) const;
  324. void loadOasisPictureEffect(KoOasisLoadingContext & context );
  325. virtual void fillStyle( KoGenStyle& styleObjectAuto, KoGenStyles& mainStyles ) const;
  326. /**
  327. * @internal
  328. * Draws the shadow
  329. */
  330. void drawShadow( TQPainter* _painter, KoZoomHandler* _zoomHandler);
  331. TQPixmap generatePixmap(KoZoomHandler*_zoomHandler);
  332. TQString convertValueToPercent( int val ) const;
  333. KoPictureCollection *imageCollection;
  334. KoPicture image;
  335. PictureMirrorType mirrorType, m_cachedMirrorType;
  336. int depth, m_cachedDepth;
  337. bool swapRGB, m_cachedSwapRGB;
  338. bool grayscal, m_cachedGrayscal;
  339. int bright, m_cachedBright;
  340. //image effect and its params
  341. ImageEffect m_effect, m_cachedEffect;
  342. TQVariant m_ie_par1, m_cachedPar1;
  343. TQVariant m_ie_par2, m_cachedPar2;
  344. TQVariant m_ie_par3, m_cachedPar3;
  345. TQPixmap m_cachedPixmap;
  346. TQRect m_cachedRect;
  347. };
  348. } // namespace KSpread
  349. #endif // KSPREAD_OBJECT_H