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