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