kpresenter

KPrCommand.cpp

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) 2001 Laurent Montel <lmontel@mandrakesoft.com>
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 #include "KPrDocument.h"
00023 #include "KPrPage.h"
00024 #include "KPrCommand.h"
00025 #include "KPrBackground.h"
00026 #include "KPrGroupObject.h"
00027 
00028 
00029 #include "KPrLineObject.h"
00030 #include "KPrEllipseObject.h"
00031 #include "KPrAutoformObject.h"
00032 #include "KPrFreehandObject.h"
00033 #include "KPrPolylineObject.h"
00034 #include "KPrBezierCurveObject.h"
00035 #include "KPrPolygonObject.h"
00036 #include "KPrClosedLineObject.h"
00037 
00038 #include "KPrTextObject.h"
00039 #include "KPrPixmapObject.h"
00040 
00041 #include "KPrPartObject.h"
00042 #include <KoRuler.h>
00043 #include "KPrPieObject.h"
00044 #include "KPrRectObject.h"
00045 #include "KPrView.h"
00046 #include "KoTextObject.h"
00047 #include "KPrTextDocument.h"
00048 #include <kdebug.h>
00049 #include "KPrVariableCollection.h"
00050 #include <KoRect.h>
00051 #include <KoSize.h>
00052 #include <KoPoint.h>
00053 #include <KoDom.h>
00054 #include <KoTextParag.h>
00055 #include <KoXmlNS.h>
00056 #include <KoStore.h>
00057 #include <KoOasisContext.h>
00058 #include <KoOasisStyles.h>
00059 #include <KoOasisStore.h>
00060 
00061 #include <qxml.h>
00062 #include <qbuffer.h>
00063 
00064 
00065 KPrShadowCmd::KPrShadowCmd( const QString &_name, QPtrList<ShadowValues> &_oldShadow, ShadowValues _newShadow,
00066                       QPtrList<KPrObject> &_objects, KPrDocument *_doc )
00067     : KNamedCommand( _name ), oldShadow( _oldShadow ), objects( _objects )
00068 {
00069     objects.setAutoDelete( false );
00070     oldShadow.setAutoDelete( false );
00071     doc = _doc;
00072     newShadow = _newShadow;
00073 
00074     m_page = doc->findPage( objects );
00075 
00076     QPtrListIterator<KPrObject> it( objects );
00077     for ( ; it.current() ; ++it )
00078         it.current()->incCmdRef();
00079 }
00080 
00081 KPrShadowCmd::~KPrShadowCmd()
00082 {
00083     QPtrListIterator<KPrObject> it( objects );
00084     for ( ; it.current() ; ++it )
00085         it.current()->decCmdRef();
00086     oldShadow.setAutoDelete( true );
00087     oldShadow.clear();
00088 }
00089 
00090 void KPrShadowCmd::execute()
00091 {
00092     QPtrListIterator<KPrObject> it( objects );
00093     for ( ; it.current() ; ++it )
00094         it.current()->setShadowParameter(newShadow.shadowDistance,
00095                                          newShadow.shadowDirection,
00096                                          newShadow.shadowColor);
00097     doc->repaint( false );
00098 
00099     doc->updateSideBarItem( m_page );
00100 }
00101 
00102 void KPrShadowCmd::unexecute()
00103 {
00104     for ( unsigned int i = 0; i < objects.count(); i++ )
00105         objects.at( i )->setShadowParameter(oldShadow.at(i)->shadowDistance,
00106                                             oldShadow.at(i)->shadowDirection,
00107                                             oldShadow.at(i)->shadowColor);
00108     doc->repaint( false );
00109 
00110     doc->updateSideBarItem( m_page );
00111 }
00112 
00113 
00114 KPrSetOptionsCmd::KPrSetOptionsCmd( const QString &_name, QValueList<KoPoint> &_diffs, QPtrList<KPrObject> &_objects,
00115                               double _gridX, double _gridY, double _oldGridX, double _oldGridY,
00116                               const QColor &_txtBackCol, const QColor &_otxtBackCol, KPrDocument *_doc )
00117     : KNamedCommand( _name ),
00118       diffs( _diffs ),
00119       objects( _objects ),
00120       txtBackCol( _txtBackCol ),
00121       otxtBackCol( _otxtBackCol )
00122 {
00123     gridX = _gridX;
00124     gridY = _gridY;
00125     oldGridX = _oldGridX;
00126     oldGridY = _oldGridY;
00127     doc = _doc;
00128     QPtrListIterator<KPrObject> it( objects );
00129     for ( ; it.current() ; ++it )
00130         it.current()->incCmdRef();
00131 }
00132 
00133 KPrSetOptionsCmd::~KPrSetOptionsCmd()
00134 {
00135     QPtrListIterator<KPrObject> it( objects );
00136     for ( ; it.current() ; ++it )
00137         it.current()->decCmdRef();
00138 }
00139 
00140 void KPrSetOptionsCmd::execute()
00141 {
00142     // ## use iterator
00143     for ( unsigned int i = 0; i < objects.count(); i++ )
00144         objects.at( i )->moveBy( *diffs.at( i ) );
00145     doc->setGridValue( gridX, gridY, false );
00146     doc->updateRuler();
00147     doc->setTxtBackCol( txtBackCol );
00148     doc->repaint( false );
00149 }
00150 
00151 void KPrSetOptionsCmd::unexecute()
00152 {
00153     for ( unsigned int i = 0; i < objects.count(); i++ )
00154         objects.at( i )->moveBy( -(*diffs.at( i )).x(), -(*diffs.at( i )).y() );
00155     doc->setGridValue( oldGridX, oldGridY, false );
00156     doc->updateRuler();
00157     doc->setTxtBackCol( otxtBackCol );
00158     doc->repaint( false );
00159 }
00160 
00161 KPrSetBackCmd::KPrSetBackCmd( const QString &name, const KPrBackGround::Settings &settings,
00162                         const KPrBackGround::Settings &oldSettings,
00163                         bool useMasterBackground,
00164                         bool takeGlobal, KPrDocument *doc, KPrPage *page )
00165 : KNamedCommand( name )
00166 , m_settings( settings )
00167 , m_oldSettings( oldSettings )
00168 , m_useMasterBackground( useMasterBackground )
00169 , m_oldUseMasterBackground( page->useMasterBackground() )
00170 , m_takeGlobal( takeGlobal )
00171 , m_doc( doc )
00172 , m_page( page )
00173 {
00174 }
00175 
00176 void KPrSetBackCmd::execute()
00177 {
00178     if ( !m_takeGlobal ) {
00179         m_page->background()->setBackGround( m_settings );
00180         m_page->setUseMasterBackground( m_useMasterBackground );
00181         m_doc->restoreBackground( m_page );
00182     } else {
00183         QPtrListIterator<KPrPage> it( m_doc->getPageList() );
00184         for ( ; it.current() ; ++it )
00185         {
00186             it.current()->background()->setBackGround( m_settings );
00187             it.current()->setUseMasterBackground( m_useMasterBackground );
00188             m_doc->restoreBackground(it.current());
00189         }
00190 
00191     }
00192     m_doc->repaint( false );
00193 
00194     if ( m_takeGlobal ) {
00195         QPtrListIterator<KPrPage> it( m_doc->getPageList() );
00196         for ( int pos = 0; it.current(); ++it, ++pos ) {
00197             m_doc->updateSideBarItem( it.current() );
00198         }
00199     }
00200     else {
00201         m_doc->updateSideBarItem( m_page );
00202     }
00203 }
00204 
00205 void KPrSetBackCmd::unexecute()
00206 {
00207     if ( !m_takeGlobal ) {
00208         m_page->background()->setBackGround( m_oldSettings );
00209         m_page->setUseMasterBackground( m_oldUseMasterBackground );
00210         m_doc->restoreBackground( m_page );
00211     } else {
00212         QPtrListIterator<KPrPage> it( m_doc->getPageList() );
00213         for ( ; it.current() ; ++it )
00214         {
00215             it.current()->background()->setBackGround( m_oldSettings );
00216             it.current()->setUseMasterBackground( m_oldUseMasterBackground );
00217             m_doc->restoreBackground(it.current());
00218         }
00219     }
00220     m_doc->repaint( false );
00221 
00222     if ( m_takeGlobal ) {
00223         QPtrListIterator<KPrPage> it( m_doc->getPageList() );
00224         for ( int pos = 0; it.current(); ++it, ++pos ) {
00225             m_doc->updateSideBarItem( it.current() );
00226         }
00227     }
00228     else {
00229         m_doc->updateSideBarItem( m_page );
00230     }
00231 }
00232 
00233 KPrRotateCmd::KPrRotateCmd( const QString &_name, float newAngle, QPtrList<KPrObject> &objects,
00234                       KPrDocument *doc, bool addAngle )
00235     : KNamedCommand( _name ), m_doc( doc ), m_newAngle( newAngle ), m_addAngle( addAngle )
00236 {
00237     m_objects.setAutoDelete( false );
00238     m_oldAngles.setAutoDelete( false );
00239 
00240     QPtrListIterator<KPrObject> it( objects );
00241     for ( ; it.current() ; ++it )
00242     {
00243         m_objects.append( it.current() );
00244 
00245         RotateValues *old = new RotateValues;
00246         old->angle = it.current()->getAngle();
00247         m_oldAngles.append( old );
00248 
00249         it.current()->incCmdRef();
00250     }
00251 
00252     m_page = m_doc->findPage( m_objects );
00253 }
00254 
00255 KPrRotateCmd::~KPrRotateCmd()
00256 {
00257     QPtrListIterator<KPrObject> it( m_objects );
00258     for ( ; it.current() ; ++it )
00259         it.current()->decCmdRef();
00260     m_oldAngles.setAutoDelete( true );
00261     m_oldAngles.clear();
00262 }
00263 
00264 void KPrRotateCmd::execute()
00265 {
00266     QPtrListIterator<KPrObject> it( m_objects );
00267     for ( ; it.current() ; ++it )
00268     {
00269         if ( m_addAngle )
00270             it.current()->rotate( it.current()->getAngle() + m_newAngle );
00271         else
00272             it.current()->rotate( m_newAngle );
00273     }
00274     m_doc->updateRuler();
00275     m_doc->repaint( false );
00276 
00277     m_doc->updateSideBarItem( m_page );
00278 }
00279 
00280 void KPrRotateCmd::unexecute()
00281 {
00282     for ( unsigned int i = 0; i < m_objects.count(); i++ )
00283         m_objects.at(i)->rotate( m_oldAngles.at( i )->angle );
00284     m_doc->updateRuler();
00285     m_doc->repaint( false );
00286 
00287     m_doc->updateSideBarItem( m_page );
00288 }
00289 
00290 
00291 KPrChgPixCmd::KPrChgPixCmd( const QString &_name, KPrPixmapObject *_oldObject, KPrPixmapObject *_newObject,
00292                       KPrDocument *_doc, KPrPage *_page)
00293     : KNamedCommand( _name )
00294 {
00295     oldObject = _oldObject;
00296     newObject = _newObject;
00297     m_page=_page;
00298     doc = _doc;
00299     oldObject->incCmdRef();
00300     newObject->incCmdRef();
00301     newObject->setSize( oldObject->getSize() );
00302     newObject->setOrig( oldObject->getOrig() );
00303 }
00304 
00305 KPrChgPixCmd::~KPrChgPixCmd()
00306 {
00307     oldObject->decCmdRef();
00308     newObject->decCmdRef();
00309 }
00310 
00311 void KPrChgPixCmd::execute()
00312 {
00313     m_page->replaceObject( oldObject, newObject );
00314     doc->repaint( newObject );
00315 
00316     doc->updateSideBarItem( m_page );
00317 }
00318 
00319 void KPrChgPixCmd::unexecute()
00320 {
00321     m_page->replaceObject( newObject, oldObject );
00322     doc->repaint( oldObject );
00323 
00324     doc->updateSideBarItem( m_page );
00325 }
00326 
00327 KPrDeleteCmd::KPrDeleteCmd( const QString &_name, QPtrList<KPrObject> &_objects,
00328                       KPrDocument *_doc, KPrPage *_page )
00329 : KNamedCommand( _name )
00330 , m_oldObjectList( _page->objectList() )
00331 , m_objectsToDelete( _objects )
00332 , m_doc( _doc )
00333 , m_page( _page )
00334 {
00335     QPtrListIterator<KPrObject> it( m_oldObjectList );
00336     for ( ; it.current() ; ++it )
00337         it.current()->incCmdRef();
00338 }
00339 
00340 KPrDeleteCmd::~KPrDeleteCmd()
00341 {
00342     QPtrListIterator<KPrObject> it( m_oldObjectList );
00343     for ( ; it.current() ; ++it )
00344         it.current()->decCmdRef();
00345 }
00346 
00347 void KPrDeleteCmd::execute()
00348 {
00349     bool textObj=false;
00350 
00351     QPtrListIterator<KPrObject> it( m_oldObjectList );
00352     QPtrListIterator<KPrObject> itDelete( m_objectsToDelete );
00353     QPtrList<KPrObject> newObjectList;
00354     for ( ; it.current(); ++it )
00355     {
00356         if ( it.current() == itDelete.current() )
00357         {
00358             it.current()->setSelected( false );
00359             it.current()->removeFromObjList();
00360 
00361             if ( !textObj && it.current()->getType() == OT_TEXT )
00362             {
00363                 KPrTextObject * tmp = dynamic_cast<KPrTextObject *>( it.current() );
00364                 if ( tmp )
00365                     tmp->setEditingTextObj( false );
00366                 textObj=true;
00367             }
00368             ++itDelete;
00369         }
00370         else
00371         {
00372             newObjectList.append( it.current() );
00373         }
00374     }
00375 
00376     m_page->setObjectList( newObjectList );
00377 
00378     for ( itDelete.toFirst(); itDelete.current(); ++itDelete )
00379     {
00380         QRect oldRect = m_doc->zoomHandler()->zoomRect( itDelete.current()->getRepaintRect() );
00381         m_doc->repaint( oldRect );
00382     }
00383     if(textObj)
00384         m_doc->updateRuler();
00385 
00386     m_doc->updateSideBarItem( m_page );
00387 }
00388 
00389 void KPrDeleteCmd::unexecute()
00390 {
00391     m_page->setObjectList( m_oldObjectList );
00392     QPtrListIterator<KPrObject> it( m_objectsToDelete );
00393     for ( ; it.current(); ++it )
00394     {
00395         it.current()->addToObjList();
00396         m_doc->repaint( it.current() );
00397     }
00398 
00399     m_doc->updateSideBarItem( m_page );
00400 }
00401 
00402 
00403 KPrEffectCmd::KPrEffectCmd( const QString &_name, const QPtrList<KPrObject> &_objs,
00404                       const QValueList<EffectStruct> &_oldEffects, EffectStruct _newEffect )
00405     : KNamedCommand( _name ), oldEffects( _oldEffects ),
00406       newEffect( _newEffect ), objs( _objs )
00407 {
00408     QPtrListIterator<KPrObject> it( objs );
00409     for ( ; it.current() ; ++it )
00410         it.current()->incCmdRef();
00411 }
00412 
00413 KPrEffectCmd::~KPrEffectCmd()
00414 {
00415     QPtrListIterator<KPrObject> it( objs );
00416     for ( ; it.current() ; ++it )
00417         it.current()->decCmdRef();
00418 }
00419 
00420 void KPrEffectCmd::execute()
00421 {
00422     QPtrListIterator<KPrObject> it( objs );
00423     for ( ; it.current() ; ++it )
00424     {
00425         it.current()->setAppearStep( newEffect.appearStep );
00426         it.current()->setEffect( newEffect.effect );
00427         it.current()->setEffect2( newEffect.effect2 );
00428         it.current()->setDisappear( newEffect.disappear );
00429         it.current()->setEffect3( newEffect.effect3 );
00430         it.current()->setDisappearStep( newEffect.disappearStep );
00431         it.current()->setAppearSpeed( newEffect.m_appearSpeed );
00432         it.current()->setDisappearSpeed( newEffect.m_disappearSpeed );
00433         it.current()->setAppearTimer( newEffect.appearTimer );
00434         it.current()->setDisappearTimer( newEffect.disappearTimer );
00435         it.current()->setAppearSoundEffect( newEffect.appearSoundEffect );
00436         it.current()->setDisappearSoundEffect( newEffect.disappearSoundEffect );
00437         it.current()->setAppearSoundEffectFileName( newEffect.a_fileName );
00438         it.current()->setDisappearSoundEffectFileName( newEffect.d_fileName );
00439     }
00440 }
00441 
00442 void KPrEffectCmd::unexecute()
00443 {
00444     KPrObject *object = 0;
00445     for ( unsigned int i = 0; i < objs.count(); ++i ) {
00446         object = objs.at( i );
00447 
00448         object->setAppearStep( oldEffects[ i ].appearStep );
00449         object->setEffect( oldEffects[ i ].effect );
00450         object->setEffect2( oldEffects[ i ].effect2 );
00451         object->setDisappear( oldEffects[ i ].disappear );
00452         object->setEffect3( oldEffects[ i ].effect3 );
00453         object->setDisappearStep( oldEffects[ i ].disappearStep );
00454         object->setAppearSpeed( oldEffects[ i ].m_appearSpeed );
00455         object->setDisappearSpeed( oldEffects[ i ].m_disappearSpeed );
00456         object->setAppearTimer( oldEffects[ i ].appearTimer );
00457         object->setDisappearTimer( oldEffects[ i ].disappearTimer );
00458         object->setAppearSoundEffect( oldEffects[ i ].appearSoundEffect );
00459         object->setDisappearSoundEffect( oldEffects[ i ].disappearSoundEffect );
00460         object->setAppearSoundEffectFileName( oldEffects[ i ].a_fileName );
00461         object->setDisappearSoundEffectFileName( oldEffects[ i ].d_fileName );
00462     }
00463 }
00464 
00465 KPrGroupObjCmd::KPrGroupObjCmd( const QString &_name,
00466                           const QPtrList<KPrObject> &_objects,
00467                           KPrDocument *_doc, KPrPage *_page )
00468 : KNamedCommand( _name )
00469 , m_objectsToGroup( _objects )
00470 , m_oldObjectList( _page->objectList() )
00471 , m_doc( _doc )
00472 , m_page( _page )
00473 {
00474     m_groupObject = new KPrGroupObject( m_objectsToGroup );
00475     m_groupObject->incCmdRef();
00476 }
00477 
00478 KPrGroupObjCmd::~KPrGroupObjCmd()
00479 {
00480     m_groupObject->decCmdRef();
00481 }
00482 
00483 void KPrGroupObjCmd::execute()
00484 {
00485     KoRect r;
00486     int position = 0;
00487     QPtrListIterator<KPrObject> it( m_objectsToGroup );
00488     for ( ; it.current() ; ++it )
00489     {
00490         it.current()->setSelected( false );
00491         position = m_page->takeObject(it.current() );
00492         r |= it.current()->getRealRect();
00493     }
00494 
00495     m_groupObject->setUpdateObjects( false );
00496     m_groupObject->setOrig( r.x(), r.y() );
00497     m_groupObject->setSize( r.width(), r.height() );
00498     m_page->insertObject( m_groupObject, position );
00499     m_groupObject->addToObjList();
00500     m_groupObject->setUpdateObjects( true );
00501     m_groupObject->setSelected( true );
00502     m_doc->refreshGroupButton();
00503 
00504     m_doc->repaint( false );
00505 
00506     m_doc->updateSideBarItem( m_page );
00507 }
00508 
00509 void KPrGroupObjCmd::unexecute()
00510 {
00511     m_groupObject->setUpdateObjects( false );
00512 
00513     m_page->setObjectList( m_oldObjectList );
00514     m_groupObject->removeFromObjList();
00515 
00516     QPtrListIterator<KPrObject> it( m_objectsToGroup );
00517     for ( ; it.current() ; ++it )
00518     {
00519         it.current()->addToObjList();
00520         it.current()->setSelected( true );
00521     }
00522 
00523     m_doc->refreshGroupButton();
00524 
00525     m_doc->repaint( false );
00526 
00527     m_doc->updateSideBarItem( m_page );
00528 }
00529 
00530 UnGroupObjCmd::UnGroupObjCmd( const QString &_name,
00531                               KPrGroupObject *grpObj_,
00532                               KPrDocument *_doc, KPrPage *_page )
00533 : KNamedCommand( _name )
00534 , m_groupedObjects( grpObj_->getObjects() )
00535 , m_groupObject( grpObj_ )
00536 , m_doc( _doc )
00537 , m_page( _page )
00538 {
00539     m_groupObject->incCmdRef();
00540 }
00541 
00542 UnGroupObjCmd::~UnGroupObjCmd()
00543 {
00544     m_groupObject->decCmdRef();
00545 }
00546 
00547 void UnGroupObjCmd::execute()
00548 {
00549     m_groupObject->setUpdateObjects( false );
00550 
00551     int position = m_page->takeObject( m_groupObject );
00552     m_groupObject->removeFromObjList();
00553 
00554     QPtrListIterator<KPrObject> it( m_groupedObjects );
00555     for ( it.toLast(); it.current() ; --it )
00556     {
00557         m_page->insertObject( it.current(), position );
00558         it.current()->addToObjList();
00559         it.current()->setSelected( true );
00560     }
00561 
00562     m_doc->refreshGroupButton();
00563 
00564     m_doc->repaint( false );
00565 
00566     m_doc->updateSideBarItem( m_page );
00567 }
00568 
00569 void UnGroupObjCmd::unexecute()
00570 {
00571     KoRect r=KoRect();
00572     int position = 0;
00573     QPtrListIterator<KPrObject> it( m_groupedObjects );
00574     for ( ; it.current() ; ++it )
00575     {
00576         it.current()->setSelected( false );
00577         position = m_page->takeObject( it.current() );
00578         r |= it.current()->getRealRect();
00579     }
00580 
00581     m_groupObject->setUpdateObjects( false );
00582     m_groupObject->setOrig( r.x(), r.y() );
00583     m_groupObject->setSize( r.width(), r.height() );
00584     m_page->insertObject( m_groupObject, position );
00585     m_groupObject->addToObjList();
00586     m_groupObject->setUpdateObjects( true );
00587     m_groupObject->setSelected( true );
00588     m_doc->refreshGroupButton();
00589 
00590     m_doc->repaint( false );
00591 
00592     m_doc->updateSideBarItem( m_page );
00593 }
00594 
00595 KPrInsertCmd::KPrInsertCmd( const QString &name, const QValueList<KPrObject *> objects, 
00596                             KPrDocument *doc, KPrPage *page )
00597 : KNamedCommand( name )
00598 , m_objects( objects )    
00599 , m_object( 0 )
00600 , m_doc( doc )
00601 , m_page( page )    
00602 {
00603     QValueListConstIterator<KPrObject *> it( m_objects.begin() );
00604     for ( ; it != m_objects.end(); ++it )
00605     {
00606         ( *it )->incCmdRef();
00607     }
00608 }
00609 
00610 KPrInsertCmd::KPrInsertCmd( const QString &name, KPrObject *object,
00611                             KPrDocument *doc, KPrPage *page )
00612 : KNamedCommand( name )
00613 , m_object( object )
00614 , m_doc( doc )
00615 , m_page( page )    
00616 {
00617     m_object->incCmdRef();
00618 }
00619 
00620 KPrInsertCmd::~KPrInsertCmd()
00621 {
00622     if ( m_object )
00623     {
00624         m_object->decCmdRef();
00625     }
00626     else
00627     {
00628         QValueListConstIterator<KPrObject *> it( m_objects.begin() );
00629         for ( ; it != m_objects.end(); ++it )
00630         {
00631             ( *it )->decCmdRef();
00632         }
00633     }
00634 }
00635 
00636 void KPrInsertCmd::execute()
00637 {
00638     if ( m_object )
00639     {
00640         m_page->appendObject( m_object );
00641         m_object->addToObjList();
00642         if ( m_object->getType() == OT_TEXT )
00643             m_doc->updateRuler();
00644         m_doc->repaint( m_object );
00645     }
00646     else
00647     {
00648         m_page->appendObjects( m_objects );
00649         QValueListConstIterator<KPrObject *> it( m_objects.begin() );
00650         bool updateRuler = false;
00651         for ( ; it != m_objects.end(); ++it )
00652         {
00653             ( *it )->addToObjList();
00654             if ( ( *it )->getType() == OT_TEXT )
00655                 updateRuler = true;
00656             m_doc->repaint( *it );
00657         }
00658         if ( updateRuler )
00659             m_doc->updateRuler();
00660     }
00661 
00662     m_doc->updateSideBarItem( m_page );
00663 }
00664 
00665 void KPrInsertCmd::unexecute()
00666 {
00667     if ( m_object )
00668     {
00669         QRect oldRect = m_doc->zoomHandler()->zoomRect( m_object->getRepaintRect() );
00670         QPtrList<KPrObject> list(m_page->objectList());
00671         if ( list.findRef( m_object ) != -1 ) {
00672             m_page->takeObject( m_object );
00673             m_object->removeFromObjList();
00674             if ( m_object->getType() == OT_TEXT )
00675             {
00676                 m_doc->terminateEditing( (KPrTextObject*)m_object );
00677                 ((KPrTextObject*)m_object)->setEditingTextObj( false );
00678                 m_doc->updateRuler();
00679             }
00680         }
00681         m_doc->repaint( oldRect );
00682     }
00683     else
00684     {
00685         QPtrList<KPrObject> list(m_page->objectList());
00686         bool updateRuler = false;
00687 
00688         QValueListConstIterator<KPrObject *> it( m_objects.begin() );
00689         for ( ; it != m_objects.end(); ++it )
00690         {
00691             if ( list.findRef( *it ) != -1 )
00692             {
00693                 m_page->takeObject( *it );
00694                 ( *it )->removeFromObjList();
00695                 if ( ( *it )->getType() == OT_TEXT )
00696                 {
00697                     m_doc->terminateEditing( (KPrTextObject*)( *it ) );
00698                     ( (KPrTextObject*) *it )->setEditingTextObj( false );
00699                     updateRuler = true;
00700                 }
00701             }
00702         }
00703         if ( updateRuler )
00704             m_doc->updateRuler();
00705 
00706         m_doc->repaint( false );
00707     }
00708 
00709     m_doc->updateSideBarItem( m_page );
00710 }
00711 
00712 KPrLowerRaiseCmd::KPrLowerRaiseCmd( const QString &_name, const QPtrList<KPrObject>& _oldList,
00713                               const QPtrList<KPrObject>& _newList, KPrDocument *_doc,
00714                               KPrPage *_page )
00715     : KNamedCommand( _name )
00716 {
00717     oldList = _oldList;
00718     newList = _newList;
00719     m_page=_page;
00720     oldList.setAutoDelete( false );
00721     newList.setAutoDelete( false );
00722     doc = _doc;
00723 
00724     QPtrListIterator<KPrObject> it( oldList );
00725     for ( ; it.current() ; ++it )
00726         it.current()->incCmdRef();
00727 }
00728 
00729 KPrLowerRaiseCmd::~KPrLowerRaiseCmd()
00730 {
00731     QPtrListIterator<KPrObject> it( oldList );
00732     for ( ; it.current() ; ++it )
00733         it.current()->decCmdRef();
00734 }
00735 
00736 void KPrLowerRaiseCmd::execute()
00737 {
00738     m_page->setObjectList( newList );
00739     doc->repaint( false );
00740 
00741     doc->updateSideBarItem( m_page );
00742 }
00743 
00744 void KPrLowerRaiseCmd::unexecute()
00745 {
00746     m_page->setObjectList( oldList );
00747     doc->repaint( false );
00748 
00749     doc->updateSideBarItem( m_page );
00750 }
00751 
00752 
00753 KPrMoveByCmd::KPrMoveByCmd( const QString &_name, const KoPoint &_diff, QPtrList<KPrObject> &_objects,
00754                       KPrDocument *_doc,KPrPage *_page )
00755     : KNamedCommand( _name ), diff( _diff ), objects( _objects )
00756 {
00757     objects.setAutoDelete( false );
00758     doc = _doc;
00759     m_page=_page;
00760     QPtrListIterator<KPrObject> it( objects );
00761     for ( ; it.current() ; ++it )
00762     {
00763         it.current()->incCmdRef();
00764     }
00765 }
00766 
00767 KPrMoveByCmd::~KPrMoveByCmd()
00768 {
00769     QPtrListIterator<KPrObject> it( objects );
00770     for ( ; it.current() ; ++it )
00771         it.current()->decCmdRef();
00772 }
00773 
00774 void KPrMoveByCmd::execute()
00775 {
00776     QRect oldRect;
00777 
00778     for ( unsigned int i = 0; i < objects.count(); i++ ) {
00779         oldRect = doc->zoomHandler()->zoomRect( objects.at( i )->getRepaintRect() );
00780         objects.at( i )->moveBy( diff );
00781         if ( objects.at( i )->getType() == OT_TEXT )
00782         {
00783             if(objects.at(i)->isSelected())
00784                 doc->updateRuler();
00785         }
00786         doc->repaint( oldRect );
00787         doc->repaint( objects.at( i ) );
00788     }
00789 
00790     doc->updateSideBarItem( m_page );
00791     doc->updateObjectStatusBarItem();
00792 }
00793 
00794 void KPrMoveByCmd::unexecute()
00795 {
00796     QRect oldRect;
00797 
00798     for ( unsigned int i = 0; i < objects.count(); i++ ) {
00799         oldRect = doc->zoomHandler()->zoomRect( objects.at( i )->getRepaintRect() );
00800         objects.at( i )->moveBy( -diff.x(), -diff.y() );
00801         if ( objects.at( i )->getType() == OT_TEXT )
00802         {
00803             if(objects.at(i)->isSelected())
00804                 doc->updateRuler();
00805         }
00806         doc->repaint( oldRect );
00807         doc->repaint( objects.at( i ) );
00808     }
00809 
00810     doc->updateSideBarItem( m_page );
00811     doc->updateObjectStatusBarItem();
00812 }
00813 
00814 KPrAlignCmd::KPrAlignCmd( const QString &_name, QPtrList<KPrObject> &_objects, AlignType _at, KPrDocument *_doc )
00815     : KNamedCommand( _name ), doc(_doc)
00816 {
00817     objects.setAutoDelete( false );
00818     diffs.setAutoDelete( true );
00819     m_page = doc->findPage( _objects );
00820 
00821     QPtrListIterator<KPrObject> it( _objects );
00822     KoRect boundingRect;
00823     for ( ; it.current() ; ++it )
00824     {
00825         boundingRect |= it.current()->getRealRect();
00826     }
00827 
00828     if ( _objects.count() == 1 )
00829         boundingRect = m_page->getPageRect();
00830 
00831     it.toFirst();
00832     for ( ; it.current() ; ++it )
00833     {
00834         KoPoint * diff = NULL;
00835         switch ( _at )
00836         {
00837             case AT_LEFT:
00838               diff = new KoPoint( boundingRect.x() - it.current()->getRealOrig().x(), 0 );
00839               break;
00840             case AT_TOP:
00841               diff = new KoPoint( 0, boundingRect.y() - it.current()->getRealOrig().y() );
00842               break;
00843             case AT_RIGHT:
00844               diff = new KoPoint( boundingRect.x() + boundingRect.width() -
00845                                   it.current()->getRealOrig().x() - it.current()->getRealSize().width(), 0 );
00846               break;
00847             case AT_BOTTOM:
00848               diff = new KoPoint( 0, boundingRect.y() + boundingRect.height() -
00849                                   it.current()->getRealOrig().y() - it.current()->getRealSize().height() );
00850               break;
00851             case AT_HCENTER:
00852               diff = new KoPoint( ( boundingRect.width() - it.current()->getRealSize().width() ) / 2 -
00853                                   it.current()->getRealOrig().x() + boundingRect.x(), 0 );
00854               break;
00855             case AT_VCENTER:
00856               diff = new KoPoint( 0, ( boundingRect.height() - it.current()->getRealSize().height() ) / 2 -
00857                                   it.current()->getRealOrig().y() + boundingRect.y() );
00858               break;
00859         }
00860         if ( diff )
00861         {
00862             objects.append( it.current() );
00863             diffs.append( diff );
00864             it.current()->incCmdRef();
00865         }
00866     }
00867 }
00868 
00869 KPrAlignCmd::~KPrAlignCmd()
00870 {
00871     QPtrListIterator<KPrObject> it( objects );
00872     for ( ; it.current() ; ++it )
00873         it.current()->decCmdRef();
00874 
00875     diffs.clear();
00876 }
00877 
00878 void KPrAlignCmd::execute()
00879 {
00880     QRect oldRect;
00881 
00882     for ( unsigned int i = 0; i < objects.count(); i++ ) {
00883         oldRect = doc->zoomHandler()->zoomRect( objects.at( i )->getRepaintRect() );
00884         objects.at( i )->moveBy( *diffs.at( i ) );
00885         if ( objects.at( i )->getType() == OT_TEXT )
00886         {
00887             if(objects.at(i)->isSelected())
00888                 doc->updateRuler();
00889         }
00890 
00891         doc->repaint( oldRect );
00892         doc->repaint( objects.at( i ) );
00893     }
00894 
00895     doc->updateSideBarItem( m_page );
00896 }
00897 
00898 void KPrAlignCmd::unexecute()
00899 {
00900     QRect oldRect;
00901 
00902     for ( unsigned int i = 0; i < objects.count(); i++ ) {
00903         oldRect = doc->zoomHandler()->zoomRect(objects.at( i )->getRepaintRect() );
00904         objects.at( i )->moveBy( -diffs.at( i )->x(), -diffs.at( i )->y() );
00905         if ( objects.at( i )->getType() == OT_TEXT )
00906         {
00907             if(objects.at(i)->isSelected())
00908                 doc->updateRuler();
00909         }
00910         doc->repaint( oldRect );
00911         doc->repaint( objects.at( i ) );
00912         doc->updateRuler();
00913     }
00914 
00915     doc->updateSideBarItem( m_page );
00916 }
00917 
00918 KoPenCmd::KoPenCmd( const QString &_name, QPtrList<KPrObject> &_objects, Pen _newPen,
00919                 KPrDocument *_doc, KPrPage *_page, int _flags )
00920 : KNamedCommand(_name), doc(_doc), m_page( _page ), newPen(_newPen), flags(_flags)
00921 {
00922     objects.setAutoDelete( false );
00923     oldPen.setAutoDelete( false );
00924 
00925     addObjects( _objects );
00926 }
00927 
00928 KoPenCmd::~KoPenCmd()
00929 {
00930     QPtrListIterator<KPrObject> it( objects );
00931     for ( ; it.current() ; ++it )
00932         it.current()->decCmdRef();
00933 
00934     oldPen.setAutoDelete( true );
00935     oldPen.clear();
00936 }
00937 
00938 void KoPenCmd::execute()
00939 {
00940     for ( int i = 0; i < static_cast<int>( objects.count() ); i++ )
00941     {
00942         Pen tmpPen = *oldPen.at( i );
00943 
00944         if ( flags & LineBegin )
00945             tmpPen.lineBegin = newPen.lineBegin;
00946 
00947         if ( flags & LineEnd )
00948             tmpPen.lineEnd = newPen.lineEnd;
00949 
00950         if ( flags & Color )
00951             tmpPen.pen.setColor( newPen.pen.color() );
00952 
00953         if ( flags & Width )
00954             tmpPen.pen.setPointWidth( newPen.pen.pointWidth() );
00955 
00956         if ( flags & Style )
00957             tmpPen.pen.setStyle( newPen.pen.style() );
00958 
00959         applyPen( objects.at( i ), &tmpPen );
00960     }
00961 
00962     // this has to be called as the outline could have been changed so 
00963     // that the toolbar is updated correctly
00964     doc->updateObjectSelected();
00965     doc->updateSideBarItem( m_page );
00966 }
00967 
00968 void KoPenCmd::applyPen( KPrObject *object, Pen *tmpPen )
00969 {
00970     switch (object->getType()) {
00971         case OT_LINE:
00972         {
00973             KPrLineObject* obj=dynamic_cast<KPrLineObject*>( object );
00974             if( obj )
00975             {
00976                 //obj->setPen( tmpPen->pen );
00977                 obj->setLineBegin( tmpPen->lineBegin );
00978                 obj->setLineEnd( tmpPen->lineEnd );
00979                 //doc->repaint( obj );
00980             }
00981         } break;
00982         case OT_FREEHAND:
00983         case OT_POLYLINE:
00984         case OT_QUADRICBEZIERCURVE:
00985         case OT_CUBICBEZIERCURVE:
00986         {
00987             KPrPointObject *obj = dynamic_cast<KPrPointObject*>( object );
00988             if ( obj )
00989             {
00990                 //obj->setPen( tmpPen->pen );
00991                 obj->setLineBegin( tmpPen->lineBegin );
00992                 obj->setLineEnd( tmpPen->lineEnd );
00993                 //doc->repaint( obj );
00994             }
00995         } break;
00996         case OT_PIE:
00997         {
00998             KPrPieObject *obj = dynamic_cast<KPrPieObject*>( object );
00999             if ( obj )
01000             {
01001                 obj->setLineBegin( tmpPen->lineBegin );
01002                 obj->setLineEnd( tmpPen->lineEnd );
01003             }
01004         } break;
01005         case OT_AUTOFORM:
01006         {
01007             KPrAutoformObject *obj = dynamic_cast<KPrAutoformObject*>( object );
01008             if ( obj )
01009             {
01010                 obj->setLineBegin( tmpPen->lineBegin );
01011                 obj->setLineEnd( tmpPen->lineEnd );
01012             }
01013         } break;
01014         default:
01015             break;
01016     }
01017 
01018     KPrShadowObject *obj = dynamic_cast<KPrShadowObject*>( object );
01019     if ( obj )
01020     {
01021         obj->setPen( tmpPen->pen );
01022         doc->repaint( obj );
01023     }
01024 }
01025 
01026 void KoPenCmd::unexecute()
01027 {
01028     for ( unsigned int i = 0; i < objects.count(); ++i ) {
01029         if( oldPen.count() > i )
01030             applyPen( objects.at( i ), oldPen.at( i ) );
01031     }
01032 
01033     // this has to be called as the outline could have been changed so 
01034     // that the toolbar is updated correctly
01035     doc->updateObjectSelected();
01036     doc->updateSideBarItem( m_page );
01037 }
01038 
01039 void KoPenCmd::addObjects( const QPtrList<KPrObject> &_objects )
01040 {
01041     QPtrListIterator<KPrObject> it( _objects );
01042     for ( ; it.current(); ++it )
01043     {
01044         KPrObject * object( it.current() );
01045         if ( object->getType() == OT_GROUP )
01046         {
01047             KPrGroupObject * obj=dynamic_cast<KPrGroupObject*>( object );
01048             if ( obj )
01049             {
01050                 addObjects( obj->objectList() );
01051             }
01052         }
01053         else
01054         {
01055             // tz TODO fix name
01056             ::LineEnd lineBegin = L_NORMAL;
01057             ::LineEnd lineEnd = L_NORMAL;
01058             switch ( it.current()->getType() ) {
01059                 case OT_LINE:
01060                 {
01061                     KPrLineObject *obj=dynamic_cast<KPrLineObject*>( object );
01062                     if ( obj )
01063                     {
01064                         lineBegin = obj->getLineBegin();
01065                         lineEnd = obj->getLineEnd();
01066                     }
01067                 } break;
01068                 case OT_FREEHAND:
01069                 case OT_POLYLINE:
01070                 case OT_QUADRICBEZIERCURVE:
01071                 case OT_CUBICBEZIERCURVE:
01072                 {
01073                     KPrPointObject *obj = dynamic_cast<KPrPointObject*>( object );
01074                     if ( obj )
01075                     {
01076                         lineBegin = obj->getLineBegin();
01077                         lineEnd = obj->getLineEnd();
01078                     }
01079                 } break;
01080                 case OT_PIE:
01081                 {
01082                     KPrPieObject *obj = dynamic_cast<KPrPieObject*>( object );
01083                     if ( obj )
01084                     {
01085                         lineBegin = obj->getLineBegin();
01086                         lineEnd = obj->getLineEnd();
01087                     }
01088                 } break;
01089                 case OT_AUTOFORM:
01090                 {
01091                     KPrAutoformObject *obj = dynamic_cast<KPrAutoformObject*>( object );
01092                     if ( obj )
01093                     {
01094                         lineBegin = obj->getLineBegin();
01095                         lineEnd = obj->getLineEnd();
01096                     }
01097                 } break;
01098                 default:
01099                    break;
01100             }
01101 
01102             KPrShadowObject *obj = dynamic_cast<KPrShadowObject*>( object );
01103             if ( obj )
01104             {
01105                 objects.append( obj );
01106                 obj->incCmdRef();
01107 
01108                 Pen * pen = new KoPenCmd::Pen( obj->getPen(), lineBegin, lineEnd );
01109 
01110                 oldPen.append( pen );
01111             }
01112         }
01113     }
01114 }
01115 
01116 
01117 KPrBrushCmd::KPrBrushCmd( const QString &_name, QPtrList<KPrObject> &_objects, Brush _newBrush,
01118                     KPrDocument *_doc, KPrPage *_page, int _flags )
01119 : KNamedCommand(_name), doc(_doc), newBrush(_newBrush), m_page(_page), flags(_flags)
01120 {
01121     objects.setAutoDelete( false );
01122     oldBrush.setAutoDelete( false );
01123 
01124     addObjects( _objects );
01125 }
01126 
01127 void KPrBrushCmd::addObjects( const QPtrList<KPrObject> &_objects )
01128 {
01129     QPtrListIterator<KPrObject> it( _objects );
01130     for ( ; it.current(); ++it )
01131     {
01132         if ( it.current()->getType() == OT_GROUP )
01133         {
01134             KPrGroupObject * obj=dynamic_cast<KPrGroupObject*>( it.current() );
01135             if ( obj )
01136             {
01137                 addObjects( obj->objectList() );
01138             }
01139         }
01140         else
01141         {
01142             KPr2DObject * obj = dynamic_cast<KPr2DObject *>( it.current() );
01143             if( obj )
01144             {
01145                 objects.append( obj );
01146                 obj->incCmdRef();
01147 
01148                 Brush * brush = new KPrBrushCmd::Brush;
01149                 brush->brush = obj->getBrush();
01150                 brush->fillType = obj->getFillType();
01151                 brush->gColor1 = obj->getGColor1();
01152                 brush->gColor2 = obj->getGColor2();
01153                 brush->gType = obj->getGType();
01154                 brush->unbalanced = obj->getGUnbalanced();
01155                 brush->xfactor = obj->getGXFactor();
01156                 brush->yfactor = obj->getGYFactor();
01157 
01158                 oldBrush.append( brush );
01159             }
01160         }
01161     }
01162 }
01163 
01164 KPrBrushCmd::~KPrBrushCmd()
01165 {
01166     QPtrListIterator<KPr2DObject> it( objects );
01167     for ( ; it.current() ; ++it )
01168         it.current()->decCmdRef();
01169 
01170     oldBrush.setAutoDelete( true );
01171     oldBrush.clear();
01172 }
01173 
01174 void KPrBrushCmd::execute()
01175 {
01176     for ( int i = 0; i < static_cast<int>( objects.count() ); i++ )
01177     {
01178         Brush tmpBrush = *oldBrush.at( i );
01179 
01180         if ( flags & BrushColor )
01181             tmpBrush.brush.setColor( newBrush.brush.color() );
01182 
01183         if ( flags & BrushStyle )
01184             tmpBrush.brush.setStyle( newBrush.brush.style() );
01185 
01186         if ( flags & BrushGradientSelect )
01187             tmpBrush.fillType = newBrush.fillType;
01188 
01189         if ( flags & GradientColor1 )
01190             tmpBrush.gColor1 = newBrush.gColor1;
01191 
01192         if ( flags & GradientColor2 )
01193             tmpBrush.gColor2 = newBrush.gColor2;
01194 
01195         if ( flags & GradientType )
01196             tmpBrush.gType = newBrush.gType;
01197 
01198         if ( flags & GradientBalanced )
01199             tmpBrush.unbalanced = newBrush.unbalanced;
01200 
01201         if ( flags & GradientXFactor )
01202             tmpBrush.xfactor = newBrush.xfactor;
01203 
01204         if ( flags & GradientYFactor )
01205             tmpBrush.yfactor = newBrush.yfactor;
01206 
01207         applyBrush( objects.at( i ), &tmpBrush );
01208     }
01209 
01210     doc->updateSideBarItem( m_page );
01211 }
01212 
01213 void KPrBrushCmd::applyBrush( KPr2DObject *object, Brush *tmpBrush )
01214 {
01215     object->setBrush( tmpBrush->brush );
01216     object->setFillType( tmpBrush->fillType );
01217     object->setGColor1( tmpBrush->gColor1 );
01218     object->setGColor2( tmpBrush->gColor2 );
01219     object->setGType( tmpBrush->gType );
01220     object->setGUnbalanced( tmpBrush->unbalanced );
01221     object->setGXFactor( tmpBrush->xfactor );
01222     object->setGYFactor( tmpBrush->yfactor );
01223     doc->repaint( object );
01224 }
01225 
01226 void KPrBrushCmd::unexecute()
01227 {
01228     for ( unsigned int i = 0; i < objects.count(); i++ ) {
01229         applyBrush( objects.at( i ), oldBrush.at( i ) );
01230     }
01231 
01232     doc->updateSideBarItem( m_page );
01233 }
01234 
01235 
01236 KPrPgConfCmd::KPrPgConfCmd( const QString &_name, bool _manualSwitch, bool _infiniteLoop,
01237                       bool _showEndOfPresentationSlide, bool _showPresentationDuration, QPen _pen,
01238                       QValueList<bool> _selectedSlides, const QString & _presentationName,
01239                       bool _oldManualSwitch, bool _oldInfiniteLoop,
01240                       bool _oldShowEndOfPresentationSlide, bool _oldShowPresentationDuration, QPen _oldPen,
01241                       QValueList<bool> _oldSelectedSlides, const QString & _oldPresentationName,
01242                       KPrDocument *_doc )
01243     : KNamedCommand( _name )
01244 {
01245     manualSwitch = _manualSwitch;
01246     infiniteLoop = _infiniteLoop;
01247     showEndOfPresentationSlide = _showEndOfPresentationSlide;
01248     showPresentationDuration = _showPresentationDuration;
01249     pen = _pen;
01250     selectedSlides = _selectedSlides;
01251     oldManualSwitch = _oldManualSwitch;
01252     oldInfiniteLoop = _oldInfiniteLoop;
01253     oldShowEndOfPresentationSlide = _oldShowEndOfPresentationSlide;
01254     oldShowPresentationDuration = _oldShowPresentationDuration;
01255     oldPen = _oldPen;
01256     oldSelectedSlides = _oldSelectedSlides;
01257     oldPresentationName = _oldPresentationName;
01258     presentationName = _presentationName;
01259     doc = _doc;
01260 }
01261 
01262 void KPrPgConfCmd::execute()
01263 {
01264     doc->setManualSwitch( manualSwitch );
01265     doc->setInfiniteLoop( infiniteLoop );
01266     doc->setShowEndOfPresentationSlide ( showEndOfPresentationSlide );
01267     doc->setPresentationDuration( showPresentationDuration );
01268     doc->setPresPen( pen );
01269     doc->setPresentationName( presentationName );
01270     QPtrList<KPrPage> pages = doc->pageList();
01271     unsigned count = selectedSlides.count();
01272     if( count > pages.count() ) count = pages.count();
01273     for( unsigned i = 0; i < selectedSlides.count(); i++ )
01274         pages.at( i )->slideSelected( selectedSlides[ i ] );
01275 }
01276 
01277 void KPrPgConfCmd::unexecute()
01278 {
01279     doc->setManualSwitch( oldManualSwitch );
01280     doc->setInfiniteLoop( oldInfiniteLoop );
01281     doc->setShowEndOfPresentationSlide( oldShowEndOfPresentationSlide );
01282     doc->setPresentationDuration( oldShowPresentationDuration );
01283     doc->setPresPen( oldPen );
01284     doc->setPresentationName( oldPresentationName );
01285 
01286     QPtrList<KPrPage> pages = doc->pageList();
01287     unsigned count = oldSelectedSlides.count();
01288     if( count > pages.count() ) count = pages.count();
01289     for( unsigned i = 0; i < oldSelectedSlides.count(); i++ )
01290         pages.at( i )->slideSelected( oldSelectedSlides[ i ] );
01291 }
01292 
01293 
01294 KPrTransEffectCmd::KPrTransEffectCmd( QValueVector<PageEffectSettings> oldSettings,
01295                                 PageEffectSettings newSettings,
01296                                 KPrPage* page, KPrDocument* doc )
01297 {
01298     m_newSettings = newSettings;
01299     m_oldSettings = oldSettings;
01300     Q_ASSERT( !m_oldSettings.isEmpty() );
01301     m_page = page;
01302     m_doc = doc;
01303 }
01304 
01305 void KPrTransEffectCmd::PageEffectSettings::applyTo( KPrPage *page )
01306 {
01307     page->setPageEffect( pageEffect );
01308     page->setPageEffectSpeed( effectSpeed );
01309     page->setPageSoundEffect( soundEffect );
01310     page->setPageSoundFileName( soundFileName );
01311     // TODO page->setAutoAdvance( autoAdvance );
01312     page->setPageTimer( slideTime );
01313 }
01314 
01315 void KPrTransEffectCmd::execute()
01316 {
01317     if ( m_page )
01318         m_newSettings.applyTo( m_page );
01319     else
01320         for( QPtrListIterator<KPrPage> it( m_doc->getPageList() ); *it; ++it )
01321             m_newSettings.applyTo( it.current() );
01322 }
01323 
01324 void KPrTransEffectCmd::unexecute()
01325 {
01326     if ( m_page )
01327         m_oldSettings[0].applyTo( m_page );
01328     else {
01329         int i = 0;
01330         for( QPtrListIterator<KPrPage> it( m_doc->getPageList() ); *it; ++it, ++i )
01331             m_oldSettings[i].applyTo( it.current() );
01332     }
01333 }
01334 
01335 QString KPrTransEffectCmd::name() const
01336 {
01337     if ( m_page )
01338         return i18n( "Modify Slide Transition" );
01339     else
01340         return i18n( "Modify Slide Transition For All Pages" );
01341 }
01342 
01343 KPrPgLayoutCmd::KPrPgLayoutCmd( const QString &_name, KoPageLayout _layout, KoPageLayout _oldLayout,
01344                           KoUnit::Unit _oldUnit, KoUnit::Unit _unit,KPrDocument *_doc )
01345     : KNamedCommand( _name )
01346 {
01347     m_doc=_doc;
01348     layout = _layout;
01349     oldLayout = _oldLayout;
01350     oldUnit = _oldUnit;
01351     unit = _unit;
01352 }
01353 
01354 void KPrPgLayoutCmd::execute()
01355 {
01356     m_doc->setUnit( unit );
01357     m_doc->setPageLayout( layout );
01358     m_doc->updateHeaderFooterPosition();
01359     m_doc->updateRuler();
01360     m_doc->updateRulerPageLayout();
01361 }
01362 
01363 void KPrPgLayoutCmd::unexecute()
01364 {
01365     m_doc->setUnit( oldUnit );
01366     m_doc->setPageLayout( oldLayout );
01367     m_doc->updateHeaderFooterPosition();
01368     m_doc->updateRuler();
01369     m_doc->updateRulerPageLayout();
01370 }
01371 
01372 
01373 KPrPieValueCmd::KPrPieValueCmd( const QString &name, PieValues newValues,
01374                           QPtrList<KPrObject> &objects, KPrDocument *doc,
01375                           KPrPage *page, int flags )
01376 : KNamedCommand( name )
01377 , m_doc( doc )
01378 , m_page( page )
01379 , m_newValues( newValues )
01380 , m_flags( flags )
01381 {
01382     m_objects.setAutoDelete( false );
01383     m_oldValues.setAutoDelete( false );
01384 
01385     addObjects( objects );
01386 }
01387 
01388 KPrPieValueCmd::KPrPieValueCmd( const QString &_name, QPtrList<PieValues> &_oldValues, PieValues _newValues,
01389                           QPtrList<KPrObject> &_objects, KPrDocument *_doc, KPrPage *_page, int _flags )
01390     : KNamedCommand( _name ), m_oldValues( _oldValues ), m_objects( _objects ), m_flags(_flags)
01391 {
01392     m_objects.setAutoDelete( false );
01393     m_oldValues.setAutoDelete( false );
01394     m_doc = _doc;
01395     m_page = _page;
01396     m_newValues = _newValues;
01397 
01398     QPtrListIterator<KPrObject> it( m_objects );
01399     for ( ; it.current() ; ++it )
01400         it.current()->incCmdRef();
01401 }
01402 
01403 KPrPieValueCmd::~KPrPieValueCmd()
01404 {
01405     QPtrListIterator<KPrObject> it( m_objects );
01406     for ( ; it.current() ; ++it )
01407         it.current()->decCmdRef();
01408     m_oldValues.setAutoDelete( true );
01409     m_oldValues.clear();
01410 }
01411 
01412 void KPrPieValueCmd::addObjects( const QPtrList<KPrObject> &objects )
01413 {
01414     QPtrListIterator<KPrObject> it( objects );
01415     for ( ; it.current(); ++it )
01416     {
01417         if ( it.current()->getType() == OT_GROUP )
01418         {
01419             KPrGroupObject * obj = dynamic_cast<KPrGroupObject*>( it.current() );
01420             if ( obj )
01421             {
01422                 addObjects( obj->objectList() );
01423             }
01424         }
01425         else
01426         {
01427             KPrPieObject *obj = dynamic_cast<KPrPieObject*>( it.current() );
01428             if( obj )
01429             {
01430                 m_objects.append( obj );
01431                 obj->incCmdRef();
01432 
01433                 PieValues * pieValues = new PieValues;
01434                 pieValues->pieType = obj->getPieType();
01435                 pieValues->pieAngle = obj->getPieAngle();
01436                 pieValues->pieLength = obj->getPieLength();
01437                 m_oldValues.append( pieValues );
01438             }
01439         }
01440     }
01441 }
01442 
01443 void KPrPieValueCmd::execute()
01444 {
01445     QPtrListIterator<KPrObject> it( m_objects );
01446     for ( ; it.current() ; ++it )
01447     {
01448         KPrPieObject* obj=dynamic_cast<KPrPieObject*>( it.current() );
01449         if(obj)
01450         {
01451             if (m_flags & Type)
01452                 obj->setPieType( m_newValues.pieType );
01453             if (m_flags & Angle)
01454                 obj->setPieAngle( m_newValues.pieAngle );
01455             if (m_flags & Length)
01456                 obj->setPieLength( m_newValues.pieLength );
01457         }
01458     }
01459     m_doc->repaint( false );
01460 
01461     m_doc->updateSideBarItem( m_page );
01462 }
01463 
01464 void KPrPieValueCmd::unexecute()
01465 {
01466     for ( unsigned int i = 0; i < m_objects.count(); i++ )
01467     {
01468         KPrPieObject* obj=dynamic_cast<KPrPieObject*>( m_objects.at( i ) );
01469         if(obj)
01470         {
01471             obj->setPieType( m_oldValues.at( i )->pieType );
01472             obj->setPieAngle( m_oldValues.at( i )->pieAngle );
01473             obj->setPieLength( m_oldValues.at( i )->pieLength );
01474         }
01475     }
01476     m_doc->repaint( false );
01477 
01478     m_doc->updateSideBarItem( m_page );
01479 }
01480 
01481 
01482 KPrPolygonSettingCmd::KPrPolygonSettingCmd( const QString &name, PolygonSettings newSettings,
01483                                             QPtrList<KPrObject> &objects, KPrDocument *doc,
01484                                             KPrPage *page, int flags )
01485 : KNamedCommand( name )
01486 , m_doc( doc )
01487 , m_page( page )
01488 , m_newSettings( newSettings )
01489 , m_flags( flags )
01490 {
01491     m_objects.setAutoDelete( false );
01492     m_oldSettings.setAutoDelete( false );
01493 
01494     addObjects( objects );
01495 }
01496 
01497 
01498 KPrPolygonSettingCmd::~KPrPolygonSettingCmd()
01499 {
01500     QPtrListIterator<KPrObject> it( m_objects );
01501     for ( ; it.current() ; ++it )
01502         it.current()->decCmdRef();
01503     m_oldSettings.setAutoDelete( true );
01504     m_oldSettings.clear();
01505 }
01506 
01507 void KPrPolygonSettingCmd::addObjects( const QPtrList<KPrObject> &objects )
01508 {
01509     QPtrListIterator<KPrObject> it( objects );
01510     for ( ; it.current(); ++it )
01511     {
01512         if ( it.current()->getType() == OT_GROUP )
01513         {
01514             KPrGroupObject * obj = dynamic_cast<KPrGroupObject*>( it.current() );
01515             if ( obj )
01516             {
01517                 addObjects( obj->objectList() );
01518             }
01519         }
01520         else
01521         {
01522             KPrPolygonObject *obj = dynamic_cast<KPrPolygonObject*>( it.current() );
01523             if( obj )
01524             {
01525                 m_objects.append( obj );
01526                 obj->incCmdRef();
01527 
01528                 PolygonSettings * polygonSettings = new PolygonSettings;
01529 
01530                 polygonSettings->checkConcavePolygon = obj->getCheckConcavePolygon();
01531                 polygonSettings->cornersValue = obj->getCornersValue();
01532                 polygonSettings->sharpnessValue = obj->getSharpnessValue();
01533 
01534                 m_oldSettings.append( polygonSettings );
01535             }
01536         }
01537     }
01538 }
01539 
01540 void KPrPolygonSettingCmd::execute()
01541 {
01542     QPtrListIterator<KPrObject> it( m_objects );
01543     for ( ; it.current() ; ++it )
01544     {
01545         KPrPolygonObject * obj=dynamic_cast<KPrPolygonObject*>( it.current() );
01546         if(obj)
01547         {
01548             if (m_flags & ConcaveConvex)
01549                 obj->setCheckConcavePolygon(m_newSettings.checkConcavePolygon);
01550             if (m_flags & Corners)
01551                 obj->setCornersValue(m_newSettings.cornersValue);
01552             if (m_flags & Sharpness)
01553                 obj->setSharpnessValue(m_newSettings.sharpnessValue );
01554         }
01555     }
01556     m_doc->repaint( false );
01557 
01558     m_doc->updateSideBarItem( m_page );
01559 }
01560 
01561 void KPrPolygonSettingCmd::unexecute()
01562 {
01563     for ( unsigned int i = 0; i < m_objects.count(); ++i )
01564     {
01565         KPrPolygonObject * obj=dynamic_cast<KPrPolygonObject*>( m_objects.at(i) );
01566         if(obj)
01567         {
01568             obj->setCheckConcavePolygon(m_oldSettings.at( i )->checkConcavePolygon);
01569             obj->setCornersValue(m_oldSettings.at( i )->cornersValue);
01570             obj->setSharpnessValue(m_oldSettings.at( i )->sharpnessValue);
01571         }
01572     }
01573     m_doc->repaint( false );
01574 
01575     m_doc->updateSideBarItem( m_page );
01576 }
01577 
01578 
01579 KPrPictureSettingCmd::KPrPictureSettingCmd( const QString &name, PictureSettings newSettings,
01580                                       QPtrList<KPrObject> &objects, KPrDocument *doc,
01581                                       KPrPage *page, int flags )
01582 : KNamedCommand( name )
01583 , m_doc( doc )
01584 , m_newSettings( newSettings )
01585 , m_page( page )
01586 , m_flags( flags )
01587 {
01588     m_objects.setAutoDelete( false );
01589     m_oldValues.setAutoDelete( false );
01590 
01591     addObjects( objects );
01592 }
01593 
01594 KPrPictureSettingCmd::KPrPictureSettingCmd( const QString &_name, QPtrList<PictureSettings> &_oldSettings,
01595                                       PictureSettings _newSettings, QPtrList<KPrObject> &_objects,
01596                                       KPrDocument *_doc, int flags )
01597     : KNamedCommand( _name ), m_oldValues( _oldSettings ), m_objects( _objects ), m_flags( flags )
01598 {
01599     m_objects.setAutoDelete( false );
01600     m_oldValues.setAutoDelete( false );
01601     m_doc = _doc;
01602     m_newSettings = _newSettings;
01603 
01604     m_page = m_doc->findPage( m_objects );
01605 
01606     QPtrListIterator<KPrObject> it( m_objects );
01607     for ( ; it.current() ; ++it )
01608         it.current()->incCmdRef();
01609 }
01610 
01611 KPrPictureSettingCmd::~KPrPictureSettingCmd()
01612 {
01613     QPtrListIterator<KPrObject> it( m_objects );
01614     for ( ; it.current() ; ++it )
01615         it.current()->decCmdRef();
01616     m_oldValues.setAutoDelete( true );
01617     m_oldValues.clear();
01618 }
01619 
01620 void KPrPictureSettingCmd::addObjects( const QPtrList<KPrObject> &objects )
01621 {
01622     QPtrListIterator<KPrObject> it( objects );
01623     for ( ; it.current(); ++it )
01624     {
01625         if ( it.current()->getType() == OT_GROUP )
01626         {
01627             KPrGroupObject * obj = dynamic_cast<KPrGroupObject*>( it.current() );
01628             if ( obj )
01629             {
01630                 addObjects( obj->objectList() );
01631             }
01632         }
01633         else
01634         {
01635             KPrPixmapObject *obj = dynamic_cast<KPrPixmapObject*>( it.current() );
01636             if( obj )
01637             {
01638                 m_objects.append( obj );
01639                 obj->incCmdRef();
01640 
01641                 PictureSettings * pictureSettings = new PictureSettings;
01642 
01643                 pictureSettings->mirrorType = obj->getPictureMirrorType();
01644                 pictureSettings->depth = obj->getPictureDepth();
01645                 pictureSettings->swapRGB = obj->getPictureSwapRGB();
01646                 pictureSettings->grayscal = obj->getPictureGrayscal();
01647                 pictureSettings->bright = obj->getPictureBright();
01648 
01649                 m_oldValues.append( pictureSettings );
01650             }
01651         }
01652     }
01653 }
01654 
01655 void KPrPictureSettingCmd::execute()
01656 {
01657     QPtrListIterator<KPrObject> it( m_objects );
01658     for ( ; it.current() ; ++it ) {
01659         KPrPixmapObject * obj = dynamic_cast<KPrPixmapObject*>( it.current() );
01660         if ( obj ) {
01661             if ( m_flags & MirrorType )
01662                 obj->setPictureMirrorType( m_newSettings.mirrorType );
01663             if ( m_flags & Depth )
01664                 obj->setPictureDepth( m_newSettings.depth );
01665             if ( m_flags & SwapRGB )
01666                 obj->setPictureSwapRGB( m_newSettings.swapRGB );
01667             if ( m_flags & Grayscal )
01668                 obj->setPictureGrayscal( m_newSettings.grayscal );
01669             if ( m_flags & Bright )
01670                 obj->setPictureBright( m_newSettings.bright );
01671         }
01672     }
01673     m_doc->repaint( false );
01674 
01675     m_doc->updateSideBarItem( m_page );
01676 }
01677 
01678 void KPrPictureSettingCmd::unexecute()
01679 {
01680     for ( unsigned int i = 0; i < m_objects.count(); ++i ) {
01681         KPrPixmapObject * obj = dynamic_cast<KPrPixmapObject*>( m_objects.at(i) );
01682         if ( obj ) {
01683             PictureSettings *pictureSettings = m_oldValues.at( i );
01684             obj->setPictureMirrorType( pictureSettings->mirrorType );
01685             obj->setPictureDepth( pictureSettings->depth );
01686             obj->setPictureSwapRGB( pictureSettings->swapRGB );
01687             obj->setPictureGrayscal( pictureSettings->grayscal );
01688             obj->setPictureBright( pictureSettings->bright );
01689         }
01690     }
01691     m_doc->repaint( false );
01692 
01693     m_doc->updateSideBarItem( m_page );
01694 }
01695 
01696 
01697 KPrRectValueCmd::KPrRectValueCmd( const QString &_name, QPtrList<RectValues> &_oldValues, RectValues _newValues,
01698                             QPtrList<KPrObject> &_objects, KPrDocument *_doc, KPrPage *_page, int _flags )
01699     : KNamedCommand( _name ), m_oldValues( _oldValues ), m_objects( _objects ), m_flags(_flags)
01700 {
01701     m_objects.setAutoDelete( false );
01702     m_oldValues.setAutoDelete( false );
01703     m_doc = _doc;
01704     m_page = _page;
01705     m_newValues = _newValues;
01706 
01707     QPtrListIterator<KPrObject> it( m_objects );
01708     for ( ; it.current() ; ++it )
01709         it.current()->incCmdRef();
01710 }
01711 
01712 
01713 KPrRectValueCmd::KPrRectValueCmd( const QString &name, QPtrList<KPrObject> &objects, RectValues newValues,
01714                             KPrDocument *doc, KPrPage *page, int flags )
01715 : KNamedCommand( name )
01716 , m_doc( doc )
01717 , m_page( page )
01718 , m_newValues( newValues )
01719 , m_flags( flags )
01720 {
01721     m_objects.setAutoDelete( false );
01722     m_oldValues.setAutoDelete( false );
01723 
01724     addObjects( objects );
01725 }
01726 
01727 
01728 KPrRectValueCmd::~KPrRectValueCmd()
01729 {
01730     QPtrListIterator<KPrObject> it( m_objects );
01731     for ( ; it.current() ; ++it )
01732         it.current()->decCmdRef();
01733 
01734     m_oldValues.setAutoDelete( true );
01735     m_oldValues.clear();
01736 }
01737 
01738 
01739 void KPrRectValueCmd::addObjects( const QPtrList<KPrObject> &objects )
01740 {
01741     QPtrListIterator<KPrObject> it( objects );
01742     for ( ; it.current(); ++it )
01743     {
01744         if ( it.current()->getType() == OT_GROUP )
01745         {
01746             KPrGroupObject * obj = dynamic_cast<KPrGroupObject*>( it.current() );
01747             if ( obj )
01748             {
01749                 addObjects( obj->objectList() );
01750             }
01751         }
01752         else
01753         {
01754             KPrRectObject *obj = dynamic_cast<KPrRectObject*>( it.current() );
01755             if( obj )
01756             {
01757                 m_objects.append( obj );
01758                 obj->incCmdRef();
01759 
01760                 RectValues * rectValue = new RectValues;
01761 
01762                 int xtmp, ytmp;
01763                 obj->getRnds( xtmp, ytmp );
01764                 rectValue->xRnd = xtmp;
01765                 rectValue->yRnd = ytmp;
01766 
01767                 m_oldValues.append( rectValue );
01768             }
01769         }
01770     }
01771 }
01772 
01773 
01774 void KPrRectValueCmd::execute()
01775 {
01776     QPtrListIterator<KPrObject> it( m_objects );
01777     for ( ; it.current() ; ++it )
01778     {
01779         KPrRectObject *obj = dynamic_cast<KPrRectObject*>( it.current() );
01780         if( obj )
01781         {
01782             int xtmp, ytmp;
01783             obj->getRnds( xtmp, ytmp );
01784 
01785             if ( m_flags & XRnd )
01786             {
01787                 xtmp = m_newValues.xRnd;
01788             }
01789 
01790             if ( m_flags & YRnd )
01791             {
01792                 ytmp = m_newValues.yRnd;
01793             }
01794 
01795             obj->setRnds( xtmp, ytmp );
01796         }
01797     }
01798     m_doc->repaint( false );
01799 
01800     m_doc->updateSideBarItem( m_page );
01801 }
01802 
01803 void KPrRectValueCmd::unexecute()
01804 {
01805     for ( unsigned int i = 0; i < m_objects.count(); i++ )
01806     {
01807         KPrRectObject *obj = dynamic_cast<KPrRectObject*>( m_objects.at( i ) );
01808 
01809         if( obj )
01810             obj->setRnds( m_oldValues.at( i )->xRnd, m_oldValues.at( i )->yRnd );
01811     }
01812     m_doc->repaint( false );
01813 
01814     m_doc->updateSideBarItem( m_page );
01815 }
01816 
01817 
01818 KPrResizeCmd::KPrResizeCmd( const QString &_name, const KoPoint &_m_diff, const KoSize &_r_diff,
01819                       KPrObject *_object, KPrDocument *_doc )
01820     : KNamedCommand( _name ), m_diff( _m_diff ), r_diff( _r_diff )
01821 {
01822     object = _object;
01823     doc = _doc;
01824     m_page = doc->findPage( object );
01825 
01826     object->incCmdRef();
01827 }
01828 
01829 KPrResizeCmd::~KPrResizeCmd()
01830 {
01831     object->decCmdRef();
01832 }
01833 
01834 void KPrResizeCmd::execute()
01835 {
01836     QRect oldRect;
01837 
01838     oldRect = doc->zoomHandler()->zoomRect( object->getRepaintRect() );
01839     object->moveBy( m_diff );
01840     object->resizeBy( r_diff );
01841     if ( object->getType() == OT_TEXT )
01842     {
01843         if(object->isSelected())
01844             doc->updateRuler();
01845         doc->layout( object );
01846     }
01847     if ( object->isSelected())
01848         doc->updateObjectStatusBarItem();
01849     doc->repaint( oldRect );
01850     doc->repaint( object );
01851 
01852     doc->updateSideBarItem( m_page );
01853 }
01854 
01855 void KPrResizeCmd::unexecute()
01856 {
01857     QRect oldRect;
01858 
01859     oldRect = doc->zoomHandler()->zoomRect( object->getRepaintRect() );
01860     object->moveBy( -m_diff.x(), -m_diff.y() );
01861     object->resizeBy( -r_diff.width(), -r_diff.height() );
01862     if ( object->getType() == OT_TEXT )
01863     {
01864         if(object->isSelected())
01865             doc->updateRuler();
01866         doc->layout( object );
01867     }
01868     if ( object->isSelected())
01869         doc->updateObjectStatusBarItem();
01870 
01871     doc->repaint( oldRect );
01872     doc->repaint( object );
01873 
01874     doc->updateSideBarItem( m_page );
01875 }
01876 
01877 
01878 KPrOasisPasteTextCommand::KPrOasisPasteTextCommand( KoTextDocument *d, int parag, int idx,
01879                                 const QByteArray &data )
01880     : KoTextDocCommand( d ), m_parag( parag ), m_idx( idx ), m_data( data ), m_oldParagLayout( 0 )
01881 {
01882 }
01883 
01884 KoTextCursor * KPrOasisPasteTextCommand::execute( KoTextCursor *c )
01885 {
01886     KoTextParag *firstParag = doc->paragAt( m_parag );
01887     if ( !firstParag ) {
01888         qWarning( "can't locate parag at %d, last parag: %d", m_parag, doc->lastParag()->paragId() );
01889         return 0;
01890     }
01891     //kdDebug() << "KWOasisPasteCommand::execute m_parag=" << m_parag << " m_idx=" << m_idx
01892     //          << " firstParag=" << firstParag << " " << firstParag->paragId() << endl;
01893     cursor.setParag( firstParag );
01894     cursor.setIndex( m_idx );
01895     c->setParag( firstParag );
01896     c->setIndex( m_idx );
01897     
01898     QBuffer buffer( m_data );
01899     KoStore * store = KoStore::createStore( &buffer, KoStore::Read ); 
01900 
01901     if ( store->bad() || !store->hasFile( "content.xml" ) )
01902     {
01903         kdError(33001) << "Invalid ZIP store in memory" << endl;
01904         if ( !store->hasFile( "content.xml" ) )
01905             kdError(33001) << "No content.xml file" << endl;
01906         return c;
01907     }
01908     store->disallowNameExpansion();
01909 
01910     KoOasisStore oasisStore( store );
01911     QDomDocument contentDoc;
01912     QString errorMessage;
01913     bool ok = oasisStore.loadAndParse( "content.xml", contentDoc, errorMessage );
01914     if ( !ok ) {
01915         kdError(33001) << "Error parsing content.xml: " << errorMessage << endl;
01916         return c;
01917     }
01918 
01919     KoOasisStyles oasisStyles;
01920     QDomDocument stylesDoc;
01921     (void)oasisStore.loadAndParse( "styles.xml", stylesDoc, errorMessage );
01922     // Load styles from style.xml
01923     oasisStyles.createStyleMap( stylesDoc, true );
01924     // Also load styles from content.xml
01925     oasisStyles.createStyleMap( contentDoc, false );
01926 
01927     QDomElement content = contentDoc.documentElement();
01928 
01929     QDomElement body ( KoDom::namedItemNS( content, KoXmlNS::office, "body" ) );
01930     
01931     // We then want to use whichever element is the child of <office:body>,
01932     // whether that's <office:text> or <office:presentation> or whatever.
01933     QDomElement iter, realBody;
01934     forEachElement( iter, body ) {
01935         realBody = iter;
01936     }
01937     if ( realBody.isNull() ) {
01938         kdError(33001) << "No element found inside office:body!" << endl;
01939         return c;
01940     }
01941 
01942     KPrTextDocument * textdoc = static_cast<KPrTextDocument *>(c->parag()->document());
01943     KPrDocument *doc = textdoc->textObject()->kPresenterDocument();
01944     KoOasisContext context( doc, *doc->getVariableCollection(), oasisStyles, store );
01945 
01946     *c = textdoc->textObject()->textObject()->pasteOasisText( realBody, context, cursor, doc->styleCollection() );
01947     textdoc->textObject()->textObject()->setNeedSpellCheck( true );
01948 
01949     m_lastParag = c->parag()->paragId();
01950     m_lastIndex = c->index();
01951     return c;
01952 }
01953 
01954 KoTextCursor * KPrOasisPasteTextCommand::unexecute( KoTextCursor *c )
01955 {
01956     KoTextParag *firstParag = doc->paragAt( m_parag );
01957     if ( !firstParag ) {
01958         qWarning( "can't locate parag at %d, last parag: %d", m_parag, doc->lastParag()->paragId() );
01959         return 0;
01960     }
01961     cursor.setParag( firstParag );
01962     cursor.setIndex( m_idx );
01963     doc->setSelectionStart( KoTextDocument::Temp, &cursor );
01964 
01965     KoTextParag *lastParag = doc->paragAt( m_lastParag );
01966     if ( !lastParag ) {
01967         qWarning( "can't locate parag at %d, last parag: %d", m_lastParag, doc->lastParag()->paragId() );
01968         return 0;
01969     }
01970     //Q_ASSERT( lastParag->document() );
01971     // Get hold of the document before deleting the parag
01972     //KoTextDocument* textdoc = lastParag->document();
01973 
01974     //kdDebug() << "Undoing paste: deleting from (" << firstParag->paragId() << "," << m_idx << ")"
01975     //          << " to (" << lastParag->paragId() << "," << m_lastIndex << ")" << endl;
01976 
01977     cursor.setParag( lastParag );
01978     cursor.setIndex( m_lastIndex );
01979     doc->setSelectionEnd( KoTextDocument::Temp, &cursor );
01980     doc->removeSelectedText( KoTextDocument::Temp, c /* sets c to the correct position */ );
01981 
01982     if ( m_idx == 0 ) {
01983         Q_ASSERT( m_oldParagLayout );
01984         if ( m_oldParagLayout )
01985             firstParag->setParagLayout( *m_oldParagLayout );
01986     }
01987     return c;
01988 }
01989 
01990 
01991 KPrChangeStartingPageCommand::KPrChangeStartingPageCommand( const QString &name, KPrDocument *_doc,
01992                                                             int _oldStartingPage, int _newStartingPage):
01993     KNamedCommand(name),
01994     m_doc(_doc),
01995     oldStartingPage(_oldStartingPage),
01996     newStartingPage(_newStartingPage)
01997 {
01998 }
01999 
02000 void KPrChangeStartingPageCommand::execute()
02001 {
02002     m_doc->getVariableCollection()->variableSetting()->setStartingPageNumber(newStartingPage);
02003     m_doc->recalcVariables( VT_PGNUM );
02004 }
02005 
02006 void KPrChangeStartingPageCommand::unexecute()
02007 {
02008     m_doc->getVariableCollection()->variableSetting()->setStartingPageNumber(oldStartingPage);
02009     m_doc->recalcVariables( VT_PGNUM );
02010 }
02011 
02012 
02013 KPrChangeVariableSettingsCommand::KPrChangeVariableSettingsCommand( const QString &name, KPrDocument *_doc,
02014                                                                     bool _oldValue, bool _newValue,
02015                                                                     VariableProperties _type):
02016     KNamedCommand(name),
02017     m_doc(_doc),
02018     type(_type),
02019     m_bOldValue(_oldValue),
02020     m_bNewValue(_newValue)
02021 {
02022 }
02023 
02024 void KPrChangeVariableSettingsCommand::changeValue( bool b )
02025 {
02026     switch(type)
02027     {
02028     case VS_DISPLAYLINK:
02029         m_doc->getVariableCollection()->variableSetting()->setDisplayLink(b);
02030         m_doc->recalcVariables( VT_LINK );
02031         break;
02032     case  VS_UNDERLINELINK:
02033         m_doc->getVariableCollection()->variableSetting()->setUnderlineLink(b);
02034         m_doc->recalcVariables( VT_LINK );
02035         break;
02036     case VS_DISPLAYCOMMENT:
02037         m_doc->getVariableCollection()->variableSetting()->setDisplayComment(b);
02038         m_doc->recalcVariables( VT_NOTE );
02039         break;
02040     case VS_DISPLAYFIELDCODE:
02041         m_doc->getVariableCollection()->variableSetting()->setDisplayFieldCode(b);
02042         m_doc->recalcVariables( VT_ALL );
02043         break;
02044     }
02045 }
02046 
02047 void KPrChangeVariableSettingsCommand::execute()
02048 {
02049     changeValue(m_bNewValue);
02050 }
02051 
02052 void KPrChangeVariableSettingsCommand::unexecute()
02053 {
02054     changeValue(m_bOldValue);
02055 }
02056 
02057 KPrDeletePageCmd::KPrDeletePageCmd( const QString &name, int pageNum, KPrDocument *doc )
02058 : KNamedCommand( name )
02059 , m_doc( doc )
02060 , m_pageNum( pageNum )
02061 {
02062     m_page = m_doc->pageList().at( m_pageNum );
02063 }
02064 
02065 KPrDeletePageCmd::~KPrDeletePageCmd()
02066 {
02067 }
02068 
02069 void KPrDeletePageCmd::execute()
02070 {
02071     m_doc->deSelectAllObj();
02072     m_doc->takePage( m_page, QMAX( m_pageNum - 1, 0 ) );
02073     m_doc->updatePresentationButton();
02074 }
02075 
02076 void KPrDeletePageCmd::unexecute()
02077 {
02078     m_doc->deSelectAllObj();
02079     m_doc->insertPage( m_page, QMAX( m_pageNum - 1, 0 ), m_pageNum );
02080     m_doc->updatePresentationButton();
02081 }
02082 
02083 KPrInsertPageCmd::KPrInsertPageCmd( const QString &name, int pageNum, InsertPos pos,
02084                                     KPrPage *page, KPrDocument *doc )
02085 : KNamedCommand(name)
02086 , m_doc( doc )
02087 , m_page( page )
02088 , m_currentPageNum( pageNum )
02089 , m_insertPageNum( 0 )
02090 {
02091     switch( pos )
02092     {
02093         case IP_BEFORE:
02094             m_insertPageNum = m_currentPageNum;
02095             break;
02096         case IP_AFTER:
02097             m_insertPageNum = m_currentPageNum + 1;
02098             break;
02099     }
02100 }
02101 
02102 KPrInsertPageCmd::~KPrInsertPageCmd()
02103 {
02104 }
02105 
02106 void KPrInsertPageCmd::execute()
02107 {
02108     m_doc->deSelectAllObj();
02109     m_doc->insertPage( m_page, m_currentPageNum, m_insertPageNum );
02110     m_page->completeLoading( false, -1 );
02111     m_doc->updatePresentationButton();
02112 }
02113 
02114 void KPrInsertPageCmd::unexecute()
02115 {
02116     m_doc->deSelectAllObj();
02117     m_doc->takePage( m_page, m_currentPageNum );
02118     m_doc->updatePresentationButton();
02119 }
02120 
02121 KPrMovePageCmd::KPrMovePageCmd( const QString &_name,int from, int to, KPrDocument *_doc ) :
02122     KNamedCommand( _name ),
02123     m_doc( _doc ),
02124     m_oldPosition( from ),
02125     m_newPosition( to )
02126 {
02127 }
02128 
02129 KPrMovePageCmd::~KPrMovePageCmd()
02130 {
02131 }
02132 
02133 void KPrMovePageCmd::execute()
02134 {
02135     m_doc->deSelectAllObj();
02136     m_doc->movePageTo( m_oldPosition, m_newPosition );
02137 }
02138 
02139 void KPrMovePageCmd::unexecute()
02140 {
02141     m_doc->deSelectAllObj();
02142     m_doc->movePageTo( m_newPosition, m_oldPosition );
02143 }
02144 
02145 
02146 KPrChangeTitlePageNameCommand::KPrChangeTitlePageNameCommand( const QString &_name,KPrDocument *_doc,
02147                                                               const QString &_oldPageName,
02148                                                               const QString &_newPageName, KPrPage *_page ) :
02149     KNamedCommand(_name),
02150     m_doc(_doc),
02151     oldPageName(_oldPageName),
02152     newPageName(_newPageName),
02153     m_page(_page)
02154 {
02155 }
02156 
02157 void KPrChangeTitlePageNameCommand::execute()
02158 {
02159     m_page->insertManualTitle(newPageName);
02160     m_doc->updateSideBarItem( m_page );
02161     m_doc->recalcVariables( VT_PGNUM );
02162 }
02163 
02164 void KPrChangeTitlePageNameCommand::unexecute()
02165 {
02166     m_page->insertManualTitle(oldPageName);
02167     m_doc->updateSideBarItem( m_page );
02168     m_doc->recalcVariables( VT_PGNUM );
02169 }
02170 
02171 KPrChangeCustomVariableValue::KPrChangeCustomVariableValue( const QString &name, KPrDocument *_doc,
02172                                                             const QString & _oldValue, const QString & _newValue,
02173                                                             KoCustomVariable *var):
02174     KNamedCommand(name),
02175     m_doc(_doc),
02176     newValue(_newValue),
02177     oldValue(_oldValue),
02178     m_var(var)
02179 {
02180 }
02181 
02182 void KPrChangeCustomVariableValue::execute()
02183 {
02184     Q_ASSERT(m_var);
02185     m_var->setValue(newValue);
02186     m_doc->recalcVariables( VT_CUSTOM );
02187 }
02188 
02189 void KPrChangeCustomVariableValue::unexecute()
02190 {
02191     Q_ASSERT(m_var);
02192     m_var->setValue(oldValue);
02193     m_doc->recalcVariables( VT_CUSTOM );
02194 }
02195 
02196 KPrChangeLinkVariable::KPrChangeLinkVariable( const QString &name, KPrDocument *_doc,
02197                                               const QString & _oldHref, const QString & _newHref,
02198                                               const QString & _oldLink,const QString &_newLink,
02199                                               KoLinkVariable *var):
02200     KNamedCommand(name),
02201     m_doc(_doc),
02202     oldHref(_oldHref),
02203     newHref(_newHref),
02204     oldLink(_oldLink),
02205     newLink(_newLink),
02206     m_var(var)
02207 {
02208 }
02209 
02210 
02211 void KPrChangeLinkVariable::execute()
02212 {
02213     m_var->setLink(newLink,newHref);
02214     m_doc->recalcVariables(VT_LINK);
02215 }
02216 
02217 void KPrChangeLinkVariable::unexecute()
02218 {
02219     m_var->setLink(oldLink,oldHref);
02220     m_doc->recalcVariables(VT_LINK);
02221 }
02222 
02223 
02224 KPrNameObjectCommand::KPrNameObjectCommand( const QString &_name, const QString &_objectName,
02225                                             KPrObject *_obj, KPrDocument *_doc ):
02226     KNamedCommand( _name ),
02227     newObjectName( _objectName ),
02228     object( _obj ),
02229     doc( _doc )
02230 {
02231     oldObjectName = object->getObjectName();
02232 
02233     m_page = doc->findPage( object );
02234 }
02235 
02236 KPrNameObjectCommand::~KPrNameObjectCommand()
02237 {
02238 }
02239 
02240 void KPrNameObjectCommand::execute()
02241 {
02242     object->setObjectName( newObjectName );
02243     m_page->unifyObjectName( object );
02244 
02245     doc->updateSideBarItem( m_page );
02246 }
02247 
02248 void KPrNameObjectCommand::unexecute()
02249 {
02250     object->setObjectName( oldObjectName );
02251 
02252     doc->updateSideBarItem( m_page );
02253 }
02254 
02255 KPrDisplayObjectFromMasterPage::KPrDisplayObjectFromMasterPage(const QString &name, KPrDocument *_doc, KPrPage *_page, bool _newValue)
02256     :KNamedCommand(name),
02257      m_doc( _doc ),
02258      m_page(_page),
02259      newValue(_newValue)
02260 {
02261 }
02262 
02263 void KPrDisplayObjectFromMasterPage::execute()
02264 {
02265     m_page->setDisplayObjectFromMasterPage( newValue );
02266     m_doc->updateSideBarItem( m_doc->masterPage() );
02267 }
02268 
02269 void KPrDisplayObjectFromMasterPage::unexecute()
02270 {
02271     m_page->setDisplayObjectFromMasterPage( !newValue );
02272     m_doc->updateSideBarItem( m_doc->masterPage() );
02273 }
02274 
02275 
02276 KPrDisplayBackgroundPage::KPrDisplayBackgroundPage(const QString &name, KPrDocument *_doc, KPrPage *_page, bool _newValue)
02277     :KNamedCommand(name),
02278      m_doc( _doc ),
02279      m_page(_page),
02280      newValue(_newValue)
02281 {
02282 }
02283 
02284 void KPrDisplayBackgroundPage::execute()
02285 {
02286     m_page->setDisplayBackground( newValue );
02287     m_doc->updateSideBarItem( m_doc->masterPage() );
02288 }
02289 
02290 void KPrDisplayBackgroundPage::unexecute()
02291 {
02292     m_page->setDisplayBackground( !newValue );
02293     m_doc->updateSideBarItem( m_doc->masterPage() );
02294 }
02295 
02296 
02297 KPrHideShowHeaderFooter::KPrHideShowHeaderFooter( const QString &name, KPrDocument *_doc, KPrPage *_page,
02298                                                   bool _newValue, KPrTextObject *_textObject):
02299     KNamedCommand(name),
02300     m_doc( _doc ),
02301     m_page(_page),
02302     m_textObject(_textObject),
02303     newValue(_newValue)
02304 {
02305 }
02306 
02307 
02308 void KPrHideShowHeaderFooter::execute()
02309 {
02310     if( m_textObject==m_doc->footer())
02311         m_page->setFooter( newValue );
02312     else if( m_textObject==m_doc->header())
02313         m_page->setHeader( newValue );
02314     else
02315         kdDebug(33001)<<"Error in void KPrHideShowHeaderFooter::execute()\n";
02316 
02317     m_doc->updateSideBarItem( m_doc->masterPage() );
02318 }
02319 
02320 void KPrHideShowHeaderFooter::unexecute()
02321 {
02322     if( m_textObject==m_doc->footer())
02323         m_page->setFooter( !newValue );
02324     else if( m_textObject==m_doc->header())
02325         m_page->setHeader( !newValue );
02326     else
02327         kdDebug(33001)<<"Error in void KPrHideShowHeaderFooter::unexecute()\n";
02328 
02329     m_doc->updateSideBarItem( m_doc->masterPage() );
02330 }
02331 
02332 KPrFlipObjectCommand::KPrFlipObjectCommand( const QString &name, KPrDocument *_doc,
02333                                             bool _horizontal, QPtrList<KPrObject> &_objects ):
02334     KNamedCommand( name ),
02335     m_doc( _doc ),
02336     objects( _objects ),
02337     horizontal( _horizontal )
02338 {
02339     objects.setAutoDelete( false );
02340 
02341     m_page = m_doc->findPage( objects );
02342 
02343     QPtrListIterator<KPrObject> it( objects );
02344     for ( ; it.current() ; ++it )
02345         it.current()->incCmdRef();
02346 }
02347 
02348 KPrFlipObjectCommand::~KPrFlipObjectCommand()
02349 {
02350     QPtrListIterator<KPrObject> it( objects );
02351     for ( ; it.current() ; ++it )
02352         it.current()->decCmdRef();
02353 }
02354 
02355 void KPrFlipObjectCommand::execute()
02356 {
02357     flipObjects();
02358 }
02359 
02360 void KPrFlipObjectCommand::unexecute()
02361 {
02362     flipObjects();
02363 }
02364 
02365 void KPrFlipObjectCommand::flipObjects()
02366 {
02367     QPtrListIterator<KPrObject> it( objects );
02368     for ( ; it.current() ; ++it )
02369     {
02370         it.current()->flip( horizontal );
02371         m_doc->repaint( it.current() );
02372     }
02373 
02374     m_doc->updateSideBarItem( m_page );
02375 }
02376 
02377 
02378 KPrGeometryPropertiesCommand::KPrGeometryPropertiesCommand( const QString &name, QPtrList<KPrObject> &objects,
02379                                                             bool newValue, KgpType type,KPrDocument *_doc )
02380 : KNamedCommand( name )
02381 , m_objects( objects )
02382 , m_newValue( newValue )
02383 , m_type( type )
02384     , m_doc( _doc )
02385 {
02386     QPtrListIterator<KPrObject> it( m_objects );
02387     for ( ; it.current() ; ++it )
02388     {
02389         it.current()->incCmdRef();
02390         if ( m_type == ProtectSize )
02391             m_oldValue.append( it.current()->isProtect() );
02392         else if ( m_type == KeepRatio)
02393             m_oldValue.append( it.current()->isKeepRatio() );
02394     }
02395 }
02396 
02397 KPrGeometryPropertiesCommand::KPrGeometryPropertiesCommand( const QString &name, QValueList<bool> &lst,
02398                                                             QPtrList<KPrObject> &objects, bool newValue,
02399                                                             KgpType type, KPrDocument *_doc)
02400 : KNamedCommand( name )
02401 , m_oldValue( lst )
02402 , m_objects( objects )
02403 , m_newValue( newValue )
02404 , m_type( type )
02405 , m_doc ( _doc )
02406 {
02407     QPtrListIterator<KPrObject> it( m_objects );
02408     for ( ; it.current() ; ++it )
02409         it.current()->incCmdRef();
02410 }
02411 
02412 KPrGeometryPropertiesCommand::~KPrGeometryPropertiesCommand()
02413 {
02414     QPtrListIterator<KPrObject> it( m_objects );
02415     for ( ; it.current() ; ++it )
02416         it.current()->decCmdRef();
02417 }
02418 
02419 void KPrGeometryPropertiesCommand::execute()
02420 {
02421     QPtrListIterator<KPrObject> it( m_objects );
02422     for ( ; it.current() ; ++it )
02423     {
02424         if ( m_type == ProtectSize )
02425         {
02426             it.current()->setProtect( m_newValue );
02427             if ( it.current()->isSelected() )
02428                 m_doc->repaint( it.current() );
02429         }
02430         else if ( m_type == KeepRatio)
02431             it.current()->setKeepRatio( m_newValue );
02432     }
02433 }
02434 
02435 void KPrGeometryPropertiesCommand::unexecute()
02436 {
02437     KPrObject *obj = 0;
02438     for ( unsigned int i = 0; i < m_objects.count(); ++i ) {
02439         obj = m_objects.at( i );
02440         if ( m_type == ProtectSize )
02441         {
02442             obj->setProtect( *m_oldValue.at(i) );
02443             if ( obj->isSelected() )
02444                 m_doc->repaint( obj );
02445         }
02446         else if ( m_type == KeepRatio)
02447             obj->setKeepRatio( *m_oldValue.at(i) );
02448     }
02449 }
02450 
02451 KPrProtectContentCommand::KPrProtectContentCommand( const QString &name, QPtrList<KPrObject> &objects,
02452                                                     bool protectContent, KPrDocument *doc )
02453 : KNamedCommand( name )
02454 , m_protectContent( protectContent )
02455 , m_doc( doc )
02456 {
02457     m_objects.setAutoDelete( false );
02458 
02459     addObjects( objects );
02460 }
02461 
02462 KPrProtectContentCommand::KPrProtectContentCommand( const QString &name, bool protectContent,
02463                                                     KPrTextObject *obj, KPrDocument *doc )
02464 : KNamedCommand( name )
02465 , m_protectContent( protectContent )
02466 , m_doc( doc )
02467 {
02468     obj->incCmdRef();
02469     m_objects.append( obj );
02470     m_oldValues.append( obj->isProtectContent() );
02471 }
02472 
02473 KPrProtectContentCommand::~KPrProtectContentCommand()
02474 {
02475     QPtrListIterator<KPrTextObject> it( m_objects );
02476     for ( ; it.current() ; ++it )
02477         it.current()->decCmdRef();
02478 }
02479 
02480 void KPrProtectContentCommand::addObjects( const QPtrList<KPrObject> &objects )
02481 {
02482     QPtrListIterator<KPrObject> it( objects );
02483     for ( ; it.current(); ++it )
02484     {
02485         if ( it.current()->getType() == OT_GROUP )
02486         {
02487             KPrGroupObject * obj = dynamic_cast<KPrGroupObject*>( it.current() );
02488             if ( obj )
02489             {
02490                 addObjects( obj->objectList() );
02491             }
02492         }
02493         else
02494         {
02495             KPrTextObject *obj = dynamic_cast<KPrTextObject*>( it.current() );
02496             if( obj )
02497             {
02498                 m_objects.append( obj );
02499                 obj->incCmdRef();
02500 
02501                 m_oldValues.append( obj->isProtectContent() );
02502             }
02503         }
02504     }
02505 }
02506 
02507 void KPrProtectContentCommand::execute()
02508 {
02509     QPtrListIterator<KPrTextObject> it( m_objects );
02510     for ( ; it.current() ; ++it )
02511     {
02512         it.current()->setProtectContent( m_protectContent );
02513     }
02514     m_doc->updateObjectSelected();
02515     m_doc->updateRulerInProtectContentMode();
02516 
02517 }
02518 
02519 void KPrProtectContentCommand::unexecute()
02520 {
02521     for ( unsigned int i = 0; i < m_objects.count(); i++ )
02522     {
02523         m_objects.at( i )->setProtectContent( m_oldValues[i] );
02524     }
02525     m_doc->updateObjectSelected();
02526     m_doc->updateRulerInProtectContentMode();
02527 }
02528 
02529 KPrCloseObjectCommand::KPrCloseObjectCommand( const QString &name, QPtrList<KPrObject> objects, KPrDocument *doc )
02530 : KNamedCommand( name )
02531 , m_doc( doc )
02532 , m_page( doc->findPage( objects.at( 0 ) ) )
02533 {
02534     QPtrListIterator<KPrObject> it( objects );
02535     for ( ; it.current(); ++it )
02536     {
02537         KPrPointObject * pointObject = dynamic_cast<KPrPointObject *>( *it );
02538         if ( pointObject )
02539         {
02540             m_openObjects.append( *it );
02541             ( *it )->incCmdRef();
02542             KPrClosedLineObject * closedObject = new KPrClosedLineObject( *pointObject );
02543             closedObject->incCmdRef();
02544             m_closedObjects.append( closedObject );
02545         }
02546     }
02547 }
02548 
02549 KPrCloseObjectCommand::~KPrCloseObjectCommand()
02550 {
02551     QPtrListIterator<KPrObject> it( m_openObjects );
02552     for ( ; it.current() ; ++it )
02553         it.current()->decCmdRef();
02554     QPtrListIterator<KPrObject> it2( m_closedObjects );
02555     for ( ; it2.current() ; ++it2 )
02556         it2.current()->decCmdRef();
02557 }
02558 
02559 void KPrCloseObjectCommand::execute()
02560 {
02561     QPtrListIterator<KPrObject> openIt( m_openObjects );
02562     QPtrListIterator<KPrObject> closeIt( m_closedObjects );
02563     for ( ; openIt.current() ; ++openIt, ++closeIt )
02564     {
02565         m_page->replaceObject( *openIt, *closeIt );
02566         bool selected = ( *openIt )->isSelected();
02567         ( *openIt )->removeFromObjList();
02568         ( *closeIt )->addToObjList();
02569         ( *openIt )->setSelected( false );
02570         ( *closeIt )->setSelected( selected );
02571         m_doc->repaint( *closeIt );
02572     }
02573     m_doc->updateSideBarItem( m_page );
02574 }
02575 
02576 void KPrCloseObjectCommand::unexecute()
02577 {
02578     QPtrListIterator<KPrObject> openIt( m_openObjects );
02579     QPtrListIterator<KPrObject> closeIt( m_closedObjects );
02580     for ( ; openIt.current() ; ++openIt, ++closeIt )
02581     {
02582         m_page->replaceObject( *closeIt, *openIt );
02583         bool selected = ( *closeIt )->isSelected();
02584         ( *closeIt )->removeFromObjList();
02585         ( *openIt )->addToObjList();
02586         ( *closeIt )->setSelected( false );
02587         ( *openIt )->setSelected( selected );
02588         m_doc->repaint( *openIt );
02589     }
02590     m_doc->updateSideBarItem( m_page );
02591 }
02592 
02593 MarginsStruct::MarginsStruct( KPrTextObject *obj )
02594 {
02595     topMargin = obj->bTop();
02596     bottomMargin= obj->bBottom();
02597     leftMargin = obj->bLeft();
02598     rightMargin= obj->bRight();
02599 }
02600 
02601 MarginsStruct::MarginsStruct( double _left, double _top, double _right, double _bottom ):
02602     topMargin(_top),
02603     bottomMargin(_bottom),
02604     leftMargin(_left),
02605     rightMargin(_right)
02606 {
02607 }
02608 
02609 
02610 KPrChangeMarginCommand::KPrChangeMarginCommand( const QString &name, QPtrList<KPrObject> &objects,
02611                                                 MarginsStruct newMargins, KPrDocument *doc,
02612                                                 KPrPage *page )
02613 : KNamedCommand( name )
02614 , m_newMargins( newMargins )
02615 , m_page( page )
02616 , m_doc( doc )
02617 {
02618     m_objects.setAutoDelete( false );
02619     m_oldMargins.setAutoDelete( false );
02620 
02621     addObjects( objects );
02622 }
02623 
02624 
02625 KPrChangeMarginCommand::~KPrChangeMarginCommand()
02626 {
02627     QPtrListIterator<KPrTextObject> it( m_objects );
02628     for ( ; it.current() ; ++it )
02629         it.current()->decCmdRef();
02630     m_oldMargins.setAutoDelete( true );
02631     m_oldMargins.clear();
02632 }
02633 
02634 
02635 void KPrChangeMarginCommand::addObjects( const QPtrList<KPrObject> &objects )
02636 {
02637     QPtrListIterator<KPrObject> it( objects );
02638     for ( ; it.current(); ++it )
02639     {
02640         if ( it.current()->getType() == OT_GROUP )
02641         {
02642             KPrGroupObject * obj = dynamic_cast<KPrGroupObject*>( it.current() );
02643             if ( obj )
02644             {
02645                 addObjects( obj->objectList() );
02646             }
02647         }
02648         else
02649         {
02650             KPrTextObject *obj = dynamic_cast<KPrTextObject*>( it.current() );
02651             if( obj )
02652             {
02653                 m_objects.append( obj );
02654                 obj->incCmdRef();
02655 
02656                 m_oldMargins.append( new MarginsStruct( obj ) );
02657             }
02658         }
02659     }
02660 }
02661 
02662 
02663 void KPrChangeMarginCommand::execute()
02664 {
02665     QPtrListIterator<KPrTextObject> it( m_objects );
02666     for ( ; it.current() ; ++it )
02667     {
02668         it.current()->setTextMargins( m_newMargins.leftMargin, m_newMargins.topMargin,
02669                                       m_newMargins.rightMargin, m_newMargins.bottomMargin);
02670         it.current()->resizeTextDocument();
02671         it.current()->layout();
02672     }
02673     m_doc->repaint( false );
02674 
02675     m_doc->updateSideBarItem( m_page );
02676 }
02677 
02678 void KPrChangeMarginCommand::unexecute()
02679 {
02680     for ( unsigned int i = 0; i < m_objects.count(); i++ )
02681     {
02682         KPrTextObject *object = m_objects.at( i );
02683         MarginsStruct *marginsStruct = m_oldMargins.at( i );
02684         object->setTextMargins( marginsStruct->leftMargin, marginsStruct->topMargin,
02685                                 marginsStruct->rightMargin, marginsStruct->bottomMargin);
02686         object->resizeTextDocument();
02687         object->layout();
02688     }
02689     m_doc->repaint( false );
02690 
02691     m_doc->updateSideBarItem( m_page );
02692 }
02693 
02694 
02695 KPrChangeVerticalAlignmentCommand::KPrChangeVerticalAlignmentCommand( const QString &name, KPrTextObject *_obj,
02696                                                                       VerticalAlignmentType _oldAlign,
02697                                                                       VerticalAlignmentType _newAlign,
02698                                                                       KPrDocument *_doc) :
02699     KNamedCommand(name),
02700     m_obj( _obj ),
02701     m_oldAlign(_oldAlign),
02702     m_newAlign(_newAlign),
02703     m_doc( _doc )
02704 {
02705     m_page = m_doc->findPage( _obj );
02706 }
02707 
02708 void KPrChangeVerticalAlignmentCommand::execute()
02709 {
02710     m_obj->setVerticalAligment( m_newAlign );
02711     m_obj->kPresenterDocument()->layout(m_obj);
02712     m_obj->kPresenterDocument()->repaint(m_obj);
02713 
02714     m_doc->updateSideBarItem( m_page );
02715 }
02716 
02717 void KPrChangeVerticalAlignmentCommand::unexecute()
02718 {
02719     m_obj->setVerticalAligment( m_oldAlign );
02720     m_obj->kPresenterDocument()->layout(m_obj);
02721     m_obj->kPresenterDocument()->repaint(m_obj);
02722 
02723     m_doc->updateSideBarItem( m_page );
02724 }
02725 
02726 
02727 KPrChangeTabStopValueCommand::KPrChangeTabStopValueCommand( const QString &name, double _oldValue, double _newValue,
02728                                                             KPrDocument *_doc):
02729     KNamedCommand(name),
02730     m_doc( _doc ),
02731     m_oldValue(_oldValue),
02732     m_newValue(_newValue)
02733 {
02734 }
02735 
02736 void KPrChangeTabStopValueCommand::execute()
02737 {
02738     m_doc->setTabStopValue ( m_newValue );
02739 }
02740 
02741 void KPrChangeTabStopValueCommand::unexecute()
02742 {
02743     m_doc->setTabStopValue ( m_oldValue );
02744 }
02745 
02746 KPrImageEffectCmd::KPrImageEffectCmd(const QString &_name, QPtrList<ImageEffectSettings> &_oldSettings,
02747                                ImageEffectSettings _newSettings, QPtrList<KPrObject> &_objects,
02748                                KPrDocument *_doc )
02749     :KNamedCommand( _name ), oldSettings( _oldSettings ), objects( _objects )
02750 {
02751     objects.setAutoDelete( false );
02752     oldSettings.setAutoDelete( false );
02753     doc = _doc;
02754     newSettings = _newSettings;
02755 
02756     m_page = doc->findPage( objects );
02757 
02758     QPtrListIterator<KPrObject> it( objects );
02759     for ( ; it.current() ; ++it )
02760         it.current()->incCmdRef();
02761 }
02762 
02763 KPrImageEffectCmd::~KPrImageEffectCmd()
02764 {
02765     QPtrListIterator<KPrObject> it( objects );
02766     for ( ; it.current() ; ++it )
02767         it.current()->decCmdRef();
02768     oldSettings.setAutoDelete( true );
02769     oldSettings.clear();
02770 }
02771 
02772 void KPrImageEffectCmd::execute()
02773 {
02774     QPtrListIterator<KPrObject> it( objects );
02775     for ( ; it.current() ; ++it ) {
02776         KPrPixmapObject * obj = dynamic_cast<KPrPixmapObject*>( it.current() );
02777         if ( obj ) {
02778             obj->setImageEffect(newSettings.effect);
02779             obj->setIEParams(newSettings.param1, newSettings.param2, newSettings.param3);
02780         }
02781     }
02782     doc->repaint( false );
02783 
02784     doc->updateSideBarItem( m_page );
02785 }
02786 
02787 void KPrImageEffectCmd::unexecute()
02788 {
02789     for ( unsigned int i = 0; i < objects.count(); ++i ) {
02790         KPrPixmapObject * obj = dynamic_cast<KPrPixmapObject*>( objects.at(i) );
02791         if ( obj ) {
02792             obj->setImageEffect(oldSettings.at( i )->effect);
02793             obj->setIEParams(oldSettings.at( i )->param1, oldSettings.at( i )->param2,
02794                              oldSettings.at( i )->param3);
02795         }
02796     }
02797     doc->repaint( false );
02798 
02799     doc->updateSideBarItem( m_page );
02800 }
02801 
02802 KPrChangeVariableNoteText::KPrChangeVariableNoteText( const QString &name, KPrDocument *_doc,
02803                         const QString &_oldValue,const QString &_newValue,
02804                         KoNoteVariable *var):
02805     KNamedCommand(name),
02806     m_doc(_doc),
02807     newValue(_newValue),
02808     oldValue(_oldValue),
02809     m_var(var)
02810 {
02811 }
02812 
02813 KPrChangeVariableNoteText::~KPrChangeVariableNoteText()
02814 {
02815 }
02816 
02817 void KPrChangeVariableNoteText::execute()
02818 {
02819     Q_ASSERT(m_var);
02820     m_var->setNote(newValue);
02821 }
02822 
02823 void KPrChangeVariableNoteText::unexecute()
02824 {
02825     Q_ASSERT(m_var);
02826     m_var->setNote(oldValue);
02827 }
KDE Home | KDE Accessibility Home | Description of Access Keys