kpresenter

KPrDocument.cpp
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
3 Copyright (C) 2005-2006 Thorsten Zachmann <zachmann@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include "KPrDocument.h"
22#include "KPrView.h"
23#include "KPrCanvas.h"
24#include "KPrPage.h"
25#include "KPrObject.h"
26#include "KPrLineObject.h"
27#include "KPrRectObject.h"
28#include "KPrEllipseObject.h"
29#include "KPrAutoformObject.h"
30#include "KPrTextObject.h"
31#include "KPrTextDocument.h"
32#include "KPrPixmapObject.h"
33#include "KPrPieObject.h"
34#include "KPrPartObject.h"
35#include "KPrGroupObject.h"
36#include "KPrCommand.h"
37#include "insertpagedia.h"
38#include "KPrFreehandObject.h"
39#include "KPrPolylineObject.h"
40#include "KPrBezierCurveObject.h"
41#include "KPrPolygonObject.h"
42#include "KPrClosedLineObject.h"
43#include "KPrSVGPathParser.h"
44
45#include <tqpopupmenu.h>
46#include <tqclipboard.h>
47#include <tqregexp.h>
48#include <tqfileinfo.h>
49#include <tqdom.h>
50#include <tqdict.h>
51
52#include <KoDom.h>
53#include <KoXmlNS.h>
54
55#include <kurl.h>
56#include <kdebug.h>
57#include <KoGlobal.h>
58#include <tdeapplication.h>
59#include <kurldrag.h>
60#include <tdetempfile.h>
61#include <tdelocale.h>
62#include <tdefiledialog.h>
63#include <tdeglobal.h>
64#include <kstandarddirs.h>
65#include <tdemessagebox.h>
66#include <kprocess.h>
67#include <tdeio/netaccess.h>
68
69#include <KoTemplateChooseDia.h>
70#include <KoRuler.h>
71#include <KoGenStyles.h>
72#include <KoFilterManager.h>
73#include <KoStore.h>
74#include <KoStoreDevice.h>
75#include <KoQueryTrader.h>
76#include <KoXmlWriter.h>
77#include <KoOasisSettings.h>
78#include <KoMainWindow.h>
79
80#include <stdlib.h>
81#include <stdio.h>
82#include <math.h>
83#include <unistd.h>
84#include <config.h>
85
86#include <KoRichText.h>
87#include <KoTextObject.h>
88#include <KoTextZoomHandler.h>
89#include <KoStyleCollection.h>
90#include <kcommand.h>
91#include "KPrDocumentIface.h"
92
93#include <tdespell2/settings.h>
94
95#include <KoVariable.h>
96#include <KoAutoFormat.h>
97#include <KoDocumentInfo.h>
98#include "KPrVariableCollection.h"
99#include "KPrBackground.h"
100#include "KPrNoteBar.h"
101#include "KPrBgSpellCheck.h"
102#include <tdeglobalsettings.h>
103#include <KoCommandHistory.h>
104#include "KoApplication.h"
105#include <KoOasisStyles.h>
106#include <KoOasisContext.h>
107
108#include "KPrLoadingInfo.h"
109
110using namespace std;
111
112static const int CURRENT_SYNTAX_VERSION = 2;
113// Make sure an appropriate DTD is available in www/koffice/DTD if changing this value
114static const char * CURRENT_DTD_VERSION = "1.2";
115
116KPrChild::KPrChild( KPrDocument *_kpr, KoDocument* _doc, const TQRect& _rect )
117 : KoDocumentChild( _kpr, _doc, _rect )
118{
119 m_parent = _kpr;
120}
121
122KPrChild::KPrChild( KPrDocument *_kpr ) :
123 KoDocumentChild( _kpr )
124{
125 m_parent = _kpr;
126}
127
128KPrChild::~KPrChild()
129{
130}
131
132KoDocument *KPrChild::hitTest( const TQPoint &, const TQWMatrix & )
133{
134 // hitTest functionality is disabled because kpresenter handles activation
135 // of embedded parts by itself. See KPrPartObject::activate().
136 return 0;
137}
138
139KPrDocument::KPrDocument( TQWidget *parentWidget, const char *widgetName, TQObject* parent, const char* name,
140 bool singleViewMode )
141 : KoDocument( parentWidget,widgetName, parent, name, singleViewMode ),
142 _gradientCollection(), m_customListTest( 0L ),
143 m_childCountBeforeInsert( 0 )
144{
145 setInstance( KPrFactory::global() );
146 setTemplateType( "kpresenter_template" );
147 //Necessary to define page where we load object otherwise copy-duplicate page doesn't work.
148 m_pageWhereLoadObject=0L;
149 m_loadingInfo=0L;
150 m_tabStop = MM_TO_POINT( 15.0 );
151 m_styleColl=new KoStyleCollection();
152 m_insertFilePage = 0;
153 m_picturePath= TDEGlobalSettings::documentPath();
154 m_globalLanguage = TDEGlobal::locale()->language();
155 m_bGlobalHyphenation = false;
156 _duplicatePage=false;
157
158 KoParagStyle* m_standardStyle = new KoParagStyle( "Standard" );
159 m_styleColl->addStyle( m_standardStyle );
160
161 TDEConfig *config = KPrFactory::global()->config();
162 config->setGroup("Document defaults" );
163 TQString defaultFontname=config->readEntry("DefaultFont");
164 if ( !defaultFontname.isEmpty() )
165 m_defaultFont.fromString( defaultFontname );
166 // If not found, we automatically fallback to the application font (the one from KControl's font module)
167
168 // Try to force a scalable font.
169 m_defaultFont.setStyleStrategy( TQFont::ForceOutline );
170 //kdDebug(33001) << "Default font: requested family: " << m_defaultFont.family() << endl;
171 //kdDebug(33001) << "Default font: real family: " << TQFontInfo(m_defaultFont).family() << endl;
172
173 int ptSize = m_defaultFont.pointSize();
174 if ( ptSize == -1 ) // specified with a pixel size ?
175 ptSize = TQFontInfo(m_defaultFont).pointSize();
176 //kdDebug(33001) << "KPrDocument::KPrDocument[2] ptSize=" << ptSize << endl;
177 // Ok, this is KPresenter. A default font of 10 makes no sense. Let's go for 20.
178 ptSize = TQMAX( 20, ptSize );
179
180 m_standardStyle->format().setFont( m_defaultFont );
181
183 m_standardStyle->format().setColor( TQt::black );
184
185 if( config->hasGroup("Interface") ) {
186 config->setGroup( "Interface" );
187 m_globalLanguage=config->readEntry("language", TDEGlobal::locale()->language());
188 m_bGlobalHyphenation=config->readBoolEntry("hyphenation", false);
189 }
190
191 m_standardStyle->format().setLanguage( m_globalLanguage);
192
193 m_zoomHandler = new KoTextZoomHandler;
194
195 m_varFormatCollection = new KoVariableFormatCollection;
196 m_varColl = new KPrVariableCollection( new KoVariableSettings(), m_varFormatCollection );
197 m_bgSpellCheck = new KPrBgSpellCheck(this);
198 dcop = 0;
199 m_initialActivePage=0;
200 m_bShowStatusBar = true;
201 m_autoFormat = new KoAutoFormat(this,m_varColl,m_varFormatCollection);
202 _clean = true;
203 _spInfiniteLoop = false;
204 _spShowEndOfPresentationSlide = true;
205 _spManualSwitch = true;
206 _showPresentationDuration = false;
207 tmpSoundFileList = TQPtrList<KTempFile>();
208 _xRnd = 20;
209 _yRnd = 20;
210 _txtBackCol = lightGray;
211 _otxtBackCol = lightGray;
212
213 m_bShowRuler=true;
214 m_bAllowAutoFormat = true;
215
216 m_bViewFormattingChars = false;
217 m_bShowGuideLines = true;
218
219 m_bShowGrid = true;
220
221 m_bSnapToGrid = true;
222
223 m_cursorInProtectectedArea=true;
224
225 usedSoundFile = TQStringList();
226 haveNotOwnDiskSoundFile = TQStringList();
227
228 m_zoomHandler->setZoomAndResolution( 100, KoGlobal::dpiX(), KoGlobal::dpiY() );
229 newZoomAndResolution(false,false);
230
231 // _pageLayout.format = PG_SCREEN;
232 // _pageLayout.orientation = PG_PORTRAIT;
233 // _pageLayout.width = PG_SCREEN_WIDTH;
234 // _pageLayout.height = PG_SCREEN_HEIGHT;
235 // _pageLayout.left = 0;
236 // _pageLayout.right = 0;
237 // _pageLayout.top = 0;
238 // _pageLayout.bottom = 0;
239 // _pageLayout.ptWidth = cMM_TO_POINT( PG_SCREEN_WIDTH );
240 // _pageLayout.ptHeight = cMM_TO_POINT( PG_SCREEN_HEIGHT );
241 // _pageLayout.ptLeft = 0;
242 // _pageLayout.ptRight = 0;
243 // _pageLayout.ptTop = 0;
244 // _pageLayout.ptBottom = 0;
245
246 m_indent = MM_TO_POINT( 10.0 );
247 m_gridX = MM_TO_POINT( 5.0 );
248 m_gridY = MM_TO_POINT( 5.0 );
249
250 oldGridX = m_gridX;
251 oldGridY = m_gridY;
252
253 m_masterPage=new KPrPage(this);
254 KPrPage *newpage = new KPrPage( this, m_masterPage );
255 m_pageList.insert( 0,newpage);
256 m_bInsertDirectCursor = false;
257
258 objStartY = 0;
259 _presPen = TQPen( red, 3, SolidLine );
260 ignoreSticky = true;
261
262 m_gridColor=TQt::black;
263
264 _header = new KPrTextObject( this );
265 _header->setDrawEditRect( false );
266 _header->setDrawEmpty( false );
267
268 _footer = new KPrTextObject( this );
269 _footer->setDrawEditRect( false );
270 _footer->setDrawEmpty( false );
271
272 saveOnlyPage = -1;
273 m_maxRecentFiles = 10;
274
275 connect( TQApplication::clipboard(), TQ_SIGNAL( dataChanged() ),
276 this, TQ_SLOT( clipboardDataChanged() ) );
277
278 m_commandHistory = new KoCommandHistory( actionCollection(), true ) ;
279 initConfig();
280
281 connect( m_commandHistory, TQ_SIGNAL( documentRestored() ), this, TQ_SLOT( slotDocumentRestored() ) );
282 connect( m_commandHistory, TQ_SIGNAL( commandExecuted() ), this, TQ_SLOT( slotCommandExecuted() ) );
283
284 dcopObject();
285}
286
287void KPrDocument::refreshMenuCustomVariable()
288{
289 emit sig_refreshMenuCustomVariable();
290}
291
292void KPrDocument::slotDocumentRestored()
293{
294 setModified( false );
295}
296
297void KPrDocument::slotCommandExecuted()
298{
299 setModified( true );
300}
301
302void KPrDocument::saveConfig()
303{
304 if ( !isReadWrite())
305 return;
306 TDEConfigGroup group( KoGlobal::kofficeConfig(), "Spelling" );
307 group.writeEntry( "PersonalDict", m_spellCheckPersonalDict );
308 if ( !isEmbedded() )
309 {
310 TDEConfig *config = KPrFactory::global()->config();
311 config->setGroup( "Interface" );
312 config->writeEntry( "Zoom", m_zoomHandler->zoom() );
313 config->writeEntry( "AllowAutoFormat" , m_bAllowAutoFormat );
314 config->writeEntry( "ViewFormattingChars", m_bViewFormattingChars );
315 config->writeEntry( "ShowGrid" , m_bShowGrid );
316 config->writeEntry( "SnapToGrid" , m_bSnapToGrid );
317 config->writeEntry( "ResolutionX", m_gridX );
318 config->writeEntry( "ResolutionY", m_gridY );
319 }
320}
321
322void KPrDocument::initConfig()
323{
324 int zoom;
325 TDEConfig* config = KPrFactory::global()->config();
326 if( config->hasGroup("Interface") ) {
327 config->setGroup( "Interface" );
328 setAutoSave( config->readNumEntry( "AutoSave", defaultAutoSave()/60 ) * 60 );
329 setBackupFile( config->readBoolEntry("BackupFile", true));
330 setCursorInProtectedArea( config->readBoolEntry( "cursorInProtectArea", true ));
331
332 // Config-file value in mm, default 10 pt
333 double indent = config->readDoubleNumEntry("Indent", MM_TO_POINT(10.0) ) ;
334 setIndentValue(indent);
335 m_maxRecentFiles = config->readNumEntry( "NbRecentFile", 10 );
336 setShowRuler(config->readBoolEntry("Rulers",true));
337 zoom = config->readNumEntry( "Zoom", 100 );
338 setShowStatusBar( config->readBoolEntry( "ShowStatusBar" , true ));
339 setAllowAutoFormat( config->readBoolEntry( "AllowAutoFormat" , true ));
340 setViewFormattingChars( config->readBoolEntry( "ViewFormattingChars", false ) );
341 setShowGrid( config->readBoolEntry( "ShowGrid" , true ));
342 setSnapToGrid( config->readBoolEntry( "SnapToGrid", true ));
343 setGridX( config->readDoubleNumEntry( "ResolutionX", MM_TO_POINT( 5.0 ) ));
344 setGridY( config->readDoubleNumEntry( "ResolutionY", MM_TO_POINT( 5.0 ) ));
345
346 m_bInsertDirectCursor= config->readBoolEntry( "InsertDirectCursor", false );
347 m_globalLanguage=config->readEntry("language", TDEGlobal::locale()->language());
348
349 }
350 else
351 zoom=100;
352
353 TQColor oldBgColor = TQt::white;
354 TQColor oldGridColor = TQt::black;
355 if ( config->hasGroup( "KPresenter Color" ) ) {
356 config->setGroup( "KPresenter Color" );
357 setTxtBackCol(config->readColorEntry( "BackgroundColor", &oldBgColor ));
358 setGridColor(config->readColorEntry( "GridColor", &oldGridColor ));
359 }
360
361
362 if( config->hasGroup("KSpell kpresenter" ) )
363 {
364 config->setGroup( "KSpell kpresenter" );
365
366 // Default is false for spellcheck, but the spell-check config dialog
367 // should write out "true" when the user configures spell checking.
368 if ( isReadWrite() )
369 m_bgSpellCheck->setEnabled(config->readBoolEntry( "SpellCheck", false ));
370 else
371 m_bgSpellCheck->setEnabled( false );
372 }
373 int undo=30;
374 if(config->hasGroup("Misc" ) )
375 {
376 config->setGroup( "Misc" );
377 undo=config->readNumEntry("UndoRedo",-1);
378 }
379 if(undo!=-1)
380 setUndoRedoLimit(undo);
381
382 if(config->hasGroup("Kpresenter Path" ) )
383 {
384 config->setGroup( "Kpresenter Path" );
385 m_picturePath=config->readPathEntry( "picture path",TDEGlobalSettings::documentPath());
386 setBackupPath(config->readPathEntry( "backup path" ));
387 }
388
389 // Load personal dict
390 TDEConfigGroup group( KoGlobal::kofficeConfig(), "Spelling" );
391 m_spellCheckPersonalDict = group.readListEntry( "PersonalDict" );
392
393 // Apply configuration, without creating an undo/redo command
394 replaceObjs( false );
395 zoomHandler()->setZoom( zoom );
396 newZoomAndResolution(false,false);
397}
398
399DCOPObject* KPrDocument::dcopObject()
400{
401 if ( !dcop )
402 dcop = new KPrDocumentIface( this );
403
404 return dcop;
405}
406
407KPrDocument::~KPrDocument()
408{
409 if(isReadWrite())
410 saveConfig();
411 clearTestCustomSlideShow();
412 //Be carefull !!!!!! don't delete this pointer delete in stickypage
413#if 0
414 delete _header;
415 delete _footer;
416#endif
417
418 delete m_commandHistory;
419 delete m_zoomHandler;
420 delete m_autoFormat;
421 delete m_varColl;
422 delete m_varFormatCollection;
423 delete dcop;
424 delete m_masterPage;
425 delete m_bgSpellCheck;
426 delete m_styleColl;
427
428 m_pageList.setAutoDelete( true );
429 m_pageList.clear();
430 m_deletedPageList.setAutoDelete( true );
431 m_deletedPageList.clear();
432 tmpSoundFileList.setAutoDelete( true );
433 tmpSoundFileList.clear();
434}
435
436void KPrDocument::addCommand( KCommand * cmd )
437{
438 kdDebug(33001) << "KPrDocument::addCommand " << cmd->name() << endl;
439 m_commandHistory->addCommand( cmd, false );
440 setModified( true );
441}
442
443bool KPrDocument::saveChildren( KoStore* _store )
444{
445 int i = 0;
446
447 TQPtrListIterator<KoDocumentChild> it( children() );
448 for( ; it.current(); ++it ) {
449 // Don't save children that are only in the undo/redo history
450 // but not anymore in the presentation
451 TQPtrListIterator<KPrPage> pageIt( m_pageList );
452 for ( int pagePos = 0; pageIt.current(); ++pageIt, ++pagePos )
453 {
454 if ( saveOnlyPage == -1 || pagePos == saveOnlyPage )
455 {
456 TQPtrListIterator<KPrObject> oIt(pageIt.current()->objectList());
457 for (; oIt.current(); ++oIt )
458 {
459 if ( oIt.current()->getType() == OT_PART &&
460 dynamic_cast<KPrPartObject*>( oIt.current() )->getChild() == it.current() )
461 {
462 if (((KoDocumentChild*)(it.current()))->document()!=0)
463 if ( !((KoDocumentChild*)(it.current()))->document()->saveToStore( _store, TQString::number( i++ ) ) )
464 return false;
465 }
466 }
467 }
468 }
469 if ( saveOnlyPage == -1 )
470 {
471 TQPtrListIterator<KPrObject> oIt(m_masterPage->objectList());
472 for (; oIt.current(); ++oIt )
473 {
474 if ( oIt.current()->getType() == OT_PART &&
475 dynamic_cast<KPrPartObject*>( oIt.current() )->getChild() == it.current() )
476 {
477 if (((KoDocumentChild*)(it.current()))->document()!=0)
478 if ( !((KoDocumentChild*)(it.current()))->document()->saveToStore( _store, TQString::number( i++ ) ) )
479 return false;
480 }
481 }
482 }
483 }
484 return true;
485}
486
487TQDomDocument KPrDocument::saveXML()
488{
489 if ( saveOnlyPage == -1 ) {
490 emit sigProgress( 0 );
491 }
492
493 m_varColl->variableSetting()->setModificationDate(TQDateTime::currentDateTime());
494 recalcVariables( VT_DATE );
495 recalcVariables( VT_TIME );
496 recalcVariables( VT_STATISTIC );
497 TQDomDocument doc = createDomDocument( "DOC", CURRENT_DTD_VERSION );
498 TQDomElement presenter=doc.documentElement();
499 presenter.setAttribute("editor", "KPresenter");
500 presenter.setAttribute("mime", "application/x-kpresenter");
501 presenter.setAttribute("syntaxVersion", CURRENT_SYNTAX_VERSION);
502 TQDomElement paper=doc.createElement("PAPER");
503 paper.setAttribute("format", static_cast<int>( m_pageLayout.format ));
504 paper.setAttribute("ptWidth", TQString::number( m_pageLayout.ptWidth, 'g', 10 ));
505 paper.setAttribute("ptHeight", TQString::number( m_pageLayout.ptHeight, 'g', 10 ));
506
507 paper.setAttribute("orientation", static_cast<int>( m_pageLayout.orientation ));
508 paper.setAttribute("unit", unit() );
509 paper.setAttribute("tabStopValue", m_tabStop );
510
511 TQDomElement paperBorders=doc.createElement("PAPERBORDERS");
512
513 paperBorders.setAttribute("ptLeft", m_pageLayout.ptLeft);
514 paperBorders.setAttribute("ptTop", m_pageLayout.ptTop);
515 paperBorders.setAttribute("ptRight", m_pageLayout.ptRight);
516 paperBorders.setAttribute("ptBottom", m_pageLayout.ptBottom);
517 paper.appendChild(paperBorders);
518 presenter.appendChild(paper);
519
520 m_varColl->variableSetting()->save(presenter );
521
522 presenter.appendChild(saveAttribute( doc ));
523
524 if ( saveOnlyPage == -1 )
525 emit sigProgress( 5 );
526
527 TQDomElement element=doc.createElement("BACKGROUND");
528 element.appendChild(saveBackground( doc ));
529 presenter.appendChild(element);
530
531 if ( saveOnlyPage == -1 )
532 emit sigProgress( 10 );
533
534 //TODO save correct page info for header/footer
535 element=doc.createElement("HEADER");
536 element.setAttribute("show", static_cast<int>( m_pageList.at(0)->hasHeader() ));
537 element.appendChild(_header->save( doc,0 ));
538 presenter.appendChild(element);
539
540 element=doc.createElement("FOOTER");
541 element.setAttribute("show", static_cast<int>( m_pageList.at(0)->hasFooter() ));
542 element.appendChild(_footer->save( doc,0 ));
543 presenter.appendChild(element);
544
545 element = doc.createElement( "HEADERFOOTERBYPAGE" );
546 element.setAttribute( "value", "true" );
547 presenter.appendChild( element );
548
549 element=doc.createElement("HELPLINES");
550 element.setAttribute("show", static_cast<int>( showGuideLines() ));
551 saveGuideLines( doc, element );
552 presenter.appendChild(element);
553
554 if ( saveOnlyPage == -1 )
555 {
556 if( !m_spellCheckIgnoreList.isEmpty() )
557 {
558 TQDomElement spellCheckIgnore = doc.createElement( "SPELLCHECKIGNORELIST" );
559 presenter.appendChild( spellCheckIgnore );
560 for ( TQStringList::Iterator it = m_spellCheckIgnoreList.begin(); it != m_spellCheckIgnoreList.end(); ++it )
561 {
562 TQDomElement spellElem = doc.createElement( "SPELLCHECKIGNOREWORD" );
563 spellCheckIgnore.appendChild( spellElem );
564 spellElem.setAttribute( "word", *it );
565 }
566 }
567 }
568
569 if ( saveOnlyPage == -1 )
570 emit sigProgress( 20 );
571
572 presenter.appendChild(saveTitle( doc ));
573
574 presenter.appendChild(saveNote( doc ));
575
576 if ( saveOnlyPage == -1 )
577 emit sigProgress( 30 );
578
579 presenter.appendChild(saveObjects(doc));
580
581 // ### If we will create a new version of the file format, fix that spelling error
582 element=doc.createElement("INFINITLOOP");
583 element.setAttribute("value", _spInfiniteLoop);
584 element=doc.createElement("SHOWENDOFPRESENTATIONSLIDE");
585 element.setAttribute("value", _spShowEndOfPresentationSlide);
586 presenter.appendChild(element);
587 element=doc.createElement("MANUALSWITCH");
588 element.setAttribute("value", _spManualSwitch);
589 presenter.appendChild(element);
590 element=doc.createElement("PRESSPEED");
591//TODO FIXME !!!!!!!!!!
592//element.setAttribute("value", static_cast<int>( presSpeed ));
593 presenter.appendChild(element);
594 element=doc.createElement("SHOWPRESENTATIONDURATION");
595 element.setAttribute("value", _showPresentationDuration);
596 presenter.appendChild(element);
597
598 if ( saveOnlyPage == -1 )
599 {
600 if ( !m_customListSlideShow.isEmpty() )
601 {
602 TQMap<KPrPage *, TQString> page2name;
603 int pos = 1;
604 for ( TQPtrListIterator<KPrPage> it( m_pageList ); it.current(); ++it )
605 {
606 page2name.insert( it.current(), "page" + TQString::number( pos++ ) ) ;
607 }
608
609 element = doc.createElement( "CUSTOMSLIDESHOWCONFIG" );
610 CustomSlideShowMap::Iterator it;
611 for ( it = m_customListSlideShow.begin(); it != m_customListSlideShow.end(); ++it )
612 {
613 TQDomElement slide=doc.createElement("CUSTOMSLIDESHOW");
614 slide.setAttribute("name", it.key() );
615 TQString tmp;
616 TQValueListIterator<KPrPage*> itPage ;
617 for( itPage = ( *it ).begin(); itPage != ( *it ).end(); ++itPage )
618 {
619 int posPage = m_pageList.find( *itPage );
620 if ( posPage != -1 )
621 {
622 if ( itPage != ( *it ).begin() )
623 tmp += ",";
624 tmp += page2name[*itPage];
625 }
626 }
627 slide.setAttribute( "pages", tmp );
628 element.appendChild(slide);
629 }
630 presenter.appendChild(element);
631
632 }
633
634 if ( !m_presentationName.isEmpty() )
635 {
636 element = doc.createElement( "DEFAULTCUSTOMSLIDESHOWNAME" );
637 element.setAttribute( "name", m_presentationName );
638 presenter.appendChild(element);
639 }
640 }
641
642 if ( saveOnlyPage == -1 )
643 emit sigProgress( 40 );
644
645 if ( saveOnlyPage == -1 )
646 {
647 element=doc.createElement("SELSLIDES");
648 for ( uint i = 0; i < m_pageList.count(); i++ ) {
649 TQDomElement slide=doc.createElement("SLIDE");
650 slide.setAttribute("nr", i);
651 slide.setAttribute("show", m_pageList.at(i)->isSlideSelected());
652 element.appendChild(slide);
653 }
654 presenter.appendChild(element);
655
656 emit sigProgress( 50 );
657 }
658
659 if ( saveOnlyPage == -1 )
660 {
661 TQDomElement styles = doc.createElement( "STYLES" );
662 presenter.appendChild( styles );
663 TQValueList<KoUserStyle *> styleList(m_styleColl->styleList());
664 for ( TQValueList<KoUserStyle *>::const_iterator it = styleList.begin(), end = styleList.end();
665 it != end ; ++it )
666 saveStyle( static_cast<KoParagStyle *>( *it ), styles );
667
668 emit sigProgress( 60 );
669 }
670
671 // Write "OBJECT" tag for every child
672 TQPtrListIterator<KoDocumentChild> chl( children() );
673 for( ; chl.current(); ++chl ) {
674 // Don't save children that are only in the undo/redo history
675 // but not anymore in the presentation
676 for ( int i = 0; i < static_cast<int>( m_pageList.count() ); i++ ) {
677 if ( saveOnlyPage != -1 && i != saveOnlyPage )
678 continue;
679 double offset=0;
680 if ( saveOnlyPage == -1 )
681 {
682 offset = i * m_pageList.at(i)->getPageRect().height();
683 }
684 saveEmbeddedObject(m_pageList.at(i), chl.current(),doc,presenter,offset );
685 }
686 if ( saveOnlyPage == -1 )
687 {
688 saveEmbeddedObject(m_masterPage, chl.current(),doc,presenter,0.0 );
689 }
690 }
691
692 if ( saveOnlyPage == -1 )
693 emit sigProgress( 70 );
694 makeUsedPixmapList();
695
696 TQDomElement pictures = m_pictureCollection.saveXML( KoPictureCollection::CollectionPicture, doc, usedPictures );
697 presenter.appendChild( pictures );
698
699 if ( saveOnlyPage == -1 )
700 emit sigProgress( 90 );
701
702 // Save sound file list.
703 makeUsedSoundFileList();
704 TQDomElement soundFiles = saveUsedSoundFileToXML( doc, usedSoundFile );
705 presenter.appendChild( soundFiles );
706
707 if ( saveOnlyPage == -1 )
708 setModified( false );
709 return doc;
710}
711
712void KPrDocument::saveEmbeddedObject(KPrPage *page, const TQPtrList<KoDocumentChild>& childList,
713 TQDomDocument &doc,TQDomElement &presenter )
714{
715 TQPtrListIterator<KoDocumentChild> chl( childList );
716 double offset = 0.0;
717 // we need no offset for objects on the master page and when we copy a page
718 if ( m_pageList.findRef( page ) )
719 {
720 offset=m_pageList.findRef(page)*page->getPageRect().height();
721 }
722 for( ; chl.current(); ++chl )
723 saveEmbeddedObject(page, chl.current(),doc,presenter, offset );
724}
725
726void KPrDocument::saveEmbeddedObject(KPrPage *page, KoDocumentChild *chl, TQDomDocument &doc,
727 TQDomElement &presenter, double offset )
728{
729 TQPtrListIterator<KPrObject> oIt(page->objectList());
730 for ( int pos = 0; oIt.current(); ++oIt, ++pos )
731 {
732 if ( oIt.current()->getType() == OT_PART &&
733 static_cast<KPrPartObject*>( oIt.current() )->getChild() == chl )
734 {
735 TQDomElement embedded=doc.createElement("EMBEDDED");
736 KPrChild* curr = (KPrChild*)chl;
737
738 // geometry is no zoom value !
739 TQRect _rect = curr->geometry();
740 int tmpX = (int)zoomHandler()->unzoomItX( _rect.x() );
741 int tmpY = (int)zoomHandler()->unzoomItY( _rect.y() );
742 int tmpWidth = (int)zoomHandler()->unzoomItX( _rect.width() );
743 int tmpHeight = (int)zoomHandler()->unzoomItY( _rect.height() );
744 curr->setGeometry( TQRect( tmpX, tmpY, tmpWidth, tmpHeight ) );
745
746 embedded.appendChild(curr->save(doc, true));
747
748 curr->setGeometry( _rect ); // replace zoom value
749
750 TQDomElement settings=doc.createElement("SETTINGS");
751 settings.setAttribute( "z-index", pos );
752 if ( page == m_masterPage )
753 settings.setAttribute("sticky", 1 );
754 TQPtrListIterator<KPrObject> setOIt(page->objectList());
755 for (; setOIt.current(); ++setOIt )
756 {
757 if ( setOIt.current()->getType() == OT_PART &&
758 dynamic_cast<KPrPartObject*>( setOIt.current() )->getChild() == curr )
759 settings.appendChild(setOIt.current()->save( doc,offset ));
760 }
761 embedded.appendChild(settings);
762 presenter.appendChild(embedded);
763 }
764 }
765
766}
767
768//TODO with changes with new file format header/footer can't be change
769void KPrDocument::compatibilityFromOldFileFormat()
770{
771 //function to keep compatibility with old file format
772 //for example for presSpeed
773 if ( m_loadingInfo && m_loadingInfo->oldFormat() )
774 {
775 EffectSpeed newValue = ES_MEDIUM;
776 bool presSpeedChanged = ( m_loadingInfo->presSpeed != -1 );
777 if ( presSpeedChanged )
778 {
779 if ( m_loadingInfo->presSpeed < 3 )
780 newValue = ES_SLOW;
781 else if ( m_loadingInfo->presSpeed > 7 )
782 newValue = ES_FAST;
783 }
784 if ( !m_loadingInfo->m_headerFooterByPage )
785 {
786 for ( int i = 0; i < static_cast<int>( m_pageList.count() ); i++ )
787 {
788 if ( presSpeedChanged )
789 m_pageList.at(i)->setPageEffectSpeed( newValue );
790 m_pageList.at( i )->setHeader( m_loadingInfo->m_header );
791 m_pageList.at( i )->setFooter( m_loadingInfo->m_footer );
792 }
793 }
794
795 }
796 delete m_loadingInfo;
797 m_loadingInfo = 0L;
798
799}
800
801void KPrDocument::enableEmbeddedParts( bool f )
802{
803 TQPtrListIterator<KPrPage> it( m_pageList );
804 for ( ; it.current(); ++it )
805 it.current()->enableEmbeddedParts(f);
806}
807
808TQDomDocumentFragment KPrDocument::saveBackground( TQDomDocument &doc )
809{
810 TQDomDocumentFragment fragment=doc.createDocumentFragment();
811 for ( int i = 0; i < static_cast<int>( m_pageList.count() ); i++ ) {
812 if ( saveOnlyPage != -1 && i != saveOnlyPage )
813 continue;
814 fragment.appendChild( m_pageList.at(i)->save( doc ) );
815 }
816 // save backgound of masterpage only when the complete doc is saved
817 if ( saveOnlyPage == -1 )
818 {
819 fragment.appendChild( m_masterPage->save( doc ) );
820 }
821 return fragment;
822}
823
824TQDomElement KPrDocument::saveObjects( TQDomDocument &doc )
825{
826 TQDomElement objects=doc.createElement("OBJECTS");
827 double yoffset=0.0;
828 for ( int i = 0; i < static_cast<int>( m_pageList.count() ); i++ ) {
829 if ( saveOnlyPage != -1 && saveOnlyPage!=i)
830 continue;
831 yoffset=i*m_pageList.at(i)->getPageRect().height(); // yoffset is not zoom value !!
832 objects=m_pageList.at(i)->saveObjects( doc, objects, yoffset, saveOnlyPage );
833
834 }
835 if ( !_duplicatePage ) //don't copy objects on master slide when we duplicate page
836 {
837 objects = m_masterPage->saveObjects( doc, objects, 0.0, saveOnlyPage );
838 }
839
840 return objects;
841}
842
843TQDomElement KPrDocument::saveTitle( TQDomDocument &doc )
844{
845 TQDomElement titles=doc.createElement("PAGETITLES");
846
847 if ( saveOnlyPage == -1 )
848 { // All page titles.
849 for ( int i = 0; i < static_cast<int>( m_pageList.count() ); i++ )
850 {
851 TQDomElement title=doc.createElement("Title");
852 title.setAttribute("title", m_pageList.at(i)->manualTitle());
853 titles.appendChild(title);
854 }
855 }
856 else
857 { // Only current page title.
858 TQDomElement title=doc.createElement("Title");
859 title.setAttribute("title", m_pageList.at(saveOnlyPage)->manualTitle());
860 titles.appendChild(title);
861 }
862 return titles;
863}
864
865TQDomElement KPrDocument::saveNote( TQDomDocument &doc )
866{
867 TQDomElement notes=doc.createElement("PAGENOTES");
868
869 if ( saveOnlyPage == -1 ) { // All page notes.
870 for ( int i = 0; i < static_cast<int>( m_pageList.count() ); i++ )
871 {
872 TQDomElement note=doc.createElement("Note");
873 note.setAttribute("note", m_pageList.at(i)->noteText( ));
874 notes.appendChild(note);
875 }
876 }
877 else { // Only current page note.
878 TQDomElement note=doc.createElement("Note");
879 note.setAttribute("note", m_pageList.at(saveOnlyPage)->noteText( ));
880 notes.appendChild(note);
881 }
882
883 return notes;
884}
885
886TQDomElement KPrDocument::saveAttribute( TQDomDocument &doc )
887{
888 TQDomElement attributes=doc.createElement("ATTRIBUTES");
889 //store first view parameter.
890 int activePage=0;
891
892 if ( m_initialActivePage )
893 activePage=m_pageList.findRef(m_initialActivePage);
894 activePage = TQMAX( activePage, 0);
895 attributes.setAttribute("activePage",activePage );
896 attributes.setAttribute("gridx", m_gridX );
897 attributes.setAttribute("gridy", m_gridY );
898 attributes.setAttribute("snaptogrid", (int)m_bSnapToGrid );
899 return attributes;
900}
901
902TQDomElement KPrDocument::saveUsedSoundFileToXML( TQDomDocument &_doc, TQStringList _list )
903{
904 TQDomElement soundFiles = _doc.createElement( "SOUNDS" );
905
906 unsigned int i = 0;
907 TQStringList::Iterator it = _list.begin();
908 for ( ; it != _list.end(); ++it ) {
909 TQString soundFileName = *it;
910 int position = soundFileName.findRev( '.' );
911 TQString format = soundFileName.right( soundFileName.length() - position - 1 );
912 TQString _name = TQString( "sounds/sound%1.%2" ).arg( ++i ).arg( format.lower() );
913
914 TQDomElement fileElem = _doc.createElement( "FILE" );
915 soundFiles.appendChild( fileElem );
916 fileElem.setAttribute( "filename", soundFileName );
917 fileElem.setAttribute( "name", _name );
918 }
919
920 return soundFiles;
921}
922
923bool KPrDocument::completeSaving( KoStore* _store )
924{
925 if ( !_store ) {
926 if ( saveOnlyPage == -1 ) {
927 emit sigProgress( 100 );
928 emit sigProgress( -1 );
929 }
930 return true;
931 }
932
933 m_pictureCollection.saveToStore( KoPictureCollection::CollectionPicture, _store, usedPictures );
934
935 saveUsedSoundFileToStore( _store, usedSoundFile );
936
937 if ( saveOnlyPage == -1 ) {
938 emit sigProgress( 100 );
939 emit sigProgress( -1 );
940 }
941
942 return true;
943}
944
945int KPrDocument::supportedSpecialFormats() const
946{
947 return KoDocument::supportedSpecialFormats();
948}
949
950void KPrDocument::saveUsedSoundFileToStore( KoStore *_store, TQStringList _list )
951{
952 unsigned int i = 0;
953 TQStringList::Iterator it = _list.begin();
954 for ( ; it != _list.end(); ++it ) {
955 TQString soundFileName = *it;
956 int position = soundFileName.findRev( '.' );
957 TQString format = soundFileName.right( soundFileName.length() - position - 1 );
958 TQString _storeURL = TQString( "sounds/sound%1.%2" ).arg( ++i ).arg( format.lower() );
959
960 if ( _store->open( _storeURL ) ) {
961 KoStoreDevice dev( _store );
962 TQFile _file( soundFileName );
963 if ( _file.open( IO_ReadOnly ) ) {
964 dev.writeBlock( ( _file.readAll() ).data(), _file.size() );
965 _file.close();
966 }
967 _store->close();
968 }
969 }
970}
971
972bool KPrDocument::loadChildren( KoStore* _store )
973{
974 if ( objStartY == 0 && _clean) // Don't do this when inserting a template or a page...
975 {
976 TQPtrListIterator<KoDocumentChild> it( children() );
977 for( ; it.current(); ++it ) {
978 if ( !((KoDocumentChild*)it.current())->loadDocument( _store ) )
979 return false;
980 }
981 }
982 else // instead load form the correct child on, m_childCountBeforeInsert has the be set
983 {
984 TQPtrListIterator<KoDocumentChild> it( children() );
985 for( int i = 0; it.current(); ++it, ++i ) {
986 if ( i < m_childCountBeforeInsert )
987 continue;
988 if ( !((KoDocumentChild*)it.current())->loadDocument( _store ) )
989 return false;
990 }
991 }
992 return true;
993}
994
995bool KPrDocument::saveOasis( KoStore* store, KoXmlWriter* manifestWriter )
996{
997
998 //todo necessary for new format ?
999 if ( saveOnlyPage == -1 ) {
1000 emit sigProgress( 0 );
1001 }
1002 if ( !store->open( "content.xml" ) )
1003 return false;
1004 m_pictureCollection.assignUniqueIds();
1005 KoStoreDevice contentDev( store );
1006 KoXmlWriter* contentWriter = createOasisXmlWriter( &contentDev, "office:document-content" );
1007
1008
1009 m_varColl->variableSetting()->setModificationDate(TQDateTime::currentDateTime());
1010 recalcVariables( VT_DATE );
1011 recalcVariables( VT_TIME );
1012 recalcVariables( VT_STATISTIC );
1013 KoGenStyles mainStyles;
1014 KoSavingContext savingContext( mainStyles, 0, false, KoSavingContext::Store );
1015
1016 // Save user styles as KoGenStyle objects
1017 m_styleColl->saveOasis( mainStyles, KoGenStyle::STYLE_USER, savingContext );
1018
1019 KTempFile contentTmpFile;
1020 contentTmpFile.setAutoDelete( true );
1021 TQFile* tmpFile = contentTmpFile.file();
1022 KoXmlWriter contentTmpWriter( tmpFile, 1 );
1023
1024
1025 //For sticky objects
1026 KTempFile stickyTmpFile;
1027 stickyTmpFile.setAutoDelete( true );
1028 TQFile* masterStyles = stickyTmpFile.file();
1029 KoXmlWriter stickyTmpWriter( masterStyles, 1 );
1030
1031
1032 contentTmpWriter.startElement( "office:body" );
1033 contentTmpWriter.startElement( "office:presentation" );
1034
1035 saveOasisCustomFied( contentTmpWriter );
1036
1037 int indexObj = 1;
1038 int partIndexObj = 0;
1039//save page
1040
1041 TQMap<TQString, int> pageNames;
1042
1043 if ( !_duplicatePage )
1044 {
1045 m_masterPage->saveOasisPage( store, stickyTmpWriter, 0, savingContext, indexObj, partIndexObj, manifestWriter, pageNames );
1046
1047 // Now mark all autostyles as "for styles.xml" since headers/footers need them
1048 TQValueList<KoGenStyles::NamedStyle> autoStyles = mainStyles.styles( KoGenStyle::STYLE_AUTO );
1049 for ( TQValueList<KoGenStyles::NamedStyle>::const_iterator it = autoStyles.begin();
1050 it != autoStyles.end(); ++it ) {
1051 kdDebug() << "marking for styles.xml:" << ( *it ).name << endl;
1052 mainStyles.markStyleForStylesXml( ( *it ).name );
1053 }
1054
1055 }
1056
1057 if ( saveOnlyPage != -1 )
1058 {
1059 m_pageList.at( saveOnlyPage )->saveOasisPage( store, contentTmpWriter, ( saveOnlyPage+1 ), savingContext, indexObj, partIndexObj , manifestWriter, pageNames );
1060 }
1061 else
1062 {
1063 for ( int i = 0; i < static_cast<int>( m_pageList.count() ); i++ )
1064 {
1065 m_pageList.at( i )->saveOasisPage( store, contentTmpWriter, ( i+1 ), savingContext, indexObj, partIndexObj , manifestWriter, pageNames );
1066 }
1067 }
1068 if ( saveOnlyPage == -1 ) //don't save setting when we save on page
1069 {
1070 TQMap<int, TQString> page2name;
1071 TQMap<TQString, int>::ConstIterator it( pageNames.begin() );
1072 for ( ; it != pageNames.end(); ++it )
1073 {
1074 page2name.insert( it.data(), it.key() );
1075 }
1076 saveOasisPresentationSettings( contentTmpWriter, page2name );
1077 }
1078
1079 contentTmpWriter.endElement(); //office:presentation
1080 contentTmpWriter.endElement(); //office:body
1081
1082 writeAutomaticStyles( *contentWriter, mainStyles, savingContext, false );
1083
1084 // And now we can copy over the contents from the tempfile to the real one
1085 tmpFile->close();
1086 contentWriter->addCompleteElement( tmpFile );
1087 contentTmpFile.close();
1088
1089 contentWriter->endElement(); // root element
1090 contentWriter->endDocument();
1091 delete contentWriter;
1092
1093 if ( !store->close() ) // done with content.xml
1094 return false;
1095
1096 //add manifest line for content.xml
1097 manifestWriter->addManifestEntry( "content.xml", "text/xml" );
1098
1099 if ( !store->open( "styles.xml" ) )
1100 return false;
1101
1102 manifestWriter->addManifestEntry( "styles.xml", "text/xml" );
1103
1104 //todo fixme????
1105 masterStyles->close();
1106 saveOasisDocumentStyles( store, mainStyles, masterStyles, savingContext );
1107 stickyTmpFile.close();
1108
1109 if ( !store->close() ) // done with styles.xml
1110 return false;
1111
1112
1113 if ( saveOnlyPage == -1 )
1114 emit sigProgress( 90 );
1115
1116 // Save sound file list.
1117//todo ????
1118
1119
1120 makeUsedPixmapList();
1121
1122 m_pictureCollection.saveOasisToStore( store, usedPictures, manifestWriter);
1123
1124 if(!store->open("settings.xml"))
1125 return false;
1126
1127 KoXmlWriter& settingsWriter = *createOasisXmlWriter(&contentDev, "office:document-settings");
1128 settingsWriter.startElement("office:settings");
1129
1130 settingsWriter.startElement("config:config-item-set");
1131 settingsWriter.addAttribute("config:name", "view-settings");
1132
1133 KoUnit::saveOasis(&settingsWriter, unit());
1134 saveOasisSettings( settingsWriter );
1135
1136 settingsWriter.endElement(); // config:config-item-set
1137
1138 settingsWriter.startElement("config:config-item-set");
1139 settingsWriter.addAttribute("config:name", "configuration-settings");
1140 settingsWriter.addConfigItem("SpellCheckerIgnoreList", m_spellCheckIgnoreList.join( "," ) );
1141 settingsWriter.addConfigItem("ShowPresentationDuration", _showPresentationDuration );
1142 settingsWriter.endElement(); // config:config-item-set
1143
1144 m_varColl->variableSetting()->saveOasis( settingsWriter );
1145
1146 settingsWriter.endElement(); // office:settings
1147 settingsWriter.endElement(); // Root:Element
1148 settingsWriter.endDocument();
1149 delete &settingsWriter;
1150
1151 if(!store->close())
1152 return false;
1153
1154 manifestWriter->addManifestEntry("settings.xml", "text/xml");
1155
1156 //reset progressbar
1157 emit sigProgress( 100 );
1158 emit sigProgress( -1 );
1159
1160 setModified( false );
1161
1162 return true;
1163}
1164
1165void KPrDocument::saveOasisCustomFied( KoXmlWriter &writer )const
1166{
1167 bool customVariableFound = false;
1168 TQPtrListIterator<KoVariable> it( m_varColl->getVariables() );
1169 for ( ; it.current() ; ++it )
1170 {
1171 if ( it.current()->type() == VT_CUSTOM )
1172 {
1173 if ( !customVariableFound )
1174 {
1175 writer.startElement( "text:user-field-decls" );
1176 customVariableFound = true;
1177 }
1178 //<text:user-field-decl office:value-type="string" office:string-value="dfddd" text:name="cvbcbcbx"/>
1179 writer.startElement( "text:user-field-decl" );
1180 writer.addAttribute( "office:value-type", "string" );
1181 writer.addAttribute( "office:string-value", static_cast<KoCustomVariable *>( it.current() )->value() );
1182 writer.addAttribute( "text:name", static_cast<KoCustomVariable*>( it.current() )->name() );
1183 writer.endElement();
1184 }
1185 }
1186 if ( customVariableFound )
1187 writer.endElement();
1188}
1189
1190void KPrDocument::loadOasisIgnoreList( const KoOasisSettings& settings )
1191{
1192 KoOasisSettings::Items configurationSettings = settings.itemSet( "configuration-settings" );
1193 if ( !configurationSettings.isNull() )
1194 {
1195 _showPresentationDuration = configurationSettings.parseConfigItemBool( "ShowPresentationDuration", false );
1196 const TQString ignorelist = configurationSettings.parseConfigItemString( "SpellCheckerIgnoreList" );
1197 m_spellCheckIgnoreList = TQStringList::split( ',', ignorelist );
1198 }
1199}
1200
1201void KPrDocument::writeAutomaticStyles( KoXmlWriter& contentWriter, KoGenStyles& mainStyles, KoSavingContext& context, bool stylesDotXml )
1202{
1203 if ( !stylesDotXml )
1204 {
1205 context.writeFontFaces( contentWriter );
1206 contentWriter.startElement( "office:automatic-styles" );
1207 }
1208 TQValueList<KoGenStyles::NamedStyle> styles = mainStyles.styles( KoGenStyle::STYLE_AUTO, stylesDotXml );
1209 TQValueList<KoGenStyles::NamedStyle>::const_iterator it = styles.begin();
1210 for ( ; it != styles.end() ; ++it ) {
1211 (*it).style->writeStyle( &contentWriter, mainStyles, "style:style", (*it).name, "style:paragraph-properties" );
1212 }
1213
1214 styles = mainStyles.styles( KoGenStyle::STYLE_AUTO_LIST, stylesDotXml );
1215 it = styles.begin();
1216 for ( ; it != styles.end() ; ++it ) {
1217 ( *it ).style->writeStyle( &contentWriter, mainStyles, "text:list-style", (*it).name, 0 );
1218 }
1219
1220 styles = mainStyles.styles( STYLE_BACKGROUNDPAGEAUTO, stylesDotXml );
1221 it = styles.begin();
1222 for ( ; it != styles.end() ; ++it ) {
1223 (*it).style->writeStyle( &contentWriter, mainStyles, "style:style", (*it).name, "style:drawing-page-properties" );
1224 }
1225
1226 styles = mainStyles.styles( KoGenStyle::STYLE_GRAPHICAUTO, stylesDotXml );
1227 it = styles.begin();
1228 for ( ; it != styles.end() ; ++it ) {
1229 (*it).style->writeStyle( &contentWriter, mainStyles, "style:style", (*it).name , "style:graphic-properties" );
1230 }
1231
1232 styles = mainStyles.styles( KoGenStyle::STYLE_NUMERIC_DATE, stylesDotXml );
1233 it = styles.begin();
1234 for ( ; it != styles.end() ; ++it ) {
1235 (*it).style->writeStyle( &contentWriter, mainStyles, "number:date-style", (*it).name, 0 /*TODO ????*/ );
1236 }
1237 styles = mainStyles.styles( KoGenStyle::STYLE_NUMERIC_TIME, stylesDotXml );
1238 it = styles.begin();
1239 for ( ; it != styles.end() ; ++it ) {
1240 (*it).style->writeStyle( &contentWriter, mainStyles, "number:time-style", (*it).name, 0 /*TODO ????*/ );
1241 }
1242
1243 if ( !stylesDotXml )
1244 {
1245 contentWriter.endElement(); // office:automatic-styles
1246 }
1247}
1248
1249void KPrDocument::loadOasisHeaderFooter(TQDomNode & drawPage, KoOasisContext & context)
1250{
1251 TQDomNode tmp = KoDom::namedItemNS( drawPage, KoXmlNS::style, "header" );
1252 if ( !tmp.isNull() )
1253 {
1254 //kdDebug()<<" there is a header \n";
1255 _header->textObject()->loadOasisContent( tmp.toElement(), context, styleCollection() );
1256 }
1257 tmp = KoDom::namedItemNS( drawPage, KoXmlNS::style, "footer" );
1258 if ( !tmp.isNull() )
1259 {
1260 //kdDebug()<<" there is a footer \n";
1261 _footer->textObject()->loadOasisContent( tmp.toElement(), context, styleCollection() );
1262 }
1263}
1264
1265void KPrDocument::saveOasisSettings( KoXmlWriter &settingsWriter )
1266{
1267 settingsWriter.startElement("config:config-item-map-indexed");
1268 settingsWriter.addAttribute("config:name", "Views");
1269 settingsWriter.startElement( "config:config-item-map-entry" );
1270
1271 //ooimpress save it as this line.
1272 //<config:config-item config:name="SnapLinesDrawing" config:type="string">H2260V14397H7693H12415H15345H1424</config:config-item>
1273 TQString guideLinesOasis;
1274 //save in mm as in oo
1275 for( TQValueList<double>::Iterator it = m_vGuideLines.begin(); it != m_vGuideLines.end(); ++it )
1276 {
1277 int tmpX = ( int ) ( KoUnit::toMM( *it )*100 );
1278 guideLinesOasis += "V" + TQString::number( tmpX );
1279 }
1280
1281 for( TQValueList<double>::Iterator it = m_hGuideLines.begin(); it != m_hGuideLines.end(); ++it )
1282 {
1283 int tmpY = ( int ) ( KoUnit::toMM( *it )*100 );
1284 guideLinesOasis += "H" + TQString::number( tmpY );
1285 }
1286 if ( !guideLinesOasis.isEmpty() )
1287 {
1288 settingsWriter.addConfigItem( "SnapLinesDrawing", guideLinesOasis );
1289 }
1290 //<config:config-item config:name="IsSnapToGrid" config:type="boolean">false</config:config-item>
1291 settingsWriter.addConfigItem( "IsSnapToGrid", m_bSnapToGrid );
1292
1293 //<config:config-item config:name="GridFineWidth" config:type="int">500</config:config-item>
1294 settingsWriter.addConfigItem( "GridFineWidth", ( ( int ) ( KoUnit::toMM( ( m_gridX ) )*100 ) ) );
1295
1296
1297 //<config:config-item config:name="GridFineHeight" config:type="int">500</config:config-item>
1298 settingsWriter.addConfigItem( "GridFineHeight", ( ( int ) ( KoUnit::toMM( ( m_gridY ) )*100 ) ) );
1299
1300 //<config:config-item config:name="SelectedPage" config:type="short">3</config:config-item>
1301 //store first view parameter.
1302 int activePage=0;
1303 if ( m_initialActivePage )
1304 activePage=m_pageList.findRef(m_initialActivePage);
1305 activePage = TQMAX( activePage, 0);
1306 settingsWriter.addConfigItem( "SelectedPage", activePage );
1307
1308 //not define into oo spec
1309 settingsWriter.addConfigItem( "SnapLineIsVisible", showGuideLines() );
1310 settingsWriter.endElement();
1311 settingsWriter.endElement();
1312}
1313
1314void KPrDocument::loadOasisSettings(const TQDomDocument&settingsDoc)
1315{
1316 kdDebug(33001)<<"void KPrDocument::loadOasisSettings(const TQDomDocument&settingsDoc)**********\n";
1317 KoOasisSettings settings( settingsDoc );
1318 KoOasisSettings::Items viewSettings = settings.itemSet( "view-settings" );
1319 setUnit(KoUnit::unit(viewSettings.parseConfigItemString("unit")));
1320 KoOasisSettings::IndexedMap viewMap = viewSettings.indexedMap( "Views" );
1321 KoOasisSettings::Items firstView = viewMap.entry( 0 );
1322 if ( !firstView.isNull() )
1323 {
1324 parseOasisGuideLines( firstView.parseConfigItemString( "SnapLinesDrawing" ) );
1325 setShowGuideLines( firstView.parseConfigItemBool( "SnapLineIsVisible" ) );
1326 int valx = firstView.parseConfigItemInt( "GridFineWidth" );
1327 m_gridX = MM_TO_POINT( valx / 100.0 );
1328 int valy = firstView.parseConfigItemInt( "GridFineHeight" );
1329 m_gridY = MM_TO_POINT( valy / 100.0 );
1330
1331 m_bSnapToGrid = firstView.parseConfigItemBool( "IsSnapToGrid" );
1332
1333 int activePage = firstView.parseConfigItemInt( "SelectedPage" );
1334 kdDebug(33001)<<" activePage :"<<activePage<<endl;
1335 if(activePage!=-1)
1336 m_initialActivePage=m_pageList.at(activePage);
1337 }
1338 loadOasisIgnoreList( settings );
1339 m_varColl->variableSetting()->loadOasis( settings );
1340}
1341
1342void KPrDocument::parseOasisGuideLines( const TQString &text )
1343{
1344 TQString str;
1345 int newPos = text.length()-1; //start to element = 1
1346 for ( int pos = text.length()-1; pos >=0;--pos )
1347 {
1348 if ( text[pos]=='V' )
1349 {
1350 //vertical element
1351 str = text.mid( pos+1, ( newPos-pos ) );
1352 //kdDebug()<<" vertical :"<< str <<endl;
1353 double posX = ( str.toInt() / 100.0 );
1354 m_vGuideLines.append( MM_TO_POINT( posX ) );
1355 newPos = pos-1;
1356 }
1357 else if ( text[pos]=='H' )
1358 {
1359 //horizontal element
1360 str = text.mid( pos+1, ( newPos-pos ) );
1361 //kdDebug()<<" horizontal :"<< str <<endl;
1362 double posY = ( str.toInt() / 100.0 );
1363 m_hGuideLines.append( MM_TO_POINT( posY ) );
1364 newPos = pos-1;
1365 }
1366 }
1367}
1368
1369void KPrDocument::loadOasisPresentationSettings( TQDomNode &settingsDoc )
1370{
1371 //kdDebug()<<"presentation:settings ********************************************* \n";
1372 TQDomElement settings( settingsDoc.toElement() );
1373 //kdDebug()<<"settings.attribute(presentation:endless) :"<<settings.attributeNS( KoXmlNS::presentation, "endless", TQString())<<endl;
1374 if (settings.attributeNS( KoXmlNS::presentation, "endless", TQString())=="true")
1375 _spInfiniteLoop = true;
1376 if (settings.attributeNS( KoXmlNS::presentation, "show-end-of-presentation-slide", TQString())=="true")
1377 _spShowEndOfPresentationSlide = true;
1378 if (settings.attributeNS( KoXmlNS::presentation, "force-manual", TQString())=="true")
1379 _spManualSwitch = true;
1380 if ( settings.hasAttributeNS( KoXmlNS::presentation, "start-page" ) )
1381 {
1382 //TODO allow to start presentation to specific page
1383 //???? = settings.attributeNS( KoXmlNS::presentation, "start-page", TQString() );
1384 }
1385 if ( settings.hasAttributeNS( KoXmlNS::presentation, "show" ) )
1386 {
1387 m_presentationName = settings.attributeNS( KoXmlNS::presentation, "show", TQString() );
1388 kdDebug()<<" default presentation name :"<<m_presentationName<<endl;
1389 }
1390 loadOasisPresentationCustomSlideShow( settingsDoc );
1391}
1392
1393void KPrDocument::loadOasisPresentationCustomSlideShow( TQDomNode &settingsDoc )
1394{
1395 //kdDebug()<<"void KPrDocument::loadOasisPresentationCustomSlideShow( TQDomNode &settingsDoc )**********\n";
1396 for ( TQDomNode element = settingsDoc.firstChild(); !element.isNull(); element = element.nextSibling() )
1397 {
1398 TQDomElement e = element.toElement();
1399 TQCString tagName = e.tagName().latin1();
1400 //kdDebug()<<" tagName :"<<tagName<<endl;
1401 if ( tagName == "show" && e.namespaceURI() == KoXmlNS::presentation )
1402 {
1403 //kdDebug()<<" e.attribute(presentation:name) :"<<e.attributeNS( KoXmlNS::presentation, "name", TQString())<< " e.attribute(presentation:pages) :"<<e.attributeNS( KoXmlNS::presentation, "pages", TQString())<<endl;
1404 TQString name = e.attributeNS( KoXmlNS::presentation, "name", TQString() );
1405 TQStringList tmp = TQStringList::split( ",", e.attributeNS( KoXmlNS::presentation, "pages", TQString()) );
1406 TQValueList<KPrPage *> pageList;
1407 for ( TQStringList::Iterator it = tmp.begin(); it != tmp.end(); ++it )
1408 {
1409 if ( m_loadingInfo->m_name2page.contains( *it ) )
1410 {
1411 kdDebug(33001) << "slide show " << name << " page = " << *it << endl;
1412 pageList.push_back( m_loadingInfo->m_name2page[*it] );
1413 }
1414 }
1415 if ( ! pageList.empty() )
1416 {
1417 m_customListSlideShow.insert( name, pageList );
1418 }
1419 }
1420 }
1421}
1422
1423void KPrDocument::saveOasisPresentationSettings( KoXmlWriter &contentTmpWriter, TQMap<int, TQString> &page2name )
1424{
1425 //todo don't save when is not value by default (check with oo)
1426 //FIXME
1427 contentTmpWriter.startElement( "presentation:settings" );
1428 contentTmpWriter.addAttribute( "presentation:endless", ( _spInfiniteLoop ? "true" : "false" ) );
1429 contentTmpWriter.addAttribute( "presentation:show-end-of-presentation-slide", ( _spShowEndOfPresentationSlide ? "true" : "false" ) );
1430 contentTmpWriter.addAttribute( "presentation:force-manual", ( _spManualSwitch ? "true" : "false" ) );
1431 //add for default presentation
1432 if ( !m_presentationName.isEmpty() )
1433 contentTmpWriter.addAttribute( "presentation:show", m_presentationName );
1434
1435 saveOasisPresentationCustomSlideShow( contentTmpWriter, page2name );
1436 contentTmpWriter.endElement();
1437}
1438
1439void KPrDocument::saveOasisPresentationCustomSlideShow( KoXmlWriter &contentTmpWriter, TQMap<int, TQString> &page2name )
1440{
1441 if ( m_customListSlideShow.isEmpty() )
1442 return;
1443
1444 CustomSlideShowMap::Iterator it;
1445 for ( it = m_customListSlideShow.begin(); it != m_customListSlideShow.end(); ++it )
1446 {
1447 contentTmpWriter.startElement( "presentation:show" );
1448 contentTmpWriter.addAttribute( "presentation:name", it.key() );
1449 TQString tmp;
1450 TQValueListIterator<KPrPage*> itPage ;
1451 for( itPage = ( *it ).begin(); itPage != ( *it ).end(); ++itPage )
1452 {
1453 int posPage = m_pageList.find(*itPage );
1454 if ( posPage != -1 )
1455 {
1456 if ( itPage != ( *it ).begin() )
1457 tmp += ",";
1458 //tmp+=( *itPage )->oasisNamePage(posPage+1)+",";
1459 tmp += page2name[posPage + 1];
1460 }
1461 }
1462 contentTmpWriter.addAttribute( "presentation:pages", tmp );
1463 contentTmpWriter.endElement();
1464 }
1465 //<presentation:show presentation:name="New Custom Slide Show" presentation:pages="page1,page1,page1,page1,page1"/>
1466}
1467
1468void KPrDocument::saveOasisDocumentStyles( KoStore* store, KoGenStyles& mainStyles, TQFile* masterStyles,
1469 KoSavingContext & savingContext, SaveFlag saveFlag ) const
1470{
1471 KoStoreDevice stylesDev( store );
1472 KoXmlWriter* stylesWriter = createOasisXmlWriter( &stylesDev, "office:document-styles" );
1473
1474 // Yeah we need to save the same font faces in both content.xml and styles.xml...
1475 savingContext.writeFontFaces( *stylesWriter );
1476
1477 stylesWriter->startElement( "office:styles" );
1478 TQValueList<KoGenStyles::NamedStyle> styles = mainStyles.styles( KoGenStyle::STYLE_USER );
1479 TQValueList<KoGenStyles::NamedStyle>::const_iterator it = styles.begin();
1480 for ( ; it != styles.end() ; ++it ) {
1481 (*it).style->writeStyle( stylesWriter, mainStyles, "style:style", (*it).name, "style:paragraph-properties" );
1482 }
1483 styles = mainStyles.styles( KoGenStyle::STYLE_LIST );
1484 it = styles.begin();
1485 for ( ; it != styles.end() ; ++it ) {
1486 (*it).style->writeStyle( stylesWriter, mainStyles, "text:list-style", (*it).name, 0 );
1487 }
1488 styles = mainStyles.styles( KoGenStyle::STYLE_HATCH );
1489 it = styles.begin();
1490 for ( ; it != styles.end() ; ++it ) {
1491 (*it).style->writeStyle( stylesWriter, mainStyles, "draw:hatch", (*it).name, "style:graphic-properties" , true, true /*add draw:name*/);
1492 }
1493 styles = mainStyles.styles( STYLE_GRADIENT );
1494 it = styles.begin();
1495 for ( ; it != styles.end() ; ++it ) {
1496 (*it).style->writeStyle( stylesWriter, mainStyles, "draw:gradient", (*it).name, "style:graphic-properties" , true, true /*add draw:name*/);
1497 }
1498
1499 styles = mainStyles.styles( STYLE_STROKE );
1500 it = styles.begin();
1501 for ( ; it != styles.end() ; ++it ) {
1502 (*it).style->writeStyle( stylesWriter, mainStyles, "draw:stroke-dash", (*it).name, "style:graphic-properties" , true, true /*add draw:name*/);
1503 }
1504
1505 styles = mainStyles.styles( STYLE_MARKER );
1506 it = styles.begin();
1507 for ( ; it != styles.end() ; ++it ) {
1508 (*it).style->writeStyle( stylesWriter, mainStyles, "draw:marker", (*it).name, "style:graphic-properties" , true, true /*add draw:name*/);
1509 }
1510 styles = mainStyles.styles( STYLE_PICTURE );
1511 it = styles.begin();
1512 for ( ; it != styles.end() ; ++it ) {
1513 (*it).style->writeStyle( stylesWriter, mainStyles, "draw:fill-image", (*it).name, "style:image-properties" , true, true /*add draw:name*/);
1514 }
1515
1516 stylesWriter->endElement(); // office:styles
1517
1518 if ( saveFlag == SaveAll )
1519 {
1520 stylesWriter->startElement( "office:automatic-styles" );
1521 // this has to be the first
1522 if ( masterStyles )
1523 {
1524 writeAutomaticStyles( *stylesWriter, mainStyles, savingContext, true );
1525 }
1526
1527 styles = mainStyles.styles( STYLE_BACKGROUNDPAGE );
1528 it = styles.begin();
1529 for ( ; it != styles.end() ; ++it ) {
1530 (*it).style->writeStyle( stylesWriter, mainStyles, "style:style", (*it).name , "style:drawing-page-properties" );
1531 }
1532
1533 // if there's more than one pagemaster we need to rethink all this
1534 styles = mainStyles.styles( KoGenStyle::STYLE_PAGELAYOUT );
1535 Q_ASSERT( styles.count() == 1 );
1536 it = styles.begin();
1537 for ( ; it != styles.end() ; ++it ) {
1538 (*it).style->writeStyle( stylesWriter, mainStyles, "style:page-layout", (*it).name, "style:page-layout-properties", false /*don't close*/ );
1539 stylesWriter->endElement();
1540 }
1541
1542 styles = mainStyles.styles( STYLE_PRESENTATIONSTICKYOBJECT );
1543 it = styles.begin();
1544 for ( ; it != styles.end() ; ++it ) {
1545 //TODO fix me graphic-properties ???
1546 (*it).style->writeStyle( stylesWriter, mainStyles, "style:style", (*it).name , "style:graphic-properties" );
1547 }
1548
1549 stylesWriter->endElement(); // office:automatic-styles
1550
1551
1552 if ( masterStyles )
1553 {
1554 stylesWriter->startElement( "office:master-styles" );
1555 stylesWriter->addCompleteElement( masterStyles );
1556 stylesWriter->endElement();
1557 }
1558 }
1559
1560 stylesWriter->endElement(); // root element (office:document-styles)
1561 stylesWriter->endDocument();
1562 delete stylesWriter;
1563}
1564
1565bool KPrDocument::loadOasis( const TQDomDocument& doc, KoOasisStyles&oasisStyles, const TQDomDocument&settingsDoc, KoStore*store )
1566{
1567 TQTime dt;
1568 dt.start();
1569 m_loadingInfo = new KPrLoadingInfo;
1570 ignoreSticky = false;
1571 emit sigProgress( 0 );
1572
1573 lastObj = -1;
1574 // clean
1575 if ( _clean ) {
1576 m_styleColl->clear();
1577 // Some simple import filters don't define any style,
1578 // so let's have a Standard style at least
1579 KoParagStyle * standardStyle = new KoParagStyle( "Standard" ); // This gets translated later on
1580 //kdDebug() << "KWDocument::KWDocument creating standardStyle " << standardStyle << endl;
1581 standardStyle->format().setFont( m_defaultFont );
1582 m_styleColl->addStyle( standardStyle );
1583
1584 __pgLayout = KoPageLayout::standardLayout();
1585 _spInfiniteLoop = false;
1586 _spShowEndOfPresentationSlide = true;
1587 _spManualSwitch = true;
1588 _showPresentationDuration = false;
1589 _xRnd = 20;
1590 _yRnd = 20;
1591 urlIntern = url().path();
1592 }
1593 else
1594 m_spellCheckIgnoreList.clear();
1595 emit sigProgress( 5 );
1596
1597 TQDomElement content = doc.documentElement();
1598 TQDomElement realBody (KoDom::namedItemNS( content, KoXmlNS::office, "body" ) );
1599 if ( realBody.isNull() )
1600 {
1601 kdError(33001) << "No office:body found!" << endl;
1602 setErrorMessage( i18n( "Invalid OASIS OpenDocument file. No office:body tag found." ) );
1603 return false;
1604 }
1605 TQDomElement body = KoDom::namedItemNS( realBody, KoXmlNS::office, "presentation" );
1606 if ( body.isNull() )
1607 {
1608 kdError(33001) << "No office:presentation found!" << endl;
1609 TQDomElement childElem;
1610 TQString localName;
1611 forEachElement( childElem, realBody ) {
1612 localName = childElem.localName();
1613 }
1614 if ( localName.isEmpty() )
1615 setErrorMessage( i18n( "Invalid OASIS OpenDocument file. No tag found inside office:body." ) );
1616 else
1617 setErrorMessage( i18n( "This document is not a presentation, but a %1. Please try opening it with the appropriate application." ).arg( KoDocument::tagNameToDocumentType( localName ) ) );
1618 return false;
1619 }
1620
1621 // it seems that ooimpress has different paper-settings for every slide.
1622 // we take the settings of the first slide for the whole document.
1623 TQDomNode drawPage = KoDom::namedItemNS( body, KoXmlNS::draw, "page" );
1624 if ( drawPage.isNull() ) // no slides? give up.
1625 return false;
1626 TQDomElement dp = drawPage.toElement();
1627
1628 //code from kword
1629 // TODO variable settings
1630 // By default display real variable value
1631 if ( !isReadWrite())
1632 getVariableCollection()->variableSetting()->setDisplayFieldCode(false);
1633
1634 KoOasisContext context( this, *m_varColl, oasisStyles, store );
1635 Q_ASSERT( !oasisStyles.officeStyle().isNull() );
1636
1637 // Load all styles before the corresponding paragraphs try to use them!
1638 m_styleColl->loadOasisStyles( context );
1639
1640 // if we only copy a page we have no master
1641 // also don't copy master when you insert file as long as we don't have multiple masters
1642 if ( !m_pageWhereLoadObject && _clean )
1643 {
1644 TQString masterPageName = drawPage.toElement().attributeNS( KoXmlNS::draw, "master-page-name", TQString() );
1645 TQDomElement *master = oasisStyles.masterPages()[ masterPageName];
1646
1647 kdDebug()<<" master :"<<master<<endl;
1648 kdDebug()<<" masterPageName:"<<masterPageName<<endl;
1649 if ( ! master )
1650 {
1651 masterPageName = "Standard"; // use default layout as fallback (default in kpresenter)
1652 master = oasisStyles.masterPages()[ masterPageName];
1653 if ( !master ) //last test...
1654 master = oasisStyles.masterPages()["Default"];
1655 }
1656
1657 if ( master == 0 )
1658 {
1659 setErrorMessage( i18n( "Invalid OASIS OpenDocument file. No master-style found inside office:master-styles." ) );
1660 return false;
1661 }
1662
1663 kdDebug()<<" load oasis master styles\n";
1664 TQDomNode node = *master;
1665 TQDomElement masterElement = node.toElement();
1666 kdDebug()<<" node.isNull() :"<<node.isNull()<< ", " << masterElement.attributeNS( KoXmlNS::draw, "style-name", TQString() ) << endl;
1667 // add the correct styles
1668 const TQDomElement* masterPageStyle = context.oasisStyles().findStyleAutoStyle( masterElement.attributeNS( KoXmlNS::draw, "style-name", TQString() ), "drawing-page" );
1669 if (masterPageStyle)
1670 context.styleStack().push( *masterPageStyle );
1671
1672 context.setUseStylesAutoStyles( true );
1673 m_masterPage->loadOasis( context );
1674
1675 createPresentationAnimation( KoDom::namedItemNS( node, KoXmlNS::presentation, "animations"));
1676
1677 loadOasisObject( m_masterPage, node , context);
1678
1679 m_loadingInfo->clearAnimationShowDict(); // clear all show animations style
1680 m_loadingInfo->clearAnimationHideDict(); // clear all hide animations style
1681
1682 loadOasisHeaderFooter( node,context );
1683 context.setUseStylesAutoStyles( false );
1684
1685 kdDebug()<<" end load oasis master style \n";
1686
1687 Q_ASSERT( master );
1688 const TQDomElement *style = master ? oasisStyles.findStyle(master->attributeNS( KoXmlNS::style, "page-layout-name", TQString() )) : 0;
1689 const TQDomElement *backgroundStyle = oasisStyles.findStyle( "Standard-background", "presentation" );
1690 kdDebug()<<"Standard background "<<backgroundStyle<<endl;
1691 // parse all pages
1692 Q_ASSERT( style );
1693 if ( style )
1694 {
1695 __pgLayout.loadOasis( *style );
1696 kdDebug()<<"Page size __pgLayout.ptWidth :"<<__pgLayout.ptWidth<<" __pgLayout.ptHeight :"<<__pgLayout.ptHeight<<endl;
1697 kdDebug()<<"Page orientation :"<<(( __pgLayout.orientation== PG_LANDSCAPE )? " landscape " : " portrait ")<<endl;
1698
1699 kdDebug()<<" margin right:"<< __pgLayout.ptRight <<" __pgLayout.ptBottom :"<<__pgLayout.ptBottom<<" __pgLayout.ptLeft :"<<__pgLayout.ptLeft<<" __pgLayout.ptTop :"<<__pgLayout.ptTop<<endl;
1700 }
1701 if ( _clean )
1702 {
1704 setPageLayout( __pgLayout );
1705 }
1706 }
1707
1708 int pos = m_insertFilePage;
1709 for ( drawPage = body.firstChild(); !drawPage.isNull(); drawPage = drawPage.nextSibling() )
1710 {
1711 dp = drawPage.toElement();
1712 kdDebug()<<"dp.tagName() :"<<dp.tagName()<<endl;
1713 if ( dp.tagName()== "page" && dp.namespaceURI() == KoXmlNS::draw ) // don't try to parse "</draw:page>" as page
1714 {
1715 context.styleStack().clear(); // remove all styles
1716 fillStyleStack( dp, context, "drawing-page" );
1717 context.styleStack().save();
1718 kdDebug ()<<"insert new page "<<pos<<endl;
1719 KPrPage *newpage = 0L;
1720 if ( m_pageWhereLoadObject )
1721 {
1722 newpage = m_pageWhereLoadObject;
1723 }
1724 else
1725 {
1726 if ( pos != 0 )
1727 {
1728 newpage = new KPrPage( this, m_masterPage );
1729 m_pageList.insert( pos,newpage);
1730 }
1731 else //we create a first page into KPrDocument()
1732 {
1733 newpage = m_pageList.at(pos);
1734 }
1735 }
1736 //only set the manual title if it is different to the draw:id. Only in this case it had one.
1737 TQString str = dp.attributeNS( KoXmlNS::draw, "name", TQString() );
1738 m_loadingInfo->m_name2page.insert( str, newpage );
1739 TQString idPage = dp.attributeNS( KoXmlNS::draw, "id", TQString() );
1740
1741 if ( dp.hasAttributeNS( KoXmlNS::koffice, "name" ) )
1742 {
1743 str = dp.attributeNS( KoXmlNS::koffice, "name", TQString() );
1744 newpage->insertManualTitle(str);
1745 }
1746 else
1747 {
1748 // OO uses /page[0-9]+$/ as default for no name set
1749 TQRegExp rx( "^page[0-9]+$" );
1750 if ( rx.search( str ) == -1 )
1751 newpage->insertManualTitle(str);
1752 }
1753 context.styleStack().setTypeProperties( "drawing-page" );
1754
1755 newpage->loadOasis( context );
1756
1757 //All animation object for current page is store into this element
1758 createPresentationAnimation(KoDom::namedItemNS( drawPage, KoXmlNS::presentation, "animations"));
1759 // parse all objects
1760 loadOasisObject( newpage, drawPage, context );
1761
1762 context.styleStack().restore();
1763 m_loadingInfo->clearAnimationShowDict(); // clear all show animations style
1764 m_loadingInfo->clearAnimationHideDict(); // clear all hide animations style
1765 ++pos;
1766 }
1767 }
1768
1769 //load settings at the end as we need to know what the draw:name of a page is
1770 TQDomNode settings = KoDom::namedItemNS( body, KoXmlNS::presentation, "settings" );
1771 kdDebug()<<"settings :"<<settings.isNull()<<endl;
1772 if (!settings.isNull() && _clean /*don't load settings when we copy/paste a page*/)
1773 loadOasisPresentationSettings( settings );
1774
1775 ignoreSticky = true;
1776 kdDebug()<<" _clean :"<<_clean<<endl;
1777 if(_clean)
1778 {
1779 setModified(false);
1780#if 0 //FIXME
1781 //it crashed, I don't know why for the moment.
1782 startBackgroundSpellCheck();
1783#endif
1784 }
1785 kdDebug(33001) << "Loading took " << (float)(dt.elapsed()) / 1000.0 << " seconds" << endl;
1786
1787 if ( !settingsDoc.isNull() )
1788 {
1789 loadOasisSettings( settingsDoc );
1790 }
1791
1792 // set the initial active page
1793 if ( m_initialActivePage == 0 )
1794 {
1795 m_initialActivePage = m_pageList.at( 0 );
1796 }
1797
1798 emit sigProgress( 100 );
1799 recalcVariables( VT_ALL );
1800 emit sigProgress( -1 );
1801
1802 setModified( false );
1803 return true;
1804}
1805
1806
1807void KPrDocument::loadOasisObject( KPrPage * newpage, TQDomNode & drawPage, KoOasisContext & context, KPrGroupObject *groupObject )
1808{
1809 for ( TQDomNode object = drawPage.firstChild(); !object.isNull(); object = object.nextSibling() )
1810 {
1811 TQDomElement o = object.toElement();
1812 TQString name = o.tagName();
1813 if ( !name.isEmpty() )
1814 {
1815 kdDebug()<<" name :"<<name<<endl;
1816 if ( o.hasAttributeNS( KoXmlNS::presentation, "placeholder" ) &&
1817 o.attributeNS( KoXmlNS::presentation, "placeholder", TQString() ) == "true" )
1818 {
1819 kdDebug(33001) << "Placeholder" << endl;
1820 continue;
1821 }
1822 context.styleStack().save();
1823 const bool isDrawNS = o.namespaceURI() == KoXmlNS::draw;
1824 // draw:frame
1825 if ( name == "frame" && isDrawNS )
1826 {
1827 fillStyleStack( o, context, "graphic" );
1828 TQDomElement elem;
1829 forEachElement( elem, o )
1830 {
1831 if ( elem.namespaceURI() != KoXmlNS::draw )
1832 continue;
1833 const TQString localName = elem.localName();
1834 if ( localName == "text-box" )
1835 {
1836 KPrTextObject *kptextobject = new KPrTextObject( this );
1837 kptextobject->loadOasis(o, context, m_loadingInfo);
1838 if ( groupObject )
1839 groupObject->addObjects( kptextobject );
1840 else
1841 newpage->appendObject(kptextobject);
1842 break;
1843 }
1844 else if ( localName == "image" )
1845 {
1846 KPrPixmapObject *kppixmapobject = new KPrPixmapObject( pictureCollection() );
1847 kppixmapobject->loadOasis( o, context, m_loadingInfo);
1848 if ( groupObject )
1849 groupObject->addObjects( kppixmapobject );
1850 else
1851 newpage->appendObject(kppixmapobject);
1852 break;
1853 }
1854 else if ( localName == "object" )
1855 {
1856 KPrChild *ch = new KPrChild( this );
1857 TQRect r;
1858 KPrPartObject *kppartobject = new KPrPartObject( ch );
1859 kppartobject->loadOasis( o, context, m_loadingInfo );
1860 r = ch->geometry();
1861 if ( groupObject )
1862 groupObject->addObjects( kppartobject );
1863 else
1864 newpage->appendObject(kppartobject);
1865 insertChild( ch );
1866 kppartobject->setOrig( r.x(), r.y() );
1867 kppartobject->setSize( r.width(), r.height() );
1868 break;
1869 }
1870 }
1871 }
1872 else if ( name == "rect" && isDrawNS) // rectangle
1873 {
1874 fillStyleStack( o, context, "graphic" );
1875 KPrRectObject *kprectobject = new KPrRectObject();
1876 kprectobject->loadOasis(o, context , m_loadingInfo);
1877 if ( groupObject )
1878 groupObject->addObjects( kprectobject );
1879 else
1880 newpage->appendObject(kprectobject);
1881 }
1882 else if ( ( name == "circle" || name == "ellipse" )&& isDrawNS)
1883 {
1884 fillStyleStack( o, context, "graphic" );
1885 if ( o.hasAttributeNS( KoXmlNS::draw, "kind" ) ) // pie, chord or arc
1886 {
1887 KPrPieObject *kppieobject = new KPrPieObject();
1888 kppieobject->loadOasis(o, context, m_loadingInfo);
1889 if ( groupObject )
1890 groupObject->addObjects( kppieobject );
1891 else
1892 newpage->appendObject(kppieobject);
1893 }
1894 else // circle or ellipse
1895 {
1896 KPrEllipseObject *kpellipseobject = new KPrEllipseObject();
1897 kpellipseobject->loadOasis(o,context, m_loadingInfo);
1898 if ( groupObject )
1899 groupObject->addObjects( kpellipseobject );
1900 else
1901 newpage->appendObject(kpellipseobject);
1902 }
1903 }
1904 else if ( name == "line" && isDrawNS) // line
1905 {
1906 fillStyleStack( o, context, "graphic" );
1907 KPrLineObject *kplineobject = new KPrLineObject();
1908 kplineobject->loadOasis(o, context, m_loadingInfo);
1909 if ( groupObject )
1910 groupObject->addObjects( kplineobject );
1911 else
1912 newpage->appendObject( kplineobject );
1913 }
1914 else if (name=="polyline" && isDrawNS) { // polyline
1915 fillStyleStack( o, context, "graphic" );
1916 KPrPolylineObject *kppolylineobject = new KPrPolylineObject();
1917 kppolylineobject->loadOasis(o, context, m_loadingInfo);
1918 if ( groupObject )
1919 groupObject->addObjects( kppolylineobject );
1920 else
1921 newpage->appendObject(kppolylineobject);
1922 }
1923 else if (name=="polygon" && isDrawNS) { // plcloseobject
1924 fillStyleStack( o, context, "graphic" );
1925 KPrClosedLineObject *kpClosedObject = new KPrClosedLineObject();
1926 kpClosedObject->loadOasis( o, context, m_loadingInfo);
1927 if ( groupObject )
1928 groupObject->addObjects( kpClosedObject );
1929 else
1930 newpage->appendObject(kpClosedObject);
1931 }
1932 else if (name=="regular-polygon"&& isDrawNS) { // kppolygone object
1933 fillStyleStack( o, context, "graphic" );
1934 KPrPolygonObject *kpPolygoneObject = new KPrPolygonObject();
1935 kpPolygoneObject->loadOasis( o, context, m_loadingInfo);
1936 if ( groupObject )
1937 groupObject->addObjects( kpPolygoneObject );
1938 else
1939 newpage->appendObject(kpPolygoneObject);
1940 }
1941 else if ( name == "path" && isDrawNS)
1942 {
1943 fillStyleStack( o, context, "graphic" );
1944 TQString d = o.attributeNS( KoXmlNS::svg, "d", TQString());
1945
1946 KPrSVGPathParser parser;
1947 ObjType objType = parser.getType( d );
1948
1949 switch ( objType )
1950 {
1951 case OT_CUBICBEZIERCURVE:
1952 {
1953 kdDebug(33001) << "Cubicbeziercurve" << endl;
1954 KPrCubicBezierCurveObject *kpCurveObject = new KPrCubicBezierCurveObject();
1955 kpCurveObject->loadOasis( o, context, m_loadingInfo );
1956 if ( groupObject )
1957 groupObject->addObjects( kpCurveObject );
1958 else
1959 newpage->appendObject( kpCurveObject );
1960 } break;
1961 case OT_QUADRICBEZIERCURVE:
1962 {
1963 kdDebug(33001) << "Quadricbeziercurve" << endl;
1964 KPrQuadricBezierCurveObject *kpQuadricObject = new KPrQuadricBezierCurveObject();
1965 kpQuadricObject->loadOasis( o, context, m_loadingInfo );
1966 if ( groupObject )
1967 groupObject->addObjects( kpQuadricObject );
1968 else
1969 newpage->appendObject( kpQuadricObject );
1970 } break;
1971 case OT_FREEHAND:
1972 {
1973 kdDebug(33001) << "Freehand" << endl;
1974 KPrFreehandObject *kpFreeHandObject = new KPrFreehandObject();
1975 kpFreeHandObject->loadOasis( o, context, m_loadingInfo );
1976 if ( groupObject )
1977 groupObject->addObjects( kpFreeHandObject );
1978 else
1979 newpage->appendObject( kpFreeHandObject );
1980 } break;
1981 case OT_CLOSED_LINE:
1982 {
1983 kdDebug(33001) << "Closed Line" << endl;
1984 KPrClosedLineObject *kpClosedObject = new KPrClosedLineObject();
1985 kpClosedObject->loadOasis( o, context, m_loadingInfo );
1986 if ( groupObject )
1987 groupObject->addObjects( kpClosedObject );
1988 else
1989 newpage->appendObject( kpClosedObject );
1990 } break;
1991 default:
1992 kdDebug(33001) << "draw:path found unsupported object type " << objType << " in svg:d " << d << endl;
1993 break;
1994 }
1995 }
1996 else if ( name == "custom-shape" && isDrawNS )
1997 {
1998 fillStyleStack( o, context, "graphic" );
1999
2000 TQDomElement enhancedGeometry = KoDom::namedItemNS( o, KoXmlNS::draw, "enhanced-geometry" );
2001
2002 if ( !enhancedGeometry.isNull() )
2003 {
2004 TQString d = enhancedGeometry.attributeNS( KoXmlNS::draw, "enhanced-path", TQString() );
2005 TQRegExp rx( "^([0-9 ML]+Z) N$" );
2006 if ( rx.search( d ) != -1 )
2007 {
2008 d = rx.cap( 1 );
2009 KPrSVGPathParser parser;
2010 ObjType objType = parser.getType( d );
2011
2012 switch ( objType )
2013 {
2014#if 0 // not yet supported
2015 case OT_CUBICBEZIERCURVE:
2016 {
2017 kdDebug(33001) << "Cubicbeziercurve" << endl;
2018 KPrCubicBezierCurveObject *kpCurveObject = new KPrCubicBezierCurveObject();
2019 kpCurveObject->loadOasis( o, context, m_loadingInfo );
2020 if ( groupObject )
2021 groupObject->addObjects( kpCurveObject );
2022 else
2023 newpage->appendObject( kpCurveObject );
2024 } break;
2025 case OT_QUADRICBEZIERCURVE:
2026 {
2027 kdDebug(33001) << "Quadricbeziercurve" << endl;
2028 KPrQuadricBezierCurveObject *kpQuadricObject = new KPrQuadricBezierCurveObject();
2029 kpQuadricObject->loadOasis( o, context, m_loadingInfo );
2030 if ( groupObject )
2031 groupObject->addObjects( kpQuadricObject );
2032 else
2033 newpage->appendObject( kpQuadricObject );
2034 } break;
2035 case OT_FREEHAND:
2036 {
2037 kdDebug(33001) << "Freehand" << endl;
2038 KPrFreehandObject *kpFreeHandObject = new KPrFreehandObject();
2039 kpFreeHandObject->loadOasis( o, context, m_loadingInfo );
2040 if ( groupObject )
2041 groupObject->addObjects( kpFreeHandObject );
2042 else
2043 newpage->appendObject( kpFreeHandObject );
2044 } break;
2045#endif
2046 case OT_CLOSED_LINE:
2047 {
2048 kdDebug(33001) << "Closed Line" << endl;
2049 KPrClosedLineObject *kpClosedObject = new KPrClosedLineObject();
2050 kpClosedObject->loadOasis( o, context, m_loadingInfo );
2051 if ( groupObject )
2052 groupObject->addObjects( kpClosedObject );
2053 else
2054 newpage->appendObject( kpClosedObject );
2055 } break;
2056 default:
2057 kdDebug(33001) << "draw:custom-shape found unsupported object type " << objType << " in draw:enhanced-path " << d << endl;
2058 break;
2059 }
2060 }
2061 else
2062 {
2063 kdDebug(33001) << "draw:custom-shape not supported" << endl;
2064 }
2065 }
2066 }
2067 else if ( name == "g" && isDrawNS)
2068 {
2069 fillStyleStack( o, context, "graphic" );
2070 KPrGroupObject *kpgroupobject = new KPrGroupObject();
2071 TQDomNode nodegroup = object.firstChild();
2072
2073 kpgroupobject->loadOasisGroupObject( this, newpage, object, context, m_loadingInfo);
2074 if ( groupObject )
2075 groupObject->addObjects( kpgroupobject );
2076 else
2077 newpage->appendObject(kpgroupobject);
2078 }
2079 else if ( name == "notes" && o.namespaceURI() == KoXmlNS::presentation ) // notes
2080 {
2081 //we must extend note attribute
2082 //kdDebug()<<"presentation:notes----------------------------------\n";
2083 TQDomNode frameBox = KoDom::namedItemNS( o, KoXmlNS::draw, "frame" );
2084 TQString note;
2085
2086 while ( !frameBox.isNull() )
2087 {
2088 //add an empty line between the different frames
2089 if ( !note.isEmpty() )
2090 note += "\n";
2091
2092 //todo load layout for note.
2093 TQDomNode textBox = KoDom::namedItemNS( frameBox, KoXmlNS::draw, "text-box" );
2094
2095 if ( !textBox.isNull() )
2096 {
2097 for ( TQDomNode text = textBox.firstChild(); !text.isNull(); text = text.nextSibling() )
2098 {
2099 // We don't care about styles as they are not supported in kpresenter.
2100 // Only add a linebreak for every child.
2101 TQDomElement t = text.toElement();
2102 if ( t.tagName() == "p" )
2103 {
2104 note += t.text() + "\n";
2105 }
2106 }
2107 }
2108 frameBox = frameBox.nextSibling();
2109 }
2110 newpage->setNoteText( note );
2111 }
2112 else if ( ( name == "header" || name == "footer" ) && o.namespaceURI() == KoXmlNS::style ||
2113 ( name == "animations" && o.namespaceURI() == KoXmlNS::presentation) )
2114 {
2115 //nothing
2116 }
2117 else
2118 {
2119 kdDebug() << "Unsupported object '" << name << "'" << endl;
2120 }
2121 context.styleStack().restore();
2122 }
2123 }
2124
2125}
2126
2127int KPrDocument::createPresentationAnimation(const TQDomElement& element, int order, bool increaseOrder)
2128{
2129 kdDebug()<<"void KPrDocument::createPresentationAnimation(const TQDomElement& element)\n";
2130 int orderAnimation = increaseOrder ? 0 : order;
2131 for ( TQDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() )
2132 {
2133 TQDomElement e = n.toElement();
2134 TQCString tagName = e.tagName().latin1();
2135 if ( ! tagName.isEmpty() ) // only tags that open
2136 {
2137 const bool isPresentationNS = e.namespaceURI() == KoXmlNS::presentation;
2138 if ( isPresentationNS &&
2139 ( tagName == "show-shape" || tagName == "hide-shape" ) )
2140 {
2141 Q_ASSERT( e.hasAttributeNS( KoXmlNS::draw, "shape-id" ) );
2142 TQString name = e.attributeNS( KoXmlNS::draw, "shape-id", TQString() );
2143 kdDebug()<<" insert animation " << tagName << " name :" << name << endl;
2144
2145 if ( e.hasAttributeNS( KoXmlNS::koffice, "order-id" ) )
2146 {
2147 orderAnimation = e.attributeNS( KoXmlNS::koffice, "order-id", TQString() ).toInt();
2148 }
2149
2150 lstAnimation *tmp = new lstAnimation;
2151 tmp->element = new TQDomElement( e );
2152 tmp->order = orderAnimation;
2153 if ( tagName == "show-shape" )
2154 {
2155 m_loadingInfo->storePresentationShowAnimation( tmp, name );
2156 }
2157 else
2158 {
2159 m_loadingInfo->storePresentationHideAnimation( tmp, name );
2160 }
2161 if ( increaseOrder )
2162 ++orderAnimation;
2163 }
2164 else if ( tagName == "animation-group" && isPresentationNS )
2165 {
2166 orderAnimation = createPresentationAnimation( e, orderAnimation, false );
2167 }
2168 }
2169 }
2170 //increase when we finish it necessary for group object
2171 ++orderAnimation;
2172 return orderAnimation;
2173}
2174
2175void KPrDocument::fillStyleStack( const TQDomElement& object, KoOasisContext & context, const char* family )
2176{
2177 // See OpenDoc 9.2.15 Common Drawing Shape Attributes
2178 // presentation:style-name is allways family presentation
2179 if ( object.hasAttributeNS( KoXmlNS::presentation, "style-name" ))
2180 {
2181 context.fillStyleStack( object, KoXmlNS::presentation, "style-name", "presentation" );
2182 }
2183 if ( object.hasAttributeNS( KoXmlNS::draw, "style-name" ) )
2184 {
2185 context.fillStyleStack( object, KoXmlNS::draw, "style-name", family );
2186 }
2187 // draw:tex-style-name is allways family paragraph
2188 if ( object.hasAttributeNS( KoXmlNS::draw, "text-style-name" ) )
2189 {
2190 context.fillStyleStack( object, KoXmlNS::draw, "text-style-name", "paragraph" );
2191 }
2192 if ( object.hasAttributeNS( KoXmlNS::text, "style-name" ) )
2193 {
2194 context.fillStyleStack( object, KoXmlNS::text, "style-name", family );
2195 }
2196}
2197
2198bool KPrDocument::loadXML( TQIODevice * dev, const TQDomDocument& doc )
2199{
2200 TQTime dt;
2201 dt.start();
2202 m_loadingInfo = new KPrLoadingInfo( true );
2203
2204 ignoreSticky = false;
2205 bool b=false;
2206 TQDomElement docelem = doc.documentElement();
2207 const int syntaxVersion = docelem.attribute( "syntaxVersion" ).toInt();
2208 if ( syntaxVersion < 2 )
2209 {
2210 // This is an old style document, before the current TextObject
2211 // We have kprconverter.pl for it
2212 kdWarning(33001) << "KPresenter document version 1. Launching perl script to convert it." << endl;
2213
2214 // Read the full XML and write it to a temp file
2215 KTempFile tmpFileIn;
2216 tmpFileIn.setAutoDelete( true );
2217 dev->reset();
2218 tmpFileIn.file()->writeBlock( dev->readAll() ); // copy stresm to temp file
2219 tmpFileIn.close();
2220
2221 // Launch the perl script on it
2222 KTempFile tmpFileOut;
2223 tmpFileOut.setAutoDelete( true );
2224 TQString cmd = TDEGlobal::dirs()->findExe("perl");
2225 if (cmd.isEmpty())
2226 {
2227 setErrorMessage( i18n("You don't appear to have PERL installed.\nIt is needed to convert this document.\nPlease install PERL and try again."));
2228 return false;
2229 }
2230 cmd += " ";
2231 cmd += locate( "exe", "kprconverter.pl" );
2232 cmd += " ";
2233 cmd += TDEProcess::quote( tmpFileIn.name() );
2234 cmd += " ";
2235 cmd += TDEProcess::quote( tmpFileOut.name() );
2236 system( TQFile::encodeName(cmd) );
2237
2238 // Build a new TQDomDocument from the result
2239 TQString errorMsg;
2240 int errorLine;
2241 int errorColumn;
2242 TQDomDocument newdoc;
2243 if ( ! newdoc.setContent( tmpFileOut.file(), &errorMsg, &errorLine, &errorColumn ) )
2244 {
2245 kdError (33001) << "Parsing Error! Aborting! (in KPrDocument::loadXML)" << endl
2246 << " Line: " << errorLine << " Column: " << errorColumn << endl
2247 << " Message: " << errorMsg << endl;
2248 setErrorMessage( i18n( "parsing error in the main document (converted from an old KPresenter format) at line %1, column %2\nError message: %3" )
2249 .arg( errorLine ).arg( errorColumn ).arg( i18n ( errorMsg.utf8() ) ) );
2250 return false;
2251 }
2252 b = loadXML( newdoc );
2253 }
2254 else
2255 b = loadXML( doc );
2256
2257 ignoreSticky = true;
2258
2259 if(_clean)
2260 {
2261 startBackgroundSpellCheck();
2262 }
2263 if ( m_pageWhereLoadObject == 0 && m_insertFilePage == 0 )
2264 setModified( false );
2265 kdDebug(33001) << "Loading took " << (float)(dt.elapsed()) / 1000.0 << " seconds" << endl;
2266 return b;
2267}
2268
2269void KPrDocument::createHeaderFooter()
2270{
2271 //add header/footer to sticky page
2272 KoRect pageRect=m_masterPage->getPageRect();
2273 _header->setOrig(pageRect.topLeft());
2274 _header->setSize(pageRect.width(),20);
2275
2276 _footer->setOrig(pageRect.left(),pageRect.bottom()-20);
2277 _footer->setSize(pageRect.width(),20);
2278
2279 m_masterPage->appendObject(_header);
2280 m_masterPage->appendObject(_footer);
2281}
2282
2283void KPrDocument::insertEmbedded( KoStore *store, TQDomElement topElem, KMacroCommand * macroCmd, KPrPage *page, int pos )
2284{
2285 TQDomElement elem = topElem.firstChild().toElement();
2286 for ( ; !elem.isNull() ; elem = elem.nextSibling().toElement() )
2287 {
2288 kdDebug(33001) << "Element name: " << elem.tagName() << endl;
2289 if(elem.tagName()=="EMBEDDED") {
2290 KPrChild *ch = new KPrChild( this );
2291 KPrPartObject *kppartobject = 0L;
2292 TQRect r;
2293
2294 TQDomElement object=elem.namedItem("OBJECT").toElement();
2295 if(!object.isNull()) {
2296 ch->load(object, true); // true == uppercase
2297 r = ch->geometry();
2298 ch->loadDocument( store );
2299 insertChild( ch );
2300 kppartobject = new KPrPartObject( ch );
2301 }
2302 TQDomElement settings=elem.namedItem("SETTINGS").toElement();
2303 int zIndex = 0;
2304 if ( settings.hasAttribute( "z-index" ) )
2305 {
2306 zIndex = settings.attribute( "z-index" ).toInt();
2307 }
2308 double offset = 0.0;
2309 if(!settings.isNull() && kppartobject!=0)
2310 offset=kppartobject->load(settings);
2311 else if ( settings.isNull() ) // all embedded obj must have SETTING tags
2312 {
2313 delete kppartobject;
2314 kppartobject = 0L;
2315 return;
2316 }
2317 int index = m_pageList.findRef(page);
2318 int pageIndex = (int)(offset/__pgLayout.ptHeight)+index;
2319 int newPos=(int)((offset+index*__pgLayout.ptHeight)-pageIndex*__pgLayout.ptHeight);
2320 kppartobject->setOrig(kppartobject->getOrig().x(),newPos);
2321
2322 KPrInsertCmd *insertCmd = new KPrInsertCmd( i18n( "Insert Part Object" ), kppartobject, this,page );
2323 insertCmd->execute();
2324 if ( !macroCmd )
2325 macroCmd = new KMacroCommand( i18n("Insert Part Object"));
2326 macroCmd->addCommand( insertCmd );
2327 if ( pos != 0 )
2328 {
2329 const TQPtrList<KPrObject>& oldList( page->objectList() );
2330 // tz TODO this is not 100% correct
2331 if ( static_cast<int>( oldList.count() ) > pos + zIndex )
2332 {
2333 page->takeObject( kppartobject );
2334 page->insertObject( kppartobject, pos + zIndex );
2335 KPrLowerRaiseCmd *lrCmd = new KPrLowerRaiseCmd( i18n("Insert Part Object"),
2336 oldList, page->objectList(),
2337 this, page );
2338 macroCmd->addCommand( lrCmd );
2339 }
2340 }
2341 }
2342 }
2343}
2344
2345bool KPrDocument::loadXML( const TQDomDocument &doc )
2346{
2347 emit sigProgress( 0 );
2348 int activePage=0;
2349 lastObj = -1;
2350 bool allSlides = false;
2351 // clean
2352 if ( _clean ) {
2353 __pgLayout = KoPageLayout::standardLayout();
2354 _spInfiniteLoop = false;
2355 _spShowEndOfPresentationSlide = true;
2356 _spManualSwitch = true;
2357 _showPresentationDuration = false;
2358 _xRnd = 20;
2359 _yRnd = 20;
2360 //_txtBackCol = white;
2361 urlIntern = url().path();
2362 }
2363 else
2364 m_spellCheckIgnoreList.clear();
2365 emit sigProgress( 5 );
2366
2367 TQDomElement document=doc.documentElement();
2368 // DOC
2369 if(document.tagName()!="DOC") {
2370 kdWarning(33001) << "Missing DOC" << endl;
2371 setErrorMessage( i18n("Invalid document, DOC tag missing.") );
2372 return false;
2373 }
2374
2375 if(!document.hasAttribute("mime") || (
2376 document.attribute("mime")!="application/x-kpresenter" &&
2377 document.attribute("mime")!="application/vnd.kde.kpresenter" ) ) {
2378 kdError(33001) << "Unknown mime type " << document.attribute("mime") << endl;
2379 setErrorMessage( i18n("Invalid document, expected mimetype application/x-kpresenter or application/vnd.kde.kpresenter, got %1").arg(document.attribute("mime")) );
2380 return false;
2381 }
2382 if(document.hasAttribute("url"))
2383 urlIntern=KURL(document.attribute("url")).path();
2384
2385 emit sigProgress( 10 );
2386
2387 TQDomElement elem=document.firstChild().toElement();
2388
2389 uint childTotalCount=document.childNodes().count();
2390 uint childCount = 0;
2391
2392 loadTextStyle( document );
2393
2394 while(!elem.isNull()) {
2395 kdDebug(33001) << "Element name: " << elem.tagName() << endl;
2396 if(elem.tagName()=="EMBEDDED") {
2397 KPrChild *ch = new KPrChild( this );
2398 KPrPartObject *kppartobject = 0L;
2399 TQRect r;
2400
2401 TQDomElement object=elem.namedItem("OBJECT").toElement();
2402 if(!object.isNull()) {
2403 ch->load(object, true); // true == uppercase
2404 r = ch->geometry();
2405 insertChild( ch );
2406 kppartobject = new KPrPartObject( ch );
2407 //emit sig_insertObject( ch, kppartobject );
2408 }
2409 TQDomElement settings=elem.namedItem("SETTINGS").toElement();
2410 int tmp=0;
2411 int pos = -1;
2412 if ( settings.hasAttribute( "z-index" ) )
2413 {
2414 pos = settings.attribute( "z-index" ).toInt();
2415 }
2416 if(settings.hasAttribute("sticky"))
2417 tmp=settings.attribute("sticky").toInt();
2418 bool sticky=static_cast<bool>(tmp);
2419 double offset = 0.0;
2420 if(!settings.isNull() && kppartobject!=0)
2421 {
2422 offset=kppartobject->load(settings);
2423 }
2424 else if ( settings.isNull() ) // all embedded obj must have SETTING tags
2425 {
2426 delete kppartobject;
2427 kppartobject = 0L;
2428 }
2429 //hack for some old file, they don't have ORIG tag !
2430 if ( offset == -1.0 )
2431 offset = r.y();
2432 if ( sticky && !ignoreSticky && kppartobject )
2433 {
2434 if ( pos == -1 )
2435 {
2436 m_masterPage->appendObject( kppartobject );
2437 }
2438 else
2439 {
2440 m_masterPage->insertObject( kppartobject, pos );
2441 }
2442 kppartobject->setOrig(kppartobject->getOrig().x(), offset);
2443 }
2444 else if ( kppartobject ) {
2445 if ( m_pageWhereLoadObject )
2446 {
2447 kppartobject->setOrig(kppartobject->getOrig().x(), offset);
2448 m_pageWhereLoadObject->insertObject( kppartobject, pos );
2449 }
2450 else
2451 {
2452 insertObjectInPage( offset, kppartobject, pos );
2453 }
2454 }
2455 } else if(elem.tagName()=="PAPER" && _clean) {
2456 if(elem.hasAttribute("format"))
2457 __pgLayout.format=static_cast<KoFormat>(elem.attribute("format").toInt());
2458 if(elem.hasAttribute("orientation"))
2459 __pgLayout.orientation=static_cast<KoOrientation>(elem.attribute("orientation").toInt());
2460 if(elem.hasAttribute("ptWidth"))
2461 __pgLayout.ptWidth = elem.attribute("ptWidth").toDouble();
2462 else if(elem.hasAttribute("inchWidth")) //compatibility
2463 __pgLayout.ptWidth = INCH_TO_POINT( elem.attribute("inchWidth").toDouble() );
2464 else if(elem.hasAttribute("mmWidth")) //compatibility
2465 __pgLayout.ptWidth = MM_TO_POINT( elem.attribute("mmWidth").toDouble() );
2466 if(elem.hasAttribute("ptHeight"))
2467 __pgLayout.ptHeight = elem.attribute("ptHeight").toDouble();
2468 else if(elem.hasAttribute("inchHeight")) //compatibility
2469 __pgLayout.ptHeight = INCH_TO_POINT( elem.attribute("inchHeight").toDouble() );
2470 else if(elem.hasAttribute("mmHeight")) //compatibility
2471 __pgLayout.ptHeight = MM_TO_POINT( elem.attribute("mmHeight").toDouble() );
2472 if(elem.hasAttribute("unit"))
2473 setUnit( static_cast<KoUnit::Unit>(elem.attribute("unit").toInt()) );
2474 if ( elem.hasAttribute("tabStopValue"))
2475 m_tabStop = elem.attribute("tabStopValue").toDouble();
2476
2477 if(elem.hasAttribute("width"))
2478 __pgLayout.ptWidth = MM_TO_POINT( elem.attribute("width").toDouble() );
2479 if(elem.hasAttribute("height"))
2480 __pgLayout.ptHeight = MM_TO_POINT( elem.attribute("height").toDouble() );
2481
2482 TQDomElement borders=elem.namedItem("PAPERBORDERS").toElement();
2483 if(!borders.isNull()) {
2484 if(borders.hasAttribute("left"))
2485 __pgLayout.ptLeft = MM_TO_POINT( borders.attribute("left").toDouble() );
2486 if(borders.hasAttribute("top"))
2487 __pgLayout.ptTop = MM_TO_POINT( borders.attribute("top").toDouble() );
2488 if(borders.hasAttribute("right"))
2489 __pgLayout.ptRight = MM_TO_POINT( borders.attribute("right").toDouble() );
2490 if(borders.hasAttribute("bottom"))
2491 __pgLayout.ptBottom = MM_TO_POINT( borders.attribute("bottom").toDouble() );
2492 if(borders.hasAttribute("ptLeft"))
2493 __pgLayout.ptLeft = borders.attribute("ptLeft").toDouble();
2494 else if(borders.hasAttribute("inchLeft")) //compatibility
2495 __pgLayout.ptLeft = INCH_TO_POINT( borders.attribute("inchLeft").toDouble() );
2496 else if(borders.hasAttribute("mmLeft")) //compatibility
2497 __pgLayout.ptLeft = MM_TO_POINT( borders.attribute("mmLeft").toDouble() );
2498 if(borders.hasAttribute("ptRight"))
2499 __pgLayout.ptRight = borders.attribute("ptRight").toDouble();
2500 else if(borders.hasAttribute("inchRight")) //compatibility
2501 __pgLayout.ptRight = INCH_TO_POINT( borders.attribute("inchRight").toDouble() );
2502 else if(borders.hasAttribute("mmRight")) //compatibility
2503 __pgLayout.ptRight = MM_TO_POINT( borders.attribute("mmRight").toDouble() );
2504 if(borders.hasAttribute("ptTop"))
2505 __pgLayout.ptTop = borders.attribute("ptTop").toDouble();
2506 else if(borders.hasAttribute("inchTop")) //compatibility
2507 __pgLayout.ptTop = INCH_TO_POINT( borders.attribute("inchTop").toDouble() );
2508 else if(borders.hasAttribute("mmTop")) //compatibility
2509 __pgLayout.ptTop = MM_TO_POINT( borders.attribute("mmTop").toDouble() );
2510 if(borders.hasAttribute("ptBottom"))
2511 __pgLayout.ptBottom = borders.attribute("ptBottom").toDouble();
2512 else if(borders.hasAttribute("inchBottom")) //compatibility
2513 __pgLayout.ptBottom = INCH_TO_POINT( borders.attribute("inchBottom").toDouble() );
2514 else if(borders.hasAttribute("mmBottom")) //compatibility
2515 __pgLayout.ptBottom = MM_TO_POINT( borders.attribute("inchBottom").toDouble() );
2516 }
2517 // PAPER found and parsed -> apply page layout
2518 // e.g. the text objects need it
2519 if ( _clean )
2520 setPageLayout( __pgLayout );
2521
2522 } else if(elem.tagName()=="VARIABLESETTINGS" && _clean){
2523 getVariableCollection()->variableSetting()->load(document);
2524 //by default display real variable value
2525 if ( !isReadWrite())
2526 getVariableCollection()->variableSetting()->setDisplayFieldCode(false);
2527
2528 }
2529 else if(elem.tagName()=="BACKGROUND") {
2530 int red=0, green=0, blue=0;
2531 if(elem.hasAttribute("xRnd"))
2532 _xRnd = elem.attribute("xRnd").toInt();
2533 if(elem.hasAttribute("yRnd"))
2534 _yRnd = elem.attribute("yRnd").toInt();
2535 if(elem.hasAttribute("bred"))
2536 red = elem.attribute("bred").toInt();
2537 if(elem.hasAttribute("bgreen"))
2538 green = elem.attribute("bgreen").toInt();
2539 if(elem.hasAttribute("bblue"))
2540 blue = elem.attribute("bblue").toInt();
2541 loadBackground(elem);
2542 } else if(elem.tagName()=="HEADER") {
2543 if ( _clean /*don't reload header footer, header/footer was created at the beginning || !hasHeader()*/ ) {
2544 if(elem.hasAttribute("show")) {
2545 setHeader(static_cast<bool>(elem.attribute("show").toInt()));
2546 }
2547 _header->load(elem);
2548 }
2549 } else if ( elem.tagName()=="HEADERFOOTERBYPAGE" ) {
2550 if ( elem.hasAttribute( "value" ) ) {
2551 m_loadingInfo->m_headerFooterByPage = true;
2552 }
2553 } else if(elem.tagName()=="FOOTER") {
2554 if ( _clean /*|| !hasFooter()*/ ) {
2555 if(elem.hasAttribute("show")) {
2556 setFooter( static_cast<bool>(elem.attribute("show").toInt() ) );
2557 }
2558 _footer->load(elem);
2559 }
2560 }else if( elem.tagName()=="HELPLINES"){
2561 if ( _clean ) {
2562 if(elem.hasAttribute("show")) {
2563 setShowGuideLines( static_cast<bool>(elem.attribute("show").toInt() ) );
2564 }
2565 loadGuideLines( elem );
2566 }
2567 }else if( elem.tagName()=="SPELLCHECKIGNORELIST"){
2568 TQDomElement spellWord=elem.toElement();
2569 spellWord=spellWord.firstChild().toElement();
2570 while ( !spellWord.isNull() )
2571 {
2572 if ( spellWord.tagName()=="SPELLCHECKIGNOREWORD" )
2573 {
2574 m_spellCheckIgnoreList.append(spellWord.attribute("word"));
2575 }
2576 spellWord=spellWord.nextSibling().toElement();
2577 }
2578 }else if(elem.tagName()=="ATTRIBUTES" && _clean) {
2579 if(elem.hasAttribute("activePage"))
2580 activePage=elem.attribute("activePage").toInt();
2581 if(elem.hasAttribute("gridx"))
2582 m_gridX = elem.attribute("gridx").toDouble();
2583 if(elem.hasAttribute("gridy"))
2584 m_gridY = elem.attribute("gridy").toDouble();
2585 if(elem.hasAttribute("snaptogrid"))
2586 m_bSnapToGrid = (bool)elem.attribute("snaptogrid").toInt();
2587 } else if(elem.tagName()=="PAGETITLES") {
2588 loadTitle(elem);
2589 } else if(elem.tagName()=="PAGENOTES") {
2590 loadNote(elem);
2591 } else if(elem.tagName()=="OBJECTS") {
2592 //FIXME**********************
2593#if 0
2594 lastObj = _objectList->count() - 1;
2595#endif
2596 //don't add command we don't paste object
2597 KCommand * cmd =loadObjects(elem);
2598 if ( cmd )
2599 delete cmd;
2600 } else if(elem.tagName()=="INFINITLOOP") {
2601 if(_clean) {
2602 if(elem.hasAttribute("value"))
2603 _spInfiniteLoop = static_cast<bool>(elem.attribute("value").toInt());
2604 }
2605 } else if(elem.tagName()=="SHOWENDOFPRESENTATIONSLIDE") {
2606 if(_clean) {
2607 if(elem.hasAttribute("value"))
2608 _spShowEndOfPresentationSlide = static_cast<bool>(elem.attribute("value").toInt());
2609 }
2610 } else if(elem.tagName()=="PRESSPEED") {
2611 if(_clean) {
2612 if(elem.hasAttribute("value"))
2613 m_loadingInfo->presSpeed = elem.attribute("value").toInt();
2614 }
2615 } else if(elem.tagName()=="MANUALSWITCH") {
2616 if(_clean) {
2617 if(elem.hasAttribute("value"))
2618 _spManualSwitch = static_cast<bool>(elem.attribute("value").toInt());
2619 }
2620 } else if(elem.tagName()=="SHOWPRESENTATIONDURATION") {
2621 if(_clean) {
2622 if(elem.hasAttribute("value"))
2623 _showPresentationDuration = static_cast<bool>(elem.attribute("value").toInt());
2624 }
2625 } else if(elem.tagName()=="PRESSLIDES") {
2626 if(elem.hasAttribute("value") && elem.attribute("value").toInt()==0)
2627 allSlides = true;
2628 } else if ( elem.tagName()=="DEFAULTCUSTOMSLIDESHOWNAME" ) {
2629 if(elem.hasAttribute("name") )
2630 m_presentationName=elem.attribute( "name" );
2631 } else if ( elem.tagName()=="CUSTOMSLIDESHOWCONFIG" ) {
2632 if ( _clean ) {
2633 TQMap<TQString, KPrPage *> name2page;
2634 int pos = 1;
2635 for ( TQPtrListIterator<KPrPage> it( m_pageList ); it.current(); ++it )
2636 {
2637 name2page.insert( "page" + TQString::number( pos++ ), it.current() ) ;
2638 }
2639
2640 TQDomElement slide=elem.firstChild().toElement();
2641 while(!slide.isNull()) {
2642 if(slide.tagName()=="CUSTOMSLIDESHOW") {
2643 TQStringList tmp = TQStringList::split( ",", slide.attribute( "pages" ) );
2644 TQValueList<KPrPage *> pageList;
2645 for ( TQStringList::Iterator it = tmp.begin(); it != tmp.end(); ++it )
2646 {
2647 if ( name2page.contains( *it ) )
2648 {
2649 kdDebug(33001) << "slide show " << slide.attribute( "name" ) << " page = " << *it << endl;
2650 pageList.push_back( name2page[*it] );
2651 }
2652 }
2653 if ( ! pageList.empty() )
2654 {
2655 m_customListSlideShow.insert( slide.attribute( "name" ), pageList );
2656 }
2657 }
2658 slide=slide.nextSibling().toElement();
2659 }
2660 }
2661 } else if(elem.tagName()=="SELSLIDES") {
2662 if( _clean ) { // Skip this when loading a single page
2663 TQDomElement slide=elem.firstChild().toElement();
2664 while(!slide.isNull()) {
2665 if(slide.tagName()=="SLIDE") {
2666 int nr = -1;
2667 bool show = false;
2668 if(slide.hasAttribute("nr"))
2669 nr=slide.attribute("nr").toInt();
2670 if(slide.hasAttribute("show"))
2671 show=static_cast<bool>(slide.attribute("show").toInt());
2672 if ( nr >= 0 )
2673 {
2674 //kdDebug(33001) << "KPrDocument::loadXML m_selectedSlides nr=" << nr << " show=" << show << endl;
2675 if ( nr > ( (int)m_pageList.count() - 1 ) )
2676 {
2677 for (int i=(m_pageList.count()-1); i<nr;i++)
2678 m_pageList.append( new KPrPage( this, m_masterPage ) );
2679 }
2680 m_pageList.at(nr)->slideSelected(show);
2681 } else kdWarning(33001) << "Parse error. No nr in <SLIDE> !" << endl;
2682 }
2683 slide=slide.nextSibling().toElement();
2684 }
2685 }
2686 } else if ( elem.tagName() == "SOUNDS" ) {
2687 loadUsedSoundFileFromXML( elem );
2688 }
2689 elem=elem.nextSibling().toElement();
2690
2691 emit sigProgress( childCount * ( 70/childTotalCount ) + 15 );
2692 childCount += 1;
2693 }
2694
2695 loadPictureMap( document );
2696
2697 if(activePage!=-1)
2698 m_initialActivePage=m_pageList.at(activePage);
2699 if ( m_pageWhereLoadObject == 0 && m_insertFilePage == 0 )
2700 setModified(false);
2701
2702 return true;
2703}
2704
2705void KPrDocument::loadTextStyle( const TQDomElement& domElement )
2706{
2707 TQDomElement style = domElement.namedItem( "STYLES" ).toElement();
2708 if ( _clean && ! style.isNull() )
2709 loadStyleTemplates( style );
2710}
2711
2712void KPrDocument::loadPictureMap ( const TQDomElement& domElement )
2713{
2714 m_pictureMap.clear();
2715
2716 // <PICTURES>
2717 TQDomElement picturesElem = domElement.namedItem( "PICTURES" ).toElement();
2718 if ( !picturesElem.isNull() )
2719 m_pictureCollection.readXML( picturesElem, m_pictureMap );
2720
2721 // <PIXMAPS>
2722 TQDomElement pixmapsElem = domElement.namedItem( "PIXMAPS" ).toElement();
2723 if ( !pixmapsElem.isNull() )
2724 m_pictureCollection.readXML( pixmapsElem, m_pictureMap );
2725
2726 // <CLIPARTS>
2727 TQDomElement clipartsElem = domElement.namedItem( "CLIPARTS" ).toElement();
2728 if ( !clipartsElem.isNull() )
2729 m_pictureCollection.readXML( pixmapsElem, m_pictureMap );
2730}
2731
2732void KPrDocument::loadBackground( const TQDomElement &element )
2733{
2734 kdDebug(33001) << "KPrDocument::loadBackground" << endl;
2735 TQDomElement page=element.firstChild().toElement();
2736 int i=m_insertFilePage;
2737 while(!page.isNull()) {
2738 if(m_pageWhereLoadObject)
2739 {
2740 kdDebug(33001) << "m_pageWhereLoadObject->load(...)" << m_pageWhereLoadObject << endl;
2741 m_pageWhereLoadObject->load(page);
2742 break;
2743 }
2744 else
2745 {
2746 if ( page.tagName() == "MASTERPAGE" )
2747 {
2748 m_masterPage->load( page );
2749 }
2750 else
2751 {
2752 //test if there is a page at this index
2753 //=> don't add new page if there is again a page
2754 if ( i > ( (int)m_pageList.count() - 1 ) )
2755 m_pageList.append( new KPrPage( this, m_masterPage ) );
2756 m_pageList.at(i)->load(page);
2757 i++;
2758 }
2759 }
2760 page=page.nextSibling().toElement();
2761 }
2762}
2763
2764KCommand *KPrDocument::loadObjects( const TQDomElement &element, bool paste )
2765{
2766 ObjType t = OT_LINE;
2767 TQDomElement obj=element.firstChild().toElement();
2768 TQValueList<KPrObject *> pasteObjects;
2769 while(!obj.isNull()) {
2770 if(obj.tagName()=="OBJECT" ) {
2771 bool sticky=false;
2772 int tmp=0;
2773 if(obj.hasAttribute("type"))
2774 tmp=obj.attribute("type").toInt();
2775 t=static_cast<ObjType>(tmp);
2776 tmp=0;
2777 if(obj.hasAttribute("sticky"))
2778 tmp=obj.attribute("sticky").toInt();
2779 sticky=static_cast<bool>(tmp);
2780 double offset=0;
2781 switch ( t ) {
2782 case OT_LINE: {
2783 KPrLineObject *kplineobject = new KPrLineObject();
2784 offset=kplineobject->load(obj);
2785 if ( sticky && !ignoreSticky)
2786 {
2787 m_masterPage->appendObject(kplineobject);
2788 kplineobject->setOrig(kplineobject->getOrig().x(),offset);
2789 }
2790 else if (m_pageWhereLoadObject && paste) {
2791 kplineobject->setOrig(kplineobject->getOrig().x(),offset);
2792 pasteObjects.append( kplineobject );
2793 }
2794 else if( m_pageWhereLoadObject &&!paste)
2795 {
2796 m_pageWhereLoadObject->appendObject(kplineobject);
2797 kplineobject->setOrig(kplineobject->getOrig().x(),offset);
2798 }
2799 else
2800 insertObjectInPage(offset, kplineobject);
2801 } break;
2802 case OT_RECT: {
2803 KPrRectObject *kprectobject = new KPrRectObject();
2804 offset=kprectobject->load(obj);
2805 if ( sticky && !ignoreSticky)
2806 {
2807 m_masterPage->appendObject(kprectobject);
2808 kprectobject->setOrig(kprectobject->getOrig().x(),offset);
2809 }
2810 else if (m_pageWhereLoadObject && paste) {
2811 kprectobject->setOrig(kprectobject->getOrig().x(),offset);
2812 pasteObjects.append( kprectobject );
2813 }
2814 else if( m_pageWhereLoadObject &&!paste)
2815 {
2816 m_pageWhereLoadObject->appendObject(kprectobject);
2817 kprectobject->setOrig(kprectobject->getOrig().x(),offset);
2818 }
2819 else
2820 insertObjectInPage(offset, kprectobject);
2821 } break;
2822 case OT_ELLIPSE: {
2823 KPrEllipseObject *kpellipseobject = new KPrEllipseObject();
2824 offset=kpellipseobject->load(obj);
2825 if ( sticky && !ignoreSticky)
2826 {
2827 m_masterPage->appendObject(kpellipseobject);
2828 kpellipseobject->setOrig(kpellipseobject->getOrig().x(),offset);
2829 }
2830 else if ( m_pageWhereLoadObject && paste)
2831 {
2832 kpellipseobject->setOrig(kpellipseobject->getOrig().x(),offset);
2833 pasteObjects.append( kpellipseobject );
2834 }
2835 else if( m_pageWhereLoadObject &&!paste)
2836 {
2837 m_pageWhereLoadObject->appendObject(kpellipseobject);
2838 kpellipseobject->setOrig(kpellipseobject->getOrig().x(),offset);
2839 }
2840 else
2841 insertObjectInPage(offset, kpellipseobject);
2842 } break;
2843 case OT_PIE: {
2844 KPrPieObject *kppieobject = new KPrPieObject();
2845 offset=kppieobject->load(obj);
2846 if ( sticky && !ignoreSticky)
2847 {
2848 m_masterPage->appendObject(kppieobject);
2849 kppieobject->setOrig(kppieobject->getOrig().x(),offset);
2850 }
2851 else if ( m_pageWhereLoadObject && paste) {
2852 kppieobject->setOrig(kppieobject->getOrig().x(),offset);
2853 pasteObjects.append( kppieobject );
2854 }
2855 else if( m_pageWhereLoadObject &&!paste)
2856 {
2857 m_pageWhereLoadObject->appendObject(kppieobject);
2858 kppieobject->setOrig(kppieobject->getOrig().x(),offset);
2859 }
2860 else
2861 insertObjectInPage(offset, kppieobject);
2862 } break;
2863 case OT_AUTOFORM: {
2864 KPrAutoformObject *kpautoformobject = new KPrAutoformObject();
2865 offset=kpautoformobject->load(obj);
2866 if ( sticky && !ignoreSticky)
2867 {
2868 m_masterPage->appendObject(kpautoformobject);
2869 kpautoformobject->setOrig(kpautoformobject->getOrig().x(),offset);
2870 }
2871 else if ( m_pageWhereLoadObject&& paste) {
2872 kpautoformobject->setOrig(kpautoformobject->getOrig().x(),offset);
2873 pasteObjects.append( kpautoformobject );
2874 }
2875 else if( m_pageWhereLoadObject &&!paste)
2876 {
2877 m_pageWhereLoadObject->appendObject(kpautoformobject);
2878 kpautoformobject->setOrig(kpautoformobject->getOrig().x(),offset);
2879 }
2880 else
2881 insertObjectInPage(offset, kpautoformobject);
2882 } break;
2883 case OT_TEXT: {
2884 KPrTextObject *kptextobject = new KPrTextObject( this );
2885 offset=kptextobject->load(obj);
2886 if ( sticky && !ignoreSticky)
2887 {
2888 m_masterPage->appendObject(kptextobject);
2889 kptextobject->setOrig(kptextobject->getOrig().x(),offset);
2890 }
2891 else if ( m_pageWhereLoadObject && paste) {
2892 kptextobject->setOrig(kptextobject->getOrig().x(),offset);
2893 pasteObjects.append( kptextobject );
2894 }
2895 else if( m_pageWhereLoadObject &&!paste)
2896 {
2897 m_pageWhereLoadObject->appendObject(kptextobject);
2898 kptextobject->setOrig(kptextobject->getOrig().x(),offset);
2899 }
2900 else
2901 insertObjectInPage(offset, kptextobject);
2902 } break;
2903 case OT_CLIPART:
2904 case OT_PICTURE: {
2905 KPrPixmapObject *kppixmapobject = new KPrPixmapObject( pictureCollection() );
2906 offset=kppixmapobject->load(obj);
2907 if ( sticky && !ignoreSticky)
2908 {
2909 m_masterPage->appendObject(kppixmapobject);
2910 kppixmapobject->setOrig(kppixmapobject->getOrig().x(),offset);
2911 }
2912 else if ( m_pageWhereLoadObject && paste) {
2913 kppixmapobject->setOrig(kppixmapobject->getOrig().x(),offset);
2914 pasteObjects.append( kppixmapobject );
2915 kppixmapobject->reload();
2916 }
2917 else if( m_pageWhereLoadObject &&!paste)
2918 {
2919 m_pageWhereLoadObject->appendObject(kppixmapobject);
2920 kppixmapobject->setOrig(kppixmapobject->getOrig().x(),offset);
2921 }
2922 else
2923 insertObjectInPage(offset, kppixmapobject);
2924 } break;
2925 case OT_FREEHAND: {
2926 KPrFreehandObject *kpfreehandobject = new KPrFreehandObject();
2927 offset=kpfreehandobject->load(obj);
2928
2929 if ( sticky && !ignoreSticky)
2930 {
2931 m_masterPage->appendObject(kpfreehandobject);
2932 kpfreehandobject->setOrig(kpfreehandobject->getOrig().x(),offset);
2933 }
2934 else if ( m_pageWhereLoadObject && paste) {
2935 kpfreehandobject->setOrig(kpfreehandobject->getOrig().x(),offset);
2936 pasteObjects.append( kpfreehandobject );
2937 }
2938 else if( m_pageWhereLoadObject &&!paste)
2939 {
2940 m_pageWhereLoadObject->appendObject(kpfreehandobject);
2941 kpfreehandobject->setOrig(kpfreehandobject->getOrig().x(),offset);
2942 }
2943 else
2944 insertObjectInPage(offset,kpfreehandobject);
2945 } break;
2946 case OT_POLYLINE: {
2947 KPrPolylineObject *kppolylineobject = new KPrPolylineObject();
2948 offset=kppolylineobject->load(obj);
2949 if ( sticky && !ignoreSticky)
2950 {
2951 m_masterPage->appendObject(kppolylineobject);
2952 kppolylineobject->setOrig(kppolylineobject->getOrig().x(),offset);
2953 }
2954 else if (m_pageWhereLoadObject && paste) {
2955 kppolylineobject->setOrig(kppolylineobject->getOrig().x(),offset);
2956 pasteObjects.append( kppolylineobject );
2957 }
2958 else if( m_pageWhereLoadObject &&!paste)
2959 {
2960 m_pageWhereLoadObject->appendObject(kppolylineobject);
2961 kppolylineobject->setOrig(kppolylineobject->getOrig().x(),offset);
2962 }
2963 else
2964 insertObjectInPage(offset, kppolylineobject);
2965 } break;
2966 case OT_QUADRICBEZIERCURVE: {
2967 KPrQuadricBezierCurveObject *kpQuadricBezierCurveObject = new KPrQuadricBezierCurveObject();
2968 offset=kpQuadricBezierCurveObject->load(obj);
2969 if ( sticky && !ignoreSticky)
2970 {
2971 m_masterPage->appendObject(kpQuadricBezierCurveObject);
2972 kpQuadricBezierCurveObject->setOrig(kpQuadricBezierCurveObject->getOrig().x(),offset);
2973 }
2974 else if ( m_pageWhereLoadObject && paste) {
2975 kpQuadricBezierCurveObject->setOrig(kpQuadricBezierCurveObject->getOrig().x(),offset);
2976 pasteObjects.append( kpQuadricBezierCurveObject );
2977 }
2978 else if( m_pageWhereLoadObject &&!paste)
2979 {
2980 m_pageWhereLoadObject->appendObject(kpQuadricBezierCurveObject);
2981 kpQuadricBezierCurveObject->setOrig(kpQuadricBezierCurveObject->getOrig().x(),offset);
2982 }
2983 else
2984 insertObjectInPage(offset, kpQuadricBezierCurveObject);
2985 } break;
2986 case OT_CUBICBEZIERCURVE: {
2987 KPrCubicBezierCurveObject *kpCubicBezierCurveObject = new KPrCubicBezierCurveObject();
2988 offset=kpCubicBezierCurveObject->load(obj);
2989 if ( sticky && !ignoreSticky)
2990 {
2991 m_masterPage->appendObject(kpCubicBezierCurveObject);
2992 kpCubicBezierCurveObject->setOrig(kpCubicBezierCurveObject->getOrig().x(),offset);
2993 }
2994 else if ( m_pageWhereLoadObject && paste) {
2995 kpCubicBezierCurveObject->setOrig(kpCubicBezierCurveObject->getOrig().x(),offset);
2996 pasteObjects.append( kpCubicBezierCurveObject );
2997 }
2998 else if( m_pageWhereLoadObject &&!paste)
2999 {
3000 m_pageWhereLoadObject->appendObject(kpCubicBezierCurveObject);
3001 kpCubicBezierCurveObject->setOrig(kpCubicBezierCurveObject->getOrig().x(),offset);
3002 }
3003 else
3004 insertObjectInPage(offset, kpCubicBezierCurveObject);
3005 } break;
3006 case OT_POLYGON: {
3007 KPrPolygonObject *kpPolygonObject = new KPrPolygonObject();
3008 offset=kpPolygonObject->load( obj );
3009 if ( sticky && !ignoreSticky)
3010 {
3011 m_masterPage->appendObject(kpPolygonObject);
3012 kpPolygonObject->setOrig(kpPolygonObject->getOrig().x(),offset);
3013 }
3014 else if ( m_pageWhereLoadObject && paste) {
3015 kpPolygonObject->setOrig(kpPolygonObject->getOrig().x(),offset);
3016 pasteObjects.append( kpPolygonObject );
3017 }
3018 else if( m_pageWhereLoadObject &&!paste)
3019 {
3020 m_pageWhereLoadObject->appendObject(kpPolygonObject);
3021 kpPolygonObject->setOrig(kpPolygonObject->getOrig().x(),offset);
3022 }
3023 else
3024 insertObjectInPage(offset, kpPolygonObject);
3025 } break;
3026 case OT_CLOSED_LINE: {
3027 KPrClosedLineObject *kpClosedLinneObject = new KPrClosedLineObject();
3028 offset = kpClosedLinneObject->load( obj );
3029 if ( sticky && !ignoreSticky) {
3030 m_masterPage->appendObject( kpClosedLinneObject );
3031 kpClosedLinneObject->setOrig( kpClosedLinneObject->getOrig().x(), offset );
3032 }
3033 else if ( m_pageWhereLoadObject && paste ) {
3034 kpClosedLinneObject->setOrig( kpClosedLinneObject->getOrig().x(), offset );
3035 pasteObjects.append( kpClosedLinneObject );
3036 }
3037 else if( m_pageWhereLoadObject &&!paste)
3038 {
3039 m_pageWhereLoadObject->appendObject( kpClosedLinneObject );
3040 kpClosedLinneObject->setOrig( kpClosedLinneObject->getOrig().x(), offset );
3041 }
3042 else
3043 insertObjectInPage( offset, kpClosedLinneObject );
3044 } break;
3045 case OT_GROUP: {
3046 KPrGroupObject *kpgroupobject = new KPrGroupObject();
3047 offset=kpgroupobject->load(obj, this);
3048 if ( sticky && !ignoreSticky)
3049 {
3050 m_masterPage->appendObject(kpgroupobject);
3051 kpgroupobject->setOrig(kpgroupobject->getOrig().x(),offset);
3052 }
3053 else if ( m_pageWhereLoadObject && paste) {
3054 kpgroupobject->setOrig(kpgroupobject->getOrig().x(),offset);
3055 pasteObjects.append( kpgroupobject );
3056 }
3057 else if( m_pageWhereLoadObject &&!paste)
3058 {
3059 m_pageWhereLoadObject->appendObject(kpgroupobject);
3060 kpgroupobject->setOrig(kpgroupobject->getOrig().x(),offset);
3061 }
3062 else
3063 insertObjectInPage(offset, kpgroupobject);
3064 } break;
3065 default: break;
3066 }
3067 }
3068 obj=obj.nextSibling().toElement();
3069 }
3070
3071 KPrInsertCmd *insertCmd = 0;
3072 if ( ! pasteObjects.empty() )
3073 {
3074 insertCmd = new KPrInsertCmd( i18n( "Paste Objects" ), pasteObjects,
3075 this , m_pageWhereLoadObject );
3076 insertCmd->execute();
3077 }
3078 return insertCmd;
3079}
3080
3081void KPrDocument::loadTitle( const TQDomElement &element )
3082{
3083 TQDomElement title=element.firstChild().toElement();
3084 int i=m_insertFilePage;
3085 while ( !title.isNull() ) {
3086 if ( title.tagName()=="Title" )
3087 {
3088 //test if there is a page at this index
3089 //=> don't add new page if there is again a page
3090 if(!m_pageWhereLoadObject)
3091 {
3092 if ( i > ( (int)m_pageList.count() - 1 ) )
3093 m_pageList.append( new KPrPage( this, m_masterPage ) );
3094 m_pageList.at(i)->insertManualTitle(title.attribute("title"));
3095 i++;
3096 }
3097 else
3098 m_pageWhereLoadObject->insertManualTitle(title.attribute("title"));
3099 }
3100 title=title.nextSibling().toElement();
3101 }
3102}
3103
3104void KPrDocument::loadNote( const TQDomElement &element )
3105{
3106 TQDomElement note=element.firstChild().toElement();
3107 int i=m_insertFilePage;
3108 while ( !note.isNull() ) {
3109 if ( note.tagName()=="Note" )
3110 {
3111 //test if there is a page at this index
3112 //=> don't add new page if there is again a page
3113 if(!m_pageWhereLoadObject)
3114 {
3115 if ( i > ( (int)m_pageList.count() - 1 ) )
3116 m_pageList.append( new KPrPage( this, m_masterPage ) );
3117 m_pageList.at(i)->setNoteText(note.attribute("note"));
3118 i++;
3119 }
3120 else
3121 m_pageWhereLoadObject->setNoteText(note.attribute("note"));
3122 }
3123 note=note.nextSibling().toElement();
3124 }
3125}
3126
3127void KPrDocument::loadUsedSoundFileFromXML( const TQDomElement &element )
3128{
3129 usedSoundFile = TQStringList();
3130 haveNotOwnDiskSoundFile = TQStringList();
3131 TQDomElement fileElement = element.firstChild().toElement();
3132 while ( !fileElement.isNull() ) {
3133 if ( fileElement.tagName() == "FILE" ) {
3134 TQString fileName;
3135 if ( fileElement.hasAttribute( "name" ) )
3136 fileName = fileElement.attribute( "name" );
3137
3138 if ( fileElement.hasAttribute( "filename" ) ) {
3139 TQString name = fileElement.attribute( "filename" );
3140 TQFile _file( name );
3141 if ( _file.open( IO_ReadOnly ) ) {
3142 fileName = name;
3143 _file.close();
3144 }
3145 else
3146 haveNotOwnDiskSoundFile.append( name );
3147 }
3148
3149 usedSoundFile.append( fileName );
3150
3151 fileElement = fileElement.nextSibling().toElement();
3152 }
3153 }
3154}
3155
3156void KPrDocument::loadImagesFromStore( KoStore *_store )
3157{
3158 if ( _store ) {
3159 m_pictureCollection.readFromStore( _store, m_pictureMap );
3160 m_pictureMap.clear(); // Release memory
3161 }
3162}
3163
3164bool KPrDocument::completeLoading( KoStore* _store )
3165{
3166 kdDebug()<<"bool KPrDocument::completeLoading( KoStore* _store )*************************\n";
3167 emit sigProgress( 80 );
3168
3169 if ( _store ) {
3170 loadImagesFromStore( _store );
3171 emit sigProgress( 90 );
3172
3173 if ( !usedSoundFile.isEmpty() )
3174 loadUsedSoundFileFromStore( _store, usedSoundFile );
3175
3176 if ( _clean )
3177 createHeaderFooter();
3178 //else {
3179 //m_pageList.last()->updateBackgroundSize();
3180 //}
3181
3182
3183 if ( saveOnlyPage == -1 ) {
3184 // ### following call independant of saveOnlyPage's value?
3185 m_masterPage->completeLoading( _clean, lastObj );
3186 TQPtrListIterator<KPrPage> it( m_pageList );
3187 for ( ; it.current(); ++it )
3188 it.current()->completeLoading( _clean, lastObj );
3189 }
3190 } else {
3191 if ( _clean )
3192 {
3194 setPageLayout( __pgLayout );
3195 }
3196 else
3197 setPageLayout( m_pageLayout );
3198 }
3199
3200 compatibilityFromOldFileFormat();
3201
3202 emit sigProgress( 100 );
3203 recalcVariables( VT_FIELD );
3204 emit sigProgress( -1 );
3205
3206 connect( documentInfo(), TQ_SIGNAL( sigDocumentInfoModifed()),this,TQ_SLOT(slotDocumentInfoModifed() ) );
3207 //desactivate bgspellchecking
3208 //attributes isReadWrite is not placed at the beginning !
3209 if ( !isReadWrite())
3210 enableBackgroundSpellCheck( false );
3211 return true;
3212}
3213
3214void KPrDocument::loadUsedSoundFileFromStore( KoStore *_store, TQStringList _list )
3215{
3216 int i = m_insertFilePage;
3217 TQStringList::Iterator it = _list.begin();
3218 for ( ; it != _list.end(); ++it ) {
3219 TQString soundFile = *it;
3220
3221 if ( _store->open( soundFile ) ) {
3222 kdDebug( 33001 ) << "Not found file on disk. Use this( " << soundFile << " ) file." << endl;
3223 KoStoreDevice dev( _store );
3224 int size = _store->size();
3225 char *data = new char[size];
3226 dev.readBlock( data, size );
3227
3228 int position = soundFile.findRev( '.' );
3229 TQString format = soundFile.right( soundFile.length() - position );
3230 KTempFile *tmpFile = new KTempFile( TQString(), format );
3231 tmpFile->setAutoDelete( true );
3232 tmpFile->file()->writeBlock( data, size );
3233 tmpFile->close();
3234
3235 TQString tmpFileName = tmpFile->name();
3236 tmpSoundFileList.append( tmpFile );
3237
3238 TQString _fileName = *haveNotOwnDiskSoundFile.at( i );
3239 ++i;
3240
3241 TQPtrListIterator<KPrPage> it( m_pageList );
3242 for ( ; it.current(); ++it ) {
3243 TQString _file = it.current()->getPageSoundFileName();
3244 if ( !_file.isEmpty() && _file == _fileName )
3245 it.current()->setPageSoundFileName( tmpFileName );
3246
3247 TQPtrListIterator<KPrObject> oIt( it.current()->objectList() );
3248 for ( ; oIt.current(); ++oIt ) {
3249 _file = oIt.current()->getAppearSoundEffectFileName();
3250 if ( !_file.isEmpty() && _file == _fileName )
3251 oIt.current()->setAppearSoundEffectFileName( tmpFileName );
3252
3253 _file = oIt.current()->getDisappearSoundEffectFileName();
3254 if ( !_file.isEmpty() && _file == _fileName )
3255 oIt.current()->setDisappearSoundEffectFileName( tmpFileName );
3256 }
3257 }
3258
3259 _store->close();
3260 delete[] data;
3261 }
3262 else {
3263 kdDebug( 33001 ) << "Found this( " << soundFile << " ) file on disk" << endl;
3264 }
3265 }
3266}
3267
3268void KPrDocument::setPageLayout( const KoPageLayout &pgLayout )
3269{
3270 // if ( _pageLayout == pgLayout )
3271 // return;
3272
3273 m_pageLayout = pgLayout;
3274
3275 //for ( int i = 0; i < static_cast<int>( m_pageList.count() ); i++ )
3276 // m_pageList.at( i )->updateBackgroundSize();
3277
3278 repaint( false );
3279 layout();
3280 // don't setModified(true) here, since this is called on startup
3281}
3282
3283//when we change pagelayout we must re-position header/footer
3284void KPrDocument::updateHeaderFooterPosition( )
3285{
3286 KoRect pageRect=m_masterPage->getPageRect();
3287 TQRect oldBoundingRect = zoomHandler()->zoomRect( _header->getRepaintRect() );
3288 _header->setOrig(pageRect.topLeft ());
3289 _header->setSize(pageRect.width(),_header->getSize().height());
3290 repaint( oldBoundingRect );
3291 repaint(_header);
3292
3293 oldBoundingRect = zoomHandler()->zoomRect( _footer->getRepaintRect() );
3294 _footer->setOrig(pageRect.left(),pageRect.bottom()-_footer->getSize().height());
3295 _footer->setSize(pageRect.width(),_footer->getSize().height());
3296 repaint(oldBoundingRect);
3297 repaint(_footer);
3298}
3299
3300bool KPrDocument::initDoc(InitDocFlags flags, TQWidget* parentWidget)
3301{
3302
3303 if (flags==KoDocument::InitDocEmpty)
3304 {
3305 TQString fileName( locate("kpresenter_template", "Screenpresentations/.source/Plain.kpt",
3306 KPrFactory::global() ) );
3307 objStartY = 0;
3308 _clean = true;
3309 bool ok = loadNativeFormat( fileName );
3310 if ( !ok )
3311 showLoadingErrorDialog();
3312 resetURL();
3313 setEmpty();
3314 return ok;
3315 }
3316
3317 TQString file;
3318 KoTemplateChooseDia::ReturnType ret;
3319 KoTemplateChooseDia::DialogType dlgtype;
3320 if (flags != InitDocFileNew)
3321 dlgtype = KoTemplateChooseDia::Everything;
3322 else
3323 dlgtype = KoTemplateChooseDia::OnlyTemplates;
3324
3325 ret = KoTemplateChooseDia::choose( KPrFactory::global(), file,
3326 dlgtype, "kpresenter_template", parentWidget );
3327 if ( ret == KoTemplateChooseDia::Template ) {
3328 _clean = true; //was a parameter called "clean", but unused
3329 bool ok = loadNativeFormat( file );
3330 if ( !ok )
3331 showLoadingErrorDialog();
3332 objStartY = 0;
3333 _clean = true;
3334 resetURL();
3335 setEmpty();
3336 return ok;
3337 } else if ( ret == KoTemplateChooseDia::File ) {
3338 objStartY = 0;
3339 _clean = true;
3340 KURL url( file );
3341 bool ok = openURL( url );
3342 return ok;
3343 } else if ( ret == KoTemplateChooseDia::Empty ) {
3344 TQString fileName( locate("kpresenter_template", "Screenpresentations/.source/Plain.kpt",
3345 KPrFactory::global() ) );
3346 objStartY = 0;
3347 _clean = true;
3348 bool ok = loadNativeFormat( fileName );
3349 if ( !ok )
3350 showLoadingErrorDialog();
3351 resetURL();
3352 setEmpty();
3353 return ok;
3354 } else
3355 return false;
3356}
3357
3358void KPrDocument::openExistingFile( const TQString& file )
3359{
3360 objStartY = 0;
3361 _clean = true;
3362 KoDocument::openExistingFile( file );
3363}
3364
3365void KPrDocument::openTemplate( const TQString& file )
3366{
3367 KoDocument::openTemplate( file );
3368 objStartY = 0;
3369 _clean = true;
3370}
3371
3372void KPrDocument::initEmpty()
3373{
3374 TQString fileName( locate("kpresenter_template", "Screenpresentations/.source/Plain.kpt",
3375 KPrFactory::global() ) );
3376 objStartY = 0;
3377 _clean = true;
3378 setModified(true);
3379 bool ok = loadNativeFormat( fileName );
3380 if ( !ok )
3381 showLoadingErrorDialog();
3382 resetURL();
3383}
3384
3385void KPrDocument::setEmpty()
3386{
3387 KoDocument::setEmpty();
3388 // Whether loaded from template or from empty doc: this is a new one -> set creation date
3389 m_varColl->variableSetting()->setCreationDate(TQDateTime::currentDateTime());
3390 recalcVariables( VT_DATE ); // , VST_CREATION_DATE ...
3391 // If we then load a document, it will override that date.
3392}
3393
3394void KPrDocument::setGridValue( double _x, double _y, bool _replace )
3395{
3396 oldGridX = m_gridX;
3397 oldGridY = m_gridY;
3398 m_gridX=_x;
3399 m_gridY=_y;
3400 if ( _replace )
3401 replaceObjs();
3402}
3403
3404void KPrDocument::repaint( bool erase )
3405{
3406 TQPtrListIterator<KoView> it( views() );
3407 for( ; it.current(); ++it ) {
3408 KPrCanvas* canvas = ((KPrView*)it.current())->getCanvas();
3409 canvas->repaint( erase );
3410 }
3411}
3412
3413void KPrDocument::repaint( const TQRect& rect )
3414{
3415 TQRect r;
3416 TQPtrListIterator<KoView> it( views() );
3417 for( ; it.current(); ++it ) {
3418 r = rect;
3419 KPrCanvas* canvas = ((KPrView*)it.current())->getCanvas();
3420 r.moveTopLeft( TQPoint( r.x() - canvas->diffx(),
3421 r.y() - canvas->diffy() ) );
3422 canvas->update( r );
3423 }
3424}
3425
3426void KPrDocument::layout(KPrObject *kpobject)
3427{
3428 KPrTextObject * obj = dynamic_cast<KPrTextObject *>( kpobject );
3429 if (obj)
3430 obj->layout();
3431}
3432
3433void KPrDocument::layout()
3434{
3435 TQPtrListIterator<KoView> it( views() );
3436 for( ; it.current(); ++it ) {
3437 KPrCanvas* canvas = ((KPrView*)it.current())->getCanvas();
3438 canvas->layout();
3439 }
3440}
3441
3442void KPrDocument::repaint( KPrObject *kpobject )
3443{
3444 repaint( m_zoomHandler->zoomRect( kpobject->getRepaintRect() ) );
3445}
3446
3447TQValueList<int> KPrDocument::getPageEffectSteps( unsigned int num )
3448{
3449 return m_pageList.at(num)->getEffectSteps();
3450}
3451
3452TQRect KPrDocument::getPageRect( bool decBorders ) const
3453{
3454 int pw, ph, bl = static_cast<int>(m_pageLayout.ptLeft);
3455 int br = static_cast<int>(m_pageLayout.ptRight);
3456 int bt = static_cast<int>(m_pageLayout.ptTop);
3457 int bb = static_cast<int>(m_pageLayout.ptBottom);
3458 int wid = static_cast<int>(m_pageLayout.ptWidth);
3459 int hei = static_cast<int>(m_pageLayout.ptHeight);
3460
3461 if ( !decBorders ) {
3462 br = 0;
3463 bt = 0;
3464 bl = 0;
3465 bb = 0;
3466 }
3467
3468 pw = wid - ( bl + br );
3469 ph = hei - ( bt + bb );
3470
3471 return TQRect( bl, bt, pw, ph );
3472}
3473
3474int KPrDocument::getLeftBorder() const
3475{
3476 return static_cast<int>(m_pageLayout.ptLeft);
3477}
3478
3479int KPrDocument::getTopBorder() const
3480{
3481 return static_cast<int>(m_pageLayout.ptTop);
3482}
3483
3484int KPrDocument::getBottomBorder() const
3485{
3486 return static_cast<int>(m_pageLayout.ptBottom);
3487}
3488
3489int KPrDocument::getRightBorder() const
3490{
3491 return static_cast<int>(m_pageLayout.ptRight);
3492}
3493
3494void KPrDocument::deletePage( int _page )
3495{
3496 kdDebug(33001) << "KPrDocument::deletePage " << _page << endl;
3497 //m_pageList.at(_page)->deletePage();
3498 if ( m_pageList.count()==1 )
3499 return;
3500 KPrDeletePageCmd *cmd = new KPrDeletePageCmd( i18n("Delete Slide"), _page, this );
3501 cmd->execute();
3502 addCommand(cmd);
3503}
3504
3505void KPrDocument::insertPage( KPrPage *page, int currentPageNum, int insertPageNum )
3506{
3507 // check if page was allready deleted
3508 int pos = m_deletedPageList.findRef( page );
3509 if ( pos != -1 )
3510 m_deletedPageList.take( pos );
3511
3512 m_pageList.insert( insertPageNum, page );
3513
3514 pageOrderChanged();
3515 //activate this page in all views which on slide currentPageNum
3516 TQPtrListIterator<KoView> it( views() );
3517 for (; it.current(); ++it )
3518 {
3519 KPrView *view = static_cast<KPrView*>( it.current() );
3520 view->addSideBarItem( insertPageNum );
3521
3522 // change to the new page if the view was on the current page.
3523 if ( (int)view->getCurrPgNum() - 1 == currentPageNum )
3524 {
3525 view->skipToPage( insertPageNum );
3526 }
3527 else // recalc the page number as it might have been changed
3528 {
3529 view->recalcCurrentPageNum();
3530 }
3531 }
3532}
3533
3534void KPrDocument::takePage( KPrPage *page, int pageNum )
3535{
3536 int pos = m_pageList.findRef( page );
3537 m_pageList.take( pos );
3538 m_deletedPageList.append( page );
3539
3540 pageOrderChanged();
3541
3542 TQPtrListIterator<KoView> it( views() );
3543 for (; it.current(); ++it )
3544 {
3545 KPrView *view = static_cast<KPrView*>( it.current() );
3546 view->removeSideBarItem( pos );
3547
3548 // change to the new page if the view was on the current page.
3549 if ( (int)view->getCurrPgNum() - 1 == pos )
3550 {
3551 view->skipToPage( pageNum );
3552 }
3553 else // recalc the page number as it might have been changed
3554 {
3555 view->recalcCurrentPageNum();
3556 }
3557 }
3558
3559 repaint( false );
3560}
3561
3562void KPrDocument::pageOrderChanged()
3563{
3564 recalcVariables( VT_PGNUM );
3565
3566 //update statusbar
3567 emit pageNumChanged();
3568 emit sig_updateMenuBar();
3569}
3570
3571void KPrDocument::movePageTo( int oldPos, int newPos )
3572{
3573 kdDebug(33001) << "movePage oldPos = " << oldPos << ", neuPos = " << newPos << endl;
3574
3575 KPrPage * page = m_pageList.take( oldPos );
3576 m_pageList.insert( newPos, page );
3577
3578 pageOrderChanged();
3579
3580 // Update the sidebars
3581 TQPtrListIterator<KoView> it( views() );
3582 for (; it.current(); ++it )
3583 {
3584 KPrView *view = static_cast<KPrView*>( it.current() );
3585 view->moveSideBarItem( oldPos, newPos );
3586
3587 // change to the new page if the view was on the old pos.
3588 if ( (int)view->getCurrPgNum() - 1 == oldPos )
3589 {
3590 view->skipToPage( newPos );
3591 }
3592 else // recalc the page number as it might have been changed
3593 {
3594 view->recalcCurrentPageNum();
3595 }
3596 }
3597}
3598
3599TQString KPrDocument::templateFileName( bool chooseTemplate, const TQString &theFile )
3600{
3601 TQString fileName;
3602 if ( !chooseTemplate ) {
3603 if ( theFile.isEmpty() )
3604 fileName = locateLocal( "data", "kpresenter/default.kpr" );
3605 else
3606 fileName = theFile;
3607 } else {
3608 // TODO: pass parentWidget as parameter to this method
3609 TQWidget* parentWidget = 0;
3610 TQString _template;
3611 if ( KoTemplateChooseDia::choose( KPrFactory::global(), _template,
3612 KoTemplateChooseDia::OnlyTemplates,
3613 "kpresenter_template", parentWidget ) == KoTemplateChooseDia::Cancel )
3614 return TQString();
3615 TQFileInfo fileInfo( _template );
3616 fileName = fileInfo.dirPath( true ) + "/" + fileInfo.baseName() + ".kpt";
3617
3618 KURL src, dest;
3619 src.setPath( fileName );
3620 dest.setPath( locateLocal( "data", "kpresenter/default.kpr" ) );
3621 kdDebug(33001) << "Copying template (in KPrDocument::templateFileName)" << endl
3622 << " from: " << src.prettyURL() << endl
3623 << " to: " << dest.prettyURL() << endl;
3624 TDEIO::NetAccess::file_copy( src,
3625 dest,
3626 -1, /* default permissions */
3627 true /* overwrite */ );
3628 }
3629 return fileName;
3630}
3631
3632int KPrDocument::insertNewPage( const TQString &cmdName, int _page, InsertPos _insPos,
3633 bool chooseTemplate, const TQString &theFile )
3634{
3635 kdDebug(33001) << "KPrDocument::insertNewPage " << _page << endl;
3636
3637 TQString fileName=templateFileName(chooseTemplate, theFile);
3638 if(fileName.isEmpty())
3639 return -1;
3640
3641 _clean = false;
3642
3643 objStartY=-1;
3644
3645 //insert page.
3646 KPrPage *newpage = new KPrPage( this, m_masterPage );
3647
3648 m_pageWhereLoadObject=newpage;
3649 m_childCountBeforeInsert = children().count();
3650
3651 bool ok = loadNativeFormat( fileName );
3652 if ( !ok )
3653 showLoadingErrorDialog();
3654
3655 objStartY = 0;
3656
3657 KPrInsertPageCmd *cmd = new KPrInsertPageCmd( cmdName, _page, _insPos, newpage, this );
3658 cmd->execute();
3659 addCommand(cmd);
3660
3661 _clean = true;
3662 m_pageWhereLoadObject=0L;
3663 m_childCountBeforeInsert = 0;
3664 return _page;
3665}
3666
3667void KPrDocument::savePage( const TQString &file, int pgnum, bool ignore )
3668{
3669 saveOnlyPage = pgnum;
3670 _duplicatePage=ignore;
3671 saveNativeFormat( file );
3672 _duplicatePage=false;
3673 saveOnlyPage = -1;
3674}
3675
3676void KPrDocument::replaceObjs( bool createUndoRedo )
3677{
3678 KMacroCommand * macroCmd = 0L;
3679 TQPtrListIterator<KPrPage> oIt(m_pageList);
3680 for (; oIt.current(); ++oIt )
3681 {
3682 KCommand *cmd=oIt.current()->replaceObjs( createUndoRedo, oldGridX,oldGridY,_txtBackCol, _otxtBackCol);
3683 if(cmd && createUndoRedo)
3684 {
3685 if ( !macroCmd)
3686 macroCmd = new KMacroCommand( i18n("Set New Options") );
3687 macroCmd->addCommand(cmd);
3688 }
3689 else
3690 delete cmd;
3691 }
3692
3693 if(macroCmd)
3694 {
3695 macroCmd->execute();
3696 addCommand(macroCmd);
3697 }
3698}
3699
3700void KPrDocument::restoreBackground( KPrPage *page )
3701{
3702 page->background()->reload();
3703}
3704
3705KCommand * KPrDocument::loadPastedObjs( const TQString &in, KPrPage* _page )
3706{
3707 TQDomDocument doc;
3708 doc.setContent( in );
3709
3710 TQDomElement document=doc.documentElement();
3711
3712 // DOC
3713 if (document.tagName()!="DOC") {
3714 kdError(33001) << "Missing DOC" << endl;
3715 return 0L;
3716 }
3717
3718 bool ok = false;
3719
3720 if(document.hasAttribute("mime") && document.attribute("mime")=="application/x-kpresenter")
3721 ok=true;
3722
3723 if ( !ok )
3724 return 0L;
3725 m_pageWhereLoadObject=_page;
3726 KCommand *cmd = loadObjects(document,true);
3727 m_pageWhereLoadObject=0L;
3728
3729 repaint( false );
3730 setModified( true );
3731 return cmd;
3732}
3733
3734void KPrDocument::deSelectAllObj()
3735{
3736 TQPtrListIterator<KoView> it( views() );
3737 for (; it.current(); ++it )
3738 ((KPrView*)it.current())->getCanvas()->deSelectAllObj();
3739}
3740
3741void KPrDocument::deSelectObj(KPrObject *obj)
3742{
3743 TQPtrListIterator<KoView> it( views() );
3744 for (; it.current(); ++it )
3745 ((KPrView*)it.current())->getCanvas()->deSelectObj( obj );
3746}
3747
3748void KPrDocument::setDisplayObjectMasterPage( bool b )
3749{
3750 TQPtrListIterator<KoView> it( views() );
3751 for (; it.current(); ++it )
3752 ((KPrView*)it.current())->updateDisplayObjectMasterPageButton();
3753 repaint(b);
3754}
3755
3756void KPrDocument::setDisplayBackground( bool b )
3757{
3758 TQPtrListIterator<KoView> it( views() );
3759 for (; it.current(); ++it )
3760 ((KPrView*)it.current())->updateDisplayBackgroundButton();
3761 repaint(b);
3762}
3763
3764void KPrDocument::setHeader( bool b )
3765{
3766 _header->setDrawEditRect( b );
3767 _header->setDrawEmpty( b );
3768 if(!b)
3769 {
3770 terminateEditing(_header);
3771 deSelectObj(_header);
3772 }
3773 m_masterPage->setHeader( b, false );
3774 updateHeaderFooterButton();
3775 repaint(b);
3776}
3777
3778void KPrDocument::setFooter( bool b )
3779{
3780 _footer->setDrawEditRect( b );
3781 _footer->setDrawEmpty( b );
3782 if(!b)
3783 {
3784 terminateEditing(_footer);
3785 deSelectObj(_footer);
3786 }
3787 m_masterPage->setFooter( b, false );
3788 updateHeaderFooterButton();
3789 repaint(b);
3790}
3791
3792void KPrDocument::updateHeaderFooterButton()
3793{
3794 TQPtrListIterator<KoView> it( views() );
3795 for (; it.current(); ++it )
3796 ((KPrView*)it.current())->updateHeaderFooterButton();
3797}
3798
3799void KPrDocument::makeUsedPixmapList()
3800{
3801 usedPictures.clear();
3802
3803 for ( uint i = 0; i < m_pageList.count(); i++ ) {
3804 if ( saveOnlyPage != -1 &&
3805 static_cast<int>(i) != saveOnlyPage )
3806 continue;
3807 m_pageList.at(i)->makeUsedPixmapList();
3808 }
3809 // ### following call independant of saveOnlyPage's value?
3810 if ( saveOnlyPage == -1 )
3811 m_masterPage->makeUsedPixmapList();
3812}
3813
3814void KPrDocument::makeUsedSoundFileList()
3815{
3816 if ( saveOnlyPage != -1 )
3817 return;
3818
3819 usedSoundFile.clear();
3820
3821 TQPtrListIterator<KPrPage> it( m_pageList );
3822 for ( ; it.current(); ++it ) {
3823 TQString _file = it.current()->getPageSoundFileName();
3824 if ( !_file.isEmpty() && usedSoundFile.findIndex( _file ) == -1 )
3825 usedSoundFile.append( _file );
3826
3827 TQPtrListIterator<KPrObject> oIt( it.current()->objectList() );
3828 for ( ; oIt.current(); ++oIt ) {
3829 _file = oIt.current()->getAppearSoundEffectFileName();
3830 if ( !_file.isEmpty() && usedSoundFile.findIndex( _file ) == -1 )
3831 usedSoundFile.append( _file );
3832
3833 _file = oIt.current()->getDisappearSoundEffectFileName();
3834 if ( !_file.isEmpty() && usedSoundFile.findIndex( _file ) == -1 )
3835 usedSoundFile.append( _file );
3836 }
3837 }
3838}
3839
3840KoView* KPrDocument::createViewInstance( TQWidget* parent, const char* name )
3841{
3842 //the page numbers have to be recalced for the sticky objects
3843 //as it could not be done during the constructor of KPrView
3844 recalcPageNum();
3845 return new KPrView( this, parent, name );
3846}
3847
3848void KPrDocument::paintContent( TQPainter& painter, const TQRect& rect,
3849 bool /*transparent*/, double zoomX, double zoomY )
3850{
3851 m_zoomHandler->setZoom( 100 );
3852 if ( zoomHandler()->zoomedResolutionX() != zoomX || zoomHandler()->zoomedResolutionY() != zoomY )
3853 {
3854 int zoomLevel = tqRound( 100 * zoomY / zoomHandler()->zoomedResolutionY() ); // ## ignores the case where the x and y scaling differs
3855 zoomHandler()->setZoom( zoomLevel );
3856 bool forPrint = painter.device() && painter.device()->devType() == TQInternal::Printer;
3857 newZoomAndResolution( false, forPrint );
3858 }
3859 //for the moment draw first page.
3860 KPrPage *page=m_pageList.first();
3861 if( m_initialActivePage )
3862 page = m_initialActivePage;
3863
3864 int pageNum = m_pageList.findRef( page );
3865
3866 if ( page->displayBackground() )
3867 page->background()->drawBackground( &painter, zoomHandler(), rect, false );
3868 if ( page->displayObjectFromMasterPage() )
3869 {
3870 KPrPage *masterPage = page->masterPage();
3871 if ( masterPage )
3872 {
3873 TQPtrListIterator<KPrObject> it( masterPage->objectList() );
3874 //draw objects on master slide
3875 for ( ; it.current() ; ++it )
3876 {
3877 if( (it.current()==_header && !page->hasHeader())||(it.current()==_footer && !page->hasFooter()))
3878 continue;
3879 it.current()->draw( &painter, zoomHandler(), pageNum, SM_NONE );
3880 }
3881 }
3882 }
3883 TQPtrListIterator<KPrObject> it( page->objectList() );
3884 for ( ; it.current() ; ++it )
3885 it.current()->draw( &painter, zoomHandler(), pageNum, SM_NONE );
3886}
3887
3888TQPixmap KPrDocument::generatePreview( const TQSize& size )
3889{
3890 int oldZoom = zoomHandler()->zoom();
3891 double oldResolutionX = zoomHandler()->resolutionX();
3892 double oldResolutionY = zoomHandler()->resolutionY();
3893
3894 TQPixmap pix = KoDocument::generatePreview(size);
3895
3896 zoomHandler()->setResolution( oldResolutionX, oldResolutionY );
3897 zoomHandler()->setZoom(oldZoom);
3898 newZoomAndResolution( false, false );
3899
3900 return pix;
3901}
3902
3903void KPrDocument::addShell( KoMainWindow *shell )
3904{
3905 connect( shell, TQ_SIGNAL( documentSaved() ), m_commandHistory, TQ_SLOT( documentSaved() ) );
3906 KoDocument::addShell( shell );
3907}
3908
3909void KPrDocument::movePage( int from, int to )
3910{
3911 kdDebug(33001) << "KPrDocument::movePage from=" << from << " to=" << to << endl;
3912 KPrMovePageCmd *cmd = new KPrMovePageCmd( i18n("Move Slide"), from, to, this );
3913 cmd->execute();
3914 addCommand(cmd);
3915}
3916
3917void KPrDocument::copyPage( int from )
3918{
3919 _clean = false;
3920 m_childCountBeforeInsert = children().count();
3921
3922 _duplicatePage=true; // ### now also set via savePage() parameter below
3923
3924 kdDebug(33001) << "KPrDocument::copyPage from=" << from << " to=" << from + 1 << endl;
3925 kdDebug(33001) << "mimeType = " << mimeType() << ", outputMimeType = " << outputMimeType() << endl;
3926 bool wasSelected = isSlideSelected( from );
3927 KTempFile tempFile( TQString(), mimeType() == nativeOasisMimeType() ? ".oop": ".kpr" );
3928 tempFile.setAutoDelete( true );
3929 savePage( tempFile.name(), from, true );
3930
3931 //insert page.
3932 KPrPage *newpage = new KPrPage( this, m_masterPage );
3933
3934 m_pageWhereLoadObject = newpage;
3935
3936 bool ok = loadNativeFormat( tempFile.name() );
3937 if ( !ok )
3938 showLoadingErrorDialog();
3939
3940 KPrInsertPageCmd *cmd = new KPrInsertPageCmd( i18n("Duplicate Slide"), from, IP_AFTER, newpage, this );
3941 cmd->execute();
3942 addCommand(cmd);
3943
3944 _duplicatePage=false;
3945
3946 _clean = true;
3947 m_pageWhereLoadObject=0L;
3948 m_childCountBeforeInsert = 0;
3949
3950 selectPage( from + 1, wasSelected );
3951}
3952
3953void KPrDocument::copyPageToClipboard( int pgnum )
3954{
3955 // We save the page to a temp file and set the URL of the file in the clipboard
3956 // Yes it's a hack but at least we don't hit the clipboard size limit :)
3957 // (and we don't have to implement copy-tar-structure-to-clipboard)
3958 // In fact it even allows copying a [1-page] kpr in konq and pasting it in kpresenter :))
3959 kdDebug(33001) << "KPrDocument::copyPageToClipboard pgnum=" << pgnum << endl;
3960 kdDebug(33001) << "mimeType = " << mimeType() << ", outputMimeType = " << outputMimeType() << endl;
3961 KTempFile tempFile( TQString(), mimeType() == nativeOasisMimeType() ? ".oop": ".kpr" );
3962 savePage( tempFile.name(), pgnum, true );
3963 KURL url; url.setPath( tempFile.name() );
3964 KURL::List lst;
3965 lst.append( url );
3966 TQApplication::clipboard()->setData( new KURLDrag( lst ) );
3967 m_tempFileInClipboard = tempFile.name(); // do this last, the above calls clipboardDataChanged
3968}
3969
3970void KPrDocument::pastePage( const TQMimeSource * data, int pgnum )
3971{
3972 KURL::List lst;
3973 if ( KURLDrag::decode( data, lst ) && !lst.isEmpty() )
3974 {
3975 insertNewPage(i18n("Paste Slide"), pgnum, IP_BEFORE, false, lst.first().path() );
3976 //selectPage( pgnum, true /* should be part of the file ? */ );
3977 }
3978}
3979
3980void KPrDocument::clipboardDataChanged()
3981{
3982 if ( !m_tempFileInClipboard.isEmpty() )
3983 {
3984 kdDebug(33001) << "KPrDocument::clipboardDataChanged, deleting temp file " << m_tempFileInClipboard << endl;
3985 unlink( TQFile::encodeName( m_tempFileInClipboard ) );
3986 m_tempFileInClipboard = TQString();
3987 }
3988 // TODO enable paste as well, when a txtobject is activated
3989 // and there is plain text in the clipboard. Then enable this code.
3990 //TQMimeSource *data = TQApplication::clipboard()->data();
3991 //bool canPaste = data->provides( "text/uri-list" ) || data->provides( "application/x-kpresenter-selection" );
3992 // emit enablePaste( canPaste );
3993}
3994
3995void KPrDocument::selectPage( int pgNum /* 0-based */, bool select )
3996{
3997 Q_ASSERT( pgNum >= 0 );
3998 KPrPage *page = m_pageList.at( pgNum );
3999 page->slideSelected(select);
4000 kdDebug(33001) << "KPrDocument::selectPage pgNum=" << pgNum << " select=" << select << endl;
4001 setModified(true);
4002
4003 updateSideBarItem( page );
4004 updatePresentationButton();
4005 //update statusbar
4006 emit pageNumChanged();
4007}
4008
4009KPrPage * KPrDocument::findPage(KPrObject *object)
4010{
4011 TQPtrList<KPrObject> masterObjects( m_masterPage->objectList() );
4012 if ( masterObjects.findRef( object ) != -1 )
4013 {
4014 //kdDebug(33001) << "Object is on the master page" << endl;
4015 return m_masterPage;
4016 }
4017 TQPtrListIterator<KPrPage> it( m_pageList );
4018 for ( ; it.current(); ++it ) {
4019 TQPtrList<KPrObject> list( it.current()->objectList() );
4020 if ( list.findRef( object ) != -1 ) {
4021 //kdDebug(33001) << "Object is on page " << m_pageList.findRef(it.current()) + 1 << endl;
4022 return it.current();
4023 }
4024 }
4025 kdDebug(33001) << "Object not found on a page" << endl;
4026 return 0L;
4027}
4028
4029KPrPage * KPrDocument::findPage(TQPtrList<KPrObject> &objects)
4030{
4031 KPrObject *object;
4032 for ( object = objects.first(); object; object=objects.next() ) {
4033 TQPtrList<KPrObject> list( m_masterPage->objectList() );
4034 if ( list.findRef( object ) != -1 )
4035 {
4036 //kdDebug(33001) << "Object is on the master page" << endl;
4037 return m_masterPage;
4038 }
4039 }
4040 object = objects.first();
4041 for ( KPrPage *page=m_pageList.first(); page; page=m_pageList.next() ) {
4042 TQPtrList<KPrObject> list( page->objectList() );
4043 if ( list.findRef( object ) != -1 ) {
4044 //kdDebug(33001) << "The Objects are on page " << m_pageList.findRef(page) + 1 << endl;
4045 return page;
4046 }
4047 }
4048 kdDebug(33001) << "Objects not found on a page" << endl;
4049 return 0L;
4050}
4051
4052void KPrDocument::updateSideBarItem( KPrPage * page )
4053{
4054 // Update the views
4055 TQPtrListIterator<KoView> it( views() );
4056 for (; it.current(); ++it )
4057 static_cast<KPrView*>( it.current() )->updateSideBarItem( page );
4058}
4059
4060bool KPrDocument::isSlideSelected( int pgNum /* 0-based */ )
4061{
4062 Q_ASSERT( pgNum >= 0 );
4063 return m_pageList.at(pgNum)->isSlideSelected();
4064}
4065
4066TQValueList<int> KPrDocument::listOfDisplaySelectedSlides( const TQValueList<KPrPage*> & lst) /* returned list is 0-based */
4067{
4068 TQValueList<int> result;
4069 TQValueListConstIterator<KPrPage*> itPage;
4070 TQValueListConstIterator<KPrPage*> itPageEnd = lst.end();
4071 for( itPage = lst.begin() ; itPage != itPageEnd; ++itPage )
4072 {
4073 int pageNum = m_pageList.find(*itPage );
4074 if ( pageNum != -1 )
4075 {
4076 kdDebug()<<" KPrDocument::displaySelectedSlide : add slide number :"<<pageNum<<endl;
4077 result << pageNum;
4078 }
4079 }
4080 return result;
4081}
4082
4083
4084TQValueList<int> KPrDocument::displaySelectedSlides() /* returned list is 0-based */
4085{
4086 TQValueList<int> result;
4087 if ( m_customListTest )
4088 return *m_customListTest;
4089 if ( m_presentationName.isEmpty() )
4090 return selectedSlides();
4091 else
4092 {
4093 kdDebug()<<" KPrDocument::displaySelectedSlide m_presentationName : "<<m_presentationName<<endl;
4094 result = listOfDisplaySelectedSlides( m_customListSlideShow[m_presentationName]);
4095 }
4096 return result;
4097}
4098
4099TQValueList<int> KPrDocument::selectedSlides() /* returned list is 0-based */
4100{
4101 TQValueList<int> result;
4102 for ( int i = 0; i < static_cast<int>( m_pageList.count() ); i++ ) {
4103 if(m_pageList.at(i)->isSlideSelected())
4104 result <<i;
4105 }
4106 return result;
4107}
4108
4109TQString KPrDocument::selectedForPrinting() {
4110 TQString ret;
4111 int start=-1, end=-1;
4112 bool continuous=false;
4113 for ( int i = 0; i < static_cast<int>( m_pageList.count() ); i++ ) {
4114 if(m_pageList.at(i)->isSlideSelected()) {
4115 if(continuous)
4116 ++end;
4117 else {
4118 start=i;
4119 end=i;
4120 continuous=true;
4121 }
4122 }
4123 else {
4124 if(continuous) {
4125 if(start==end)
4126 ret+=TQString::number(start+1)+",";
4127 else
4128 ret+=TQString::number(start+1)+"-"+TQString::number(end+1)+",";
4129 continuous=false;
4130 }
4131 }
4132 }
4133 if(continuous) {
4134 if(start==end)
4135 ret+=TQString::number(start+1);
4136 else
4137 ret+=TQString::number(start+1)+"-"+TQString::number(end+1);
4138 }
4139 if(','==ret[ret.length()-1])
4140 ret.truncate(ret.length()-1);
4141 return ret;
4142}
4143
4144void KPrDocument::slotRepaintChanged( KPrTextObject *kptextobj )
4145{
4146 //todo
4147 //use this function for the moment
4148 repaint( kptextobj );
4149}
4150
4151
4152void KPrDocument::recalcVariables( int type )
4153{
4154 recalcPageNum();
4155 TQValueList<KoVariable* > modifiedVariables = m_varColl->recalcVariables(type);
4156 if ( modifiedVariables.isEmpty() )
4157 return;
4158
4159 // TODO use the return value from recalcVariables to only repaint what has changed.
4160 TQPtrListIterator<KPrPage> it( m_pageList );
4161 for ( ; it.current(); ++it )
4162 it.current()->slotRepaintVariable();
4163 m_masterPage->slotRepaintVariable();
4164}
4165
4166void KPrDocument::slotGuideLinesChanged( KoView *view )
4167{
4168 ( (KPrView*)view )->getCanvas()->guideLines().getGuideLines( m_hGuideLines, m_vGuideLines );
4169 TQPtrListIterator<KoView> it( views() );
4170 for (; it.current(); ++it )
4171 {
4172 if ( it.current() != view )
4173 {
4174 ( (KPrView*)it.current() )->getCanvas()->guideLines().setGuideLines( m_hGuideLines, m_vGuideLines );
4175 }
4176 }
4177}
4178
4179void KPrDocument::slotDocumentInfoModifed()
4180{
4181 if (!getVariableCollection()->variableSetting()->displayFieldCode())
4182 recalcVariables( VT_FIELD );
4183}
4184
4185void KPrDocument::reorganizeGUI()
4186{
4187 TQPtrListIterator<KoView> it( views() );
4188 for (; it.current(); ++it )
4189 ((KPrView*)it.current())->reorganize();
4190}
4191
4192int KPrDocument::undoRedoLimit() const
4193{
4194 return m_commandHistory->undoLimit();
4195}
4196
4197void KPrDocument::setUndoRedoLimit(int val)
4198{
4199 m_commandHistory->setUndoLimit(val);
4200 m_commandHistory->setRedoLimit(val);
4201}
4202
4203void KPrDocument::updateRuler()
4204{
4205 emit sig_updateRuler();
4206}
4207
4208void KPrDocument::recalcPageNum()
4209{
4210 TQPtrListIterator<KPrPage> it( m_pageList );
4211 for ( ; it.current(); ++it )
4212 it.current()->recalcPageNum();
4213 m_masterPage->recalcPageNum();
4214}
4215
4216KPrPage * KPrDocument::activePage()const
4217{
4218 return m_initialActivePage;
4219}
4220
4221void KPrDocument::insertObjectInPage(double offset, KPrObject *_obj, int pos)
4222{
4224 int page = (int)(offset/__pgLayout.ptHeight)+m_insertFilePage;
4225 if ( page < 0 )
4226 {
4227 kdDebug(33001) << "insertObjectInPage object cound not be inserted page = " << page << endl;
4228 return;
4229 }
4230 double newPos = offset - ( page - m_insertFilePage ) * __pgLayout.ptHeight;
4231 // due to a very small caluculating error which gives us the wrong page
4232 // for objects placed on top of the page we have to move them to the right page.
4233 if ( __pgLayout.ptHeight - newPos < 1e-6 )
4234 {
4235 page++;
4236 newPos = 0.0;
4237 }
4238 if ( page > ( (int)m_pageList.count()-1 ) )
4239 {
4240 for (int i=(m_pageList.count()-1); i<page;i++)
4241 m_pageList.append( new KPrPage( this, m_masterPage ) );
4242 }
4243 _obj->setOrig(_obj->getOrig().x(),newPos);
4244
4245 if ( pos == -1 )
4246 {
4247 m_pageList.at(page)->appendObject(_obj);
4248 }
4249 else
4250 {
4251 m_pageList.at( page )->insertObject( _obj, pos );
4252 }
4253}
4254
4255void KPrDocument::insertPixmapKey( KoPictureKey key )
4256{
4257 if ( !usedPictures.contains( key ) )
4258 usedPictures.append( key );
4259}
4260
4261KPrPage * KPrDocument::initialActivePage() const
4262{
4263 return m_initialActivePage;
4264}
4265
4266void KPrDocument::displayActivePage(KPrPage * _page)
4267{
4268 m_initialActivePage = _page;
4269}
4270
4271void KPrDocument::updateZoomRuler()
4272{
4273 TQPtrListIterator<KoView> it( views() );
4274 for (; it.current(); ++it )
4275 {
4276 ((KPrView*)it.current())->getHRuler()->setZoom( m_zoomHandler->zoomedResolutionX() );
4277 ((KPrView*)it.current())->getVRuler()->setZoom( m_zoomHandler->zoomedResolutionY() );
4278 ((KPrView*)it.current())->slotUpdateRuler();
4279 }
4280}
4281
4282void KPrDocument::newZoomAndResolution( bool updateViews, bool /*forPrint*/ )
4283{
4284 TQPtrListIterator<KPrPage> it( m_pageList );
4285 for ( ; it.current(); ++it ) {
4286 TQPtrListIterator<KPrObject> oit(it.current()->objectList());
4287 for ( ; oit.current(); ++oit ) {
4288 if ( oit.current()->getType() == OT_TEXT )
4289 static_cast<KPrTextObject *>( oit.current() )->textDocument()->formatCollection()->zoomChanged();
4290 }
4291 }
4292 if ( updateViews )
4293 {
4294 TQPtrListIterator<KoView> it( views() );
4295 for (; it.current(); ++it )
4296 {
4297 static_cast<KPrView *>( it.current() )->getCanvas()->update();
4298 static_cast<KPrView *>( it.current() )->getCanvas()->layout();
4299 }
4300 }
4301}
4302
4303bool KPrDocument::isHeader(const KPrObject *obj) const
4304{
4305 return (obj==_header);
4306}
4307
4308bool KPrDocument::isFooter(const KPrObject *obj) const
4309{
4310 return (obj==_footer);
4311}
4312
4313bool KPrDocument::isHeaderFooter(const KPrObject *obj) const
4314{
4315 return (obj==_header)||(obj==_footer);
4316}
4317
4318void KPrDocument::updateRulerPageLayout()
4319{
4320 TQPtrListIterator<KoView> it( views() );
4321 for (; it.current(); ++it )
4322 {
4323 ((KPrView*)it.current())->getHRuler()->setPageLayout(m_pageLayout );
4324 ((KPrView*)it.current())->getVRuler()->setPageLayout(m_pageLayout );
4325
4326 }
4327}
4328
4329void KPrDocument::refreshAllNoteBarMasterPage(const TQString &text, KPrView *exceptView)
4330{
4331 m_masterPage->setNoteText(text );
4332 TQPtrListIterator<KoView> it( views() );
4333 for (; it.current(); ++it )
4334 {
4335 KPrView* view=(KPrView*)it.current();
4336 if ( view->getNoteBar() && view != exceptView && view->editMaster() )
4337 view->getNoteBar()->setCurrentNoteText(text );
4338 }
4339}
4340
4341void KPrDocument::refreshAllNoteBar(int page, const TQString &text, KPrView *exceptView)
4342{
4343 m_pageList.at(page)->setNoteText(text );
4344 TQPtrListIterator<KoView> it( views() );
4345 for (; it.current(); ++it )
4346 {
4347 KPrView* view=(KPrView*)it.current();
4348 if ( view->getNoteBar() && view != exceptView && ((int)(view->getCurrPgNum())-1 == page))
4349 view->getNoteBar()->setCurrentNoteText(text );
4350 }
4351}
4352
4353void KPrDocument::loadStyleTemplates( const TQDomElement &stylesElem )
4354{
4355 TQValueList<TQString> followingStyles;
4356
4357 TQDomNodeList listStyles = stylesElem.elementsByTagName( "STYLE" );
4358 if( listStyles.count() > 0) { // we are going to import at least one style.
4359 KoParagStyle *s = m_styleColl->findStyle("Standard");
4360 kdDebug(32001) << "KPrDocument::loadStyleTemplates looking for Standard, to delete it. Found " << s << endl;
4361 if(s) // delete the standard style.
4362 m_styleColl->removeStyle(s);
4363 }
4364 for (unsigned int item = 0; item < listStyles.count(); item++) {
4365 TQDomElement styleElem = listStyles.item( item ).toElement();
4366
4367 KoParagStyle *sty = new KoParagStyle( TQString() );
4368 // Load the style from the <STYLE> element
4369 sty->loadStyle( styleElem );
4370
4371 TQDomElement formatElem = styleElem.namedItem( "FORMAT" ).toElement();
4372 if ( !formatElem.isNull() )
4373 sty->format() = KPrTextObject::loadFormat( formatElem, 0L, defaultFont(), globalLanguage(), globalHyphenation() );
4374 else
4375 kdWarning(33001) << "No FORMAT tag in <STYLE>" << endl; // This leads to problems in applyStyle().
4376
4377 // Style created, now let's try to add it
4378 sty = m_styleColl->addStyle( sty );
4379 kdDebug() << k_funcinfo << m_styleColl->styleList().count() << " styles, " << followingStyles.count() << " following styles" << endl;
4380 if(m_styleColl->styleList().count() > followingStyles.count() )
4381 {
4382 TQString following = styleElem.namedItem("FOLLOWING").toElement().attribute("name");
4383 followingStyles.append( following );
4384 }
4385 else
4386 kdWarning (33001) << "Found duplicate style declaration, overwriting former " << sty->name() << endl;
4387 }
4388
4389 Q_ASSERT( followingStyles.count() == m_styleColl->styleList().count() );
4390 unsigned int i=0;
4391 for( TQValueList<TQString>::Iterator it = followingStyles.begin(); it != followingStyles.end(); ++it ) {
4392 KoParagStyle * style = m_styleColl->findStyle(*it);
4393 m_styleColl->styleAt( i++)->setFollowingStyle( style );
4394 }
4395}
4396
4397
4398void KPrDocument::updateAllStyleLists()
4399{
4400 TQPtrListIterator<KoView> it( views() );
4401 for (; it.current(); ++it )
4402 ((KPrView*)it.current())->updateStyleList();
4403}
4404
4405void KPrDocument::applyStyleChange( KoStyleChangeDefMap changed )
4406{
4407 TQPtrListIterator<KPrPage> it( m_pageList );
4408 for ( ; it.current(); ++it )
4409 it.current()->applyStyleChange( changed );
4410 m_masterPage->applyStyleChange( changed );
4411}
4412
4413void KPrDocument::saveStyle( KoParagStyle *sty, TQDomElement parentElem )
4414{
4415 TQDomDocument doc = parentElem.ownerDocument();
4416 TQDomElement styleElem = doc.createElement( "STYLE" );
4417 parentElem.appendChild( styleElem );
4418
4419 sty->saveStyle( styleElem );
4420 TQDomElement formatElem = doc.createElement("FORMAT");
4421 KPrTextObject::saveFormat( formatElem, &sty->format() );
4422 styleElem.appendChild( formatElem );
4423}
4424
4425void KPrDocument::startBackgroundSpellCheck()
4426{
4427 //don't start spell checking when document is embedded in konqueror
4428 if(backgroundSpellCheckEnabled() && isReadWrite())
4429 {
4430 if(m_initialActivePage->allTextObjects().count()>0)
4431 {
4432 m_bgSpellCheck->start();
4433 }
4434 }
4435}
4436
4437void KPrDocument::enableBackgroundSpellCheck( bool b )
4438{
4439 //m_bgSpellCheck->enableBackgroundSpellCheck(b);
4440 m_bgSpellCheck->setEnabled(b);
4441 TQPtrListIterator<KoView> it( views() );
4442 for( ; it.current(); ++it )
4443 ((KPrView*)it.current())->updateBgSpellCheckingState();
4444}
4445
4446bool KPrDocument::backgroundSpellCheckEnabled() const
4447{
4448 return m_bgSpellCheck->enabled();
4449}
4450
4451void KPrDocument::reactivateBgSpellChecking(bool refreshTextObj)
4452{
4453 TQPtrListIterator<KPrPage> it( m_pageList );
4454#if 0
4455 if(m_kpresenterView && m_kpresenterView->getCanvas())
4456 activePage=m_kpresenterView->getCanvas()->activePage();
4457#endif
4458 KPrPage *activePage=m_initialActivePage;
4459 for ( ; it.current(); ++it )
4460 {
4461 if( it.current()!=activePage)
4462 it.current()->reactivateBgSpellChecking(false );
4463 else
4464 it.current()->reactivateBgSpellChecking( true);
4465 }
4466 m_masterPage->reactivateBgSpellChecking(refreshTextObj);
4467 startBackgroundSpellCheck();
4468}
4469
4470TQPtrList<KoTextObject> KPrDocument::allTextObjects() const
4471{
4472 TQPtrList<KoTextObject> lst;
4473 TQPtrListIterator<KPrPage> it( m_pageList );
4474 for ( ; it.current(); ++it )
4475 it.current()->addTextObjects( lst );
4476 m_masterPage->addTextObjects( lst );
4477 return lst;
4478}
4479
4480TQValueList<KoTextDocument *> KPrDocument::allTextDocuments() const
4481{
4482 TQValueList<KoTextDocument *> lst;
4483 const TQPtrList<KoTextObject> textObjects = allTextObjects();
4484 TQPtrListIterator<KoTextObject> it( textObjects );
4485 for ( ; it.current() ; ++it ) {
4486 lst.append( it.current()->textDocument() );
4487 }
4488 return lst;
4489}
4490
4491TQValueList<KoTextObject *> KPrDocument::visibleTextObjects( ) const
4492{
4493 TQValueList<KoTextObject *> lst;
4494 TQPtrList<KoTextObject> textFramesets = allTextObjects( );
4495
4496 KoTextObject *frm;
4497 for ( frm=textFramesets.first(); frm != 0; frm=textFramesets.next() ) {
4498 if ( frm && !frm->protectContent() )
4499 {
4500 lst.append( frm );
4501 }
4502 }
4503 return lst;
4504}
4505
4506void KPrDocument::setShowGuideLines( bool b )
4507{
4508 m_bShowGuideLines = b;
4509 setModified( true );
4510}
4511
4512void KPrDocument::horizontalGuideLines( const TQValueList<double> &lines )
4513{
4514 m_hGuideLines = lines;
4515}
4516
4517void KPrDocument::verticalGuideLines( const TQValueList<double> &lines )
4518{
4519 m_vGuideLines = lines;
4520}
4521
4522
4523void KPrDocument::addGuideLine( TQt::Orientation o, double pos )
4524{
4525 if ( o == TQt::Horizontal )
4526 {
4527 m_hGuideLines.append( pos );
4528 }
4529 else
4530 {
4531 m_vGuideLines.append( pos );
4532 }
4533
4534 TQPtrListIterator<KoView> it( views() );
4535 for (; it.current(); ++it )
4536 {
4537 ( (KPrView*)it.current() )->getCanvas()->guideLines().setGuideLines( m_hGuideLines, m_vGuideLines );
4538 }
4539}
4540
4541
4542void KPrDocument::updateGuideLineButton()
4543{
4544 TQPtrListIterator<KoView> it( views() );
4545 for (; it.current(); ++it )
4546 ((KPrView*)it.current())->updateGuideLineButton();
4547}
4548
4549void KPrDocument::loadGuideLines( const TQDomElement &element )
4550{
4551 // In early versions of KPresenter 1.2 (up to Beta 2), there is child also naed <HELPLINES>
4552 // Before KPresenter 1.5 the guide lines where named helplines that is why they are still
4553 // named like this in the fileformat
4554 TQDomElement guidelines = element.namedItem( "HELPLINES" ).toElement();
4555 if ( guidelines.isNull() )
4556 guidelines = element;
4557
4558 guidelines = guidelines.firstChild().toElement();
4559 while ( !guidelines.isNull() )
4560 {
4561 if ( guidelines.tagName() == "Vertical" )
4562 m_vGuideLines.append( guidelines.attribute( "value" ).toDouble() );
4563 else if ( guidelines.tagName() == "Horizontal" )
4564 m_hGuideLines.append( guidelines.attribute( "value" ).toDouble() );
4565 guidelines = guidelines.nextSibling().toElement();
4566 }
4567}
4568
4569void KPrDocument::saveGuideLines( TQDomDocument &doc, TQDomElement& element )
4570{
4571 for(TQValueList<double>::Iterator it = m_vGuideLines.begin(); it != m_vGuideLines.end(); ++it)
4572 {
4573 TQDomElement lines=doc.createElement("Vertical");
4574 lines.setAttribute("value", (double)*it);
4575 element.appendChild( lines );
4576 }
4577
4578 for(TQValueList<double>::Iterator it = m_hGuideLines.begin(); it != m_hGuideLines.end(); ++it)
4579 {
4580 TQDomElement lines=doc.createElement("Horizontal");
4581 lines.setAttribute("value", *it);
4582 element.appendChild( lines );
4583 }
4584}
4585
4586void KPrDocument::updateGridButton()
4587{
4588 TQPtrListIterator<KoView> it( views() );
4589 for (; it.current(); ++it )
4590 ((KPrView*)it.current())->updateGridButton();
4591
4592}
4593
4594void KPrDocument::setSpellCheckIgnoreList( const TQStringList& lst )
4595{
4596 m_spellCheckIgnoreList = lst;
4597 m_bgSpellCheck->settings()->setCurrentIgnoreList( m_spellCheckIgnoreList + m_spellCheckPersonalDict );
4598 setModified( true );
4599}
4600
4601void KPrDocument::addSpellCheckIgnoreWord( const TQString & word )
4602{
4603 // ### missing: undo/redo support
4604 if( m_spellCheckIgnoreList.findIndex( word ) == -1 )
4605 m_spellCheckIgnoreList.append( word );
4606 setSpellCheckIgnoreList( m_spellCheckIgnoreList );
4607}
4608
4609void KPrDocument::updateObjectStatusBarItem()
4610{
4611 TQPtrListIterator<KoView> it( views() );
4612 for (; it.current(); ++it )
4613 ((KPrView*)it.current())->updateObjectStatusBarItem();
4614}
4615
4616void KPrDocument::updateObjectSelected()
4617{
4618 TQPtrListIterator<KoView> it( views() );
4619 for (; it.current(); ++it )
4620 ((KPrView*)it.current())->objectSelectedChanged();
4621}
4622
4623void KPrDocument::setTabStopValue ( double _tabStop )
4624{
4625 m_tabStop = _tabStop;
4626 TQPtrListIterator<KPrPage> it( m_pageList );
4627 for ( ; it.current(); ++it )
4628 it.current()->changeTabStopValue( m_tabStop );
4629 //styckypage
4630 m_masterPage->changeTabStopValue( m_tabStop );
4631}
4632
4633void KPrDocument::changeBgSpellCheckingState( bool b )
4634{
4635 enableBackgroundSpellCheck( b );
4636 reactivateBgSpellChecking();
4637 TDEConfig *config = KPrFactory::global()->config();
4638 config->setGroup("KSpell kpresenter" );
4639 config->writeEntry( "SpellCheck", (int)b );
4640}
4641
4642
4643bool KPrDocument::cursorInProtectedArea()const
4644{
4645 return m_cursorInProtectectedArea;
4646}
4647
4648void KPrDocument::setCursorInProtectedArea( bool b )
4649{
4650 m_cursorInProtectectedArea=b;
4651 testAndCloseAllTextObjectProtectedContent();
4652}
4653
4654void KPrDocument::testAndCloseAllTextObjectProtectedContent()
4655{
4656 if ( !m_cursorInProtectectedArea )
4657 {
4658 TQPtrListIterator<KoView> it( views() );
4659 for (; it.current(); ++it )
4660 static_cast<KPrView*>(it.current())->testAndCloseAllTextObjectProtectedContent();
4661 }
4662}
4663
4664void KPrDocument::insertFile(const TQString & file )
4665{
4666 m_insertFilePage = m_pageList.count();
4667
4668 m_childCountBeforeInsert = children().count();
4669 objStartY = 0;
4670 bool clean = _clean;
4671 _clean = false;
4672 bool ok = loadNativeFormat(file );
4673 if ( !ok )
4674 {
4675 showLoadingErrorDialog();
4676 return;
4677 }
4678 KMacroCommand *macro = 0L;
4679 for ( int i = m_insertFilePage; i<(int)m_pageList.count();i++)
4680 {
4681 if ( !macro )
4682 macro = new KMacroCommand( i18n("Insert File"));
4683 KPrInsertPageCmd * cmd = new KPrInsertPageCmd( i18n("Insert File"), i - 1, IP_AFTER, m_pageList.at(i), this ) ;
4684 macro->addCommand(cmd );
4685 }
4686 if ( macro )
4687 addCommand( macro );
4688
4689 m_insertFilePage = 0;
4690 m_childCountBeforeInsert = 0;
4691 // Update the views
4692 int newPos = m_pageList.count()-1;
4693 TQPtrListIterator<KoView> it( views() );
4694 for (; it.current(); ++it )
4695 static_cast<KPrView*>(it.current())->updateSideBar();
4696 _clean = clean;
4697 updatePresentationButton();
4698
4699 //activate this page in all views (...)
4700 TQPtrListIterator<KoView>it2( views() );
4701 for (; it2.current(); ++it2 )
4702 static_cast<KPrView*>(it2.current())->skipToPage(newPos);
4703}
4704
4705void KPrDocument::spellCheckParagraphDeleted( KoTextParag * /* _parag */, KPrTextObject * /* frm */ )
4706{
4707 //m_bgSpellCheck->spellCheckParagraphDeleted( _parag, frm->textObject());
4708}
4709
4710void KPrDocument::updateRulerInProtectContentMode()
4711{
4712 TQPtrListIterator<KoView> it( views() );
4713 for (; it.current(); ++it )
4714 static_cast<KPrView*>(it.current())->updateRulerInProtectContentMode();
4715}
4716
4717void KPrDocument::updatePresentationButton()
4718{
4719 TQPtrListIterator<KoView> it( views() );
4720 for (; it.current(); ++it )
4721 static_cast<KPrView*>(it.current())->updatePresentationButton((selectedSlides().count()>0));
4722}
4723
4724void KPrDocument::refreshGroupButton()
4725{
4726 TQPtrListIterator<KoView> it( views() );
4727 for (; it.current(); ++it )
4728 static_cast<KPrView*>(it.current())->refreshGroupButton();
4729}
4730
4731void KPrDocument::addView( KoView *_view )
4732{
4733 KoDocument::addView( _view );
4734 TQPtrListIterator<KoView> it( views() );
4735 for (; it.current(); ++it )
4736 static_cast<KPrView*>(it.current())->closeTextObject();
4737}
4738
4739void KPrDocument::removeView( KoView *_view )
4740{
4741 KoDocument::removeView( _view );
4742 TQPtrListIterator<KoView> it( views() );
4743 for (; it.current(); ++it )
4744 static_cast<KPrView*>(it.current())->deSelectAllObjects();
4745}
4746
4747void KPrDocument::updateStyleListOrder( const TQStringList &list )
4748{
4749 styleCollection()->updateStyleListOrder( list );
4750}
4751
4752void KPrDocument::updateDirectCursorButton()
4753{
4754 TQPtrListIterator<KoView> it( views() );
4755 for (; it.current(); ++it )
4756 static_cast<KPrView*>(it.current())->updateDirectCursorButton();
4757}
4758
4759void KPrDocument::setInsertDirectCursor(bool _b)
4760{
4761 m_bInsertDirectCursor=_b;
4762 TDEConfig *config = KPrFactory::global()->config();
4763 config->setGroup( "Interface" );
4764 config->writeEntry( "InsertDirectCursor", _b );
4765 updateDirectCursorButton();
4766}
4767
4768KPrView *KPrDocument::firstView() const
4769{
4770 if ( views().count()>0)
4771 return static_cast<KPrView*>(views().getFirst());
4772 else
4773 return 0L;
4774}
4775
4776void KPrDocument::addWordToDictionary( const TQString & word)
4777{
4778 if ( m_bgSpellCheck )
4779 {
4780 if( m_spellCheckPersonalDict.findIndex( word ) == -1 )
4781 m_spellCheckPersonalDict.append( word );
4782 m_bgSpellCheck->settings()->setCurrentIgnoreList( m_spellCheckIgnoreList + m_spellCheckPersonalDict );
4783 if ( backgroundSpellCheckEnabled() )
4784 // Re-check everything to make this word normal again
4785 reactivateBgSpellChecking();
4786 }
4787}
4788
4789TQValueList <KPrPage *> KPrDocument::customListPage( const TQStringList & lst, bool loadOasis )
4790{
4791 TQStringList tmp( lst );
4792 TQValueList <KPrPage *> tmpValueList;
4793 for ( TQStringList::Iterator itList = tmp.begin(); itList != tmp.end(); ++itList )
4794 {
4795 for ( int i = 0; i < static_cast<int>( m_pageList.count() ); i++ )
4796 {
4797 //kdDebug()<<" insert page name :"<<*itList<<endl;
4798 if ( loadOasis )
4799 {
4800 if ( m_pageList.at( i )->oasisNamePage(i+1)== ( *itList ) )
4801 {
4802 tmpValueList.append( m_pageList.at( i ) );
4803 //kdDebug()<<" really insert\n";
4804 break;
4805 }
4806 }
4807 else
4808 {
4809 if ( m_pageList.at( i )->pageTitle()== ( *itList ) )
4810 {
4811 tmpValueList.append( m_pageList.at( i ) );
4812 //kdDebug()<<" really insert\n";
4813 break;
4814 }
4815 }
4816
4817 }
4818 }
4819 return tmpValueList;
4820
4821}
4822
4823void KPrDocument::setCustomSlideShows( const CustomSlideShowMap & customSlideShows )
4824{
4825 m_customListSlideShow = customSlideShows;
4826 setModified( true );
4827}
4828
4829TQStringList KPrDocument::presentationList()
4830{
4831 TQStringList lst;
4832 if ( !m_customListSlideShow.isEmpty() )
4833 {
4834 CustomSlideShowMap::Iterator it;
4835 for ( it = m_customListSlideShow.begin(); it != m_customListSlideShow.end(); ++it )
4836 lst << it.key();
4837 }
4838 return lst;
4839}
4840
4841void KPrDocument::testCustomSlideShow( const TQValueList<KPrPage *> &pages, KPrView *view )
4842{
4843 delete m_customListTest;
4844 m_customListTest = new TQValueList<int>( listOfDisplaySelectedSlides( pages ) );
4845 if ( view )
4846 view->screenStartFromFirst();
4847
4848}
4849
4850void KPrDocument::clearTestCustomSlideShow()
4851{
4852 delete m_customListTest;
4853 m_customListTest = 0L;
4854}
4855
4856
4857#include "KPrDocument.moc"
Class KPCanvas - There is a single instance of this class for a given view.
Definition KPrCanvas.h:82
Temporary information used only during loading.