kpresenter

KPrObject.h

00001 // -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; -*-
00002 /* This file is part of the KDE project
00003    Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
00004    Copyright (C) 2005-2006 Thorsten Zachmann <zachmann@kde.org>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #ifndef kpobject_h
00023 #define kpobject_h
00024 
00025 #include <qbrush.h>
00026 #include <qcursor.h>
00027 
00028 #include "global.h"
00029 
00030 #include "KPrGradient.h"
00031 #include "KoPointArray.h"
00032 #include <klocale.h>
00033 #include <KoPoint.h>
00034 #include <KoSize.h>
00035 #include <KoRect.h>
00036 #include <KoStyleStack.h>
00037 #include <KoOasisStyles.h>
00038 #include <KoXmlWriter.h>
00039 #include <KoGenStyles.h>
00040 #include "KPrLoadingInfo.h"
00041 #include "KPrBrush.h"
00042 #include <KoPen.h>
00043 
00044 class KoSavingContext;
00045 class QPainter;
00046 class DCOPObject;
00047 class QDomDocumentFragment;
00048 class QDomDocument;
00049 class QDomElement;
00050 class KoTextZoomHandler;
00051 class KPrDocument;
00052 class KPrTextObject;
00053 class KoTextObject;
00054 class KoOasisContext;
00055 
00056 #define RAD_FACTOR 180.0 / M_PI
00057 #define MIN_SIZE 10
00058 
00059 class KPrObject
00060 {
00061 public:
00062     KPrObject();
00063     virtual ~KPrObject();
00064 
00065 
00066     virtual DCOPObject* dcopObject();
00067 
00068     virtual void setSelected( bool _selected )
00069         { selected = _selected; }
00070     virtual void rotate( float _angle )
00071         { angle = _angle; }
00072     virtual void setSize( const KoSize & _size )
00073         { setSize( _size.width(), _size.height() ); }
00074     virtual void setSize(double _width, double _height )
00075         { ext = KoSize( QMAX( MIN_SIZE, _width ), QMAX( MIN_SIZE, _height ) ); } // no object is smaller than 10x10
00076     virtual void setOrig( const KoPoint & _point )
00077         { orig = _point; }
00078     virtual void setOrig( double _x, double _y )
00079         { orig = KoPoint( _x, _y ); }
00080     virtual void moveBy( const KoPoint &_point )
00081         { orig = orig + _point; }
00082     virtual void moveBy( double _dx, double _dy )
00083         { orig = orig + KoPoint( _dx, _dy ); }
00084     virtual void resizeBy( const KoSize & _size )
00085         { resizeBy( _size.width(), _size.height() ); }
00086     virtual void resizeBy( double _dx, double _dy )
00087         { setSize( ext.width() + _dx, ext.height() + _dy ); } // call (possibly reimplemented) setSize
00088 
00089     virtual void setShadowParameter(int _distance,ShadowDirection _direction,const QColor &_color)
00090         {
00091             shadowDistance = _distance;
00092             shadowDirection = _direction;
00093             shadowColor = _color;
00094         }
00095 
00096     virtual void setShadowDistance( int _distance )
00097         { shadowDistance = _distance; }
00098     virtual void setShadowDirection( ShadowDirection _direction )
00099         { shadowDirection = _direction; }
00100     virtual void setShadowColor( const QColor & _color )
00101         { shadowColor = _color; }
00102     virtual void setEffect( Effect _effect )
00103         { effect = _effect; }
00104     virtual void setEffect2( Effect2 _effect2 )
00105         { effect2 = _effect2; }
00106     virtual void setAppearStep( int _appearStep )
00107         { appearStep = _appearStep; }
00108     virtual void setDisappear( bool b )
00109         { disappear = b; }
00110     virtual void setDisappearStep( int num )
00111         { disappearStep = num; }
00112     virtual void setEffect3( Effect3 _effect3)
00113         { effect3 = _effect3; }
00114     virtual void setAppearSpeed( EffectSpeed _speed )
00115         { m_appearSpeed = _speed; }
00116     virtual void setDisappearSpeed( EffectSpeed _speed )
00117         { m_disappearSpeed = _speed; }
00118     virtual void setAppearTimer( int _appearTimer )
00119         { appearTimer = _appearTimer; }
00120     virtual void setDisappearTimer( int _disappearTimer )
00121         { disappearTimer = _disappearTimer; }
00122     virtual void setAppearSoundEffect( bool b )
00123         { appearSoundEffect = b; }
00124     virtual void setDisappearSoundEffect( bool b )
00125         { disappearSoundEffect = b; }
00126     virtual void setAppearSoundEffectFileName( const QString & _a_fileName )
00127         { a_fileName = _a_fileName; }
00128     virtual void setDisappearSoundEffectFileName( const QString &_d_fileName )
00129         { d_fileName = _d_fileName; }
00130 
00131     virtual void setObjectName( const QString &_objectName )
00132         { objectName = _objectName; }
00133     virtual QString getObjectName() const
00134         { return objectName; }
00135 
00136     virtual QDomDocumentFragment save( QDomDocument& doc, double offset );
00137     virtual double load(const QDomElement &element);
00138     virtual void loadOasis(const QDomElement &element, KoOasisContext & context,  KPrLoadingInfo *info);
00139 
00140     struct KPOasisSaveContext
00141     {
00142         KPOasisSaveContext( KoXmlWriter &_xmlWriter, KoSavingContext &_context,
00143                             int &_indexObj, int &_partIndexObj, bool _onMaster )
00144             : xmlWriter( _xmlWriter )
00145             , context( _context ) 
00146             , indexObj( _indexObj )
00147             , partIndexObj( _partIndexObj )
00148             , onMaster( _onMaster ) {};
00149             
00150         KoXmlWriter &xmlWriter;
00151         KoSavingContext &context;
00152         int &indexObj;
00153         int &partIndexObj;
00154         bool onMaster;
00155     };
00156 
00157     virtual bool saveOasisObject( KPOasisSaveContext &sc ) const;
00158 
00159     //return true if we have a animation into object
00160     bool saveOasisObjectStyleShowAnimation( KoXmlWriter &animation, int objectId );
00161     bool saveOasisObjectStyleHideAnimation( KoXmlWriter &animation, int objectId );
00162 
00163     virtual void flip(bool horizontal );
00164 
00165     virtual ObjType getType() const
00166         { return OT_UNDEFINED; }
00167     virtual QString getTypeString() const
00168         { return QString(); }
00169 
00170     virtual bool isSelected() const
00171         { return selected; }
00172     virtual float getAngle() const
00173         { return angle; }
00174     virtual int getShadowDistance() const
00175         { return shadowDistance; }
00176     virtual ShadowDirection getShadowDirection() const
00177         { return shadowDirection; }
00178     virtual QColor getShadowColor() const
00179         { return shadowColor; }
00180     virtual KoSize getSize() const
00181         { return ext; }
00182     virtual KoPoint getOrig() const
00183         { return orig; }
00184     KoRect getRect() const
00185         { return KoRect( getOrig(), getSize() ); }
00186 
00187     virtual KoSize getRealSize() const;
00188     virtual KoPoint getRealOrig() const;
00189     KoRect getRealRect() const;
00195     KoRect getRepaintRect() const;
00196 
00197     virtual Effect getEffect() const
00198         { return effect; }
00199     virtual Effect2 getEffect2() const
00200         { return effect2; }
00201     virtual Effect3 getEffect3() const
00202         { return effect3; }
00203     virtual EffectSpeed getAppearSpeed() const
00204         { return m_appearSpeed; }
00205     virtual EffectSpeed getDisappearSpeed() const
00206         { return m_disappearSpeed; }
00207     virtual int getAppearTimer() const
00208         { return appearTimer; }
00209     virtual int getDisappearTimer() const
00210         { return disappearTimer; }
00211     virtual bool getAppearSoundEffect() const
00212         { return appearSoundEffect; }
00213     virtual bool getDisappearSoundEffect() const
00214         { return disappearSoundEffect; }
00215     virtual QString getAppearSoundEffectFileName() const
00216         { return a_fileName; }
00217     virtual QString getDisappearSoundEffectFileName() const
00218         { return d_fileName; }
00222     virtual int getAppearStep() const
00223         { return appearStep; }
00224     virtual int getSubPresSteps() const
00225         { return 0; }
00226     virtual bool getDisappear() const
00227         { return disappear; }
00231     virtual int getDisappearStep() const
00232         { return disappearStep; }
00233 
00234     virtual void setOwnClipping( bool _ownClipping )
00235         { ownClipping = _ownClipping; }
00236     virtual void setSubPresStep( int _subPresStep )
00237         { subPresStep = _subPresStep; }
00238     virtual void doSpecificEffects( bool _specEffects, bool _onlyCurrStep = true )
00239         { specEffects = _specEffects; onlyCurrStep = _onlyCurrStep; }
00240 
00241     // the main drawing method.
00242     virtual void draw( QPainter *_painter, KoTextZoomHandler*_zoomHandler,
00243                        int /*pageNum*/, SelectionMode selectionMode, bool drawContour = FALSE );
00244 
00253     virtual bool contains( const KoPoint &point ) const;
00254 
00263     virtual bool intersects( const KoRect & rect ) const;
00264 
00265     virtual QCursor getCursor( const KoPoint &_point, ModifyType &_modType, KPrDocument *doc ) const;
00266 
00267     KoRect rotateRectObject() const;
00268     void rotateObject(QPainter *paint,KoTextZoomHandler *_zoomHandler);
00269 
00270     virtual void removeFromObjList()
00271         { inObjList = false; }
00272     virtual void addToObjList()
00273         { inObjList = true; }
00274     virtual void incCmdRef()
00275         { cmds++; }
00276     virtual void decCmdRef()
00277         { cmds--; doDelete(); }
00278 
00279     virtual void setProtect( bool b ) { protect = b; }
00280     bool isProtect() const { return protect; }
00281 
00282     virtual void setKeepRatio( bool b ) { keepRatio = b; }
00283     bool isKeepRatio() const { return keepRatio; }
00284 
00285     static void setupClipRegion( QPainter *painter, const QRegion &clipRegion );
00286 
00287     void paintSelection( QPainter *_painter,KoTextZoomHandler *_zoomHandler,
00288                          SelectionMode selectionMode );
00289 
00295     virtual void addTextObjects( QPtrList<KoTextObject> & ) const {}
00296 
00297     virtual KPrTextObject *nextTextObject() { return 0L;} // deprecated
00298     virtual void getAllObjectSelectedList(QPtrList<KPrObject> &lst, bool force = false )
00299         { if (selected || force ) lst.append( this );}
00300     virtual KoPen getPen() const;
00301 
00302     bool hasAnimation() const;
00303 
00307     void addSelfToGuides( QValueList<double> &horizontalPos, QValueList<double> &verticalPos );
00308 
00309 protected:
00316     static void getRealSizeAndOrigFromPoints( KoPointArray &points, float angle,
00317                                               KoSize &size, KoPoint &orig );
00318 
00322     void getShadowCoords( double& _x, double& _y ) const;
00323 
00324     virtual void doDelete();
00325 
00326     QDomElement createValueElement(const QString &tag, int value, QDomDocument &doc);
00327     QDomElement createGradientElement(const QString &tag, const QColor &c1, const QColor &c2,
00328                                       int type, bool unbalanced, int xfactor, int yfactor, QDomDocument &doc);
00329     QDomElement createPenElement(const QString &tag, const KoPen &pen, QDomDocument &doc);
00330     KoPen toPen(const QDomElement &element) const;
00331 
00332     QDomElement createBrushElement(const QString &tag, const QBrush &brush, QDomDocument &doc);
00333     QBrush toBrush(const QDomElement &element) const;
00334 
00335     QColor retrieveColor(const QDomElement &element, const QString &cattr="color",
00336                          const QString &rattr="red", const QString &gattr="green",
00337                          const QString &battr="blue") const;
00338 
00339     void saveOasisObjectProtectStyle( KoGenStyle &styleobjectauto ) const;
00340     void saveOasisShadowElement( KoGenStyle &styleobjectauto ) const;
00341 
00342     QString getStyle( KPOasisSaveContext &sc ) const;
00343     virtual void fillStyle( KoGenStyle& styleObjectAuto, KoGenStyles& mainStyles ) const;
00347     virtual const char * getOasisElementName() const = 0;
00348     //virtual bool saveOasisObjectAttributes( KPOasisSaveContext &sc ) const = 0;
00349     virtual bool saveOasisObjectAttributes( KPOasisSaveContext &sc ) const;
00350     virtual void saveOasisPosObject( KoXmlWriter &xmlWriter, int indexObj ) const;
00351 
00352     float angle;
00353     KoPoint orig;
00354     KoSize ext;
00355     int shadowDistance;
00356     ShadowDirection shadowDirection;
00357     QColor shadowColor;
00358     Effect effect;
00359     Effect2 effect2;
00360     Effect3 effect3;
00361     EffectSpeed m_appearSpeed;
00362     EffectSpeed m_disappearSpeed;
00363     int appearTimer, disappearTimer;
00364     QString a_fileName, d_fileName;
00365     QString objectName;
00366     // step when objects appears/disappears
00367     int appearStep, disappearStep;
00368 
00369     bool disappear:1;
00370     bool appearSoundEffect:1;
00371     bool disappearSoundEffect:1;
00372     bool selected:1;
00373     bool specEffects:1;
00374     bool onlyCurrStep:1;
00375     bool ownClipping:1;
00376     bool inObjList:1;
00377     bool resize:1;
00378     bool protect:1;
00379     bool keepRatio:1;
00380 
00381     int subPresStep;
00382     int cmds;
00383 
00384     DCOPObject *dcop;
00385 
00386     static const QString &tagORIG, &attrX, &attrY,
00387         &tagSIZE, &attrWidth, &attrHeight, &tagSHADOW,
00388         &attrDistance, &attrDirection, &attrColor, &attrC1,
00389         &attrC2, &attrType, &attrUnbalanced, &attrXFactor,
00390         &attrYFactor, &attrStyle, &tagEFFECTS, &attrEffect,
00391         &attrEffect2, &tagPRESNUM, &tagANGLE,
00392         &tagDISAPPEAR, &attrDoit, &attrNum, &tagFILLTYPE,
00393         &tagGRADIENT, &tagPEN, &tagBRUSH, &attrValue;
00394 
00395 private:
00396     // Don't copy or assign it
00397     KPrObject(const KPrObject &rhs);
00398     KPrObject &operator=(const KPrObject &rhs);
00399 };
00400 
00406 class KPrShadowObject : public KPrObject
00407 {
00408 public:
00409     KPrShadowObject();
00410     KPrShadowObject( const KoPen &_pen );
00411 
00412     KPrShadowObject &operator=( const KPrShadowObject & );
00413 
00414     virtual void setPen( const KoPen &_pen )
00415         { pen = _pen; }
00416 
00417     virtual KoPen getPen() const
00418         { return pen; }
00419 
00420     virtual QDomDocumentFragment save( QDomDocument& doc, double offset );
00421     virtual double load(const QDomElement &element);
00422     virtual void loadOasis(const QDomElement &element, KoOasisContext & context, KPrLoadingInfo *info);
00423     virtual void draw( QPainter *_painter, KoTextZoomHandler*_zoomHandler,
00424                        int pageNum, SelectionMode selectionMode, bool drawContour = FALSE );
00425     virtual void saveOasisStrokeElement( KoGenStyles& mainStyles, KoGenStyle &styleobjectauto ) const;
00426     QString saveOasisStrokeStyle( KoGenStyles& mainStyles ) const;
00427 
00428 protected:
00432     static bool saveOasisDrawPoints( const KoPointArray &points, KPOasisSaveContext &sc );
00433 
00437     bool loadOasisDrawPoints( KoPointArray &points, const QDomElement &element,
00438                               KoOasisContext & context, KPrLoadingInfo *info );
00439 
00440 
00452     bool loadOasisApplyViewBox( const QDomElement &element, KoPointArray &points );
00453 
00454     virtual void fillStyle( KoGenStyle& styleObjectAuto, KoGenStyles& mainStyles ) const;
00455 
00462     virtual KoPen defaultPen() const;
00463 
00474     virtual void paint( QPainter* /* painter */, KoTextZoomHandler* /* zoomHandler */,
00475                         int /* pageNum */, bool drawingShadow, bool /* drawContour */ =  FALSE );
00476     KoPen pen;
00477 };
00478 
00479 class KPr2DObject : public KPrShadowObject
00480 {
00481 public:
00482     KPr2DObject();
00483     KPr2DObject( const KoPen &_pen, const QBrush &_brush, FillType _fillType,
00484                 const QColor &_gColor1, const QColor &_gColor2, BCType _gType,
00485                 bool _unbalanced, int _xfactor, int _yfactor );
00486     virtual ~KPr2DObject() { delete gradient; }
00487 
00488     virtual void setFillType( FillType fillType );
00489     virtual void setBrush( const QBrush &brush )
00490         { m_brush.setBrush( brush ); }
00491     virtual void setGColor1( const QColor &gColor1 )
00492         { if ( gradient ) gradient->setColor1( gColor1 ); m_brush.setGColor1( gColor1 ); m_redrawGradientPix = true; }
00493     virtual void setGColor2( const QColor &gColor2 )
00494         { if ( gradient ) gradient->setColor2( gColor2 ); m_brush.setGColor2( gColor2 ); m_redrawGradientPix = true; }
00495     virtual void setGType( BCType gType )
00496         { if ( gradient ) gradient->setBackColorType( gType ); m_brush.setGType( gType ); m_redrawGradientPix = true; }
00497     virtual void setGUnbalanced( bool b )
00498         { if ( gradient ) gradient->setUnbalanced( b ); m_brush.setGUnbalanced( b ); m_redrawGradientPix = true; }
00499     virtual void setGXFactor( int xfactor )
00500         { if ( gradient ) gradient->setXFactor( xfactor ); m_brush.setGXFactor( xfactor ); m_redrawGradientPix = true; }
00501     virtual void setGYFactor( int yfactor )
00502         { if ( gradient ) gradient->setYFactor( yfactor ); m_brush.setGYFactor( yfactor ); m_redrawGradientPix = true; }
00503 
00504     virtual FillType getFillType() const
00505         { return m_brush.getFillType(); }
00506     virtual QBrush getBrush() const
00507         { return m_brush.getBrush(); }
00508     virtual QColor getGColor1() const
00509         { return m_brush.getGColor1(); }
00510     virtual QColor getGColor2() const
00511         { return m_brush.getGColor2(); }
00512     virtual BCType getGType() const
00513         { return m_brush.getGType(); }
00514     virtual bool getGUnbalanced() const
00515         { return m_brush.getGUnbalanced(); }
00516     virtual int getGXFactor() const
00517         { return m_brush.getGXFactor(); }
00518     virtual int getGYFactor() const
00519         { return m_brush.getGYFactor(); }
00520 
00521     virtual QDomDocumentFragment save( QDomDocument& doc, double offset );
00522     virtual double load(const QDomElement &element);
00523     virtual void loadOasis(const QDomElement &element, KoOasisContext & context, KPrLoadingInfo *info);
00524     virtual void draw( QPainter *_painter, KoTextZoomHandler*_zoomHandler,
00525                        int pageNum, SelectionMode selectionMode, bool drawContour = FALSE );
00526 
00527     virtual void flip(bool horizontal );
00528 
00529 protected:
00530     virtual void fillStyle( KoGenStyle& styleObjectAuto, KoGenStyles& mainStyles ) const;
00531 
00532     KPrBrush m_brush;
00533     KPrGradient *gradient;
00535     QPixmap m_gradientPix;
00536     bool m_redrawGradientPix;
00537 };
00538 
00539 class KPrStartEndLine
00540 {
00541 public:
00542     KPrStartEndLine( LineEnd _start, LineEnd _end );
00543     void save( QDomDocumentFragment &fragment, QDomDocument& doc );
00544     void load( const QDomElement &element );
00545 
00546     void saveOasisMarkerElement( KoGenStyles& mainStyles,  KoGenStyle &styleobjectauto ) const;
00547     QString saveOasisMarkerStyle( KoGenStyles &mainStyles, const LineEnd &_element ) const;
00548     void loadOasisMarkerElement( KoOasisContext & context, const QString & attr, LineEnd &_element );
00549 
00550 protected:
00551     //duplicate from kpobject
00552     QDomElement createValueElement(const QString &tag, int value, QDomDocument &doc);
00553 
00554     LineEnd lineBegin, lineEnd;
00555 };
00556 
00557 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys