kpresenter

KPrPage.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) 2002-2004 Laurent MONTEL <montel@kde.org>
00004    Copyright (C) 2004-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 <kurl.h>
00023 
00024 #include "KPrPage.h"
00025 #include "KPrView.h"
00026 #include "KPrPageIface.h"
00027 
00028 #include "KPrBackground.h"
00029 #include "KPrLineObject.h"
00030 #include "KPrRectObject.h"
00031 #include "KPrEllipseObject.h"
00032 #include "KPrAutoformObject.h"
00033 #include "KPrTextObject.h"
00034 #include "KPrPixmapObject.h"
00035 #include "KPrPieObject.h"
00036 #include "KPrPartObject.h"
00037 #include "KPrGroupObject.h"
00038 #include "KPrCommand.h"
00039 #include "KPrFreehandObject.h"
00040 #include "KPrPolylineObject.h"
00041 #include "KPrBezierCurveObject.h"
00042 #include "KPrPolygonObject.h"
00043 #include "KPrClosedLineObject.h"
00044 #include "KPrUtils.h"
00045 #include <kdebug.h>
00046 #include <KoQueryTrader.h>
00047 #include "KPrDocument.h"
00048 
00049 #include <KoStore.h>
00050 #include <KoStoreDevice.h>
00051 #include <KoTextZoomHandler.h>
00052 #include <KoXmlNS.h>
00053 #include "KoPointArray.h"
00054 #include "KPrTextDocument.h"
00055 #include <KoTextObject.h>
00056 #include <KoTextParag.h>
00057 #include <KoRect.h>
00058 #include <qapplication.h>
00059 #include <KoStyleCollection.h>
00060 #include <KoVariable.h>
00061 #include <KoGenStyles.h>
00062 #include <KoXmlWriter.h>
00063 #include <ktempfile.h>
00064 #include <qbuffer.h>
00065 #include <qregexp.h>
00066 #include <qfile.h>
00067 
00068 struct listAnimation {
00069     KPrObject *obj;
00070     int objIndex;
00071     bool appear;
00072 };
00073 
00074 typedef QMap<int, QPtrList<listAnimation> > lstMap;
00075 
00076 
00077 KPrPage::KPrPage(KPrDocument *_doc, KPrPage *masterPage )
00078     : m_doc( _doc )
00079     , m_masterPage( masterPage )
00080     , m_dcop( 0 )
00081     , m_selectedSlides( true )
00082     , m_bHasHeader( false )
00083     , m_bHasFooter( false )
00084     , m_useMasterBackground( false )
00085     , m_displayObjectFromMasterPage( true )
00086     , m_displayBackground( true )
00087     , m_pageEffect( PEF_NONE )
00088     , m_pageEffectSpeed( ES_MEDIUM )
00089     , m_soundEffect( false )
00090     , m_soundFileName( QString::null )
00091     , m_pageTimer( 1 )
00092 {
00093     kdDebug(33001)<<"create page : KPrPage::KPrPage(KPrDocument *_doc )"<<this<<endl;
00094     m_objectList.setAutoDelete( false );
00095 
00096     m_kpbackground= new KPrBackGround( this );
00097 
00098     //don't create dcopobject by default
00099     //dcopObject();
00100 }
00101 
00102 KPrPage::~KPrPage()
00103 {
00104     kdDebug(33001)<<"Delete page :KPrPage::~KPrPage() :"<<this<<endl;
00105     //delete object list.
00106     m_objectList.setAutoDelete( true );
00107     m_objectList.clear();
00108     delete m_kpbackground;
00109     delete m_dcop;
00110 }
00111 
00112 DCOPObject* KPrPage::dcopObject()
00113 {
00114     if ( !m_dcop ) {
00115         // 0-based. 1-based would be nicer for the dcop user, but well, docs and views are 0-based,
00116     // and the page(int) DCOP call is 0-based.
00117         int pgnum = m_doc->pageList().findRef( this );
00118         m_dcop = new KPrPageIface( this, pgnum );
00119     }
00120 
00121     return m_dcop;
00122 }
00123 
00124 
00125 void KPrPage::saveOasisObject( KoStore *store, KoXmlWriter &xmlWriter, KoSavingContext& context, int & indexObj, int &partIndexObj,  KoXmlWriter* manifestWriter ) const
00126 {
00127     Q_UNUSED( store );
00128     Q_UNUSED( manifestWriter );
00129     KPrObject::KPOasisSaveContext sc( xmlWriter, context, indexObj, partIndexObj, isMasterPage() );
00130 
00131     KTempFile animationTmpFile;
00132     animationTmpFile.setAutoDelete( true );
00133     QFile* tmpFile = animationTmpFile.file();
00134     KoXmlWriter animationTmpWriter( tmpFile );
00135     lstMap listObjectAnimation;
00136     QPtrListIterator<KPrObject> it( m_objectList );
00137     for ( ; it.current() ; ++it )
00138     {
00139         if ( it.current()== m_doc->header() || it.current()== m_doc->footer())
00140             continue;
00141         it.current()->saveOasisObject( sc );
00142 
00143         if ( it.current()->hasAnimation() )
00144         {
00145             if ( it.current()->getEffect() != EF_NONE ||
00146                  it.current()->getAppearStep() != 0 ||
00147                  !it.current()->getAppearSoundEffectFileName().isEmpty() )
00148             {
00149                 kdDebug(33001) << "has animation" << endl;
00150                 listAnimation *lstappear = new listAnimation;
00151                 lstappear->obj = it.current();
00152                 lstappear->objIndex = indexObj;
00153                 lstappear->appear = true;
00154                 //kdDebug()<<" indexObj :"<<indexObj<<endl;
00155                 lstMap::Iterator tmp = listObjectAnimation.find( it.current()->getAppearStep() );
00156                 if ( tmp!= listObjectAnimation.end() )
00157                 {
00158                     //kdDebug()<<" group already exist \n";
00159                     tmp.data().append( lstappear );
00160                 }
00161                 else
00162                 {
00163                     //kdDebug()<<" create new list \n";
00164                     QPtrList<listAnimation> tmp2;
00165                     tmp2.append( lstappear );
00166                     listObjectAnimation.insert( it.current()->getAppearStep(), tmp2 );
00167                 }
00168             }
00169             if ( it.current()->getEffect3() != EF3_NONE ||
00170                  it.current()->getDisappear() ||
00171                  ! it.current()->getDisappearSoundEffectFileName().isEmpty())
00172             {
00173                 listAnimation *lstappear = new listAnimation;
00174                 lstappear->obj = it.current();
00175                 lstappear->objIndex = indexObj;
00176                 lstappear->appear = false;
00177                 //kdDebug()<<" indexObj :"<<indexObj<<endl;
00178                 lstMap::Iterator tmp = listObjectAnimation.find( it.current()->getDisappearStep() );
00179                 if ( tmp!= listObjectAnimation.end() )
00180                 {
00181                     //kdDebug()<<" group already exist \n";
00182                     tmp.data().append( lstappear );
00183                 }
00184                 else
00185                 {
00186                     //kdDebug()<<" create new list \n";
00187                     QPtrList<listAnimation> tmp2;
00188                     tmp2.append( lstappear );
00189                     listObjectAnimation.insert( it.current()->getDisappearStep(), tmp2 );
00190                 }
00191             }
00192 
00193         }
00194         ++indexObj;
00195     }
00196 
00197     if ( !listObjectAnimation.isEmpty() )
00198     {
00199         kdDebug()<<"! listObjectAnimation.isEmpty() :"<<listObjectAnimation.count()<<endl;
00200         animationTmpWriter.startElement( "presentation:animations" );
00201         lstMap::Iterator it = listObjectAnimation.begin();
00202         lstMap::Iterator end = listObjectAnimation.end();
00203         for (; it != end; ++it )
00204         {
00205             if ( it.data().count() == 1 )
00206             {
00207                 kdDebug()<<" add unique element \n";
00208                 if ( it.data().at( 0 )->appear )
00209                     it.data().at( 0 )->obj->saveOasisObjectStyleShowAnimation( animationTmpWriter, it.data().at( 0 )->objIndex );
00210                 else
00211                     it.data().at( 0 )->obj->saveOasisObjectStyleHideAnimation( animationTmpWriter, it.data().at( 0 )->objIndex );
00212             }
00213             else if ( it.data().count() > 1 )
00214             {
00215                 QPtrList<listAnimation> list = it.data();
00216                 animationTmpWriter.startElement( "presentation:animation-group" );
00217                 for ( uint i = 0; i < list.count(); ++i )
00218                 {
00219                     if ( list.at(i) )
00220                     {
00221                         kdDebug()<<" add group element : "<<i<<endl;
00222                         if ( list.at(i)->appear )
00223                             list.at(i)->obj->saveOasisObjectStyleShowAnimation( animationTmpWriter, list.at(i)->objIndex );
00224                         else
00225                             list.at(i)->obj->saveOasisObjectStyleHideAnimation( animationTmpWriter, list.at(i)->objIndex );
00226                     }
00227                 }
00228                 animationTmpWriter.endElement();
00229             }
00230 
00231         }
00232         animationTmpWriter.endElement();//close "presentation:animations"
00233         tmpFile->close();
00234         xmlWriter.addCompleteElement( tmpFile );
00235 
00236     }
00237     else
00238         tmpFile->close();
00239     animationTmpFile.close();
00240 }
00241 
00242 void KPrPage::load( const QDomElement &element )
00243 {
00244     m_kpbackground->load( element );
00245     QDomElement e=element.namedItem("PGEFFECT").toElement();
00246     if(!e.isNull()) {
00247         int tmp=0;
00248         if(e.hasAttribute("value"))
00249             tmp=e.attribute("value").toInt();
00250         setPageEffect(static_cast<PageEffect>(tmp));
00251         tmp = (int)ES_MEDIUM;
00252         if(e.hasAttribute("speed"))
00253             tmp=e.attribute("speed").toInt();
00254         setPageEffectSpeed( static_cast<EffectSpeed>(tmp) );
00255     }
00256     e=element.namedItem("PGTIMER").toElement();
00257     if(!e.isNull()) {
00258         int timer = 1;
00259         if(e.hasAttribute("timer"))
00260             timer=e.attribute("timer").toInt();
00261         setPageTimer(timer);
00262     }
00263     else
00264         setPageTimer(1);
00265     e=element.namedItem("PGSOUNDEFFECT").toElement();
00266     if(!e.isNull()) {
00267         if(e.hasAttribute("soundEffect"))
00268             m_soundEffect=static_cast<bool>(e.attribute("soundEffect").toInt());
00269         else
00270             m_soundEffect=false;
00271 
00272         if(e.hasAttribute("soundFileNmae")) // old typo
00273             m_soundFileName=e.attribute("soundFileNmae");
00274         else
00275             m_soundFileName=e.attribute("soundFileName");
00276     }
00277     else {
00278         m_soundFileName=QString::null;
00279     }
00280 
00281     e=element.namedItem("HEADERFOOTER").toElement();
00282     if(!e.isNull()) {
00283         if(e.hasAttribute("header"))
00284             m_bHasHeader =static_cast<bool>(e.attribute("header").toInt());
00285         else
00286             m_bHasHeader = false;
00287 
00288         if(e.hasAttribute("footer"))
00289             m_bHasFooter =static_cast<bool>(e.attribute("footer").toInt());
00290         else
00291             m_bHasFooter = false;
00292     }
00293 }
00294 
00295 //TODO: implement display/hide background into old file format
00296 void KPrPage::loadOasis(KoOasisContext & context )
00297 {
00298     m_kpbackground->loadOasis( context );
00299 
00300     KoStyleStack& styleStack = context.styleStack();
00301     kdDebug()<<"KPrPage::loadOasis()\n";
00302     styleStack.setTypeProperties( "drawing-page" );
00303 
00304     if ( !isMasterPage() )
00305     {
00306         if ( !styleStack.hasAttributeNS( KoXmlNS::draw, "fill" ) )
00307         {
00308             // if non is set the fill style of the master slide is used: see OD 14.13.2 Drawing Page Style
00309             m_useMasterBackground = true;
00310         }
00311         //FIXME: fix it in old file format
00312         if ( styleStack.hasAttributeNS( KoXmlNS::presentation, "background-objects-visible" ) )
00313         {
00314             const QString str = styleStack.attributeNS( KoXmlNS::presentation, "background-objects-visible" );
00315             m_displayObjectFromMasterPage = ( str == "true" ) ? true : false;
00316         }
00317 
00318         if ( styleStack.hasAttributeNS( KoXmlNS::presentation, "background-visible" ) )
00319         {
00320             const QString str = styleStack.attributeNS( KoXmlNS::presentation, "background-visible" );
00321             m_displayBackground = ( str == "true" ) ? true : false;
00322         }
00323 
00324         if ( styleStack.hasAttributeNS( KoXmlNS::presentation, "visibility" ) )
00325         {
00326             const QString str = styleStack.attributeNS( KoXmlNS::presentation, "visibility" );
00327             if ( str=="hidden" )
00328                 slideSelected( false );
00329             else
00330                 kdDebug()<<" presentation:visibility parameter not implemented :"<<str<<endl;
00331         }
00332 
00333         if ( styleStack.hasAttributeNS( KoXmlNS::presentation, "transition-speed" ) )
00334         {
00335             // this argument is not defined into kpresenter_doc and not into kprpage
00336             // TODO add it into each page.
00337             QString speed = styleStack.attributeNS( KoXmlNS::presentation, "transition-speed" );
00338             if ( speed == "slow" )
00339             {
00340                 m_pageEffectSpeed = ES_SLOW;
00341             }
00342             else if ( speed == "medium" )
00343             {
00344                 m_pageEffectSpeed = ES_MEDIUM;
00345             }
00346             else if ( speed == "fast" )
00347             {
00348                 m_pageEffectSpeed = ES_FAST;
00349             }
00350             else
00351                 kdDebug()<<" transition-speed not defined :"<<speed<<endl;
00352         }
00353         if ( styleStack.hasAttributeNS( KoXmlNS::presentation, "duration" ))
00354         {
00355             m_pageTimer = loadOasisTimer( styleStack.attributeNS( KoXmlNS::presentation, "duration") );
00356         }
00357         if ( styleStack.hasAttributeNS( KoXmlNS::presentation, "transition-type" ) )
00358         {
00359             //Not defined into kpresenter
00360             //it's global for the moment.
00361             kdDebug()<<" presentation:transition-type :"<<styleStack.attributeNS( KoXmlNS::presentation, "transition-type" )<<endl;
00362         }
00363         if ( styleStack.hasAttributeNS( KoXmlNS::presentation, "display-header" ) )
00364         {
00365             QString tmp = styleStack.attributeNS( KoXmlNS::presentation, "display-header" );
00366             setHeader( tmp =="true" ? true : false );
00367         }
00368         if ( styleStack.hasAttributeNS( KoXmlNS::presentation, "display-footer" ) )
00369         {
00370             QString tmp = styleStack.attributeNS( KoXmlNS::presentation, "display-footer" );
00371             setFooter(tmp =="true" ? true : false);
00372         }
00373         //TODO presentation:display-date-time; presentation:display-page-number
00374         if ( styleStack.hasAttributeNS( KoXmlNS::presentation, "transition-style"))
00375         {
00376             //kdDebug()<<" have a presentation:transition-style------------\n";
00377             const QString effect = styleStack.attributeNS( KoXmlNS::presentation, "transition-style");
00378             QString additionalEffect;
00379             if ( styleStack.hasAttributeNS( KoXmlNS::koffice, "additional-transition-style" ) )
00380             {
00381                 additionalEffect = styleStack.attributeNS( KoXmlNS::koffice, "additional-transition-style" );
00382             }
00383             kdDebug() << "Transition name: " << effect << "additional name: " << additionalEffect << endl;
00384             PageEffect pef;
00385             if ( effect=="none" )
00386                 pef=PEF_NONE;
00387             else if (effect=="vertical-stripes" || effect=="vertical-lines") // PEF_BLINDS_VER
00388                 pef=PEF_BLINDS_VER;
00389             else if (effect=="horizontal-stripes" || effect=="horizontal-lines") // PEF_BLINDS_HOR
00390                 pef=PEF_BLINDS_HOR;
00391             else if (effect=="spiralin-left" || effect=="spiralin-right"
00392                     || effect== "spiralout-left" || effect=="spiralout-right") // PEF_SURROUND1
00393                 pef=PEF_SURROUND1;
00394             else if (effect=="fade-from-top") // PEF_COVER_DOWN
00395                 pef=PEF_COVER_DOWN;
00396             else if (effect=="fade-from-bottom") // PEF_COVER_UP
00397                 pef=PEF_COVER_UP;
00398             else if (effect=="fade-from-left") // PEF_COVER_RIGHT
00399                 pef=PEF_COVER_RIGHT;
00400             else if (effect=="fade-from-right") // PEF_COVER_LEFT
00401                 pef=PEF_COVER_LEFT;
00402             else if (effect=="fade-from-lowerleft")
00403             {   // PEF_COVER_RIGHT_UP
00404                 if ( additionalEffect.isEmpty() )
00405                     pef=PEF_COVER_RIGHT_UP;
00406                 else
00407                     pef=PEF_STRIPS_RIGHT_UP;
00408             }
00409             else if (effect=="fade-from-lowerright")
00410             {   // PEF_COVER_LEFT_UP
00411                 if ( additionalEffect.isEmpty() )
00412                     pef=PEF_COVER_LEFT_UP;
00413                 else
00414                     pef=PEF_STRIPS_LEFT_UP;
00415             }
00416             else if (effect=="fade-from-upperleft")
00417             {   // PEF_COVER_RIGHT_DOWN
00418                 if ( additionalEffect.isEmpty() )
00419                     pef=PEF_COVER_RIGHT_DOWN;
00420                 else
00421                     pef=PEF_STRIPS_RIGHT_DOWN;
00422             }
00423             else if (effect=="fade-from-upperright")
00424             {   // PEF_COVER_LEFT_DOWN
00425                 if ( additionalEffect.isEmpty() )
00426                     pef=PEF_COVER_LEFT_DOWN;
00427                 else
00428                     pef=PEF_STRIPS_LEFT_DOWN;
00429             }
00430             else if (effect=="fade-to-center") // PEF_BOX_IN
00431                 pef=PEF_BOX_IN;
00432             else if (effect=="fade-from-center") // PEF_BOX_OUT
00433                 pef=PEF_BOX_OUT;
00434             else if (effect=="open-vertical") // PEF_OPEN_HORZ; really, no kidding ;)
00435                 pef=PEF_OPEN_HORZ;
00436             else if (effect=="open-horizontal") // PEF_OPEN_VERT
00437                 pef=PEF_OPEN_VERT;
00438             else if (effect=="open") // PEF_OPEN_ALL
00439                 pef=PEF_OPEN_ALL;
00440             else if (effect=="close-vertical") // PEF_CLOSE_HORZ
00441                 pef=PEF_CLOSE_HORZ;
00442             else if (effect=="close-horizontal") // PEF_CLOSE_VERT
00443                 pef=PEF_CLOSE_VERT;
00444             else if (effect=="close") // PEF_CLOSE_ALL
00445                 pef=PEF_CLOSE_ALL;
00446             else if (effect=="dissolve") // PEF_DISSOLVE; perfect hit ;)
00447                 pef=PEF_DISSOLVE;
00448             else if (effect=="horizontal-checkerboard") // PEF_CHECKBOARD_ACROSS
00449                 pef=PEF_CHECKBOARD_ACROSS;
00450             else if (effect=="vertical-checkerboard") // PEF_CHECKBOARD_DOWN
00451                 pef=PEF_CHECKBOARD_DOWN;
00452             else if (effect=="uncover-to-right" || effect=="roll-from-left") // PEF_UNCOVER_RIGHT
00453                 pef=PEF_UNCOVER_RIGHT;
00454             else if (effect=="uncover-to-left" || effect=="roll-from-right") // PEF_UNCOVER_LEFT
00455                 pef=PEF_UNCOVER_LEFT;
00456             else if (effect=="uncover-to-top" || effect=="roll-from-bottom") // PEF_UNCOVER_UP
00457                 pef=PEF_UNCOVER_UP;
00458             else if (effect=="uncover-to-bottom" || effect=="roll-from-top") // PEF_UNCOVER_DOWN
00459                 pef=PEF_UNCOVER_DOWN;
00460             else if (effect=="uncover-to-upperleft") // PEF_UNCOVER_LEFT_UP
00461                 pef=PEF_UNCOVER_LEFT_UP;
00462             else if (effect=="uncover-to-upperright") // PEF_UNCOVER_RIGHT_UP
00463                 pef=PEF_UNCOVER_RIGHT_UP;
00464             else if (effect=="uncover-to-lowerleft") // PEF_UNCOVER_LEFT_DOWN
00465                 pef=PEF_UNCOVER_LEFT_DOWN;
00466             else if (effect=="uncover-to-lowerright") // PEF_UNCOVER_RIGHT_DOWN
00467                 pef=PEF_UNCOVER_RIGHT_DOWN;
00468             else if (effect=="interlocking-horizontal-left")
00469                 pef=PEF_INTERLOCKING_HORZ_1;
00470             else if (effect=="interlocking-horizontal-right")
00471                 pef=PEF_INTERLOCKING_HORZ_2;
00472             else if (effect=="interlocking-vertical-top")
00473                 pef=PEF_INTERLOCKING_VERT_1;
00474             else if (effect=="interlocking-vertical-bottom")
00475                 pef=PEF_INTERLOCKING_VERT_2;
00476             else if ( effect=="melt" )
00477                 pef=PEF_MELTING;
00478             else if ( effect=="fly-away" )
00479                 pef=PEF_FLY1;
00480             else if ( effect=="random" )
00481                 pef=PEF_RANDOM;
00482             else         // we choose a random transition instead of the unsupported ones ;)
00483                 pef=PEF_RANDOM;
00484             setPageEffect( pef );
00485         }
00486         if ( styleStack.hasChildNodeNS( KoXmlNS::presentation, "sound"))
00487         {
00488             //kdDebug()<<" presentation:sound !!!!!!!!!!!!!!!!!!!!!\n";
00489             QDomElement sound = styleStack.childNodeNS( KoXmlNS::presentation, "sound");
00490             m_soundEffect = true;
00491             m_soundFileName = sound.attributeNS( KoXmlNS::xlink, "href", QString::null );
00492         }
00493     }
00494 }
00495 
00496 QDomElement KPrPage::save( QDomDocument &doc )
00497 {
00498     QDomElement page = m_kpbackground->save( doc );
00499     QDomElement element;
00500 
00501     if ( m_pageEffect != PEF_NONE) {
00502         element = doc.createElement("PGEFFECT");
00503         element.setAttribute("value", static_cast<int>( m_pageEffect ));
00504         element.setAttribute("speed", static_cast<int>( m_pageEffectSpeed ));
00505         page.appendChild(element);
00506     }
00507 
00508     if ( m_pageTimer != 1 ) {
00509         element = doc.createElement( "PGTIMER" );
00510         element.setAttribute( "timer", m_pageTimer );
00511         page.appendChild( element );
00512     }
00513 
00514     if ( m_soundEffect || !m_soundFileName.isEmpty() ) {
00515         element = doc.createElement( "PGSOUNDEFFECT" );
00516         element.setAttribute( "soundEffect", static_cast<int>(m_soundEffect) );
00517         element.setAttribute( "soundFileName", m_soundFileName );
00518         page.appendChild( element );
00519     }
00520     element = doc.createElement( "HEADERFOOTER" );
00521     element.setAttribute( "header", static_cast<int>(m_bHasHeader ) );
00522     element.setAttribute( "footer", static_cast<int>(m_bHasFooter ) );
00523     page.appendChild( element );
00524     return page;
00525 }
00526 
00527 QString KPrPage::oasisNamePage( int posPage ) const
00528 {
00529     return  ( m_manualTitle.isEmpty() ?  QString( "page%1" ).arg( posPage ) : m_manualTitle );
00530 }
00531 
00532 bool KPrPage::saveOasisPage( KoStore *store, KoXmlWriter &xmlWriter, int posPage, KoSavingContext& context,
00533                              int & indexObj, int &partIndexObj, KoXmlWriter* manifestWriter, QMap<QString, int> &pageNames ) const
00534 {
00535     if ( isMasterPage() )
00536     {
00537         KoGenStyle pageLayout = m_doc->pageLayout().saveOasis();
00538         pageLayout.addAttribute( "style:page-usage", "all" ); // needed?
00539         QString pageLayoutName( context.mainStyles().lookup( pageLayout, "pm" ) );
00540 
00541         xmlWriter.startElement( "style:master-page" );
00542         xmlWriter.addAttribute( "style:name", "Standard" );
00543         xmlWriter.addAttribute( "style:page-layout-name", pageLayoutName );
00544 
00545         QString styleName = saveOasisPageStyle( store, context.mainStyles() );
00546         if ( !styleName.isEmpty() )
00547             xmlWriter.addAttribute( "draw:style-name", styleName );
00548 
00549         saveOasisObject( store, xmlWriter, context,  indexObj,partIndexObj, manifestWriter );
00550 
00551         xmlWriter.startElement( "style:header" );
00552         m_doc->header()->textObject()->saveOasisContent( xmlWriter, context );
00553         xmlWriter.endElement();
00554 
00555         xmlWriter.startElement( "style:footer" );
00556         m_doc->footer()->textObject()->saveOasisContent( xmlWriter, context );
00557         xmlWriter.endElement();
00558 
00559         xmlWriter.endElement();
00560     }
00561     else
00562     {
00563         //store use to save picture and co
00564         xmlWriter.startElement( "draw:page" );
00565 
00566         QString drawName( m_manualTitle );
00567         QRegExp rx( "^page[0-9]+$" );
00568         if ( drawName.isEmpty() || pageNames.contains( drawName ) || rx.search( drawName ) != -1 )
00569         {
00570             drawName = "page" + QString::number( posPage );
00571         }
00572         pageNames.insert( drawName, posPage );
00573         xmlWriter.addAttribute( "draw:name", drawName ); //we must store a name
00574         xmlWriter.addAttribute( "koffice:name", m_manualTitle ); // so that we can have the same name for different pages
00575         xmlWriter.addAttribute( "draw:id", "page" + QString::number( posPage ) );
00576         xmlWriter.addAttribute( "draw:master-page-name", "Standard"); //by default name of page is Standard
00577 
00578         QString styleName = saveOasisPageStyle( store, context.mainStyles() );
00579         kdDebug()<<" styleName :"<<styleName<<endl;
00580         if ( !styleName.isEmpty() )
00581             xmlWriter.addAttribute( "draw:style-name", styleName );
00582 
00583         saveOasisObject( store, xmlWriter, context,  indexObj,partIndexObj, manifestWriter  );
00584 
00585         saveOasisNote( xmlWriter );
00586         xmlWriter.endElement();
00587     }
00588     return true;
00589 }
00590 
00591 QString KPrPage::saveOasisPageStyle( KoStore *, KoGenStyles& mainStyles ) const
00592 {
00593     KoGenStyle stylepageauto( isMasterPage() ? KPrDocument::STYLE_BACKGROUNDPAGE : KPrDocument::STYLE_BACKGROUNDPAGEAUTO, "drawing-page" );
00594 
00595     if ( ! isMasterPage() )
00596     {
00597         stylepageauto.addProperty( "presentation:background-visible", ( m_displayBackground == true ) ? "true" : "false" );
00598         stylepageauto.addProperty( "presentation:background-objects-visible", ( m_displayObjectFromMasterPage == true ) ? "true" : "false" );
00599         QString transition = saveOasisPageEffect();
00600         if ( !transition.isEmpty() )
00601         {
00602             stylepageauto.addProperty( "presentation:transition-style", transition );
00603             QString additionalTransition = saveOasisAdditionalPageEffect();
00604             if ( !additionalTransition.isEmpty() )
00605             {
00606                 stylepageauto.addProperty( "koffice:additional-transition-style", additionalTransition );
00607             }
00608         }
00609         stylepageauto.addProperty( "presentation:display-header", hasHeader());
00610         stylepageauto.addProperty( "presentation:display-footer", hasFooter());
00611 
00612         if ( m_pageTimer != 1 )
00613         {
00614             stylepageauto.addProperty("presentation:duration", saveOasisTimer( m_pageTimer ));
00615             //not used into kpresenter but necessary into ooimpress
00616             //keep compatible
00617             stylepageauto.addProperty( "presentation:transition-type", "automatic" );
00618         }
00619         if ( m_pageEffectSpeed != ES_MEDIUM ) // we don't save the default value
00620         {
00621             if ( m_pageEffectSpeed == ES_FAST )
00622                 stylepageauto.addProperty( "presentation:transition-speed", "fast" );
00623             else if ( m_pageEffectSpeed == ES_SLOW )
00624                 stylepageauto.addProperty( "presentation:transition-speed", "slow" );
00625         }
00626         if ( !isSlideSelected() )
00627             stylepageauto.addProperty( "presentation:visibility", "hidden" );
00628         if ( !m_soundFileName.isEmpty() && m_soundEffect )
00629         {
00630             QBuffer buffer;
00631             buffer.open( IO_WriteOnly );
00632             KoXmlWriter elementWriter( &buffer );  // TODO pass indentation level
00633             elementWriter.startElement( "presentation:sound" );
00634             elementWriter.addAttribute( "xlink:href", m_soundFileName );
00635             elementWriter.addAttribute( "xlink:type", "simple" );
00636             elementWriter.addAttribute( "xlink:show", "new" );
00637             elementWriter.addAttribute( "xlink:actuate", "onRequest");
00638 
00639             elementWriter.endElement();
00640             QString elementContents = QString::fromUtf8( buffer.buffer(), buffer.buffer().size() );
00641             stylepageauto.addChildElement( "sound effect", elementContents );
00642         }
00643     }
00644 
00645     if ( ! m_useMasterBackground )
00646     {
00647         m_kpbackground->saveOasisBackgroundPageStyle( stylepageauto, mainStyles );
00648     }
00649 
00650     // todo return mainStyles.lookup( stylepageauto, "dp", isMasterPage() ? KoGenStyles::AutoStyleInStylesDotXml : KoGenStyles::NoFlag );
00651     return mainStyles.lookup( stylepageauto, "dp" );
00652 }
00653 
00654 bool KPrPage::saveOasisNote( KoXmlWriter &xmlWriter ) const
00655 {
00656     if ( m_noteText.isEmpty() )
00657         return true;
00658 
00659     //todo : add size for draw:text-box otherwise we can't import into oo
00660     //<draw:text-box presentation:style-name="pr1" draw:text-style-name="P1" draw:layer="layout" svg:width="14.5cm" svg:height="11.408cm" svg:x="3.247cm" svg:y="14.126cm" presentation:class="notes">
00661     xmlWriter.startElement( "presentation:notes" );
00662     xmlWriter.startElement( "draw:frame" );
00663     //todo save style
00664 
00665     xmlWriter.startElement( "draw:text-box" );
00666     QStringList text = QStringList::split( "\n", m_noteText );
00667     for ( QStringList::Iterator it = text.begin(); it != text.end(); ++it ) {
00668         xmlWriter.startElement( "text:p" );
00669         xmlWriter.addTextNode( *it );
00670         xmlWriter.endElement();
00671     }
00672     xmlWriter.endElement();
00673     xmlWriter.endElement();
00674     xmlWriter.endElement();
00675 
00676     return true;
00677 }
00678 
00679 QString KPrPage::saveOasisPageEffect() const
00680 {
00681     QString transition;
00682     switch( m_pageEffect )
00683     {
00684     case PEF_NONE:
00685         transition="none";
00686         break;
00687     case PEF_CLOSE_HORZ:
00688         transition="close-vertical";
00689         break;
00690     case PEF_CLOSE_VERT:
00691         transition="close-horizontal";
00692         break;
00693     case PEF_CLOSE_ALL:
00694         transition="close";
00695         break;
00696     case PEF_OPEN_HORZ:
00697         transition="open-vertical";
00698         break;
00699     case PEF_OPEN_VERT:
00700         transition="open-horizontal";
00701         break;
00702     case PEF_OPEN_ALL:
00703         transition="open";
00704         break;
00705     case PEF_INTERLOCKING_HORZ_1:
00706         transition="interlocking-horizontal-left";
00707         break;
00708     case PEF_INTERLOCKING_HORZ_2:
00709         transition="interlocking-horizontal-right";
00710         break;
00711     case PEF_INTERLOCKING_VERT_1:
00712         transition="interlocking-vertical-top";
00713         break;
00714     case PEF_INTERLOCKING_VERT_2:
00715         transition="interlocking-vertical-bottom";
00716         break;
00717     case PEF_SURROUND1:
00718         transition="spiralin-left";
00719         break;
00720     case PEF_FLY1:
00721         transition="fly-away";
00722         break;
00723     case PEF_BLINDS_HOR:
00724         transition="horizontal-stripes";
00725         break;
00726     case PEF_BLINDS_VER:
00727         transition="vertical-stripes";
00728         break;
00729     case PEF_BOX_IN:
00730         transition="fade-to-center";
00731         break;
00732     case PEF_BOX_OUT:
00733         transition="fade-from-center";
00734         break;
00735     case PEF_CHECKBOARD_ACROSS:
00736         transition="horizontal-checkerboard";
00737         break;
00738     case PEF_CHECKBOARD_DOWN:
00739         transition="vertical-checkerboard";
00740         break;
00741     case PEF_COVER_DOWN:
00742         transition="fade-from-top";
00743         break;
00744     case PEF_COVER_UP:
00745         transition="fade-from-bottom";
00746         break;
00747     case PEF_COVER_LEFT:
00748         transition="fade-from-right";
00749         break;
00750     case PEF_COVER_RIGHT:
00751         transition="fade-from-left";
00752         break;
00753     case PEF_COVER_LEFT_UP:
00754         transition="fade-from-lowerright";
00755         break;
00756     case PEF_COVER_LEFT_DOWN:
00757         transition="fade-from-upperright";
00758         break;
00759     case PEF_COVER_RIGHT_UP:
00760         transition="fade-from-lowerleft";
00761         break;
00762     case PEF_COVER_RIGHT_DOWN:
00763         transition="fade-from-upperleft";
00764         break;
00765     case PEF_UNCOVER_LEFT:
00766         transition="uncover-to-left";
00767         break;
00768     case PEF_UNCOVER_UP:
00769         transition="uncover-to-top";
00770         break;
00771     case PEF_UNCOVER_RIGHT:
00772         transition="uncover-to-right";
00773         break;
00774     case PEF_UNCOVER_DOWN:
00775         transition="uncover-to-bottom";
00776         break;
00777     case PEF_UNCOVER_LEFT_UP:
00778         transition="uncover-to-upperleft";
00779         break;
00780     case PEF_UNCOVER_LEFT_DOWN:
00781         transition="uncover-to-lowerleft";
00782         break;
00783     case PEF_UNCOVER_RIGHT_UP:
00784         transition="uncover-to-upperright";
00785         break;
00786     case PEF_UNCOVER_RIGHT_DOWN:
00787         transition="uncover-to-lowerright";
00788         break;
00789     case PEF_DISSOLVE:
00790         transition="dissolve";
00791         break;
00792     case PEF_STRIPS_LEFT_UP:
00793         transition="fade-from-lowerright";
00794         break;
00795     case PEF_STRIPS_LEFT_DOWN:
00796         transition="fade-from-upperright";
00797         break;
00798     case PEF_STRIPS_RIGHT_UP:
00799         transition="fade-from-lowerleft";
00800         break;
00801     case PEF_STRIPS_RIGHT_DOWN:
00802         transition="fade-from-upperleft";
00803         break;
00804     case PEF_MELTING:
00805         transition="melt";
00806         break;
00807     case PEF_LAST_MARKER://don't use it !!!
00808         break;
00809     case PEF_RANDOM:
00810         transition="random";
00811         break;
00812 
00813     }
00814     return transition;
00815 }
00816 
00817 
00818 QString KPrPage::saveOasisAdditionalPageEffect() const
00819 {
00820     QString additionalEffect;
00821     switch( m_pageEffect )
00822     {
00823         case PEF_STRIPS_LEFT_UP:
00824             additionalEffect="stripe-from-lowerright";
00825             break;
00826         case PEF_STRIPS_LEFT_DOWN:
00827             additionalEffect="stripe-from-upperright";
00828             break;
00829         case PEF_STRIPS_RIGHT_UP:
00830             additionalEffect="stripe-from-lowerleft";
00831             break;
00832         case PEF_STRIPS_RIGHT_DOWN:
00833             additionalEffect="stripe-from-upperleft";
00834             break;
00835         default:
00836             break;
00837     }
00838     return additionalEffect;
00839 }
00840 
00841 
00842 KPrObject *KPrPage::getObject(int num)
00843 {
00844     Q_ASSERT( num < (int)m_objectList.count() );
00845     return m_objectList.at(num);
00846 }
00847 
00848 /*
00849  * Check if object name already exists.
00850  */
00851 bool KPrPage::objectNameExists( KPrObject *object, QPtrList<KPrObject> &list ) {
00852     QPtrListIterator<KPrObject> it( list );
00853 
00854     for ( it.toFirst(); it.current(); ++it ) {
00855         // object name can exist in current object.
00856         if ( it.current()->getObjectName() == object->getObjectName() &&
00857              it.current() != object ) {
00858             return true;
00859         }
00860         else if ( it.current()->getType() == OT_GROUP ) {
00861             QPtrList<KPrObject> objectList( static_cast<KPrGroupObject*>(it.current())->getObjects() );
00862             if ( objectNameExists( object, objectList ) ) {
00863                 return true;
00864             }
00865         }
00866     }
00867     return false;
00868 }
00869 
00870 void KPrPage::unifyObjectName( KPrObject *object ) {
00871     if ( object->getObjectName().isEmpty() ) {
00872         object->setObjectName( object->getTypeString() );
00873     }
00874     QString objectName( object->getObjectName() );
00875 
00876     QPtrList<KPrObject> list( m_objectList );
00877 
00878     int count = 1;
00879 
00880     while ( objectNameExists( object, list ) ) {
00881         count++;
00882         QRegExp rx( " \\(\\d{1,}\\)$" );
00883         if ( rx.search( objectName ) != -1 ) {
00884             objectName.remove( rx );
00885         }
00886         objectName += QString(" (%1)").arg( count );
00887         object->setObjectName( objectName );
00888     }
00889 }
00890 
00891 void KPrPage::appendObject(KPrObject *_obj)
00892 {
00893     unifyObjectName(_obj);
00894     m_objectList.append(_obj);
00895 }
00896 
00897 void KPrPage::appendObjects( const QValueList<KPrObject *> &objects )
00898 {
00899     QMap <QString, int> usedPageNames;
00900     QPtrListIterator<KPrObject> it( m_objectList );
00901     // find the biggest number
00902     for ( ; it.current() ; ++it )
00903     {
00904         QString objectName( it.current()->getObjectName() );
00905 
00906         QRegExp rx( "(.*) \\((\\d{1,})\\)$" );
00907         rx.setMinimal( true );
00908         if ( rx.search( objectName ) != -1 && rx.numCaptures() == 2 )
00909         {
00910             int id = rx.cap( 2 ).toInt();
00911             if ( usedPageNames[rx.cap( 1 )] < id )
00912             {
00913                 usedPageNames[rx.cap( 1 )] = id;
00914             }
00915         }
00916         else
00917         {
00918             usedPageNames[objectName] = 1;
00919         }
00920     }
00921 
00922     QValueListConstIterator<KPrObject *> oIt( objects.begin() );
00923     for ( ; oIt != objects.end(); ++oIt )
00924     {
00925         QString objectName( ( *oIt )->getObjectName() );
00926         QRegExp rx( " \\(\\d{1,}\\)$" );
00927         if ( rx.search( objectName ) != -1 )
00928         {
00929             objectName.remove( rx );
00930         }
00931 
00932         if ( usedPageNames.contains( objectName ) )
00933         {
00934             usedPageNames[objectName]++;
00935             objectName += QString(" (%1)").arg( usedPageNames[objectName] );
00936             ( *oIt )->setObjectName( objectName );
00937         }
00938         m_objectList.append( *oIt );
00939     }
00940 }
00941 
00942 int KPrPage::takeObject( KPrObject *object )
00943 {
00944     int pos = m_objectList.findRef( object );
00945     m_objectList.take( pos );
00946     return pos;
00947 }
00948 
00949 void KPrPage::replaceObject( KPrObject *oldObject, KPrObject *newObject )
00950 {
00951     //XXX check if object name gets set
00952     unsigned int pos = m_objectList.findRef( oldObject );
00953     m_objectList.take( pos );
00954     m_objectList.insert( pos, newObject );
00955 }
00956 
00957 
00958 void KPrPage::insertObject( KPrObject *object, int pos )
00959 {
00960     unifyObjectName( object );
00961     m_objectList.insert( pos, object );
00962 }
00963 
00964 KCommand * KPrPage::deleteSelectedObjects()
00965 {
00966     QPtrList<KPrObject> objects = getSelectedObjects( true );
00967 
00968     KPrDeleteCmd *deleteCmd=0L;
00969 
00970     if ( objects.count() > 0 ) {
00971         deleteCmd = new KPrDeleteCmd( i18n( "Delete Objects" ), objects, m_doc, this );
00972         deleteCmd->execute();
00973     }
00974     else
00975         m_doc->setModified(true);
00976 
00977     return deleteCmd ;
00978 }
00979 
00980 void KPrPage::copyObjs(QDomDocument &doc, QDomElement &presenter, QValueList<KoPictureKey> & savePictures) const
00981 {
00982     if ( !numSelected() )
00983         return;
00984 
00985     QPtrListIterator<KPrObject> it( m_objectList );
00986     for ( ; it.current() ; ++it )
00987     {
00988         if(it.current()->isSelected())
00989         {
00990             if ( it.current()->getType() == OT_PICTURE )
00991             {
00992                 KoPictureKey key = static_cast<KPrPixmapObject *>( it.current() )->getKey();
00993                 if ( !savePictures.contains( key ) )
00994                     savePictures.append( key );
00995             }
00996             QDomElement object=doc.createElement("OBJECT");
00997             object.setAttribute("type", static_cast<int>( it.current()->getType() ));
00998             object.appendChild(it.current()->save( doc,0 ));
00999             presenter.appendChild(object);
01000         }
01001     }
01002 }
01003 
01004 void KPrPage::pasteObjs( const QByteArray & data,int nbCopy, double angle,
01005                          double increaseX, double increaseY, double moveX, double moveY )
01006 {
01007     m_doc->deSelectAllObj();
01008     int num = m_objectList.count();
01009     if ( !data.size() )
01010         return;
01011     QBuffer buffer( data );
01012     KoStore* store = KoStore::createStore( &buffer, KoStore::Read );
01013     int nbNewObject = -1 ;
01014     KMacroCommand *macro = 0L;
01015     if ( !store->bad() )
01016     {
01017         if ( store->open( "root" ) )
01018         {
01019             QString errorMsg;
01020             int errorLine;
01021             int errorColumn;
01022             QDomDocument domDoc;
01023             if ( !domDoc.setContent( store->device(), &errorMsg, &errorLine, &errorColumn ) )
01024             {
01025                 kdError (30003) << "Parsing Error! Aborting! (in KPrPage::PasteObj)" << endl
01026                                 << "  Line: " << errorLine << " Column: " << errorColumn << endl
01027                                 << "  Message: " << errorMsg << endl;
01028                 delete store;
01029                 return;
01030             }
01031             QDomElement topElem = domDoc.documentElement();
01032 
01033             for ( int i = 0 ; i < nbCopy ; i++ )
01034             {
01035                 KCommand *cmd = m_doc->loadPastedObjs( domDoc.toString(),this );
01036                 if (cmd )
01037                 {
01038                     if ( !macro )
01039                         macro = new KMacroCommand( i18n("Paste Objects" ));
01040                     macro->addCommand( cmd );
01041                 }
01042                 if ( nbNewObject == -1 )
01043                     nbNewObject = m_objectList.count() - num;
01044             }
01045 
01046             m_doc->loadPictureMap( topElem );
01047             store->close();
01048             int nbNewPartObject = -1;
01049             int nbElementBefore = m_objectList.count();
01050             for ( int i = 0 ; i < nbCopy ; i++ )
01051             {
01052                 m_doc->insertEmbedded( store, topElem, macro, this, num );
01053                 if ( nbNewPartObject ==-1 )
01054                     nbNewObject = nbNewObject + (m_objectList.count() - nbElementBefore);
01055             }
01056         }
01057     }
01058     delete store;
01059 
01060     //move and select all new pasted in objects
01061     KPrObject *_tempObj;
01062     int i = 0;
01063     int mod = 1;
01064     for (_tempObj = m_objectList.at(num); _tempObj; _tempObj = m_objectList.next(),  i++ ) {
01065         if ( i >= nbNewObject )
01066             mod++;
01067         _tempObj->moveBy( moveX*(double)mod,moveY*(double)mod);
01068         _tempObj->setSelected( true );
01069         if ( angle == 0.0 || (increaseY == 0.0 && increaseX == 0.0))
01070             m_doc->repaint(_tempObj);
01071     }
01072 
01073     if ( angle != 0.0)
01074     {
01075         KCommand *cmd = rotateSelectedObjects(angle, true);
01076         if (cmd )
01077         {
01078             if ( !macro )
01079                 macro = new KMacroCommand( i18n("Paste Objects" ));
01080             macro->addCommand( cmd );
01081         }
01082     }
01083     if ( increaseX != 0.0 || increaseY != 0.0 )
01084     {
01085         QPtrListIterator<KPrObject> it( m_objectList );
01086         for ( ; it.current() ; ++it )
01087         {
01088             if(it.current()->isSelected())
01089             {
01090                 KCommand *cmd =new KPrResizeCmd( i18n("Resize"), KoPoint(0, 0),
01091                                               KoSize(increaseX, increaseY), it.current(), m_doc );
01092                 if ( cmd )
01093                 {
01094                     cmd->execute();
01095                     if ( !macro )
01096                         macro = new KMacroCommand( i18n("Paste Objects" ));
01097                     macro->addCommand( cmd );
01098                 }
01099             }
01100         }
01101     }
01102 
01103     if (macro)
01104         m_doc->addCommand(macro);
01105     //update sidebar
01106     if ( angle == 0.0 || (increaseY == 0.0 && increaseX == 0.0) )
01107     {
01108         m_doc->updateSideBarItem( this );
01109     }
01110 
01111     m_doc->setModified(true);
01112 }
01113 
01114 KPrTextObject * KPrPage::textFrameSet ( unsigned int _num ) const
01115 {
01116     unsigned int i = 0;
01117     QPtrListIterator<KPrObject> it( m_objectList );
01118     for ( ; it.current() ; ++it )
01119     {
01120         if(it.current()->getType()==OT_TEXT)
01121         {
01122             if(i==_num)
01123                 return static_cast<KPrTextObject*>(it.current());
01124             i++;
01125         }
01126     }
01127     return 0L;
01128 }
01129 
01130 int KPrPage::numSelected() const
01131 {
01132     int num = 0;
01133 
01134     QPtrListIterator<KPrObject> it( m_objectList );
01135     for ( ; it.current() ; ++it )
01136     {
01137         if(it.current()->isSelected())
01138             num++;
01139     }
01140 
01141     return num;
01142 }
01143 
01144 int KPrPage::numTextObject() const
01145 {
01146     int num = 0;
01147 
01148     QPtrListIterator<KPrObject> it( m_objectList );
01149     for ( ; it.current() ; ++it )
01150     {
01151         if(it.current()->getType()==OT_TEXT)
01152             num++;
01153     }
01154 
01155     return num;
01156 }
01157 
01158 KPrObject* KPrPage::getSelectedObj() const
01159 {
01160     QPtrListIterator<KPrObject> it( m_objectList );
01161     for ( ; it.current() ; ++it )
01162     {
01163         if(it.current()->isSelected())
01164             return it.current();
01165     }
01166     return 0L;
01167 }
01168 
01169 
01170 QPtrList<KPrObject> KPrPage::getSelectedObjects( bool withoutHeaderFooter ) const
01171 {
01172     QPtrList<KPrObject> objects;
01173     QPtrListIterator<KPrObject> it( m_objectList );
01174     for ( ; it.current() ; ++it )
01175     {
01176         if( it.current()->isSelected()
01177             && ( !withoutHeaderFooter
01178                  || it.current() != m_doc->header() && it.current()!= m_doc->footer() ) )
01179         {
01180             objects.append( it.current() );
01181         }
01182     }
01183     return objects;
01184 }
01185 
01186 
01187 void KPrPage::groupObjects()
01188 {
01189     QPtrList<KPrObject> objects( getSelectedObjects( true ) );
01190 
01191     if ( objects.count() > 1 ) {
01192         KPrGroupObjCmd *groupObjCmd = new KPrGroupObjCmd( i18n( "Group Objects" ), objects, m_doc,this );
01193         m_doc->addCommand( groupObjCmd );
01194         groupObjCmd->execute();
01195     }
01196 }
01197 
01198 void KPrPage::ungroupObjects( KMacroCommand ** macro )
01199 {
01200     QPtrList<KPrObject> objects( getSelectedObjects( true ) );
01201     QPtrListIterator<KPrObject> it( objects );
01202     for ( ; it.current() ; ++it )
01203     {
01204         KPrObject *object = it.current();
01205         if ( object->getType() == OT_GROUP )
01206         {
01207             UnGroupObjCmd *cmd = new UnGroupObjCmd( i18n( "Ungroup Objects" ),
01208                 (KPrGroupObject*)object, m_doc, this );
01209             cmd->execute();
01210 
01211             if ( !*macro )
01212                 *macro = new KMacroCommand(i18n( "Ungroup Objects" ));
01213             (*macro)->addCommand( cmd );
01214         }
01215     }
01216 }
01217 
01218 void KPrPage::lowerObjs(bool backward)
01219 {
01220     KPrObject *kpobject = 0;
01221 
01222     QPtrList<KPrObject> _new;
01223 
01224     for ( unsigned int j = 0; j < m_objectList.count(); j++ )
01225         _new.append( m_objectList.at( j ) );
01226 
01227     _new.setAutoDelete( false );
01228     bool createCmd = false;
01229     int insertPos = 0;
01230     for ( int i = 0; i < static_cast<int>( _new.count() ); i++ ) {
01231         kpobject = _new.at( i );
01232         if ( kpobject->isSelected() ) {
01233             if ( i == insertPos )
01234             {
01235                 ++insertPos;
01236                 continue;
01237             }
01238             createCmd = true;
01239             _new.take( i );
01240             if ( backward )
01241                 _new.insert(QMAX(i-1,0) ,  kpobject);
01242             else
01243                 _new.insert( insertPos++, kpobject );
01244         }
01245     }
01246     if ( createCmd )
01247     {
01248         KPrLowerRaiseCmd *lrCmd = new KPrLowerRaiseCmd( i18n( "Lower Objects" ), m_objectList, _new, m_doc,this );
01249         lrCmd->execute();
01250         m_doc->addCommand( lrCmd );
01251     }
01252 
01253 }
01254 
01255 void KPrPage::raiseObjs(bool forward)
01256 {
01257     KPrObject *kpobject = 0;
01258 
01259     QPtrList<KPrObject> _new;
01260 
01261     for ( unsigned int j = 0; j < m_objectList.count(); j++ )
01262         _new.append( m_objectList.at( j ) );
01263 
01264     _new.setAutoDelete( false );
01265     bool createCmd = false;
01266     int size = int( _new.count() );
01267     int insertPos = size - 1;
01268     for ( int i = size - 1; i >= 0; i-- )
01269     {
01270         kpobject = _new.at( i );
01271         if ( kpobject->isSelected() )
01272         {
01273             if ( i == insertPos )
01274             {
01275                 --insertPos;
01276                 continue;
01277             }
01278             createCmd = true;
01279             _new.take( i );
01280             if ( forward )
01281                 _new.insert( QMIN( i+1, size - 1),  kpobject);
01282             else
01283                 _new.insert( insertPos--, kpobject );
01284         }
01285     }
01286     if ( createCmd )
01287     {
01288         KPrLowerRaiseCmd *lrCmd = new KPrLowerRaiseCmd( i18n( "Raise Objects" ), m_objectList, _new, m_doc,this );
01289         lrCmd->execute();
01290         m_doc->addCommand( lrCmd );
01291     }
01292 }
01293 
01294 KCommand *KPrPage::insertObject( const QString &name, KPrObject * object, const KoRect &r, bool addCommand )
01295 {
01296     object->setOrig( r.x(), r.y() );
01297     object->setSize( r.width(), r.height() );
01298     object->setSelected( true );
01299 
01300     KPrInsertCmd *insertCmd = new KPrInsertCmd( name, object, m_doc, this );
01301     insertCmd->execute();
01302     if ( addCommand )
01303     {
01304         m_doc->addCommand( insertCmd );
01305         return 0L;
01306     }
01307     return insertCmd;
01308 }
01309 
01310 void KPrPage::insertLine( const KoRect &r, const KoPen & pen, LineEnd lb, LineEnd le, LineType lt )
01311 {
01312     KPrLineObject *kplineobject = new KPrLineObject( pen, lb, le, lt );
01313     insertObject( i18n( "Insert Line" ), kplineobject, r );
01314 }
01315 
01316 void KPrPage::insertRectangle( const KoRect &r, const KoPen & pen, const QBrush &brush, FillType ft,
01317                                const QColor &g1, const QColor &g2,
01318                                BCType gt, int rndX, int rndY, bool unbalanced, int xfactor, int yfactor )
01319 {
01320     KPrRectObject *kprectobject = new KPrRectObject( pen, brush, ft, g1, g2, gt, rndX, rndY,
01321                                                    unbalanced, xfactor, yfactor );
01322     insertObject( i18n( "Insert Rectangle" ), kprectobject, r );
01323 }
01324 
01325 void KPrPage::insertCircleOrEllipse( const KoRect &r, const KoPen &pen, const QBrush & brush, FillType ft,
01326                                      const QColor &g1, const QColor &g2,
01327                                      BCType gt, bool unbalanced, int xfactor, int yfactor )
01328 {
01329     KPrEllipseObject *kpellipseobject = new KPrEllipseObject( pen, brush, ft, g1, g2, gt,
01330                                                             unbalanced, xfactor, yfactor );
01331     insertObject( i18n( "Insert Ellipse" ), kpellipseobject, r );
01332 }
01333 
01334 void KPrPage::insertPie( const KoRect &r, const KoPen &pen, const QBrush &brush, FillType ft,
01335                          const QColor &g1, const QColor &g2,
01336                          BCType gt, PieType pt, int _angle, int _len, LineEnd lb, LineEnd le,
01337                          bool unbalanced, int xfactor, int yfactor )
01338 {
01339     KPrPieObject *kppieobject = new KPrPieObject( pen, brush, ft, g1, g2, gt, pt, _angle,
01340                                                 _len, lb, le, unbalanced, xfactor, yfactor );
01341     insertObject( i18n( "Insert Pie/Arc/Chord" ), kppieobject, r );
01342 }
01343 
01344 KPrTextObject* KPrPage::insertTextObject( const KoRect& r, const QString&  text , KPrView * _view )
01345 {
01346     KPrTextObject *kptextobject = new KPrTextObject( m_doc );
01347     insertObject( i18n( "Insert Textbox" ), kptextobject, r );
01348     //TODO create macro command : now insertObject can return KCommand
01349     //TODO fix repaint object
01350     if (  !text.isEmpty() )
01351     {
01352         KPrTextView *view =  kptextobject->createKPTextView( _view ? _view->getCanvas() : 0L );
01353         view->insertText( text );
01354         view->terminate();
01355         delete view;
01356         m_doc->repaint( kptextobject );
01357     }
01358     return kptextobject;
01359 }
01360 
01361 void KPrPage::insertAutoform( const KoRect &r, const KoPen &pen, const QBrush &brush, LineEnd lb, LineEnd le, FillType ft,
01362                               const QColor &g1, const QColor &g2, BCType gt, const QString &fileName, bool unbalanced,
01363                               int xfactor, int yfactor ){
01364     KPrAutoformObject *kpautoformobject = new KPrAutoformObject( pen, brush, fileName, lb, le, ft,
01365                                                                g1, g2, gt, unbalanced, xfactor, yfactor );
01366     insertObject( i18n( "Insert Autoform" ), kpautoformobject, r );
01367 }
01368 
01369 void KPrPage::insertFreehand( const KoPointArray &points, const KoRect &r, const KoPen &pen,
01370                               LineEnd lb, LineEnd le )
01371 {
01372     KoSize size( r.width(), r.height() );
01373     KPrFreehandObject *kpfreehandobject = new KPrFreehandObject( points, size, pen, lb, le );
01374     insertObject( i18n( "Insert Freehand" ), kpfreehandobject, r );
01375 }
01376 
01377 void KPrPage::insertPolyline( const KoPointArray &points, const KoRect &r, const KoPen &pen,
01378                               LineEnd lb, LineEnd le )
01379 {
01380     KoSize size( r.width(), r.height() );
01381     KPrPolylineObject *kppolylineobject = new KPrPolylineObject( points, size, pen, lb, le );
01382     insertObject( i18n( "Insert Polyline" ), kppolylineobject, r );
01383 }
01384 
01385 void KPrPage::insertQuadricBezierCurve( const KoPointArray &points, const KoPointArray &allPoints,
01386                                         const KoRect &r, const KoPen &pen,
01387                                         LineEnd lb, LineEnd le )
01388 {
01389     KoSize size( r.width(), r.height() );
01390 
01391     KPrQuadricBezierCurveObject *kpQuadricBezierCurveObject = new KPrQuadricBezierCurveObject(
01392         points, allPoints, size, pen, lb, le );
01393     insertObject( i18n( "Insert Quadric Bezier Curve" ), kpQuadricBezierCurveObject, r );
01394 }
01395 
01396 void KPrPage::insertCubicBezierCurve( const KoPointArray &points, const KoPointArray &allPoints,
01397                                       const KoRect &r, const KoPen &pen,
01398                                       LineEnd lb, LineEnd le )
01399 {
01400     KoSize size( r.width(), r.height() );
01401 
01402     KPrCubicBezierCurveObject *kpCubicBezierCurveObject = new KPrCubicBezierCurveObject( points, allPoints, size, pen, lb, le );
01403     insertObject( i18n( "Insert Cubic Bezier Curve" ), kpCubicBezierCurveObject, r );
01404 }
01405 
01406 void KPrPage::insertPolygon( const KoPointArray &points, const KoRect &r, const KoPen &pen, const QBrush &brush, FillType ft,
01407                              const QColor &g1, const QColor &g2, BCType gt, bool unbalanced, int xfactor, int yfactor,
01408                              bool _checkConcavePolygon, int _cornersValue, int _sharpnessValue )
01409 {
01410     KoSize size( r.width(), r.height() );
01411 
01412     KPrPolygonObject *kpPolygonObject = new KPrPolygonObject( points, size, pen, brush, ft,
01413                                                             g1, g2, gt, unbalanced, xfactor, yfactor,
01414                                                             _checkConcavePolygon, _cornersValue, _sharpnessValue );
01415     insertObject( i18n( "Insert Polygon" ), kpPolygonObject, r );
01416 }
01417 
01418 void KPrPage::insertClosedLine( const KoPointArray &points, const KoRect &r, const KoPen &pen, const QBrush &brush,
01419                                 FillType ft,const QColor &g1, const QColor &g2,
01420                                 BCType gt, bool unbalanced, int xfactor, int yfactor, ToolEditMode _mode )
01421 {
01422     QString _type;
01423     QString _name;
01424     if ( _mode == INS_CLOSED_FREEHAND ) {
01425         _type = i18n( "Closed Freehand" );
01426         _name = i18n( "Insert Closed Freehand" );
01427     }
01428     else if ( _mode == INS_CLOSED_POLYLINE ) {
01429         _type = i18n( "Closed Polyline" );
01430         _name = i18n( "Insert Closed Polyline" );
01431     }
01432     else if ( _mode == INS_CLOSED_QUADRICBEZIERCURVE ) {
01433         _type = i18n( "Closed Quadric Bezier Curve" );
01434         _name = i18n( "Insert Closed Quadric Bezier Curve" );
01435     }
01436     else if ( _mode == INS_CLOSED_CUBICBEZIERCURVE ) {
01437         _type = i18n( "Closed Cubic Bezier Curve" );
01438         _name = i18n( "Insert Closed Cubic Bezier Curve" );
01439     }
01440 
01441     KoSize size( r.width(), r.height() );
01442 
01443     KPrClosedLineObject *kpClosedLineObject = new KPrClosedLineObject( points, size, pen, brush, ft,
01444                                                                      g1, g2, gt, unbalanced, xfactor, yfactor, _type );
01445     insertObject( _name, kpClosedLineObject, r );
01446 }
01447 
01448 KPrPartObject* KPrPage::insertObject( const KoRect& _rect, KoDocumentEntry& _e )
01449 {
01450     KoDocument* doc = _e.createDoc( m_doc );
01451     if ( !doc )
01452         return NULL;
01453 
01454     if ( !doc->showEmbedInitDialog( 0 ) ) //TODO should really have parent
01455         return NULL;
01456 
01457     QRect r = QRect( (int)_rect.left(), (int)_rect.top(),
01458                      (int)_rect.width(), (int)_rect.height() );
01459     KPrChild* ch = new KPrChild( m_doc, doc, r );
01460     m_doc->insertObject( ch );
01461 
01462     KPrPartObject *kppartobject = new KPrPartObject( ch );
01463     insertObject( i18n( "Embed Object" ), kppartobject, _rect );
01464 
01465     //emit sig_insertObject( ch, kppartobject );
01466     m_doc->repaint( false );
01467 
01468     return kppartobject;
01469 }
01470 
01471 KCommand* KPrPage::setPen( const KoPen &pen, LineEnd lb, LineEnd le, int flags )
01472 {
01473     KoPenCmd * cmd = NULL;
01474 
01475     KoPenCmd::Pen _newPen( pen, lb, le);
01476 
01477     QPtrList<KPrObject> _objects;
01478     _objects.setAutoDelete( false );
01479 
01480     QPtrListIterator<KPrObject> it( m_objectList );
01481     for ( ; it.current() ; ++it )
01482     {
01483         if( it.current()->isSelected() )
01484         {
01485             _objects.append( it.current() );
01486         }
01487     }
01488 
01489     if ( !_objects.isEmpty() && flags ) {
01490         cmd = new KoPenCmd( i18n( "Apply Styles" ), _objects, _newPen, m_doc, this, flags );
01491         cmd->execute();
01492     }
01493 
01494     return cmd;
01495 }
01496 
01497 KCommand * KPrPage::setBrush( const QBrush &brush, FillType ft, const QColor &g1, const QColor &g2,
01498                               BCType gt, bool unbalanced, int xfactor, int yfactor, int flags )
01499 {
01500     KPrBrushCmd * cmd = NULL;
01501 
01502     KPrBrushCmd::Brush _newBrush;
01503 
01504     _newBrush.brush = QBrush( brush );
01505     _newBrush.fillType = ft;
01506     _newBrush.gColor1 = g1;
01507     _newBrush.gColor2 = g2;
01508     _newBrush.gType = gt;
01509     _newBrush.unbalanced = unbalanced;
01510     _newBrush.xfactor = xfactor;
01511     _newBrush.yfactor = yfactor;
01512 
01513     QPtrList<KPrObject> _objects;
01514     _objects.setAutoDelete( false );
01515 
01516     QPtrListIterator<KPrObject> it( m_objectList );
01517     for ( ; it.current() ; ++it )
01518     {
01519         if( it.current()->isSelected() )
01520         {
01521             _objects.append( it.current() );
01522         }
01523     }
01524 
01525     if ( !_objects.isEmpty() && flags ) {
01526         cmd = new KPrBrushCmd( i18n( "Apply Styles" ), _objects, _newBrush, m_doc, this, flags );
01527         cmd->execute();
01528     }
01529 
01530     return cmd;
01531 }
01532 
01533 void KPrPage::slotRepaintVariable()
01534 {
01535     QPtrListIterator<KPrObject> it( m_objectList );
01536     for ( ; it.current() ; ++it )
01537     {
01538         if ( it.current()->getType() == OT_TEXT )
01539             m_doc->repaint( it.current() );
01540     }
01541 }
01542 
01543 void KPrPage::recalcPageNum()
01544 {
01545     QPtrListIterator<KPrObject> it( m_objectList );
01546     for ( ; it.current() ; ++it )
01547     {
01548         if ( it.current()->getType() == OT_TEXT ) {
01549             ( (KPrTextObject*)it.current() )->recalcPageNum( this );
01550             m_doc->repaint( it.current() ); // TODO only if something changed
01551         }
01552     }
01553 }
01554 
01555 void KPrPage::changePicture( const KURL & url, QWidget *parent )
01556 {
01557     // filename has been chosen in KPrView with a filedialog,
01558     // so we know it exists
01559     KoPicture image = m_doc->pictureCollection()->downloadPicture( url, parent );
01560 
01561     QPtrListIterator<KPrObject> it( m_objectList );
01562     for ( ; it.current() ; ++it )
01563     {
01564         if(it.current()->isSelected() && it.current()->getType()==OT_PICTURE)
01565         {
01566             KPrPixmapObject* obj=dynamic_cast<KPrPixmapObject*>( it.current() );
01567             if( obj)
01568             {
01569                 KPrPixmapObject *pix = new KPrPixmapObject( m_doc->pictureCollection(), image.getKey() );
01570                 KPrChgPixCmd *chgPixCmd = new KPrChgPixCmd( i18n( "Change Pixmap" ),obj,pix, m_doc,this );
01571                 chgPixCmd->execute();
01572                 m_doc->addCommand( chgPixCmd );
01573             }
01574             break;
01575         }
01576     }
01577 }
01578 
01579 void KPrPage::insertPicture( const QString &filename, const KoPoint &pos )
01580 {
01581     KoPictureKey key = m_doc->pictureCollection()->loadPicture( filename ).getKey();
01582     KPrPixmapObject *kppixmapobject = new KPrPixmapObject(m_doc->pictureCollection() , key );
01583 
01584     kppixmapobject->setOrig( pos );
01585     kppixmapobject->setSelected( true );
01586 
01587     kppixmapobject->setSize( m_doc->zoomHandler()->pixelXToPt( kppixmapobject->originalSize().width() ),
01588                              m_doc->zoomHandler()->pixelYToPt( kppixmapobject->originalSize().height() ) );
01589     kppixmapobject->setKeepRatio( true ); // pics have keep-aspect-ratio on by default.
01590 
01591     KPrInsertCmd *insertCmd = new KPrInsertCmd( i18n( "Insert Picture" ), kppixmapobject, m_doc, this );
01592     insertCmd->execute();
01593     m_doc->addCommand( insertCmd );
01594 
01595     KoRect s = getPageRect();
01596     float fakt = 1;
01597     if ( kppixmapobject->getSize().width() > s.width() )
01598         fakt = (float)s.width() / (float)kppixmapobject->getSize().width();
01599     if ( kppixmapobject->getSize().height() > s.height() )
01600         fakt = QMIN( fakt, (float)s.height() / (float)kppixmapobject->getSize().height() );
01601 
01602     //kdDebug(33001) << k_funcinfo << "Fakt: " << fakt << endl;
01603 
01604     if ( fakt < 1 ) {
01605         int w = (int)( fakt * (float)kppixmapobject->getSize().width() );
01606         int h = (int)( fakt * (float)kppixmapobject->getSize().height() );
01607         //kdDebug(33001) << k_funcinfo << "Size: " << w << ", " << h << endl;
01608         kppixmapobject->setOrig(0,0);
01609         kppixmapobject->setSize(w, h);
01610         m_doc->repaint( false );
01611     }
01612 }
01613 
01614 void KPrPage::insertPicture( const QString &_file, const KoRect &_rect )
01615 {
01616     KoPictureKey key = m_doc->pictureCollection()->loadPicture( _file ).getKey();
01617     KPrPixmapObject *kppixmapobject = new KPrPixmapObject( m_doc->pictureCollection(), key );
01618     kppixmapobject->setKeepRatio( true ); // pics have keep-aspect-ratio on by default.
01619     insertObject( i18n( "Insert Picture" ), kppixmapobject, _rect );
01620 }
01621 
01622 void KPrPage::enableEmbeddedParts( bool f )
01623 {
01624     KPrPartObject *obj=0L;
01625     QPtrListIterator<KPrObject> it( m_objectList );
01626     for ( ; it.current() ; ++it )
01627     {
01628         if(it.current()->getType()==OT_PART)
01629         {
01630             obj=dynamic_cast<KPrPartObject*>( it.current() );
01631             if(obj)
01632                 obj->enableDrawing( f );
01633         }
01634     }
01635 }
01636 
01637 
01638 void KPrPage::setBackColor(const  QColor &backColor1, const QColor &backColor2, BCType bcType,
01639                            bool unbalanced, int xfactor, int yfactor )
01640 {
01641     m_kpbackground->setBackColor1( backColor1 );
01642     m_kpbackground->setBackColor2( backColor2 );
01643     m_kpbackground->setBackColorType( bcType );
01644     m_kpbackground->setBackUnbalanced( unbalanced );
01645     m_kpbackground->setBackXFactor( xfactor );
01646     m_kpbackground->setBackYFactor( yfactor );
01647 }
01648 
01649 void KPrPage::setBackPicture( const KoPictureKey & key )
01650 {
01651     m_kpbackground->setBackPicture( key );
01652 }
01653 
01654 bool KPrPage::getBackUnbalanced() const
01655 {
01656     return m_kpbackground->getBackUnbalanced();
01657 }
01658 
01659 void KPrPage::setBackView( BackView backView )
01660 {
01661     m_kpbackground->setBackView( backView );
01662 }
01663 
01664 void KPrPage::setBackType( BackType backType )
01665 {
01666     m_kpbackground->setBackType( backType );
01667 }
01668 
01669 void KPrPage::setPageEffectSpeed( EffectSpeed pageEffectSpeed )
01670 {
01671     m_pageEffectSpeed = pageEffectSpeed;
01672 }
01673 
01674 void KPrPage::setPageEffect( PageEffect pageEffect )
01675 {
01676     m_pageEffect = pageEffect;
01677 }
01678 
01679 void KPrPage::setPageTimer( int pageTimer )
01680 {
01681     m_pageTimer = pageTimer;
01682 }
01683 
01684 void KPrPage::setPageSoundEffect( bool soundEffect )
01685 {
01686     m_soundEffect = soundEffect;
01687 }
01688 
01689 void KPrPage::setPageSoundFileName( const QString &fileName )
01690 {
01691     m_soundFileName = fileName;
01692 }
01693 
01694 BackType KPrPage::getBackType() const
01695 {
01696     return m_kpbackground->getBackType();
01697 }
01698 
01699 BackView KPrPage::getBackView() const
01700 {
01701     return m_kpbackground->getBackView();
01702 }
01703 
01704 KoPictureKey KPrPage::getBackPictureKey() const
01705 {
01706     return m_kpbackground->getBackPictureKey();
01707 }
01708 
01709 KoPicture KPrPage::getBackPicture() const
01710 {
01711     return m_kpbackground->getBackPicture();
01712 }
01713 
01714 QColor KPrPage::getBackColor1() const
01715 {
01716     return m_kpbackground->getBackColor1();
01717 }
01718 
01719 QColor KPrPage::getBackColor2() const
01720 {
01721     return m_kpbackground->getBackColor2();
01722 }
01723 
01724 int KPrPage::getBackXFactor() const
01725 {
01726     return m_kpbackground->getBackXFactor();
01727 }
01728 
01729 int KPrPage::getBackYFactor() const
01730 {
01731     return m_kpbackground->getBackYFactor();
01732 }
01733 
01734 BCType KPrPage::getBackColorType() const
01735 {
01736     return m_kpbackground->getBackColorType();
01737 }
01738 
01739 EffectSpeed KPrPage::getPageEffectSpeed() const
01740 {
01741     return m_pageEffectSpeed;
01742 }
01743 
01744 PageEffect KPrPage::getPageEffect() const
01745 {
01746     return m_pageEffect;
01747 }
01748 
01749 int KPrPage::getPageTimer() const
01750 {
01751     return m_pageTimer;
01752 }
01753 
01754 bool KPrPage::getPageSoundEffect() const
01755 {
01756     return m_soundEffect;
01757 }
01758 
01759 QString KPrPage::getPageSoundFileName() const
01760 {
01761     return m_soundFileName;
01762 }
01763 
01764 KoRect KPrPage::getPageRect() const
01765 {
01766     const KoPageLayout& p = m_doc->pageLayout();
01767     return KoRect( p.ptLeft, p.ptTop, p.ptWidth - p.ptRight - p.ptLeft, p.ptHeight - p.ptTop - p.ptBottom );
01768 }
01769 
01770 QRect KPrPage::getZoomPageRect() const
01771 {
01772     return m_doc->zoomHandler()->zoomRect(getPageRect());
01773 }
01774 
01775 void KPrPage::completeLoading( bool _clean, int lastObj )
01776 {
01777     QPtrListIterator<KPrObject> it( m_objectList );
01778     for ( ; it.current() ; ++it )
01779     {
01780         // Pictures and cliparts have been loaded from the store, we can now
01781         // get the picture from the collection, and set it in the image/clipart object
01782         if ( ( it.current()->getType() == OT_PICTURE )
01783              || ( it.current()->getType() == OT_CLIPART ) ) {
01784             if ( _clean || m_objectList.findRef( it.current() ) > lastObj )
01785             {
01786                 KPrPixmapObject* obj=dynamic_cast<KPrPixmapObject*>( it.current());
01787                 if(obj)
01788                     obj->reload();
01789             }
01790         }
01791         else if ( it.current()->getType() == OT_TEXT )
01792         {
01793             KPrTextObject*obj=dynamic_cast<KPrTextObject*>( it.current() );
01794             if(obj)
01795                 obj->recalcPageNum( this );
01796         }
01797         else if ( it.current()->getType() == OT_GROUP )
01798             completeLoadingForGroupObject( it.current() );
01799     }
01800     m_kpbackground->reload();
01801 }
01802 
01803 void KPrPage::completeLoadingForGroupObject( KPrObject *_obj )
01804 {
01805     KPrGroupObject *_groupObj = static_cast<KPrGroupObject*>( _obj );
01806 
01807     if ( _groupObj ) {
01808         QPtrListIterator<KPrObject> it( _groupObj->objectList() );
01809         for ( ; it.current(); ++it ) {
01810             if ( ( it.current()->getType() == OT_PICTURE )
01811                  || ( it.current()->getType() == OT_CLIPART ) ) {
01812                 KPrPixmapObject *_pixObj = dynamic_cast<KPrPixmapObject*>( it.current() );
01813                 if ( _pixObj )
01814                     _pixObj->reload();
01815             }
01816             else if ( it.current()->getType() == OT_TEXT ) {
01817                 KPrTextObject *_textObj=  dynamic_cast<KPrTextObject*>( it.current() );
01818                 if ( _textObj )
01819                     _textObj->recalcPageNum(  this );
01820             }
01821             else if ( it.current()->getType() == OT_GROUP )
01822                 completeLoadingForGroupObject( it.current() ); // recursion
01823         }
01824     }
01825 }
01826 
01827 KCommand * KPrPage::replaceObjs( bool createUndoRedo, double _orastX,double _orastY,const QColor & _txtBackCol,
01828                                  const QColor & _otxtBackCol )
01829 {
01830     KPrObject *kpobject = 0;
01831     double ox=0, oy=0;
01832     QPtrList<KPrObject> _objects;
01833     QValueList<KoPoint> _diffs;
01834     _objects.setAutoDelete( false );
01835 
01836     for ( int i = 0; i < static_cast<int>( m_objectList.count() ); i++ ) {
01837         kpobject = m_objectList.at( i );
01838         ox = kpobject->getOrig().x();
01839         oy = kpobject->getOrig().y();
01840         ox = static_cast<int>(ox / m_doc->getGridX() * m_doc->getGridX());
01841         oy = static_cast<int>(oy / m_doc->getGridY() * m_doc->getGridY());
01842 
01843         _diffs.append( KoPoint( ox - kpobject->getOrig().x(), oy - kpobject->getOrig().y() ) );
01844         _objects.append( kpobject );
01845     }
01846 
01847     KPrSetOptionsCmd *setOptionsCmd = new KPrSetOptionsCmd( i18n( "Set New Options" ), _diffs, _objects, m_doc->getGridX(),
01848                                                       m_doc->getGridY(),_orastX, _orastY, _txtBackCol, _otxtBackCol, m_doc );
01849     if ( createUndoRedo )
01850         return setOptionsCmd;
01851 
01852     delete setOptionsCmd;
01853     return 0L;
01854 }
01855 
01856 QString KPrPage::manualTitle() const
01857 {
01858     return m_manualTitle;
01859 }
01860 
01861 void KPrPage::insertManualTitle(const QString & title)
01862 {
01863     m_manualTitle=title;
01864 }
01865 
01866 QString KPrPage::pageTitle( const QString &_title ) const
01867 {
01868     // If a user sets a title with manual, return it.
01869     if ( !m_manualTitle.isEmpty() )
01870         return m_manualTitle;
01871 
01872     QPtrList<KPrTextObject> objs;
01873 
01874     // Create list of text objects in this page
01875 
01876     QPtrListIterator<KPrObject> it( m_objectList );
01877     for ( ; it.current() ; ++it )
01878     {
01879         if(it.current()->getType()==OT_TEXT)
01880             objs.append( static_cast<KPrTextObject*>( it.current() ) );
01881     }
01882 
01883     QString title;
01884     if ( _title.isNull() )
01885     {
01886         // MASTERPAGE
01887         if ( m_masterPage )
01888             title = i18n( "Slide %1" ).arg( m_doc->pageList().findRef( this ) + 1 );
01889         else
01890             title = i18n( "Slide Master" );
01891     }
01892     else
01893     {
01894         title = _title;
01895     }
01896 
01897     if ( objs.isEmpty() )
01898         return title;
01899 
01900     // Find object most on top
01901     KPrTextObject *tmp = objs.first();
01902     KPrTextObject *textobject=tmp;
01903     for ( tmp = objs.next(); tmp; tmp = objs.next() )
01904         if ( tmp->getOrig().y() < textobject->getOrig().y() )
01905             textobject = tmp;
01906 
01907     // this can't happen, but you never know :- )
01908     if ( !textobject )
01909         return QString( title );
01910 
01911     QString txt;
01912     if ( textobject->textDocument()->firstParag() )
01913         txt = textobject->textDocument()->firstParag()->toString();
01914     if ( txt.stripWhiteSpace().isEmpty() || txt=="\n" )
01915         return title;
01916     return txt;
01917 }
01918 
01919 void KPrPage::setNoteText( const QString &_text )
01920 {
01921     m_noteText=_text;
01922     m_doc->setModified(true);
01923 }
01924 
01925 QString KPrPage::noteText() const
01926 {
01927     return m_noteText;
01928 }
01929 
01930 void KPrPage::makeUsedPixmapList()
01931 {
01932     QPtrListIterator<KPrObject> it( m_objectList );
01933     for ( ; it.current() ; ++it )
01934     {
01935         if( it.current()->getType()==OT_PICTURE || it.current()->getType()==OT_CLIPART)
01936             m_doc->insertPixmapKey(static_cast<KPrPixmapObject*>( it.current() )->getKey() );
01937         else if ( it.current()->getType() == OT_GROUP )
01938             makeUsedPixmapListForGroupObject( it.current() );
01939     }
01940 
01941     if( m_kpbackground->getBackType()==BT_PICTURE || m_kpbackground->getBackType()==BT_CLIPART)
01942         m_doc->insertPixmapKey(m_kpbackground->getBackPictureKey());
01943 }
01944 
01945 void KPrPage::makeUsedPixmapListForGroupObject( KPrObject *_obj )
01946 {
01947     KPrGroupObject *_groupObj = static_cast<KPrGroupObject*>( _obj );
01948 
01949     if ( _groupObj ) {
01950         QPtrListIterator<KPrObject> it( _groupObj->objectList() );
01951         for ( ; it.current(); ++it ) {
01952             if ( ( it.current()->getType() == OT_PICTURE )
01953                  || ( it.current()->getType() == OT_CLIPART ) )
01954                 m_doc->insertPixmapKey(static_cast<KPrPixmapObject*>( it.current() )->getKey() );
01955             else if ( it.current()->getType() == OT_GROUP )
01956                 makeUsedPixmapListForGroupObject( it.current() );  // recursion
01957         }
01958     }
01959 }
01960 
01961 
01962 QValueList<int> KPrPage::getEffectSteps() const
01963 {
01964     QMap<int,bool> stepmap;
01965     stepmap[0] = true;
01966 
01967     QPtrListIterator<KPrObject> it( m_objectList );
01968     for ( ; it.current(); ++it )
01969     {
01970         stepmap[it.current()->getAppearStep()] = true;
01971 
01972         if ( it.current()->getDisappear() )
01973         {
01974             stepmap[it.current()->getDisappearStep()] = true;
01975         }
01976     }
01977 
01978     return stepmap.keys();
01979 }
01980 
01981 
01982 void KPrPage::deSelectAllObj()
01983 {
01984     QPtrListIterator<KPrObject> sIt( m_objectList );
01985     for ( ; sIt.current() ; ++sIt )
01986     {
01987         if(sIt.current()->isSelected())
01988             deSelectObj(sIt.current() );
01989     }
01990 }
01991 
01992 void KPrPage::deSelectObj( KPrObject *kpobject )
01993 {
01994     kpobject->setSelected( false );
01995     m_doc->repaint( kpobject );
01996 }
01997 
01998 QDomElement KPrPage::saveObjects( QDomDocument &doc, QDomElement &objects, double yoffset,
01999                                   int saveOnlyPage ) const
02000 {
02001     QPtrListIterator<KPrObject> oIt(m_objectList);
02002     for (; oIt.current(); ++oIt )
02003     {
02004         //don't store header/footer (store in header/footer section)
02005         if ( oIt.current()==m_doc->header()
02006              || oIt.current()==m_doc->footer()
02007              ||  oIt.current()->getType() == OT_PART)
02008             continue;
02009         QDomElement object=doc.createElement("OBJECT");
02010         object.setAttribute("type", static_cast<int>( oIt.current()->getType() ));
02011         bool _sticky = ( this->m_masterPage == 0 );
02012         if (_sticky)
02013             object.setAttribute("sticky", static_cast<int>(_sticky));
02014         if ( saveOnlyPage != -1 )
02015             yoffset=0;
02016         //add yoffset to compatibility with koffice 1.1
02017         object.appendChild(oIt.current()->save( doc, yoffset ));
02018 
02019         objects.appendChild(object);
02020     }
02021     return objects;
02022 }
02023 
02024 bool KPrPage::oneObjectTextExist(bool forceAllTextObject)
02025 {
02026     QPtrList<KPrObject> lst;
02027     getAllObjectSelectedList(lst,forceAllTextObject );
02028     QPtrListIterator<KPrObject> it( lst );
02029     for ( ; it.current() ; ++it )
02030     {
02031         if ( (it.current() == m_doc->header() && !hasHeader())
02032              || (it.current() == m_doc->footer() && !hasFooter()) )
02033             continue;
02034         if (it.current()->getType()==OT_TEXT)
02035             return true;
02036     }
02037     return false;
02038 }
02039 
02040 bool KPrPage::oneObjectTextSelected()
02041 {
02042     return oneObjectTextExist(false);
02043 }
02044 
02045 
02046 bool KPrPage::isOneObjectSelected()
02047 {
02048     return 0 != getSelectedObj();
02049 }
02050 
02051 bool KPrPage::haveASelectedPartObj()
02052 {
02053     QPtrList<KPrObject> lst;
02054     getAllObjectSelectedList(lst );
02055     QPtrListIterator<KPrObject> it( lst );
02056     for ( ; it.current(); ++it ) {
02057         if (it.current()->getType() == OT_PART )
02058             return true;
02059     }
02060     return false;
02061 }
02062 
02063 bool KPrPage::haveASelectedGroupObj()
02064 {
02065     QPtrList<KPrObject> objects( getSelectedObjects( true ) );
02066     QPtrListIterator<KPrObject> it( objects );
02067     for ( ; it.current(); ++it ) {
02068         if ( it.current()->getType() == OT_GROUP )
02069             return true;
02070     }
02071     return false;
02072 }
02073 
02074 bool KPrPage::haveASelectedPixmapObj()
02075 {
02076     QPtrList<KPrObject> lst;
02077     getAllObjectSelectedList(lst );
02078     QPtrListIterator<KPrObject> it( lst );
02079     for ( ; it.current() ; ++it ) {
02080         if (( it.current()->getType() == OT_PICTURE )
02081             || ( it.current()->getType() == OT_CLIPART ) )
02082             return true;
02083     }
02084     return false;
02085 }
02086 
02087 KoRect KPrPage::getRealRect( bool all ) const
02088 {
02089     KoRect rect;
02090 
02091     QPtrListIterator<KPrObject> it( m_objectList );
02092     for ( ; it.current() ; ++it )
02093     {
02094         if ( it.current()== m_doc->header() || it.current()== m_doc->footer())
02095             continue;
02096 
02097         if ( all || ( it.current()->isSelected() && ! it.current()->isProtect() ) )
02098             rect |= it.current()->getRealRect();
02099     }
02100 
02101     return rect;
02102 }
02103 
02104 //return true if we change picture
02105 bool KPrPage::chPic( KPrView *_view)
02106 {
02107     QPtrListIterator<KPrObject> it( m_objectList );
02108     for ( ; it.current() ; ++it )
02109     {
02110         if ( it.current()->isSelected() &&
02111              ( ( it.current()->getType() == OT_PICTURE )
02112                || ( it.current()->getType() == OT_CLIPART ) ) )
02113         {
02114             KPrPixmapObject* obj=dynamic_cast<KPrPixmapObject*>( it.current() );
02115             if( obj)
02116             {
02117                 _view->changePicture( obj->getFileName() );
02118                 return true;
02119             }
02120         }
02121     }
02122     return false;
02123 }
02124 
02125 bool KPrPage::savePicture( KPrView *_view ) const
02126 {
02127     QPtrListIterator<KPrObject> it( m_objectList );
02128     for ( ; it.current() ; ++it )
02129     {
02130         if ( it.current()->isSelected() &&
02131              ( ( it.current()->getType() == OT_PICTURE )
02132                || ( it.current()->getType() == OT_CLIPART ) ) )
02133         {
02134             KPrPixmapObject* obj=dynamic_cast<KPrPixmapObject*>( it.current() );
02135             if( obj)
02136             {
02137                 _view->savePicture( obj );
02138                 return true;
02139             }
02140         }
02141     }
02142     return false;
02143 }
02144 
02145 // move object for releasemouseevent
02146 KCommand *KPrPage::moveObject(KPrView *_view, double diffx, double diffy)
02147 {
02148     bool createCommand=false;
02149     KPrMoveByCmd *moveByCmd=0L;
02150     QPtrList<KPrObject> _objects;
02151     _objects.setAutoDelete( false );
02152     QPtrListIterator<KPrObject> it( m_objectList );
02153     for ( ; it.current() ; ++it )
02154     {
02155         //don't move a header/footer
02156         if ( it.current() == m_doc->header() || it.current() == m_doc->footer())
02157             continue;
02158         if ( it.current()->isSelected() && !it.current()->isProtect())
02159         {
02160             _objects.append( it.current() );
02161             QRect br = _view->zoomHandler()->zoomRect( it.current()->getRepaintRect() );
02162             br.moveBy( _view->zoomHandler()->zoomItX( diffx ), _view->zoomHandler()->zoomItY( diffy ) );
02163             m_doc->repaint( br ); // Previous position
02164             m_doc->repaint( it.current() ); // New position
02165             createCommand=true;
02166         }
02167     }
02168     if(createCommand) {
02169         moveByCmd = new KPrMoveByCmd( i18n( "Move Objects" ), KoPoint( diffx, diffy ),
02170                                    _objects, m_doc,this );
02171 
02172         m_doc->updateSideBarItem( this );
02173     }
02174     return moveByCmd;
02175 }
02176 
02177 KCommand *KPrPage::moveObject(KPrView *m_view,const KoPoint &_move,bool key)
02178 {
02179     QPtrList<KPrObject> _objects;
02180     _objects.setAutoDelete( false );
02181     KPrMoveByCmd *moveByCmd=0L;
02182     QPtrListIterator<KPrObject> it( m_objectList );
02183     for ( ; it.current() ; ++it )
02184     {
02185         //don't move a header/footer
02186         if ( it.current()== m_doc->header() || it.current()== m_doc->footer())
02187             continue;
02188         if ( it.current()->isSelected() && !it.current()->isProtect()) {
02189 
02190             QRect oldBoundingRect = m_view->zoomHandler()->zoomRect( it.current()->getRepaintRect() );
02191 
02192             it.current()->moveBy( _move );
02193             _objects.append( it.current() );
02194             m_doc->repaint( oldBoundingRect );
02195             m_doc->repaint( it.current() );
02196         }
02197     }
02198 
02199     if ( key && !_objects.isEmpty())
02200         moveByCmd = new KPrMoveByCmd( i18n( "Move Objects" ),
02201                                    KoPoint( _move ),
02202                                    _objects, m_doc,this );
02203 
02204     return moveByCmd;
02205 }
02206 
02207 void KPrPage::repaintObj()
02208 {
02209     QPtrListIterator<KPrObject> it( m_objectList );
02210     for ( ; it.current() ; ++it )
02211     {
02212         if(it.current()->isSelected())
02213             m_doc->repaint(it.current() );
02214     }
02215 }
02216 
02217 KCommand *KPrPage::rotateSelectedObjects( float _newAngle, bool addAngle )
02218 {
02219     KPrRotateCmd * cmd = NULL;
02220 
02221     QPtrList<KPrObject> _objects;
02222     _objects.setAutoDelete( false );
02223 
02224     QPtrListIterator<KPrObject> it( m_objectList );
02225     for ( ; it.current() ; ++it )
02226     {
02227         if ( it.current()== m_doc->header() || it.current()== m_doc->footer() )
02228             continue;
02229         if( it.current()->isSelected() && !it.current()->isProtect())
02230         {
02231             _objects.append( it.current() );
02232         }
02233     }
02234 
02235     if ( !_objects.isEmpty() ) {
02236         cmd = new KPrRotateCmd( i18n( "Change Rotation" ), _newAngle, _objects, m_doc, addAngle );
02237         cmd->execute();
02238     }
02239 
02240     return cmd;
02241 }
02242 
02243 
02244 KCommand *KPrPage::shadowObj(ShadowDirection dir,int dist, const QColor &col)
02245 {
02246     KPrShadowCmd *shadowCmd=0L;
02247     bool newShadow=false;
02248     QPtrList<KPrObject> _objects;
02249     QPtrList<KPrShadowCmd::ShadowValues> _oldShadow;
02250     KPrShadowCmd::ShadowValues _newShadow, *tmp;
02251 
02252     _objects.setAutoDelete( false );
02253     _oldShadow.setAutoDelete( false );
02254 
02255     _newShadow.shadowDirection = dir;
02256     _newShadow.shadowDistance = dist;
02257     _newShadow.shadowColor = col;
02258 
02259     QPtrListIterator<KPrObject> it( m_objectList );
02260     for ( ; it.current() ; ++it )
02261     {
02262         //don't shadow a header/footer
02263         if ( it.current()== m_doc->header() || it.current()== m_doc->footer())
02264             continue;
02265 
02266         if ( it.current()->isSelected() ) {
02267             tmp = new KPrShadowCmd::ShadowValues;
02268             tmp->shadowDirection = it.current()->getShadowDirection();
02269             tmp->shadowDistance =it.current()->getShadowDistance();
02270             tmp->shadowColor = it.current()->getShadowColor();
02271 
02272             if(!newShadow &&( tmp->shadowDirection!=_newShadow.shadowDirection
02273                               || tmp->shadowDistance!=_newShadow.shadowDistance
02274                               || tmp->shadowColor!=_newShadow.shadowColor))
02275                 newShadow=true;
02276 
02277             _oldShadow.append( tmp );
02278             _objects.append( it.current() );
02279         }
02280     }
02281 
02282     if ( !_objects.isEmpty() && newShadow ) {
02283         shadowCmd = new KPrShadowCmd( i18n( "Change Shadow" ),
02284                                    _oldShadow, _newShadow, _objects, m_doc );
02285         shadowCmd->execute();
02286     }
02287     else
02288     {
02289         _oldShadow.setAutoDelete( true );
02290         _oldShadow.clear();
02291     }
02292     return shadowCmd;
02293 }
02294 
02295 QPtrList<KoTextObject> KPrPage::allTextObjects() const
02296 {
02297     QPtrList<KoTextObject> lst;
02298     addTextObjects( lst );
02299     return lst;
02300 }
02301 
02302 void KPrPage::addTextObjects(QPtrList<KoTextObject>& lst) const
02303 {
02304     QPtrListIterator<KPrObject> it( m_objectList );
02305     for ( ; it.current() ; ++it )
02306         it.current()->addTextObjects( lst );
02307 }
02308 
02309 KPrObject * KPrPage::getCursor( const QPoint &pos )
02310 {
02311     return getCursor( m_doc->zoomHandler()->unzoomPoint( pos ) );
02312 }
02313 
02314 KPrObject * KPrPage::getCursor(const KoPoint &pos )
02315 {
02316     QPtrListIterator<KPrObject> it( m_objectList );
02317     KPrObject *kpobject = it.toLast();
02318     while ( kpobject ) {
02319         if ( kpobject->contains( pos ) && kpobject->isSelected() )
02320             return kpobject;
02321         kpobject = --it;
02322     }
02323     return 0L;
02324 }
02325 
02326 KPrObject* KPrPage::getObjectAt( const KoPoint &pos, bool withoutProtected ) const
02327 {
02328     QPtrListIterator<KPrObject> it( m_objectList );
02329     KPrObject *o = 0;
02330     //tz Check first if there is a selected object at this pos!
02331     for ( int i = 0; i < 2; ++i )
02332     {
02333         o = it.toLast();
02334         while ( o ) {
02335             if ( o != m_doc->footer() || 
02336                  o != m_doc->header() || 
02337                  ( m_bHasFooter && o == m_doc->footer() ) || 
02338                  ( m_bHasHeader && o == m_doc->header() ) )
02339             {
02340                 if ( ( o->isSelected() || i > 0 ) && 
02341                        o->contains( pos ) && !( o->isProtect() && withoutProtected ) )
02342                     return o;
02343             }
02344             o = --it;
02345         }
02346     }
02347     return 0L;
02348 }
02349 
02350 KPrPixmapObject * KPrPage::picViewOrigHelper() const
02351 {
02352     KPrPixmapObject *obj=0L;
02353     QPtrListIterator<KPrObject> it( m_objectList );
02354     for ( ; it.current() ; ++it )
02355     {
02356         if ( it.current()->isSelected() &&
02357              ( ( it.current()->getType() == OT_PICTURE )
02358                || ( it.current()->getType() == OT_CLIPART ) ) )
02359         {
02360             obj=(KPrPixmapObject*)it.current();
02361             break;
02362         }
02363     }
02364     return obj;
02365 }
02366 
02367 void KPrPage::applyStyleChange( KoStyleChangeDefMap changed )
02368 {
02369     QPtrList<KPrObject> lst;
02370     getAllObjectSelectedList(lst,true /*force*/ );
02371     QPtrListIterator<KPrObject> it( lst );
02372 
02373     for ( ; it.current() ; ++it )
02374     {
02375         KPrTextObject *obj=dynamic_cast<KPrTextObject*>(it.current());
02376         if( obj)
02377             obj->applyStyleChange( changed );
02378     }
02379 }
02380 
02381 void KPrPage::reactivateBgSpellChecking(bool refreshTextObj)
02382 {
02383     QPtrList<KPrObject> lst;
02384     getAllObjectSelectedList(lst,true /*force*/ );
02385     QPtrListIterator<KPrObject> oIt( lst );
02386 
02387     for ( ; oIt.current() ; ++oIt )
02388     {
02389         if(oIt.current()->getType()==OT_TEXT)
02390         {
02391             static_cast<KPrTextObject*>( oIt.current() )->textObject()->setNeedSpellCheck(true);
02392             if(refreshTextObj)
02393                 m_doc->repaint( oIt.current() );
02394         }
02395     }
02396 }
02397 
02398 bool KPrPage::canMoveOneObject() const
02399 {
02400     QPtrListIterator<KPrObject> it( m_objectList );
02401     for ( ; it.current() ; ++it )
02402     {
02403         //don't test header/footer all the time sticky
02404         if ( it.current()== m_doc->header() || it.current()== m_doc->footer())
02405             continue;
02406         if(it.current()->isSelected()&& !it.current()->isProtect())
02407             return true;
02408     }
02409     return false;
02410 }
02411 
02412 KCommand *KPrPage::alignVertical( VerticalAlignmentType _type )
02413 {
02414     KMacroCommand *macro = 0L;
02415     QPtrList<KPrObject> lst;
02416     getAllObjectSelectedList(lst );
02417     QPtrListIterator<KPrObject> it( lst );
02418     for ( ; it.current() ; ++it )
02419     {
02420         if(it.current()->getType()==OT_TEXT)
02421         {
02422             KPrTextObject *obj = dynamic_cast<KPrTextObject *>(it.current());
02423             if ( obj  && !obj->isProtectContent())
02424             {
02425                 KPrChangeVerticalAlignmentCommand * cmd = new KPrChangeVerticalAlignmentCommand( i18n("Change Vertical Alignment"),
02426                                                                                                  obj, obj->verticalAlignment(),_type, m_doc);
02427                 if ( !macro )
02428                     macro = new KMacroCommand( i18n("Change Vertical Alignment"));
02429                 macro->addCommand( cmd );
02430                 cmd->execute();
02431             }
02432         }
02433     }
02434     return macro;
02435 }
02436 
02437 void KPrPage::changeTabStopValue ( double _tabStop )
02438 {
02439     QPtrList<KPrObject> lst;
02440     getAllObjectSelectedList(lst,true /*force*/ );
02441     QPtrListIterator<KPrObject> it( lst );
02442     for ( ; it.current() ; ++it )
02443     {
02444         if(it.current()->getType()==OT_TEXT)
02445         {
02446             KPrTextObject *obj = dynamic_cast<KPrTextObject *>(it.current());
02447             if ( obj )
02448             {
02449                 obj->textDocument()->setTabStops( m_doc->zoomHandler()->ptToLayoutUnitPixX( _tabStop ));
02450                 obj->layout();
02451                 m_doc->repaint( obj );
02452             }
02453         }
02454     }
02455 }
02456 
02457 KPrObject *KPrPage::nextTextObject(KPrTextObject *obj)
02458 {
02459     if ( m_objectList.count()==0 )
02460         return 0L;
02461     int pos = -1;
02462     if ( obj )
02463         pos = m_objectList.findNextRef(obj);
02464 
02465     if (pos != -1 )
02466     {
02467         KPrObject *frm=0L;
02468         for ( frm=m_objectList.at(pos); frm != 0; frm=m_objectList.next() )
02469         {
02470             KPrTextObject *newObj = frm->nextTextObject();
02471             if(newObj && newObj->nextTextObject()->textObject()->needSpellCheck())
02472                 return frm;
02473         }
02474     }
02475     else
02476     {
02477         KPrObject *frm=0L;
02478         for ( frm=m_objectList.at(0); frm != 0; frm=m_objectList.next() )
02479         {
02480             KPrTextObject *newObj = frm->nextTextObject();
02481             if(newObj && newObj->nextTextObject()->textObject()->needSpellCheck())
02482                 return frm;
02483         }
02484     }
02485     return 0L;
02486 }
02487 
02488 bool KPrPage::findTextObject( KPrObject *obj )
02489 {
02490     return (m_objectList.findRef( obj )>=0 );
02491 }
02492 
02493 void KPrPage::getAllObjectSelectedList(QPtrList<KPrObject> &lst, bool force )
02494 {
02495     QPtrListIterator<KPrObject> it( m_objectList );
02496     for ( ; it.current() ; ++it )
02497         it.current()->getAllObjectSelectedList( lst,force );
02498 }
02499 
02500 void KPrPage::getAllEmbeddedObjectSelected(QPtrList<KoDocumentChild> &embeddedObjects )
02501 {
02502     QPtrListIterator<KPrObject> it( m_objectList );
02503     for ( ; it.current() ; ++it )
02504     {
02505         if ( it.current()->isSelected() && it.current()->getType() == OT_PART )
02506             embeddedObjects.append( static_cast<KPrPartObject *>(it.current())->getChild() );
02507     }
02508 }
02509 
02510 KPrPixmapObject* KPrPage::getSelectedImage() const
02511 {
02512     KPrPixmapObject *obj=0L;
02513     QPtrListIterator<KPrObject> it( m_objectList );
02514     for ( ; it.current() ; ++it )
02515     {
02516         if ( it.current()->isSelected() && it.current()->getType() == OT_PICTURE )
02517         {
02518             obj=dynamic_cast<KPrPixmapObject*>(it.current());
02519             break;
02520         }
02521     }
02522     return obj;
02523 }
02524 
02525 KCommand * KPrPage::setImageEffect(ImageEffect eff, QVariant param1, QVariant param2, QVariant param3)
02526 {
02527     bool changed = false;
02528     KPrImageEffectCmd *imageEffectCmd = 0L;
02529     QPtrList<KPrObject> _objects;
02530     QPtrList<KPrImageEffectCmd::ImageEffectSettings> _oldSettings;
02531     KPrImageEffectCmd::ImageEffectSettings _newSettings, *tmp;
02532 
02533     _objects.setAutoDelete( false );
02534     _oldSettings.setAutoDelete( false );
02535 
02536     _newSettings.effect = eff;
02537     _newSettings.param1 = param1;
02538     _newSettings.param2 = param2;
02539     _newSettings.param3 = param3;
02540 
02541     QPtrListIterator<KPrObject> it( m_objectList );
02542     for ( ; it.current(); ++it ) {
02543         if ( it.current()->getType() == OT_PICTURE && it.current()->isSelected()) {
02544             tmp = new KPrImageEffectCmd::ImageEffectSettings;
02545             tmp->effect = static_cast<KPrPixmapObject*>(it.current())->getImageEffect();
02546             tmp->param1 = static_cast<KPrPixmapObject*>(it.current())->getIEParam1();
02547             tmp->param2 = static_cast<KPrPixmapObject*>(it.current())->getIEParam2();
02548             tmp->param3 = static_cast<KPrPixmapObject*>(it.current())->getIEParam3();
02549             _oldSettings.append( tmp );
02550             _objects.append( it.current() );
02551 
02552             if( !changed && ( tmp->effect != _newSettings.effect
02553                               || tmp->param1 != _newSettings.param1
02554                               || tmp->param2 != _newSettings.param2
02555                               || tmp->param3 != _newSettings.param3 ) )
02556                 changed = true;
02557         }
02558     }
02559 
02560     if ( !_objects.isEmpty() && changed ) {
02561         imageEffectCmd = new KPrImageEffectCmd( i18n( "Change Image Effect" ), _oldSettings, _newSettings,
02562                                              _objects, m_doc );
02563         imageEffectCmd->execute();
02564     }
02565     else {
02566         _oldSettings.setAutoDelete( true );
02567         _oldSettings.clear();
02568     }
02569 
02570     m_doc->setModified( true );
02571 
02572     return imageEffectCmd;
02573 }
02574 
02575 void KPrPage::setHeader( bool b, bool _updateDoc )
02576 {
02577     m_bHasHeader = b;
02578     if ( _updateDoc )
02579         m_doc->setHeader(b);
02580 }
02581 
02582 void KPrPage::setFooter( bool b, bool _updateDoc )
02583 {
02584     m_bHasFooter = b;
02585     if ( _updateDoc )
02586         m_doc->setFooter( b );
02587 }
02588 
02589 void KPrPage::setUseMasterBackground( bool useMasterBackground )
02590 {
02591     m_useMasterBackground = useMasterBackground;
02592 }
02593 
02594 bool KPrPage::useMasterBackground() const
02595 {
02596     return m_useMasterBackground;
02597 }
02598 
02599 bool KPrPage::isMasterPage() const
02600 {
02601     return ( m_masterPage==0 );
02602 }
02603 
02604 void KPrPage::setDisplayObjectFromMasterPage( bool _b )
02605 {
02606     m_displayObjectFromMasterPage = _b;
02607     m_doc->setDisplayObjectMasterPage( _b );
02608 }
02609 
02610 void KPrPage::setDisplayBackground( bool _b )
02611 {
02612     m_displayBackground = _b;
02613     m_doc->setDisplayBackground( _b );
02614 }
02615 
02616 
KDE Home | KDE Accessibility Home | Description of Access Keys