kpresenter

KPrPage.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002-2004 Laurent MONTEL <montel@kde.org>
3 Copyright (C) 2004-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 <kurl.h>
22
23#include "KPrPage.h"
24#include "KPrView.h"
25#include "KPrPageIface.h"
26
27#include "KPrBackground.h"
28#include "KPrLineObject.h"
29#include "KPrRectObject.h"
30#include "KPrEllipseObject.h"
31#include "KPrAutoformObject.h"
32#include "KPrTextObject.h"
33#include "KPrPixmapObject.h"
34#include "KPrPieObject.h"
35#include "KPrPartObject.h"
36#include "KPrGroupObject.h"
37#include "KPrCommand.h"
38#include "KPrFreehandObject.h"
39#include "KPrPolylineObject.h"
40#include "KPrBezierCurveObject.h"
41#include "KPrPolygonObject.h"
42#include "KPrClosedLineObject.h"
43#include "KPrUtils.h"
44#include <kdebug.h>
45#include <KoQueryTrader.h>
46#include "KPrDocument.h"
47
48#include <KoStore.h>
49#include <KoStoreDevice.h>
50#include <KoTextZoomHandler.h>
51#include <KoXmlNS.h>
52#include "KoPointArray.h"
53#include "KPrTextDocument.h"
54#include <KoTextObject.h>
55#include <KoTextParag.h>
56#include <KoRect.h>
57#include <tqapplication.h>
58#include <KoStyleCollection.h>
59#include <KoVariable.h>
60#include <KoGenStyles.h>
61#include <KoXmlWriter.h>
62#include <tdetempfile.h>
63#include <tqbuffer.h>
64#include <tqregexp.h>
65#include <tqfile.h>
66
67struct listAnimation {
68 KPrObject *obj;
69 int objIndex;
70 bool appear;
71};
72
73typedef TQMap<int, TQPtrList<listAnimation> > lstMap;
74
75
76KPrPage::KPrPage(KPrDocument *_doc, KPrPage *masterPage )
77 : m_doc( _doc )
78 , m_masterPage( masterPage )
79 , m_dcop( 0 )
80 , m_selectedSlides( true )
81 , m_bHasHeader( false )
82 , m_bHasFooter( false )
83 , m_useMasterBackground( false )
84 , m_displayObjectFromMasterPage( true )
85 , m_displayBackground( true )
86 , m_pageEffect( PEF_NONE )
87 , m_pageEffectSpeed( ES_MEDIUM )
88 , m_soundEffect( false )
89 , m_soundFileName( TQString() )
90 , m_pageTimer( 1 )
91{
92 kdDebug(33001)<<"create page : KPrPage::KPrPage(KPrDocument *_doc )"<<this<<endl;
93 m_objectList.setAutoDelete( false );
94
95 m_kpbackground= new KPrBackGround( this );
96
97 //don't create dcopobject by default
98 //dcopObject();
99}
100
101KPrPage::~KPrPage()
102{
103 kdDebug(33001)<<"Delete page :KPrPage::~KPrPage() :"<<this<<endl;
104 //delete object list.
105 m_objectList.setAutoDelete( true );
106 m_objectList.clear();
107 delete m_kpbackground;
108 delete m_dcop;
109}
110
111DCOPObject* KPrPage::dcopObject()
112{
113 if ( !m_dcop ) {
114 // 0-based. 1-based would be nicer for the dcop user, but well, docs and views are 0-based,
115 // and the page(int) DCOP call is 0-based.
116 int pgnum = m_doc->pageList().findRef( this );
117 m_dcop = new KPrPageIface( this, pgnum );
118 }
119
120 return m_dcop;
121}
122
123
124void KPrPage::saveOasisObject( KoStore *store, KoXmlWriter &xmlWriter, KoSavingContext& context, int & indexObj, int &partIndexObj, KoXmlWriter* manifestWriter ) const
125{
126 Q_UNUSED( store );
127 Q_UNUSED( manifestWriter );
128 KPrObject::KPOasisSaveContext sc( xmlWriter, context, indexObj, partIndexObj, isMasterPage() );
129
130 KTempFile animationTmpFile;
131 animationTmpFile.setAutoDelete( true );
132 TQFile* tmpFile = animationTmpFile.file();
133 KoXmlWriter animationTmpWriter( tmpFile );
134 lstMap listObjectAnimation;
135 TQPtrListIterator<KPrObject> it( m_objectList );
136 for ( ; it.current() ; ++it )
137 {
138 if ( it.current()== m_doc->header() || it.current()== m_doc->footer())
139 continue;
140 it.current()->saveOasisObject( sc );
141
142 if ( it.current()->hasAnimation() )
143 {
144 if ( it.current()->getEffect() != EF_NONE ||
145 it.current()->getAppearStep() != 0 ||
146 !it.current()->getAppearSoundEffectFileName().isEmpty() )
147 {
148 kdDebug(33001) << "has animation" << endl;
149 listAnimation *lstappear = new listAnimation;
150 lstappear->obj = it.current();
151 lstappear->objIndex = indexObj;
152 lstappear->appear = true;
153 //kdDebug()<<" indexObj :"<<indexObj<<endl;
154 lstMap::Iterator tmp = listObjectAnimation.find( it.current()->getAppearStep() );
155 if ( tmp!= listObjectAnimation.end() )
156 {
157 //kdDebug()<<" group already exist \n";
158 tmp.data().append( lstappear );
159 }
160 else
161 {
162 //kdDebug()<<" create new list \n";
163 TQPtrList<listAnimation> tmp2;
164 tmp2.append( lstappear );
165 listObjectAnimation.insert( it.current()->getAppearStep(), tmp2 );
166 }
167 }
168 if ( it.current()->getDisappear() )
169 {
170 listAnimation *lstappear = new listAnimation;
171 lstappear->obj = it.current();
172 lstappear->objIndex = indexObj;
173 lstappear->appear = false;
174 //kdDebug()<<" indexObj :"<<indexObj<<endl;
175 lstMap::Iterator tmp = listObjectAnimation.find( it.current()->getDisappearStep() );
176 if ( tmp!= listObjectAnimation.end() )
177 {
178 //kdDebug()<<" group already exist \n";
179 tmp.data().append( lstappear );
180 }
181 else
182 {
183 //kdDebug()<<" create new list \n";
184 TQPtrList<listAnimation> tmp2;
185 tmp2.append( lstappear );
186 listObjectAnimation.insert( it.current()->getDisappearStep(), tmp2 );
187 }
188 }
189
190 }
191 ++indexObj;
192 }
193
194 if ( !listObjectAnimation.isEmpty() )
195 {
196 kdDebug()<<"! listObjectAnimation.isEmpty() :"<<listObjectAnimation.count()<<endl;
197 animationTmpWriter.startElement( "presentation:animations" );
198 lstMap::Iterator it = listObjectAnimation.begin();
199 lstMap::Iterator end = listObjectAnimation.end();
200 for (; it != end; ++it )
201 {
202 if ( it.data().count() == 1 )
203 {
204 kdDebug()<<" add unique element \n";
205 if ( it.data().at( 0 )->appear )
206 it.data().at( 0 )->obj->saveOasisObjectStyleShowAnimation( animationTmpWriter, it.data().at( 0 )->objIndex );
207 else
208 it.data().at( 0 )->obj->saveOasisObjectStyleHideAnimation( animationTmpWriter, it.data().at( 0 )->objIndex );
209 }
210 else if ( it.data().count() > 1 )
211 {
212 TQPtrList<listAnimation> list = it.data();
213 animationTmpWriter.startElement( "presentation:animation-group" );
214 for ( uint i = 0; i < list.count(); ++i )
215 {
216 if ( list.at(i) )
217 {
218 kdDebug()<<" add group element : "<<i<<endl;
219 if ( list.at(i)->appear )
220 list.at(i)->obj->saveOasisObjectStyleShowAnimation( animationTmpWriter, list.at(i)->objIndex );
221 else
222 list.at(i)->obj->saveOasisObjectStyleHideAnimation( animationTmpWriter, list.at(i)->objIndex );
223 }
224 }
225 animationTmpWriter.endElement();
226 }
227
228 }
229 animationTmpWriter.endElement();//close "presentation:animations"
230 tmpFile->close();
231 xmlWriter.addCompleteElement( tmpFile );
232
233 }
234 else
235 tmpFile->close();
236 animationTmpFile.close();
237}
238
239void KPrPage::load( const TQDomElement &element )
240{
241 m_kpbackground->load( element );
242 TQDomElement e=element.namedItem("PGEFFECT").toElement();
243 if(!e.isNull()) {
244 int tmp=0;
245 if(e.hasAttribute("value"))
246 tmp=e.attribute("value").toInt();
247 setPageEffect(static_cast<PageEffect>(tmp));
248 tmp = (int)ES_MEDIUM;
249 if(e.hasAttribute("speed"))
250 tmp=e.attribute("speed").toInt();
251 setPageEffectSpeed( static_cast<EffectSpeed>(tmp) );
252 }
253 e=element.namedItem("PGTIMER").toElement();
254 if(!e.isNull()) {
255 int timer = 1;
256 if(e.hasAttribute("timer"))
257 timer=e.attribute("timer").toInt();
258 setPageTimer(timer);
259 }
260 else
261 setPageTimer(1);
262 e=element.namedItem("PGSOUNDEFFECT").toElement();
263 if(!e.isNull()) {
264 if(e.hasAttribute("soundEffect"))
265 m_soundEffect=static_cast<bool>(e.attribute("soundEffect").toInt());
266 else
267 m_soundEffect=false;
268
269 if(e.hasAttribute("soundFileNmae")) // old typo
270 m_soundFileName=e.attribute("soundFileNmae");
271 else
272 m_soundFileName=e.attribute("soundFileName");
273 }
274 else {
275 m_soundFileName=TQString();
276 }
277
278 e=element.namedItem("HEADERFOOTER").toElement();
279 if(!e.isNull()) {
280 if(e.hasAttribute("header"))
281 m_bHasHeader =static_cast<bool>(e.attribute("header").toInt());
282 else
283 m_bHasHeader = false;
284
285 if(e.hasAttribute("footer"))
286 m_bHasFooter =static_cast<bool>(e.attribute("footer").toInt());
287 else
288 m_bHasFooter = false;
289 }
290}
291
292//TODO: implement display/hide background into old file format
293void KPrPage::loadOasis(KoOasisContext & context )
294{
295 m_kpbackground->loadOasis( context );
296
297 KoStyleStack& styleStack = context.styleStack();
298 kdDebug()<<"KPrPage::loadOasis()\n";
299 styleStack.setTypeProperties( "drawing-page" );
300
301 if ( !isMasterPage() )
302 {
303 if ( !styleStack.hasAttributeNS( KoXmlNS::draw, "fill" ) )
304 {
305 // if non is set the fill style of the master slide is used: see OD 14.13.2 Drawing Page Style
306 m_useMasterBackground = true;
307 }
308 //FIXME: fix it in old file format
309 if ( styleStack.hasAttributeNS( KoXmlNS::presentation, "background-objects-visible" ) )
310 {
311 const TQString str = styleStack.attributeNS( KoXmlNS::presentation, "background-objects-visible" );
312 m_displayObjectFromMasterPage = ( str == "true" ) ? true : false;
313 }
314
315 if ( styleStack.hasAttributeNS( KoXmlNS::presentation, "background-visible" ) )
316 {
317 const TQString str = styleStack.attributeNS( KoXmlNS::presentation, "background-visible" );
318 m_displayBackground = ( str == "true" ) ? true : false;
319 }
320
321 if ( styleStack.hasAttributeNS( KoXmlNS::presentation, "visibility" ) )
322 {
323 const TQString str = styleStack.attributeNS( KoXmlNS::presentation, "visibility" );
324 if ( str=="hidden" )
325 slideSelected( false );
326 else
327 kdDebug()<<" presentation:visibility parameter not implemented :"<<str<<endl;
328 }
329
330 if ( styleStack.hasAttributeNS( KoXmlNS::presentation, "transition-speed" ) )
331 {
332 // this argument is not defined into kpresenter_doc and not into kprpage
333 // TODO add it into each page.
334 TQString speed = styleStack.attributeNS( KoXmlNS::presentation, "transition-speed" );
335 if ( speed == "slow" )
336 {
337 m_pageEffectSpeed = ES_SLOW;
338 }
339 else if ( speed == "medium" )
340 {
341 m_pageEffectSpeed = ES_MEDIUM;
342 }
343 else if ( speed == "fast" )
344 {
345 m_pageEffectSpeed = ES_FAST;
346 }
347 else
348 kdDebug()<<" transition-speed not defined :"<<speed<<endl;
349 }
350 if ( styleStack.hasAttributeNS( KoXmlNS::presentation, "duration" ))
351 {
352 m_pageTimer = loadOasisTimer( styleStack.attributeNS( KoXmlNS::presentation, "duration") );
353 }
354 if ( styleStack.hasAttributeNS( KoXmlNS::presentation, "transition-type" ) )
355 {
356 //Not defined into kpresenter
357 //it's global for the moment.
358 kdDebug()<<" presentation:transition-type :"<<styleStack.attributeNS( KoXmlNS::presentation, "transition-type" )<<endl;
359 }
360 if ( styleStack.hasAttributeNS( KoXmlNS::presentation, "display-header" ) )
361 {
362 TQString tmp = styleStack.attributeNS( KoXmlNS::presentation, "display-header" );
363 setHeader( tmp =="true" ? true : false );
364 }
365 if ( styleStack.hasAttributeNS( KoXmlNS::presentation, "display-footer" ) )
366 {
367 TQString tmp = styleStack.attributeNS( KoXmlNS::presentation, "display-footer" );
368 setFooter(tmp =="true" ? true : false);
369 }
370 //TODO presentation:display-date-time; presentation:display-page-number
371 if ( styleStack.hasAttributeNS( KoXmlNS::presentation, "transition-style"))
372 {
373 //kdDebug()<<" have a presentation:transition-style------------\n";
374 const TQString effect = styleStack.attributeNS( KoXmlNS::presentation, "transition-style");
375 TQString additionalEffect;
376 if ( styleStack.hasAttributeNS( KoXmlNS::koffice, "additional-transition-style" ) )
377 {
378 additionalEffect = styleStack.attributeNS( KoXmlNS::koffice, "additional-transition-style" );
379 }
380 kdDebug() << "Transition name: " << effect << "additional name: " << additionalEffect << endl;
381 PageEffect pef;
382 if ( effect=="none" )
383 pef=PEF_NONE;
384 else if (effect=="vertical-stripes" || effect=="vertical-lines") // PEF_BLINDS_VER
385 pef=PEF_BLINDS_VER;
386 else if (effect=="horizontal-stripes" || effect=="horizontal-lines") // PEF_BLINDS_HOR
387 pef=PEF_BLINDS_HOR;
388 else if (effect=="spiralin-left" || effect=="spiralin-right"
389 || effect== "spiralout-left" || effect=="spiralout-right") // PEF_SURROUND1
390 pef=PEF_SURROUND1;
391 else if (effect=="fade-from-top") // PEF_COVER_DOWN
392 pef=PEF_COVER_DOWN;
393 else if (effect=="fade-from-bottom") // PEF_COVER_UP
394 pef=PEF_COVER_UP;
395 else if (effect=="fade-from-left") // PEF_COVER_RIGHT
396 pef=PEF_COVER_RIGHT;
397 else if (effect=="fade-from-right") // PEF_COVER_LEFT
398 pef=PEF_COVER_LEFT;
399 else if (effect=="fade-from-lowerleft")
400 { // PEF_COVER_RIGHT_UP
401 if ( additionalEffect.isEmpty() )
402 pef=PEF_COVER_RIGHT_UP;
403 else
404 pef=PEF_STRIPS_RIGHT_UP;
405 }
406 else if (effect=="fade-from-lowerright")
407 { // PEF_COVER_LEFT_UP
408 if ( additionalEffect.isEmpty() )
409 pef=PEF_COVER_LEFT_UP;
410 else
411 pef=PEF_STRIPS_LEFT_UP;
412 }
413 else if (effect=="fade-from-upperleft")
414 { // PEF_COVER_RIGHT_DOWN
415 if ( additionalEffect.isEmpty() )
416 pef=PEF_COVER_RIGHT_DOWN;
417 else
418 pef=PEF_STRIPS_RIGHT_DOWN;
419 }
420 else if (effect=="fade-from-upperright")
421 { // PEF_COVER_LEFT_DOWN
422 if ( additionalEffect.isEmpty() )
423 pef=PEF_COVER_LEFT_DOWN;
424 else
425 pef=PEF_STRIPS_LEFT_DOWN;
426 }
427 else if (effect=="fade-to-center") // PEF_BOX_IN
428 pef=PEF_BOX_IN;
429 else if (effect=="fade-from-center") // PEF_BOX_OUT
430 pef=PEF_BOX_OUT;
431 else if (effect=="open-vertical") // PEF_OPEN_HORZ; really, no kidding ;)
432 pef=PEF_OPEN_HORZ;
433 else if (effect=="open-horizontal") // PEF_OPEN_VERT
434 pef=PEF_OPEN_VERT;
435 else if (effect=="open") // PEF_OPEN_ALL
436 pef=PEF_OPEN_ALL;
437 else if (effect=="close-vertical") // PEF_CLOSE_HORZ
438 pef=PEF_CLOSE_HORZ;
439 else if (effect=="close-horizontal") // PEF_CLOSE_VERT
440 pef=PEF_CLOSE_VERT;
441 else if (effect=="close") // PEF_CLOSE_ALL
442 pef=PEF_CLOSE_ALL;
443 else if (effect=="dissolve") // PEF_DISSOLVE; perfect hit ;)
444 pef=PEF_DISSOLVE;
445 else if (effect=="horizontal-checkerboard") // PEF_CHECKBOARD_ACROSS
446 pef=PEF_CHECKBOARD_ACROSS;
447 else if (effect=="vertical-checkerboard") // PEF_CHECKBOARD_DOWN
448 pef=PEF_CHECKBOARD_DOWN;
449 else if (effect=="uncover-to-right" || effect=="roll-from-left") // PEF_UNCOVER_RIGHT
450 pef=PEF_UNCOVER_RIGHT;
451 else if (effect=="uncover-to-left" || effect=="roll-from-right") // PEF_UNCOVER_LEFT
452 pef=PEF_UNCOVER_LEFT;
453 else if (effect=="uncover-to-top" || effect=="roll-from-bottom") // PEF_UNCOVER_UP
454 pef=PEF_UNCOVER_UP;
455 else if (effect=="uncover-to-bottom" || effect=="roll-from-top") // PEF_UNCOVER_DOWN
456 pef=PEF_UNCOVER_DOWN;
457 else if (effect=="uncover-to-upperleft") // PEF_UNCOVER_LEFT_UP
458 pef=PEF_UNCOVER_LEFT_UP;
459 else if (effect=="uncover-to-upperright") // PEF_UNCOVER_RIGHT_UP
460 pef=PEF_UNCOVER_RIGHT_UP;
461 else if (effect=="uncover-to-lowerleft") // PEF_UNCOVER_LEFT_DOWN
462 pef=PEF_UNCOVER_LEFT_DOWN;
463 else if (effect=="uncover-to-lowerright") // PEF_UNCOVER_RIGHT_DOWN
464 pef=PEF_UNCOVER_RIGHT_DOWN;
465 else if (effect=="interlocking-horizontal-left")
466 pef=PEF_INTERLOCKING_HORZ_1;
467 else if (effect=="interlocking-horizontal-right")
468 pef=PEF_INTERLOCKING_HORZ_2;
469 else if (effect=="interlocking-vertical-top")
470 pef=PEF_INTERLOCKING_VERT_1;
471 else if (effect=="interlocking-vertical-bottom")
472 pef=PEF_INTERLOCKING_VERT_2;
473 else if ( effect=="melt" )
474 pef=PEF_MELTING;
475 else if ( effect=="fly-away" )
476 pef=PEF_FLY1;
477 else if ( effect=="random" )
478 pef=PEF_RANDOM;
479 else // we choose a random transition instead of the unsupported ones ;)
480 pef=PEF_RANDOM;
481 setPageEffect( pef );
482 }
483 if ( styleStack.hasChildNodeNS( KoXmlNS::presentation, "sound"))
484 {
485 //kdDebug()<<" presentation:sound !!!!!!!!!!!!!!!!!!!!!\n";
486 TQDomElement sound = styleStack.childNodeNS( KoXmlNS::presentation, "sound");
487 m_soundEffect = true;
488 m_soundFileName = sound.attributeNS( KoXmlNS::xlink, "href", TQString() );
489 }
490 }
491}
492
493TQDomElement KPrPage::save( TQDomDocument &doc )
494{
495 TQDomElement page = m_kpbackground->save( doc );
496 TQDomElement element;
497
498 if ( m_pageEffect != PEF_NONE) {
499 element = doc.createElement("PGEFFECT");
500 element.setAttribute("value", static_cast<int>( m_pageEffect ));
501 element.setAttribute("speed", static_cast<int>( m_pageEffectSpeed ));
502 page.appendChild(element);
503 }
504
505 if ( m_pageTimer != 1 ) {
506 element = doc.createElement( "PGTIMER" );
507 element.setAttribute( "timer", m_pageTimer );
508 page.appendChild( element );
509 }
510
511 if ( m_soundEffect || !m_soundFileName.isEmpty() ) {
512 element = doc.createElement( "PGSOUNDEFFECT" );
513 element.setAttribute( "soundEffect", static_cast<int>(m_soundEffect) );
514 element.setAttribute( "soundFileName", m_soundFileName );
515 page.appendChild( element );
516 }
517 element = doc.createElement( "HEADERFOOTER" );
518 element.setAttribute( "header", static_cast<int>(m_bHasHeader ) );
519 element.setAttribute( "footer", static_cast<int>(m_bHasFooter ) );
520 page.appendChild( element );
521 return page;
522}
523
524TQString KPrPage::oasisNamePage( int posPage ) const
525{
526 return ( m_manualTitle.isEmpty() ? TQString( "page%1" ).arg( posPage ) : m_manualTitle );
527}
528
529bool KPrPage::saveOasisPage( KoStore *store, KoXmlWriter &xmlWriter, int posPage, KoSavingContext& context,
530 int & indexObj, int &partIndexObj, KoXmlWriter* manifestWriter, TQMap<TQString, int> &pageNames ) const
531{
532 if ( isMasterPage() )
533 {
534 KoGenStyle pageLayout = m_doc->pageLayout().saveOasis();
535 pageLayout.addAttribute( "style:page-usage", "all" ); // needed?
536 TQString pageLayoutName( context.mainStyles().lookup( pageLayout, "pm" ) );
537
538 xmlWriter.startElement( "style:master-page" );
539 xmlWriter.addAttribute( "style:name", "Standard" );
540 xmlWriter.addAttribute( "style:page-layout-name", pageLayoutName );
541
542 TQString styleName = saveOasisPageStyle( store, context.mainStyles() );
543 if ( !styleName.isEmpty() )
544 xmlWriter.addAttribute( "draw:style-name", styleName );
545
546 saveOasisObject( store, xmlWriter, context, indexObj,partIndexObj, manifestWriter );
547
548 xmlWriter.startElement( "style:header" );
549 m_doc->header()->textObject()->saveOasisContent( xmlWriter, context );
550 xmlWriter.endElement();
551
552 xmlWriter.startElement( "style:footer" );
553 m_doc->footer()->textObject()->saveOasisContent( xmlWriter, context );
554 xmlWriter.endElement();
555
556 xmlWriter.endElement();
557 }
558 else
559 {
560 //store use to save picture and co
561 xmlWriter.startElement( "draw:page" );
562
563 TQString drawName( m_manualTitle );
564 TQRegExp rx( "^page[0-9]+$" );
565 if ( drawName.isEmpty() || pageNames.contains( drawName ) || rx.search( drawName ) != -1 )
566 {
567 drawName = "page" + TQString::number( posPage );
568 }
569 pageNames.insert( drawName, posPage );
570 xmlWriter.addAttribute( "draw:name", drawName ); //we must store a name
571 xmlWriter.addAttribute( "koffice:name", m_manualTitle ); // so that we can have the same name for different pages
572 xmlWriter.addAttribute( "draw:id", "page" + TQString::number( posPage ) );
573 xmlWriter.addAttribute( "draw:master-page-name", "Standard"); //by default name of page is Standard
574
575 TQString styleName = saveOasisPageStyle( store, context.mainStyles() );
576 kdDebug()<<" styleName :"<<styleName<<endl;
577 if ( !styleName.isEmpty() )
578 xmlWriter.addAttribute( "draw:style-name", styleName );
579
580 saveOasisObject( store, xmlWriter, context, indexObj,partIndexObj, manifestWriter );
581
582 saveOasisNote( xmlWriter );
583 xmlWriter.endElement();
584 }
585 return true;
586}
587
588TQString KPrPage::saveOasisPageStyle( KoStore *, KoGenStyles& mainStyles ) const
589{
590 KoGenStyle stylepageauto( isMasterPage() ? KPrDocument::STYLE_BACKGROUNDPAGE : KPrDocument::STYLE_BACKGROUNDPAGEAUTO, "drawing-page" );
591
592 if ( ! isMasterPage() )
593 {
594 stylepageauto.addProperty( "presentation:background-visible", ( m_displayBackground == true ) ? "true" : "false" );
595 stylepageauto.addProperty( "presentation:background-objects-visible", ( m_displayObjectFromMasterPage == true ) ? "true" : "false" );
596 TQString transition = saveOasisPageEffect();
597 if ( !transition.isEmpty() )
598 {
599 stylepageauto.addProperty( "presentation:transition-style", transition );
600 TQString additionalTransition = saveOasisAdditionalPageEffect();
601 if ( !additionalTransition.isEmpty() )
602 {
603 stylepageauto.addProperty( "koffice:additional-transition-style", additionalTransition );
604 }
605 }
606 stylepageauto.addProperty( "presentation:display-header", hasHeader());
607 stylepageauto.addProperty( "presentation:display-footer", hasFooter());
608
609 if ( m_pageTimer != 1 )
610 {
611 stylepageauto.addProperty("presentation:duration", saveOasisTimer( m_pageTimer ));
612 //not used into kpresenter but necessary into ooimpress
613 //keep compatible
614 stylepageauto.addProperty( "presentation:transition-type", "automatic" );
615 }
616 if ( m_pageEffectSpeed != ES_MEDIUM ) // we don't save the default value
617 {
618 if ( m_pageEffectSpeed == ES_FAST )
619 stylepageauto.addProperty( "presentation:transition-speed", "fast" );
620 else if ( m_pageEffectSpeed == ES_SLOW )
621 stylepageauto.addProperty( "presentation:transition-speed", "slow" );
622 }
623 if ( !isSlideSelected() )
624 stylepageauto.addProperty( "presentation:visibility", "hidden" );
625 if ( !m_soundFileName.isEmpty() && m_soundEffect )
626 {
627 TQBuffer buffer;
628 buffer.open( IO_WriteOnly );
629 KoXmlWriter elementWriter( &buffer ); // TODO pass indentation level
630 elementWriter.startElement( "presentation:sound" );
631 elementWriter.addAttribute( "xlink:href", m_soundFileName );
632 elementWriter.addAttribute( "xlink:type", "simple" );
633 elementWriter.addAttribute( "xlink:show", "new" );
634 elementWriter.addAttribute( "xlink:actuate", "onRequest");
635
636 elementWriter.endElement();
637 TQString elementContents = TQString::fromUtf8( buffer.buffer(), buffer.buffer().size() );
638 stylepageauto.addChildElement( "sound effect", elementContents );
639 }
640 }
641
642 if ( ! m_useMasterBackground )
643 {
644 m_kpbackground->saveOasisBackgroundPageStyle( stylepageauto, mainStyles );
645 }
646
647 // todo return mainStyles.lookup( stylepageauto, "dp", isMasterPage() ? KoGenStyles::AutoStyleInStylesDotXml : KoGenStyles::NoFlag );
648 return mainStyles.lookup( stylepageauto, "dp" );
649}
650
651bool KPrPage::saveOasisNote( KoXmlWriter &xmlWriter ) const
652{
653 if ( m_noteText.isEmpty() )
654 return true;
655
656 //todo : add size for draw:text-box otherwise we can't import into oo
657 //<draw:text-box presentation:style-name="pr1" draw:text-style-name="P1" draw:layer="layout" svg:width="14.5cm" svg:height="11.408cm" svg:x="3.247cm" svg:y="14.126cm" presentation:class="notes">
658 xmlWriter.startElement( "presentation:notes" );
659 xmlWriter.startElement( "draw:frame" );
660 //todo save style
661
662 xmlWriter.startElement( "draw:text-box" );
663 TQStringList text = TQStringList::split( "\n", m_noteText );
664 for ( TQStringList::Iterator it = text.begin(); it != text.end(); ++it ) {
665 xmlWriter.startElement( "text:p" );
666 xmlWriter.addTextNode( *it );
667 xmlWriter.endElement();
668 }
669 xmlWriter.endElement();
670 xmlWriter.endElement();
671 xmlWriter.endElement();
672
673 return true;
674}
675
676TQString KPrPage::saveOasisPageEffect() const
677{
678 TQString transition;
679 switch( m_pageEffect )
680 {
681 case PEF_NONE:
682 transition="none";
683 break;
684 case PEF_CLOSE_HORZ:
685 transition="close-vertical";
686 break;
687 case PEF_CLOSE_VERT:
688 transition="close-horizontal";
689 break;
690 case PEF_CLOSE_ALL:
691 transition="close";
692 break;
693 case PEF_OPEN_HORZ:
694 transition="open-vertical";
695 break;
696 case PEF_OPEN_VERT:
697 transition="open-horizontal";
698 break;
699 case PEF_OPEN_ALL:
700 transition="open";
701 break;
702 case PEF_INTERLOCKING_HORZ_1:
703 transition="interlocking-horizontal-left";
704 break;
705 case PEF_INTERLOCKING_HORZ_2:
706 transition="interlocking-horizontal-right";
707 break;
708 case PEF_INTERLOCKING_VERT_1:
709 transition="interlocking-vertical-top";
710 break;
711 case PEF_INTERLOCKING_VERT_2:
712 transition="interlocking-vertical-bottom";
713 break;
714 case PEF_SURROUND1:
715 transition="spiralin-left";
716 break;
717 case PEF_FLY1:
718 transition="fly-away";
719 break;
720 case PEF_BLINDS_HOR:
721 transition="horizontal-stripes";
722 break;
723 case PEF_BLINDS_VER:
724 transition="vertical-stripes";
725 break;
726 case PEF_BOX_IN:
727 transition="fade-to-center";
728 break;
729 case PEF_BOX_OUT:
730 transition="fade-from-center";
731 break;
732 case PEF_CHECKBOARD_ACROSS:
733 transition="horizontal-checkerboard";
734 break;
735 case PEF_CHECKBOARD_DOWN:
736 transition="vertical-checkerboard";
737 break;
738 case PEF_COVER_DOWN:
739 transition="fade-from-top";
740 break;
741 case PEF_COVER_UP:
742 transition="fade-from-bottom";
743 break;
744 case PEF_COVER_LEFT:
745 transition="fade-from-right";
746 break;
747 case PEF_COVER_RIGHT:
748 transition="fade-from-left";
749 break;
750 case PEF_COVER_LEFT_UP:
751 transition="fade-from-lowerright";
752 break;
753 case PEF_COVER_LEFT_DOWN:
754 transition="fade-from-upperright";
755 break;
756 case PEF_COVER_RIGHT_UP:
757 transition="fade-from-lowerleft";
758 break;
759 case PEF_COVER_RIGHT_DOWN:
760 transition="fade-from-upperleft";
761 break;
762 case PEF_UNCOVER_LEFT:
763 transition="uncover-to-left";
764 break;
765 case PEF_UNCOVER_UP:
766 transition="uncover-to-top";
767 break;
768 case PEF_UNCOVER_RIGHT:
769 transition="uncover-to-right";
770 break;
771 case PEF_UNCOVER_DOWN:
772 transition="uncover-to-bottom";
773 break;
774 case PEF_UNCOVER_LEFT_UP:
775 transition="uncover-to-upperleft";
776 break;
777 case PEF_UNCOVER_LEFT_DOWN:
778 transition="uncover-to-lowerleft";
779 break;
780 case PEF_UNCOVER_RIGHT_UP:
781 transition="uncover-to-upperright";
782 break;
783 case PEF_UNCOVER_RIGHT_DOWN:
784 transition="uncover-to-lowerright";
785 break;
786 case PEF_DISSOLVE:
787 transition="dissolve";
788 break;
789 case PEF_STRIPS_LEFT_UP:
790 transition="fade-from-lowerright";
791 break;
792 case PEF_STRIPS_LEFT_DOWN:
793 transition="fade-from-upperright";
794 break;
795 case PEF_STRIPS_RIGHT_UP:
796 transition="fade-from-lowerleft";
797 break;
798 case PEF_STRIPS_RIGHT_DOWN:
799 transition="fade-from-upperleft";
800 break;
801 case PEF_MELTING:
802 transition="melt";
803 break;
804 case PEF_LAST_MARKER://don't use it !!!
805 break;
806 case PEF_RANDOM:
807 transition="random";
808 break;
809
810 }
811 return transition;
812}
813
814
815TQString KPrPage::saveOasisAdditionalPageEffect() const
816{
817 TQString additionalEffect;
818 switch( m_pageEffect )
819 {
820 case PEF_STRIPS_LEFT_UP:
821 additionalEffect="stripe-from-lowerright";
822 break;
823 case PEF_STRIPS_LEFT_DOWN:
824 additionalEffect="stripe-from-upperright";
825 break;
826 case PEF_STRIPS_RIGHT_UP:
827 additionalEffect="stripe-from-lowerleft";
828 break;
829 case PEF_STRIPS_RIGHT_DOWN:
830 additionalEffect="stripe-from-upperleft";
831 break;
832 default:
833 break;
834 }
835 return additionalEffect;
836}
837
838
839KPrObject *KPrPage::getObject(int num)
840{
841 Q_ASSERT( num < (int)m_objectList.count() );
842 return m_objectList.at(num);
843}
844
845/*
846 * Check if object name already exists.
847 */
848bool KPrPage::objectNameExists( KPrObject *object, TQPtrList<KPrObject> &list ) {
849 TQPtrListIterator<KPrObject> it( list );
850
851 for ( it.toFirst(); it.current(); ++it ) {
852 // object name can exist in current object.
853 if ( it.current()->getObjectName() == object->getObjectName() &&
854 it.current() != object ) {
855 return true;
856 }
857 else if ( it.current()->getType() == OT_GROUP ) {
858 TQPtrList<KPrObject> objectList( static_cast<KPrGroupObject*>(it.current())->getObjects() );
859 if ( objectNameExists( object, objectList ) ) {
860 return true;
861 }
862 }
863 }
864 return false;
865}
866
867void KPrPage::unifyObjectName( KPrObject *object ) {
868 if ( object->getObjectName().isEmpty() ) {
869 object->setObjectName( object->getTypeString() );
870 }
871 TQString objectName( object->getObjectName() );
872
873 TQPtrList<KPrObject> list( m_objectList );
874
875 int count = 1;
876
877 while ( objectNameExists( object, list ) ) {
878 count++;
879 TQRegExp rx( " \\(\\d{1,}\\)$" );
880 if ( rx.search( objectName ) != -1 ) {
881 objectName.remove( rx );
882 }
883 objectName += TQString(" (%1)").arg( count );
884 object->setObjectName( objectName );
885 }
886}
887
888void KPrPage::appendObject(KPrObject *_obj)
889{
890 unifyObjectName(_obj);
891 m_objectList.append(_obj);
892}
893
894void KPrPage::appendObjects( const TQValueList<KPrObject *> &objects )
895{
896 TQMap <TQString, int> usedPageNames;
897 TQPtrListIterator<KPrObject> it( m_objectList );
898 // find the biggest number
899 for ( ; it.current() ; ++it )
900 {
901 TQString objectName( it.current()->getObjectName() );
902
903 TQRegExp rx( "(.*) \\((\\d{1,})\\)$" );
904 rx.setMinimal( true );
905 if ( rx.search( objectName ) != -1 && rx.numCaptures() == 2 )
906 {
907 int id = rx.cap( 2 ).toInt();
908 if ( usedPageNames[rx.cap( 1 )] < id )
909 {
910 usedPageNames[rx.cap( 1 )] = id;
911 }
912 }
913 else
914 {
915 usedPageNames[objectName] = 1;
916 }
917 }
918
919 TQValueListConstIterator<KPrObject *> oIt( objects.begin() );
920 for ( ; oIt != objects.end(); ++oIt )
921 {
922 TQString objectName( ( *oIt )->getObjectName() );
923 TQRegExp rx( " \\(\\d{1,}\\)$" );
924 if ( rx.search( objectName ) != -1 )
925 {
926 objectName.remove( rx );
927 }
928
929 if ( usedPageNames.contains( objectName ) )
930 {
931 usedPageNames[objectName]++;
932 objectName += TQString(" (%1)").arg( usedPageNames[objectName] );
933 ( *oIt )->setObjectName( objectName );
934 }
935 m_objectList.append( *oIt );
936 }
937}
938
939int KPrPage::takeObject( KPrObject *object )
940{
941 int pos = m_objectList.findRef( object );
942 m_objectList.take( pos );
943 return pos;
944}
945
946void KPrPage::replaceObject( KPrObject *oldObject, KPrObject *newObject )
947{
948 //XXX check if object name gets set
949 unsigned int pos = m_objectList.findRef( oldObject );
950 m_objectList.take( pos );
951 m_objectList.insert( pos, newObject );
952}
953
954
955void KPrPage::insertObject( KPrObject *object, int pos )
956{
957 unifyObjectName( object );
958 m_objectList.insert( pos, object );
959}
960
961KCommand * KPrPage::deleteSelectedObjects()
962{
963 TQPtrList<KPrObject> objects = getSelectedObjects( true );
964
965 KPrDeleteCmd *deleteCmd=0L;
966
967 if ( objects.count() > 0 ) {
968 deleteCmd = new KPrDeleteCmd( i18n( "Delete Objects" ), objects, m_doc, this );
969 deleteCmd->execute();
970 }
971 else
972 m_doc->setModified(true);
973
974 return deleteCmd ;
975}
976
977void KPrPage::copyObjs(TQDomDocument &doc, TQDomElement &presenter, TQValueList<KoPictureKey> & savePictures) const
978{
979 if ( !numSelected() )
980 return;
981
982 TQPtrListIterator<KPrObject> it( m_objectList );
983 for ( ; it.current() ; ++it )
984 {
985 if(it.current()->isSelected())
986 {
987 if ( it.current()->getType() == OT_PICTURE )
988 {
989 KoPictureKey key = static_cast<KPrPixmapObject *>( it.current() )->getKey();
990 if ( !savePictures.contains( key ) )
991 savePictures.append( key );
992 }
993 TQDomElement object=doc.createElement("OBJECT");
994 object.setAttribute("type", static_cast<int>( it.current()->getType() ));
995 object.appendChild(it.current()->save( doc,0 ));
996 presenter.appendChild(object);
997 }
998 }
999}
1000
1001void KPrPage::pasteObjs( const TQByteArray & data,int nbCopy, double angle,
1002 double increaseX, double increaseY, double moveX, double moveY )
1003{
1004 m_doc->deSelectAllObj();
1005 int num = m_objectList.count();
1006 if ( !data.size() )
1007 return;
1008 TQBuffer buffer( data );
1009 KoStore* store = KoStore::createStore( &buffer, KoStore::Read );
1010 int nbNewObject = -1 ;
1011 KMacroCommand *macro = 0L;
1012 if ( !store->bad() )
1013 {
1014 if ( store->open( "root" ) )
1015 {
1016 TQString errorMsg;
1017 int errorLine;
1018 int errorColumn;
1019 TQDomDocument domDoc;
1020 if ( !domDoc.setContent( store->device(), &errorMsg, &errorLine, &errorColumn ) )
1021 {
1022 kdError (30003) << "Parsing Error! Aborting! (in KPrPage::PasteObj)" << endl
1023 << " Line: " << errorLine << " Column: " << errorColumn << endl
1024 << " Message: " << errorMsg << endl;
1025 delete store;
1026 return;
1027 }
1028 TQDomElement topElem = domDoc.documentElement();
1029
1030 for ( int i = 0 ; i < nbCopy ; i++ )
1031 {
1032 KCommand *cmd = m_doc->loadPastedObjs( domDoc.toString(),this );
1033 if (cmd )
1034 {
1035 if ( !macro )
1036 macro = new KMacroCommand( i18n("Paste Objects" ));
1037 macro->addCommand( cmd );
1038 }
1039 if ( nbNewObject == -1 )
1040 nbNewObject = m_objectList.count() - num;
1041 }
1042
1043 m_doc->loadPictureMap( topElem );
1044 store->close();
1045 int nbNewPartObject = -1;
1046 int nbElementBefore = m_objectList.count();
1047 for ( int i = 0 ; i < nbCopy ; i++ )
1048 {
1049 m_doc->insertEmbedded( store, topElem, macro, this, num );
1050 if ( nbNewPartObject ==-1 )
1051 nbNewObject = nbNewObject + (m_objectList.count() - nbElementBefore);
1052 }
1053 }
1054 }
1055 delete store;
1056
1057 //move and select all new pasted in objects
1058 KPrObject *_tempObj;
1059 int i = 0;
1060 int mod = 1;
1061 for (_tempObj = m_objectList.at(num); _tempObj; _tempObj = m_objectList.next(), i++ ) {
1062 if ( i >= nbNewObject )
1063 mod++;
1064 _tempObj->moveBy( moveX*(double)mod,moveY*(double)mod);
1065 _tempObj->setSelected( true );
1066 if ( angle == 0.0 || (increaseY == 0.0 && increaseX == 0.0))
1067 m_doc->repaint(_tempObj);
1068 }
1069
1070 if ( angle != 0.0)
1071 {
1072 KCommand *cmd = rotateSelectedObjects(angle, true);
1073 if (cmd )
1074 {
1075 if ( !macro )
1076 macro = new KMacroCommand( i18n("Paste Objects" ));
1077 macro->addCommand( cmd );
1078 }
1079 }
1080 if ( increaseX != 0.0 || increaseY != 0.0 )
1081 {
1082 TQPtrListIterator<KPrObject> it( m_objectList );
1083 for ( ; it.current() ; ++it )
1084 {
1085 if(it.current()->isSelected())
1086 {
1087 KCommand *cmd =new KPrResizeCmd( i18n("Resize"), KoPoint(0, 0),
1088 KoSize(increaseX, increaseY), it.current(), m_doc );
1089 if ( cmd )
1090 {
1091 cmd->execute();
1092 if ( !macro )
1093 macro = new KMacroCommand( i18n("Paste Objects" ));
1094 macro->addCommand( cmd );
1095 }
1096 }
1097 }
1098 }
1099
1100 if (macro)
1101 m_doc->addCommand(macro);
1102 //update sidebar
1103 if ( angle == 0.0 || (increaseY == 0.0 && increaseX == 0.0) )
1104 {
1105 m_doc->updateSideBarItem( this );
1106 }
1107
1108 m_doc->setModified(true);
1109}
1110
1111KPrTextObject * KPrPage::textFrameSet ( unsigned int _num ) const
1112{
1113 unsigned int i = 0;
1114 TQPtrListIterator<KPrObject> it( m_objectList );
1115 for ( ; it.current() ; ++it )
1116 {
1117 if(it.current()->getType()==OT_TEXT)
1118 {
1119 if(i==_num)
1120 return static_cast<KPrTextObject*>(it.current());
1121 i++;
1122 }
1123 }
1124 return 0L;
1125}
1126
1127int KPrPage::numSelected() const
1128{
1129 int num = 0;
1130
1131 TQPtrListIterator<KPrObject> it( m_objectList );
1132 for ( ; it.current() ; ++it )
1133 {
1134 if(it.current()->isSelected())
1135 num++;
1136 }
1137
1138 return num;
1139}
1140
1141int KPrPage::numTextObject() const
1142{
1143 int num = 0;
1144
1145 TQPtrListIterator<KPrObject> it( m_objectList );
1146 for ( ; it.current() ; ++it )
1147 {
1148 if(it.current()->getType()==OT_TEXT)
1149 num++;
1150 }
1151
1152 return num;
1153}
1154
1155KPrObject* KPrPage::getSelectedObj() const
1156{
1157 TQPtrListIterator<KPrObject> it( m_objectList );
1158 for ( ; it.current() ; ++it )
1159 {
1160 if(it.current()->isSelected())
1161 return it.current();
1162 }
1163 return 0L;
1164}
1165
1166
1167TQPtrList<KPrObject> KPrPage::getSelectedObjects( bool withoutHeaderFooter ) const
1168{
1169 TQPtrList<KPrObject> objects;
1170 TQPtrListIterator<KPrObject> it( m_objectList );
1171 for ( ; it.current() ; ++it )
1172 {
1173 if( it.current()->isSelected()
1174 && ( !withoutHeaderFooter
1175 || it.current() != m_doc->header() && it.current()!= m_doc->footer() ) )
1176 {
1177 objects.append( it.current() );
1178 }
1179 }
1180 return objects;
1181}
1182
1183
1184void KPrPage::groupObjects()
1185{
1186 TQPtrList<KPrObject> objects( getSelectedObjects( true ) );
1187
1188 if ( objects.count() > 1 ) {
1189 KPrGroupObjCmd *groupObjCmd = new KPrGroupObjCmd( i18n( "Group Objects" ), objects, m_doc,this );
1190 m_doc->addCommand( groupObjCmd );
1191 groupObjCmd->execute();
1192 }
1193}
1194
1195void KPrPage::ungroupObjects( KMacroCommand ** macro )
1196{
1197 TQPtrList<KPrObject> objects( getSelectedObjects( true ) );
1198 TQPtrListIterator<KPrObject> it( objects );
1199 for ( ; it.current() ; ++it )
1200 {
1201 KPrObject *object = it.current();
1202 if ( object->getType() == OT_GROUP )
1203 {
1204 UnGroupObjCmd *cmd = new UnGroupObjCmd( i18n( "Ungroup Objects" ),
1205 (KPrGroupObject*)object, m_doc, this );
1206 cmd->execute();
1207
1208 if ( !*macro )
1209 *macro = new KMacroCommand(i18n( "Ungroup Objects" ));
1210 (*macro)->addCommand( cmd );
1211 }
1212 }
1213}
1214
1215void KPrPage::lowerObjs(bool backward)
1216{
1217 KPrObject *kpobject = 0;
1218
1219 TQPtrList<KPrObject> _new;
1220
1221 for ( unsigned int j = 0; j < m_objectList.count(); j++ )
1222 _new.append( m_objectList.at( j ) );
1223
1224 _new.setAutoDelete( false );
1225 bool createCmd = false;
1226 int insertPos = 0;
1227 for ( int i = 0; i < static_cast<int>( _new.count() ); i++ ) {
1228 kpobject = _new.at( i );
1229 if ( kpobject->isSelected() ) {
1230 if ( i == insertPos )
1231 {
1232 ++insertPos;
1233 continue;
1234 }
1235 createCmd = true;
1236 _new.take( i );
1237 if ( backward )
1238 _new.insert(TQMAX(i-1,0) , kpobject);
1239 else
1240 _new.insert( insertPos++, kpobject );
1241 }
1242 }
1243 if ( createCmd )
1244 {
1245 KPrLowerRaiseCmd *lrCmd = new KPrLowerRaiseCmd( i18n( "Lower Objects" ), m_objectList, _new, m_doc,this );
1246 lrCmd->execute();
1247 m_doc->addCommand( lrCmd );
1248 }
1249
1250}
1251
1252void KPrPage::raiseObjs(bool forward)
1253{
1254 KPrObject *kpobject = 0;
1255
1256 TQPtrList<KPrObject> _new;
1257
1258 for ( unsigned int j = 0; j < m_objectList.count(); j++ )
1259 _new.append( m_objectList.at( j ) );
1260
1261 _new.setAutoDelete( false );
1262 bool createCmd = false;
1263 int size = int( _new.count() );
1264 int insertPos = size - 1;
1265 for ( int i = size - 1; i >= 0; i-- )
1266 {
1267 kpobject = _new.at( i );
1268 if ( kpobject->isSelected() )
1269 {
1270 if ( i == insertPos )
1271 {
1272 --insertPos;
1273 continue;
1274 }
1275 createCmd = true;
1276 _new.take( i );
1277 if ( forward )
1278 _new.insert( TQMIN( i+1, size - 1), kpobject);
1279 else
1280 _new.insert( insertPos--, kpobject );
1281 }
1282 }
1283 if ( createCmd )
1284 {
1285 KPrLowerRaiseCmd *lrCmd = new KPrLowerRaiseCmd( i18n( "Raise Objects" ), m_objectList, _new, m_doc,this );
1286 lrCmd->execute();
1287 m_doc->addCommand( lrCmd );
1288 }
1289}
1290
1291KCommand *KPrPage::insertObject( const TQString &name, KPrObject * object, const KoRect &r, bool addCommand )
1292{
1293 object->setOrig( r.x(), r.y() );
1294 object->setSize( r.width(), r.height() );
1295 object->setSelected( true );
1296
1297 KPrInsertCmd *insertCmd = new KPrInsertCmd( name, object, m_doc, this );
1298 insertCmd->execute();
1299 if ( addCommand )
1300 {
1301 m_doc->addCommand( insertCmd );
1302 return 0L;
1303 }
1304 return insertCmd;
1305}
1306
1307void KPrPage::insertLine( const KoRect &r, const KoPen & pen, LineEnd lb, LineEnd le, LineType lt )
1308{
1309 KPrLineObject *kplineobject = new KPrLineObject( pen, lb, le, lt );
1310 insertObject( i18n( "Insert Line" ), kplineobject, r );
1311}
1312
1313void KPrPage::insertRectangle( const KoRect &r, const KoPen & pen, const TQBrush &brush, FillType ft,
1314 const TQColor &g1, const TQColor &g2,
1315 BCType gt, int rndX, int rndY, bool unbalanced, int xfactor, int yfactor )
1316{
1317 KPrRectObject *kprectobject = new KPrRectObject( pen, brush, ft, g1, g2, gt, rndX, rndY,
1318 unbalanced, xfactor, yfactor );
1319 insertObject( i18n( "Insert Rectangle" ), kprectobject, r );
1320}
1321
1322void KPrPage::insertCircleOrEllipse( const KoRect &r, const KoPen &pen, const TQBrush & brush, FillType ft,
1323 const TQColor &g1, const TQColor &g2,
1324 BCType gt, bool unbalanced, int xfactor, int yfactor )
1325{
1326 KPrEllipseObject *kpellipseobject = new KPrEllipseObject( pen, brush, ft, g1, g2, gt,
1327 unbalanced, xfactor, yfactor );
1328 insertObject( i18n( "Insert Ellipse" ), kpellipseobject, r );
1329}
1330
1331void KPrPage::insertPie( const KoRect &r, const KoPen &pen, const TQBrush &brush, FillType ft,
1332 const TQColor &g1, const TQColor &g2,
1333 BCType gt, PieType pt, int _angle, int _len, LineEnd lb, LineEnd le,
1334 bool unbalanced, int xfactor, int yfactor )
1335{
1336 KPrPieObject *kppieobject = new KPrPieObject( pen, brush, ft, g1, g2, gt, pt, _angle,
1337 _len, lb, le, unbalanced, xfactor, yfactor );
1338 insertObject( i18n( "Insert Pie/Arc/Chord" ), kppieobject, r );
1339}
1340
1341KPrTextObject* KPrPage::insertTextObject( const KoRect& r, const TQString& text , KPrView * _view )
1342{
1343 KPrTextObject *kptextobject = new KPrTextObject( m_doc );
1344 insertObject( i18n( "Insert Textbox" ), kptextobject, r );
1345 //TODO create macro command : now insertObject can return KCommand
1346 //TODO fix repaint object
1347 if ( !text.isEmpty() )
1348 {
1349 KPrTextView *view = kptextobject->createKPTextView( _view ? _view->getCanvas() : 0L );
1350 view->insertText( text );
1351 view->terminate();
1352 delete view;
1353 m_doc->repaint( kptextobject );
1354 }
1355 return kptextobject;
1356}
1357
1358void KPrPage::insertAutoform( const KoRect &r, const KoPen &pen, const TQBrush &brush, LineEnd lb, LineEnd le, FillType ft,
1359 const TQColor &g1, const TQColor &g2, BCType gt, const TQString &fileName, bool unbalanced,
1360 int xfactor, int yfactor ){
1361 KPrAutoformObject *kpautoformobject = new KPrAutoformObject( pen, brush, fileName, lb, le, ft,
1362 g1, g2, gt, unbalanced, xfactor, yfactor );
1363 insertObject( i18n( "Insert Autoform" ), kpautoformobject, r );
1364}
1365
1366void KPrPage::insertFreehand( const KoPointArray &points, const KoRect &r, const KoPen &pen,
1367 LineEnd lb, LineEnd le )
1368{
1369 KoSize size( r.width(), r.height() );
1370 KPrFreehandObject *kpfreehandobject = new KPrFreehandObject( points, size, pen, lb, le );
1371 insertObject( i18n( "Insert Freehand" ), kpfreehandobject, r );
1372}
1373
1374void KPrPage::insertPolyline( const KoPointArray &points, const KoRect &r, const KoPen &pen,
1375 LineEnd lb, LineEnd le )
1376{
1377 KoSize size( r.width(), r.height() );
1378 KPrPolylineObject *kppolylineobject = new KPrPolylineObject( points, size, pen, lb, le );
1379 insertObject( i18n( "Insert Polyline" ), kppolylineobject, r );
1380}
1381
1382void KPrPage::insertQuadricBezierCurve( const KoPointArray &points, const KoPointArray &allPoints,
1383 const KoRect &r, const KoPen &pen,
1384 LineEnd lb, LineEnd le )
1385{
1386 KoSize size( r.width(), r.height() );
1387
1388 KPrQuadricBezierCurveObject *kpQuadricBezierCurveObject = new KPrQuadricBezierCurveObject(
1389 points, allPoints, size, pen, lb, le );
1390 insertObject( i18n( "Insert Quadric Bezier Curve" ), kpQuadricBezierCurveObject, r );
1391}
1392
1393void KPrPage::insertCubicBezierCurve( const KoPointArray &points, const KoPointArray &allPoints,
1394 const KoRect &r, const KoPen &pen,
1395 LineEnd lb, LineEnd le )
1396{
1397 KoSize size( r.width(), r.height() );
1398
1399 KPrCubicBezierCurveObject *kpCubicBezierCurveObject = new KPrCubicBezierCurveObject( points, allPoints, size, pen, lb, le );
1400 insertObject( i18n( "Insert Cubic Bezier Curve" ), kpCubicBezierCurveObject, r );
1401}
1402
1403void KPrPage::insertPolygon( const KoPointArray &points, const KoRect &r, const KoPen &pen, const TQBrush &brush, FillType ft,
1404 const TQColor &g1, const TQColor &g2, BCType gt, bool unbalanced, int xfactor, int yfactor,
1405 bool _checkConcavePolygon, int _cornersValue, int _sharpnessValue )
1406{
1407 KoSize size( r.width(), r.height() );
1408
1409 KPrPolygonObject *kpPolygonObject = new KPrPolygonObject( points, size, pen, brush, ft,
1410 g1, g2, gt, unbalanced, xfactor, yfactor,
1411 _checkConcavePolygon, _cornersValue, _sharpnessValue );
1412 insertObject( i18n( "Insert Polygon" ), kpPolygonObject, r );
1413}
1414
1415void KPrPage::insertClosedLine( const KoPointArray &points, const KoRect &r, const KoPen &pen, const TQBrush &brush,
1416 FillType ft,const TQColor &g1, const TQColor &g2,
1417 BCType gt, bool unbalanced, int xfactor, int yfactor, ToolEditMode _mode )
1418{
1419 TQString _type;
1420 TQString _name;
1421 if ( _mode == INS_CLOSED_FREEHAND ) {
1422 _type = i18n( "Closed Freehand" );
1423 _name = i18n( "Insert Closed Freehand" );
1424 }
1425 else if ( _mode == INS_CLOSED_POLYLINE ) {
1426 _type = i18n( "Closed Polyline" );
1427 _name = i18n( "Insert Closed Polyline" );
1428 }
1429 else if ( _mode == INS_CLOSED_QUADRICBEZIERCURVE ) {
1430 _type = i18n( "Closed Quadric Bezier Curve" );
1431 _name = i18n( "Insert Closed Quadric Bezier Curve" );
1432 }
1433 else if ( _mode == INS_CLOSED_CUBICBEZIERCURVE ) {
1434 _type = i18n( "Closed Cubic Bezier Curve" );
1435 _name = i18n( "Insert Closed Cubic Bezier Curve" );
1436 }
1437
1438 KoSize size( r.width(), r.height() );
1439
1440 KPrClosedLineObject *kpClosedLineObject = new KPrClosedLineObject( points, size, pen, brush, ft,
1441 g1, g2, gt, unbalanced, xfactor, yfactor, _type );
1442 insertObject( _name, kpClosedLineObject, r );
1443}
1444
1445KPrPartObject* KPrPage::insertObject( const KoRect& _rect, KoDocumentEntry& _e )
1446{
1447 KoDocument* doc = _e.createDoc( m_doc );
1448 if ( !doc )
1449 return NULL;
1450
1451 if ( !doc->showEmbedInitDialog( 0 ) ) //TODO should really have parent
1452 return NULL;
1453
1454 TQRect r = TQRect( (int)_rect.left(), (int)_rect.top(),
1455 (int)_rect.width(), (int)_rect.height() );
1456 KPrChild* ch = new KPrChild( m_doc, doc, r );
1457 m_doc->insertObject( ch );
1458
1459 KPrPartObject *kppartobject = new KPrPartObject( ch );
1460 insertObject( i18n( "Embed Object" ), kppartobject, _rect );
1461
1462 //emit sig_insertObject( ch, kppartobject );
1463 m_doc->repaint( false );
1464
1465 return kppartobject;
1466}
1467
1468KCommand* KPrPage::setPen( const KoPen &pen, LineEnd lb, LineEnd le, int flags )
1469{
1470 KoPenCmd * cmd = NULL;
1471
1472 KoPenCmd::Pen _newPen( pen, lb, le);
1473
1474 TQPtrList<KPrObject> _objects;
1475 _objects.setAutoDelete( false );
1476
1477 TQPtrListIterator<KPrObject> it( m_objectList );
1478 for ( ; it.current() ; ++it )
1479 {
1480 if( it.current()->isSelected() )
1481 {
1482 _objects.append( it.current() );
1483 }
1484 }
1485
1486 if ( !_objects.isEmpty() && flags ) {
1487 cmd = new KoPenCmd( i18n( "Apply Styles" ), _objects, _newPen, m_doc, this, flags );
1488 cmd->execute();
1489 }
1490
1491 return cmd;
1492}
1493
1494KCommand * KPrPage::setBrush( const TQBrush &brush, FillType ft, const TQColor &g1, const TQColor &g2,
1495 BCType gt, bool unbalanced, int xfactor, int yfactor, int flags )
1496{
1497 KPrBrushCmd * cmd = NULL;
1498
1499 KPrBrushCmd::Brush _newBrush;
1500
1501 _newBrush.brush = TQBrush( brush );
1502 _newBrush.fillType = ft;
1503 _newBrush.gColor1 = g1;
1504 _newBrush.gColor2 = g2;
1505 _newBrush.gType = gt;
1506 _newBrush.unbalanced = unbalanced;
1507 _newBrush.xfactor = xfactor;
1508 _newBrush.yfactor = yfactor;
1509
1510 TQPtrList<KPrObject> _objects;
1511 _objects.setAutoDelete( false );
1512
1513 TQPtrListIterator<KPrObject> it( m_objectList );
1514 for ( ; it.current() ; ++it )
1515 {
1516 if( it.current()->isSelected() )
1517 {
1518 _objects.append( it.current() );
1519 }
1520 }
1521
1522 if ( !_objects.isEmpty() && flags ) {
1523 cmd = new KPrBrushCmd( i18n( "Apply Styles" ), _objects, _newBrush, m_doc, this, flags );
1524 cmd->execute();
1525 }
1526
1527 return cmd;
1528}
1529
1530void KPrPage::slotRepaintVariable()
1531{
1532 TQPtrListIterator<KPrObject> it( m_objectList );
1533 for ( ; it.current() ; ++it )
1534 {
1535 if ( it.current()->getType() == OT_TEXT )
1536 m_doc->repaint( it.current() );
1537 }
1538}
1539
1540void KPrPage::recalcPageNum()
1541{
1542 TQPtrListIterator<KPrObject> it( m_objectList );
1543 for ( ; it.current() ; ++it )
1544 {
1545 if ( it.current()->getType() == OT_TEXT ) {
1546 ( (KPrTextObject*)it.current() )->recalcPageNum( this );
1547 m_doc->repaint( it.current() ); // TODO only if something changed
1548 }
1549 }
1550}
1551
1552void KPrPage::changePicture( const KURL & url, TQWidget *parent )
1553{
1554 // filename has been chosen in KPrView with a filedialog,
1555 // so we know it exists
1556 KoPicture image = m_doc->pictureCollection()->downloadPicture( url, parent );
1557
1558 TQPtrListIterator<KPrObject> it( m_objectList );
1559 for ( ; it.current() ; ++it )
1560 {
1561 if(it.current()->isSelected() && it.current()->getType()==OT_PICTURE)
1562 {
1563 KPrPixmapObject* obj=dynamic_cast<KPrPixmapObject*>( it.current() );
1564 if( obj)
1565 {
1566 KPrPixmapObject *pix = new KPrPixmapObject( m_doc->pictureCollection(), image.getKey() );
1567 KPrChgPixCmd *chgPixCmd = new KPrChgPixCmd( i18n( "Change Pixmap" ),obj,pix, m_doc,this );
1568 chgPixCmd->execute();
1569 m_doc->addCommand( chgPixCmd );
1570 }
1571 break;
1572 }
1573 }
1574}
1575
1576void KPrPage::insertPicture( const TQString &filename, const KoPoint &pos )
1577{
1578 KoPictureKey key = m_doc->pictureCollection()->loadPicture( filename ).getKey();
1579 KPrPixmapObject *kppixmapobject = new KPrPixmapObject(m_doc->pictureCollection() , key );
1580
1581 kppixmapobject->setOrig( pos );
1582 kppixmapobject->setSelected( true );
1583
1584 kppixmapobject->setSize( m_doc->zoomHandler()->pixelXToPt( kppixmapobject->originalSize().width() ),
1585 m_doc->zoomHandler()->pixelYToPt( kppixmapobject->originalSize().height() ) );
1586 kppixmapobject->setKeepRatio( true ); // pics have keep-aspect-ratio on by default.
1587
1588 KPrInsertCmd *insertCmd = new KPrInsertCmd( i18n( "Insert Picture" ), kppixmapobject, m_doc, this );
1589 insertCmd->execute();
1590 m_doc->addCommand( insertCmd );
1591
1592 KoRect s = getPageRect();
1593 float fakt = 1;
1594 if ( kppixmapobject->getSize().width() > s.width() )
1595 fakt = (float)s.width() / (float)kppixmapobject->getSize().width();
1596 if ( kppixmapobject->getSize().height() > s.height() )
1597 fakt = TQMIN( fakt, (float)s.height() / (float)kppixmapobject->getSize().height() );
1598
1599 //kdDebug(33001) << k_funcinfo << "Fakt: " << fakt << endl;
1600
1601 if ( fakt < 1 ) {
1602 int w = (int)( fakt * (float)kppixmapobject->getSize().width() );
1603 int h = (int)( fakt * (float)kppixmapobject->getSize().height() );
1604 //kdDebug(33001) << k_funcinfo << "Size: " << w << ", " << h << endl;
1605 kppixmapobject->setOrig(0,0);
1606 kppixmapobject->setSize(w, h);
1607 m_doc->repaint( false );
1608 }
1609}
1610
1611void KPrPage::insertPicture( const TQString &_file, const KoRect &_rect )
1612{
1613 KoPictureKey key = m_doc->pictureCollection()->loadPicture( _file ).getKey();
1614 KPrPixmapObject *kppixmapobject = new KPrPixmapObject( m_doc->pictureCollection(), key );
1615 kppixmapobject->setKeepRatio( true ); // pics have keep-aspect-ratio on by default.
1616 insertObject( i18n( "Insert Picture" ), kppixmapobject, _rect );
1617}
1618
1619void KPrPage::enableEmbeddedParts( bool f )
1620{
1621 KPrPartObject *obj=0L;
1622 TQPtrListIterator<KPrObject> it( m_objectList );
1623 for ( ; it.current() ; ++it )
1624 {
1625 if(it.current()->getType()==OT_PART)
1626 {
1627 obj=dynamic_cast<KPrPartObject*>( it.current() );
1628 if(obj)
1629 obj->enableDrawing( f );
1630 }
1631 }
1632}
1633
1634
1635void KPrPage::setBackColor(const TQColor &backColor1, const TQColor &backColor2, BCType bcType,
1636 bool unbalanced, int xfactor, int yfactor )
1637{
1638 m_kpbackground->setBackColor1( backColor1 );
1639 m_kpbackground->setBackColor2( backColor2 );
1640 m_kpbackground->setBackColorType( bcType );
1641 m_kpbackground->setBackUnbalanced( unbalanced );
1642 m_kpbackground->setBackXFactor( xfactor );
1643 m_kpbackground->setBackYFactor( yfactor );
1644}
1645
1646void KPrPage::setBackPicture( const KoPictureKey & key )
1647{
1648 m_kpbackground->setBackPicture( key );
1649}
1650
1651bool KPrPage::getBackUnbalanced() const
1652{
1653 return m_kpbackground->getBackUnbalanced();
1654}
1655
1656void KPrPage::setBackView( BackView backView )
1657{
1658 m_kpbackground->setBackView( backView );
1659}
1660
1661void KPrPage::setBackType( BackType backType )
1662{
1663 m_kpbackground->setBackType( backType );
1664}
1665
1666void KPrPage::setPageEffectSpeed( EffectSpeed pageEffectSpeed )
1667{
1668 m_pageEffectSpeed = pageEffectSpeed;
1669}
1670
1671void KPrPage::setPageEffect( PageEffect pageEffect )
1672{
1673 m_pageEffect = pageEffect;
1674}
1675
1676void KPrPage::setPageTimer( int pageTimer )
1677{
1678 m_pageTimer = pageTimer;
1679}
1680
1681void KPrPage::setPageSoundEffect( bool soundEffect )
1682{
1683 m_soundEffect = soundEffect;
1684}
1685
1686void KPrPage::setPageSoundFileName( const TQString &fileName )
1687{
1688 m_soundFileName = fileName;
1689}
1690
1691BackType KPrPage::getBackType() const
1692{
1693 return m_kpbackground->getBackType();
1694}
1695
1696BackView KPrPage::getBackView() const
1697{
1698 return m_kpbackground->getBackView();
1699}
1700
1701KoPictureKey KPrPage::getBackPictureKey() const
1702{
1703 return m_kpbackground->getBackPictureKey();
1704}
1705
1706KoPicture KPrPage::getBackPicture() const
1707{
1708 return m_kpbackground->getBackPicture();
1709}
1710
1711TQColor KPrPage::getBackColor1() const
1712{
1713 return m_kpbackground->getBackColor1();
1714}
1715
1716TQColor KPrPage::getBackColor2() const
1717{
1718 return m_kpbackground->getBackColor2();
1719}
1720
1721int KPrPage::getBackXFactor() const
1722{
1723 return m_kpbackground->getBackXFactor();
1724}
1725
1726int KPrPage::getBackYFactor() const
1727{
1728 return m_kpbackground->getBackYFactor();
1729}
1730
1731BCType KPrPage::getBackColorType() const
1732{
1733 return m_kpbackground->getBackColorType();
1734}
1735
1736EffectSpeed KPrPage::getPageEffectSpeed() const
1737{
1738 return m_pageEffectSpeed;
1739}
1740
1741PageEffect KPrPage::getPageEffect() const
1742{
1743 return m_pageEffect;
1744}
1745
1746int KPrPage::getPageTimer() const
1747{
1748 return m_pageTimer;
1749}
1750
1751bool KPrPage::getPageSoundEffect() const
1752{
1753 return m_soundEffect;
1754}
1755
1756TQString KPrPage::getPageSoundFileName() const
1757{
1758 return m_soundFileName;
1759}
1760
1761KoRect KPrPage::getPageRect() const
1762{
1763 const KoPageLayout& p = m_doc->pageLayout();
1764 return KoRect( p.ptLeft, p.ptTop, p.ptWidth - p.ptRight - p.ptLeft, p.ptHeight - p.ptTop - p.ptBottom );
1765}
1766
1767TQRect KPrPage::getZoomPageRect() const
1768{
1769 return m_doc->zoomHandler()->zoomRect(getPageRect());
1770}
1771
1772void KPrPage::completeLoading( bool _clean, int lastObj )
1773{
1774 TQPtrListIterator<KPrObject> it( m_objectList );
1775 for ( ; it.current() ; ++it )
1776 {
1777 // Pictures and cliparts have been loaded from the store, we can now
1778 // get the picture from the collection, and set it in the image/clipart object
1779 if ( ( it.current()->getType() == OT_PICTURE )
1780 || ( it.current()->getType() == OT_CLIPART ) ) {
1781 if ( _clean || m_objectList.findRef( it.current() ) > lastObj )
1782 {
1783 KPrPixmapObject* obj=dynamic_cast<KPrPixmapObject*>( it.current());
1784 if(obj)
1785 obj->reload();
1786 }
1787 }
1788 else if ( it.current()->getType() == OT_TEXT )
1789 {
1790 KPrTextObject*obj=dynamic_cast<KPrTextObject*>( it.current() );
1791 if(obj)
1792 obj->recalcPageNum( this );
1793 }
1794 else if ( it.current()->getType() == OT_GROUP )
1795 completeLoadingForGroupObject( it.current() );
1796 }
1797 m_kpbackground->reload();
1798}
1799
1800void KPrPage::completeLoadingForGroupObject( KPrObject *_obj )
1801{
1802 KPrGroupObject *_groupObj = static_cast<KPrGroupObject*>( _obj );
1803
1804 if ( _groupObj ) {
1805 TQPtrListIterator<KPrObject> it( _groupObj->objectList() );
1806 for ( ; it.current(); ++it ) {
1807 if ( ( it.current()->getType() == OT_PICTURE )
1808 || ( it.current()->getType() == OT_CLIPART ) ) {
1809 KPrPixmapObject *_pixObj = dynamic_cast<KPrPixmapObject*>( it.current() );
1810 if ( _pixObj )
1811 _pixObj->reload();
1812 }
1813 else if ( it.current()->getType() == OT_TEXT ) {
1814 KPrTextObject *_textObj= dynamic_cast<KPrTextObject*>( it.current() );
1815 if ( _textObj )
1816 _textObj->recalcPageNum( this );
1817 }
1818 else if ( it.current()->getType() == OT_GROUP )
1819 completeLoadingForGroupObject( it.current() ); // recursion
1820 }
1821 }
1822}
1823
1824KCommand * KPrPage::replaceObjs( bool createUndoRedo, double _orastX,double _orastY,const TQColor & _txtBackCol,
1825 const TQColor & _otxtBackCol )
1826{
1827 KPrObject *kpobject = 0;
1828 double ox=0, oy=0;
1829 TQPtrList<KPrObject> _objects;
1830 TQValueList<KoPoint> _diffs;
1831 _objects.setAutoDelete( false );
1832
1833 for ( int i = 0; i < static_cast<int>( m_objectList.count() ); i++ ) {
1834 kpobject = m_objectList.at( i );
1835 ox = kpobject->getOrig().x();
1836 oy = kpobject->getOrig().y();
1837 ox = static_cast<int>(ox / m_doc->getGridX() * m_doc->getGridX());
1838 oy = static_cast<int>(oy / m_doc->getGridY() * m_doc->getGridY());
1839
1840 _diffs.append( KoPoint( ox - kpobject->getOrig().x(), oy - kpobject->getOrig().y() ) );
1841 _objects.append( kpobject );
1842 }
1843
1844 KPrSetOptionsCmd *setOptionsCmd = new KPrSetOptionsCmd( i18n( "Set New Options" ), _diffs, _objects, m_doc->getGridX(),
1845 m_doc->getGridY(),_orastX, _orastY, _txtBackCol, _otxtBackCol, m_doc );
1846 if ( createUndoRedo )
1847 return setOptionsCmd;
1848
1849 delete setOptionsCmd;
1850 return 0L;
1851}
1852
1853TQString KPrPage::manualTitle() const
1854{
1855 return m_manualTitle;
1856}
1857
1858void KPrPage::insertManualTitle(const TQString & title)
1859{
1860 m_manualTitle=title;
1861}
1862
1863TQString KPrPage::pageTitle( const TQString &_title ) const
1864{
1865 // If a user sets a title with manual, return it.
1866 if ( !m_manualTitle.isEmpty() )
1867 return m_manualTitle;
1868
1869 TQPtrList<KPrTextObject> objs;
1870
1871 // Create list of text objects in this page
1872
1873 TQPtrListIterator<KPrObject> it( m_objectList );
1874 for ( ; it.current() ; ++it )
1875 {
1876 if(it.current()->getType()==OT_TEXT)
1877 objs.append( static_cast<KPrTextObject*>( it.current() ) );
1878 }
1879
1880 TQString title;
1881 if ( _title.isNull() )
1882 {
1883 // MASTERPAGE
1884 if ( m_masterPage )
1885 title = i18n( "Slide %1" ).arg( m_doc->pageList().findRef( this ) + 1 );
1886 else
1887 title = i18n( "Slide Master" );
1888 }
1889 else
1890 {
1891 title = _title;
1892 }
1893
1894 if ( objs.isEmpty() )
1895 return title;
1896
1897 // Find object most on top
1898 KPrTextObject *tmp = objs.first();
1899 KPrTextObject *textobject=tmp;
1900 for ( tmp = objs.next(); tmp; tmp = objs.next() )
1901 if ( tmp->getOrig().y() < textobject->getOrig().y() )
1902 textobject = tmp;
1903
1904 // this can't happen, but you never know :- )
1905 if ( !textobject )
1906 return TQString( title );
1907
1908 TQString txt;
1909 if ( textobject->textDocument()->firstParag() )
1910 txt = textobject->textDocument()->firstParag()->toString();
1911 if ( txt.stripWhiteSpace().isEmpty() || txt=="\n" )
1912 return title;
1913 return txt;
1914}
1915
1916void KPrPage::setNoteText( const TQString &_text )
1917{
1918 m_noteText=_text;
1919 m_doc->setModified(true);
1920}
1921
1922TQString KPrPage::noteText() const
1923{
1924 return m_noteText;
1925}
1926
1927void KPrPage::makeUsedPixmapList()
1928{
1929 TQPtrListIterator<KPrObject> it( m_objectList );
1930 for ( ; it.current() ; ++it )
1931 {
1932 if( it.current()->getType()==OT_PICTURE || it.current()->getType()==OT_CLIPART)
1933 m_doc->insertPixmapKey(static_cast<KPrPixmapObject*>( it.current() )->getKey() );
1934 else if ( it.current()->getType() == OT_GROUP )
1935 makeUsedPixmapListForGroupObject( it.current() );
1936 }
1937
1938 if( m_kpbackground->getBackType()==BT_PICTURE || m_kpbackground->getBackType()==BT_CLIPART)
1939 m_doc->insertPixmapKey(m_kpbackground->getBackPictureKey());
1940}
1941
1942void KPrPage::makeUsedPixmapListForGroupObject( KPrObject *_obj )
1943{
1944 KPrGroupObject *_groupObj = static_cast<KPrGroupObject*>( _obj );
1945
1946 if ( _groupObj ) {
1947 TQPtrListIterator<KPrObject> it( _groupObj->objectList() );
1948 for ( ; it.current(); ++it ) {
1949 if ( ( it.current()->getType() == OT_PICTURE )
1950 || ( it.current()->getType() == OT_CLIPART ) )
1951 m_doc->insertPixmapKey(static_cast<KPrPixmapObject*>( it.current() )->getKey() );
1952 else if ( it.current()->getType() == OT_GROUP )
1953 makeUsedPixmapListForGroupObject( it.current() ); // recursion
1954 }
1955 }
1956}
1957
1958
1959TQValueList<int> KPrPage::getEffectSteps() const
1960{
1961 TQMap<int,bool> stepmap;
1962 stepmap[0] = true;
1963
1964 TQPtrListIterator<KPrObject> it( m_objectList );
1965 for ( ; it.current(); ++it )
1966 {
1967 stepmap[it.current()->getAppearStep()] = true;
1968
1969 if ( it.current()->getDisappear() )
1970 {
1971 stepmap[it.current()->getDisappearStep()] = true;
1972 }
1973 }
1974
1975 return stepmap.keys();
1976}
1977
1978
1979void KPrPage::deSelectAllObj()
1980{
1981 TQPtrListIterator<KPrObject> sIt( m_objectList );
1982 for ( ; sIt.current() ; ++sIt )
1983 {
1984 if(sIt.current()->isSelected())
1985 deSelectObj(sIt.current() );
1986 }
1987}
1988
1989void KPrPage::deSelectObj( KPrObject *kpobject )
1990{
1991 kpobject->setSelected( false );
1992 m_doc->repaint( kpobject );
1993}
1994
1995TQDomElement KPrPage::saveObjects( TQDomDocument &doc, TQDomElement &objects, double yoffset,
1996 int saveOnlyPage ) const
1997{
1998 TQPtrListIterator<KPrObject> oIt(m_objectList);
1999 for (; oIt.current(); ++oIt )
2000 {
2001 //don't store header/footer (store in header/footer section)
2002 if ( oIt.current()==m_doc->header()
2003 || oIt.current()==m_doc->footer()
2004 || oIt.current()->getType() == OT_PART)
2005 continue;
2006 TQDomElement object=doc.createElement("OBJECT");
2007 object.setAttribute("type", static_cast<int>( oIt.current()->getType() ));
2008 bool _sticky = ( this->m_masterPage == 0 );
2009 if (_sticky)
2010 object.setAttribute("sticky", static_cast<int>(_sticky));
2011 if ( saveOnlyPage != -1 )
2012 yoffset=0;
2013 //add yoffset to compatibility with koffice 1.1
2014 object.appendChild(oIt.current()->save( doc, yoffset ));
2015
2016 objects.appendChild(object);
2017 }
2018 return objects;
2019}
2020
2021bool KPrPage::oneObjectTextExist(bool forceAllTextObject)
2022{
2023 TQPtrList<KPrObject> lst;
2024 getAllObjectSelectedList(lst,forceAllTextObject );
2025 TQPtrListIterator<KPrObject> it( lst );
2026 for ( ; it.current() ; ++it )
2027 {
2028 if ( (it.current() == m_doc->header() && !hasHeader())
2029 || (it.current() == m_doc->footer() && !hasFooter()) )
2030 continue;
2031 if (it.current()->getType()==OT_TEXT)
2032 return true;
2033 }
2034 return false;
2035}
2036
2037bool KPrPage::oneObjectTextSelected()
2038{
2039 return oneObjectTextExist(false);
2040}
2041
2042
2043bool KPrPage::isOneObjectSelected()
2044{
2045 return 0 != getSelectedObj();
2046}
2047
2048bool KPrPage::haveASelectedPartObj()
2049{
2050 TQPtrList<KPrObject> lst;
2051 getAllObjectSelectedList(lst );
2052 TQPtrListIterator<KPrObject> it( lst );
2053 for ( ; it.current(); ++it ) {
2054 if (it.current()->getType() == OT_PART )
2055 return true;
2056 }
2057 return false;
2058}
2059
2060bool KPrPage::haveASelectedGroupObj()
2061{
2062 TQPtrList<KPrObject> objects( getSelectedObjects( true ) );
2063 TQPtrListIterator<KPrObject> it( objects );
2064 for ( ; it.current(); ++it ) {
2065 if ( it.current()->getType() == OT_GROUP )
2066 return true;
2067 }
2068 return false;
2069}
2070
2071bool KPrPage::haveASelectedPixmapObj()
2072{
2073 TQPtrList<KPrObject> lst;
2074 getAllObjectSelectedList(lst );
2075 TQPtrListIterator<KPrObject> it( lst );
2076 for ( ; it.current() ; ++it ) {
2077 if (( it.current()->getType() == OT_PICTURE )
2078 || ( it.current()->getType() == OT_CLIPART ) )
2079 return true;
2080 }
2081 return false;
2082}
2083
2084KoRect KPrPage::getRealRect( bool all ) const
2085{
2086 KoRect rect;
2087
2088 TQPtrListIterator<KPrObject> it( m_objectList );
2089 for ( ; it.current() ; ++it )
2090 {
2091 if ( it.current()== m_doc->header() || it.current()== m_doc->footer())
2092 continue;
2093
2094 if ( all || ( it.current()->isSelected() && ! it.current()->isProtect() ) )
2095 rect |= it.current()->getRealRect();
2096 }
2097
2098 return rect;
2099}
2100
2101//return true if we change picture
2102bool KPrPage::chPic( KPrView *_view)
2103{
2104 TQPtrListIterator<KPrObject> it( m_objectList );
2105 for ( ; it.current() ; ++it )
2106 {
2107 if ( it.current()->isSelected() &&
2108 ( ( it.current()->getType() == OT_PICTURE )
2109 || ( it.current()->getType() == OT_CLIPART ) ) )
2110 {
2111 KPrPixmapObject* obj=dynamic_cast<KPrPixmapObject*>( it.current() );
2112 if( obj)
2113 {
2114 _view->changePicture( obj->getFileName() );
2115 return true;
2116 }
2117 }
2118 }
2119 return false;
2120}
2121
2122bool KPrPage::savePicture( KPrView *_view ) const
2123{
2124 TQPtrListIterator<KPrObject> it( m_objectList );
2125 for ( ; it.current() ; ++it )
2126 {
2127 if ( it.current()->isSelected() &&
2128 ( ( it.current()->getType() == OT_PICTURE )
2129 || ( it.current()->getType() == OT_CLIPART ) ) )
2130 {
2131 KPrPixmapObject* obj=dynamic_cast<KPrPixmapObject*>( it.current() );
2132 if( obj)
2133 {
2134 _view->savePicture( obj );
2135 return true;
2136 }
2137 }
2138 }
2139 return false;
2140}
2141
2142// move object for releasemouseevent
2143KCommand *KPrPage::moveObject(KPrView *_view, double diffx, double diffy)
2144{
2145 bool createCommand=false;
2146 KPrMoveByCmd *moveByCmd=0L;
2147 TQPtrList<KPrObject> _objects;
2148 _objects.setAutoDelete( false );
2149 TQPtrListIterator<KPrObject> it( m_objectList );
2150 for ( ; it.current() ; ++it )
2151 {
2152 //don't move a header/footer
2153 if ( it.current() == m_doc->header() || it.current() == m_doc->footer())
2154 continue;
2155 if ( it.current()->isSelected() && !it.current()->isProtect())
2156 {
2157 _objects.append( it.current() );
2158 TQRect br = _view->zoomHandler()->zoomRect( it.current()->getRepaintRect() );
2159 br.moveBy( _view->zoomHandler()->zoomItX( diffx ), _view->zoomHandler()->zoomItY( diffy ) );
2160 m_doc->repaint( br ); // Previous position
2161 m_doc->repaint( it.current() ); // New position
2162 createCommand=true;
2163 }
2164 }
2165 if(createCommand) {
2166 moveByCmd = new KPrMoveByCmd( i18n( "Move Objects" ), KoPoint( diffx, diffy ),
2167 _objects, m_doc,this );
2168
2169 m_doc->updateSideBarItem( this );
2170 }
2171 return moveByCmd;
2172}
2173
2174KCommand *KPrPage::moveObject(KPrView *m_view,const KoPoint &_move,bool key)
2175{
2176 TQPtrList<KPrObject> _objects;
2177 _objects.setAutoDelete( false );
2178 KPrMoveByCmd *moveByCmd=0L;
2179 TQPtrListIterator<KPrObject> it( m_objectList );
2180 for ( ; it.current() ; ++it )
2181 {
2182 //don't move a header/footer
2183 if ( it.current()== m_doc->header() || it.current()== m_doc->footer())
2184 continue;
2185 if ( it.current()->isSelected() && !it.current()->isProtect()) {
2186
2187 TQRect oldBoundingRect = m_view->zoomHandler()->zoomRect( it.current()->getRepaintRect() );
2188
2189 it.current()->moveBy( _move );
2190 _objects.append( it.current() );
2191 m_doc->repaint( oldBoundingRect );
2192 m_doc->repaint( it.current() );
2193 }
2194 }
2195
2196 if ( key && !_objects.isEmpty())
2197 moveByCmd = new KPrMoveByCmd( i18n( "Move Objects" ),
2198 KoPoint( _move ),
2199 _objects, m_doc,this );
2200
2201 return moveByCmd;
2202}
2203
2204void KPrPage::repaintObj()
2205{
2206 TQPtrListIterator<KPrObject> it( m_objectList );
2207 for ( ; it.current() ; ++it )
2208 {
2209 if(it.current()->isSelected())
2210 m_doc->repaint(it.current() );
2211 }
2212}
2213
2214KCommand *KPrPage::rotateSelectedObjects( float _newAngle, bool addAngle )
2215{
2216 KPrRotateCmd * cmd = NULL;
2217
2218 TQPtrList<KPrObject> _objects;
2219 _objects.setAutoDelete( false );
2220
2221 TQPtrListIterator<KPrObject> it( m_objectList );
2222 for ( ; it.current() ; ++it )
2223 {
2224 if ( it.current()== m_doc->header() || it.current()== m_doc->footer() )
2225 continue;
2226 if( it.current()->isSelected() && !it.current()->isProtect())
2227 {
2228 _objects.append( it.current() );
2229 }
2230 }
2231
2232 if ( !_objects.isEmpty() ) {
2233 cmd = new KPrRotateCmd( i18n( "Change Rotation" ), _newAngle, _objects, m_doc, addAngle );
2234 cmd->execute();
2235 }
2236
2237 return cmd;
2238}
2239
2240
2241KCommand *KPrPage::shadowObj(ShadowDirection dir,int dist, const TQColor &col)
2242{
2243 KPrShadowCmd *shadowCmd=0L;
2244 bool newShadow=false;
2245 TQPtrList<KPrObject> _objects;
2246 TQPtrList<KPrShadowCmd::ShadowValues> _oldShadow;
2247 KPrShadowCmd::ShadowValues _newShadow, *tmp;
2248
2249 _objects.setAutoDelete( false );
2250 _oldShadow.setAutoDelete( false );
2251
2252 _newShadow.shadowDirection = dir;
2253 _newShadow.shadowDistance = dist;
2254 _newShadow.shadowColor = col;
2255
2256 TQPtrListIterator<KPrObject> it( m_objectList );
2257 for ( ; it.current() ; ++it )
2258 {
2259 //don't shadow a header/footer
2260 if ( it.current()== m_doc->header() || it.current()== m_doc->footer())
2261 continue;
2262
2263 if ( it.current()->isSelected() ) {
2264 tmp = new KPrShadowCmd::ShadowValues;
2265 tmp->shadowDirection = it.current()->getShadowDirection();
2266 tmp->shadowDistance =it.current()->getShadowDistance();
2267 tmp->shadowColor = it.current()->getShadowColor();
2268
2269 if(!newShadow &&( tmp->shadowDirection!=_newShadow.shadowDirection
2270 || tmp->shadowDistance!=_newShadow.shadowDistance
2271 || tmp->shadowColor!=_newShadow.shadowColor))
2272 newShadow=true;
2273
2274 _oldShadow.append( tmp );
2275 _objects.append( it.current() );
2276 }
2277 }
2278
2279 if ( !_objects.isEmpty() && newShadow ) {
2280 shadowCmd = new KPrShadowCmd( i18n( "Change Shadow" ),
2281 _oldShadow, _newShadow, _objects, m_doc );
2282 shadowCmd->execute();
2283 }
2284 else
2285 {
2286 _oldShadow.setAutoDelete( true );
2287 _oldShadow.clear();
2288 }
2289 return shadowCmd;
2290}
2291
2292TQPtrList<KoTextObject> KPrPage::allTextObjects() const
2293{
2294 TQPtrList<KoTextObject> lst;
2295 addTextObjects( lst );
2296 return lst;
2297}
2298
2299void KPrPage::addTextObjects(TQPtrList<KoTextObject>& lst) const
2300{
2301 TQPtrListIterator<KPrObject> it( m_objectList );
2302 for ( ; it.current() ; ++it )
2303 it.current()->addTextObjects( lst );
2304}
2305
2306KPrObject * KPrPage::getCursor( const TQPoint &pos )
2307{
2308 return getCursor( m_doc->zoomHandler()->unzoomPoint( pos ) );
2309}
2310
2311KPrObject * KPrPage::getCursor(const KoPoint &pos )
2312{
2313 TQPtrListIterator<KPrObject> it( m_objectList );
2314 KPrObject *kpobject = it.toLast();
2315 while ( kpobject ) {
2316 if ( kpobject->contains( pos ) && kpobject->isSelected() )
2317 return kpobject;
2318 kpobject = --it;
2319 }
2320 return 0L;
2321}
2322
2323KPrObject* KPrPage::getObjectAt( const KoPoint &pos, bool withoutProtected ) const
2324{
2325 TQPtrListIterator<KPrObject> it( m_objectList );
2326 KPrObject *o = 0;
2327 //tz Check first if there is a selected object at this pos!
2328 for ( int i = 0; i < 2; ++i )
2329 {
2330 o = it.toLast();
2331 while ( o ) {
2332 if ( o != m_doc->footer() ||
2333 o != m_doc->header() ||
2334 ( m_bHasFooter && o == m_doc->footer() ) ||
2335 ( m_bHasHeader && o == m_doc->header() ) )
2336 {
2337 if ( ( o->isSelected() || i > 0 ) &&
2338 o->contains( pos ) && !( o->isProtect() && withoutProtected ) )
2339 return o;
2340 }
2341 o = --it;
2342 }
2343 }
2344 return 0L;
2345}
2346
2347KPrPixmapObject * KPrPage::picViewOrigHelper() const
2348{
2349 KPrPixmapObject *obj=0L;
2350 TQPtrListIterator<KPrObject> it( m_objectList );
2351 for ( ; it.current() ; ++it )
2352 {
2353 if ( it.current()->isSelected() &&
2354 ( ( it.current()->getType() == OT_PICTURE )
2355 || ( it.current()->getType() == OT_CLIPART ) ) )
2356 {
2357 obj=(KPrPixmapObject*)it.current();
2358 break;
2359 }
2360 }
2361 return obj;
2362}
2363
2364void KPrPage::applyStyleChange( KoStyleChangeDefMap changed )
2365{
2366 TQPtrList<KPrObject> lst;
2367 getAllObjectSelectedList(lst,true /*force*/ );
2368 TQPtrListIterator<KPrObject> it( lst );
2369
2370 for ( ; it.current() ; ++it )
2371 {
2372 KPrTextObject *obj=dynamic_cast<KPrTextObject*>(it.current());
2373 if( obj)
2374 obj->applyStyleChange( changed );
2375 }
2376}
2377
2378void KPrPage::reactivateBgSpellChecking(bool refreshTextObj)
2379{
2380 TQPtrList<KPrObject> lst;
2381 getAllObjectSelectedList(lst,true /*force*/ );
2382 TQPtrListIterator<KPrObject> oIt( lst );
2383
2384 for ( ; oIt.current() ; ++oIt )
2385 {
2386 if(oIt.current()->getType()==OT_TEXT)
2387 {
2388 static_cast<KPrTextObject*>( oIt.current() )->textObject()->setNeedSpellCheck(true);
2389 if(refreshTextObj)
2390 m_doc->repaint( oIt.current() );
2391 }
2392 }
2393}
2394
2395bool KPrPage::canMoveOneObject() const
2396{
2397 TQPtrListIterator<KPrObject> it( m_objectList );
2398 for ( ; it.current() ; ++it )
2399 {
2400 //don't test header/footer all the time sticky
2401 if ( it.current()== m_doc->header() || it.current()== m_doc->footer())
2402 continue;
2403 if(it.current()->isSelected()&& !it.current()->isProtect())
2404 return true;
2405 }
2406 return false;
2407}
2408
2409KCommand *KPrPage::alignVertical(VerticalAlignmentType _type )
2410{
2411 KMacroCommand *macro = 0L;
2412 TQPtrList<KPrObject> lst;
2413 getAllObjectSelectedList(lst );
2414 TQPtrListIterator<KPrObject> it( lst );
2415 for ( ; it.current() ; ++it )
2416 {
2417 if(it.current()->getType()==OT_TEXT)
2418 {
2419 KPrTextObject *obj = dynamic_cast<KPrTextObject *>(it.current());
2420 if ( obj && !obj->isProtectContent())
2421 {
2422 KPrChangeVerticalAlignmentCommand * cmd = new KPrChangeVerticalAlignmentCommand( i18n("Change Vertical Alignment"),
2423 obj, obj->verticalAlignment(),_type, m_doc);
2424 if ( !macro )
2425 macro = new KMacroCommand( i18n("Change Vertical Alignment"));
2426 macro->addCommand( cmd );
2427 cmd->execute();
2428 }
2429 }
2430 }
2431 return macro;
2432}
2433
2434void KPrPage::changeTabStopValue ( double _tabStop )
2435{
2436 TQPtrList<KPrObject> lst;
2437 getAllObjectSelectedList(lst,true /*force*/ );
2438 TQPtrListIterator<KPrObject> it( lst );
2439 for ( ; it.current() ; ++it )
2440 {
2441 if(it.current()->getType()==OT_TEXT)
2442 {
2443 KPrTextObject *obj = dynamic_cast<KPrTextObject *>(it.current());
2444 if ( obj )
2445 {
2446 obj->textDocument()->setTabStops( m_doc->zoomHandler()->ptToLayoutUnitPixX( _tabStop ));
2447 obj->layout();
2448 m_doc->repaint( obj );
2449 }
2450 }
2451 }
2452}
2453
2454KPrObject *KPrPage::nextTextObject(KPrTextObject *obj)
2455{
2456 if ( m_objectList.count()==0 )
2457 return 0L;
2458 int pos = -1;
2459 if ( obj )
2460 pos = m_objectList.findNextRef(obj);
2461
2462 if (pos != -1 )
2463 {
2464 KPrObject *frm=0L;
2465 for ( frm=m_objectList.at(pos); frm != 0; frm=m_objectList.next() )
2466 {
2467 KPrTextObject *newObj = frm->nextTextObject();
2468 if(newObj && newObj->nextTextObject()->textObject()->needSpellCheck())
2469 return frm;
2470 }
2471 }
2472 else
2473 {
2474 KPrObject *frm=0L;
2475 for ( frm=m_objectList.at(0); frm != 0; frm=m_objectList.next() )
2476 {
2477 KPrTextObject *newObj = frm->nextTextObject();
2478 if(newObj && newObj->nextTextObject()->textObject()->needSpellCheck())
2479 return frm;
2480 }
2481 }
2482 return 0L;
2483}
2484
2485bool KPrPage::findTextObject( KPrObject *obj )
2486{
2487 return (m_objectList.findRef( obj )>=0 );
2488}
2489
2490void KPrPage::getAllObjectSelectedList(TQPtrList<KPrObject> &lst, bool force )
2491{
2492 TQPtrListIterator<KPrObject> it( m_objectList );
2493 for ( ; it.current() ; ++it )
2494 it.current()->getAllObjectSelectedList( lst,force );
2495}
2496
2497void KPrPage::getAllEmbeddedObjectSelected(TQPtrList<KoDocumentChild> &embeddedObjects )
2498{
2499 TQPtrListIterator<KPrObject> it( m_objectList );
2500 for ( ; it.current() ; ++it )
2501 {
2502 if ( it.current()->isSelected() && it.current()->getType() == OT_PART )
2503 embeddedObjects.append( static_cast<KPrPartObject *>(it.current())->getChild() );
2504 }
2505}
2506
2507KPrPixmapObject* KPrPage::getSelectedImage() const
2508{
2509 KPrPixmapObject *obj=0L;
2510 TQPtrListIterator<KPrObject> it( m_objectList );
2511 for ( ; it.current() ; ++it )
2512 {
2513 if ( it.current()->isSelected() && it.current()->getType() == OT_PICTURE )
2514 {
2515 obj=dynamic_cast<KPrPixmapObject*>(it.current());
2516 break;
2517 }
2518 }
2519 return obj;
2520}
2521
2522KCommand * KPrPage::setImageEffect(ImageEffect eff, TQVariant param1, TQVariant param2, TQVariant param3)
2523{
2524 bool changed = false;
2525 KPrImageEffectCmd *imageEffectCmd = 0L;
2526 TQPtrList<KPrObject> _objects;
2527 TQPtrList<KPrImageEffectCmd::ImageEffectSettings> _oldSettings;
2528 KPrImageEffectCmd::ImageEffectSettings _newSettings, *tmp;
2529
2530 _objects.setAutoDelete( false );
2531 _oldSettings.setAutoDelete( false );
2532
2533 _newSettings.effect = eff;
2534 _newSettings.param1 = param1;
2535 _newSettings.param2 = param2;
2536 _newSettings.param3 = param3;
2537
2538 TQPtrListIterator<KPrObject> it( m_objectList );
2539 for ( ; it.current(); ++it ) {
2540 if ( it.current()->getType() == OT_PICTURE && it.current()->isSelected()) {
2541 tmp = new KPrImageEffectCmd::ImageEffectSettings;
2542 tmp->effect = static_cast<KPrPixmapObject*>(it.current())->getImageEffect();
2543 tmp->param1 = static_cast<KPrPixmapObject*>(it.current())->getIEParam1();
2544 tmp->param2 = static_cast<KPrPixmapObject*>(it.current())->getIEParam2();
2545 tmp->param3 = static_cast<KPrPixmapObject*>(it.current())->getIEParam3();
2546 _oldSettings.append( tmp );
2547 _objects.append( it.current() );
2548
2549 if( !changed && ( tmp->effect != _newSettings.effect
2550 || tmp->param1 != _newSettings.param1
2551 || tmp->param2 != _newSettings.param2
2552 || tmp->param3 != _newSettings.param3 ) )
2553 changed = true;
2554 }
2555 }
2556
2557 if ( !_objects.isEmpty() && changed ) {
2558 imageEffectCmd = new KPrImageEffectCmd( i18n( "Change Image Effect" ), _oldSettings, _newSettings,
2559 _objects, m_doc );
2560 imageEffectCmd->execute();
2561 }
2562 else {
2563 _oldSettings.setAutoDelete( true );
2564 _oldSettings.clear();
2565 }
2566
2567 m_doc->setModified( true );
2568
2569 return imageEffectCmd;
2570}
2571
2572void KPrPage::setHeader( bool b, bool _updateDoc )
2573{
2574 m_bHasHeader = b;
2575 if ( _updateDoc )
2576 m_doc->setHeader(b);
2577}
2578
2579void KPrPage::setFooter( bool b, bool _updateDoc )
2580{
2581 m_bHasFooter = b;
2582 if ( _updateDoc )
2583 m_doc->setFooter( b );
2584}
2585
2586void KPrPage::setUseMasterBackground( bool useMasterBackground )
2587{
2588 m_useMasterBackground = useMasterBackground;
2589}
2590
2591bool KPrPage::useMasterBackground() const
2592{
2593 return m_useMasterBackground;
2594}
2595
2596bool KPrPage::isMasterPage() const
2597{
2598 return ( m_masterPage==0 );
2599}
2600
2601void KPrPage::setDisplayObjectFromMasterPage( bool _b )
2602{
2603 m_displayObjectFromMasterPage = _b;
2604 m_doc->setDisplayObjectMasterPage( _b );
2605}
2606
2607void KPrPage::setDisplayBackground( bool _b )
2608{
2609 m_displayBackground = _b;
2610 m_doc->setDisplayBackground( _b );
2611}
2612
2613