kpresenter

KPrDocument.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
00003    Copyright (C) 2005-2006 Thorsten Zachmann <zachmann@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "KPrDocument.h"
00022 #include "KPrView.h"
00023 #include "KPrCanvas.h"
00024 #include "KPrPage.h"
00025 #include "KPrObject.h"
00026 #include "KPrLineObject.h"
00027 #include "KPrRectObject.h"
00028 #include "KPrEllipseObject.h"
00029 #include "KPrAutoformObject.h"
00030 #include "KPrTextObject.h"
00031 #include "KPrTextDocument.h"
00032 #include "KPrPixmapObject.h"
00033 #include "KPrPieObject.h"
00034 #include "KPrPartObject.h"
00035 #include "KPrGroupObject.h"
00036 #include "KPrCommand.h"
00037 #include "insertpagedia.h"
00038 #include "KPrFreehandObject.h"
00039 #include "KPrPolylineObject.h"
00040 #include "KPrBezierCurveObject.h"
00041 #include "KPrPolygonObject.h"
00042 #include "KPrClosedLineObject.h"
00043 #include "KPrSVGPathParser.h"
00044 
00045 #include <qpopupmenu.h>
00046 #include <qclipboard.h>
00047 #include <qregexp.h>
00048 #include <qfileinfo.h>
00049 #include <qdom.h>
00050 #include <qdict.h>
00051 
00052 #include <KoDom.h>
00053 #include <KoXmlNS.h>
00054 
00055 #include <kurl.h>
00056 #include <kdebug.h>
00057 #include <KoGlobal.h>
00058 #include <kapplication.h>
00059 #include <kurldrag.h>
00060 #include <ktempfile.h>
00061 #include <klocale.h>
00062 #include <kfiledialog.h>
00063 #include <kglobal.h>
00064 #include <kstandarddirs.h>
00065 #include <kmessagebox.h>
00066 #include <kprocess.h>
00067 #include <kio/netaccess.h>
00068 
00069 #include <KoTemplateChooseDia.h>
00070 #include <KoRuler.h>
00071 #include <KoGenStyles.h>
00072 #include <KoFilterManager.h>
00073 #include <KoStore.h>
00074 #include <KoStoreDevice.h>
00075 #include <KoQueryTrader.h>
00076 #include <KoXmlWriter.h>
00077 #include <KoOasisSettings.h>
00078 #include <KoMainWindow.h>
00079 
00080 #include <stdlib.h>
00081 #include <stdio.h>
00082 #include <math.h>
00083 #include <unistd.h>
00084 #include <config.h>
00085 
00086 #include <KoRichText.h>
00087 #include <KoTextObject.h>
00088 #include <KoTextZoomHandler.h>
00089 #include <KoStyleCollection.h>
00090 #include <kcommand.h>
00091 #include "KPrDocumentIface.h"
00092 
00093 #include <kspell2/settings.h>
00094 
00095 #include <KoVariable.h>
00096 #include <KoAutoFormat.h>
00097 #include <KoDocumentInfo.h>
00098 #include "KPrVariableCollection.h"
00099 #include "KPrBackground.h"
00100 #include "KPrNoteBar.h"
00101 #include "KPrBgSpellCheck.h"
00102 #include <kglobalsettings.h>
00103 #include <KoCommandHistory.h>
00104 #include "KoApplication.h"
00105 #include <KoOasisStyles.h>
00106 #include <KoOasisContext.h>
00107 
00108 #include "KPrLoadingInfo.h"
00109 
00110 using namespace std;
00111 
00112 static const int CURRENT_SYNTAX_VERSION = 2;
00113 // Make sure an appropriate DTD is available in www/koffice/DTD if changing this value
00114 static const char * CURRENT_DTD_VERSION = "1.2";
00115 
00116 KPrChild::KPrChild( KPrDocument *_kpr, KoDocument* _doc, const QRect& _rect )
00117     : KoDocumentChild( _kpr, _doc, _rect )
00118 {
00119     m_parent = _kpr;
00120 }
00121 
00122 KPrChild::KPrChild( KPrDocument *_kpr ) :
00123     KoDocumentChild( _kpr )
00124 {
00125     m_parent = _kpr;
00126 }
00127 
00128 KPrChild::~KPrChild()
00129 {
00130 }
00131 
00132 KoDocument *KPrChild::hitTest( const QPoint &, const QWMatrix & )
00133 {
00134     return 0L;
00135 }
00136 
00137 KPrDocument::KPrDocument( QWidget *parentWidget, const char *widgetName, QObject* parent, const char* name,
00138                               bool singleViewMode )
00139     : KoDocument( parentWidget,widgetName, parent, name, singleViewMode ),
00140       _gradientCollection(), m_customListTest( 0L ),
00141       m_childCountBeforeInsert( 0 )
00142 {
00143     setInstance( KPrFactory::global() );
00144     setTemplateType( "kpresenter_template" );
00145     //Necessary to define page where we load object otherwise copy-duplicate page doesn't work.
00146     m_pageWhereLoadObject=0L;
00147     m_loadingInfo=0L;
00148     m_tabStop = MM_TO_POINT( 15.0 );
00149     m_styleColl=new KoStyleCollection();
00150     m_insertFilePage = 0;
00151     m_picturePath= KGlobalSettings::documentPath();
00152     m_globalLanguage = KGlobal::locale()->language();
00153     m_bGlobalHyphenation = false;
00154     _duplicatePage=false;
00155 
00156     KoParagStyle* m_standardStyle = new KoParagStyle( "Standard" );
00157     m_styleColl->addStyle( m_standardStyle );
00158 
00159     KConfig *config = KPrFactory::global()->config();
00160     config->setGroup("Document defaults" );
00161     QString defaultFontname=config->readEntry("DefaultFont");
00162     if ( !defaultFontname.isEmpty() )
00163         m_defaultFont.fromString( defaultFontname );
00164     // If not found, we automatically fallback to the application font (the one from KControl's font module)
00165 
00166     // Try to force a scalable font.
00167     m_defaultFont.setStyleStrategy( QFont::ForceOutline );
00168     //kdDebug(33001) << "Default font: requested family: " << m_defaultFont.family() << endl;
00169     //kdDebug(33001) << "Default font: real family: " << QFontInfo(m_defaultFont).family() << endl;
00170 
00171     int ptSize = m_defaultFont.pointSize();
00172     if ( ptSize == -1 ) // specified with a pixel size ?
00173         ptSize = QFontInfo(m_defaultFont).pointSize();
00174     //kdDebug(33001) << "KPrDocument::KPrDocument[2] ptSize=" << ptSize << endl;
00175     // Ok, this is KPresenter. A default font of 10 makes no sense. Let's go for 20.
00176     ptSize = QMAX( 20, ptSize );
00177 
00178     m_standardStyle->format().setFont( m_defaultFont );
00179 
00181     m_standardStyle->format().setColor( Qt::black );
00182 
00183     if( config->hasGroup("Interface") ) {
00184         config->setGroup( "Interface" );
00185         m_globalLanguage=config->readEntry("language", KGlobal::locale()->language());
00186         m_bGlobalHyphenation=config->readBoolEntry("hyphenation", false);
00187     }
00188 
00189     m_standardStyle->format().setLanguage( m_globalLanguage);
00190 
00191     m_zoomHandler = new KoTextZoomHandler;
00192 
00193     m_varFormatCollection = new KoVariableFormatCollection;
00194     m_varColl = new KPrVariableCollection( new KoVariableSettings(), m_varFormatCollection );
00195     m_bgSpellCheck = new KPrBgSpellCheck(this);
00196     dcop = 0;
00197     m_initialActivePage=0;
00198     m_bShowStatusBar = true;
00199     m_autoFormat = new KoAutoFormat(this,m_varColl,m_varFormatCollection);
00200     _clean = true;
00201     _spInfiniteLoop = false;
00202     _spManualSwitch = true;
00203     _showPresentationDuration = false;
00204     tmpSoundFileList = QPtrList<KTempFile>();
00205     _xRnd = 20;
00206     _yRnd = 20;
00207     _txtBackCol = lightGray;
00208     _otxtBackCol = lightGray;
00209 
00210     m_bShowRuler=true;
00211     m_bAllowAutoFormat = true;
00212 
00213     m_bViewFormattingChars = false;
00214     m_bShowGuideLines = true;
00215 
00216     m_bShowGrid = true;
00217 
00218     m_bSnapToGrid = true;
00219 
00220     m_cursorInProtectectedArea=true;
00221 
00222     usedSoundFile = QStringList();
00223     haveNotOwnDiskSoundFile = QStringList();
00224 
00225     m_zoomHandler->setZoomAndResolution( 100, KoGlobal::dpiX(), KoGlobal::dpiY() );
00226     newZoomAndResolution(false,false);
00227 
00228     //   _pageLayout.format = PG_SCREEN;
00229     //   _pageLayout.orientation = PG_PORTRAIT;
00230     //   _pageLayout.width = PG_SCREEN_WIDTH;
00231     //   _pageLayout.height = PG_SCREEN_HEIGHT;
00232     //   _pageLayout.left = 0;
00233     //   _pageLayout.right = 0;
00234     //   _pageLayout.top = 0;
00235     //   _pageLayout.bottom = 0;
00236     //   _pageLayout.ptWidth = cMM_TO_POINT( PG_SCREEN_WIDTH );
00237     //   _pageLayout.ptHeight = cMM_TO_POINT( PG_SCREEN_HEIGHT );
00238     //   _pageLayout.ptLeft = 0;
00239     //   _pageLayout.ptRight = 0;
00240     //   _pageLayout.ptTop = 0;
00241     //   _pageLayout.ptBottom = 0;
00242 
00243     m_indent = MM_TO_POINT( 10.0 );
00244     m_gridX = MM_TO_POINT( 5.0 );
00245     m_gridY = MM_TO_POINT( 5.0 );
00246 
00247     oldGridX = m_gridX;
00248     oldGridY = m_gridY;
00249 
00250     m_masterPage=new KPrPage(this);
00251     KPrPage *newpage = new KPrPage( this, m_masterPage );
00252     m_pageList.insert( 0,newpage);
00253     m_bInsertDirectCursor = false;
00254 
00255     objStartY = 0;
00256     _presPen = QPen( red, 3, SolidLine );
00257     ignoreSticky = TRUE;
00258 
00259     m_gridColor=Qt::black;
00260 
00261     _header = new KPrTextObject( this );
00262     _header->setDrawEditRect( false );
00263     _header->setDrawEmpty( false );
00264 
00265     _footer = new KPrTextObject( this );
00266     _footer->setDrawEditRect( false );
00267     _footer->setDrawEmpty( false );
00268 
00269     saveOnlyPage = -1;
00270     m_maxRecentFiles = 10;
00271 
00272     connect( QApplication::clipboard(), SIGNAL( dataChanged() ),
00273              this, SLOT( clipboardDataChanged() ) );
00274 
00275     m_commandHistory = new KoCommandHistory( actionCollection(),  true ) ;
00276     initConfig();
00277 
00278     connect( m_commandHistory, SIGNAL( documentRestored() ), this, SLOT( slotDocumentRestored() ) );
00279     connect( m_commandHistory, SIGNAL( commandExecuted() ), this, SLOT( slotCommandExecuted() ) );
00280 
00281     dcopObject();
00282 }
00283 
00284 void KPrDocument::refreshMenuCustomVariable()
00285 {
00286     emit sig_refreshMenuCustomVariable();
00287 }
00288 
00289 void KPrDocument::slotDocumentRestored()
00290 {
00291     setModified( false );
00292 }
00293 
00294 void KPrDocument::slotCommandExecuted()
00295 {
00296     setModified( true );
00297 }
00298 
00299 void KPrDocument::saveConfig()
00300 {
00301     if ( !isReadWrite())
00302         return;
00303     KConfigGroup group( KoGlobal::kofficeConfig(), "Spelling" );
00304     group.writeEntry( "PersonalDict", m_spellCheckPersonalDict );
00305     if ( !isEmbedded() )
00306     {
00307         KConfig *config = KPrFactory::global()->config();
00308         config->setGroup( "Interface" );
00309         config->writeEntry( "Zoom", m_zoomHandler->zoom() );
00310         config->writeEntry( "AllowAutoFormat" , m_bAllowAutoFormat );
00311         config->writeEntry( "ViewFormattingChars", m_bViewFormattingChars );
00312         config->writeEntry( "ShowGrid" , m_bShowGrid );
00313         config->writeEntry( "SnapToGrid" , m_bSnapToGrid );
00314         config->writeEntry( "ResolutionX", m_gridX );
00315         config->writeEntry( "ResolutionY", m_gridY );
00316     }
00317 }
00318 
00319 void KPrDocument::initConfig()
00320 {
00321     int zoom;
00322     KConfig* config = KPrFactory::global()->config();
00323     if( config->hasGroup("Interface") ) {
00324         config->setGroup( "Interface" );
00325         setAutoSave( config->readNumEntry( "AutoSave", defaultAutoSave()/60 ) * 60 );
00326         setBackupFile( config->readBoolEntry("BackupFile", true));
00327         setCursorInProtectedArea( config->readBoolEntry( "cursorInProtectArea", true ));
00328 
00329         // Config-file value in mm, default 10 pt
00330         double indent =  config->readDoubleNumEntry("Indent", MM_TO_POINT(10.0) ) ;
00331         setIndentValue(indent);
00332         m_maxRecentFiles = config->readNumEntry( "NbRecentFile", 10 );
00333         setShowRuler(config->readBoolEntry("Rulers",true));
00334         zoom = config->readNumEntry( "Zoom", 100 );
00335         setShowStatusBar( config->readBoolEntry( "ShowStatusBar" , true ));
00336         setAllowAutoFormat( config->readBoolEntry( "AllowAutoFormat" , true ));
00337         setViewFormattingChars( config->readBoolEntry( "ViewFormattingChars", false ) );
00338         setShowGrid( config->readBoolEntry( "ShowGrid" , true ));
00339         setSnapToGrid( config->readBoolEntry( "SnapToGrid", true ));
00340         setGridX( config->readDoubleNumEntry( "ResolutionX", MM_TO_POINT( 5.0 ) ));
00341         setGridY( config->readDoubleNumEntry( "ResolutionY", MM_TO_POINT( 5.0 ) ));
00342 
00343         m_bInsertDirectCursor= config->readBoolEntry( "InsertDirectCursor", false );
00344         m_globalLanguage=config->readEntry("language", KGlobal::locale()->language());
00345 
00346     }
00347     else
00348         zoom=100;
00349 
00350     QColor oldBgColor = Qt::white;
00351     QColor oldGridColor = Qt::black;
00352     if ( config->hasGroup( "KPresenter Color" ) ) {
00353         config->setGroup( "KPresenter Color" );
00354         setTxtBackCol(config->readColorEntry( "BackgroundColor", &oldBgColor ));
00355         setGridColor(config->readColorEntry( "GridColor", &oldGridColor ));
00356     }
00357 
00358 
00359     if( config->hasGroup("KSpell kpresenter" ) )
00360     {
00361         config->setGroup( "KSpell kpresenter" );
00362 
00363        // Default is false for spellcheck, but the spell-check config dialog
00364        // should write out "true" when the user configures spell checking.
00365         if ( isReadWrite() )
00366           m_bgSpellCheck->setEnabled(config->readBoolEntry( "SpellCheck", false ));
00367        else
00368           m_bgSpellCheck->setEnabled( false );
00369     }
00370     int undo=30;
00371     if(config->hasGroup("Misc" ) )
00372     {
00373         config->setGroup( "Misc" );
00374         undo=config->readNumEntry("UndoRedo",-1);
00375     }
00376     if(undo!=-1)
00377         setUndoRedoLimit(undo);
00378 
00379     if(config->hasGroup("Kpresenter Path" ) )
00380     {
00381         config->setGroup( "Kpresenter Path" );
00382         m_picturePath=config->readPathEntry( "picture path",KGlobalSettings::documentPath());
00383         setBackupPath(config->readPathEntry( "backup path" ));
00384     }
00385 
00386     // Load personal dict
00387     KConfigGroup group( KoGlobal::kofficeConfig(), "Spelling" );
00388     m_spellCheckPersonalDict = group.readListEntry( "PersonalDict" );
00389 
00390     // Apply configuration, without creating an undo/redo command
00391     replaceObjs( false );
00392     zoomHandler()->setZoom( zoom );
00393     newZoomAndResolution(false,false);
00394 }
00395 
00396 DCOPObject* KPrDocument::dcopObject()
00397 {
00398     if ( !dcop )
00399         dcop = new KPrDocumentIface( this );
00400 
00401     return dcop;
00402 }
00403 
00404 KPrDocument::~KPrDocument()
00405 {
00406     if(isReadWrite())
00407         saveConfig();
00408     clearTestCustomSlideShow();
00409     //Be carefull !!!!!! don't delete this pointer delete in stickypage
00410 #if 0
00411     delete _header;
00412     delete _footer;
00413 #endif
00414 
00415     delete m_commandHistory;
00416     delete m_zoomHandler;
00417     delete m_autoFormat;
00418     delete m_varColl;
00419     delete m_varFormatCollection;
00420     delete dcop;
00421     delete m_masterPage;
00422     delete m_bgSpellCheck;
00423     delete m_styleColl;
00424 
00425     m_pageList.setAutoDelete( true );
00426     m_pageList.clear();
00427     m_deletedPageList.setAutoDelete( true );
00428     m_deletedPageList.clear();
00429     tmpSoundFileList.setAutoDelete( true );
00430     tmpSoundFileList.clear();
00431 }
00432 
00433 void KPrDocument::addCommand( KCommand * cmd )
00434 {
00435     kdDebug(33001) << "KPrDocument::addCommand " << cmd->name() << endl;
00436     m_commandHistory->addCommand( cmd, false );
00437     setModified( true );
00438 }
00439 
00440 bool KPrDocument::saveChildren( KoStore* _store )
00441 {
00442     int i = 0;
00443 
00444     QPtrListIterator<KoDocumentChild> it( children() );
00445     for( ; it.current(); ++it ) {
00446         // Don't save children that are only in the undo/redo history
00447         // but not anymore in the presentation
00448         QPtrListIterator<KPrPage> pageIt( m_pageList );
00449         for ( int pagePos = 0; pageIt.current(); ++pageIt, ++pagePos )
00450         {
00451             if ( saveOnlyPage == -1 || pagePos == saveOnlyPage )
00452             {
00453                 QPtrListIterator<KPrObject> oIt(pageIt.current()->objectList());
00454                 for (; oIt.current(); ++oIt )
00455                 {
00456                     if ( oIt.current()->getType() == OT_PART &&
00457                          dynamic_cast<KPrPartObject*>( oIt.current() )->getChild() == it.current() )
00458                     {
00459                         if (((KoDocumentChild*)(it.current()))->document()!=0)
00460                             if ( !((KoDocumentChild*)(it.current()))->document()->saveToStore( _store, QString::number( i++ ) ) )
00461                                 return false;
00462                     }
00463                 }
00464             }
00465         }
00466         if ( saveOnlyPage == -1 )
00467         {
00468             QPtrListIterator<KPrObject> oIt(m_masterPage->objectList());
00469             for (; oIt.current(); ++oIt )
00470             {
00471                 if ( oIt.current()->getType() == OT_PART &&
00472                         dynamic_cast<KPrPartObject*>( oIt.current() )->getChild() == it.current() )
00473                 {
00474                     if (((KoDocumentChild*)(it.current()))->document()!=0)
00475                         if ( !((KoDocumentChild*)(it.current()))->document()->saveToStore( _store, QString::number( i++ ) ) )
00476                             return false;
00477                 }
00478             }
00479         }
00480     }
00481     return true;
00482 }
00483 
00484 QDomDocument KPrDocument::saveXML()
00485 {
00486     if ( saveOnlyPage == -1 ) {
00487         emit sigProgress( 0 );
00488     }
00489 
00490     m_varColl->variableSetting()->setModificationDate(QDateTime::currentDateTime());
00491     recalcVariables( VT_DATE );
00492     recalcVariables( VT_TIME );
00493     recalcVariables( VT_STATISTIC );
00494     QDomDocument doc = createDomDocument( "DOC", CURRENT_DTD_VERSION );
00495     QDomElement presenter=doc.documentElement();
00496     presenter.setAttribute("editor", "KPresenter");
00497     presenter.setAttribute("mime", "application/x-kpresenter");
00498     presenter.setAttribute("syntaxVersion", CURRENT_SYNTAX_VERSION);
00499     QDomElement paper=doc.createElement("PAPER");
00500     paper.setAttribute("format", static_cast<int>( m_pageLayout.format ));
00501     paper.setAttribute("ptWidth", QString::number( m_pageLayout.ptWidth, 'g', 10 ));
00502     paper.setAttribute("ptHeight", QString::number( m_pageLayout.ptHeight, 'g', 10 ));
00503 
00504     paper.setAttribute("orientation", static_cast<int>( m_pageLayout.orientation ));
00505     paper.setAttribute("unit", unit() );
00506     paper.setAttribute("tabStopValue", m_tabStop );
00507 
00508     QDomElement paperBorders=doc.createElement("PAPERBORDERS");
00509 
00510     paperBorders.setAttribute("ptLeft", m_pageLayout.ptLeft);
00511     paperBorders.setAttribute("ptTop", m_pageLayout.ptTop);
00512     paperBorders.setAttribute("ptRight", m_pageLayout.ptRight);
00513     paperBorders.setAttribute("ptBottom", m_pageLayout.ptBottom);
00514     paper.appendChild(paperBorders);
00515     presenter.appendChild(paper);
00516 
00517     m_varColl->variableSetting()->save(presenter );
00518 
00519     presenter.appendChild(saveAttribute( doc ));
00520 
00521     if ( saveOnlyPage == -1 )
00522         emit sigProgress( 5 );
00523 
00524     QDomElement element=doc.createElement("BACKGROUND");
00525     element.appendChild(saveBackground( doc ));
00526     presenter.appendChild(element);
00527 
00528     if ( saveOnlyPage == -1 )
00529         emit sigProgress( 10 );
00530 
00531     //TODO save correct page info for header/footer
00532     element=doc.createElement("HEADER");
00533     element.setAttribute("show", static_cast<int>( m_pageList.at(0)->hasHeader() ));
00534     element.appendChild(_header->save( doc,0 ));
00535     presenter.appendChild(element);
00536 
00537     element=doc.createElement("FOOTER");
00538     element.setAttribute("show", static_cast<int>( m_pageList.at(0)->hasFooter() ));
00539     element.appendChild(_footer->save( doc,0 ));
00540     presenter.appendChild(element);
00541 
00542     element = doc.createElement( "HEADERFOOTERBYPAGE" );
00543     element.setAttribute( "value", "true" );
00544     presenter.appendChild( element );
00545 
00546     element=doc.createElement("HELPLINES");
00547     element.setAttribute("show", static_cast<int>( showGuideLines() ));
00548     saveGuideLines( doc, element );
00549     presenter.appendChild(element);
00550 
00551     if ( saveOnlyPage == -1 )
00552     {
00553         if( !m_spellCheckIgnoreList.isEmpty() )
00554         {
00555             QDomElement spellCheckIgnore = doc.createElement( "SPELLCHECKIGNORELIST" );
00556             presenter.appendChild( spellCheckIgnore );
00557             for ( QStringList::Iterator it = m_spellCheckIgnoreList.begin(); it != m_spellCheckIgnoreList.end(); ++it )
00558             {
00559                 QDomElement spellElem = doc.createElement( "SPELLCHECKIGNOREWORD" );
00560                 spellCheckIgnore.appendChild( spellElem );
00561                 spellElem.setAttribute( "word", *it );
00562             }
00563         }
00564     }
00565 
00566     if ( saveOnlyPage == -1 )
00567         emit sigProgress( 20 );
00568 
00569     presenter.appendChild(saveTitle( doc ));
00570 
00571     presenter.appendChild(saveNote( doc ));
00572 
00573     if ( saveOnlyPage == -1 )
00574         emit sigProgress( 30 );
00575 
00576     presenter.appendChild(saveObjects(doc));
00577 
00578     // ### If we will create a new version of the file format, fix that spelling error
00579     element=doc.createElement("INFINITLOOP");
00580     element.setAttribute("value", _spInfiniteLoop);
00581     presenter.appendChild(element);
00582     element=doc.createElement("MANUALSWITCH");
00583     element.setAttribute("value", _spManualSwitch);
00584     presenter.appendChild(element);
00585     element=doc.createElement("PRESSPEED");
00586 //TODO FIXME !!!!!!!!!!
00587 //element.setAttribute("value", static_cast<int>( presSpeed ));
00588     presenter.appendChild(element);
00589     element=doc.createElement("SHOWPRESENTATIONDURATION");
00590     element.setAttribute("value", _showPresentationDuration);
00591     presenter.appendChild(element);
00592 
00593     if ( saveOnlyPage == -1 )
00594     {
00595         if ( !m_customListSlideShow.isEmpty() )
00596         {
00597             QMap<KPrPage *, QString> page2name;
00598             int pos = 1;
00599             for ( QPtrListIterator<KPrPage> it( m_pageList ); it.current(); ++it )
00600             {
00601                 page2name.insert( it.current(), "page" + QString::number( pos++ ) ) ;
00602             }
00603 
00604             element = doc.createElement( "CUSTOMSLIDESHOWCONFIG" );
00605             CustomSlideShowMap::Iterator it;
00606             for ( it = m_customListSlideShow.begin(); it != m_customListSlideShow.end(); ++it )
00607             {
00608                 QDomElement slide=doc.createElement("CUSTOMSLIDESHOW");
00609                 slide.setAttribute("name", it.key() );
00610                 QString tmp;
00611                 QValueListIterator<KPrPage*> itPage ;
00612                 for( itPage = ( *it ).begin(); itPage != ( *it ).end(); ++itPage )
00613                 {
00614                     int posPage = m_pageList.find( *itPage );
00615                     if ( posPage != -1 )
00616                     {
00617                         if ( itPage != ( *it ).begin() )
00618                             tmp += ",";
00619                         tmp += page2name[*itPage];
00620                     }
00621                 }
00622                 slide.setAttribute( "pages", tmp );
00623                 element.appendChild(slide);
00624             }
00625             presenter.appendChild(element);
00626 
00627         }
00628 
00629         if ( !m_presentationName.isEmpty() )
00630         {
00631             element = doc.createElement( "DEFAULTCUSTOMSLIDESHOWNAME" );
00632             element.setAttribute( "name", m_presentationName );
00633             presenter.appendChild(element);
00634         }
00635     }
00636 
00637     if ( saveOnlyPage == -1 )
00638         emit sigProgress( 40 );
00639 
00640     if ( saveOnlyPage == -1 )
00641     {
00642         element=doc.createElement("SELSLIDES");
00643         for ( uint i = 0; i < m_pageList.count(); i++ ) {
00644             QDomElement slide=doc.createElement("SLIDE");
00645             slide.setAttribute("nr", i);
00646             slide.setAttribute("show", m_pageList.at(i)->isSlideSelected());
00647             element.appendChild(slide);
00648         }
00649         presenter.appendChild(element);
00650 
00651         emit sigProgress( 50 );
00652     }
00653 
00654     if ( saveOnlyPage == -1 )
00655     {
00656         QDomElement styles = doc.createElement( "STYLES" );
00657         presenter.appendChild( styles );
00658         QValueList<KoUserStyle *> styleList(m_styleColl->styleList());
00659         for ( QValueList<KoUserStyle *>::const_iterator it = styleList.begin(), end = styleList.end();
00660               it != end ; ++it )
00661             saveStyle( static_cast<KoParagStyle *>( *it ), styles );
00662 
00663         emit sigProgress( 60 );
00664     }
00665 
00666     // Write "OBJECT" tag for every child
00667     QPtrListIterator<KoDocumentChild> chl( children() );
00668     for( ; chl.current(); ++chl ) {
00669         // Don't save children that are only in the undo/redo history
00670         // but not anymore in the presentation
00671         for ( int i = 0; i < static_cast<int>( m_pageList.count() ); i++ ) {
00672             if ( saveOnlyPage != -1 && i != saveOnlyPage )
00673                 continue;
00674             double offset=0;
00675             if ( saveOnlyPage == -1 )
00676             {
00677                 offset = i * m_pageList.at(i)->getPageRect().height();
00678             }
00679             saveEmbeddedObject(m_pageList.at(i), chl.current(),doc,presenter,offset );
00680         }
00681         if ( saveOnlyPage == -1 )
00682         {
00683             saveEmbeddedObject(m_masterPage, chl.current(),doc,presenter,0.0 );
00684         }
00685     }
00686 
00687     if ( saveOnlyPage == -1 )
00688         emit sigProgress( 70 );
00689     makeUsedPixmapList();
00690 
00691     QDomElement pictures = m_pictureCollection.saveXML( KoPictureCollection::CollectionPicture, doc, usedPictures );
00692     presenter.appendChild( pictures );
00693 
00694     if ( saveOnlyPage == -1 )
00695         emit sigProgress( 90 );
00696 
00697     // Save sound file list.
00698     makeUsedSoundFileList();
00699     QDomElement soundFiles = saveUsedSoundFileToXML( doc, usedSoundFile );
00700     presenter.appendChild( soundFiles );
00701 
00702     if ( saveOnlyPage == -1 )
00703         setModified( false );
00704     return doc;
00705 }
00706 
00707 void KPrDocument::saveEmbeddedObject(KPrPage *page, const QPtrList<KoDocumentChild>& childList,
00708                                        QDomDocument &doc,QDomElement &presenter )
00709 {
00710     QPtrListIterator<KoDocumentChild> chl( childList );
00711     double offset = 0.0;
00712     // we need no offset for objects on the master page and when we copy a page
00713     if ( m_pageList.findRef( page ) )
00714     {
00715         offset=m_pageList.findRef(page)*page->getPageRect().height();
00716     }
00717     for( ; chl.current(); ++chl )
00718         saveEmbeddedObject(page, chl.current(),doc,presenter, offset );
00719 }
00720 
00721 void KPrDocument::saveEmbeddedObject(KPrPage *page, KoDocumentChild *chl, QDomDocument &doc,
00722                                        QDomElement &presenter, double offset )
00723 {
00724     QPtrListIterator<KPrObject> oIt(page->objectList());
00725     for ( int pos = 0; oIt.current(); ++oIt, ++pos )
00726     {
00727         if ( oIt.current()->getType() == OT_PART &&
00728              static_cast<KPrPartObject*>( oIt.current() )->getChild() == chl )
00729         {
00730             QDomElement embedded=doc.createElement("EMBEDDED");
00731             KPrChild* curr = (KPrChild*)chl;
00732 
00733             // geometry is no zoom value !
00734             QRect _rect = curr->geometry();
00735             int tmpX = (int)zoomHandler()->unzoomItX( _rect.x() );
00736             int tmpY = (int)zoomHandler()->unzoomItY( _rect.y() );
00737             int tmpWidth = (int)zoomHandler()->unzoomItX( _rect.width() );
00738             int tmpHeight = (int)zoomHandler()->unzoomItY( _rect.height() );
00739             curr->setGeometry( QRect( tmpX, tmpY, tmpWidth, tmpHeight ) );
00740 
00741             embedded.appendChild(curr->save(doc, true));
00742 
00743             curr->setGeometry( _rect ); // replace zoom value
00744 
00745             QDomElement settings=doc.createElement("SETTINGS");
00746             settings.setAttribute( "z-index", pos );
00747             if ( page == m_masterPage )
00748                 settings.setAttribute("sticky", 1 );
00749             QPtrListIterator<KPrObject> setOIt(page->objectList());
00750             for (; setOIt.current(); ++setOIt )
00751             {
00752                 if ( setOIt.current()->getType() == OT_PART &&
00753                      dynamic_cast<KPrPartObject*>( setOIt.current() )->getChild() == curr )
00754                     settings.appendChild(setOIt.current()->save( doc,offset ));
00755             }
00756             embedded.appendChild(settings);
00757             presenter.appendChild(embedded);
00758         }
00759     }
00760 
00761 }
00762 
00763 //TODO with changes with new file format header/footer can't be change
00764 void KPrDocument::compatibilityFromOldFileFormat()
00765 {
00766     //function to keep compatibility with old file format
00767     //for example for presSpeed
00768     if ( m_loadingInfo && m_loadingInfo->oldFormat() )
00769     {
00770         EffectSpeed newValue = ES_MEDIUM;
00771         bool presSpeedChanged = ( m_loadingInfo->presSpeed != -1 );
00772         if ( presSpeedChanged )
00773         {
00774             if ( m_loadingInfo->presSpeed < 3 )
00775                 newValue = ES_SLOW;
00776             else if ( m_loadingInfo->presSpeed > 7 )
00777                 newValue = ES_FAST;
00778         }
00779         if ( !m_loadingInfo->m_headerFooterByPage )
00780         {
00781             for ( int i = 0; i < static_cast<int>( m_pageList.count() ); i++ )
00782             {
00783                 if ( presSpeedChanged )
00784                     m_pageList.at(i)->setPageEffectSpeed( newValue );
00785                 m_pageList.at( i )->setHeader( m_loadingInfo->m_header );
00786                 m_pageList.at( i )->setFooter( m_loadingInfo->m_footer );
00787             }
00788         }
00789 
00790     }
00791     delete m_loadingInfo;
00792     m_loadingInfo = 0L;
00793 
00794 }
00795 
00796 void KPrDocument::enableEmbeddedParts( bool f )
00797 {
00798     QPtrListIterator<KPrPage> it( m_pageList );
00799     for ( ; it.current(); ++it )
00800         it.current()->enableEmbeddedParts(f);
00801 }
00802 
00803 QDomDocumentFragment KPrDocument::saveBackground( QDomDocument &doc )
00804 {
00805     QDomDocumentFragment fragment=doc.createDocumentFragment();
00806     for ( int i = 0; i < static_cast<int>( m_pageList.count() ); i++ ) {
00807         if ( saveOnlyPage != -1 && i != saveOnlyPage )
00808             continue;
00809         fragment.appendChild( m_pageList.at(i)->save( doc ) );
00810     }
00811     // save backgound of masterpage only when the complete doc is saved
00812     if ( saveOnlyPage == -1 )
00813     {
00814         fragment.appendChild( m_masterPage->save( doc ) );
00815     }
00816     return fragment;
00817 }
00818 
00819 QDomElement KPrDocument::saveObjects( QDomDocument &doc )
00820 {
00821     QDomElement objects=doc.createElement("OBJECTS");
00822     double yoffset=0.0;
00823     for ( int i = 0; i < static_cast<int>( m_pageList.count() ); i++ ) {
00824         if ( saveOnlyPage != -1 && saveOnlyPage!=i)
00825             continue;
00826         yoffset=i*m_pageList.at(i)->getPageRect().height(); // yoffset is not zoom value !!
00827         objects=m_pageList.at(i)->saveObjects( doc, objects, yoffset, saveOnlyPage );
00828 
00829     }
00830     if ( !_duplicatePage ) //don't copy objects on master slide when we duplicate page
00831     {
00832         objects = m_masterPage->saveObjects( doc, objects, 0.0, saveOnlyPage );
00833     }
00834 
00835     return objects;
00836 }
00837 
00838 QDomElement KPrDocument::saveTitle( QDomDocument &doc )
00839 {
00840     QDomElement titles=doc.createElement("PAGETITLES");
00841 
00842     if ( saveOnlyPage == -1 )
00843     { // All page titles.
00844         for ( int i = 0; i < static_cast<int>( m_pageList.count() ); i++ )
00845         {
00846             QDomElement title=doc.createElement("Title");
00847             title.setAttribute("title", m_pageList.at(i)->manualTitle());
00848             titles.appendChild(title);
00849         }
00850     }
00851     else
00852     { // Only current page title.
00853         QDomElement title=doc.createElement("Title");
00854         title.setAttribute("title", m_pageList.at(saveOnlyPage)->manualTitle());
00855         titles.appendChild(title);
00856     }
00857     return titles;
00858 }
00859 
00860 QDomElement KPrDocument::saveNote( QDomDocument &doc )
00861 {
00862     QDomElement notes=doc.createElement("PAGENOTES");
00863 
00864     if ( saveOnlyPage == -1 ) { // All page notes.
00865         for ( int i = 0; i < static_cast<int>( m_pageList.count() ); i++ )
00866         {
00867             QDomElement note=doc.createElement("Note");
00868             note.setAttribute("note", m_pageList.at(i)->noteText( ));
00869             notes.appendChild(note);
00870         }
00871     }
00872     else { // Only current page note.
00873         QDomElement note=doc.createElement("Note");
00874         note.setAttribute("note", m_pageList.at(saveOnlyPage)->noteText( ));
00875         notes.appendChild(note);
00876     }
00877 
00878     return notes;
00879 }
00880 
00881 QDomElement KPrDocument::saveAttribute( QDomDocument &doc )
00882 {
00883     QDomElement attributes=doc.createElement("ATTRIBUTES");
00884     //store first view parameter.
00885     int activePage=0;
00886 
00887     if ( m_initialActivePage )
00888         activePage=m_pageList.findRef(m_initialActivePage);
00889     activePage = QMAX( activePage, 0);
00890     attributes.setAttribute("activePage",activePage );
00891     attributes.setAttribute("gridx", m_gridX );
00892     attributes.setAttribute("gridy", m_gridY );
00893     attributes.setAttribute("snaptogrid", (int)m_bSnapToGrid );
00894     return attributes;
00895 }
00896 
00897 QDomElement KPrDocument::saveUsedSoundFileToXML( QDomDocument &_doc, QStringList _list )
00898 {
00899     QDomElement soundFiles = _doc.createElement( "SOUNDS" );
00900 
00901     unsigned int i = 0;
00902     QStringList::Iterator it = _list.begin();
00903     for ( ; it != _list.end(); ++it ) {
00904         QString soundFileName = *it;
00905         int position = soundFileName.findRev( '.' );
00906         QString format = soundFileName.right( soundFileName.length() - position - 1 );
00907         QString _name = QString( "sounds/sound%1.%2" ).arg( ++i ).arg( format.lower() );
00908 
00909         QDomElement fileElem = _doc.createElement( "FILE" );
00910         soundFiles.appendChild( fileElem );
00911         fileElem.setAttribute( "filename", soundFileName );
00912         fileElem.setAttribute( "name", _name );
00913     }
00914 
00915     return soundFiles;
00916 }
00917 
00918 bool KPrDocument::completeSaving( KoStore* _store )
00919 {
00920     if ( !_store ) {
00921         if ( saveOnlyPage == -1 ) {
00922             emit sigProgress( 100 );
00923             emit sigProgress( -1 );
00924         }
00925         return true;
00926     }
00927 
00928     m_pictureCollection.saveToStore( KoPictureCollection::CollectionPicture, _store, usedPictures );
00929 
00930     saveUsedSoundFileToStore( _store, usedSoundFile );
00931 
00932     if ( saveOnlyPage == -1 ) {
00933         emit sigProgress( 100 );
00934         emit sigProgress( -1 );
00935     }
00936 
00937     return true;
00938 }
00939 
00940 int KPrDocument::supportedSpecialFormats() const
00941 {
00942     return KoDocument::supportedSpecialFormats();
00943 }
00944 
00945 void KPrDocument::saveUsedSoundFileToStore( KoStore *_store, QStringList _list )
00946 {
00947     unsigned int i = 0;
00948     QStringList::Iterator it = _list.begin();
00949     for ( ; it != _list.end(); ++it ) {
00950         QString soundFileName = *it;
00951         int position = soundFileName.findRev( '.' );
00952         QString format = soundFileName.right( soundFileName.length() - position - 1 );
00953         QString _storeURL = QString( "sounds/sound%1.%2" ).arg( ++i ).arg( format.lower() );
00954 
00955         if ( _store->open( _storeURL ) ) {
00956             KoStoreDevice dev( _store );
00957             QFile _file( soundFileName );
00958             if ( _file.open( IO_ReadOnly ) ) {
00959                 dev.writeBlock( ( _file.readAll() ).data(), _file.size() );
00960                 _file.close();
00961             }
00962             _store->close();
00963         }
00964     }
00965 }
00966 
00967 bool KPrDocument::loadChildren( KoStore* _store )
00968 {
00969     if ( objStartY == 0 && _clean) // Don't do this when inserting a template or a page...
00970     {
00971         QPtrListIterator<KoDocumentChild> it( children() );
00972         for( ; it.current(); ++it ) {
00973             if ( !((KoDocumentChild*)it.current())->loadDocument( _store ) )
00974                 return false;
00975         }
00976     }
00977     else // instead load form the correct child on, m_childCountBeforeInsert has the be set
00978     {
00979         QPtrListIterator<KoDocumentChild> it( children() );
00980         for( int i = 0; it.current(); ++it, ++i ) {
00981             if ( i < m_childCountBeforeInsert )
00982                 continue;
00983             if ( !((KoDocumentChild*)it.current())->loadDocument( _store ) )
00984                 return false;
00985         }
00986     }
00987     return true;
00988 }
00989 
00990 bool KPrDocument::saveOasis( KoStore* store, KoXmlWriter* manifestWriter )
00991 {
00992 
00993     //todo necessary for new format ?
00994     if ( saveOnlyPage == -1 ) {
00995         emit sigProgress( 0 );
00996     }
00997     if ( !store->open( "content.xml" ) )
00998         return false;
00999     m_pictureCollection.assignUniqueIds();
01000     KoStoreDevice contentDev( store );
01001     KoXmlWriter* contentWriter = createOasisXmlWriter( &contentDev, "office:document-content" );
01002 
01003 
01004     m_varColl->variableSetting()->setModificationDate(QDateTime::currentDateTime());
01005     recalcVariables( VT_DATE );
01006     recalcVariables( VT_TIME );
01007     recalcVariables( VT_STATISTIC );
01008     KoGenStyles mainStyles;
01009     KoSavingContext savingContext( mainStyles, 0, false, KoSavingContext::Store );
01010 
01011     // Save user styles as KoGenStyle objects
01012     m_styleColl->saveOasis( mainStyles, KoGenStyle::STYLE_USER, savingContext );
01013 
01014     KTempFile contentTmpFile;
01015     contentTmpFile.setAutoDelete( true );
01016     QFile* tmpFile = contentTmpFile.file();
01017     KoXmlWriter contentTmpWriter( tmpFile, 1 );
01018 
01019 
01020     //For sticky objects
01021     KTempFile stickyTmpFile;
01022     stickyTmpFile.setAutoDelete( true );
01023     QFile* masterStyles = stickyTmpFile.file();
01024     KoXmlWriter stickyTmpWriter( masterStyles, 1 );
01025 
01026 
01027     contentTmpWriter.startElement( "office:body" );
01028     contentTmpWriter.startElement( "office:presentation" );
01029 
01030     saveOasisCustomFied( contentTmpWriter );
01031 
01032     int indexObj = 1;
01033     int partIndexObj = 0;
01034 //save page
01035 
01036     QMap<QString, int> pageNames;
01037     
01038     if ( !_duplicatePage )
01039     {
01040         m_masterPage->saveOasisPage( store, stickyTmpWriter, 0, savingContext, indexObj, partIndexObj, manifestWriter, pageNames );
01041 
01042         // Now mark all autostyles as "for styles.xml" since headers/footers need them
01043         QValueList<KoGenStyles::NamedStyle> autoStyles = mainStyles.styles(  KoGenStyle::STYLE_AUTO );
01044         for ( QValueList<KoGenStyles::NamedStyle>::const_iterator it = autoStyles.begin();
01045                 it != autoStyles.end(); ++it ) {
01046             kdDebug() << "marking for styles.xml:" << (  *it ).name << endl;
01047             mainStyles.markStyleForStylesXml(  ( *it ).name );
01048         }
01049 
01050     }
01051     
01052     if ( saveOnlyPage != -1 )
01053     {
01054         m_pageList.at( saveOnlyPage )->saveOasisPage( store, contentTmpWriter, ( saveOnlyPage+1 ), savingContext, indexObj, partIndexObj , manifestWriter, pageNames );
01055     }
01056     else
01057     {
01058         for ( int i = 0; i < static_cast<int>( m_pageList.count() ); i++ )
01059         {
01060             m_pageList.at( i )->saveOasisPage( store, contentTmpWriter, ( i+1 ), savingContext, indexObj, partIndexObj , manifestWriter, pageNames );
01061         }
01062     }
01063     if ( saveOnlyPage == -1 ) //don't save setting when we save on page
01064     {
01065         QMap<int, QString> page2name;
01066         QMap<QString, int>::ConstIterator it( pageNames.begin() );
01067         for ( ; it != pageNames.end(); ++it )
01068         {
01069             page2name.insert( it.data(), it.key() );
01070         }
01071         saveOasisPresentationSettings( contentTmpWriter, page2name );
01072     }
01073 
01074     contentTmpWriter.endElement(); //office:presentation
01075     contentTmpWriter.endElement(); //office:body
01076 
01077     writeAutomaticStyles( *contentWriter, mainStyles, savingContext, false );
01078 
01079     // And now we can copy over the contents from the tempfile to the real one
01080     tmpFile->close();
01081     contentWriter->addCompleteElement( tmpFile );
01082     contentTmpFile.close();
01083 
01084     contentWriter->endElement(); // root element
01085     contentWriter->endDocument();
01086     delete contentWriter;
01087 
01088     if ( !store->close() ) // done with content.xml
01089         return false;
01090 
01091     //add manifest line for content.xml
01092     manifestWriter->addManifestEntry( "content.xml", "text/xml" );
01093 
01094     if ( !store->open( "styles.xml" ) )
01095         return false;
01096 
01097     manifestWriter->addManifestEntry( "styles.xml", "text/xml" );
01098 
01099     //todo fixme????
01100     masterStyles->close();
01101     saveOasisDocumentStyles( store, mainStyles, masterStyles, savingContext );
01102     stickyTmpFile.close();
01103 
01104     if ( !store->close() ) // done with styles.xml
01105         return false;
01106 
01107 
01108     if ( saveOnlyPage == -1 )
01109         emit sigProgress( 90 );
01110 
01111     // Save sound file list.
01112 //todo ????
01113 
01114 
01115     makeUsedPixmapList();
01116 
01117     m_pictureCollection.saveOasisToStore( store, usedPictures, manifestWriter);
01118 
01119     if(!store->open("settings.xml"))
01120         return false;
01121 
01122     KoXmlWriter& settingsWriter = *createOasisXmlWriter(&contentDev, "office:document-settings");
01123     settingsWriter.startElement("office:settings");
01124 
01125     settingsWriter.startElement("config:config-item-set");
01126     settingsWriter.addAttribute("config:name", "view-settings");
01127 
01128     KoUnit::saveOasis(&settingsWriter, unit());
01129     saveOasisSettings( settingsWriter );
01130 
01131     settingsWriter.endElement(); // config:config-item-set
01132 
01133     settingsWriter.startElement("config:config-item-set");
01134     settingsWriter.addAttribute("config:name", "configuration-settings");
01135     settingsWriter.addConfigItem("SpellCheckerIgnoreList", m_spellCheckIgnoreList.join( "," ) );
01136     settingsWriter.endElement(); // config:config-item-set
01137 
01138     m_varColl->variableSetting()->saveOasis( settingsWriter );
01139 
01140     settingsWriter.endElement(); // office:settings
01141     settingsWriter.endElement(); // Root:Element
01142     settingsWriter.endDocument();
01143     delete &settingsWriter;
01144 
01145     if(!store->close())
01146         return false;
01147 
01148     manifestWriter->addManifestEntry("settings.xml", "text/xml");
01149 
01150     //reset progressbar
01151     emit sigProgress( 100 );
01152     emit sigProgress( -1 );
01153 
01154     setModified( false );
01155 
01156     return true;
01157 }
01158 
01159 void KPrDocument::saveOasisCustomFied( KoXmlWriter &writer )const
01160 {
01161     bool customVariableFound = false;
01162     QPtrListIterator<KoVariable> it( m_varColl->getVariables() );
01163     for ( ; it.current() ; ++it )
01164     {
01165         if ( it.current()->type() == VT_CUSTOM )
01166         {
01167             if ( !customVariableFound )
01168             {
01169                 writer.startElement( "text:user-field-decls" );
01170                 customVariableFound = true;
01171             }
01172             //<text:user-field-decl office:value-type="string" office:string-value="dfddd" text:name="cvbcbcbx"/>
01173             writer.startElement( "text:user-field-decl" );
01174             writer.addAttribute( "office:value-type", "string" );
01175             writer.addAttribute( "office:string-value", static_cast<KoCustomVariable *>( it.current() )->value() );
01176             writer.addAttribute( "text:name", static_cast<KoCustomVariable*>( it.current() )->name() );
01177             writer.endElement();
01178         }
01179     }
01180     if ( customVariableFound )
01181         writer.endElement();
01182 }
01183 
01184 
01185 void KPrDocument::loadOasisIgnoreList( const KoOasisSettings& settings )
01186 {
01187     KoOasisSettings::Items configurationSettings = settings.itemSet( "configuration-settings" );
01188     if ( !configurationSettings.isNull() )
01189     {
01190         const QString ignorelist = configurationSettings.parseConfigItemString( "SpellCheckerIgnoreList" );
01191         m_spellCheckIgnoreList = QStringList::split( ',', ignorelist );
01192     }
01193 }
01194 
01195 void KPrDocument::writeAutomaticStyles( KoXmlWriter& contentWriter, KoGenStyles& mainStyles, KoSavingContext& context, bool stylesDotXml )
01196 {
01197     context.writeFontFaces( contentWriter );
01198     if ( !stylesDotXml )
01199     {
01200         contentWriter.startElement( "office:automatic-styles" );
01201     }
01202     QValueList<KoGenStyles::NamedStyle> styles = mainStyles.styles( KoGenStyle::STYLE_AUTO, stylesDotXml );
01203     QValueList<KoGenStyles::NamedStyle>::const_iterator it = styles.begin();
01204     for ( ; it != styles.end() ; ++it ) {
01205         (*it).style->writeStyle( &contentWriter, mainStyles, "style:style", (*it).name, "style:paragraph-properties" );
01206     }
01207 
01208     styles = mainStyles.styles( KoGenStyle::STYLE_AUTO_LIST, stylesDotXml );
01209     it = styles.begin();
01210     for ( ; it != styles.end() ; ++it ) {
01211         ( *it ).style->writeStyle( &contentWriter, mainStyles, "text:list-style", (*it).name, 0 );
01212     }
01213 
01214     styles = mainStyles.styles( STYLE_BACKGROUNDPAGEAUTO, stylesDotXml );
01215     it = styles.begin();
01216     for ( ; it != styles.end() ; ++it ) {
01217         (*it).style->writeStyle( &contentWriter, mainStyles, "style:style", (*it).name, "style:drawing-page-properties" );
01218     }
01219 
01220     styles = mainStyles.styles( KoGenStyle::STYLE_GRAPHICAUTO, stylesDotXml );
01221     it = styles.begin();
01222     for ( ; it != styles.end() ; ++it ) {
01223         (*it).style->writeStyle( &contentWriter, mainStyles, "style:style", (*it).name , "style:graphic-properties"  );
01224     }
01225 
01226     styles = mainStyles.styles( KoGenStyle::STYLE_NUMERIC_DATE, stylesDotXml );
01227     it = styles.begin();
01228     for ( ; it != styles.end() ; ++it ) {
01229         (*it).style->writeStyle( &contentWriter, mainStyles, "number:date-style", (*it).name, 0 /*TODO ????*/  );
01230     }
01231     styles = mainStyles.styles( KoGenStyle::STYLE_NUMERIC_TIME, stylesDotXml );
01232     it = styles.begin();
01233     for ( ; it != styles.end() ; ++it ) {
01234         (*it).style->writeStyle( &contentWriter, mainStyles, "number:time-style", (*it).name, 0 /*TODO ????*/  );
01235     }
01236 
01237     if ( !stylesDotXml )
01238     {
01239         contentWriter.endElement(); // office:automatic-styles
01240     }
01241 }
01242 
01243 void KPrDocument::loadOasisHeaderFooter(QDomNode & drawPage, KoOasisContext & context)
01244 {
01245     QDomNode tmp = KoDom::namedItemNS( drawPage, KoXmlNS::style, "header" );
01246     if ( !tmp.isNull() )
01247     {
01248         //kdDebug()<<" there is a header \n";
01249         _header->textObject()->loadOasisContent( tmp.toElement(), context, styleCollection() );
01250     }
01251     tmp = KoDom::namedItemNS( drawPage, KoXmlNS::style, "footer" );
01252     if ( !tmp.isNull() )
01253     {
01254         //kdDebug()<<" there is a footer \n";
01255         _footer->textObject()->loadOasisContent( tmp.toElement(), context, styleCollection() );
01256     }
01257 }
01258 
01259 void KPrDocument::saveOasisSettings( KoXmlWriter &settingsWriter )
01260 {
01261     settingsWriter.startElement("config:config-item-map-indexed");
01262     settingsWriter.addAttribute("config:name", "Views");
01263     settingsWriter.startElement( "config:config-item-map-entry" );
01264 
01265     //ooimpress save it as this line.
01266     //<config:config-item config:name="SnapLinesDrawing" config:type="string">H2260V14397H7693H12415H15345H1424</config:config-item>
01267     QString guideLinesOasis;
01268     //save in mm as in oo
01269     for( QValueList<double>::Iterator it = m_vGuideLines.begin(); it != m_vGuideLines.end(); ++it )
01270     {
01271         int tmpX = ( int ) ( KoUnit::toMM( *it  )*100 );
01272         guideLinesOasis += "V" + QString::number( tmpX );
01273     }
01274 
01275     for( QValueList<double>::Iterator it = m_hGuideLines.begin(); it != m_hGuideLines.end(); ++it )
01276     {
01277         int tmpY = ( int ) ( KoUnit::toMM( *it  )*100 );
01278         guideLinesOasis += "H" + QString::number( tmpY );
01279     }
01280     if ( !guideLinesOasis.isEmpty() )
01281     {
01282         settingsWriter.addConfigItem( "SnapLinesDrawing", guideLinesOasis );
01283     }
01284     //<config:config-item config:name="IsSnapToGrid" config:type="boolean">false</config:config-item>
01285     settingsWriter.addConfigItem( "IsSnapToGrid", m_bSnapToGrid );
01286 
01287     //<config:config-item config:name="GridFineWidth" config:type="int">500</config:config-item>
01288     settingsWriter.addConfigItem( "GridFineWidth", ( ( int ) ( KoUnit::toMM( ( m_gridX )  )*100 ) ) );
01289 
01290 
01291     //<config:config-item config:name="GridFineHeight" config:type="int">500</config:config-item>
01292     settingsWriter.addConfigItem( "GridFineHeight", ( ( int ) ( KoUnit::toMM( ( m_gridY )  )*100 ) ) );
01293 
01294     //<config:config-item config:name="SelectedPage" config:type="short">3</config:config-item>
01295     //store first view parameter.
01296     int activePage=0;
01297     if ( m_initialActivePage )
01298         activePage=m_pageList.findRef(m_initialActivePage);
01299     activePage = QMAX( activePage, 0);
01300     settingsWriter.addConfigItem( "SelectedPage", activePage );
01301 
01302     //not define into oo spec
01303     settingsWriter.addConfigItem( "SnapLineIsVisible", showGuideLines() );
01304     settingsWriter.endElement();
01305     settingsWriter.endElement();
01306 }
01307 
01308 void KPrDocument::loadOasisSettings(const QDomDocument&settingsDoc)
01309 {
01310     kdDebug(33001)<<"void KPrDocument::loadOasisSettings(const QDomDocument&settingsDoc)**********\n";
01311     KoOasisSettings settings( settingsDoc );
01312     KoOasisSettings::Items viewSettings = settings.itemSet( "view-settings" );
01313     setUnit(KoUnit::unit(viewSettings.parseConfigItemString("unit")));
01314     KoOasisSettings::IndexedMap viewMap = viewSettings.indexedMap( "Views" );
01315     KoOasisSettings::Items firstView = viewMap.entry( 0 );
01316     if ( !firstView.isNull() )
01317     {
01318         parseOasisGuideLines( firstView.parseConfigItemString( "SnapLinesDrawing" ) );
01319         setShowGuideLines( firstView.parseConfigItemBool( "SnapLineIsVisible" ) );
01320         int valx = firstView.parseConfigItemInt( "GridFineWidth" );
01321         m_gridX = MM_TO_POINT( valx / 100.0 );
01322         int valy = firstView.parseConfigItemInt( "GridFineHeight" );
01323         m_gridY = MM_TO_POINT( valy / 100.0 );
01324 
01325         m_bSnapToGrid = firstView.parseConfigItemBool( "IsSnapToGrid" );
01326 
01327         int activePage = firstView.parseConfigItemInt( "SelectedPage" );
01328         kdDebug(33001)<<" activePage :"<<activePage<<endl;
01329         if(activePage!=-1)
01330             m_initialActivePage=m_pageList.at(activePage);
01331     }
01332     loadOasisIgnoreList( settings );
01333     m_varColl->variableSetting()->loadOasis( settings );
01334 }
01335 
01336 void KPrDocument::parseOasisGuideLines( const QString &text )
01337 {
01338     QString str;
01339     int newPos = text.length()-1; //start to element = 1
01340     for ( int pos = text.length()-1; pos >=0;--pos )
01341     {
01342         if ( text[pos]=='V' )
01343         {
01344             //vertical element
01345             str = text.mid( pos+1, ( newPos-pos ) );
01346             //kdDebug()<<" vertical  :"<< str <<endl;
01347             double posX = ( str.toInt() / 100.0 );
01348             m_vGuideLines.append( MM_TO_POINT( posX ) );
01349             newPos = pos-1;
01350         }
01351         else if ( text[pos]=='H' )
01352         {
01353             //horizontal element
01354             str = text.mid( pos+1, ( newPos-pos ) );
01355             //kdDebug()<<" horizontal  :"<< str <<endl;
01356             double posY = ( str.toInt() / 100.0 );
01357             m_hGuideLines.append( MM_TO_POINT( posY ) );
01358             newPos = pos-1;
01359         }
01360     }
01361 }
01362 
01363 void KPrDocument::loadOasisPresentationSettings( QDomNode &settingsDoc )
01364 {
01365     //kdDebug()<<"presentation:settings ********************************************* \n";
01366     QDomElement settings( settingsDoc.toElement() );
01367     //kdDebug()<<"settings.attribute(presentation:endless) :"<<settings.attributeNS( KoXmlNS::presentation, "endless", QString::null)<<endl;
01368     if (settings.attributeNS( KoXmlNS::presentation, "endless", QString::null)=="true")
01369         _spInfiniteLoop = true;
01370 
01371     if (settings.attributeNS( KoXmlNS::presentation, "force-manual", QString::null)=="true")
01372         _spManualSwitch = true;
01373     if ( settings.hasAttributeNS( KoXmlNS::presentation, "start-page" ) )
01374     {
01375         //TODO allow to start presentation to specific page
01376         //???? = settings.attributeNS( KoXmlNS::presentation, "start-page", QString::null );
01377     }
01378     if ( settings.hasAttributeNS( KoXmlNS::presentation, "show" ) )
01379     {
01380         m_presentationName = settings.attributeNS( KoXmlNS::presentation, "show", QString::null );
01381         kdDebug()<<" default presentation name :"<<m_presentationName<<endl;
01382     }
01383     loadOasisPresentationCustomSlideShow( settingsDoc );
01384 }
01385 
01386 void KPrDocument::loadOasisPresentationCustomSlideShow( QDomNode &settingsDoc )
01387 {
01388     //kdDebug()<<"void KPrDocument::loadOasisPresentationCustomSlideShow( QDomNode &settingsDoc )**********\n";
01389     for ( QDomNode element = settingsDoc.firstChild(); !element.isNull(); element = element.nextSibling() )
01390     {
01391         QDomElement e = element.toElement();
01392         QCString tagName = e.tagName().latin1();
01393         //kdDebug()<<" tagName :"<<tagName<<endl;
01394         if ( tagName == "show" && e.namespaceURI() == KoXmlNS::presentation )
01395         {
01396             //kdDebug()<<" e.attribute(presentation:name) :"<<e.attributeNS( KoXmlNS::presentation, "name", QString::null)<< " e.attribute(presentation:pages) :"<<e.attributeNS( KoXmlNS::presentation, "pages", QString::null)<<endl;
01397             QString name = e.attributeNS( KoXmlNS::presentation, "name", QString::null );
01398             QStringList tmp = QStringList::split( ",", e.attributeNS( KoXmlNS::presentation, "pages", QString::null) );
01399             QValueList<KPrPage *> pageList;
01400             for ( QStringList::Iterator it = tmp.begin(); it != tmp.end(); ++it )
01401             {
01402                 if ( m_loadingInfo->m_name2page.contains( *it ) )
01403                 {
01404                     kdDebug(33001) << "slide show " << name << " page = " << *it << endl;
01405                     pageList.push_back( m_loadingInfo->m_name2page[*it] );
01406                 }
01407             }
01408             if ( ! pageList.empty() )
01409             {
01410                 m_customListSlideShow.insert( name, pageList );
01411             }
01412         }
01413     }
01414 }
01415 
01416 void KPrDocument::saveOasisPresentationSettings( KoXmlWriter &contentTmpWriter, QMap<int, QString> &page2name )
01417 {
01418     //todo don't save when is not value by default (check with oo)
01419     //FIXME
01420     contentTmpWriter.startElement( "presentation:settings" );
01421     contentTmpWriter.addAttribute( "presentation:endless",  ( _spInfiniteLoop ? "true" : "false" ) );
01422     contentTmpWriter.addAttribute( "presentation:force-manual",  ( _spManualSwitch ? "true" : "false" ) );
01423     //add for default presentation
01424     if ( !m_presentationName.isEmpty() )
01425         contentTmpWriter.addAttribute( "presentation:show",  m_presentationName );
01426 
01427     saveOasisPresentationCustomSlideShow( contentTmpWriter, page2name );
01428     contentTmpWriter.endElement();
01429 }
01430 
01431 void KPrDocument::saveOasisPresentationCustomSlideShow( KoXmlWriter &contentTmpWriter, QMap<int, QString> &page2name )
01432 {
01433     if ( m_customListSlideShow.isEmpty() )
01434         return;
01435 
01436     CustomSlideShowMap::Iterator it;
01437     for ( it = m_customListSlideShow.begin(); it != m_customListSlideShow.end(); ++it )
01438     {
01439         contentTmpWriter.startElement( "presentation:show" );
01440         contentTmpWriter.addAttribute( "presentation:name", it.key() );
01441         QString tmp;
01442         QValueListIterator<KPrPage*> itPage ;
01443         for( itPage = ( *it ).begin(); itPage != ( *it ).end(); ++itPage )
01444         {
01445             int posPage = m_pageList.find(*itPage );
01446             if ( posPage != -1 )
01447             {
01448                 if ( itPage != ( *it ).begin() )
01449                     tmp += ",";
01450                 //tmp+=( *itPage )->oasisNamePage(posPage+1)+",";
01451                 tmp += page2name[posPage + 1];
01452             }
01453         }
01454         contentTmpWriter.addAttribute( "presentation:pages", tmp );
01455         contentTmpWriter.endElement();
01456     }
01457     //<presentation:show presentation:name="New Custom Slide Show" presentation:pages="page1,page1,page1,page1,page1"/>
01458 }
01459 
01460 void KPrDocument::saveOasisDocumentStyles( KoStore* store, KoGenStyles& mainStyles, QFile* masterStyles, 
01461                                            KoSavingContext & savingContext, SaveFlag saveFlag ) const
01462 {
01463     KoStoreDevice stylesDev( store );
01464     KoXmlWriter* stylesWriter = createOasisXmlWriter( &stylesDev, "office:document-styles" );
01465 
01466     stylesWriter->startElement( "office:styles" );
01467     QValueList<KoGenStyles::NamedStyle> styles = mainStyles.styles( KoGenStyle::STYLE_USER );
01468     QValueList<KoGenStyles::NamedStyle>::const_iterator it = styles.begin();
01469     for ( ; it != styles.end() ; ++it ) {
01470         (*it).style->writeStyle( stylesWriter, mainStyles, "style:style", (*it).name, "style:paragraph-properties" );
01471     }
01472     styles = mainStyles.styles( KoGenStyle::STYLE_LIST );
01473     it = styles.begin();
01474     for ( ; it != styles.end() ; ++it ) {
01475         (*it).style->writeStyle( stylesWriter, mainStyles, "text:list-style", (*it).name, 0 );
01476     }
01477     styles = mainStyles.styles( KoGenStyle::STYLE_HATCH );
01478     it = styles.begin();
01479     for ( ; it != styles.end() ; ++it ) {
01480         (*it).style->writeStyle( stylesWriter, mainStyles, "draw:hatch", (*it).name, "style:graphic-properties" ,  true,  true /*add draw:name*/);
01481     }
01482     styles = mainStyles.styles( STYLE_GRADIENT );
01483     it = styles.begin();
01484     for ( ; it != styles.end() ; ++it ) {
01485         (*it).style->writeStyle( stylesWriter, mainStyles, "draw:gradient", (*it).name, "style:graphic-properties" ,  true,  true /*add draw:name*/);
01486     }
01487 
01488     styles = mainStyles.styles( STYLE_STROKE );
01489     it = styles.begin();
01490     for ( ; it != styles.end() ; ++it ) {
01491         (*it).style->writeStyle( stylesWriter, mainStyles, "draw:stroke-dash", (*it).name, "style:graphic-properties" ,  true,  true /*add draw:name*/);
01492     }
01493 
01494     styles = mainStyles.styles( STYLE_MARKER );
01495     it = styles.begin();
01496     for ( ; it != styles.end() ; ++it ) {
01497         (*it).style->writeStyle( stylesWriter, mainStyles, "draw:marker", (*it).name, "style:graphic-properties" ,  true,  true /*add draw:name*/);
01498     }
01499     styles = mainStyles.styles( STYLE_PICTURE );
01500     it = styles.begin();
01501     for ( ; it != styles.end() ; ++it ) {
01502         (*it).style->writeStyle( stylesWriter, mainStyles, "draw:fill-image", (*it).name, "style:image-properties" ,  true,  true /*add draw:name*/);
01503     }
01504 
01505     stylesWriter->endElement(); // office:styles
01506 
01507     if ( saveFlag == SaveAll )
01508     {
01509         stylesWriter->startElement( "office:automatic-styles" );
01510         // this has to be the first
01511         if ( masterStyles )
01512         {
01513             writeAutomaticStyles( *stylesWriter, mainStyles, savingContext, true );
01514         }
01515 
01516         styles = mainStyles.styles( STYLE_BACKGROUNDPAGE );
01517         it = styles.begin();
01518         for ( ; it != styles.end() ; ++it ) {
01519             (*it).style->writeStyle( stylesWriter, mainStyles, "style:style", (*it).name , "style:drawing-page-properties"  );
01520         }
01521 
01522         // if there's more than one pagemaster we need to rethink all this
01523         styles = mainStyles.styles( KoGenStyle::STYLE_PAGELAYOUT );
01524         Q_ASSERT( styles.count() == 1 );
01525         it = styles.begin();
01526         for ( ; it != styles.end() ; ++it ) {
01527             (*it).style->writeStyle( stylesWriter, mainStyles, "style:page-layout", (*it).name, "style:page-layout-properties", false /*don't close*/ );
01528             stylesWriter->endElement();
01529         }
01530 
01531         styles = mainStyles.styles( STYLE_PRESENTATIONSTICKYOBJECT );
01532         it = styles.begin();
01533         for ( ; it != styles.end() ; ++it ) {
01534             //TODO fix me graphic-properties ???
01535             (*it).style->writeStyle( stylesWriter, mainStyles, "style:style", (*it).name , "style:graphic-properties"  );
01536         }
01537 
01538         stylesWriter->endElement(); // office:automatic-styles
01539 
01540 
01541         if ( masterStyles )
01542         {
01543             stylesWriter->startElement( "office:master-styles" );
01544             stylesWriter->addCompleteElement( masterStyles );
01545             stylesWriter->endElement();
01546         }
01547     }
01548 
01549     stylesWriter->endElement(); // root element (office:document-styles)
01550     stylesWriter->endDocument();
01551     delete stylesWriter;
01552 }
01553 
01554 bool KPrDocument::loadOasis( const QDomDocument& doc, KoOasisStyles&oasisStyles, const QDomDocument&settingsDoc, KoStore*store )
01555 {
01556     QTime dt;
01557     dt.start();
01558     m_loadingInfo = new KPrLoadingInfo;
01559     ignoreSticky = FALSE;
01560     emit sigProgress( 0 );
01561 
01562     lastObj = -1;
01563     // clean
01564     if ( _clean ) {
01565         m_styleColl->clear();
01566         // Some simple import filters don't define any style,
01567         // so let's have a Standard style at least
01568         KoParagStyle * standardStyle = new KoParagStyle( "Standard" ); // This gets translated later on
01569         //kdDebug() << "KWDocument::KWDocument creating standardStyle " << standardStyle << endl;
01570         standardStyle->format().setFont( m_defaultFont );
01571         m_styleColl->addStyle( standardStyle );
01572 
01573         __pgLayout = KoPageLayout::standardLayout();
01574         _spInfiniteLoop = false;
01575         _spManualSwitch = true;
01576         _showPresentationDuration = false;
01577         _xRnd = 20;
01578         _yRnd = 20;
01579         urlIntern = url().path();
01580     }
01581     else
01582         m_spellCheckIgnoreList.clear();
01583     emit sigProgress( 5 );
01584 
01585     QDomElement content = doc.documentElement();
01586     QDomElement realBody (KoDom::namedItemNS( content, KoXmlNS::office, "body" ) );
01587     if ( realBody.isNull() )
01588     {
01589         kdError(33001) << "No office:body found!" << endl;
01590         setErrorMessage( i18n( "Invalid OASIS OpenDocument file. No office:body tag found." ) );
01591         return false;
01592     }
01593     QDomElement body = KoDom::namedItemNS( realBody, KoXmlNS::office, "presentation" );
01594     if ( body.isNull() )
01595     {
01596         kdError(33001) << "No office:presentation found!" << endl;
01597         QDomElement childElem;
01598         QString localName;
01599         forEachElement( childElem, realBody ) {
01600             localName = childElem.localName();
01601         }
01602         if ( localName.isEmpty() )
01603             setErrorMessage( i18n( "Invalid OASIS OpenDocument file. No tag found inside office:body." ) );
01604         else
01605             setErrorMessage( i18n( "This document is not a presentation, but a %1. Please try opening it with the appropriate application." ).arg( KoDocument::tagNameToDocumentType( localName ) ) );
01606         return false;
01607     }
01608 
01609     // it seems that ooimpress has different paper-settings for every slide.
01610     // we take the settings of the first slide for the whole document.
01611     QDomNode drawPage = KoDom::namedItemNS( body, KoXmlNS::draw, "page" );
01612     if ( drawPage.isNull() ) // no slides? give up.
01613         return false;
01614     QDomElement dp = drawPage.toElement();
01615 
01616     //code from kword
01617     // TODO variable settings
01618     // By default display real variable value
01619     if ( !isReadWrite())
01620         getVariableCollection()->variableSetting()->setDisplayFieldCode(false);
01621 
01622     KoOasisContext context( this, *m_varColl, oasisStyles, store );
01623     Q_ASSERT( !oasisStyles.officeStyle().isNull() );
01624 
01625     // Load all styles before the corresponding paragraphs try to use them!
01626     m_styleColl->loadOasisStyles( context );
01627 
01628     // if we only copy a page we have no master
01629     // also don't copy master when you insert file as long as we don't have multiple masters
01630     if ( !m_pageWhereLoadObject && _clean )
01631     {
01632         QString masterPageName = drawPage.toElement().attributeNS( KoXmlNS::draw, "master-page-name", QString::null );
01633         QDomElement *master = oasisStyles.masterPages()[ masterPageName];
01634 
01635         kdDebug()<<" master :"<<master<<endl;
01636         kdDebug()<<" masterPageName:"<<masterPageName<<endl;
01637         if ( ! master )
01638         {
01639             masterPageName = "Standard"; // use default layout as fallback (default in kpresenter)
01640             master = oasisStyles.masterPages()[ masterPageName];
01641             if ( !master ) //last test...
01642                 master = oasisStyles.masterPages()["Default"];
01643         }
01644 
01645         if ( master == 0 )
01646         {
01647             setErrorMessage( i18n( "Invalid OASIS OpenDocument file. No master-style found inside office:master-styles." ) );
01648             return false;
01649         }
01650 
01651         kdDebug()<<" load oasis master styles\n";
01652         QDomNode node = *master;
01653         QDomElement masterElement = node.toElement();
01654         kdDebug()<<" node.isNull() :"<<node.isNull()<< ", " << masterElement.attributeNS( KoXmlNS::draw, "style-name", QString::null ) << endl;
01655         // add the correct styles
01656         const QDomElement* masterPageStyle = context.oasisStyles().findStyleAutoStyle( masterElement.attributeNS( KoXmlNS::draw, "style-name", QString::null ), "drawing-page" );
01657         context.styleStack().push( *masterPageStyle );
01658 
01659         context.setUseStylesAutoStyles( true );
01660         m_masterPage->loadOasis( context );
01661 
01662         createPresentationAnimation( KoDom::namedItemNS( node, KoXmlNS::presentation, "animations"));
01663 
01664         loadOasisObject( m_masterPage, node , context);
01665 
01666         m_loadingInfo->clearAnimationShowDict(); // clear all show animations style
01667         m_loadingInfo->clearAnimationHideDict(); // clear all hide animations style
01668 
01669         loadOasisHeaderFooter( node,context );
01670         context.setUseStylesAutoStyles( false );
01671 
01672         kdDebug()<<" end load oasis master style \n";
01673 
01674         Q_ASSERT( master );
01675         const QDomElement *style = master ? oasisStyles.findStyle(master->attributeNS( KoXmlNS::style, "page-layout-name", QString::null )) : 0;
01676         const QDomElement *backgroundStyle = oasisStyles.findStyle( "Standard-background", "presentation" );
01677         kdDebug()<<"Standard background "<<backgroundStyle<<endl;
01678         // parse all pages
01679         Q_ASSERT( style );
01680         if ( style )
01681         {
01682             __pgLayout.loadOasis( *style );
01683             kdDebug()<<"Page size __pgLayout.ptWidth :"<<__pgLayout.ptWidth<<" __pgLayout.ptHeight :"<<__pgLayout.ptHeight<<endl;
01684             kdDebug()<<"Page orientation :"<<(( __pgLayout.orientation== PG_LANDSCAPE )? " landscape " : " portrait ")<<endl;
01685 
01686             kdDebug()<<" margin right:"<< __pgLayout.ptRight <<" __pgLayout.ptBottom :"<<__pgLayout.ptBottom<<" __pgLayout.ptLeft :"<<__pgLayout.ptLeft<<" __pgLayout.ptTop :"<<__pgLayout.ptTop<<endl;
01687         }
01688         if ( _clean )
01689         {
01691             setPageLayout( __pgLayout );
01692         }
01693     }
01694 
01695     int pos = m_insertFilePage;
01696     for ( drawPage = body.firstChild(); !drawPage.isNull(); drawPage = drawPage.nextSibling() )
01697     {
01698         dp = drawPage.toElement();
01699         kdDebug()<<"dp.tagName() :"<<dp.tagName()<<endl;
01700         if ( dp.tagName()== "page" && dp.namespaceURI() == KoXmlNS::draw ) // don't try to parse "</draw:page>" as page
01701         {
01702             context.styleStack().clear(); // remove all styles
01703             fillStyleStack( dp, context, "drawing-page" );
01704             context.styleStack().save();
01705             kdDebug ()<<"insert new page "<<pos<<endl;
01706             KPrPage *newpage = 0L;
01707             if ( m_pageWhereLoadObject )
01708             {
01709                 newpage = m_pageWhereLoadObject;
01710             }
01711             else
01712             {
01713                 if ( pos != 0 )
01714                 {
01715                     newpage = new KPrPage( this, m_masterPage );
01716                     m_pageList.insert( pos,newpage);
01717                 }
01718                 else //we create a first page into KPrDocument()
01719                 {
01720                     newpage = m_pageList.at(pos);
01721                 }
01722             }
01723             //only set the manual title if it is different to the draw:id. Only in this case it had one.
01724             QString str = dp.attributeNS( KoXmlNS::draw, "name", QString::null );
01725             m_loadingInfo->m_name2page.insert( str, newpage );
01726             QString idPage = dp.attributeNS( KoXmlNS::draw, "id", QString::null );
01727 
01728             if ( dp.hasAttributeNS( KoXmlNS::koffice, "name" ) )
01729             {
01730                 str = dp.attributeNS( KoXmlNS::koffice, "name", QString::null );
01731                 newpage->insertManualTitle(str);
01732             }
01733             else
01734             {
01735                 // OO uses /page[0-9]+$/ as default for no name set
01736                 QRegExp rx( "^page[0-9]+$" );
01737                 if ( rx.search( str ) == -1 )
01738                     newpage->insertManualTitle(str);
01739             }
01740             context.styleStack().setTypeProperties( "drawing-page" );
01741 
01742             newpage->loadOasis( context );
01743 
01744             //All animation object for current page is store into this element
01745             createPresentationAnimation(KoDom::namedItemNS( drawPage, KoXmlNS::presentation, "animations"));
01746             // parse all objects
01747             loadOasisObject( newpage, drawPage, context );
01748 
01749             context.styleStack().restore();
01750             m_loadingInfo->clearAnimationShowDict(); // clear all show animations style
01751             m_loadingInfo->clearAnimationHideDict(); // clear all hide animations style
01752             ++pos;
01753         }
01754     }
01755 
01756     //load settings at the end as we need to know what the draw:name of a page is
01757     QDomNode settings  = KoDom::namedItemNS( body, KoXmlNS::presentation, "settings" );
01758     kdDebug()<<"settings :"<<settings.isNull()<<endl;
01759     if (!settings.isNull() && _clean /*don't load settings when we copy/paste a page*/)
01760         loadOasisPresentationSettings( settings );
01761 
01762     ignoreSticky = TRUE;
01763     kdDebug()<<" _clean :"<<_clean<<endl;
01764     if(_clean)
01765     {
01766         setModified(false);
01767 #if 0   //FIXME
01768         //it crashed, I don't know why for the moment.
01769         startBackgroundSpellCheck();
01770 #endif
01771     }
01772     kdDebug(33001) << "Loading took " << (float)(dt.elapsed()) / 1000.0 << " seconds" << endl;
01773 
01774     if ( !settingsDoc.isNull() )
01775     {
01776         loadOasisSettings( settingsDoc );
01777     }
01778 
01779     // set the initial active page
01780     if ( m_initialActivePage == 0 )
01781     {
01782         m_initialActivePage = m_pageList.at( 0 );
01783     }
01784 
01785     emit sigProgress( 100 );
01786     recalcVariables( VT_FIELD );
01787     recalcVariables( VT_STATISTIC );
01788     emit sigProgress( -1 );
01789 
01790     setModified( false );
01791     return true;
01792 }
01793 
01794 
01795 void KPrDocument::loadOasisObject( KPrPage * newpage, QDomNode & drawPage, KoOasisContext & context, KPrGroupObject *groupObject )
01796 {
01797     for ( QDomNode object = drawPage.firstChild(); !object.isNull(); object = object.nextSibling() )
01798     {
01799         QDomElement o = object.toElement();
01800         QString name = o.tagName();
01801         if ( !name.isEmpty() )
01802         {
01803             kdDebug()<<" name :"<<name<<endl;
01804             if ( o.hasAttributeNS( KoXmlNS::presentation, "placeholder" ) &&
01805                  o.attributeNS( KoXmlNS::presentation, "placeholder", QString::null ) == "true" )
01806             {
01807                 kdDebug(33001) << "Placeholder" << endl;
01808                 continue;
01809             }
01810             context.styleStack().save();
01811             const bool isDrawNS = o.namespaceURI() == KoXmlNS::draw;
01812             // draw:frame
01813             if ( name == "frame" && isDrawNS )
01814             {
01815                 fillStyleStack( o, context, "graphic" );
01816                 QDomElement elem;
01817                 forEachElement( elem, o )
01818                 {
01819                     if ( elem.namespaceURI() != KoXmlNS::draw )
01820                         continue;
01821                     const QString localName = elem.localName();
01822                     if ( localName == "text-box" )
01823                     {
01824                         KPrTextObject *kptextobject = new KPrTextObject( this );
01825                         kptextobject->loadOasis(o, context, m_loadingInfo);
01826                         if ( groupObject )
01827                             groupObject->addObjects( kptextobject );
01828                         else
01829                             newpage->appendObject(kptextobject);
01830                         break;
01831                     }
01832                     else if ( localName == "image" )
01833                     {
01834                         KPrPixmapObject *kppixmapobject = new KPrPixmapObject( pictureCollection() );
01835                         kppixmapobject->loadOasis( o, context, m_loadingInfo);
01836                         if ( groupObject )
01837                             groupObject->addObjects( kppixmapobject );
01838                         else
01839                             newpage->appendObject(kppixmapobject);
01840                         break;
01841                     } 
01842                     else if ( localName == "object" )
01843                     {
01844                         KPrChild *ch = new KPrChild( this );
01845                         QRect r;
01846                         KPrPartObject *kppartobject = new KPrPartObject( ch );
01847                         kppartobject->loadOasis( o, context, m_loadingInfo );
01848                         r = ch->geometry();
01849                         if ( groupObject )
01850                             groupObject->addObjects( kppartobject );
01851                         else
01852                             newpage->appendObject(kppartobject);
01853                         insertChild( ch );
01854                         kppartobject->setOrig( r.x(), r.y() );
01855                         kppartobject->setSize( r.width(), r.height() );
01856                         break;
01857                     }
01858                 }
01859             }
01860             else if ( name == "rect" && isDrawNS) // rectangle
01861             {
01862                 fillStyleStack( o, context, "graphic" );
01863                 KPrRectObject *kprectobject = new KPrRectObject();
01864                 kprectobject->loadOasis(o, context , m_loadingInfo);
01865                 if ( groupObject )
01866                     groupObject->addObjects( kprectobject );
01867                 else
01868                     newpage->appendObject(kprectobject);
01869             }
01870             else if ( ( name == "circle" || name == "ellipse" )&& isDrawNS)
01871             {
01872                 fillStyleStack( o, context, "graphic" );
01873                 if ( o.hasAttributeNS( KoXmlNS::draw, "kind" ) ) // pie, chord or arc
01874                 {
01875                     KPrPieObject *kppieobject = new KPrPieObject();
01876                     kppieobject->loadOasis(o, context, m_loadingInfo);
01877                     if ( groupObject )
01878                         groupObject->addObjects( kppieobject );
01879                     else
01880                         newpage->appendObject(kppieobject);
01881                 }
01882                 else  // circle or ellipse
01883                 {
01884                     KPrEllipseObject *kpellipseobject = new KPrEllipseObject();
01885                     kpellipseobject->loadOasis(o,context, m_loadingInfo);
01886                     if ( groupObject )
01887                         groupObject->addObjects( kpellipseobject );
01888                     else
01889                         newpage->appendObject(kpellipseobject);
01890                 }
01891             }
01892             else if ( name == "line" && isDrawNS) // line
01893             {
01894                 fillStyleStack( o, context, "graphic" );
01895                 KPrLineObject *kplineobject = new KPrLineObject();
01896                 kplineobject->loadOasis(o, context, m_loadingInfo);
01897                 if ( groupObject )
01898                     groupObject->addObjects( kplineobject );
01899                 else
01900                     newpage->appendObject( kplineobject );
01901             }
01902             else if (name=="polyline" && isDrawNS) { // polyline
01903                 fillStyleStack( o, context, "graphic" );
01904                 KPrPolylineObject *kppolylineobject = new KPrPolylineObject();
01905                 kppolylineobject->loadOasis(o, context, m_loadingInfo);
01906                 if ( groupObject )
01907                     groupObject->addObjects( kppolylineobject );
01908                 else
01909                     newpage->appendObject(kppolylineobject);
01910             }
01911             else if (name=="polygon" && isDrawNS) { // plcloseobject
01912                 fillStyleStack( o, context, "graphic" );
01913                 KPrClosedLineObject *kpClosedObject = new KPrClosedLineObject();
01914                 kpClosedObject->loadOasis( o, context, m_loadingInfo);
01915                 if ( groupObject )
01916                     groupObject->addObjects( kpClosedObject );
01917                 else
01918                     newpage->appendObject(kpClosedObject);
01919             }
01920             else if (name=="regular-polygon"&& isDrawNS) { // kppolygone object
01921                 fillStyleStack( o, context, "graphic" );
01922                 KPrPolygonObject *kpPolygoneObject = new KPrPolygonObject();
01923                 kpPolygoneObject->loadOasis( o, context, m_loadingInfo);
01924                 if ( groupObject )
01925                     groupObject->addObjects( kpPolygoneObject );
01926                 else
01927                     newpage->appendObject(kpPolygoneObject);
01928             }
01929             else if ( name == "path" && isDrawNS)
01930             {
01931                 fillStyleStack( o, context, "graphic" );
01932                 QString d = o.attributeNS( KoXmlNS::svg, "d", QString::null);
01933 
01934                 KPrSVGPathParser parser;
01935                 ObjType objType = parser.getType( d );
01936 
01937                 switch ( objType )
01938                 {
01939                     case OT_CUBICBEZIERCURVE:
01940                         {
01941                             kdDebug(33001) << "Cubicbeziercurve" << endl;
01942                             KPrCubicBezierCurveObject *kpCurveObject = new KPrCubicBezierCurveObject();
01943                             kpCurveObject->loadOasis( o, context, m_loadingInfo );
01944                             if ( groupObject )
01945                                 groupObject->addObjects( kpCurveObject );
01946                             else
01947                                 newpage->appendObject( kpCurveObject );
01948                         } break;
01949                     case OT_QUADRICBEZIERCURVE:
01950                         {
01951                             kdDebug(33001) << "Quadricbeziercurve" << endl;
01952                             KPrQuadricBezierCurveObject *kpQuadricObject = new KPrQuadricBezierCurveObject();
01953                             kpQuadricObject->loadOasis( o, context, m_loadingInfo );
01954                             if ( groupObject )
01955                                 groupObject->addObjects( kpQuadricObject );
01956                             else
01957                                 newpage->appendObject( kpQuadricObject );
01958                         } break;
01959                     case OT_FREEHAND:
01960                         {
01961                             kdDebug(33001) << "Freehand" << endl;
01962                             KPrFreehandObject *kpFreeHandObject = new KPrFreehandObject();
01963                             kpFreeHandObject->loadOasis( o, context, m_loadingInfo );
01964                             if ( groupObject )
01965                                 groupObject->addObjects( kpFreeHandObject );
01966                             else
01967                                 newpage->appendObject( kpFreeHandObject );
01968                         } break;
01969                     case OT_CLOSED_LINE:
01970                         {
01971                             kdDebug(33001) << "Closed Line" << endl;
01972                             KPrClosedLineObject *kpClosedObject = new KPrClosedLineObject();
01973                             kpClosedObject->loadOasis( o, context, m_loadingInfo );
01974                             if ( groupObject )
01975                                 groupObject->addObjects( kpClosedObject );
01976                             else
01977                                 newpage->appendObject( kpClosedObject );
01978                         } break;
01979                     default:
01980                         kdDebug(33001) << "draw:path found unsupported object type " << objType << " in svg:d " << d << endl;
01981                         break;
01982                 }
01983             }
01984             else if ( name == "custom-shape" && isDrawNS )
01985             {
01986                 fillStyleStack( o, context, "graphic" );
01987 
01988                 QDomElement enhancedGeometry = KoDom::namedItemNS( o, KoXmlNS::draw, "enhanced-geometry" );
01989 
01990                 if ( !enhancedGeometry.isNull() )
01991                 {
01992                     QString d = enhancedGeometry.attributeNS( KoXmlNS::draw, "enhanced-path", QString::null );
01993                     QRegExp rx( "^([0-9 ML]+Z) N$" );
01994                     if ( rx.search( d ) != -1 )
01995                     {
01996                         d = rx.cap( 1 );
01997                         KPrSVGPathParser parser;
01998                         ObjType objType = parser.getType( d );
01999 
02000                         switch ( objType )
02001                         {
02002 #if 0 // not yet supported
02003                             case OT_CUBICBEZIERCURVE:
02004                                 {
02005                                     kdDebug(33001) << "Cubicbeziercurve" << endl;
02006                                     KPrCubicBezierCurveObject *kpCurveObject = new KPrCubicBezierCurveObject();
02007                                     kpCurveObject->loadOasis( o, context, m_loadingInfo );
02008                                     if ( groupObject )
02009                                         groupObject->addObjects( kpCurveObject );
02010                                     else
02011                                         newpage->appendObject( kpCurveObject );
02012                                 } break;
02013                             case OT_QUADRICBEZIERCURVE:
02014                                 {
02015                                     kdDebug(33001) << "Quadricbeziercurve" << endl;
02016                                     KPrQuadricBezierCurveObject *kpQuadricObject = new KPrQuadricBezierCurveObject();
02017                                     kpQuadricObject->loadOasis( o, context, m_loadingInfo );
02018                                     if ( groupObject )
02019                                         groupObject->addObjects( kpQuadricObject );
02020                                     else
02021                                         newpage->appendObject( kpQuadricObject );
02022                                 } break;
02023                             case OT_FREEHAND:
02024                                 {
02025                                     kdDebug(33001) << "Freehand" << endl;
02026                                     KPrFreehandObject *kpFreeHandObject = new KPrFreehandObject();
02027                                     kpFreeHandObject->loadOasis( o, context, m_loadingInfo );
02028                                     if ( groupObject )
02029                                         groupObject->addObjects( kpFreeHandObject );
02030                                     else
02031                                         newpage->appendObject( kpFreeHandObject );
02032                                 } break;
02033 #endif
02034                             case OT_CLOSED_LINE:
02035                                 {
02036                                     kdDebug(33001) << "Closed Line" << endl;
02037                                     KPrClosedLineObject *kpClosedObject = new KPrClosedLineObject();
02038                                     kpClosedObject->loadOasis( o, context, m_loadingInfo );
02039                                     if ( groupObject )
02040                                         groupObject->addObjects( kpClosedObject );
02041                                     else
02042                                         newpage->appendObject( kpClosedObject );
02043                                 } break;
02044                             default:
02045                                 kdDebug(33001) << "draw:custom-shape found unsupported object type " << objType << " in draw:enhanced-path " << d << endl;
02046                                 break;
02047                         }
02048                     }
02049                     else
02050                     {
02051                         kdDebug(33001) << "draw:custom-shape not supported" << endl;
02052                     }
02053                 }
02054             }
02055             else if ( name == "g" && isDrawNS)
02056             {
02057                 fillStyleStack( o, context, "graphic" );
02058                 KPrGroupObject *kpgroupobject = new KPrGroupObject();
02059                 QDomNode nodegroup = object.firstChild();
02060 
02061                 kpgroupobject->loadOasisGroupObject( this, newpage, object, context, m_loadingInfo);
02062                 if ( groupObject )
02063                     groupObject->addObjects( kpgroupobject );
02064                 else
02065                     newpage->appendObject(kpgroupobject);
02066             }
02067             else if ( name == "notes" && o.namespaceURI() == KoXmlNS::presentation ) // notes
02068             {
02069                 //we must extend note attribute
02070                 //kdDebug()<<"presentation:notes----------------------------------\n";
02071                 QDomNode frameBox = KoDom::namedItemNS( o, KoXmlNS::draw, "frame" );
02072                 QString note;
02073 
02074                 while ( !frameBox.isNull() )
02075                 {
02076                     //add an empty line between the different frames
02077                     if ( !note.isEmpty() )
02078                         note += "\n";
02079 
02080                     //todo load layout for note.
02081                     QDomNode textBox = KoDom::namedItemNS( frameBox, KoXmlNS::draw, "text-box" );
02082 
02083                     if ( !textBox.isNull() )
02084                     {
02085                         for ( QDomNode text = textBox.firstChild(); !text.isNull(); text = text.nextSibling() )
02086                         {
02087                             // We don't care about styles as they are not supported in kpresenter.
02088                             // Only add a linebreak for every child.
02089                             QDomElement t = text.toElement();
02090                             if ( t.tagName() == "p" )
02091                             {
02092                                 note += t.text() + "\n";
02093                             }
02094                         }
02095                     }
02096                     frameBox = frameBox.nextSibling();
02097                 }
02098                 newpage->setNoteText( note );
02099             }
02100             else if ( ( name == "header" || name == "footer" ) && o.namespaceURI() == KoXmlNS::style ||
02101                       ( name == "animations" && o.namespaceURI() == KoXmlNS::presentation) )
02102             {
02103                 //nothing
02104             }
02105             else
02106             {
02107                 kdDebug() << "Unsupported object '" << name << "'" << endl;
02108             }
02109             context.styleStack().restore();
02110         }
02111     }
02112 
02113 }
02114 
02115 int KPrDocument::createPresentationAnimation(const QDomElement& element, int order, bool increaseOrder)
02116 {
02117     kdDebug()<<"void KPrDocument::createPresentationAnimation(const QDomElement& element)\n";
02118     int orderAnimation = increaseOrder ? 0 : order;
02119     for ( QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() )
02120     {
02121         QDomElement e = n.toElement();
02122         QCString tagName = e.tagName().latin1();
02123         if ( ! tagName.isEmpty() ) // only tags that open
02124         {
02125             const bool isPresentationNS = e.namespaceURI() == KoXmlNS::presentation;
02126             if ( isPresentationNS &&
02127                  ( tagName == "show-shape" || tagName == "hide-shape" ) )
02128             {
02129                 Q_ASSERT( e.hasAttributeNS( KoXmlNS::draw, "shape-id" ) );
02130                 QString name = e.attributeNS( KoXmlNS::draw, "shape-id", QString::null );
02131                 kdDebug()<<" insert animation " << tagName << " name :" << name << endl;
02132 
02133                 if ( e.hasAttributeNS( KoXmlNS::koffice, "order-id" ) )
02134                 {
02135                     orderAnimation = e.attributeNS( KoXmlNS::koffice, "order-id", QString::null ).toInt();
02136                 }
02137 
02138                 lstAnimation *tmp = new lstAnimation;
02139                 tmp->element = new QDomElement( e );
02140                 tmp->order = orderAnimation;
02141                 if ( tagName == "show-shape" )
02142                 {
02143                     m_loadingInfo->storePresentationShowAnimation( tmp, name );
02144                 }
02145                 else
02146                 {
02147                     m_loadingInfo->storePresentationHideAnimation( tmp, name );
02148                 }
02149                 if ( increaseOrder )
02150                     ++orderAnimation;
02151             }
02152             else if ( tagName == "animation-group" && isPresentationNS )
02153             {
02154                 orderAnimation = createPresentationAnimation( e, orderAnimation, false );
02155             }
02156         }
02157     }
02158     //increase when we finish it necessary for group object
02159     ++orderAnimation;
02160     return orderAnimation;
02161 }
02162 
02163 void KPrDocument::fillStyleStack( const QDomElement& object, KoOasisContext & context, const char* family )
02164 {
02165     if ( object.hasAttributeNS( KoXmlNS::presentation, "style-name" ))
02166     {
02167         context.fillStyleStack( object, KoXmlNS::presentation, "style-name", family );
02168     }
02169     if ( object.hasAttributeNS( KoXmlNS::draw, "style-name" ) )
02170     {
02171         context.fillStyleStack( object, KoXmlNS::draw, "style-name", family );
02172     }
02173     if ( object.hasAttributeNS( KoXmlNS::draw, "text-style-name" ) )
02174     {
02175         context.fillStyleStack( object, KoXmlNS::draw, "text-style-name", family );
02176     }
02177     if ( object.hasAttributeNS( KoXmlNS::text, "style-name" ) )
02178     {
02179         context.fillStyleStack( object, KoXmlNS::text, "style-name", family );
02180     }
02181 }
02182 
02183 bool KPrDocument::loadXML( QIODevice * dev, const QDomDocument& doc )
02184 {
02185     QTime dt;
02186     dt.start();
02187     m_loadingInfo = new KPrLoadingInfo( true );
02188 
02189     ignoreSticky = FALSE;
02190     bool b=false;
02191     QDomElement docelem = doc.documentElement();
02192     const int syntaxVersion = docelem.attribute( "syntaxVersion" ).toInt();
02193     if ( syntaxVersion < 2 )
02194     {
02195         // This is an old style document, before the current TextObject
02196         // We have kprconverter.pl for it
02197         kdWarning(33001) << "KPresenter document version 1. Launching perl script to convert it." << endl;
02198 
02199         // Read the full XML and write it to a temp file
02200         KTempFile tmpFileIn;
02201         tmpFileIn.setAutoDelete( true );
02202         dev->reset();
02203         tmpFileIn.file()->writeBlock( dev->readAll() ); // copy stresm to temp file
02204         tmpFileIn.close();
02205 
02206         // Launch the perl script on it
02207         KTempFile tmpFileOut;
02208         tmpFileOut.setAutoDelete( true );
02209         QString cmd = KGlobal::dirs()->findExe("perl");
02210         if (cmd.isEmpty())
02211         {
02212             setErrorMessage( i18n("You don't appear to have PERL installed.\nIt is needed to convert this document.\nPlease install PERL and try again."));
02213             return false;
02214         }
02215         cmd += " ";
02216         cmd += locate( "exe", "kprconverter.pl" );
02217         cmd += " ";
02218         cmd += KProcess::quote( tmpFileIn.name() );
02219         cmd += " ";
02220         cmd += KProcess::quote( tmpFileOut.name() );
02221         system( QFile::encodeName(cmd) );
02222 
02223         // Build a new QDomDocument from the result
02224         QString errorMsg;
02225         int errorLine;
02226         int errorColumn;
02227         QDomDocument newdoc;
02228         if ( ! newdoc.setContent( tmpFileOut.file(), &errorMsg, &errorLine, &errorColumn ) )
02229         {
02230             kdError (33001) << "Parsing Error! Aborting! (in KPrDocument::loadXML)" << endl
02231                             << "  Line: " << errorLine << " Column: " << errorColumn << endl
02232                             << "  Message: " << errorMsg << endl;
02233             setErrorMessage( i18n( "parsing error in the main document (converted from an old KPresenter format) at line %1, column %2\nError message: %3" )
02234                              .arg( errorLine ).arg( errorColumn ).arg( i18n ( errorMsg.utf8() ) ) );
02235             return false;
02236         }
02237         b = loadXML( newdoc );
02238     }
02239     else
02240         b = loadXML( doc );
02241 
02242     ignoreSticky = TRUE;
02243 
02244     if(_clean)
02245     {
02246         startBackgroundSpellCheck();
02247     }
02248     if ( m_pageWhereLoadObject == 0 && m_insertFilePage == 0 )
02249         setModified( false );
02250     kdDebug(33001) << "Loading took " << (float)(dt.elapsed()) / 1000.0 << " seconds" << endl;
02251     return b;
02252 }
02253 
02254 void KPrDocument::createHeaderFooter()
02255 {
02256     //add header/footer to sticky page
02257     KoRect pageRect=m_masterPage->getPageRect();
02258     _header->setOrig(pageRect.topLeft());
02259     _header->setSize(pageRect.width(),20);
02260 
02261     _footer->setOrig(pageRect.left(),pageRect.bottom()-20);
02262     _footer->setSize(pageRect.width(),20);
02263 
02264     m_masterPage->appendObject(_header);
02265     m_masterPage->appendObject(_footer);
02266 }
02267 
02268 void KPrDocument::insertEmbedded( KoStore *store, QDomElement topElem, KMacroCommand * macroCmd, KPrPage *page, int pos )
02269 {
02270     QDomElement elem = topElem.firstChild().toElement();
02271     for ( ; !elem.isNull() ; elem = elem.nextSibling().toElement() )
02272     {
02273         kdDebug(33001) << "Element name: " << elem.tagName() << endl;
02274         if(elem.tagName()=="EMBEDDED") {
02275             KPrChild *ch = new KPrChild( this );
02276             KPrPartObject *kppartobject = 0L;
02277             QRect r;
02278 
02279             QDomElement object=elem.namedItem("OBJECT").toElement();
02280             if(!object.isNull()) {
02281                 ch->load(object, true);  // true == uppercase
02282                 r = ch->geometry();
02283                 ch->loadDocument( store );
02284                 insertChild( ch );
02285                 kppartobject = new KPrPartObject( ch );
02286             }
02287             QDomElement settings=elem.namedItem("SETTINGS").toElement();
02288             int zIndex = 0;
02289             if ( settings.hasAttribute( "z-index" ) )
02290             {
02291                 zIndex = settings.attribute( "z-index" ).toInt();
02292             }
02293             double offset = 0.0;
02294             if(!settings.isNull() && kppartobject!=0)
02295                 offset=kppartobject->load(settings);
02296             else if ( settings.isNull() ) // all embedded obj must have SETTING tags
02297             {
02298                 delete kppartobject;
02299                 kppartobject = 0L;
02300                 return;
02301             }
02302             int index = m_pageList.findRef(page);
02303             int pageIndex = (int)(offset/__pgLayout.ptHeight)+index;
02304             int newPos=(int)((offset+index*__pgLayout.ptHeight)-pageIndex*__pgLayout.ptHeight);
02305             kppartobject->setOrig(kppartobject->getOrig().x(),newPos);
02306 
02307             KPrInsertCmd *insertCmd = new KPrInsertCmd( i18n( "Insert Part Object" ), kppartobject, this,page );
02308             insertCmd->execute();
02309             if ( !macroCmd )
02310                 macroCmd = new KMacroCommand( i18n("Insert Part Object"));
02311             macroCmd->addCommand( insertCmd );
02312             if ( pos != 0 )
02313             {
02314                 const QPtrList<KPrObject>& oldList( page->objectList() );
02315                 // tz TODO this is not 100% correct
02316                 if ( static_cast<int>( oldList.count() ) > pos + zIndex )
02317                 {
02318                     page->takeObject( kppartobject );
02319                     page->insertObject( kppartobject, pos + zIndex );
02320                     KPrLowerRaiseCmd *lrCmd = new KPrLowerRaiseCmd( i18n("Insert Part Object"),
02321                                                               oldList, page->objectList(),
02322                                                               this, page );
02323                     macroCmd->addCommand( lrCmd );
02324                 }
02325             }
02326         }
02327     }
02328 }
02329 
02330 bool KPrDocument::loadXML( const QDomDocument &doc )
02331 {
02332     emit sigProgress( 0 );
02333     int activePage=0;
02334     lastObj = -1;
02335     bool allSlides = false;
02336     // clean
02337     if ( _clean ) {
02338         __pgLayout = KoPageLayout::standardLayout();
02339         _spInfiniteLoop = false;
02340         _spManualSwitch = true;
02341         _showPresentationDuration = false;
02342         _xRnd = 20;
02343         _yRnd = 20;
02344         //_txtBackCol = white;
02345         urlIntern = url().path();
02346     }
02347     else
02348         m_spellCheckIgnoreList.clear();
02349     emit sigProgress( 5 );
02350 
02351     QDomElement document=doc.documentElement();
02352     // DOC
02353     if(document.tagName()!="DOC") {
02354         kdWarning(33001) << "Missing DOC" << endl;
02355         setErrorMessage( i18n("Invalid document, DOC tag missing.") );
02356         return false;
02357     }
02358 
02359     if(!document.hasAttribute("mime") ||  (
02360            document.attribute("mime")!="application/x-kpresenter" &&
02361            document.attribute("mime")!="application/vnd.kde.kpresenter" ) ) {
02362         kdError(33001) << "Unknown mime type " << document.attribute("mime") << endl;
02363         setErrorMessage( i18n("Invalid document, expected mimetype application/x-kpresenter or application/vnd.kde.kpresenter, got %1").arg(document.attribute("mime")) );
02364         return false;
02365     }
02366     if(document.hasAttribute("url"))
02367         urlIntern=KURL(document.attribute("url")).path();
02368 
02369     emit sigProgress( 10 );
02370 
02371     QDomElement elem=document.firstChild().toElement();
02372 
02373     uint childTotalCount=document.childNodes().count();
02374     uint childCount = 0;
02375 
02376     loadTextStyle( document );
02377 
02378     while(!elem.isNull()) {
02379         kdDebug(33001) << "Element name: " << elem.tagName() << endl;
02380         if(elem.tagName()=="EMBEDDED") {
02381             KPrChild *ch = new KPrChild( this );
02382             KPrPartObject *kppartobject = 0L;
02383             QRect r;
02384 
02385             QDomElement object=elem.namedItem("OBJECT").toElement();
02386             if(!object.isNull()) {
02387                 ch->load(object, true);  // true == uppercase
02388                 r = ch->geometry();
02389                 insertChild( ch );
02390                 kppartobject = new KPrPartObject( ch );
02391                 //emit sig_insertObject( ch, kppartobject );
02392             }
02393             QDomElement settings=elem.namedItem("SETTINGS").toElement();
02394             int tmp=0;
02395             int pos = -1;
02396             if ( settings.hasAttribute( "z-index" ) )
02397             {
02398                 pos = settings.attribute( "z-index" ).toInt();
02399             }
02400             if(settings.hasAttribute("sticky"))
02401                 tmp=settings.attribute("sticky").toInt();
02402             bool sticky=static_cast<bool>(tmp);
02403             double offset = 0.0;
02404             if(!settings.isNull() && kppartobject!=0)
02405             {
02406                 offset=kppartobject->load(settings);
02407             }
02408             else if ( settings.isNull() ) // all embedded obj must have SETTING tags
02409             {
02410                 delete kppartobject;
02411                 kppartobject = 0L;
02412             }
02413             //hack for some old file, they don't have ORIG tag !
02414             if ( offset == -1.0 )
02415                 offset = r.y();
02416             if ( sticky && !ignoreSticky && kppartobject )
02417             {
02418                 if ( pos == -1 )
02419                 {
02420                     m_masterPage->appendObject( kppartobject );
02421                 }
02422                 else
02423                 {
02424                     m_masterPage->insertObject( kppartobject, pos );
02425                 }
02426                 kppartobject->setOrig(kppartobject->getOrig().x(), offset);
02427             }
02428             else if ( kppartobject ) {
02429                 if ( m_pageWhereLoadObject )
02430                 {
02431                     kppartobject->setOrig(kppartobject->getOrig().x(), offset);
02432                     m_pageWhereLoadObject->insertObject( kppartobject, pos );
02433                 }
02434                 else
02435                 {
02436                     insertObjectInPage( offset, kppartobject, pos );
02437                 }
02438             }
02439         } else if(elem.tagName()=="PAPER" && _clean)  {
02440             if(elem.hasAttribute("format"))
02441                 __pgLayout.format=static_cast<KoFormat>(elem.attribute("format").toInt());
02442             if(elem.hasAttribute("orientation"))
02443                 __pgLayout.orientation=static_cast<KoOrientation>(elem.attribute("orientation").toInt());
02444             if(elem.hasAttribute("ptWidth"))
02445                 __pgLayout.ptWidth = elem.attribute("ptWidth").toDouble();
02446             else if(elem.hasAttribute("inchWidth"))  //compatibility
02447                 __pgLayout.ptWidth = INCH_TO_POINT( elem.attribute("inchWidth").toDouble() );
02448             else if(elem.hasAttribute("mmWidth"))    //compatibility
02449                 __pgLayout.ptWidth = MM_TO_POINT( elem.attribute("mmWidth").toDouble() );
02450             if(elem.hasAttribute("ptHeight"))
02451                 __pgLayout.ptHeight = elem.attribute("ptHeight").toDouble();
02452             else if(elem.hasAttribute("inchHeight")) //compatibility
02453                 __pgLayout.ptHeight = INCH_TO_POINT( elem.attribute("inchHeight").toDouble() );
02454             else if(elem.hasAttribute("mmHeight"))   //compatibility
02455                 __pgLayout.ptHeight = MM_TO_POINT( elem.attribute("mmHeight").toDouble() );
02456             if(elem.hasAttribute("unit"))
02457                 setUnit( static_cast<KoUnit::Unit>(elem.attribute("unit").toInt()) );
02458             if ( elem.hasAttribute("tabStopValue"))
02459                 m_tabStop = elem.attribute("tabStopValue").toDouble();
02460 
02461             if(elem.hasAttribute("width"))
02462                 __pgLayout.ptWidth = MM_TO_POINT( elem.attribute("width").toDouble() );
02463             if(elem.hasAttribute("height"))
02464                 __pgLayout.ptHeight = MM_TO_POINT( elem.attribute("height").toDouble() );
02465 
02466             QDomElement borders=elem.namedItem("PAPERBORDERS").toElement();
02467             if(!borders.isNull()) {
02468                 if(borders.hasAttribute("left"))
02469                     __pgLayout.ptLeft = MM_TO_POINT( borders.attribute("left").toDouble() );
02470                 if(borders.hasAttribute("top"))
02471                     __pgLayout.ptTop = MM_TO_POINT( borders.attribute("top").toDouble() );
02472                 if(borders.hasAttribute("right"))
02473                     __pgLayout.ptRight = MM_TO_POINT( borders.attribute("right").toDouble() );
02474                 if(borders.hasAttribute("bottom"))
02475                     __pgLayout.ptBottom = MM_TO_POINT( borders.attribute("bottom").toDouble() );
02476                 if(borders.hasAttribute("ptLeft"))
02477                     __pgLayout.ptLeft = borders.attribute("ptLeft").toDouble();
02478                 else if(borders.hasAttribute("inchLeft"))    //compatibility
02479                     __pgLayout.ptLeft = INCH_TO_POINT( borders.attribute("inchLeft").toDouble() );
02480                 else if(borders.hasAttribute("mmLeft"))      //compatibility
02481                     __pgLayout.ptLeft = MM_TO_POINT( borders.attribute("mmLeft").toDouble() );
02482                 if(borders.hasAttribute("ptRight"))
02483                     __pgLayout.ptRight = borders.attribute("ptRight").toDouble();
02484                 else if(borders.hasAttribute("inchRight"))   //compatibility
02485                     __pgLayout.ptRight = INCH_TO_POINT( borders.attribute("inchRight").toDouble() );
02486                 else if(borders.hasAttribute("mmRight"))     //compatibility
02487                     __pgLayout.ptRight = MM_TO_POINT( borders.attribute("mmRight").toDouble() );
02488                 if(borders.hasAttribute("ptTop"))
02489                     __pgLayout.ptTop = borders.attribute("ptTop").toDouble();
02490                 else if(borders.hasAttribute("inchTop"))     //compatibility
02491                     __pgLayout.ptTop = INCH_TO_POINT( borders.attribute("inchTop").toDouble() );
02492                 else if(borders.hasAttribute("mmTop"))       //compatibility
02493                     __pgLayout.ptTop = MM_TO_POINT( borders.attribute("mmTop").toDouble() );
02494                 if(borders.hasAttribute("ptBottom"))
02495                     __pgLayout.ptBottom = borders.attribute("ptBottom").toDouble();
02496                 else if(borders.hasAttribute("inchBottom"))  //compatibility
02497                     __pgLayout.ptBottom = INCH_TO_POINT( borders.attribute("inchBottom").toDouble() );
02498                 else if(borders.hasAttribute("mmBottom"))    //compatibility
02499                     __pgLayout.ptBottom = MM_TO_POINT( borders.attribute("inchBottom").toDouble() );
02500             }
02501             // PAPER found and parsed -> apply page layout
02502             // e.g. the text objects need it
02503             if ( _clean )
02504                 setPageLayout( __pgLayout );
02505 
02506         } else if(elem.tagName()=="VARIABLESETTINGS" && _clean){
02507             getVariableCollection()->variableSetting()->load(document);
02508             //by default display real variable value
02509             if ( !isReadWrite())
02510                 getVariableCollection()->variableSetting()->setDisplayFieldCode(false);
02511 
02512         }
02513         else if(elem.tagName()=="BACKGROUND") {
02514             int red=0, green=0, blue=0;
02515             if(elem.hasAttribute("xRnd"))
02516                 _xRnd = elem.attribute("xRnd").toInt();
02517             if(elem.hasAttribute("yRnd"))
02518                 _yRnd = elem.attribute("yRnd").toInt();
02519             if(elem.hasAttribute("bred"))
02520                 red = elem.attribute("bred").toInt();
02521             if(elem.hasAttribute("bgreen"))
02522                 green = elem.attribute("bgreen").toInt();
02523             if(elem.hasAttribute("bblue"))
02524                 blue = elem.attribute("bblue").toInt();
02525             loadBackground(elem);
02526         } else if(elem.tagName()=="HEADER") {
02527             if ( _clean /*don't reload header footer, header/footer was created at the beginning || !hasHeader()*/ ) {
02528                 if(elem.hasAttribute("show")) {
02529                     setHeader(static_cast<bool>(elem.attribute("show").toInt()));
02530                 }
02531                 _header->load(elem);
02532             }
02533         } else if ( elem.tagName()=="HEADERFOOTERBYPAGE" ) {
02534             if ( elem.hasAttribute( "value" ) ) {
02535                 m_loadingInfo->m_headerFooterByPage = true;
02536             }
02537         } else if(elem.tagName()=="FOOTER") {
02538             if ( _clean /*|| !hasFooter()*/ ) {
02539                 if(elem.hasAttribute("show")) {
02540                     setFooter( static_cast<bool>(elem.attribute("show").toInt() ) );
02541                 }
02542                 _footer->load(elem);
02543             }
02544         }else if( elem.tagName()=="HELPLINES"){
02545             if ( _clean  ) {
02546                 if(elem.hasAttribute("show")) {
02547                     setShowGuideLines( static_cast<bool>(elem.attribute("show").toInt() ) );
02548                 }
02549                 loadGuideLines( elem );
02550             }
02551         }else if( elem.tagName()=="SPELLCHECKIGNORELIST"){
02552             QDomElement spellWord=elem.toElement();
02553             spellWord=spellWord.firstChild().toElement();
02554             while ( !spellWord.isNull() )
02555             {
02556                 if ( spellWord.tagName()=="SPELLCHECKIGNOREWORD" )
02557                 {
02558                     m_spellCheckIgnoreList.append(spellWord.attribute("word"));
02559                 }
02560                 spellWord=spellWord.nextSibling().toElement();
02561             }
02562         }else if(elem.tagName()=="ATTRIBUTES" && _clean) {
02563             if(elem.hasAttribute("activePage"))
02564                 activePage=elem.attribute("activePage").toInt();
02565             if(elem.hasAttribute("gridx"))
02566                 m_gridX = elem.attribute("gridx").toDouble();
02567             if(elem.hasAttribute("gridy"))
02568                 m_gridY = elem.attribute("gridy").toDouble();
02569             if(elem.hasAttribute("snaptogrid"))
02570                 m_bSnapToGrid = (bool)elem.attribute("snaptogrid").toInt();
02571         } else if(elem.tagName()=="PAGETITLES") {
02572             loadTitle(elem);
02573         } else if(elem.tagName()=="PAGENOTES") {
02574             loadNote(elem);
02575         } else if(elem.tagName()=="OBJECTS") {
02576             //FIXME**********************
02577 #if 0
02578             lastObj = _objectList->count() - 1;
02579 #endif
02580             //don't add command we don't paste object
02581             KCommand * cmd =loadObjects(elem);
02582             if ( cmd )
02583                 delete cmd;
02584         } else if(elem.tagName()=="INFINITLOOP") {
02585             if(_clean) {
02586                 if(elem.hasAttribute("value"))
02587                     _spInfiniteLoop = static_cast<bool>(elem.attribute("value").toInt());
02588             }
02589         } else if(elem.tagName()=="PRESSPEED") {
02590             if(_clean) {
02591                 if(elem.hasAttribute("value"))
02592                     m_loadingInfo->presSpeed = elem.attribute("value").toInt();
02593             }
02594         } else if(elem.tagName()=="MANUALSWITCH") {
02595             if(_clean) {
02596                 if(elem.hasAttribute("value"))
02597                     _spManualSwitch = static_cast<bool>(elem.attribute("value").toInt());
02598             }
02599         } else if(elem.tagName()=="SHOWPRESENTATIONDURATION") {
02600             if(_clean) {
02601                 if(elem.hasAttribute("value"))
02602                     _showPresentationDuration = static_cast<bool>(elem.attribute("value").toInt());
02603             }
02604         } else if(elem.tagName()=="PRESSLIDES") {
02605             if(elem.hasAttribute("value") && elem.attribute("value").toInt()==0)
02606                 allSlides = TRUE;
02607         } else if ( elem.tagName()=="DEFAULTCUSTOMSLIDESHOWNAME" ) {
02608             if(elem.hasAttribute("name") )
02609                 m_presentationName=elem.attribute( "name" );
02610         } else if ( elem.tagName()=="CUSTOMSLIDESHOWCONFIG" ) {
02611             if ( _clean ) {
02612                 QMap<QString, KPrPage *> name2page;
02613                 int pos = 1;
02614                 for ( QPtrListIterator<KPrPage> it( m_pageList ); it.current(); ++it )
02615                 {
02616                     name2page.insert( "page" + QString::number( pos++ ), it.current() ) ;
02617                 }
02618 
02619                 QDomElement slide=elem.firstChild().toElement();
02620                 while(!slide.isNull()) {
02621                     if(slide.tagName()=="CUSTOMSLIDESHOW") {
02622                         QStringList tmp = QStringList::split( ",", slide.attribute( "pages" ) );
02623                         QValueList<KPrPage *> pageList;
02624                         for ( QStringList::Iterator it = tmp.begin(); it != tmp.end(); ++it )
02625                         {
02626                             if ( name2page.contains( *it ) )
02627                             {
02628                                 kdDebug(33001) << "slide show " << slide.attribute( "name" ) << " page = " << *it << endl;
02629                                 pageList.push_back( name2page[*it] );
02630                             }
02631                         }
02632                         if ( ! pageList.empty() )
02633                         {
02634                             m_customListSlideShow.insert( slide.attribute( "name" ), pageList );
02635                         }
02636                     }
02637                     slide=slide.nextSibling().toElement();
02638                 }
02639             }
02640         } else if(elem.tagName()=="SELSLIDES") {
02641             if( _clean ) { // Skip this when loading a single page
02642                 QDomElement slide=elem.firstChild().toElement();
02643                 while(!slide.isNull()) {
02644                     if(slide.tagName()=="SLIDE") {
02645                         int nr = -1;
02646                         bool show = false;
02647                         if(slide.hasAttribute("nr"))
02648                             nr=slide.attribute("nr").toInt();
02649                         if(slide.hasAttribute("show"))
02650                             show=static_cast<bool>(slide.attribute("show").toInt());
02651                         if ( nr >= 0 )
02652                         {
02653                             //kdDebug(33001) << "KPrDocument::loadXML m_selectedSlides nr=" << nr << " show=" << show << endl;
02654                             if ( nr > ( (int)m_pageList.count() - 1 ) )
02655                             {
02656                                 for (int i=(m_pageList.count()-1); i<nr;i++)
02657                                     m_pageList.append( new KPrPage( this, m_masterPage ) );
02658                             }
02659                             m_pageList.at(nr)->slideSelected(show);
02660                         } else kdWarning(33001) << "Parse error. No nr in <SLIDE> !" << endl;
02661                     }
02662                     slide=slide.nextSibling().toElement();
02663                 }
02664             }
02665         } else if ( elem.tagName() == "SOUNDS" ) {
02666             loadUsedSoundFileFromXML( elem );
02667         }
02668         elem=elem.nextSibling().toElement();
02669 
02670         emit sigProgress( childCount * ( 70/childTotalCount ) + 15 );
02671         childCount += 1;
02672     }
02673 
02674     loadPictureMap( document );
02675 
02676     if(activePage!=-1)
02677         m_initialActivePage=m_pageList.at(activePage);
02678     if ( m_pageWhereLoadObject == 0 && m_insertFilePage == 0 )
02679         setModified(false);
02680 
02681     return true;
02682 }
02683 
02684 void KPrDocument::loadTextStyle( const QDomElement& domElement )
02685 {
02686     QDomElement style = domElement.namedItem( "STYLES" ).toElement();
02687     if ( _clean && ! style.isNull() )
02688         loadStyleTemplates( style );
02689 }
02690 
02691 void KPrDocument::loadPictureMap ( const QDomElement& domElement )
02692 {
02693     m_pictureMap.clear();
02694 
02695     // <PICTURES>
02696     QDomElement picturesElem = domElement.namedItem( "PICTURES" ).toElement();
02697     if ( !picturesElem.isNull() )
02698         m_pictureCollection.readXML( picturesElem, m_pictureMap );
02699 
02700     // <PIXMAPS>
02701     QDomElement pixmapsElem = domElement.namedItem( "PIXMAPS" ).toElement();
02702     if ( !pixmapsElem.isNull() )
02703         m_pictureCollection.readXML( pixmapsElem, m_pictureMap );
02704 
02705     // <CLIPARTS>
02706     QDomElement clipartsElem = domElement.namedItem( "CLIPARTS" ).toElement();
02707     if ( !clipartsElem.isNull() )
02708         m_pictureCollection.readXML( pixmapsElem, m_pictureMap );
02709 }
02710 
02711 void KPrDocument::loadBackground( const QDomElement &element )
02712 {
02713     kdDebug(33001) << "KPrDocument::loadBackground" << endl;
02714     QDomElement page=element.firstChild().toElement();
02715     int i=m_insertFilePage;
02716     while(!page.isNull()) {
02717         if(m_pageWhereLoadObject)
02718         {
02719             kdDebug(33001) << "m_pageWhereLoadObject->load(...)" << m_pageWhereLoadObject <<  endl;
02720             m_pageWhereLoadObject->load(page);
02721             break;
02722         }
02723         else
02724         {
02725             if ( page.tagName() == "MASTERPAGE" )
02726             {
02727                 m_masterPage->load( page );
02728             }
02729             else
02730             {
02731                 //test if there is a page at this index
02732                 //=> don't add new page if there is again a page
02733                 if ( i > ( (int)m_pageList.count() - 1 ) )
02734                     m_pageList.append( new KPrPage( this, m_masterPage ) );
02735                 m_pageList.at(i)->load(page);
02736                 i++;
02737             }
02738         }
02739         page=page.nextSibling().toElement();
02740     }
02741 }
02742 
02743 KCommand *KPrDocument::loadObjects( const QDomElement &element, bool paste )
02744 {
02745     ObjType t = OT_LINE;
02746     QDomElement obj=element.firstChild().toElement();
02747     QValueList<KPrObject *> pasteObjects;
02748     while(!obj.isNull()) {
02749         if(obj.tagName()=="OBJECT" ) {
02750             bool sticky=false;
02751             int tmp=0;
02752             if(obj.hasAttribute("type"))
02753                 tmp=obj.attribute("type").toInt();
02754             t=static_cast<ObjType>(tmp);
02755             tmp=0;
02756             if(obj.hasAttribute("sticky"))
02757                 tmp=obj.attribute("sticky").toInt();
02758             sticky=static_cast<bool>(tmp);
02759             double offset=0;
02760             switch ( t ) {
02761             case OT_LINE: {
02762                 KPrLineObject *kplineobject = new KPrLineObject();
02763                 offset=kplineobject->load(obj);
02764                 if ( sticky && !ignoreSticky)
02765                 {
02766                     m_masterPage->appendObject(kplineobject);
02767                     kplineobject->setOrig(kplineobject->getOrig().x(),offset);
02768                 }
02769                 else if (m_pageWhereLoadObject && paste) {
02770                     kplineobject->setOrig(kplineobject->getOrig().x(),offset);
02771                     pasteObjects.append( kplineobject );
02772                 }
02773                 else if( m_pageWhereLoadObject &&!paste)
02774                 {
02775                     m_pageWhereLoadObject->appendObject(kplineobject);
02776                     kplineobject->setOrig(kplineobject->getOrig().x(),offset);
02777                 }
02778                 else
02779                     insertObjectInPage(offset, kplineobject);
02780             } break;
02781             case OT_RECT: {
02782                 KPrRectObject *kprectobject = new KPrRectObject();
02783                 offset=kprectobject->load(obj);
02784                 if ( sticky && !ignoreSticky)
02785                 {
02786                     m_masterPage->appendObject(kprectobject);
02787                     kprectobject->setOrig(kprectobject->getOrig().x(),offset);
02788                 }
02789                 else if (m_pageWhereLoadObject && paste) {
02790                     kprectobject->setOrig(kprectobject->getOrig().x(),offset);
02791                     pasteObjects.append( kprectobject );
02792                 }
02793                 else if( m_pageWhereLoadObject &&!paste)
02794                 {
02795                     m_pageWhereLoadObject->appendObject(kprectobject);
02796                     kprectobject->setOrig(kprectobject->getOrig().x(),offset);
02797                 }
02798                 else
02799                     insertObjectInPage(offset, kprectobject);
02800             } break;
02801             case OT_ELLIPSE: {
02802                 KPrEllipseObject *kpellipseobject = new KPrEllipseObject();
02803                 offset=kpellipseobject->load(obj);
02804                 if ( sticky && !ignoreSticky)
02805                 {
02806                     m_masterPage->appendObject(kpellipseobject);
02807                     kpellipseobject->setOrig(kpellipseobject->getOrig().x(),offset);
02808                 }
02809                 else if ( m_pageWhereLoadObject && paste)
02810                 {
02811                     kpellipseobject->setOrig(kpellipseobject->getOrig().x(),offset);
02812                     pasteObjects.append( kpellipseobject );
02813                 }
02814                 else if( m_pageWhereLoadObject &&!paste)
02815                 {
02816                     m_pageWhereLoadObject->appendObject(kpellipseobject);
02817                     kpellipseobject->setOrig(kpellipseobject->getOrig().x(),offset);
02818                 }
02819                 else
02820                     insertObjectInPage(offset, kpellipseobject);
02821             } break;
02822             case OT_PIE: {
02823                 KPrPieObject *kppieobject = new KPrPieObject();
02824                 offset=kppieobject->load(obj);
02825                 if ( sticky && !ignoreSticky)
02826                 {
02827                     m_masterPage->appendObject(kppieobject);
02828                     kppieobject->setOrig(kppieobject->getOrig().x(),offset);
02829                 }
02830                 else if ( m_pageWhereLoadObject && paste) {
02831                     kppieobject->setOrig(kppieobject->getOrig().x(),offset);
02832                     pasteObjects.append( kppieobject );
02833                 }
02834                 else if( m_pageWhereLoadObject &&!paste)
02835                 {
02836                     m_pageWhereLoadObject->appendObject(kppieobject);
02837                     kppieobject->setOrig(kppieobject->getOrig().x(),offset);
02838                 }
02839                 else
02840                     insertObjectInPage(offset, kppieobject);
02841             } break;
02842             case OT_AUTOFORM: {
02843                 KPrAutoformObject *kpautoformobject = new KPrAutoformObject();
02844                 offset=kpautoformobject->load(obj);
02845                 if ( sticky && !ignoreSticky)
02846                 {
02847                     m_masterPage->appendObject(kpautoformobject);
02848                     kpautoformobject->setOrig(kpautoformobject->getOrig().x(),offset);
02849                 }
02850                 else if ( m_pageWhereLoadObject&& paste) {
02851                     kpautoformobject->setOrig(kpautoformobject->getOrig().x(),offset);
02852                     pasteObjects.append( kpautoformobject );
02853                 }
02854                 else if( m_pageWhereLoadObject &&!paste)
02855                 {
02856                     m_pageWhereLoadObject->appendObject(kpautoformobject);
02857                     kpautoformobject->setOrig(kpautoformobject->getOrig().x(),offset);
02858                 }
02859                 else
02860                     insertObjectInPage(offset, kpautoformobject);
02861             } break;
02862             case OT_TEXT: {
02863                 KPrTextObject *kptextobject = new KPrTextObject( this );
02864                 offset=kptextobject->load(obj);
02865                 if ( sticky && !ignoreSticky)
02866                 {
02867                     m_masterPage->appendObject(kptextobject);
02868                     kptextobject->setOrig(kptextobject->getOrig().x(),offset);
02869                 }
02870                 else if ( m_pageWhereLoadObject && paste) {
02871                     kptextobject->setOrig(kptextobject->getOrig().x(),offset);
02872                     pasteObjects.append( kptextobject );
02873                 }
02874                 else if( m_pageWhereLoadObject &&!paste)
02875                 {
02876                     m_pageWhereLoadObject->appendObject(kptextobject);
02877                     kptextobject->setOrig(kptextobject->getOrig().x(),offset);
02878                 }
02879                 else
02880                     insertObjectInPage(offset, kptextobject);
02881             } break;
02882             case OT_CLIPART:
02883             case OT_PICTURE: {
02884                 KPrPixmapObject *kppixmapobject = new KPrPixmapObject( pictureCollection() );
02885                 offset=kppixmapobject->load(obj);
02886                 if ( sticky && !ignoreSticky)
02887                 {
02888                     m_masterPage->appendObject(kppixmapobject);
02889                     kppixmapobject->setOrig(kppixmapobject->getOrig().x(),offset);
02890                 }
02891                 else if ( m_pageWhereLoadObject && paste) {
02892                     kppixmapobject->setOrig(kppixmapobject->getOrig().x(),offset);
02893                     pasteObjects.append( kppixmapobject );
02894                     kppixmapobject->reload();
02895                 }
02896                 else if( m_pageWhereLoadObject &&!paste)
02897                 {
02898                     m_pageWhereLoadObject->appendObject(kppixmapobject);
02899                     kppixmapobject->setOrig(kppixmapobject->getOrig().x(),offset);
02900                 }
02901                 else
02902                     insertObjectInPage(offset, kppixmapobject);
02903             } break;
02904             case OT_FREEHAND: {
02905                 KPrFreehandObject *kpfreehandobject = new KPrFreehandObject();
02906                 offset=kpfreehandobject->load(obj);
02907 
02908                 if ( sticky && !ignoreSticky)
02909                 {
02910                     m_masterPage->appendObject(kpfreehandobject);
02911                     kpfreehandobject->setOrig(kpfreehandobject->getOrig().x(),offset);
02912                 }
02913                 else if ( m_pageWhereLoadObject && paste) {
02914                     kpfreehandobject->setOrig(kpfreehandobject->getOrig().x(),offset);
02915                     pasteObjects.append( kpfreehandobject );
02916                 }
02917                 else if( m_pageWhereLoadObject &&!paste)
02918                 {
02919                     m_pageWhereLoadObject->appendObject(kpfreehandobject);
02920                     kpfreehandobject->setOrig(kpfreehandobject->getOrig().x(),offset);
02921                 }
02922                 else
02923                     insertObjectInPage(offset,kpfreehandobject);
02924             } break;
02925             case OT_POLYLINE: {
02926                 KPrPolylineObject *kppolylineobject = new KPrPolylineObject();
02927                 offset=kppolylineobject->load(obj);
02928                 if ( sticky && !ignoreSticky)
02929                 {
02930                     m_masterPage->appendObject(kppolylineobject);
02931                     kppolylineobject->setOrig(kppolylineobject->getOrig().x(),offset);
02932                 }
02933                 else if (m_pageWhereLoadObject && paste) {
02934                     kppolylineobject->setOrig(kppolylineobject->getOrig().x(),offset);
02935                     pasteObjects.append( kppolylineobject );
02936                 }
02937                 else if( m_pageWhereLoadObject &&!paste)
02938                 {
02939                     m_pageWhereLoadObject->appendObject(kppolylineobject);
02940                     kppolylineobject->setOrig(kppolylineobject->getOrig().x(),offset);
02941                 }
02942                 else
02943                     insertObjectInPage(offset, kppolylineobject);
02944             } break;
02945             case OT_QUADRICBEZIERCURVE: {
02946                 KPrQuadricBezierCurveObject *kpQuadricBezierCurveObject = new KPrQuadricBezierCurveObject();
02947                 offset=kpQuadricBezierCurveObject->load(obj);
02948                 if ( sticky && !ignoreSticky)
02949                 {
02950                     m_masterPage->appendObject(kpQuadricBezierCurveObject);
02951                     kpQuadricBezierCurveObject->setOrig(kpQuadricBezierCurveObject->getOrig().x(),offset);
02952                 }
02953                 else if ( m_pageWhereLoadObject && paste) {
02954                     kpQuadricBezierCurveObject->setOrig(kpQuadricBezierCurveObject->getOrig().x(),offset);
02955                     pasteObjects.append( kpQuadricBezierCurveObject );
02956                 }
02957                 else if( m_pageWhereLoadObject &&!paste)
02958                 {
02959                     m_pageWhereLoadObject->appendObject(kpQuadricBezierCurveObject);
02960                     kpQuadricBezierCurveObject->setOrig(kpQuadricBezierCurveObject->getOrig().x(),offset);
02961                 }
02962                 else
02963                     insertObjectInPage(offset, kpQuadricBezierCurveObject);
02964             } break;
02965             case OT_CUBICBEZIERCURVE: {
02966                 KPrCubicBezierCurveObject *kpCubicBezierCurveObject = new KPrCubicBezierCurveObject();
02967                 offset=kpCubicBezierCurveObject->load(obj);
02968                 if ( sticky && !ignoreSticky)
02969                 {
02970                     m_masterPage->appendObject(kpCubicBezierCurveObject);
02971                     kpCubicBezierCurveObject->setOrig(kpCubicBezierCurveObject->getOrig().x(),offset);
02972                 }
02973                 else if ( m_pageWhereLoadObject && paste) {
02974                     kpCubicBezierCurveObject->setOrig(kpCubicBezierCurveObject->getOrig().x(),offset);
02975                     pasteObjects.append( kpCubicBezierCurveObject );
02976                 }
02977                 else if( m_pageWhereLoadObject &&!paste)
02978                 {
02979                     m_pageWhereLoadObject->appendObject(kpCubicBezierCurveObject);
02980                     kpCubicBezierCurveObject->setOrig(kpCubicBezierCurveObject->getOrig().x(),offset);
02981                 }
02982                 else
02983                     insertObjectInPage(offset, kpCubicBezierCurveObject);
02984             } break;
02985             case OT_POLYGON: {
02986                 KPrPolygonObject *kpPolygonObject = new KPrPolygonObject();
02987                 offset=kpPolygonObject->load( obj );
02988                 if ( sticky && !ignoreSticky)
02989                 {
02990                     m_masterPage->appendObject(kpPolygonObject);
02991                     kpPolygonObject->setOrig(kpPolygonObject->getOrig().x(),offset);
02992                 }
02993                 else if ( m_pageWhereLoadObject && paste) {
02994                     kpPolygonObject->setOrig(kpPolygonObject->getOrig().x(),offset);
02995                     pasteObjects.append( kpPolygonObject );
02996                 }
02997                 else if( m_pageWhereLoadObject &&!paste)
02998                 {
02999                     m_pageWhereLoadObject->appendObject(kpPolygonObject);
03000                     kpPolygonObject->setOrig(kpPolygonObject->getOrig().x(),offset);
03001                 }
03002                 else
03003                     insertObjectInPage(offset, kpPolygonObject);
03004             } break;
03005             case OT_CLOSED_LINE: {
03006                 KPrClosedLineObject *kpClosedLinneObject = new KPrClosedLineObject();
03007                 offset = kpClosedLinneObject->load( obj );
03008                 if ( sticky && !ignoreSticky) {
03009                     m_masterPage->appendObject( kpClosedLinneObject );
03010                     kpClosedLinneObject->setOrig( kpClosedLinneObject->getOrig().x(), offset );
03011                 }
03012                 else if ( m_pageWhereLoadObject && paste ) {
03013                     kpClosedLinneObject->setOrig( kpClosedLinneObject->getOrig().x(), offset );
03014                     pasteObjects.append( kpClosedLinneObject );
03015                 }
03016                 else if( m_pageWhereLoadObject &&!paste)
03017                 {
03018                     m_pageWhereLoadObject->appendObject( kpClosedLinneObject );
03019                     kpClosedLinneObject->setOrig( kpClosedLinneObject->getOrig().x(), offset );
03020                 }
03021                 else
03022                     insertObjectInPage( offset, kpClosedLinneObject );
03023             } break;
03024             case OT_GROUP: {
03025                 KPrGroupObject *kpgroupobject = new KPrGroupObject();
03026                 offset=kpgroupobject->load(obj, this);
03027                 if ( sticky && !ignoreSticky)
03028                 {
03029                     m_masterPage->appendObject(kpgroupobject);
03030                     kpgroupobject->setOrig(kpgroupobject->getOrig().x(),offset);
03031                 }
03032                 else if ( m_pageWhereLoadObject && paste) {
03033                     kpgroupobject->setOrig(kpgroupobject->getOrig().x(),offset);
03034                     pasteObjects.append( kpgroupobject );
03035                 }
03036                 else if( m_pageWhereLoadObject &&!paste)
03037                 {
03038                     m_pageWhereLoadObject->appendObject(kpgroupobject);
03039                     kpgroupobject->setOrig(kpgroupobject->getOrig().x(),offset);
03040                 }
03041                 else
03042                     insertObjectInPage(offset, kpgroupobject);
03043             } break;
03044             default: break;
03045             }
03046         }
03047         obj=obj.nextSibling().toElement();
03048     }
03049 
03050     KPrInsertCmd *insertCmd = 0;
03051     if ( ! pasteObjects.empty() )
03052     {
03053         insertCmd = new KPrInsertCmd( i18n( "Paste Objects" ), pasteObjects,
03054                                       this , m_pageWhereLoadObject );
03055         insertCmd->execute();
03056     }
03057     return insertCmd;
03058 }
03059 
03060 void KPrDocument::loadTitle( const QDomElement &element )
03061 {
03062     QDomElement title=element.firstChild().toElement();
03063     int i=m_insertFilePage;
03064     while ( !title.isNull() ) {
03065         if ( title.tagName()=="Title" )
03066         {
03067             //test if there is a page at this index
03068             //=> don't add new page if there is again a page
03069             if(!m_pageWhereLoadObject)
03070             {
03071                 if ( i > ( (int)m_pageList.count() - 1 ) )
03072                     m_pageList.append( new KPrPage( this, m_masterPage ) );
03073                 m_pageList.at(i)->insertManualTitle(title.attribute("title"));
03074                 i++;
03075             }
03076             else
03077                 m_pageWhereLoadObject->insertManualTitle(title.attribute("title"));
03078         }
03079         title=title.nextSibling().toElement();
03080     }
03081 }
03082 
03083 void KPrDocument::loadNote( const QDomElement &element )
03084 {
03085     QDomElement note=element.firstChild().toElement();
03086     int i=m_insertFilePage;
03087     while ( !note.isNull() ) {
03088         if ( note.tagName()=="Note" )
03089         {
03090             //test if there is a page at this index
03091             //=> don't add new page if there is again a page
03092             if(!m_pageWhereLoadObject)
03093             {
03094                 if ( i > ( (int)m_pageList.count() - 1 ) )
03095                     m_pageList.append( new KPrPage( this, m_masterPage ) );
03096                 m_pageList.at(i)->setNoteText(note.attribute("note"));
03097                 i++;
03098             }
03099             else
03100                 m_pageWhereLoadObject->setNoteText(note.attribute("note"));
03101         }
03102         note=note.nextSibling().toElement();
03103     }
03104 }
03105 
03106 void KPrDocument::loadUsedSoundFileFromXML( const QDomElement &element )
03107 {
03108     usedSoundFile = QStringList();
03109     haveNotOwnDiskSoundFile = QStringList();
03110     QDomElement fileElement = element.firstChild().toElement();
03111     while ( !fileElement.isNull() ) {
03112         if ( fileElement.tagName() == "FILE" ) {
03113             QString fileName;
03114             if ( fileElement.hasAttribute( "name" ) )
03115                 fileName = fileElement.attribute( "name" );
03116 
03117             if ( fileElement.hasAttribute( "filename" ) ) {
03118                 QString name = fileElement.attribute( "filename" );
03119                 QFile _file( name );
03120                 if ( _file.open( IO_ReadOnly ) ) {
03121                     fileName = name;
03122                     _file.close();
03123                 }
03124                 else
03125                     haveNotOwnDiskSoundFile.append( name );
03126             }
03127 
03128             usedSoundFile.append( fileName );
03129 
03130             fileElement = fileElement.nextSibling().toElement();
03131         }
03132     }
03133 }
03134 
03135 void KPrDocument::loadImagesFromStore( KoStore *_store )
03136 {
03137     if ( _store ) {
03138         m_pictureCollection.readFromStore( _store, m_pictureMap );
03139         m_pictureMap.clear(); // Release memory
03140     }
03141 }
03142 
03143 bool KPrDocument::completeLoading( KoStore* _store )
03144 {
03145     kdDebug()<<"bool KPrDocument::completeLoading( KoStore* _store )*************************\n";
03146     emit sigProgress( 80 );
03147 
03148     if ( _store ) {
03149         loadImagesFromStore( _store );
03150         emit sigProgress( 90 );
03151 
03152         if ( !usedSoundFile.isEmpty() )
03153             loadUsedSoundFileFromStore( _store, usedSoundFile );
03154 
03155         if ( _clean )
03156             createHeaderFooter();
03157         //else {
03158         //m_pageList.last()->updateBackgroundSize();
03159         //}
03160 
03161 
03162         if ( saveOnlyPage == -1 ) {
03163             // ### following call independant of saveOnlyPage's value?
03164             m_masterPage->completeLoading( _clean, lastObj );
03165             QPtrListIterator<KPrPage> it( m_pageList );
03166             for ( ; it.current(); ++it )
03167                 it.current()->completeLoading( _clean, lastObj );
03168         }
03169     } else {
03170         if ( _clean )
03171         {
03173             setPageLayout( __pgLayout );
03174         }
03175         else
03176             setPageLayout( m_pageLayout );
03177     }
03178 
03179     compatibilityFromOldFileFormat();
03180 
03181     emit sigProgress( 100 );
03182     recalcVariables( VT_FIELD );
03183     emit sigProgress( -1 );
03184 
03185     connect( documentInfo(), SIGNAL( sigDocumentInfoModifed()),this,SLOT(slotDocumentInfoModifed() ) );
03186     //desactivate bgspellchecking
03187     //attributes isReadWrite is not placed at the beginning !
03188     if ( !isReadWrite())
03189         enableBackgroundSpellCheck( false );
03190     return true;
03191 }
03192 
03193 void KPrDocument::loadUsedSoundFileFromStore( KoStore *_store, QStringList _list )
03194 {
03195     int i = m_insertFilePage;
03196     QStringList::Iterator it = _list.begin();
03197     for ( ; it != _list.end(); ++it ) {
03198         QString soundFile = *it;
03199 
03200         if ( _store->open( soundFile ) ) {
03201             kdDebug( 33001 ) << "Not found file on disk. Use this( " << soundFile << " ) file." << endl;
03202             KoStoreDevice dev( _store );
03203             int size = _store->size();
03204             char *data = new char[size];
03205             dev.readBlock( data, size );
03206 
03207             int position = soundFile.findRev( '.' );
03208             QString format = soundFile.right( soundFile.length() - position );
03209             KTempFile *tmpFile = new KTempFile( QString::null, format );
03210             tmpFile->setAutoDelete( true );
03211             tmpFile->file()->writeBlock( data, size );
03212             tmpFile->close();
03213 
03214             QString tmpFileName = tmpFile->name();
03215             tmpSoundFileList.append( tmpFile );
03216 
03217             QString _fileName = *haveNotOwnDiskSoundFile.at( i );
03218             ++i;
03219 
03220             QPtrListIterator<KPrPage> it( m_pageList );
03221             for ( ; it.current(); ++it ) {
03222                 QString _file = it.current()->getPageSoundFileName();
03223                 if ( !_file.isEmpty() && _file == _fileName )
03224                     it.current()->setPageSoundFileName( tmpFileName );
03225 
03226                 QPtrListIterator<KPrObject> oIt( it.current()->objectList() );
03227                 for ( ; oIt.current(); ++oIt ) {
03228                     _file = oIt.current()->getAppearSoundEffectFileName();
03229                     if ( !_file.isEmpty() && _file == _fileName )
03230                         oIt.current()->setAppearSoundEffectFileName( tmpFileName );
03231 
03232                     _file = oIt.current()->getDisappearSoundEffectFileName();
03233                     if ( !_file.isEmpty() && _file == _fileName )
03234                         oIt.current()->setDisappearSoundEffectFileName( tmpFileName );
03235                 }
03236             }
03237 
03238             _store->close();
03239             delete data;
03240         }
03241         else {
03242             kdDebug( 33001 ) << "Found this( " << soundFile << " ) file on disk" << endl;
03243         }
03244     }
03245 }
03246 
03247 void KPrDocument::setPageLayout( const KoPageLayout &pgLayout )
03248 {
03249     //     if ( _pageLayout == pgLayout )
03250     //  return;
03251 
03252     m_pageLayout = pgLayout;
03253 
03254     //for ( int i = 0; i < static_cast<int>( m_pageList.count() ); i++ )
03255     //    m_pageList.at( i )->updateBackgroundSize();
03256 
03257     repaint( false );
03258     layout();
03259     // don't setModified(true) here, since this is called on startup
03260 }
03261 
03262 //when we change pagelayout we must re-position header/footer
03263 void KPrDocument::updateHeaderFooterPosition( )
03264 {
03265     KoRect pageRect=m_masterPage->getPageRect();
03266     QRect oldBoundingRect = zoomHandler()->zoomRect( _header->getRepaintRect() );
03267     _header->setOrig(pageRect.topLeft ());
03268     _header->setSize(pageRect.width(),_header->getSize().height());
03269     repaint( oldBoundingRect );
03270     repaint(_header);
03271 
03272     oldBoundingRect = zoomHandler()->zoomRect( _footer->getRepaintRect() );
03273     _footer->setOrig(pageRect.left(),pageRect.bottom()-_footer->getSize().height());
03274     _footer->setSize(pageRect.width(),_footer->getSize().height());
03275     repaint(oldBoundingRect);
03276     repaint(_footer);
03277 }
03278 
03279 bool KPrDocument::initDoc(InitDocFlags flags, QWidget* parentWidget)
03280 {
03281 
03282     if (flags==KoDocument::InitDocEmpty)
03283     {
03284         QString fileName( locate("kpresenter_template", "Screenpresentations/.source/Plain.kpt",
03285                                  KPrFactory::global() ) );
03286         objStartY = 0;
03287         _clean = true;
03288         bool ok = loadNativeFormat( fileName );
03289         if ( !ok )
03290             showLoadingErrorDialog();
03291         resetURL();
03292         setEmpty();
03293         return ok;
03294     }
03295 
03296     QString file;
03297     KoTemplateChooseDia::ReturnType ret;
03298     KoTemplateChooseDia::DialogType dlgtype;
03299     if (flags != InitDocFileNew)
03300             dlgtype = KoTemplateChooseDia::Everything;
03301     else
03302             dlgtype = KoTemplateChooseDia::OnlyTemplates;
03303 
03304     ret = KoTemplateChooseDia::choose( KPrFactory::global(), file,
03305                                        dlgtype, "kpresenter_template", parentWidget );
03306     if ( ret == KoTemplateChooseDia::Template ) {
03307         _clean = true; //was a parameter called "clean", but unused
03308         bool ok = loadNativeFormat( file );
03309         if ( !ok )
03310             showLoadingErrorDialog();
03311         objStartY = 0;
03312         _clean = true;
03313         resetURL();
03314         setEmpty();
03315         return ok;
03316     } else if ( ret == KoTemplateChooseDia::File ) {
03317         objStartY = 0;
03318         _clean = true;
03319         KURL url( file );
03320         bool ok = openURL( url );
03321         return ok;
03322     } else if ( ret == KoTemplateChooseDia::Empty ) {
03323         QString fileName( locate("kpresenter_template", "Screenpresentations/.source/Plain.kpt",
03324                                  KPrFactory::global() ) );
03325         objStartY = 0;
03326         _clean = true;
03327         bool ok = loadNativeFormat( fileName );
03328         if ( !ok )
03329             showLoadingErrorDialog();
03330         resetURL();
03331         setEmpty();
03332         return ok;
03333     } else
03334         return false;
03335 }
03336 
03337 void KPrDocument::openExistingFile( const QString& file )
03338 {
03339     objStartY = 0;
03340     _clean = true;
03341     KoDocument::openExistingFile( file );
03342 }
03343 
03344 void KPrDocument::openTemplate( const QString& file )
03345 {
03346   KoDocument::openTemplate( file );
03347   objStartY = 0;
03348   _clean = true;
03349 }
03350 
03351 void KPrDocument::initEmpty()
03352 {
03353     QString fileName( locate("kpresenter_template", "Screenpresentations/.source/Plain.kpt",
03354                              KPrFactory::global() ) );
03355     objStartY = 0;
03356     _clean = true;
03357     setModified(true);
03358     bool ok = loadNativeFormat( fileName );
03359     if ( !ok )
03360         showLoadingErrorDialog();
03361     resetURL();
03362 }
03363 
03364 void KPrDocument::setEmpty()
03365 {
03366     KoDocument::setEmpty();
03367     // Whether loaded from template or from empty doc: this is a new one -> set creation date
03368     m_varColl->variableSetting()->setCreationDate(QDateTime::currentDateTime());
03369     recalcVariables( VT_DATE ); // , VST_CREATION_DATE ...
03370     // If we then load a document, it will override that date.
03371 }
03372 
03373 void KPrDocument::setGridValue( double _x, double _y, bool _replace )
03374 {
03375     oldGridX = m_gridX;
03376     oldGridY = m_gridY;
03377     m_gridX=_x;
03378     m_gridY=_y;
03379     if ( _replace )
03380         replaceObjs();
03381 }
03382 
03383 void KPrDocument::repaint( bool erase )
03384 {
03385     QPtrListIterator<KoView> it( views() );
03386     for( ; it.current(); ++it ) {
03387         KPrCanvas* canvas = ((KPrView*)it.current())->getCanvas();
03388         canvas->repaint( erase );
03389     }
03390 }
03391 
03392 void KPrDocument::repaint( const QRect& rect )
03393 {
03394     QRect r;
03395     QPtrListIterator<KoView> it( views() );
03396     for( ; it.current(); ++it ) {
03397         r = rect;
03398         KPrCanvas* canvas = ((KPrView*)it.current())->getCanvas();
03399         r.moveTopLeft( QPoint( r.x() - canvas->diffx(),
03400                                r.y() - canvas->diffy() ) );
03401         canvas->update( r );
03402     }
03403 }
03404 
03405 void KPrDocument::layout(KPrObject *kpobject)
03406 {
03407     KPrTextObject * obj = dynamic_cast<KPrTextObject *>( kpobject );
03408     if (obj)
03409         obj->layout();
03410 }
03411 
03412 void KPrDocument::layout()
03413 {
03414     QPtrListIterator<KoView> it( views() );
03415     for( ; it.current(); ++it ) {
03416         KPrCanvas* canvas = ((KPrView*)it.current())->getCanvas();
03417         canvas->layout();
03418     }
03419 }
03420 
03421 void KPrDocument::repaint( KPrObject *kpobject )
03422 {
03423     repaint( m_zoomHandler->zoomRect( kpobject->getRepaintRect() ) );
03424 }
03425 
03426 QValueList<int> KPrDocument::getPageEffectSteps( unsigned int num )
03427 {
03428     return m_pageList.at(num)->getEffectSteps();
03429 }
03430 
03431 QRect KPrDocument::getPageRect( bool decBorders ) const
03432 {
03433     int pw, ph, bl = static_cast<int>(m_pageLayout.ptLeft);
03434     int br = static_cast<int>(m_pageLayout.ptRight);
03435     int bt = static_cast<int>(m_pageLayout.ptTop);
03436     int bb = static_cast<int>(m_pageLayout.ptBottom);
03437     int wid = static_cast<int>(m_pageLayout.ptWidth);
03438     int hei = static_cast<int>(m_pageLayout.ptHeight);
03439 
03440     if ( !decBorders ) {
03441         br = 0;
03442         bt = 0;
03443         bl = 0;
03444         bb = 0;
03445     }
03446 
03447     pw = wid  - ( bl + br );
03448     ph = hei - ( bt + bb );
03449 
03450     return QRect( bl, bt, pw, ph );
03451 }
03452 
03453 int KPrDocument::getLeftBorder() const
03454 {
03455     return static_cast<int>(m_pageLayout.ptLeft);
03456 }
03457 
03458 int KPrDocument::getTopBorder() const
03459 {
03460     return static_cast<int>(m_pageLayout.ptTop);
03461 }
03462 
03463 int KPrDocument::getBottomBorder() const
03464 {
03465     return static_cast<int>(m_pageLayout.ptBottom);
03466 }
03467 
03468 int KPrDocument::getRightBorder() const
03469 {
03470     return static_cast<int>(m_pageLayout.ptRight);
03471 }
03472 
03473 void KPrDocument::deletePage( int _page )
03474 {
03475     kdDebug(33001) << "KPrDocument::deletePage " << _page << endl;
03476     //m_pageList.at(_page)->deletePage();
03477     if ( m_pageList.count()==1 )
03478         return;
03479     KPrDeletePageCmd *cmd = new KPrDeletePageCmd( i18n("Delete Slide"), _page, this );
03480     cmd->execute();
03481     addCommand(cmd);
03482 }
03483 
03484 void KPrDocument::insertPage( KPrPage *page, int currentPageNum, int insertPageNum )
03485 {
03486     // check if page was allready deleted
03487     int pos = m_deletedPageList.findRef( page );
03488     if ( pos != -1 )
03489         m_deletedPageList.take( pos );
03490 
03491     m_pageList.insert( insertPageNum, page );
03492 
03493     pageOrderChanged();
03494     //activate this page in all views which on slide currentPageNum
03495     QPtrListIterator<KoView> it( views() );
03496     for (; it.current(); ++it )
03497     {
03498         KPrView *view = static_cast<KPrView*>( it.current() );
03499         view->addSideBarItem( insertPageNum );
03500 
03501         // change to the new page if the view was on the current page.
03502         if ( (int)view->getCurrPgNum() - 1 == currentPageNum )
03503         {
03504             view->skipToPage( insertPageNum );
03505         }
03506         else // recalc the page number as it might have been changed
03507         {
03508             view->recalcCurrentPageNum();
03509         }
03510     }
03511 }
03512 
03513 void KPrDocument::takePage( KPrPage *page, int pageNum )
03514 {
03515     int pos = m_pageList.findRef( page );
03516     m_pageList.take( pos );
03517     m_deletedPageList.append( page );
03518 
03519     pageOrderChanged();
03520 
03521     QPtrListIterator<KoView> it( views() );
03522     for (; it.current(); ++it )
03523     {
03524         KPrView *view = static_cast<KPrView*>( it.current() );
03525         view->removeSideBarItem( pos );
03526 
03527         // change to the new page if the view was on the current page.
03528         if ( (int)view->getCurrPgNum() - 1 == pos )
03529         {
03530             view->skipToPage( pageNum );
03531         }
03532         else // recalc the page number as it might have been changed
03533         {
03534             view->recalcCurrentPageNum();
03535         }
03536     }
03537 
03538     repaint( false );
03539 }
03540 
03541 void KPrDocument::pageOrderChanged()
03542 {
03543     recalcVariables( VT_PGNUM );
03544 
03545     //update statusbar
03546     emit pageNumChanged();
03547     emit sig_updateMenuBar();
03548 }
03549 
03550 void KPrDocument::movePageTo( int oldPos, int newPos )
03551 {
03552     kdDebug(33001) << "movePage oldPos = " << oldPos << ", neuPos = " << newPos << endl;
03553 
03554     KPrPage * page = m_pageList.take( oldPos );
03555     m_pageList.insert( newPos, page );
03556 
03557     pageOrderChanged();
03558 
03559     // Update the sidebars
03560     QPtrListIterator<KoView> it( views() );
03561     for (; it.current(); ++it )
03562     {
03563         KPrView *view = static_cast<KPrView*>( it.current() );
03564         view->moveSideBarItem( oldPos, newPos );
03565 
03566         // change to the new page if the view was on the old pos.
03567         if ( (int)view->getCurrPgNum() - 1 == oldPos )
03568         {
03569             view->skipToPage( newPos );
03570         }
03571         else // recalc the page number as it might have been changed
03572         {
03573             view->recalcCurrentPageNum();
03574         }
03575     }
03576 }
03577 
03578 QString KPrDocument::templateFileName( bool chooseTemplate, const QString &theFile )
03579 {
03580     QString fileName;
03581     if ( !chooseTemplate ) {
03582         if ( theFile.isEmpty() )
03583             fileName = locateLocal( "appdata", "default.kpr" );
03584         else
03585             fileName = theFile;
03586     } else {
03587         // TODO: pass parentWidget as parameter to this method
03588         QWidget* parentWidget = 0;
03589         QString _template;
03590         if ( KoTemplateChooseDia::choose( KPrFactory::global(), _template,
03591                                           KoTemplateChooseDia::OnlyTemplates,
03592                                           "kpresenter_template", parentWidget ) == KoTemplateChooseDia::Cancel )
03593             return QString::null;
03594         QFileInfo fileInfo( _template );
03595         fileName = fileInfo.dirPath( true ) + "/" + fileInfo.baseName() + ".kpt";
03596 
03597         KURL src, dest;
03598         src.setPath( fileName );
03599         dest.setPath( locateLocal( "appdata", "default.kpr" ) );
03600         kdDebug(33001) << "Copying template  (in KPrDocument::templateFileName)" << endl
03601                        << "  from: " << src.prettyURL() << endl
03602                        << "  to: " << dest.prettyURL() << endl;
03603         KIO::NetAccess::file_copy( src,
03604                    dest,
03605                    -1, /* default permissions */
03606                    true /* overwrite */ );
03607     }
03608     return fileName;
03609 }
03610 
03611 int KPrDocument::insertNewPage( const QString &cmdName, int _page, InsertPos _insPos,
03612                                   bool chooseTemplate, const QString &theFile )
03613 {
03614     kdDebug(33001) << "KPrDocument::insertNewPage " << _page << endl;
03615 
03616     QString fileName=templateFileName(chooseTemplate, theFile);
03617     if(fileName.isEmpty())
03618         return -1;
03619 
03620     _clean = false;
03621 
03622     objStartY=-1;
03623 
03624     //insert page.
03625     KPrPage *newpage = new KPrPage( this, m_masterPage );
03626 
03627     m_pageWhereLoadObject=newpage;
03628     m_childCountBeforeInsert = children().count();
03629 
03630     bool ok = loadNativeFormat( fileName );
03631     if ( !ok )
03632         showLoadingErrorDialog();
03633 
03634     objStartY = 0;
03635 
03636     KPrInsertPageCmd *cmd = new KPrInsertPageCmd( cmdName, _page, _insPos, newpage, this );
03637     cmd->execute();
03638     addCommand(cmd);
03639 
03640     _clean = true;
03641     m_pageWhereLoadObject=0L;
03642     m_childCountBeforeInsert = 0;
03643     return _page;
03644 }
03645 
03646 void KPrDocument::savePage( const QString &file, int pgnum, bool ignore )
03647 {
03648     saveOnlyPage = pgnum;
03649     _duplicatePage=ignore;
03650     saveNativeFormat( file );
03651     _duplicatePage=false;
03652     saveOnlyPage = -1;
03653 }
03654 
03655 void KPrDocument::replaceObjs( bool createUndoRedo )
03656 {
03657     KMacroCommand * macroCmd = 0L;
03658     QPtrListIterator<KPrPage> oIt(m_pageList);
03659     for (; oIt.current(); ++oIt )
03660     {
03661         KCommand *cmd=oIt.current()->replaceObjs( createUndoRedo, oldGridX,oldGridY,_txtBackCol, _otxtBackCol);
03662         if(cmd && createUndoRedo)
03663         {
03664             if ( !macroCmd)
03665                 macroCmd = new KMacroCommand( i18n("Set New Options") );
03666             macroCmd->addCommand(cmd);
03667         }
03668         else
03669             delete cmd;
03670     }
03671 
03672     if(macroCmd)
03673     {
03674         macroCmd->execute();
03675         addCommand(macroCmd);
03676     }
03677 }
03678 
03679 void KPrDocument::restoreBackground( KPrPage *page )
03680 {
03681     page->background()->reload();
03682 }
03683 
03684 KCommand * KPrDocument::loadPastedObjs( const QString &in, KPrPage* _page )
03685 {
03686     QDomDocument doc;
03687     doc.setContent( in );
03688 
03689     QDomElement document=doc.documentElement();
03690 
03691     // DOC
03692     if (document.tagName()!="DOC") {
03693         kdError(33001) << "Missing DOC" << endl;
03694         return 0L;
03695     }
03696 
03697     bool ok = false;
03698 
03699     if(document.hasAttribute("mime") && document.attribute("mime")=="application/x-kpresenter")
03700         ok=true;
03701 
03702     if ( !ok )
03703         return 0L;
03704     m_pageWhereLoadObject=_page;
03705     KCommand *cmd = loadObjects(document,true);
03706     m_pageWhereLoadObject=0L;
03707 
03708     repaint( false );
03709     setModified( true );
03710     return cmd;
03711 }
03712 
03713 void KPrDocument::deSelectAllObj()
03714 {
03715     QPtrListIterator<KoView> it( views() );
03716     for (; it.current(); ++it )
03717         ((KPrView*)it.current())->getCanvas()->deSelectAllObj();
03718 }
03719 
03720 void KPrDocument::deSelectObj(KPrObject *obj)
03721 {
03722     QPtrListIterator<KoView> it( views() );
03723     for (; it.current(); ++it )
03724         ((KPrView*)it.current())->getCanvas()->deSelectObj( obj );
03725 }
03726 
03727 void KPrDocument::setDisplayObjectMasterPage( bool b )
03728 {
03729     QPtrListIterator<KoView> it( views() );
03730     for (; it.current(); ++it )
03731         ((KPrView*)it.current())->updateDisplayObjectMasterPageButton();
03732     repaint(b);
03733 }
03734 
03735 void KPrDocument::setDisplayBackground( bool b )
03736 {
03737     QPtrListIterator<KoView> it( views() );
03738     for (; it.current(); ++it )
03739         ((KPrView*)it.current())->updateDisplayBackgroundButton();
03740     repaint(b);
03741 }
03742 
03743 void KPrDocument::setHeader( bool b )
03744 {
03745     _header->setDrawEditRect( b );
03746     _header->setDrawEmpty( b );
03747     if(!b)
03748     {
03749         terminateEditing(_header);
03750         deSelectObj(_header);
03751     }
03752     m_masterPage->setHeader( b, false );
03753     updateHeaderFooterButton();
03754     repaint(b);
03755 }
03756 
03757 void KPrDocument::setFooter( bool b )
03758 {
03759     _footer->setDrawEditRect( b );
03760     _footer->setDrawEmpty( b );
03761     if(!b)
03762     {
03763         terminateEditing(_footer);
03764         deSelectObj(_footer);
03765     }
03766     m_masterPage->setFooter( b, false );
03767     updateHeaderFooterButton();
03768     repaint(b);
03769 }
03770 
03771 void KPrDocument::updateHeaderFooterButton()
03772 {
03773     QPtrListIterator<KoView> it( views() );
03774     for (; it.current(); ++it )
03775         ((KPrView*)it.current())->updateHeaderFooterButton();
03776 }
03777 
03778 void KPrDocument::makeUsedPixmapList()
03779 {
03780     usedPictures.clear();
03781 
03782     for ( uint i = 0; i < m_pageList.count(); i++ ) {
03783         if ( saveOnlyPage != -1 &&
03784              static_cast<int>(i) != saveOnlyPage )
03785             continue;
03786         m_pageList.at(i)->makeUsedPixmapList();
03787     }
03788     // ### following call independant of saveOnlyPage's value?
03789     if ( saveOnlyPage == -1 )
03790         m_masterPage->makeUsedPixmapList();
03791 }
03792 
03793 void KPrDocument::makeUsedSoundFileList()
03794 {
03795     if ( saveOnlyPage != -1 )
03796         return;
03797 
03798     usedSoundFile.clear();
03799 
03800     QPtrListIterator<KPrPage> it( m_pageList );
03801     for ( ; it.current(); ++it ) {
03802         QString _file = it.current()->getPageSoundFileName();
03803         if ( !_file.isEmpty() && usedSoundFile.findIndex( _file ) == -1 )
03804             usedSoundFile.append( _file );
03805 
03806         QPtrListIterator<KPrObject> oIt( it.current()->objectList() );
03807         for ( ; oIt.current(); ++oIt ) {
03808             _file = oIt.current()->getAppearSoundEffectFileName();
03809             if ( !_file.isEmpty() && usedSoundFile.findIndex( _file ) == -1 )
03810                 usedSoundFile.append( _file );
03811 
03812             _file = oIt.current()->getDisappearSoundEffectFileName();
03813             if ( !_file.isEmpty() && usedSoundFile.findIndex( _file ) == -1 )
03814                 usedSoundFile.append( _file );
03815         }
03816     }
03817 }
03818 
03819 KoView* KPrDocument::createViewInstance( QWidget* parent, const char* name )
03820 {
03821     //the page numbers have to be recalced for the sticky objects
03822     //as it could not be done during the constructor of KPrView
03823     recalcPageNum();
03824     return new KPrView( this, parent, name );
03825 }
03826 
03827 void KPrDocument::paintContent( QPainter& painter, const QRect& rect,
03828                                   bool /*transparent*/, double zoomX, double zoomY )
03829 {
03830     m_zoomHandler->setZoom( 100 );
03831     if ( zoomHandler()->zoomedResolutionX() != zoomX || zoomHandler()->zoomedResolutionY() != zoomY )
03832     {
03833         int zoomLevel = qRound( 100 * zoomY / zoomHandler()->zoomedResolutionY() ); // ## ignores the case where the x and y scaling differs
03834         zoomHandler()->setZoom( zoomLevel );
03835         bool forPrint = painter.device() && painter.device()->devType() == QInternal::Printer;
03836         newZoomAndResolution( false, forPrint );
03837     }
03838     //for the moment draw first page.
03839     KPrPage *page=m_pageList.first();
03840     if( m_initialActivePage )
03841         page = m_initialActivePage;
03842 
03843     int pageNum = m_pageList.findRef( page );
03844 
03845     if ( page->displayBackground() )
03846         page->background()->drawBackground( &painter, zoomHandler(), rect, false );
03847     if ( page->displayObjectFromMasterPage() )
03848     {
03849         KPrPage *masterPage = page->masterPage();
03850         if ( masterPage )
03851         {
03852             QPtrListIterator<KPrObject> it( masterPage->objectList() );
03853             //draw objects on master slide
03854             for ( ; it.current() ; ++it )
03855             {
03856                 if( (it.current()==_header && !page->hasHeader())||(it.current()==_footer && !page->hasFooter()))
03857                     continue;
03858                 it.current()->draw( &painter, zoomHandler(), pageNum, SM_NONE );
03859             }
03860         }
03861     }
03862     QPtrListIterator<KPrObject> it( page->objectList() );
03863     for ( ; it.current() ; ++it )
03864         it.current()->draw( &painter, zoomHandler(), pageNum, SM_NONE );
03865 }
03866 
03867 QPixmap KPrDocument::generatePreview( const QSize& size )
03868 {
03869     int oldZoom = zoomHandler()->zoom();
03870     double oldResolutionX = zoomHandler()->resolutionX();
03871     double oldResolutionY = zoomHandler()->resolutionY();
03872 
03873     QPixmap pix = KoDocument::generatePreview(size);
03874 
03875     zoomHandler()->setResolution( oldResolutionX, oldResolutionY );
03876     zoomHandler()->setZoom(oldZoom);
03877     newZoomAndResolution( false, false );
03878 
03879     return pix;
03880 }
03881 
03882 void KPrDocument::addShell( KoMainWindow *shell )
03883 {
03884     connect( shell, SIGNAL( documentSaved() ), m_commandHistory, SLOT( documentSaved() ) );
03885     KoDocument::addShell( shell );
03886 }
03887 
03888 void KPrDocument::movePage( int from, int to )
03889 {
03890     kdDebug(33001) << "KPrDocument::movePage from=" << from << " to=" << to << endl;
03891     KPrMovePageCmd *cmd = new KPrMovePageCmd( i18n("Move Slide"), from, to, this );
03892     cmd->execute();
03893     addCommand(cmd);
03894 }
03895 
03896 void KPrDocument::copyPage( int from )
03897 {
03898     _clean = false;
03899     m_childCountBeforeInsert = children().count();
03900 
03901     _duplicatePage=true; // ### now also set via savePage() parameter below
03902 
03903     kdDebug(33001) << "KPrDocument::copyPage from=" << from << " to=" << from + 1 << endl;
03904     kdDebug(33001) << "mimeType = " << mimeType() << ", outputMimeType = " << outputMimeType() << endl;
03905     bool wasSelected = isSlideSelected( from );
03906     KTempFile tempFile( QString::null, mimeType() == nativeOasisMimeType() ? ".oop": ".kpr" );
03907     tempFile.setAutoDelete( true );
03908     savePage( tempFile.name(), from, true );
03909 
03910     //insert page.
03911     KPrPage *newpage = new KPrPage( this, m_masterPage );
03912 
03913     m_pageWhereLoadObject = newpage;
03914 
03915     bool ok = loadNativeFormat( tempFile.name() );
03916     if ( !ok )
03917         showLoadingErrorDialog();
03918 
03919     KPrInsertPageCmd *cmd = new KPrInsertPageCmd( i18n("Duplicate Slide"), from, IP_AFTER, newpage, this );
03920     cmd->execute();
03921     addCommand(cmd);
03922 
03923     _duplicatePage=false;
03924 
03925     _clean = true;
03926     m_pageWhereLoadObject=0L;
03927     m_childCountBeforeInsert = 0;
03928 
03929     selectPage( from + 1, wasSelected );
03930 }
03931 
03932 void KPrDocument::copyPageToClipboard( int pgnum )
03933 {
03934     // We save the page to a temp file and set the URL of the file in the clipboard
03935     // Yes it's a hack but at least we don't hit the clipboard size limit :)
03936     // (and we don't have to implement copy-tar-structure-to-clipboard)
03937     // In fact it even allows copying a [1-page] kpr in konq and pasting it in kpresenter :))
03938     kdDebug(33001) << "KPrDocument::copyPageToClipboard pgnum=" << pgnum << endl;
03939     kdDebug(33001) << "mimeType = " << mimeType() << ", outputMimeType = " << outputMimeType() << endl;
03940     KTempFile tempFile( QString::null, mimeType() == nativeOasisMimeType() ? ".oop": ".kpr" );
03941     savePage( tempFile.name(), pgnum, true );
03942     KURL url; url.setPath( tempFile.name() );
03943     KURL::List lst;
03944     lst.append( url );
03945     QApplication::clipboard()->setData( new KURLDrag( lst ) );
03946     m_tempFileInClipboard = tempFile.name(); // do this last, the above calls clipboardDataChanged
03947 }
03948 
03949 void KPrDocument::pastePage( const QMimeSource * data, int pgnum )
03950 {
03951     KURL::List lst;
03952     if ( KURLDrag::decode( data, lst ) && !lst.isEmpty() )
03953     {
03954         insertNewPage(i18n("Paste Slide"),  pgnum, IP_BEFORE, FALSE, lst.first().path() );
03955         //selectPage( pgnum, true /* should be part of the file ? */ );
03956     }
03957 }
03958 
03959 void KPrDocument::clipboardDataChanged()
03960 {
03961     if ( !m_tempFileInClipboard.isEmpty() )
03962     {
03963         kdDebug(33001) << "KPrDocument::clipboardDataChanged, deleting temp file " << m_tempFileInClipboard << endl;
03964         unlink( QFile::encodeName( m_tempFileInClipboard ) );
03965         m_tempFileInClipboard = QString::null;
03966     }
03967     // TODO enable paste as well, when a txtobject is activated
03968     // and there is plain text in the clipboard. Then enable this code.
03969     //QMimeSource *data = QApplication::clipboard()->data();
03970     //bool canPaste = data->provides( "text/uri-list" ) || data->provides( "application/x-kpresenter-selection" );
03971     // emit enablePaste( canPaste );
03972 }
03973 
03974 void KPrDocument::selectPage( int pgNum /* 0-based */, bool select )
03975 {
03976     Q_ASSERT( pgNum >= 0 );
03977     KPrPage *page = m_pageList.at( pgNum );
03978     page->slideSelected(select);
03979     kdDebug(33001) << "KPrDocument::selectPage pgNum=" << pgNum << " select=" << select << endl;
03980     setModified(true);
03981 
03982     updateSideBarItem( page );
03983     updatePresentationButton();
03984     //update statusbar
03985     emit pageNumChanged();
03986 }
03987 
03988 KPrPage * KPrDocument::findPage(KPrObject *object)
03989 {
03990     QPtrList<KPrObject> masterObjects( m_masterPage->objectList() );
03991     if ( masterObjects.findRef( object ) != -1 )
03992     {
03993         //kdDebug(33001) << "Object is on the master page" << endl;
03994         return m_masterPage;
03995     }
03996     QPtrListIterator<KPrPage> it( m_pageList );
03997     for ( ; it.current(); ++it ) {
03998         QPtrList<KPrObject> list( it.current()->objectList() );
03999         if ( list.findRef( object ) != -1 ) {
04000             //kdDebug(33001) << "Object is on page " << m_pageList.findRef(it.current()) + 1 << endl;
04001             return it.current();
04002         }
04003     }
04004     kdDebug(33001) << "Object not found on a page" << endl;
04005     return 0L;
04006 }
04007 
04008 KPrPage * KPrDocument::findPage(QPtrList<KPrObject> &objects)
04009 {
04010     KPrObject *object;
04011     for ( object = objects.first(); object; object=objects.next() ) {
04012         QPtrList<KPrObject> list( m_masterPage->objectList() );
04013         if ( list.findRef( object ) != -1 )
04014         {
04015             //kdDebug(33001) << "Object is on the master page" << endl;
04016             return m_masterPage;
04017         }
04018     }
04019     object = objects.first();
04020     for ( KPrPage *page=m_pageList.first(); page; page=m_pageList.next() ) {
04021         QPtrList<KPrObject> list( page->objectList() );
04022         if ( list.findRef( object ) != -1 ) {
04023             //kdDebug(33001) << "The Objects are on page " << m_pageList.findRef(page) + 1 << endl;
04024             return page;
04025         }
04026     }
04027     kdDebug(33001) << "Objects not found on a page" << endl;
04028     return 0L;
04029 }
04030 
04031 void KPrDocument::updateSideBarItem( KPrPage * page )
04032 {
04033     // Update the views
04034     QPtrListIterator<KoView> it( views() );
04035     for (; it.current(); ++it )
04036         static_cast<KPrView*>( it.current() )->updateSideBarItem( page );
04037 }
04038 
04039 bool KPrDocument::isSlideSelected( int pgNum /* 0-based */ )
04040 {
04041     Q_ASSERT( pgNum >= 0 );
04042     return m_pageList.at(pgNum)->isSlideSelected();
04043 }
04044 
04045 QValueList<int> KPrDocument::listOfDisplaySelectedSlides( const QValueList<KPrPage*> & lst) /* returned list is 0-based */
04046 {
04047     QValueList<int> result;
04048     QValueListConstIterator<KPrPage*> itPage;
04049     QValueListConstIterator<KPrPage*> itPageEnd = lst.end();
04050     for( itPage =  lst.begin() ; itPage != itPageEnd; ++itPage )
04051     {
04052         int pageNum = m_pageList.find(*itPage );
04053         if ( pageNum != -1 )
04054         {
04055             kdDebug()<<" KPrDocument::displaySelectedSlide : add slide number :"<<pageNum<<endl;
04056             result << pageNum;
04057         }
04058     }
04059     return result;
04060 }
04061 
04062 
04063 QValueList<int> KPrDocument::displaySelectedSlides()  /* returned list is 0-based */
04064 {
04065     QValueList<int> result;
04066     if ( m_customListTest )
04067         return *m_customListTest;
04068     if ( m_presentationName.isEmpty() )
04069         return selectedSlides();
04070     else
04071     {
04072         kdDebug()<<" KPrDocument::displaySelectedSlide m_presentationName : "<<m_presentationName<<endl;
04073         result = listOfDisplaySelectedSlides( m_customListSlideShow[m_presentationName]);
04074     }
04075     return result;
04076 }
04077 
04078 QValueList<int> KPrDocument::selectedSlides() /* returned list is 0-based */
04079 {
04080     QValueList<int> result;
04081     for ( int i = 0; i < static_cast<int>( m_pageList.count() ); i++ ) {
04082         if(m_pageList.at(i)->isSlideSelected())
04083             result <<i;
04084     }
04085     return result;
04086 }
04087 
04088 QString KPrDocument::selectedForPrinting() {
04089     QString ret;
04090     int start=-1, end=-1;
04091     bool continuous=false;
04092     for ( int i = 0; i < static_cast<int>( m_pageList.count() ); i++ ) {
04093         if(m_pageList.at(i)->isSlideSelected()) {
04094             if(continuous)
04095                 ++end;
04096             else {
04097                 start=i;
04098                 end=i;
04099                 continuous=true;
04100             }
04101         }
04102         else {
04103             if(continuous) {
04104                 if(start==end)
04105                     ret+=QString::number(start+1)+",";
04106                 else
04107                     ret+=QString::number(start+1)+"-"+QString::number(end+1)+",";
04108                 continuous=false;
04109             }
04110         }
04111     }
04112     if(continuous) {
04113         if(start==end)
04114             ret+=QString::number(start+1);
04115         else
04116             ret+=QString::number(start+1)+"-"+QString::number(end+1);
04117     }
04118     if(','==ret[ret.length()-1])
04119         ret.truncate(ret.length()-1);
04120     return ret;
04121 }
04122 
04123 void KPrDocument::slotRepaintChanged( KPrTextObject *kptextobj )
04124 {
04125     //todo
04126     //use this function for the moment
04127     repaint( kptextobj );
04128 }
04129 
04130 
04131 void KPrDocument::recalcVariables( int type )
04132 {
04133     recalcPageNum();
04134     QValueList<KoVariable* > modifiedVariables = m_varColl->recalcVariables(type);
04135     if ( modifiedVariables.isEmpty() )
04136         return;
04137 
04138     // TODO use the return value from recalcVariables to only repaint what has changed.
04139     QPtrListIterator<KPrPage> it( m_pageList );
04140     for ( ; it.current(); ++it )
04141         it.current()->slotRepaintVariable();
04142     m_masterPage->slotRepaintVariable();
04143 }
04144 
04145 void KPrDocument::slotGuideLinesChanged( KoView *view )
04146 {
04147     ( (KPrView*)view )->getCanvas()->guideLines().getGuideLines( m_hGuideLines, m_vGuideLines );
04148     QPtrListIterator<KoView> it( views() );
04149     for (; it.current(); ++it )
04150     {
04151         if ( it.current() != view )
04152         {
04153             ( (KPrView*)it.current() )->getCanvas()->guideLines().setGuideLines( m_hGuideLines, m_vGuideLines );
04154         }
04155     }
04156 }
04157 
04158 void KPrDocument::slotDocumentInfoModifed()
04159 {
04160     if (!getVariableCollection()->variableSetting()->displayFieldCode())
04161         recalcVariables( VT_FIELD );
04162 }
04163 
04164 void KPrDocument::reorganizeGUI()
04165 {
04166     QPtrListIterator<KoView> it( views() );
04167     for (; it.current(); ++it )
04168         ((KPrView*)it.current())->reorganize();
04169 }
04170 
04171 int KPrDocument::undoRedoLimit() const
04172 {
04173     return m_commandHistory->undoLimit();
04174 }
04175 
04176 void KPrDocument::setUndoRedoLimit(int val)
04177 {
04178     m_commandHistory->setUndoLimit(val);
04179     m_commandHistory->setRedoLimit(val);
04180 }
04181 
04182 void KPrDocument::updateRuler()
04183 {
04184     emit sig_updateRuler();
04185 }
04186 
04187 void KPrDocument::recalcPageNum()
04188 {
04189     QPtrListIterator<KPrPage> it( m_pageList );
04190     for ( ; it.current(); ++it )
04191         it.current()->recalcPageNum();
04192     m_masterPage->recalcPageNum();
04193 }
04194 
04195 KPrPage * KPrDocument::activePage()const
04196 {
04197     return m_initialActivePage;
04198 }
04199 
04200 void KPrDocument::insertObjectInPage(double offset, KPrObject *_obj, int pos)
04201 {
04203     int page = (int)(offset/__pgLayout.ptHeight)+m_insertFilePage;
04204     if ( page < 0 )
04205     {
04206         kdDebug(33001) << "insertObjectInPage object cound not be inserted page = " << page << endl;
04207         return;
04208     }
04209     double newPos = offset - ( page - m_insertFilePage ) * __pgLayout.ptHeight;
04210     // due to a very small caluculating error which gives us the wrong page
04211     // for objects placed on top of the page we have to move them to the right page.
04212     if ( __pgLayout.ptHeight - newPos < 1e-6 )
04213     {
04214         page++;
04215         newPos = 0.0;
04216     }
04217     if ( page > ( (int)m_pageList.count()-1 ) )
04218     {
04219         for (int i=(m_pageList.count()-1); i<page;i++)
04220             m_pageList.append( new KPrPage( this, m_masterPage ) );
04221     }
04222     _obj->setOrig(_obj->getOrig().x(),newPos);
04223 
04224     if ( pos == -1 )
04225     {
04226         m_pageList.at(page)->appendObject(_obj);
04227     }
04228     else
04229     {
04230         m_pageList.at( page )->insertObject( _obj, pos );
04231     }
04232 }
04233 
04234 void KPrDocument::insertPixmapKey( KoPictureKey key )
04235 {
04236     if ( !usedPictures.contains( key ) )
04237         usedPictures.append( key );
04238 }
04239 
04240 KPrPage * KPrDocument::initialActivePage() const
04241 {
04242     return m_initialActivePage;
04243 }
04244 
04245 void KPrDocument::displayActivePage(KPrPage * _page)
04246 {
04247     m_initialActivePage = _page;
04248 }
04249 
04250 void KPrDocument::updateZoomRuler()
04251 {
04252     QPtrListIterator<KoView> it( views() );
04253     for (; it.current(); ++it )
04254     {
04255         ((KPrView*)it.current())->getHRuler()->setZoom( m_zoomHandler->zoomedResolutionX() );
04256         ((KPrView*)it.current())->getVRuler()->setZoom( m_zoomHandler->zoomedResolutionY() );
04257         ((KPrView*)it.current())->slotUpdateRuler();
04258     }
04259 }
04260 
04261 void KPrDocument::newZoomAndResolution( bool updateViews, bool /*forPrint*/ )
04262 {
04263     QPtrListIterator<KPrPage> it( m_pageList );
04264     for ( ; it.current(); ++it ) {
04265         QPtrListIterator<KPrObject> oit(it.current()->objectList());
04266         for ( ; oit.current(); ++oit ) {
04267             if ( oit.current()->getType() == OT_TEXT )
04268                 static_cast<KPrTextObject *>( oit.current() )->textDocument()->formatCollection()->zoomChanged();
04269         }
04270     }
04271     if ( updateViews )
04272     {
04273         QPtrListIterator<KoView> it( views() );
04274         for (; it.current(); ++it )
04275         {
04276             static_cast<KPrView *>( it.current() )->getCanvas()->update();
04277             static_cast<KPrView *>( it.current() )->getCanvas()->layout();
04278         }
04279     }
04280 }
04281 
04282 bool KPrDocument::isHeader(const KPrObject *obj) const
04283 {
04284     return (obj==_header);
04285 }
04286 
04287 bool KPrDocument::isFooter(const KPrObject *obj) const
04288 {
04289     return (obj==_footer);
04290 }
04291 
04292 bool KPrDocument::isHeaderFooter(const KPrObject *obj) const
04293 {
04294     return (obj==_header)||(obj==_footer);
04295 }
04296 
04297 void KPrDocument::updateRulerPageLayout()
04298 {
04299     QPtrListIterator<KoView> it( views() );
04300     for (; it.current(); ++it )
04301     {
04302         ((KPrView*)it.current())->getHRuler()->setPageLayout(m_pageLayout );
04303         ((KPrView*)it.current())->getVRuler()->setPageLayout(m_pageLayout );
04304 
04305     }
04306 }
04307 
04308 void KPrDocument::refreshAllNoteBarMasterPage(const QString &text, KPrView *exceptView)
04309 {
04310     m_masterPage->setNoteText(text );
04311     QPtrListIterator<KoView> it( views() );
04312     for (; it.current(); ++it )
04313     {
04314         KPrView* view=(KPrView*)it.current();
04315         if ( view->getNoteBar() && view != exceptView && view->editMaster() )
04316             view->getNoteBar()->setCurrentNoteText(text );
04317     }
04318 }
04319 
04320 void KPrDocument::refreshAllNoteBar(int page, const QString &text, KPrView *exceptView)
04321 {
04322     m_pageList.at(page)->setNoteText(text );
04323     QPtrListIterator<KoView> it( views() );
04324     for (; it.current(); ++it )
04325     {
04326         KPrView* view=(KPrView*)it.current();
04327         if ( view->getNoteBar() && view != exceptView && ((int)(view->getCurrPgNum())-1 == page))
04328             view->getNoteBar()->setCurrentNoteText(text );
04329     }
04330 }
04331 
04332 void KPrDocument::loadStyleTemplates( const QDomElement &stylesElem )
04333 {
04334     QValueList<QString> followingStyles;
04335 
04336     QDomNodeList listStyles = stylesElem.elementsByTagName( "STYLE" );
04337     if( listStyles.count() > 0) { // we are going to import at least one style.
04338         KoParagStyle *s = m_styleColl->findStyle("Standard");
04339         kdDebug(32001) << "KPrDocument::loadStyleTemplates looking for Standard, to delete it. Found " << s << endl;
04340         if(s) // delete the standard style.
04341             m_styleColl->removeStyle(s);
04342     }
04343     for (unsigned int item = 0; item < listStyles.count(); item++) {
04344         QDomElement styleElem = listStyles.item( item ).toElement();
04345 
04346         KoParagStyle *sty = new KoParagStyle( QString::null );
04347         // Load the style from the <STYLE> element
04348         sty->loadStyle( styleElem );
04349 
04350         QDomElement formatElem = styleElem.namedItem( "FORMAT" ).toElement();
04351         if ( !formatElem.isNull() )
04352             sty->format() = KPrTextObject::loadFormat( formatElem, 0L, defaultFont(), globalLanguage(), globalHyphenation() );
04353         else
04354             kdWarning(33001) << "No FORMAT tag in <STYLE>" << endl; // This leads to problems in applyStyle().
04355 
04356         // Style created, now let's try to add it
04357         sty = m_styleColl->addStyle( sty );
04358         kdDebug() << k_funcinfo << m_styleColl->styleList().count() << " styles, " << followingStyles.count() << " following styles" << endl;
04359         if(m_styleColl->styleList().count() > followingStyles.count() )
04360         {
04361             QString following = styleElem.namedItem("FOLLOWING").toElement().attribute("name");
04362             followingStyles.append( following );
04363         }
04364         else
04365             kdWarning (33001) << "Found duplicate style declaration, overwriting former " << sty->name() << endl;
04366     }
04367 
04368     Q_ASSERT( followingStyles.count() == m_styleColl->styleList().count() );
04369     unsigned int i=0;
04370     for( QValueList<QString>::Iterator it = followingStyles.begin(); it != followingStyles.end(); ++it ) {
04371         KoParagStyle * style = m_styleColl->findStyle(*it);
04372         m_styleColl->styleAt( i++)->setFollowingStyle( style );
04373     }
04374 }
04375 
04376 
04377 void KPrDocument::updateAllStyleLists()
04378 {
04379     QPtrListIterator<KoView> it( views() );
04380     for (; it.current(); ++it )
04381         ((KPrView*)it.current())->updateStyleList();
04382 }
04383 
04384 void KPrDocument::applyStyleChange( KoStyleChangeDefMap changed )
04385 {
04386     QPtrListIterator<KPrPage> it( m_pageList );
04387     for ( ; it.current(); ++it )
04388         it.current()->applyStyleChange( changed );
04389     m_masterPage->applyStyleChange( changed );
04390 }
04391 
04392 void KPrDocument::saveStyle( KoParagStyle *sty, QDomElement parentElem )
04393 {
04394     QDomDocument doc = parentElem.ownerDocument();
04395     QDomElement styleElem = doc.createElement( "STYLE" );
04396     parentElem.appendChild( styleElem );
04397 
04398     sty->saveStyle( styleElem );
04399     QDomElement formatElem = doc.createElement("FORMAT");
04400     KPrTextObject::saveFormat( formatElem, &sty->format() );
04401     styleElem.appendChild( formatElem );
04402 }
04403 
04404 void KPrDocument::startBackgroundSpellCheck()
04405 {
04406     //don't start spell checking when document is embedded in konqueror
04407     if(backgroundSpellCheckEnabled() && isReadWrite())
04408     {
04409         if(m_initialActivePage->allTextObjects().count()>0)
04410         {
04411             m_bgSpellCheck->start();
04412         }
04413     }
04414 }
04415 
04416 void KPrDocument::enableBackgroundSpellCheck( bool b )
04417 {
04418     //m_bgSpellCheck->enableBackgroundSpellCheck(b);
04419     m_bgSpellCheck->setEnabled(b);
04420     QPtrListIterator<KoView> it( views() );
04421     for( ; it.current(); ++it )
04422         ((KPrView*)it.current())->updateBgSpellCheckingState();
04423 }
04424 
04425 bool KPrDocument::backgroundSpellCheckEnabled() const
04426 {
04427     return m_bgSpellCheck->enabled();
04428 }
04429 
04430 void KPrDocument::reactivateBgSpellChecking(bool refreshTextObj)
04431 {
04432     QPtrListIterator<KPrPage> it( m_pageList );
04433 #if 0
04434     if(m_kpresenterView && m_kpresenterView->getCanvas())
04435         activePage=m_kpresenterView->getCanvas()->activePage();
04436 #endif
04437     KPrPage *activePage=m_initialActivePage;
04438     for ( ; it.current(); ++it )
04439     {
04440         if( it.current()!=activePage)
04441             it.current()->reactivateBgSpellChecking(false );
04442         else
04443             it.current()->reactivateBgSpellChecking( true);
04444     }
04445     m_masterPage->reactivateBgSpellChecking(refreshTextObj);
04446     startBackgroundSpellCheck();
04447 }
04448 
04449 QPtrList<KoTextObject> KPrDocument::allTextObjects() const
04450 {
04451     QPtrList<KoTextObject> lst;
04452     QPtrListIterator<KPrPage> it( m_pageList );
04453     for ( ; it.current(); ++it )
04454         it.current()->addTextObjects( lst );
04455     m_masterPage->addTextObjects( lst );
04456     return lst;
04457 }
04458 
04459 QValueList<KoTextDocument *> KPrDocument::allTextDocuments() const
04460 {
04461     QValueList<KoTextDocument *> lst;
04462     const QPtrList<KoTextObject> textObjects = allTextObjects();
04463     QPtrListIterator<KoTextObject> it( textObjects );
04464     for ( ; it.current() ; ++it ) {
04465         lst.append( it.current()->textDocument() );
04466     }
04467     return lst;
04468 }
04469 
04470 QValueList<KoTextObject *> KPrDocument::visibleTextObjects( ) const
04471 {
04472     QValueList<KoTextObject *> lst;
04473     QPtrList<KoTextObject> textFramesets = allTextObjects(  );
04474 
04475     KoTextObject *frm;
04476     for ( frm=textFramesets.first(); frm != 0; frm=textFramesets.next() ) {
04477         if ( frm && !frm->protectContent() )
04478         {
04479             lst.append( frm );
04480         }
04481     }
04482     return lst;
04483 }
04484 
04485 void KPrDocument::setShowGuideLines( bool b )
04486 {
04487     m_bShowGuideLines = b;
04488     setModified( true );
04489 }
04490 
04491 void KPrDocument::horizontalGuideLines( const QValueList<double> &lines )
04492 {
04493     m_hGuideLines = lines;
04494 }
04495 
04496 void KPrDocument::verticalGuideLines( const QValueList<double> &lines )
04497 {
04498     m_vGuideLines = lines;
04499 }
04500 
04501 
04502 void KPrDocument::addGuideLine( Qt::Orientation o, double pos )
04503 {
04504     if ( o == Qt::Horizontal )
04505     {
04506         m_hGuideLines.append( pos );
04507     }
04508     else
04509     {
04510         m_vGuideLines.append( pos );
04511     }
04512 
04513     QPtrListIterator<KoView> it( views() );
04514     for (; it.current(); ++it )
04515     {
04516         ( (KPrView*)it.current() )->getCanvas()->guideLines().setGuideLines( m_hGuideLines, m_vGuideLines );
04517     }
04518 }
04519 
04520 
04521 void KPrDocument::updateGuideLineButton()
04522 {
04523     QPtrListIterator<KoView> it( views() );
04524     for (; it.current(); ++it )
04525         ((KPrView*)it.current())->updateGuideLineButton();
04526 }
04527 
04528 void KPrDocument::loadGuideLines( const QDomElement &element )
04529 {
04530     // In early versions of KPresenter 1.2 (up to Beta 2), there is child also naed <HELPLINES>
04531     // Before KPresenter 1.5 the guide lines where named helplines that is why they are still
04532     // named like this in the fileformat
04533     QDomElement guidelines = element.namedItem( "HELPLINES" ).toElement();
04534     if ( guidelines.isNull() )
04535         guidelines = element;
04536 
04537     guidelines = guidelines.firstChild().toElement();
04538     while ( !guidelines.isNull() )
04539     {
04540         if ( guidelines.tagName() == "Vertical" )
04541             m_vGuideLines.append( guidelines.attribute( "value" ).toDouble() );
04542         else if ( guidelines.tagName() == "Horizontal" )
04543             m_hGuideLines.append( guidelines.attribute( "value" ).toDouble() );
04544         guidelines = guidelines.nextSibling().toElement();
04545     }
04546 }
04547 
04548 void KPrDocument::saveGuideLines( QDomDocument &doc, QDomElement& element )
04549 {
04550     for(QValueList<double>::Iterator it = m_vGuideLines.begin(); it != m_vGuideLines.end(); ++it)
04551     {
04552         QDomElement lines=doc.createElement("Vertical");
04553         lines.setAttribute("value", (double)*it);
04554         element.appendChild( lines );
04555     }
04556 
04557     for(QValueList<double>::Iterator it = m_hGuideLines.begin(); it != m_hGuideLines.end(); ++it)
04558     {
04559         QDomElement lines=doc.createElement("Horizontal");
04560         lines.setAttribute("value", *it);
04561         element.appendChild( lines );
04562     }
04563 }
04564 
04565 void KPrDocument::updateGridButton()
04566 {
04567     QPtrListIterator<KoView> it( views() );
04568     for (; it.current(); ++it )
04569         ((KPrView*)it.current())->updateGridButton();
04570 
04571 }
04572 
04573 void KPrDocument::setSpellCheckIgnoreList( const QStringList& lst )
04574 {
04575     m_spellCheckIgnoreList = lst;
04576     m_bgSpellCheck->settings()->setCurrentIgnoreList( m_spellCheckIgnoreList + m_spellCheckPersonalDict );
04577    setModified( true );
04578 }
04579 
04580 void KPrDocument::addSpellCheckIgnoreWord( const QString & word )
04581 {
04582     // ### missing: undo/redo support
04583     if( m_spellCheckIgnoreList.findIndex( word ) == -1 )
04584         m_spellCheckIgnoreList.append( word );
04585     setSpellCheckIgnoreList( m_spellCheckIgnoreList );
04586 }
04587 
04588 void KPrDocument::updateObjectStatusBarItem()
04589 {
04590     QPtrListIterator<KoView> it( views() );
04591     for (; it.current(); ++it )
04592         ((KPrView*)it.current())->updateObjectStatusBarItem();
04593 }
04594 
04595 void KPrDocument::updateObjectSelected()
04596 {
04597     QPtrListIterator<KoView> it( views() );
04598     for (; it.current(); ++it )
04599         ((KPrView*)it.current())->objectSelectedChanged();
04600 }
04601 
04602 void KPrDocument::setTabStopValue ( double _tabStop )
04603 {
04604     m_tabStop = _tabStop;
04605     QPtrListIterator<KPrPage> it( m_pageList );
04606     for ( ; it.current(); ++it )
04607         it.current()->changeTabStopValue( m_tabStop );
04608     //styckypage
04609     m_masterPage->changeTabStopValue( m_tabStop );
04610 }
04611 
04612 void KPrDocument::changeBgSpellCheckingState( bool b )
04613 {
04614     enableBackgroundSpellCheck( b );
04615     reactivateBgSpellChecking();
04616     KConfig *config = KPrFactory::global()->config();
04617     config->setGroup("KSpell kpresenter" );
04618     config->writeEntry( "SpellCheck", (int)b );
04619 }
04620 
04621 
04622 bool KPrDocument::cursorInProtectedArea()const
04623 {
04624     return m_cursorInProtectectedArea;
04625 }
04626 
04627 void KPrDocument::setCursorInProtectedArea( bool b )
04628 {
04629     m_cursorInProtectectedArea=b;
04630     testAndCloseAllTextObjectProtectedContent();
04631 }
04632 
04633 void KPrDocument::testAndCloseAllTextObjectProtectedContent()
04634 {
04635     if ( !m_cursorInProtectectedArea )
04636     {
04637         QPtrListIterator<KoView> it( views() );
04638         for (; it.current(); ++it )
04639             static_cast<KPrView*>(it.current())->testAndCloseAllTextObjectProtectedContent();
04640     }
04641 }
04642 
04643 void KPrDocument::insertFile(const QString & file )
04644 {
04645     m_insertFilePage = m_pageList.count();
04646 
04647     m_childCountBeforeInsert = children().count();
04648     objStartY = 0;
04649     bool clean = _clean;
04650     _clean = false;
04651     bool ok = loadNativeFormat(file );
04652     if ( !ok )
04653     {
04654         showLoadingErrorDialog();
04655         return;
04656     }
04657     KMacroCommand *macro = 0L;
04658     for ( int i = m_insertFilePage; i<(int)m_pageList.count();i++)
04659     {
04660         if ( !macro )
04661             macro = new KMacroCommand( i18n("Insert File"));
04662         KPrInsertPageCmd * cmd = new KPrInsertPageCmd( i18n("Insert File"), i - 1, IP_AFTER, m_pageList.at(i), this ) ;
04663         macro->addCommand(cmd );
04664     }
04665     if ( macro )
04666         addCommand( macro );
04667 
04668     m_insertFilePage = 0;
04669     m_childCountBeforeInsert = 0;
04670     // Update the views
04671     int newPos = m_pageList.count()-1;
04672     QPtrListIterator<KoView> it( views() );
04673     for (; it.current(); ++it )
04674         static_cast<KPrView*>(it.current())->updateSideBar();
04675     _clean = clean;
04676     updatePresentationButton();
04677 
04678     //activate this page in all views (...)
04679     QPtrListIterator<KoView>it2( views() );
04680     for (; it2.current(); ++it2 )
04681         static_cast<KPrView*>(it2.current())->skipToPage(newPos);
04682 }
04683 
04684 void KPrDocument::spellCheckParagraphDeleted( KoTextParag * /* _parag */,  KPrTextObject * /* frm */ )
04685 {
04686     //m_bgSpellCheck->spellCheckParagraphDeleted( _parag, frm->textObject());
04687 }
04688 
04689 void KPrDocument::updateRulerInProtectContentMode()
04690 {
04691     QPtrListIterator<KoView> it( views() );
04692     for (; it.current(); ++it )
04693         static_cast<KPrView*>(it.current())->updateRulerInProtectContentMode();
04694 }
04695 
04696 void KPrDocument::updatePresentationButton()
04697 {
04698     QPtrListIterator<KoView> it( views() );
04699     for (; it.current(); ++it )
04700         static_cast<KPrView*>(it.current())->updatePresentationButton((selectedSlides().count()>0));
04701 }
04702 
04703 void KPrDocument::refreshGroupButton()
04704 {
04705     QPtrListIterator<KoView> it( views() );
04706     for (; it.current(); ++it )
04707         static_cast<KPrView*>(it.current())->refreshGroupButton();
04708 }
04709 
04710 void KPrDocument::addView( KoView *_view )
04711 {
04712     KoDocument::addView( _view );
04713     QPtrListIterator<KoView> it( views() );
04714     for (; it.current(); ++it )
04715         static_cast<KPrView*>(it.current())->closeTextObject();
04716 }
04717 
04718 void KPrDocument::removeView( KoView *_view )
04719 {
04720     KoDocument::removeView( _view );
04721     QPtrListIterator<KoView> it( views() );
04722     for (; it.current(); ++it )
04723         static_cast<KPrView*>(it.current())->deSelectAllObjects();
04724 }
04725 
04726 void KPrDocument::updateStyleListOrder( const QStringList &list )
04727 {
04728     styleCollection()->updateStyleListOrder( list );
04729 }
04730 
04731 void KPrDocument::updateDirectCursorButton()
04732 {
04733     QPtrListIterator<KoView> it( views() );
04734     for (; it.current(); ++it )
04735         static_cast<KPrView*>(it.current())->updateDirectCursorButton();
04736 }
04737 
04738 void KPrDocument::setInsertDirectCursor(bool _b)
04739 {
04740     m_bInsertDirectCursor=_b;
04741     KConfig *config = KPrFactory::global()->config();
04742     config->setGroup( "Interface" );
04743     config->writeEntry( "InsertDirectCursor", _b );
04744     updateDirectCursorButton();
04745 }
04746 
04747 KPrView *KPrDocument::firstView() const
04748 {
04749     if ( views().count()>0)
04750         return static_cast<KPrView*>(views().getFirst());
04751     else
04752         return 0L;
04753 }
04754 
04755 void KPrDocument::addWordToDictionary( const QString & word)
04756 {
04757     if ( m_bgSpellCheck )
04758     {
04759         if( m_spellCheckPersonalDict.findIndex( word ) == -1 )
04760             m_spellCheckPersonalDict.append( word );
04761         m_bgSpellCheck->settings()->setCurrentIgnoreList( m_spellCheckIgnoreList + m_spellCheckPersonalDict );
04762         if ( backgroundSpellCheckEnabled() )
04763             // Re-check everything to make this word normal again
04764             reactivateBgSpellChecking();
04765     }
04766 }
04767 
04768 QValueList <KPrPage *> KPrDocument::customListPage( const QStringList & lst, bool loadOasis )
04769 {
04770     QStringList tmp( lst );
04771     QValueList <KPrPage *> tmpValueList;
04772     for ( QStringList::Iterator itList = tmp.begin(); itList != tmp.end(); ++itList )
04773     {
04774         for ( int i = 0; i < static_cast<int>( m_pageList.count() ); i++ )
04775         {
04776             //kdDebug()<<" insert page name :"<<*itList<<endl;
04777             if ( loadOasis )
04778             {
04779                 if ( m_pageList.at( i )->oasisNamePage(i+1)== ( *itList ) )
04780                 {
04781                     tmpValueList.append(  m_pageList.at( i ) );
04782                     //kdDebug()<<" really insert\n";
04783                     break;
04784                 }
04785             }
04786             else
04787             {
04788                 if ( m_pageList.at( i )->pageTitle()== ( *itList ) )
04789                 {
04790                     tmpValueList.append( m_pageList.at( i ) );
04791                     //kdDebug()<<" really insert\n";
04792                     break;
04793                 }
04794             }
04795 
04796         }
04797     }
04798     return tmpValueList;
04799 
04800 }
04801 
04802 void KPrDocument::setCustomSlideShows( const CustomSlideShowMap & customSlideShows )
04803 {
04804     m_customListSlideShow = customSlideShows;
04805     setModified( true );
04806 }
04807 
04808 QStringList KPrDocument::presentationList()
04809 {
04810     QStringList lst;
04811     if ( !m_customListSlideShow.isEmpty() )
04812     {
04813         CustomSlideShowMap::Iterator it;
04814         for ( it = m_customListSlideShow.begin(); it != m_customListSlideShow.end(); ++it )
04815             lst << it.key();
04816     }
04817     return lst;
04818 }
04819 
04820 void KPrDocument::testCustomSlideShow( const QValueList<KPrPage *> &pages, KPrView *view )
04821 {
04822     delete m_customListTest;
04823     m_customListTest = new QValueList<int>( listOfDisplaySelectedSlides( pages ) );
04824     if ( view )
04825         view->screenStartFromFirst();
04826 
04827 }
04828 
04829 void KPrDocument::clearTestCustomSlideShow()
04830 {
04831     delete m_customListTest;
04832     m_customListTest = 0L;
04833 }
04834 
04835 
04836 #include "KPrDocument.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys