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