kpresenter

KPrObject.h
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
3 Copyright (C) 2005-2006 Thorsten Zachmann <zachmann@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#ifndef kpobject_h
22#define kpobject_h
23
24#include <tqbrush.h>
25#include <tqcursor.h>
26
27#include "global.h"
28
29#include "KPrGradient.h"
30#include "KoPointArray.h"
31#include <tdelocale.h>
32#include <KoPoint.h>
33#include <KoSize.h>
34#include <KoRect.h>
35#include <KoStyleStack.h>
36#include <KoOasisStyles.h>
37#include <KoXmlWriter.h>
38#include <KoGenStyles.h>
39#include "KPrLoadingInfo.h"
40#include "KPrBrush.h"
41#include <KoPen.h>
42
43class KoSavingContext;
44class TQPainter;
45class DCOPObject;
46class TQDomDocumentFragment;
47class TQDomDocument;
48class TQDomElement;
49class KoTextZoomHandler;
50class KPrDocument;
51class KPrTextObject;
52class KoTextObject;
53class KoOasisContext;
54
55#define RAD_FACTOR 180.0 / M_PI
56#define MIN_SIZE 10
57
58class KPrObject
59{
60public:
61 KPrObject();
62 virtual ~KPrObject();
63
64
65 virtual DCOPObject* dcopObject();
66
67 virtual void setSelected( bool _selected )
68 { selected = _selected; }
69 virtual void rotate( float _angle )
70 { angle = _angle; }
71 virtual void setSize( const KoSize & _size )
72 { setSize( _size.width(), _size.height() ); }
73 virtual void setSize(double _width, double _height )
74 { ext = KoSize( TQMAX( MIN_SIZE, _width ), TQMAX( MIN_SIZE, _height ) ); } // no object is smaller than 10x10
75 virtual void setOrig( const KoPoint & _point )
76 { orig = _point; }
77 virtual void setOrig( double _x, double _y )
78 { orig = KoPoint( _x, _y ); }
79 virtual void moveBy( const KoPoint &_point )
80 { orig = orig + _point; }
81 virtual void moveBy( double _dx, double _dy )
82 { orig = orig + KoPoint( _dx, _dy ); }
83 virtual void resizeBy( const KoSize & _size )
84 { resizeBy( _size.width(), _size.height() ); }
85 virtual void resizeBy( double _dx, double _dy )
86 { setSize( ext.width() + _dx, ext.height() + _dy ); } // call (possibly reimplemented) setSize
87
88 virtual void setShadowParameter(int _distance,ShadowDirection _direction,const TQColor &_color)
89 {
90 shadowDistance = _distance;
91 shadowDirection = _direction;
92 shadowColor = _color;
93 }
94
95 virtual void setShadowDistance( int _distance )
96 { shadowDistance = _distance; }
97 virtual void setShadowDirection( ShadowDirection _direction )
98 { shadowDirection = _direction; }
99 virtual void setShadowColor( const TQColor & _color )
100 { shadowColor = _color; }
101 virtual void setEffect( Effect _effect )
102 { effect = _effect; }
103 virtual void setEffect2( Effect2 _effect2 )
104 { effect2 = _effect2; }
105 virtual void setAppearStep( int _appearStep )
106 { appearStep = _appearStep; }
107 virtual void setDisappear( bool b )
108 { disappear = b; }
109 virtual void setDisappearStep( int num )
110 { disappearStep = num; }
111 virtual void setEffect3( Effect3 _effect3)
112 { effect3 = _effect3; }
113 virtual void setAppearSpeed( EffectSpeed _speed )
114 { m_appearSpeed = _speed; }
115 virtual void setDisappearSpeed( EffectSpeed _speed )
116 { m_disappearSpeed = _speed; }
117 virtual void setAppearTimer( int _appearTimer )
118 { appearTimer = _appearTimer; }
119 virtual void setDisappearTimer( int _disappearTimer )
120 { disappearTimer = _disappearTimer; }
121 virtual void setAppearSoundEffect( bool b )
122 { appearSoundEffect = b; }
123 virtual void setDisappearSoundEffect( bool b )
124 { disappearSoundEffect = b; }
125 virtual void setAppearSoundEffectFileName( const TQString & _a_fileName )
126 { a_fileName = _a_fileName; }
127 virtual void setDisappearSoundEffectFileName( const TQString &_d_fileName )
128 { d_fileName = _d_fileName; }
129
130 virtual void setObjectName( const TQString &_objectName )
131 { objectName = _objectName; }
132 virtual TQString getObjectName() const
133 { return objectName; }
134
135 virtual TQDomDocumentFragment save( TQDomDocument& doc, double offset );
136 virtual double load(const TQDomElement &element);
137 virtual void loadOasis(const TQDomElement &element, KoOasisContext & context, KPrLoadingInfo *info);
138
139 struct KPOasisSaveContext
140 {
141 KPOasisSaveContext( KoXmlWriter &_xmlWriter, KoSavingContext &_context,
142 int &_indexObj, int &_partIndexObj, bool _onMaster )
143 : xmlWriter( _xmlWriter )
144 , context( _context )
145 , indexObj( _indexObj )
146 , partIndexObj( _partIndexObj )
147 , onMaster( _onMaster ) {};
148
149 KoXmlWriter &xmlWriter;
150 KoSavingContext &context;
151 int &indexObj;
152 int &partIndexObj;
153 bool onMaster;
154 };
155
156 virtual bool saveOasisObject( KPOasisSaveContext &sc ) const;
157
158 //return true if we have a animation into object
159 bool saveOasisObjectStyleShowAnimation( KoXmlWriter &animation, int objectId );
160 bool saveOasisObjectStyleHideAnimation( KoXmlWriter &animation, int objectId );
161
162 virtual void flip(bool horizontal );
163
164 virtual ObjType getType() const
165 { return OT_UNDEFINED; }
166 virtual TQString getTypeString() const
167 { return TQString(); }
168
169 virtual bool isSelected() const
170 { return selected; }
171 virtual float getAngle() const
172 { return angle; }
173 virtual int getShadowDistance() const
174 { return shadowDistance; }
175 virtual ShadowDirection getShadowDirection() const
176 { return shadowDirection; }
177 virtual TQColor getShadowColor() const
178 { return shadowColor; }
179 virtual KoSize getSize() const
180 { return ext; }
181 virtual KoPoint getOrig() const
182 { return orig; }
183 KoRect getRect() const
184 { return KoRect( getOrig(), getSize() ); }
185
186 virtual KoSize getRealSize() const;
187 virtual KoPoint getRealOrig() const;
188 KoRect getRealRect() const;
194 KoRect getRepaintRect() const;
195
196 virtual Effect getEffect() const
197 { return effect; }
198 virtual Effect2 getEffect2() const
199 { return effect2; }
200 virtual Effect3 getEffect3() const
201 { return effect3; }
202 virtual EffectSpeed getAppearSpeed() const
203 { return m_appearSpeed; }
204 virtual EffectSpeed getDisappearSpeed() const
205 { return m_disappearSpeed; }
206 virtual int getAppearTimer() const
207 { return appearTimer; }
208 virtual int getDisappearTimer() const
209 { return disappearTimer; }
210 virtual bool getAppearSoundEffect() const
211 { return appearSoundEffect; }
212 virtual bool getDisappearSoundEffect() const
213 { return disappearSoundEffect; }
214 virtual TQString getAppearSoundEffectFileName() const
215 { return a_fileName; }
216 virtual TQString getDisappearSoundEffectFileName() const
217 { return d_fileName; }
221 virtual int getAppearStep() const
222 { return appearStep; }
223 virtual int getSubPresSteps() const
224 { return 0; }
225 virtual bool getDisappear() const
226 { return disappear; }
230 virtual int getDisappearStep() const
231 { return disappearStep; }
232
233 virtual void setOwnClipping( bool _ownClipping )
234 { ownClipping = _ownClipping; }
235 virtual void setSubPresStep( int _subPresStep )
236 { subPresStep = _subPresStep; }
237 virtual void doSpecificEffects( bool _specEffects, bool _onlyCurrStep = true )
238 { specEffects = _specEffects; onlyCurrStep = _onlyCurrStep; }
239
240 // the main drawing method.
241 virtual void draw( TQPainter *_painter, KoTextZoomHandler*_zoomHandler,
242 int /*pageNum*/, SelectionMode selectionMode, bool drawContour = false );
243
252 virtual bool contains( const KoPoint &point ) const;
253
262 virtual bool intersects( const KoRect & rect ) const;
263
264 virtual TQCursor getCursor( const KoPoint &_point, ModifyType &_modType, KPrDocument *doc ) const;
265
266 KoRect rotateRectObject() const;
267 void rotateObject(TQPainter *paint,KoTextZoomHandler *_zoomHandler);
268
269 virtual void removeFromObjList()
270 { inObjList = false; }
271 virtual void addToObjList()
272 { inObjList = true; }
273 virtual void incCmdRef()
274 { cmds++; }
275 virtual void decCmdRef()
276 { cmds--; doDelete(); }
277
278 virtual void setProtect( bool b ) { protect = b; }
279 bool isProtect() const { return protect; }
280
281 virtual void setKeepRatio( bool b ) { keepRatio = b; }
282 bool isKeepRatio() const { return keepRatio; }
283
284 static void setupClipRegion( TQPainter *painter, const TQRegion &clipRegion );
285
286 void paintSelection( TQPainter *_painter,KoTextZoomHandler *_zoomHandler,
287 SelectionMode selectionMode );
288
294 virtual void addTextObjects( TQPtrList<KoTextObject> & ) const {}
295
296 virtual KPrTextObject *nextTextObject() { return 0L;} // deprecated
297 virtual void getAllObjectSelectedList(TQPtrList<KPrObject> &lst, bool force = false )
298 { if (selected || force ) lst.append( this );}
299 virtual KoPen getPen() const;
300
301 bool hasAnimation() const;
302
306 void addSelfToGuides( TQValueList<double> &horizontalPos, TQValueList<double> &verticalPos );
307
308protected:
315 static void getRealSizeAndOrigFromPoints( KoPointArray &points, float angle,
316 KoSize &size, KoPoint &orig );
317
321 void getShadowCoords( double& _x, double& _y ) const;
322
323 virtual void doDelete();
324
325 TQDomElement createValueElement(const TQString &tag, int value, TQDomDocument &doc);
326 TQDomElement createGradientElement(const TQString &tag, const TQColor &c1, const TQColor &c2,
327 int type, bool unbalanced, int xfactor, int yfactor, TQDomDocument &doc);
328 TQDomElement createPenElement(const TQString &tag, const KoPen &pen, TQDomDocument &doc);
329 KoPen toPen(const TQDomElement &element) const;
330
331 TQDomElement createBrushElement(const TQString &tag, const TQBrush &brush, TQDomDocument &doc);
332 TQBrush toBrush(const TQDomElement &element) const;
333
334 TQColor retrieveColor(const TQDomElement &element, const TQString &cattr="color",
335 const TQString &rattr="red", const TQString &gattr="green",
336 const TQString &battr="blue") const;
337
338 void saveOasisObjectProtectStyle( KoGenStyle &styleobjectauto ) const;
339 void saveOasisShadowElement( KoGenStyle &styleobjectauto ) const;
340
341 TQString getStyle( KPOasisSaveContext &sc ) const;
342 virtual void fillStyle( KoGenStyle& styleObjectAuto, KoGenStyles& mainStyles ) const;
346 virtual const char * getOasisElementName() const = 0;
347 //virtual bool saveOasisObjectAttributes( KPOasisSaveContext &sc ) const = 0;
348 virtual bool saveOasisObjectAttributes( KPOasisSaveContext &sc ) const;
349 virtual void saveOasisPosObject( KoXmlWriter &xmlWriter, int indexObj ) const;
350
351 float angle;
352 KoPoint orig;
353 KoSize ext;
354 int shadowDistance;
355 ShadowDirection shadowDirection;
356 TQColor shadowColor;
357 Effect effect;
358 Effect2 effect2;
359 Effect3 effect3;
360 EffectSpeed m_appearSpeed;
361 EffectSpeed m_disappearSpeed;
362 int appearTimer, disappearTimer;
363 TQString a_fileName, d_fileName;
364 TQString objectName;
365 // step when objects appears/disappears
366 int appearStep, disappearStep;
367
368 bool disappear:1;
369 bool appearSoundEffect:1;
370 bool disappearSoundEffect:1;
371 bool selected:1;
372 bool specEffects:1;
373 bool onlyCurrStep:1;
374 bool ownClipping:1;
375 bool inObjList:1;
376 bool resize:1;
377 bool protect:1;
378 bool keepRatio:1;
379
380 int subPresStep;
381 int cmds;
382
383 DCOPObject *dcop;
384
385 static const TQString &tagORIG, &attrX, &attrY,
386 &tagSIZE, &attrWidth, &attrHeight, &tagSHADOW,
387 &attrDistance, &attrDirection, &attrColor, &attrC1,
388 &attrC2, &attrType, &attrUnbalanced, &attrXFactor,
389 &attrYFactor, &attrStyle, &tagEFFECTS, &attrEffect,
390 &attrEffect2, &tagPRESNUM, &tagANGLE,
391 &tagDISAPPEAR, &attrDoit, &attrNum, &tagFILLTYPE,
392 &tagGRADIENT, &tagPEN, &tagBRUSH, &attrValue;
393
394private:
395 // Don't copy or assign it
396 KPrObject(const KPrObject &rhs);
397 KPrObject &operator=(const KPrObject &rhs);
398};
399
405class KPrShadowObject : public KPrObject
406{
407public:
409 KPrShadowObject( const KoPen &_pen );
410
411 KPrShadowObject &operator=( const KPrShadowObject & );
412
413 virtual void setPen( const KoPen &_pen )
414 { pen = _pen; }
415
416 virtual KoPen getPen() const
417 { return pen; }
418
419 virtual TQDomDocumentFragment save( TQDomDocument& doc, double offset );
420 virtual double load(const TQDomElement &element);
421 virtual void loadOasis(const TQDomElement &element, KoOasisContext & context, KPrLoadingInfo *info);
422 virtual void draw( TQPainter *_painter, KoTextZoomHandler*_zoomHandler,
423 int pageNum, SelectionMode selectionMode, bool drawContour = false );
424 virtual void saveOasisStrokeElement( KoGenStyles& mainStyles, KoGenStyle &styleobjectauto ) const;
425 TQString saveOasisStrokeStyle( KoGenStyles& mainStyles ) const;
426
427protected:
431 static bool saveOasisDrawPoints( const KoPointArray &points, KPOasisSaveContext &sc );
432
436 bool loadOasisDrawPoints( KoPointArray &points, const TQDomElement &element,
437 KoOasisContext & context, KPrLoadingInfo *info );
438
439
451 bool loadOasisApplyViewBox( const TQDomElement &element, KoPointArray &points );
452
453 virtual void fillStyle( KoGenStyle& styleObjectAuto, KoGenStyles& mainStyles ) const;
454
461 virtual KoPen defaultPen() const;
462
473 virtual void paint( TQPainter* /* painter */, KoTextZoomHandler* /* zoomHandler */,
474 int /* pageNum */, bool drawingShadow, bool /* drawContour */ = false );
475 KoPen pen;
476};
477
478class KPr2DObject : public KPrShadowObject
479{
480public:
481 KPr2DObject();
482 KPr2DObject( const KoPen &_pen, const TQBrush &_brush, FillType _fillType,
483 const TQColor &_gColor1, const TQColor &_gColor2, BCType _gType,
484 bool _unbalanced, int _xfactor, int _yfactor );
485 virtual ~KPr2DObject() { delete gradient; }
486
487 virtual void setFillType( FillType fillType );
488 virtual void setBrush( const TQBrush &brush )
489 { m_brush.setBrush( brush ); }
490 virtual void setGColor1( const TQColor &gColor1 )
491 { if ( gradient ) gradient->setColor1( gColor1 ); m_brush.setGColor1( gColor1 ); m_redrawGradientPix = true; }
492 virtual void setGColor2( const TQColor &gColor2 )
493 { if ( gradient ) gradient->setColor2( gColor2 ); m_brush.setGColor2( gColor2 ); m_redrawGradientPix = true; }
494 virtual void setGType( BCType gType )
495 { if ( gradient ) gradient->setBackColorType( gType ); m_brush.setGType( gType ); m_redrawGradientPix = true; }
496 virtual void setGUnbalanced( bool b )
497 { if ( gradient ) gradient->setUnbalanced( b ); m_brush.setGUnbalanced( b ); m_redrawGradientPix = true; }
498 virtual void setGXFactor( int xfactor )
499 { if ( gradient ) gradient->setXFactor( xfactor ); m_brush.setGXFactor( xfactor ); m_redrawGradientPix = true; }
500 virtual void setGYFactor( int yfactor )
501 { if ( gradient ) gradient->setYFactor( yfactor ); m_brush.setGYFactor( yfactor ); m_redrawGradientPix = true; }
502
503 virtual FillType getFillType() const
504 { return m_brush.getFillType(); }
505 virtual TQBrush getBrush() const
506 { return m_brush.getBrush(); }
507 virtual TQColor getGColor1() const
508 { return m_brush.getGColor1(); }
509 virtual TQColor getGColor2() const
510 { return m_brush.getGColor2(); }
511 virtual BCType getGType() const
512 { return m_brush.getGType(); }
513 virtual bool getGUnbalanced() const
514 { return m_brush.getGUnbalanced(); }
515 virtual int getGXFactor() const
516 { return m_brush.getGXFactor(); }
517 virtual int getGYFactor() const
518 { return m_brush.getGYFactor(); }
519
520 virtual TQDomDocumentFragment save( TQDomDocument& doc, double offset );
521 virtual double load(const TQDomElement &element);
522 virtual void loadOasis(const TQDomElement &element, KoOasisContext & context, KPrLoadingInfo *info);
523 virtual void draw( TQPainter *_painter, KoTextZoomHandler*_zoomHandler,
524 int pageNum, SelectionMode selectionMode, bool drawContour = false );
525
526 virtual void flip(bool horizontal );
527
528protected:
529 virtual void fillStyle( KoGenStyle& styleObjectAuto, KoGenStyles& mainStyles ) const;
530
531 KPrBrush m_brush;
532 KPrGradient *gradient;
534 TQPixmap m_gradientPix;
535 bool m_redrawGradientPix;
536};
537
538class KPrStartEndLine
539{
540public:
541 KPrStartEndLine( LineEnd _start, LineEnd _end );
542 void save( TQDomDocumentFragment &fragment, TQDomDocument& doc );
543 void load( const TQDomElement &element );
544
545 void saveOasisMarkerElement( KoGenStyles& mainStyles, KoGenStyle &styleobjectauto ) const;
546 TQString saveOasisMarkerStyle( KoGenStyles &mainStyles, const LineEnd &_element ) const;
547 void loadOasisMarkerElement( KoOasisContext & context, const TQString & attr, LineEnd &_element );
548
549protected:
550 //duplicate from kpobject
551 TQDomElement createValueElement(const TQString &tag, int value, TQDomDocument &doc);
552
553 LineEnd lineBegin, lineEnd;
554};
555
556#endif
Class: KPrGradient.
Definition KPrGradient.h:40
Temporary information used only during loading.
Base class for objects with a pen and a brush, and which takes care of painting the shadow in draw() ...
Definition KPrObject.h:406
bool loadOasisDrawPoints(KoPointArray &points, const TQDomElement &element, KoOasisContext &context, KPrLoadingInfo *info)
Helper method for loading draw:points.
virtual KoPen defaultPen() const
save() only saves if the pen is different from the default pen.
virtual void paint(TQPainter *, KoTextZoomHandler *, int, bool drawingShadow, bool=false)
This method is to be implemented by all KPShadowObjects, to draw themselves.
bool loadOasisApplyViewBox(const TQDomElement &element, KoPointArray &points)
Apply the svg:viewBox attribute to the points.
static bool saveOasisDrawPoints(const KoPointArray &points, KPOasisSaveContext &sc)
Helper method for saving draw:points.