00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <kurl.h>
00023
00024 #include "KPrPage.h"
00025 #include "KPrView.h"
00026 #include "KPrPageIface.h"
00027
00028 #include "KPrBackground.h"
00029 #include "KPrLineObject.h"
00030 #include "KPrRectObject.h"
00031 #include "KPrEllipseObject.h"
00032 #include "KPrAutoformObject.h"
00033 #include "KPrTextObject.h"
00034 #include "KPrPixmapObject.h"
00035 #include "KPrPieObject.h"
00036 #include "KPrPartObject.h"
00037 #include "KPrGroupObject.h"
00038 #include "KPrCommand.h"
00039 #include "KPrFreehandObject.h"
00040 #include "KPrPolylineObject.h"
00041 #include "KPrBezierCurveObject.h"
00042 #include "KPrPolygonObject.h"
00043 #include "KPrClosedLineObject.h"
00044 #include "KPrUtils.h"
00045 #include <kdebug.h>
00046 #include <KoQueryTrader.h>
00047 #include "KPrDocument.h"
00048
00049 #include <KoStore.h>
00050 #include <KoStoreDevice.h>
00051 #include <KoTextZoomHandler.h>
00052 #include <KoXmlNS.h>
00053 #include "KoPointArray.h"
00054 #include "KPrTextDocument.h"
00055 #include <KoTextObject.h>
00056 #include <KoTextParag.h>
00057 #include <KoRect.h>
00058 #include <qapplication.h>
00059 #include <KoStyleCollection.h>
00060 #include <KoVariable.h>
00061 #include <KoGenStyles.h>
00062 #include <KoXmlWriter.h>
00063 #include <ktempfile.h>
00064 #include <qbuffer.h>
00065 #include <qregexp.h>
00066 #include <qfile.h>
00067
00068 struct listAnimation {
00069 KPrObject *obj;
00070 int objIndex;
00071 bool appear;
00072 };
00073
00074 typedef QMap<int, QPtrList<listAnimation> > lstMap;
00075
00076
00077 KPrPage::KPrPage(KPrDocument *_doc, KPrPage *masterPage )
00078 : m_doc( _doc )
00079 , m_masterPage( masterPage )
00080 , m_dcop( 0 )
00081 , m_selectedSlides( true )
00082 , m_bHasHeader( false )
00083 , m_bHasFooter( false )
00084 , m_useMasterBackground( false )
00085 , m_displayObjectFromMasterPage( true )
00086 , m_displayBackground( true )
00087 , m_pageEffect( PEF_NONE )
00088 , m_pageEffectSpeed( ES_MEDIUM )
00089 , m_soundEffect( false )
00090 , m_soundFileName( QString::null )
00091 , m_pageTimer( 1 )
00092 {
00093 kdDebug(33001)<<"create page : KPrPage::KPrPage(KPrDocument *_doc )"<<this<<endl;
00094 m_objectList.setAutoDelete( false );
00095
00096 m_kpbackground= new KPrBackGround( this );
00097
00098
00099
00100 }
00101
00102 KPrPage::~KPrPage()
00103 {
00104 kdDebug(33001)<<"Delete page :KPrPage::~KPrPage() :"<<this<<endl;
00105
00106 m_objectList.setAutoDelete( true );
00107 m_objectList.clear();
00108 delete m_kpbackground;
00109 delete m_dcop;
00110 }
00111
00112 DCOPObject* KPrPage::dcopObject()
00113 {
00114 if ( !m_dcop ) {
00115
00116
00117 int pgnum = m_doc->pageList().findRef( this );
00118 m_dcop = new KPrPageIface( this, pgnum );
00119 }
00120
00121 return m_dcop;
00122 }
00123
00124
00125 void KPrPage::saveOasisObject( KoStore *store, KoXmlWriter &xmlWriter, KoSavingContext& context, int & indexObj, int &partIndexObj, KoXmlWriter* manifestWriter ) const
00126 {
00127 Q_UNUSED( store );
00128 Q_UNUSED( manifestWriter );
00129 KPrObject::KPOasisSaveContext sc( xmlWriter, context, indexObj, partIndexObj, isMasterPage() );
00130
00131 KTempFile animationTmpFile;
00132 animationTmpFile.setAutoDelete( true );
00133 QFile* tmpFile = animationTmpFile.file();
00134 KoXmlWriter animationTmpWriter( tmpFile );
00135 lstMap listObjectAnimation;
00136 QPtrListIterator<KPrObject> it( m_objectList );
00137 for ( ; it.current() ; ++it )
00138 {
00139 if ( it.current()== m_doc->header() || it.current()== m_doc->footer())
00140 continue;
00141 it.current()->saveOasisObject( sc );
00142
00143 if ( it.current()->hasAnimation() )
00144 {
00145 if ( it.current()->getEffect() != EF_NONE ||
00146 it.current()->getAppearStep() != 0 ||
00147 !it.current()->getAppearSoundEffectFileName().isEmpty() )
00148 {
00149 kdDebug(33001) << "has animation" << endl;
00150 listAnimation *lstappear = new listAnimation;
00151 lstappear->obj = it.current();
00152 lstappear->objIndex = indexObj;
00153 lstappear->appear = true;
00154
00155 lstMap::Iterator tmp = listObjectAnimation.find( it.current()->getAppearStep() );
00156 if ( tmp!= listObjectAnimation.end() )
00157 {
00158
00159 tmp.data().append( lstappear );
00160 }
00161 else
00162 {
00163
00164 QPtrList<listAnimation> tmp2;
00165 tmp2.append( lstappear );
00166 listObjectAnimation.insert( it.current()->getAppearStep(), tmp2 );
00167 }
00168 }
00169 if ( it.current()->getEffect3() != EF3_NONE ||
00170 it.current()->getDisappear() ||
00171 ! it.current()->getDisappearSoundEffectFileName().isEmpty())
00172 {
00173 listAnimation *lstappear = new listAnimation;
00174 lstappear->obj = it.current();
00175 lstappear->objIndex = indexObj;
00176 lstappear->appear = false;
00177
00178 lstMap::Iterator tmp = listObjectAnimation.find( it.current()->getDisappearStep() );
00179 if ( tmp!= listObjectAnimation.end() )
00180 {
00181
00182 tmp.data().append( lstappear );
00183 }
00184 else
00185 {
00186
00187 QPtrList<listAnimation> tmp2;
00188 tmp2.append( lstappear );
00189 listObjectAnimation.insert( it.current()->getDisappearStep(), tmp2 );
00190 }
00191 }
00192
00193 }
00194 ++indexObj;
00195 }
00196
00197 if ( !listObjectAnimation.isEmpty() )
00198 {
00199 kdDebug()<<"! listObjectAnimation.isEmpty() :"<<listObjectAnimation.count()<<endl;
00200 animationTmpWriter.startElement( "presentation:animations" );
00201 lstMap::Iterator it = listObjectAnimation.begin();
00202 lstMap::Iterator end = listObjectAnimation.end();
00203 for (; it != end; ++it )
00204 {
00205 if ( it.data().count() == 1 )
00206 {
00207 kdDebug()<<" add unique element \n";
00208 if ( it.data().at( 0 )->appear )
00209 it.data().at( 0 )->obj->saveOasisObjectStyleShowAnimation( animationTmpWriter, it.data().at( 0 )->objIndex );
00210 else
00211 it.data().at( 0 )->obj->saveOasisObjectStyleHideAnimation( animationTmpWriter, it.data().at( 0 )->objIndex );
00212 }
00213 else if ( it.data().count() > 1 )
00214 {
00215 QPtrList<listAnimation> list = it.data();
00216 animationTmpWriter.startElement( "presentation:animation-group" );
00217 for ( uint i = 0; i < list.count(); ++i )
00218 {
00219 if ( list.at(i) )
00220 {
00221 kdDebug()<<" add group element : "<<i<<endl;
00222 if ( list.at(i)->appear )
00223 list.at(i)->obj->saveOasisObjectStyleShowAnimation( animationTmpWriter, list.at(i)->objIndex );
00224 else
00225 list.at(i)->obj->saveOasisObjectStyleHideAnimation( animationTmpWriter, list.at(i)->objIndex );
00226 }
00227 }
00228 animationTmpWriter.endElement();
00229 }
00230
00231 }
00232 animationTmpWriter.endElement();
00233 tmpFile->close();
00234 xmlWriter.addCompleteElement( tmpFile );
00235
00236 }
00237 else
00238 tmpFile->close();
00239 animationTmpFile.close();
00240 }
00241
00242 void KPrPage::load( const QDomElement &element )
00243 {
00244 m_kpbackground->load( element );
00245 QDomElement e=element.namedItem("PGEFFECT").toElement();
00246 if(!e.isNull()) {
00247 int tmp=0;
00248 if(e.hasAttribute("value"))
00249 tmp=e.attribute("value").toInt();
00250 setPageEffect(static_cast<PageEffect>(tmp));
00251 tmp = (int)ES_MEDIUM;
00252 if(e.hasAttribute("speed"))
00253 tmp=e.attribute("speed").toInt();
00254 setPageEffectSpeed( static_cast<EffectSpeed>(tmp) );
00255 }
00256 e=element.namedItem("PGTIMER").toElement();
00257 if(!e.isNull()) {
00258 int timer = 1;
00259 if(e.hasAttribute("timer"))
00260 timer=e.attribute("timer").toInt();
00261 setPageTimer(timer);
00262 }
00263 else
00264 setPageTimer(1);
00265 e=element.namedItem("PGSOUNDEFFECT").toElement();
00266 if(!e.isNull()) {
00267 if(e.hasAttribute("soundEffect"))
00268 m_soundEffect=static_cast<bool>(e.attribute("soundEffect").toInt());
00269 else
00270 m_soundEffect=false;
00271
00272 if(e.hasAttribute("soundFileNmae"))
00273 m_soundFileName=e.attribute("soundFileNmae");
00274 else
00275 m_soundFileName=e.attribute("soundFileName");
00276 }
00277 else {
00278 m_soundFileName=QString::null;
00279 }
00280
00281 e=element.namedItem("HEADERFOOTER").toElement();
00282 if(!e.isNull()) {
00283 if(e.hasAttribute("header"))
00284 m_bHasHeader =static_cast<bool>(e.attribute("header").toInt());
00285 else
00286 m_bHasHeader = false;
00287
00288 if(e.hasAttribute("footer"))
00289 m_bHasFooter =static_cast<bool>(e.attribute("footer").toInt());
00290 else
00291 m_bHasFooter = false;
00292 }
00293 }
00294
00295
00296 void KPrPage::loadOasis(KoOasisContext & context )
00297 {
00298 m_kpbackground->loadOasis( context );
00299
00300 KoStyleStack& styleStack = context.styleStack();
00301 kdDebug()<<"KPrPage::loadOasis()\n";
00302 styleStack.setTypeProperties( "drawing-page" );
00303
00304 if ( !isMasterPage() )
00305 {
00306 if ( !styleStack.hasAttributeNS( KoXmlNS::draw, "fill" ) )
00307 {
00308
00309 m_useMasterBackground = true;
00310 }
00311
00312 if ( styleStack.hasAttributeNS( KoXmlNS::presentation, "background-objects-visible" ) )
00313 {
00314 const QString str = styleStack.attributeNS( KoXmlNS::presentation, "background-objects-visible" );
00315 m_displayObjectFromMasterPage = ( str == "true" ) ? true : false;
00316 }
00317
00318 if ( styleStack.hasAttributeNS( KoXmlNS::presentation, "background-visible" ) )
00319 {
00320 const QString str = styleStack.attributeNS( KoXmlNS::presentation, "background-visible" );
00321 m_displayBackground = ( str == "true" ) ? true : false;
00322 }
00323
00324 if ( styleStack.hasAttributeNS( KoXmlNS::presentation, "visibility" ) )
00325 {
00326 const QString str = styleStack.attributeNS( KoXmlNS::presentation, "visibility" );
00327 if ( str=="hidden" )
00328 slideSelected( false );
00329 else
00330 kdDebug()<<" presentation:visibility parameter not implemented :"<<str<<endl;
00331 }
00332
00333 if ( styleStack.hasAttributeNS( KoXmlNS::presentation, "transition-speed" ) )
00334 {
00335
00336
00337 QString speed = styleStack.attributeNS( KoXmlNS::presentation, "transition-speed" );
00338 if ( speed == "slow" )
00339 {
00340 m_pageEffectSpeed = ES_SLOW;
00341 }
00342 else if ( speed == "medium" )
00343 {
00344 m_pageEffectSpeed = ES_MEDIUM;
00345 }
00346 else if ( speed == "fast" )
00347 {
00348 m_pageEffectSpeed = ES_FAST;
00349 }
00350 else
00351 kdDebug()<<" transition-speed not defined :"<<speed<<endl;
00352 }
00353 if ( styleStack.hasAttributeNS( KoXmlNS::presentation, "duration" ))
00354 {
00355 m_pageTimer = loadOasisTimer( styleStack.attributeNS( KoXmlNS::presentation, "duration") );
00356 }
00357 if ( styleStack.hasAttributeNS( KoXmlNS::presentation, "transition-type" ) )
00358 {
00359
00360
00361 kdDebug()<<" presentation:transition-type :"<<styleStack.attributeNS( KoXmlNS::presentation, "transition-type" )<<endl;
00362 }
00363 if ( styleStack.hasAttributeNS( KoXmlNS::presentation, "display-header" ) )
00364 {
00365 QString tmp = styleStack.attributeNS( KoXmlNS::presentation, "display-header" );
00366 setHeader( tmp =="true" ? true : false );
00367 }
00368 if ( styleStack.hasAttributeNS( KoXmlNS::presentation, "display-footer" ) )
00369 {
00370 QString tmp = styleStack.attributeNS( KoXmlNS::presentation, "display-footer" );
00371 setFooter(tmp =="true" ? true : false);
00372 }
00373
00374 if ( styleStack.hasAttributeNS( KoXmlNS::presentation, "transition-style"))
00375 {
00376
00377 const QString effect = styleStack.attributeNS( KoXmlNS::presentation, "transition-style");
00378 QString additionalEffect;
00379 if ( styleStack.hasAttributeNS( KoXmlNS::koffice, "additional-transition-style" ) )
00380 {
00381 additionalEffect = styleStack.attributeNS( KoXmlNS::koffice, "additional-transition-style" );
00382 }
00383 kdDebug() << "Transition name: " << effect << "additional name: " << additionalEffect << endl;
00384 PageEffect pef;
00385 if ( effect=="none" )
00386 pef=PEF_NONE;
00387 else if (effect=="vertical-stripes" || effect=="vertical-lines")
00388 pef=PEF_BLINDS_VER;
00389 else if (effect=="horizontal-stripes" || effect=="horizontal-lines")
00390 pef=PEF_BLINDS_HOR;
00391 else if (effect=="spiralin-left" || effect=="spiralin-right"
00392 || effect== "spiralout-left" || effect=="spiralout-right")
00393 pef=PEF_SURROUND1;
00394 else if (effect=="fade-from-top")
00395 pef=PEF_COVER_DOWN;
00396 else if (effect=="fade-from-bottom")
00397 pef=PEF_COVER_UP;
00398 else if (effect=="fade-from-left")
00399 pef=PEF_COVER_RIGHT;
00400 else if (effect=="fade-from-right")
00401 pef=PEF_COVER_LEFT;
00402 else if (effect=="fade-from-lowerleft")
00403 {
00404 if ( additionalEffect.isEmpty() )
00405 pef=PEF_COVER_RIGHT_UP;
00406 else
00407 pef=PEF_STRIPS_RIGHT_UP;
00408 }
00409 else if (effect=="fade-from-lowerright")
00410 {
00411 if ( additionalEffect.isEmpty() )
00412 pef=PEF_COVER_LEFT_UP;
00413 else
00414 pef=PEF_STRIPS_LEFT_UP;
00415 }
00416 else if (effect=="fade-from-upperleft")
00417 {
00418 if ( additionalEffect.isEmpty() )
00419 pef=PEF_COVER_RIGHT_DOWN;
00420 else
00421 pef=PEF_STRIPS_RIGHT_DOWN;
00422 }
00423 else if (effect=="fade-from-upperright")
00424 {
00425 if ( additionalEffect.isEmpty() )
00426 pef=PEF_COVER_LEFT_DOWN;
00427 else
00428 pef=PEF_STRIPS_LEFT_DOWN;
00429 }
00430 else if (effect=="fade-to-center")
00431 pef=PEF_BOX_IN;
00432 else if (effect=="fade-from-center")
00433 pef=PEF_BOX_OUT;
00434 else if (effect=="open-vertical")
00435 pef=PEF_OPEN_HORZ;
00436 else if (effect=="open-horizontal")
00437 pef=PEF_OPEN_VERT;
00438 else if (effect=="open")
00439 pef=PEF_OPEN_ALL;
00440 else if (effect=="close-vertical")
00441 pef=PEF_CLOSE_HORZ;
00442 else if (effect=="close-horizontal")
00443 pef=PEF_CLOSE_VERT;
00444 else if (effect=="close")
00445 pef=PEF_CLOSE_ALL;
00446 else if (effect=="dissolve")
00447 pef=PEF_DISSOLVE;
00448 else if (effect=="horizontal-checkerboard")
00449 pef=PEF_CHECKBOARD_ACROSS;
00450 else if (effect=="vertical-checkerboard")
00451 pef=PEF_CHECKBOARD_DOWN;
00452 else if (effect=="uncover-to-right" || effect=="roll-from-left")
00453 pef=PEF_UNCOVER_RIGHT;
00454 else if (effect=="uncover-to-left" || effect=="roll-from-right")
00455 pef=PEF_UNCOVER_LEFT;
00456 else if (effect=="uncover-to-top" || effect=="roll-from-bottom")
00457 pef=PEF_UNCOVER_UP;
00458 else if (effect=="uncover-to-bottom" || effect=="roll-from-top")
00459 pef=PEF_UNCOVER_DOWN;
00460 else if (effect=="uncover-to-upperleft")
00461 pef=PEF_UNCOVER_LEFT_UP;
00462 else if (effect=="uncover-to-upperright")
00463 pef=PEF_UNCOVER_RIGHT_UP;
00464 else if (effect=="uncover-to-lowerleft")
00465 pef=PEF_UNCOVER_LEFT_DOWN;
00466 else if (effect=="uncover-to-lowerright")
00467 pef=PEF_UNCOVER_RIGHT_DOWN;
00468 else if (effect=="interlocking-horizontal-left")
00469 pef=PEF_INTERLOCKING_HORZ_1;
00470 else if (effect=="interlocking-horizontal-right")
00471 pef=PEF_INTERLOCKING_HORZ_2;
00472 else if (effect=="interlocking-vertical-top")
00473 pef=PEF_INTERLOCKING_VERT_1;
00474 else if (effect=="interlocking-vertical-bottom")
00475 pef=PEF_INTERLOCKING_VERT_2;
00476 else if ( effect=="melt" )
00477 pef=PEF_MELTING;
00478 else if ( effect=="fly-away" )
00479 pef=PEF_FLY1;
00480 else if ( effect=="random" )
00481 pef=PEF_RANDOM;
00482 else
00483 pef=PEF_RANDOM;
00484 setPageEffect( pef );
00485 }
00486 if ( styleStack.hasChildNodeNS( KoXmlNS::presentation, "sound"))
00487 {
00488
00489 QDomElement sound = styleStack.childNodeNS( KoXmlNS::presentation, "sound");
00490 m_soundEffect = true;
00491 m_soundFileName = sound.attributeNS( KoXmlNS::xlink, "href", QString::null );
00492 }
00493 }
00494 }
00495
00496 QDomElement KPrPage::save( QDomDocument &doc )
00497 {
00498 QDomElement page = m_kpbackground->save( doc );
00499 QDomElement element;
00500
00501 if ( m_pageEffect != PEF_NONE) {
00502 element = doc.createElement("PGEFFECT");
00503 element.setAttribute("value", static_cast<int>( m_pageEffect ));
00504 element.setAttribute("speed", static_cast<int>( m_pageEffectSpeed ));
00505 page.appendChild(element);
00506 }
00507
00508 if ( m_pageTimer != 1 ) {
00509 element = doc.createElement( "PGTIMER" );
00510 element.setAttribute( "timer", m_pageTimer );
00511 page.appendChild( element );
00512 }
00513
00514 if ( m_soundEffect || !m_soundFileName.isEmpty() ) {
00515 element = doc.createElement( "PGSOUNDEFFECT" );
00516 element.setAttribute( "soundEffect", static_cast<int>(m_soundEffect) );
00517 element.setAttribute( "soundFileName", m_soundFileName );
00518 page.appendChild( element );
00519 }
00520 element = doc.createElement( "HEADERFOOTER" );
00521 element.setAttribute( "header", static_cast<int>(m_bHasHeader ) );
00522 element.setAttribute( "footer", static_cast<int>(m_bHasFooter ) );
00523 page.appendChild( element );
00524 return page;
00525 }
00526
00527 QString KPrPage::oasisNamePage( int posPage ) const
00528 {
00529 return ( m_manualTitle.isEmpty() ? QString( "page%1" ).arg( posPage ) : m_manualTitle );
00530 }
00531
00532 bool KPrPage::saveOasisPage( KoStore *store, KoXmlWriter &xmlWriter, int posPage, KoSavingContext& context,
00533 int & indexObj, int &partIndexObj, KoXmlWriter* manifestWriter, QMap<QString, int> &pageNames ) const
00534 {
00535 if ( isMasterPage() )
00536 {
00537 KoGenStyle pageLayout = m_doc->pageLayout().saveOasis();
00538 pageLayout.addAttribute( "style:page-usage", "all" );
00539 QString pageLayoutName( context.mainStyles().lookup( pageLayout, "pm" ) );
00540
00541 xmlWriter.startElement( "style:master-page" );
00542 xmlWriter.addAttribute( "style:name", "Standard" );
00543 xmlWriter.addAttribute( "style:page-layout-name", pageLayoutName );
00544
00545 QString styleName = saveOasisPageStyle( store, context.mainStyles() );
00546 if ( !styleName.isEmpty() )
00547 xmlWriter.addAttribute( "draw:style-name", styleName );
00548
00549 saveOasisObject( store, xmlWriter, context, indexObj,partIndexObj, manifestWriter );
00550
00551 xmlWriter.startElement( "style:header" );
00552 m_doc->header()->textObject()->saveOasisContent( xmlWriter, context );
00553 xmlWriter.endElement();
00554
00555 xmlWriter.startElement( "style:footer" );
00556 m_doc->footer()->textObject()->saveOasisContent( xmlWriter, context );
00557 xmlWriter.endElement();
00558
00559 xmlWriter.endElement();
00560 }
00561 else
00562 {
00563
00564 xmlWriter.startElement( "draw:page" );
00565
00566 QString drawName( m_manualTitle );
00567 QRegExp rx( "^page[0-9]+$" );
00568 if ( drawName.isEmpty() || pageNames.contains( drawName ) || rx.search( drawName ) != -1 )
00569 {
00570 drawName = "page" + QString::number( posPage );
00571 }
00572 pageNames.insert( drawName, posPage );
00573 xmlWriter.addAttribute( "draw:name", drawName );
00574 xmlWriter.addAttribute( "koffice:name", m_manualTitle );
00575 xmlWriter.addAttribute( "draw:id", "page" + QString::number( posPage ) );
00576 xmlWriter.addAttribute( "draw:master-page-name", "Standard");
00577
00578 QString styleName = saveOasisPageStyle( store, context.mainStyles() );
00579 kdDebug()<<" styleName :"<<styleName<<endl;
00580 if ( !styleName.isEmpty() )
00581 xmlWriter.addAttribute( "draw:style-name", styleName );
00582
00583 saveOasisObject( store, xmlWriter, context, indexObj,partIndexObj, manifestWriter );
00584
00585 saveOasisNote( xmlWriter );
00586 xmlWriter.endElement();
00587 }
00588 return true;
00589 }
00590
00591 QString KPrPage::saveOasisPageStyle( KoStore *, KoGenStyles& mainStyles ) const
00592 {
00593 KoGenStyle stylepageauto( isMasterPage() ? KPrDocument::STYLE_BACKGROUNDPAGE : KPrDocument::STYLE_BACKGROUNDPAGEAUTO, "drawing-page" );
00594
00595 if ( ! isMasterPage() )
00596 {
00597 stylepageauto.addProperty( "presentation:background-visible", ( m_displayBackground == true ) ? "true" : "false" );
00598 stylepageauto.addProperty( "presentation:background-objects-visible", ( m_displayObjectFromMasterPage == true ) ? "true" : "false" );
00599 QString transition = saveOasisPageEffect();
00600 if ( !transition.isEmpty() )
00601 {
00602 stylepageauto.addProperty( "presentation:transition-style", transition );
00603 QString additionalTransition = saveOasisAdditionalPageEffect();
00604 if ( !additionalTransition.isEmpty() )
00605 {
00606 stylepageauto.addProperty( "koffice:additional-transition-style", additionalTransition );
00607 }
00608 }
00609 stylepageauto.addProperty( "presentation:display-header", hasHeader());
00610 stylepageauto.addProperty( "presentation:display-footer", hasFooter());
00611
00612 if ( m_pageTimer != 1 )
00613 {
00614 stylepageauto.addProperty("presentation:duration", saveOasisTimer( m_pageTimer ));
00615
00616
00617 stylepageauto.addProperty( "presentation:transition-type", "automatic" );
00618 }
00619 if ( m_pageEffectSpeed != ES_MEDIUM )
00620 {
00621 if ( m_pageEffectSpeed == ES_FAST )
00622 stylepageauto.addProperty( "presentation:transition-speed", "fast" );
00623 else if ( m_pageEffectSpeed == ES_SLOW )
00624 stylepageauto.addProperty( "presentation:transition-speed", "slow" );
00625 }
00626 if ( !isSlideSelected() )
00627 stylepageauto.addProperty( "presentation:visibility", "hidden" );
00628 if ( !m_soundFileName.isEmpty() && m_soundEffect )
00629 {
00630 QBuffer buffer;
00631 buffer.open( IO_WriteOnly );
00632 KoXmlWriter elementWriter( &buffer );
00633 elementWriter.startElement( "presentation:sound" );
00634 elementWriter.addAttribute( "xlink:href", m_soundFileName );
00635 elementWriter.addAttribute( "xlink:type", "simple" );
00636 elementWriter.addAttribute( "xlink:show", "new" );
00637 elementWriter.addAttribute( "xlink:actuate", "onRequest");
00638
00639 elementWriter.endElement();
00640 QString elementContents = QString::fromUtf8( buffer.buffer(), buffer.buffer().size() );
00641 stylepageauto.addChildElement( "sound effect", elementContents );
00642 }
00643 }
00644
00645 if ( ! m_useMasterBackground )
00646 {
00647 m_kpbackground->saveOasisBackgroundPageStyle( stylepageauto, mainStyles );
00648 }
00649
00650
00651 return mainStyles.lookup( stylepageauto, "dp" );
00652 }
00653
00654 bool KPrPage::saveOasisNote( KoXmlWriter &xmlWriter ) const
00655 {
00656 if ( m_noteText.isEmpty() )
00657 return true;
00658
00659
00660
00661 xmlWriter.startElement( "presentation:notes" );
00662 xmlWriter.startElement( "draw:frame" );
00663
00664
00665 xmlWriter.startElement( "draw:text-box" );
00666 QStringList text = QStringList::split( "\n", m_noteText );
00667 for ( QStringList::Iterator it = text.begin(); it != text.end(); ++it ) {
00668 xmlWriter.startElement( "text:p" );
00669 xmlWriter.addTextNode( *it );
00670 xmlWriter.endElement();
00671 }
00672 xmlWriter.endElement();
00673 xmlWriter.endElement();
00674 xmlWriter.endElement();
00675
00676 return true;
00677 }
00678
00679 QString KPrPage::saveOasisPageEffect() const
00680 {
00681 QString transition;
00682 switch( m_pageEffect )
00683 {
00684 case PEF_NONE:
00685 transition="none";
00686 break;
00687 case PEF_CLOSE_HORZ:
00688 transition="close-vertical";
00689 break;
00690 case PEF_CLOSE_VERT:
00691 transition="close-horizontal";
00692 break;
00693 case PEF_CLOSE_ALL:
00694 transition="close";
00695 break;
00696 case PEF_OPEN_HORZ:
00697 transition="open-vertical";
00698 break;
00699 case PEF_OPEN_VERT:
00700 transition="open-horizontal";
00701 break;
00702 case PEF_OPEN_ALL:
00703 transition="open";
00704 break;
00705 case PEF_INTERLOCKING_HORZ_1:
00706 transition="interlocking-horizontal-left";
00707 break;
00708 case PEF_INTERLOCKING_HORZ_2:
00709 transition="interlocking-horizontal-right";
00710 break;
00711 case PEF_INTERLOCKING_VERT_1:
00712 transition="interlocking-vertical-top";
00713 break;
00714 case PEF_INTERLOCKING_VERT_2:
00715 transition="interlocking-vertical-bottom";
00716 break;
00717 case PEF_SURROUND1:
00718 transition="spiralin-left";
00719 break;
00720 case PEF_FLY1:
00721 transition="fly-away";
00722 break;
00723 case PEF_BLINDS_HOR:
00724 transition="horizontal-stripes";
00725 break;
00726 case PEF_BLINDS_VER:
00727 transition="vertical-stripes";
00728 break;
00729 case PEF_BOX_IN:
00730 transition="fade-to-center";
00731 break;
00732 case PEF_BOX_OUT:
00733 transition="fade-from-center";
00734 break;
00735 case PEF_CHECKBOARD_ACROSS:
00736 transition="horizontal-checkerboard";
00737 break;
00738 case PEF_CHECKBOARD_DOWN:
00739 transition="vertical-checkerboard";
00740 break;
00741 case PEF_COVER_DOWN:
00742 transition="fade-from-top";
00743 break;
00744 case PEF_COVER_UP:
00745 transition="fade-from-bottom";
00746 break;
00747 case PEF_COVER_LEFT:
00748 transition="fade-from-right";
00749 break;
00750 case PEF_COVER_RIGHT:
00751 transition="fade-from-left";
00752 break;
00753 case PEF_COVER_LEFT_UP:
00754 transition="fade-from-lowerright";
00755 break;
00756 case PEF_COVER_LEFT_DOWN:
00757 transition="fade-from-upperright";
00758 break;
00759 case PEF_COVER_RIGHT_UP:
00760 transition="fade-from-lowerleft";
00761 break;
00762 case PEF_COVER_RIGHT_DOWN:
00763 transition="fade-from-upperleft";
00764 break;
00765 case PEF_UNCOVER_LEFT:
00766 transition="uncover-to-left";
00767 break;
00768 case PEF_UNCOVER_UP:
00769 transition="uncover-to-top";
00770 break;
00771 case PEF_UNCOVER_RIGHT:
00772 transition="uncover-to-right";
00773 break;
00774 case PEF_UNCOVER_DOWN:
00775 transition="uncover-to-bottom";
00776 break;
00777 case PEF_UNCOVER_LEFT_UP:
00778 transition="uncover-to-upperleft";
00779 break;
00780 case PEF_UNCOVER_LEFT_DOWN:
00781 transition="uncover-to-lowerleft";
00782 break;
00783 case PEF_UNCOVER_RIGHT_UP:
00784 transition="uncover-to-upperright";
00785 break;
00786 case PEF_UNCOVER_RIGHT_DOWN:
00787 transition="uncover-to-lowerright";
00788 break;
00789 case PEF_DISSOLVE:
00790 transition="dissolve";
00791 break;
00792 case PEF_STRIPS_LEFT_UP:
00793 transition="fade-from-lowerright";
00794 break;
00795 case PEF_STRIPS_LEFT_DOWN:
00796 transition="fade-from-upperright";
00797 break;
00798 case PEF_STRIPS_RIGHT_UP:
00799 transition="fade-from-lowerleft";
00800 break;
00801 case PEF_STRIPS_RIGHT_DOWN:
00802 transition="fade-from-upperleft";
00803 break;
00804 case PEF_MELTING:
00805 transition="melt";
00806 break;
00807 case PEF_LAST_MARKER:
00808 break;
00809 case PEF_RANDOM:
00810 transition="random";
00811 break;
00812
00813 }
00814 return transition;
00815 }
00816
00817
00818 QString KPrPage::saveOasisAdditionalPageEffect() const
00819 {
00820 QString additionalEffect;
00821 switch( m_pageEffect )
00822 {
00823 case PEF_STRIPS_LEFT_UP:
00824 additionalEffect="stripe-from-lowerright";
00825 break;
00826 case PEF_STRIPS_LEFT_DOWN:
00827 additionalEffect="stripe-from-upperright";
00828 break;
00829 case PEF_STRIPS_RIGHT_UP:
00830 additionalEffect="stripe-from-lowerleft";
00831 break;
00832 case PEF_STRIPS_RIGHT_DOWN:
00833 additionalEffect="stripe-from-upperleft";
00834 break;
00835 default:
00836 break;
00837 }
00838 return additionalEffect;
00839 }
00840
00841
00842 KPrObject *KPrPage::getObject(int num)
00843 {
00844 Q_ASSERT( num < (int)m_objectList.count() );
00845 return m_objectList.at(num);
00846 }
00847
00848
00849
00850
00851 bool KPrPage::objectNameExists( KPrObject *object, QPtrList<KPrObject> &list ) {
00852 QPtrListIterator<KPrObject> it( list );
00853
00854 for ( it.toFirst(); it.current(); ++it ) {
00855
00856 if ( it.current()->getObjectName() == object->getObjectName() &&
00857 it.current() != object ) {
00858 return true;
00859 }
00860 else if ( it.current()->getType() == OT_GROUP ) {
00861 QPtrList<KPrObject> objectList( static_cast<KPrGroupObject*>(it.current())->getObjects() );
00862 if ( objectNameExists( object, objectList ) ) {
00863 return true;
00864 }
00865 }
00866 }
00867 return false;
00868 }
00869
00870 void KPrPage::unifyObjectName( KPrObject *object ) {
00871 if ( object->getObjectName().isEmpty() ) {
00872 object->setObjectName( object->getTypeString() );
00873 }
00874 QString objectName( object->getObjectName() );
00875
00876 QPtrList<KPrObject> list( m_objectList );
00877
00878 int count = 1;
00879
00880 while ( objectNameExists( object, list ) ) {
00881 count++;
00882 QRegExp rx( " \\(\\d{1,}\\)$" );
00883 if ( rx.search( objectName ) != -1 ) {
00884 objectName.remove( rx );
00885 }
00886 objectName += QString(" (%1)").arg( count );
00887 object->setObjectName( objectName );
00888 }
00889 }
00890
00891 void KPrPage::appendObject(KPrObject *_obj)
00892 {
00893 unifyObjectName(_obj);
00894 m_objectList.append(_obj);
00895 }
00896
00897 void KPrPage::appendObjects( const QValueList<KPrObject *> &objects )
00898 {
00899 QMap <QString, int> usedPageNames;
00900 QPtrListIterator<KPrObject> it( m_objectList );
00901
00902 for ( ; it.current() ; ++it )
00903 {
00904 QString objectName( it.current()->getObjectName() );
00905
00906 QRegExp rx( "(.*) \\((\\d{1,})\\)$" );
00907 rx.setMinimal( true );
00908 if ( rx.search( objectName ) != -1 && rx.numCaptures() == 2 )
00909 {
00910 int id = rx.cap( 2 ).toInt();
00911 if ( usedPageNames[rx.cap( 1 )] < id );
00912 {
00913 usedPageNames[rx.cap( 1 )] = id;
00914 }
00915 }
00916 else
00917 {
00918 usedPageNames[objectName] = 1;
00919 }
00920 }
00921
00922 QValueListConstIterator<KPrObject *> oIt( objects.begin() );
00923 for ( ; oIt != objects.end(); ++oIt )
00924 {
00925 QString objectName( ( *oIt )->getObjectName() );
00926 QRegExp rx( " \\(\\d{1,}\\)$" );
00927 if ( rx.search( objectName ) != -1 )
00928 {
00929 objectName.remove( rx );
00930 }
00931
00932 if ( usedPageNames.contains( objectName ) )
00933 {
00934 usedPageNames[objectName]++;
00935 objectName += QString(" (%1)").arg( usedPageNames[objectName] );
00936 ( *oIt )->setObjectName( objectName );
00937 }
00938 m_objectList.append( *oIt );
00939 }
00940 }
00941
00942 int KPrPage::takeObject( KPrObject *object )
00943 {
00944 int pos = m_objectList.findRef( object );
00945 m_objectList.take( pos );
00946 return pos;
00947 }
00948
00949 void KPrPage::replaceObject( KPrObject *oldObject, KPrObject *newObject )
00950 {
00951
00952 unsigned int pos = m_objectList.findRef( oldObject );
00953 m_objectList.take( pos );
00954 m_objectList.insert( pos, newObject );
00955 }
00956
00957
00958 void KPrPage::insertObject( KPrObject *object, int pos )
00959 {
00960 unifyObjectName( object );
00961 m_objectList.insert( pos, object );
00962 }
00963
00964 KCommand * KPrPage::deleteSelectedObjects()
00965 {
00966 QPtrList<KPrObject> objects = getSelectedObjects( true );
00967
00968 KPrDeleteCmd *deleteCmd=0L;
00969
00970 if ( objects.count() > 0 ) {
00971 deleteCmd = new KPrDeleteCmd( i18n( "Delete Objects" ), objects, m_doc, this );
00972 deleteCmd->execute();
00973 }
00974 else
00975 m_doc->setModified(true);
00976
00977 return deleteCmd ;
00978 }
00979
00980 void KPrPage::copyObjs(QDomDocument &doc, QDomElement &presenter, QValueList<KoPictureKey> & savePictures) const
00981 {
00982 if ( !numSelected() )
00983 return;
00984
00985 QPtrListIterator<KPrObject> it( m_objectList );
00986 for ( ; it.current() ; ++it )
00987 {
00988 if(it.current()->isSelected())
00989 {
00990 if ( it.current()->getType() == OT_PICTURE )
00991 {
00992 KoPictureKey key = static_cast<KPrPixmapObject *>( it.current() )->getKey();
00993 if ( !savePictures.contains( key ) )
00994 savePictures.append( key );
00995 }
00996 QDomElement object=doc.createElement("OBJECT");
00997 object.setAttribute("type", static_cast<int>( it.current()->getType() ));
00998 object.appendChild(it.current()->save( doc,0 ));
00999 presenter.appendChild(object);
01000 }
01001 }
01002 }
01003
01004 void KPrPage::pasteObjs( const QByteArray & data,int nbCopy, double angle,
01005 double increaseX, double increaseY, double moveX, double moveY )
01006 {
01007 m_doc->deSelectAllObj();
01008 int num = m_objectList.count();
01009 if ( !data.size() )
01010 return;
01011 QBuffer buffer( data );
01012 KoStore* store = KoStore::createStore( &buffer, KoStore::Read );
01013 int nbNewObject = -1 ;
01014 KMacroCommand *macro = 0L;
01015 if ( !store->bad() )
01016 {
01017 if ( store->open( "root" ) )
01018 {
01019 QString errorMsg;
01020 int errorLine;
01021 int errorColumn;
01022 QDomDocument domDoc;
01023 if ( !domDoc.setContent( store->device(), &errorMsg, &errorLine, &errorColumn ) )
01024 {
01025 kdError (30003) << "Parsing Error! Aborting! (in KPrPage::PasteObj)" << endl
01026 << " Line: " << errorLine << " Column: " << errorColumn << endl
01027 << " Message: " << errorMsg << endl;
01028 delete store;
01029 return;
01030 }
01031 QDomElement topElem = domDoc.documentElement();
01032
01033 for ( int i = 0 ; i < nbCopy ; i++ )
01034 {
01035 KCommand *cmd = m_doc->loadPastedObjs( domDoc.toString(),this );
01036 if (cmd )
01037 {
01038 if ( !macro )
01039 macro = new KMacroCommand( i18n("Paste Objects" ));
01040 macro->addCommand( cmd );
01041 }
01042 if ( nbNewObject == -1 )
01043 nbNewObject = m_objectList.count() - num;
01044 }
01045
01046 m_doc->loadPictureMap( topElem );
01047 store->close();
01048 int nbNewPartObject = -1;
01049 int nbElementBefore = m_objectList.count();
01050 for ( int i = 0 ; i < nbCopy ; i++ )
01051 {
01052 m_doc->insertEmbedded( store, topElem, macro, this, num );
01053 if ( nbNewPartObject ==-1 )
01054 nbNewObject = nbNewObject + (m_objectList.count() - nbElementBefore);
01055 }
01056 }
01057 }
01058 delete store;
01059
01060
01061 KPrObject *_tempObj;
01062 int i = 0;
01063 int mod = 1;
01064 for (_tempObj = m_objectList.at(num); _tempObj; _tempObj = m_objectList.next(), i++ ) {
01065 if ( i >= nbNewObject )
01066 mod++;
01067 _tempObj->moveBy( moveX*(double)mod,moveY*(double)mod);
01068 _tempObj->setSelected( true );
01069 if ( angle == 0.0 || (increaseY == 0.0 && increaseX == 0.0))
01070 m_doc->repaint(_tempObj);
01071 }
01072
01073 if ( angle != 0.0)
01074 {
01075 KCommand *cmd = rotateSelectedObjects(angle, true);
01076 if (cmd )
01077 {
01078 if ( !macro )
01079 macro = new KMacroCommand( i18n("Paste Objects" ));
01080 macro->addCommand( cmd );
01081 }
01082 }
01083 if ( increaseX != 0.0 || increaseY != 0.0 )
01084 {
01085 QPtrListIterator<KPrObject> it( m_objectList );
01086 for ( ; it.current() ; ++it )
01087 {
01088 if(it.current()->isSelected())
01089 {
01090 KCommand *cmd =new KPrResizeCmd( i18n("Resize"), KoPoint(0, 0),
01091 KoSize(increaseX, increaseY), it.current(), m_doc );
01092 if ( cmd )
01093 {
01094 cmd->execute();
01095 if ( !macro )
01096 macro = new KMacroCommand( i18n("Paste Objects" ));
01097 macro->addCommand( cmd );
01098 }
01099 }
01100 }
01101 }
01102
01103 if (macro)
01104 m_doc->addCommand(macro);
01105
01106 if ( angle == 0.0 || (increaseY == 0.0 && increaseX == 0.0) )
01107 {
01108 m_doc->updateSideBarItem( this );
01109 }
01110
01111 m_doc->setModified(true);
01112 }
01113
01114 KPrTextObject * KPrPage::textFrameSet ( unsigned int _num ) const
01115 {
01116 unsigned int i = 0;
01117 QPtrListIterator<KPrObject> it( m_objectList );
01118 for ( ; it.current() ; ++it )
01119 {
01120 if(it.current()->getType()==OT_TEXT)
01121 {
01122 if(i==_num)
01123 return static_cast<KPrTextObject*>(it.current());
01124 i++;
01125 }
01126 }
01127 return 0L;
01128 }
01129
01130 int KPrPage::numSelected() const
01131 {
01132 int num = 0;
01133
01134 QPtrListIterator<KPrObject> it( m_objectList );
01135 for ( ; it.current() ; ++it )
01136 {
01137 if(it.current()->isSelected())
01138 num++;
01139 }
01140
01141 return num;
01142 }
01143
01144 int KPrPage::numTextObject() const
01145 {
01146 int num = 0;
01147
01148 QPtrListIterator<KPrObject> it( m_objectList );
01149 for ( ; it.current() ; ++it )
01150 {
01151 if(it.current()->getType()==OT_TEXT)
01152 num++;
01153 }
01154
01155 return num;
01156 }
01157
01158 KPrObject* KPrPage::getSelectedObj() const
01159 {
01160 QPtrListIterator<KPrObject> it( m_objectList );
01161 for ( ; it.current() ; ++it )
01162 {
01163 if(it.current()->isSelected())
01164 return it.current();
01165 }
01166 return 0L;
01167 }
01168
01169
01170 QPtrList<KPrObject> KPrPage::getSelectedObjects( bool withoutHeaderFooter ) const
01171 {
01172 QPtrList<KPrObject> objects;
01173 QPtrListIterator<KPrObject> it( m_objectList );
01174 for ( ; it.current() ; ++it )
01175 {
01176 if( it.current()->isSelected()
01177 && ( !withoutHeaderFooter
01178 || it.current() != m_doc->header() && it.current()!= m_doc->footer() ) )
01179 {
01180 objects.append( it.current() );
01181 }
01182 }
01183 return objects;
01184 }
01185
01186
01187 void KPrPage::groupObjects()
01188 {
01189 QPtrList<KPrObject> objects( getSelectedObjects( true ) );
01190
01191 if ( objects.count() > 1 ) {
01192 KPrGroupObjCmd *groupObjCmd = new KPrGroupObjCmd( i18n( "Group Objects" ), objects, m_doc,this );
01193 m_doc->addCommand( groupObjCmd );
01194 groupObjCmd->execute();
01195 }
01196 }
01197
01198 void KPrPage::ungroupObjects( KMacroCommand ** macro )
01199 {
01200 QPtrList<KPrObject> objects( getSelectedObjects( true ) );
01201 QPtrListIterator<KPrObject> it( objects );
01202 for ( ; it.current() ; ++it )
01203 {
01204 KPrObject *object = it.current();
01205 if ( object->getType() == OT_GROUP )
01206 {
01207 UnGroupObjCmd *cmd = new UnGroupObjCmd( i18n( "Ungroup Objects" ),
01208 (KPrGroupObject*)object, m_doc, this );
01209 cmd->execute();
01210
01211 if ( !*macro )
01212 *macro = new KMacroCommand(i18n( "Ungroup Objects" ));
01213 (*macro)->addCommand( cmd );
01214 }
01215 }
01216 }
01217
01218 void KPrPage::lowerObjs(bool backward)
01219 {
01220 KPrObject *kpobject = 0;
01221
01222 QPtrList<KPrObject> _new;
01223
01224 for ( unsigned int j = 0; j < m_objectList.count(); j++ )
01225 _new.append( m_objectList.at( j ) );
01226
01227 _new.setAutoDelete( false );
01228 bool createCmd = false;
01229 int insertPos = 0;
01230 for ( int i = 0; i < static_cast<int>( _new.count() ); i++ ) {
01231 kpobject = _new.at( i );
01232 if ( kpobject->isSelected() ) {
01233 if ( i == insertPos )
01234 {
01235 ++insertPos;
01236 continue;
01237 }
01238 createCmd = true;
01239 _new.take( i );
01240 if ( backward )
01241 _new.insert(QMAX(i-1,0) , kpobject);
01242 else
01243 _new.insert( insertPos++, kpobject );
01244 }
01245 }
01246 if ( createCmd )
01247 {
01248 KPrLowerRaiseCmd *lrCmd = new KPrLowerRaiseCmd( i18n( "Lower Objects" ), m_objectList, _new, m_doc,this );
01249 lrCmd->execute();
01250 m_doc->addCommand( lrCmd );
01251 }
01252
01253 }
01254
01255 void KPrPage::raiseObjs(bool forward)
01256 {
01257 KPrObject *kpobject = 0;
01258
01259 QPtrList<KPrObject> _new;
01260
01261 for ( unsigned int j = 0; j < m_objectList.count(); j++ )
01262 _new.append( m_objectList.at( j ) );
01263
01264 _new.setAutoDelete( false );
01265 bool createCmd = false;
01266 int size = int( _new.count() );
01267 int insertPos = size - 1;
01268 for ( int i = size - 1; i >= 0; i-- )
01269 {
01270 kpobject = _new.at( i );
01271 if ( kpobject->isSelected() )
01272 {
01273 if ( i == insertPos )
01274 {
01275 --insertPos;
01276 continue;
01277 }
01278 createCmd = true;
01279 _new.take( i );
01280 if ( forward )
01281 _new.insert( QMIN( i+1, size - 1), kpobject);
01282 else
01283 _new.insert( insertPos--, kpobject );
01284 }
01285 }
01286 if ( createCmd )
01287 {
01288 KPrLowerRaiseCmd *lrCmd = new KPrLowerRaiseCmd( i18n( "Raise Objects" ), m_objectList, _new, m_doc,this );
01289 lrCmd->execute();
01290 m_doc->addCommand( lrCmd );
01291 }
01292 }
01293
01294 KCommand *KPrPage::insertObject( const QString &name, KPrObject * object, const KoRect &r, bool addCommand )
01295 {
01296 object->setOrig( r.x(), r.y() );
01297 object->setSize( r.width(), r.height() );
01298 object->setSelected( true );
01299
01300 KPrInsertCmd *insertCmd = new KPrInsertCmd( name, object, m_doc, this );
01301 insertCmd->execute();
01302 if ( addCommand )
01303 {
01304 m_doc->addCommand( insertCmd );
01305 return 0L;
01306 }
01307 return insertCmd;
01308 }
01309
01310 void KPrPage::insertLine( const KoRect &r, const KoPen & pen, LineEnd lb, LineEnd le, LineType lt )
01311 {
01312 KPrLineObject *kplineobject = new KPrLineObject( pen, lb, le, lt );
01313 insertObject( i18n( "Insert Line" ), kplineobject, r );
01314 }
01315
01316 void KPrPage::insertRectangle( const KoRect &r, const KoPen & pen, const QBrush &brush, FillType ft,
01317 const QColor &g1, const QColor &g2,
01318 BCType gt, int rndX, int rndY, bool unbalanced, int xfactor, int yfactor )
01319 {
01320 KPrRectObject *kprectobject = new KPrRectObject( pen, brush, ft, g1, g2, gt, rndX, rndY,
01321 unbalanced, xfactor, yfactor );
01322 insertObject( i18n( "Insert Rectangle" ), kprectobject, r );
01323 }
01324
01325 void KPrPage::insertCircleOrEllipse( const KoRect &r, const KoPen &pen, const QBrush & brush, FillType ft,
01326 const QColor &g1, const QColor &g2,
01327 BCType gt, bool unbalanced, int xfactor, int yfactor )
01328 {
01329 KPrEllipseObject *kpellipseobject = new KPrEllipseObject( pen, brush, ft, g1, g2, gt,
01330 unbalanced, xfactor, yfactor );
01331 insertObject( i18n( "Insert Ellipse" ), kpellipseobject, r );
01332 }
01333
01334 void KPrPage::insertPie( const KoRect &r, const KoPen &pen, const QBrush &brush, FillType ft,
01335 const QColor &g1, const QColor &g2,
01336 BCType gt, PieType pt, int _angle, int _len, LineEnd lb, LineEnd le,
01337 bool unbalanced, int xfactor, int yfactor )
01338 {
01339 KPrPieObject *kppieobject = new KPrPieObject( pen, brush, ft, g1, g2, gt, pt, _angle,
01340 _len, lb, le, unbalanced, xfactor, yfactor );
01341 insertObject( i18n( "Insert Pie/Arc/Chord" ), kppieobject, r );
01342 }
01343
01344 KPrTextObject* KPrPage::insertTextObject( const KoRect& r, const QString& text , KPrView * _view )
01345 {
01346 KPrTextObject *kptextobject = new KPrTextObject( m_doc );
01347 insertObject( i18n( "Insert Textbox" ), kptextobject, r );
01348
01349
01350 if ( !text.isEmpty() )
01351 {
01352 KPrTextView *view = kptextobject->createKPTextView( _view ? _view->getCanvas() : 0L );
01353 view->insertText( text );
01354 view->terminate();
01355 delete view;
01356 m_doc->repaint( kptextobject );
01357 }
01358 return kptextobject;
01359 }
01360
01361 void KPrPage::insertAutoform( const KoRect &r, const KoPen &pen, const QBrush &brush, LineEnd lb, LineEnd le, FillType ft,
01362 const QColor &g1, const QColor &g2, BCType gt, const QString &fileName, bool unbalanced,
01363 int xfactor, int yfactor ){
01364 KPrAutoformObject *kpautoformobject = new KPrAutoformObject( pen, brush, fileName, lb, le, ft,
01365 g1, g2, gt, unbalanced, xfactor, yfactor );
01366 insertObject( i18n( "Insert Autoform" ), kpautoformobject, r );
01367 }
01368
01369 void KPrPage::insertFreehand( const KoPointArray &points, const KoRect &r, const KoPen &pen,
01370 LineEnd lb, LineEnd le )
01371 {
01372 KoSize size( r.width(), r.height() );
01373 KPrFreehandObject *kpfreehandobject = new KPrFreehandObject( points, size, pen, lb, le );
01374 insertObject( i18n( "Insert Freehand" ), kpfreehandobject, r );
01375 }
01376
01377 void KPrPage::insertPolyline( const KoPointArray &points, const KoRect &r, const KoPen &pen,
01378 LineEnd lb, LineEnd le )
01379 {
01380 KoSize size( r.width(), r.height() );
01381 KPrPolylineObject *kppolylineobject = new KPrPolylineObject( points, size, pen, lb, le );
01382 insertObject( i18n( "Insert Polyline" ), kppolylineobject, r );
01383 }
01384
01385 void KPrPage::insertQuadricBezierCurve( const KoPointArray &points, const KoPointArray &allPoints,
01386 const KoRect &r, const KoPen &pen,
01387 LineEnd lb, LineEnd le )
01388 {
01389 KoSize size( r.width(), r.height() );
01390
01391 KPrQuadricBezierCurveObject *kpQuadricBezierCurveObject = new KPrQuadricBezierCurveObject(
01392 points, allPoints, size, pen, lb, le );
01393 insertObject( i18n( "Insert Quadric Bezier Curve" ), kpQuadricBezierCurveObject, r );
01394 }
01395
01396 void KPrPage::insertCubicBezierCurve( const KoPointArray &points, const KoPointArray &allPoints,
01397 const KoRect &r, const KoPen &pen,
01398 LineEnd lb, LineEnd le )
01399 {
01400 KoSize size( r.width(), r.height() );
01401
01402 KPrCubicBezierCurveObject *kpCubicBezierCurveObject = new KPrCubicBezierCurveObject( points, allPoints, size, pen, lb, le );
01403 insertObject( i18n( "Insert Cubic Bezier Curve" ), kpCubicBezierCurveObject, r );
01404 }
01405
01406 void KPrPage::insertPolygon( const KoPointArray &points, const KoRect &r, const KoPen &pen, const QBrush &brush, FillType ft,
01407 const QColor &g1, const QColor &g2, BCType gt, bool unbalanced, int xfactor, int yfactor,
01408 bool _checkConcavePolygon, int _cornersValue, int _sharpnessValue )
01409 {
01410 KoSize size( r.width(), r.height() );
01411
01412 KPrPolygonObject *kpPolygonObject = new KPrPolygonObject( points, size, pen, brush, ft,
01413 g1, g2, gt, unbalanced, xfactor, yfactor,
01414 _checkConcavePolygon, _cornersValue, _sharpnessValue );
01415 insertObject( i18n( "Insert Polygon" ), kpPolygonObject, r );
01416 }
01417
01418 void KPrPage::insertClosedLine( const KoPointArray &points, const KoRect &r, const KoPen &pen, const QBrush &brush,
01419 FillType ft,const QColor &g1, const QColor &g2,
01420 BCType gt, bool unbalanced, int xfactor, int yfactor, ToolEditMode _mode )
01421 {
01422 QString _type;
01423 QString _name;
01424 if ( _mode == INS_CLOSED_FREEHAND ) {
01425 _type = i18n( "Closed Freehand" );
01426 _name = i18n( "Insert Closed Freehand" );
01427 }
01428 else if ( _mode == INS_CLOSED_POLYLINE ) {
01429 _type = i18n( "Closed Polyline" );
01430 _name = i18n( "Insert Closed Polyline" );
01431 }
01432 else if ( _mode == INS_CLOSED_QUADRICBEZIERCURVE ) {
01433 _type = i18n( "Closed Quadric Bezier Curve" );
01434 _name = i18n( "Insert Closed Quadric Bezier Curve" );
01435 }
01436 else if ( _mode == INS_CLOSED_CUBICBEZIERCURVE ) {
01437 _type = i18n( "Closed Cubic Bezier Curve" );
01438 _name = i18n( "Insert Closed Cubic Bezier Curve" );
01439 }
01440
01441 KoSize size( r.width(), r.height() );
01442
01443 KPrClosedLineObject *kpClosedLineObject = new KPrClosedLineObject( points, size, pen, brush, ft,
01444 g1, g2, gt, unbalanced, xfactor, yfactor, _type );
01445 insertObject( _name, kpClosedLineObject, r );
01446 }
01447
01448 KPrPartObject* KPrPage::insertObject( const KoRect& _rect, KoDocumentEntry& _e )
01449 {
01450 KoDocument* doc = _e.createDoc( m_doc );
01451 if ( !doc )
01452 return NULL;
01453
01454 if ( !doc->showEmbedInitDialog( 0 ) )
01455 return NULL;
01456
01457 QRect r = QRect( (int)_rect.left(), (int)_rect.top(),
01458 (int)_rect.width(), (int)_rect.height() );
01459 KPrChild* ch = new KPrChild( m_doc, doc, r );
01460 m_doc->insertObject( ch );
01461
01462 KPrPartObject *kppartobject = new KPrPartObject( ch );
01463 insertObject( i18n( "Embed Object" ), kppartobject, _rect );
01464
01465 QWidget::connect(ch, SIGNAL(changed(KoChild *)), kppartobject, SLOT(slot_changed(KoChild *)) );
01466
01467
01468 m_doc->repaint( false );
01469
01470 return kppartobject;
01471 }
01472
01473 KCommand* KPrPage::setPen( const KoPen &pen, LineEnd lb, LineEnd le, int flags )
01474 {
01475 KoPenCmd * cmd = NULL;
01476
01477 KoPenCmd::Pen _newPen( pen, lb, le);
01478
01479 QPtrList<KPrObject> _objects;
01480 _objects.setAutoDelete( false );
01481
01482 QPtrListIterator<KPrObject> it( m_objectList );
01483 for ( ; it.current() ; ++it )
01484 {
01485 if( it.current()->isSelected() )
01486 {
01487 _objects.append( it.current() );
01488 }
01489 }
01490
01491 if ( !_objects.isEmpty() && flags ) {
01492 cmd = new KoPenCmd( i18n( "Apply Styles" ), _objects, _newPen, m_doc, this, flags );
01493 cmd->execute();
01494 }
01495
01496 return cmd;
01497 }
01498
01499 KCommand * KPrPage::setBrush( const QBrush &brush, FillType ft, const QColor &g1, const QColor &g2,
01500 BCType gt, bool unbalanced, int xfactor, int yfactor, int flags )
01501 {
01502 KPrBrushCmd * cmd = NULL;
01503
01504 KPrBrushCmd::Brush _newBrush;
01505
01506 _newBrush.brush = QBrush( brush );
01507 _newBrush.fillType = ft;
01508 _newBrush.gColor1 = g1;
01509 _newBrush.gColor2 = g2;
01510 _newBrush.gType = gt;
01511 _newBrush.unbalanced = unbalanced;
01512 _newBrush.xfactor = xfactor;
01513 _newBrush.yfactor = yfactor;
01514
01515 QPtrList<KPrObject> _objects;
01516 _objects.setAutoDelete( false );
01517
01518 QPtrListIterator<KPrObject> it( m_objectList );
01519 for ( ; it.current() ; ++it )
01520 {
01521 if( it.current()->isSelected() )
01522 {
01523 _objects.append( it.current() );
01524 }
01525 }
01526
01527 if ( !_objects.isEmpty() && flags ) {
01528 cmd = new KPrBrushCmd( i18n( "Apply Styles" ), _objects, _newBrush, m_doc, this, flags );
01529 cmd->execute();
01530 }
01531
01532 return cmd;
01533 }
01534
01535 void KPrPage::slotRepaintVariable()
01536 {
01537 QPtrListIterator<KPrObject> it( m_objectList );
01538 for ( ; it.current() ; ++it )
01539 {
01540 if ( it.current()->getType() == OT_TEXT )
01541 m_doc->repaint( it.current() );
01542 }
01543 }
01544
01545 void KPrPage::recalcPageNum()
01546 {
01547 QPtrListIterator<KPrObject> it( m_objectList );
01548 for ( ; it.current() ; ++it )
01549 {
01550 if ( it.current()->getType() == OT_TEXT ) {
01551 ( (KPrTextObject*)it.current() )->recalcPageNum( this );
01552 m_doc->repaint( it.current() );
01553 }
01554 }
01555 }
01556
01557 void KPrPage::changePicture( const KURL & url, QWidget *parent )
01558 {
01559
01560
01561 KoPicture image = m_doc->pictureCollection()->downloadPicture( url, parent );
01562
01563 QPtrListIterator<KPrObject> it( m_objectList );
01564 for ( ; it.current() ; ++it )
01565 {
01566 if(it.current()->isSelected() && it.current()->getType()==OT_PICTURE)
01567 {
01568 KPrPixmapObject* obj=dynamic_cast<KPrPixmapObject*>( it.current() );
01569 if( obj)
01570 {
01571 KPrPixmapObject *pix = new KPrPixmapObject( m_doc->pictureCollection(), image.getKey() );
01572 KPrChgPixCmd *chgPixCmd = new KPrChgPixCmd( i18n( "Change Pixmap" ),obj,pix, m_doc,this );
01573 chgPixCmd->execute();
01574 m_doc->addCommand( chgPixCmd );
01575 }
01576 break;
01577 }
01578 }
01579 }
01580
01581 void KPrPage::insertPicture( const QString &filename, const KoPoint &pos )
01582 {
01583 KoPictureKey key = m_doc->pictureCollection()->loadPicture( filename ).getKey();
01584 KPrPixmapObject *kppixmapobject = new KPrPixmapObject(m_doc->pictureCollection() , key );
01585
01586 kppixmapobject->setOrig( pos );
01587 kppixmapobject->setSelected( true );
01588
01589 kppixmapobject->setSize( m_doc->zoomHandler()->pixelXToPt( kppixmapobject->originalSize().width() ),
01590 m_doc->zoomHandler()->pixelYToPt( kppixmapobject->originalSize().height() ) );
01591 kppixmapobject->setKeepRatio( true );
01592
01593 KPrInsertCmd *insertCmd = new KPrInsertCmd( i18n( "Insert Picture" ), kppixmapobject, m_doc, this );
01594 insertCmd->execute();
01595 m_doc->addCommand( insertCmd );
01596
01597 KoRect s = getPageRect();
01598 float fakt = 1;
01599 if ( kppixmapobject->getSize().width() > s.width() )
01600 fakt = (float)s.width() / (float)kppixmapobject->getSize().width();
01601 if ( kppixmapobject->getSize().height() > s.height() )
01602 fakt = QMIN( fakt, (float)s.height() / (float)kppixmapobject->getSize().height() );
01603
01604
01605
01606 if ( fakt < 1 ) {
01607 int w = (int)( fakt * (float)kppixmapobject->getSize().width() );
01608 int h = (int)( fakt * (float)kppixmapobject->getSize().height() );
01609
01610 kppixmapobject->setOrig(0,0);
01611 kppixmapobject->setSize(w, h);
01612 m_doc->repaint( false );
01613 }
01614 }
01615
01616 void KPrPage::insertPicture( const QString &_file, const KoRect &_rect )
01617 {
01618 KoPictureKey key = m_doc->pictureCollection()->loadPicture( _file ).getKey();
01619 KPrPixmapObject *kppixmapobject = new KPrPixmapObject( m_doc->pictureCollection(), key );
01620 kppixmapobject->setKeepRatio( true );
01621 insertObject( i18n( "Insert Picture" ), kppixmapobject, _rect );
01622 }
01623
01624 void KPrPage::enableEmbeddedParts( bool f )
01625 {
01626 KPrPartObject *obj=0L;
01627 QPtrListIterator<KPrObject> it( m_objectList );
01628 for ( ; it.current() ; ++it )
01629 {
01630 if(it.current()->getType()==OT_PART)
01631 {
01632 obj=dynamic_cast<KPrPartObject*>( it.current() );
01633 if(obj)
01634 obj->enableDrawing( f );
01635 }
01636 }
01637 }
01638
01639
01640 void KPrPage::setBackColor(const QColor &backColor1, const QColor &backColor2, BCType bcType,
01641 bool unbalanced, int xfactor, int yfactor )
01642 {
01643 m_kpbackground->setBackColor1( backColor1 );
01644 m_kpbackground->setBackColor2( backColor2 );
01645 m_kpbackground->setBackColorType( bcType );
01646 m_kpbackground->setBackUnbalanced( unbalanced );
01647 m_kpbackground->setBackXFactor( xfactor );
01648 m_kpbackground->setBackYFactor( yfactor );
01649 }
01650
01651 void KPrPage::setBackPicture( const KoPictureKey & key )
01652 {
01653 m_kpbackground->setBackPicture( key );
01654 }
01655
01656 bool KPrPage::getBackUnbalanced() const
01657 {
01658 return m_kpbackground->getBackUnbalanced();
01659 }
01660
01661 void KPrPage::setBackView( BackView backView )
01662 {
01663 m_kpbackground->setBackView( backView );
01664 }
01665
01666 void KPrPage::setBackType( BackType backType )
01667 {
01668 m_kpbackground->setBackType( backType );
01669 }
01670
01671 void KPrPage::setPageEffectSpeed( EffectSpeed pageEffectSpeed )
01672 {
01673 m_pageEffectSpeed = pageEffectSpeed;
01674 }
01675
01676 void KPrPage::setPageEffect( PageEffect pageEffect )
01677 {
01678 m_pageEffect = pageEffect;
01679 }
01680
01681 void KPrPage::setPageTimer( int pageTimer )
01682 {
01683 m_pageTimer = pageTimer;
01684 }
01685
01686 void KPrPage::setPageSoundEffect( bool soundEffect )
01687 {
01688 m_soundEffect = soundEffect;
01689 }
01690
01691 void KPrPage::setPageSoundFileName( const QString &fileName )
01692 {
01693 m_soundFileName = fileName;
01694 }
01695
01696 BackType KPrPage::getBackType() const
01697 {
01698 return m_kpbackground->getBackType();
01699 }
01700
01701 BackView KPrPage::getBackView() const
01702 {
01703 return m_kpbackground->getBackView();
01704 }
01705
01706 KoPictureKey KPrPage::getBackPictureKey() const
01707 {
01708 return m_kpbackground->getBackPictureKey();
01709 }
01710
01711 KoPicture KPrPage::getBackPicture() const
01712 {
01713 return m_kpbackground->getBackPicture();
01714 }
01715
01716 QColor KPrPage::getBackColor1() const
01717 {
01718 return m_kpbackground->getBackColor1();
01719 }
01720
01721 QColor KPrPage::getBackColor2() const
01722 {
01723 return m_kpbackground->getBackColor2();
01724 }
01725
01726 int KPrPage::getBackXFactor() const
01727 {
01728 return m_kpbackground->getBackXFactor();
01729 }
01730
01731 int KPrPage::getBackYFactor() const
01732 {
01733 return m_kpbackground->getBackYFactor();
01734 }
01735
01736 BCType KPrPage::getBackColorType() const
01737 {
01738 return m_kpbackground->getBackColorType();
01739 }
01740
01741 EffectSpeed KPrPage::getPageEffectSpeed() const
01742 {
01743 return m_pageEffectSpeed;
01744 }
01745
01746 PageEffect KPrPage::getPageEffect() const
01747 {
01748 return m_pageEffect;
01749 }
01750
01751 int KPrPage::getPageTimer() const
01752 {
01753 return m_pageTimer;
01754 }
01755
01756 bool KPrPage::getPageSoundEffect() const
01757 {
01758 return m_soundEffect;
01759 }
01760
01761 QString KPrPage::getPageSoundFileName() const
01762 {
01763 return m_soundFileName;
01764 }
01765
01766 KoRect KPrPage::getPageRect() const
01767 {
01768 const KoPageLayout& p = m_doc->pageLayout();
01769 return KoRect( p.ptLeft, p.ptTop, p.ptWidth - p.ptRight - p.ptLeft, p.ptHeight - p.ptTop - p.ptBottom );
01770 }
01771
01772 QRect KPrPage::getZoomPageRect() const
01773 {
01774 return m_doc->zoomHandler()->zoomRect(getPageRect());
01775 }
01776
01777 void KPrPage::completeLoading( bool _clean, int lastObj )
01778 {
01779 QPtrListIterator<KPrObject> it( m_objectList );
01780 for ( ; it.current() ; ++it )
01781 {
01782
01783
01784 if ( ( it.current()->getType() == OT_PICTURE )
01785 || ( it.current()->getType() == OT_CLIPART ) ) {
01786 if ( _clean || m_objectList.findRef( it.current() ) > lastObj )
01787 {
01788 KPrPixmapObject* obj=dynamic_cast<KPrPixmapObject*>( it.current());
01789 if(obj)
01790 obj->reload();
01791 }
01792 }
01793 else if ( it.current()->getType() == OT_TEXT )
01794 {
01795 KPrTextObject*obj=dynamic_cast<KPrTextObject*>( it.current() );
01796 if(obj)
01797 obj->recalcPageNum( this );
01798 }
01799 else if ( it.current()->getType() == OT_GROUP )
01800 completeLoadingForGroupObject( it.current() );
01801 }
01802 m_kpbackground->reload();
01803 }
01804
01805 void KPrPage::completeLoadingForGroupObject( KPrObject *_obj )
01806 {
01807 KPrGroupObject *_groupObj = static_cast<KPrGroupObject*>( _obj );
01808
01809 if ( _groupObj ) {
01810 QPtrListIterator<KPrObject> it( _groupObj->objectList() );
01811 for ( ; it.current(); ++it ) {
01812 if ( ( it.current()->getType() == OT_PICTURE )
01813 || ( it.current()->getType() == OT_CLIPART ) ) {
01814 KPrPixmapObject *_pixObj = dynamic_cast<KPrPixmapObject*>( it.current() );
01815 if ( _pixObj )
01816 _pixObj->reload();
01817 }
01818 else if ( it.current()->getType() == OT_TEXT ) {
01819 KPrTextObject *_textObj= dynamic_cast<KPrTextObject*>( it.current() );
01820 if ( _textObj )
01821 _textObj->recalcPageNum( this );
01822 }
01823 else if ( it.current()->getType() == OT_GROUP )
01824 completeLoadingForGroupObject( it.current() );
01825 }
01826 }
01827 }
01828
01829 KCommand * KPrPage::replaceObjs( bool createUndoRedo, double _orastX,double _orastY,const QColor & _txtBackCol,
01830 const QColor & _otxtBackCol )
01831 {
01832 KPrObject *kpobject = 0;
01833 double ox=0, oy=0;
01834 QPtrList<KPrObject> _objects;
01835 QValueList<KoPoint> _diffs;
01836 _objects.setAutoDelete( false );
01837
01838 for ( int i = 0; i < static_cast<int>( m_objectList.count() ); i++ ) {
01839 kpobject = m_objectList.at( i );
01840 ox = kpobject->getOrig().x();
01841 oy = kpobject->getOrig().y();
01842 ox = static_cast<int>(ox / m_doc->getGridX() * m_doc->getGridX());
01843 oy = static_cast<int>(oy / m_doc->getGridY() * m_doc->getGridY());
01844
01845 _diffs.append( KoPoint( ox - kpobject->getOrig().x(), oy - kpobject->getOrig().y() ) );
01846 _objects.append( kpobject );
01847 }
01848
01849 KPrSetOptionsCmd *setOptionsCmd = new KPrSetOptionsCmd( i18n( "Set New Options" ), _diffs, _objects, m_doc->getGridX(),
01850 m_doc->getGridY(),_orastX, _orastY, _txtBackCol, _otxtBackCol, m_doc );
01851 if ( createUndoRedo )
01852 return setOptionsCmd;
01853
01854 delete setOptionsCmd;
01855 return 0L;
01856 }
01857
01858 QString KPrPage::manualTitle() const
01859 {
01860 return m_manualTitle;
01861 }
01862
01863 void KPrPage::insertManualTitle(const QString & title)
01864 {
01865 m_manualTitle=title;
01866 }
01867
01868 QString KPrPage::pageTitle( const QString &_title ) const
01869 {
01870
01871 if ( !m_manualTitle.isEmpty() )
01872 return m_manualTitle;
01873
01874 QPtrList<KPrTextObject> objs;
01875
01876
01877
01878 QPtrListIterator<KPrObject> it( m_objectList );
01879 for ( ; it.current() ; ++it )
01880 {
01881 if(it.current()->getType()==OT_TEXT)
01882 objs.append( static_cast<KPrTextObject*>( it.current() ) );
01883 }
01884
01885 QString title;
01886 if ( _title.isNull() )
01887 {
01888
01889 if ( m_masterPage )
01890 title = i18n( "Slide %1" ).arg( m_doc->pageList().findRef( this ) + 1 );
01891 else
01892 title = i18n( "Slide Master" );
01893 }
01894 else
01895 {
01896 title = _title;
01897 }
01898
01899 if ( objs.isEmpty() )
01900 return title;
01901
01902
01903 KPrTextObject *tmp = objs.first();
01904 KPrTextObject *textobject=tmp;
01905 for ( tmp = objs.next(); tmp; tmp = objs.next() )
01906 if ( tmp->getOrig().y() < textobject->getOrig().y() )
01907 textobject = tmp;
01908
01909
01910 if ( !textobject )
01911 return QString( title );
01912
01913 QString txt;
01914 if ( textobject->textDocument()->firstParag() )
01915 txt = textobject->textDocument()->firstParag()->toString();
01916 if ( txt.stripWhiteSpace().isEmpty() || txt=="\n" )
01917 return title;
01918 return txt;
01919 }
01920
01921 void KPrPage::setNoteText( const QString &_text )
01922 {
01923 m_noteText=_text;
01924 m_doc->setModified(true);
01925 }
01926
01927 QString KPrPage::noteText() const
01928 {
01929 return m_noteText;
01930 }
01931
01932 void KPrPage::makeUsedPixmapList()
01933 {
01934 QPtrListIterator<KPrObject> it( m_objectList );
01935 for ( ; it.current() ; ++it )
01936 {
01937 if( it.current()->getType()==OT_PICTURE || it.current()->getType()==OT_CLIPART)
01938 m_doc->insertPixmapKey(static_cast<KPrPixmapObject*>( it.current() )->getKey() );
01939 else if ( it.current()->getType() == OT_GROUP )
01940 makeUsedPixmapListForGroupObject( it.current() );
01941 }
01942
01943 if( m_kpbackground->getBackType()==BT_PICTURE || m_kpbackground->getBackType()==BT_CLIPART)
01944 m_doc->insertPixmapKey(m_kpbackground->getBackPictureKey());
01945 }
01946
01947 void KPrPage::makeUsedPixmapListForGroupObject( KPrObject *_obj )
01948 {
01949 KPrGroupObject *_groupObj = static_cast<KPrGroupObject*>( _obj );
01950
01951 if ( _groupObj ) {
01952 QPtrListIterator<KPrObject> it( _groupObj->objectList() );
01953 for ( ; it.current(); ++it ) {
01954 if ( ( it.current()->getType() == OT_PICTURE )
01955 || ( it.current()->getType() == OT_CLIPART ) )
01956 m_doc->insertPixmapKey(static_cast<KPrPixmapObject*>( it.current() )->getKey() );
01957 else if ( it.current()->getType() == OT_GROUP )
01958 makeUsedPixmapListForGroupObject( it.current() );
01959 }
01960 }
01961 }
01962
01963
01964 QValueList<int> KPrPage::getEffectSteps() const
01965 {
01966 QMap<int,bool> stepmap;
01967 stepmap[0] = true;
01968
01969 QPtrListIterator<KPrObject> it( m_objectList );
01970 for ( ; it.current(); ++it )
01971 {
01972 stepmap[it.current()->getAppearStep()] = true;
01973
01974 if ( it.current()->getDisappear() )
01975 {
01976 stepmap[it.current()->getDisappearStep()] = true;
01977 }
01978 }
01979
01980 return stepmap.keys();
01981 }
01982
01983
01984 void KPrPage::deSelectAllObj()
01985 {
01986 QPtrListIterator<KPrObject> sIt( m_objectList );
01987 for ( ; sIt.current() ; ++sIt )
01988 {
01989 if(sIt.current()->isSelected())
01990 deSelectObj(sIt.current() );
01991 }
01992 }
01993
01994 void KPrPage::deSelectObj( KPrObject *kpobject )
01995 {
01996 kpobject->setSelected( false );
01997 m_doc->repaint( kpobject );
01998 }
01999
02000 QDomElement KPrPage::saveObjects( QDomDocument &doc, QDomElement &objects, double yoffset,
02001 int saveOnlyPage ) const
02002 {
02003 QPtrListIterator<KPrObject> oIt(m_objectList);
02004 for (; oIt.current(); ++oIt )
02005 {
02006
02007 if ( oIt.current()==m_doc->header()
02008 || oIt.current()==m_doc->footer()
02009 || oIt.current()->getType() == OT_PART)
02010 continue;
02011 QDomElement object=doc.createElement("OBJECT");
02012 object.setAttribute("type", static_cast<int>( oIt.current()->getType() ));
02013 bool _sticky = ( this->m_masterPage == 0 );
02014 if (_sticky)
02015 object.setAttribute("sticky", static_cast<int>(_sticky));
02016 if ( saveOnlyPage != -1 )
02017 yoffset=0;
02018
02019 object.appendChild(oIt.current()->save( doc, yoffset ));
02020
02021 objects.appendChild(object);
02022 }
02023 return objects;
02024 }
02025
02026 bool KPrPage::oneObjectTextExist(bool forceAllTextObject)
02027 {
02028 QPtrList<KPrObject> lst;
02029 getAllObjectSelectedList(lst,forceAllTextObject );
02030 QPtrListIterator<KPrObject> it( lst );
02031 for ( ; it.current() ; ++it )
02032 {
02033 if ( (it.current() == m_doc->header() && !hasHeader())
02034 || (it.current() == m_doc->footer() && !hasFooter()) )
02035 continue;
02036 if (it.current()->getType()==OT_TEXT)
02037 return true;
02038 }
02039 return false;
02040 }
02041
02042 bool KPrPage::oneObjectTextSelected()
02043 {
02044 return oneObjectTextExist(false);
02045 }
02046
02047
02048 bool KPrPage::isOneObjectSelected()
02049 {
02050 return 0 != getSelectedObj();
02051 }
02052
02053 bool KPrPage::haveASelectedPartObj()
02054 {
02055 QPtrList<KPrObject> lst;
02056 getAllObjectSelectedList(lst );
02057 QPtrListIterator<KPrObject> it( lst );
02058 for ( ; it.current(); ++it ) {
02059 if (it.current()->getType() == OT_PART )
02060 return true;
02061 }
02062 return false;
02063 }
02064
02065 bool KPrPage::haveASelectedGroupObj()
02066 {
02067 QPtrList<KPrObject> objects( getSelectedObjects( true ) );
02068 QPtrListIterator<KPrObject> it( objects );
02069 for ( ; it.current(); ++it ) {
02070 if ( it.current()->getType() == OT_GROUP )
02071 return true;
02072 }
02073 return false;
02074 }
02075
02076 bool KPrPage::haveASelectedPixmapObj()
02077 {
02078 QPtrList<KPrObject> lst;
02079 getAllObjectSelectedList(lst );
02080 QPtrListIterator<KPrObject> it( lst );
02081 for ( ; it.current() ; ++it ) {
02082 if (( it.current()->getType() == OT_PICTURE )
02083 || ( it.current()->getType() == OT_CLIPART ) )
02084 return true;
02085 }
02086 return false;
02087 }
02088
02089 KoRect KPrPage::getRealRect( bool all ) const
02090 {
02091 KoRect rect;
02092
02093 QPtrListIterator<KPrObject> it( m_objectList );
02094 for ( ; it.current() ; ++it )
02095 {
02096 if ( it.current()== m_doc->header() || it.current()== m_doc->footer())
02097 continue;
02098
02099 if ( all || ( it.current()->isSelected() && ! it.current()->isProtect() ) )
02100 rect |= it.current()->getRealRect();
02101 }
02102
02103 return rect;
02104 }
02105
02106
02107 bool KPrPage::chPic( KPrView *_view)
02108 {
02109 QPtrListIterator<KPrObject> it( m_objectList );
02110 for ( ; it.current() ; ++it )
02111 {
02112 if ( it.current()->isSelected() &&
02113 ( ( it.current()->getType() == OT_PICTURE )
02114 || ( it.current()->getType() == OT_CLIPART ) ) )
02115 {
02116 KPrPixmapObject* obj=dynamic_cast<KPrPixmapObject*>( it.current() );
02117 if( obj)
02118 {
02119 _view->changePicture( obj->getFileName() );
02120 return true;
02121 }
02122 }
02123 }
02124 return false;
02125 }
02126
02127 bool KPrPage::savePicture( KPrView *_view ) const
02128 {
02129 QPtrListIterator<KPrObject> it( m_objectList );
02130 for ( ; it.current() ; ++it )
02131 {
02132 if ( it.current()->isSelected() &&
02133 ( ( it.current()->getType() == OT_PICTURE )
02134 || ( it.current()->getType() == OT_CLIPART ) ) )
02135 {
02136 KPrPixmapObject* obj=dynamic_cast<KPrPixmapObject*>( it.current() );
02137 if( obj)
02138 {
02139 _view->savePicture( obj );
02140 return true;
02141 }
02142 }
02143 }
02144 return false;
02145 }
02146
02147
02148 KCommand *KPrPage::moveObject(KPrView *_view, double diffx, double diffy)
02149 {
02150 bool createCommand=false;
02151 KPrMoveByCmd *moveByCmd=0L;
02152 QPtrList<KPrObject> _objects;
02153 _objects.setAutoDelete( false );
02154 QPtrListIterator<KPrObject> it( m_objectList );
02155 for ( ; it.current() ; ++it )
02156 {
02157
02158 if ( it.current() == m_doc->header() || it.current() == m_doc->footer())
02159 continue;
02160 if ( it.current()->isSelected() && !it.current()->isProtect())
02161 {
02162 _objects.append( it.current() );
02163 QRect br = _view->zoomHandler()->zoomRect( it.current()->getRepaintRect() );
02164 br.moveBy( _view->zoomHandler()->zoomItX( diffx ), _view->zoomHandler()->zoomItY( diffy ) );
02165 m_doc->repaint( br );
02166 m_doc->repaint( it.current() );
02167 createCommand=true;
02168 }
02169 }
02170 if(createCommand) {
02171 moveByCmd = new KPrMoveByCmd( i18n( "Move Objects" ), KoPoint( diffx, diffy ),
02172 _objects, m_doc,this );
02173
02174 m_doc->updateSideBarItem( this );
02175 }
02176 return moveByCmd;
02177 }
02178
02179 KCommand *KPrPage::moveObject(KPrView *m_view,const KoPoint &_move,bool key)
02180 {
02181 QPtrList<KPrObject> _objects;
02182 _objects.setAutoDelete( false );
02183 KPrMoveByCmd *moveByCmd=0L;
02184 QPtrListIterator<KPrObject> it( m_objectList );
02185 for ( ; it.current() ; ++it )
02186 {
02187
02188 if ( it.current()== m_doc->header() || it.current()== m_doc->footer())
02189 continue;
02190 if ( it.current()->isSelected() && !it.current()->isProtect()) {
02191
02192 QRect oldBoundingRect = m_view->zoomHandler()->zoomRect( it.current()->getRepaintRect() );
02193
02194 it.current()->moveBy( _move );
02195 _objects.append( it.current() );
02196 m_doc->repaint( oldBoundingRect );
02197 m_doc->repaint( it.current() );
02198 }
02199 }
02200
02201 if ( key && !_objects.isEmpty())
02202 moveByCmd = new KPrMoveByCmd( i18n( "Move Objects" ),
02203 KoPoint( _move ),
02204 _objects, m_doc,this );
02205
02206 return moveByCmd;
02207 }
02208
02209 void KPrPage::repaintObj()
02210 {
02211 QPtrListIterator<KPrObject> it( m_objectList );
02212 for ( ; it.current() ; ++it )
02213 {
02214 if(it.current()->isSelected())
02215 m_doc->repaint(it.current() );
02216 }
02217 }
02218
02219 KCommand *KPrPage::rotateSelectedObjects( float _newAngle, bool addAngle )
02220 {
02221 KPrRotateCmd * cmd = NULL;
02222
02223 QPtrList<KPrObject> _objects;
02224 _objects.setAutoDelete( false );
02225
02226 QPtrListIterator<KPrObject> it( m_objectList );
02227 for ( ; it.current() ; ++it )
02228 {
02229 if ( it.current()== m_doc->header() || it.current()== m_doc->footer() )
02230 continue;
02231 if( it.current()->isSelected() && !it.current()->isProtect())
02232 {
02233 _objects.append( it.current() );
02234 }
02235 }
02236
02237 if ( !_objects.isEmpty() ) {
02238 cmd = new KPrRotateCmd( i18n( "Change Rotation" ), _newAngle, _objects, m_doc, addAngle );
02239 cmd->execute();
02240 }
02241
02242 return cmd;
02243 }
02244
02245
02246 KCommand *KPrPage::shadowObj(ShadowDirection dir,int dist, const QColor &col)
02247 {
02248 KPrShadowCmd *shadowCmd=0L;
02249 bool newShadow=false;
02250 QPtrList<KPrObject> _objects;
02251 QPtrList<KPrShadowCmd::ShadowValues> _oldShadow;
02252 KPrShadowCmd::ShadowValues _newShadow, *tmp;
02253
02254 _objects.setAutoDelete( false );
02255 _oldShadow.setAutoDelete( false );
02256
02257 _newShadow.shadowDirection = dir;
02258 _newShadow.shadowDistance = dist;
02259 _newShadow.shadowColor = col;
02260
02261 QPtrListIterator<KPrObject> it( m_objectList );
02262 for ( ; it.current() ; ++it )
02263 {
02264
02265 if ( it.current()== m_doc->header() || it.current()== m_doc->footer())
02266 continue;
02267
02268 if ( it.current()->isSelected() ) {
02269 tmp = new KPrShadowCmd::ShadowValues;
02270 tmp->shadowDirection = it.current()->getShadowDirection();
02271 tmp->shadowDistance =it.current()->getShadowDistance();
02272 tmp->shadowColor = it.current()->getShadowColor();
02273
02274 if(!newShadow &&( tmp->shadowDirection!=_newShadow.shadowDirection
02275 || tmp->shadowDistance!=_newShadow.shadowDistance
02276 || tmp->shadowColor!=_newShadow.shadowColor))
02277 newShadow=true;
02278
02279 _oldShadow.append( tmp );
02280 _objects.append( it.current() );
02281 }
02282 }
02283
02284 if ( !_objects.isEmpty() && newShadow ) {
02285 shadowCmd = new KPrShadowCmd( i18n( "Change Shadow" ),
02286 _oldShadow, _newShadow, _objects, m_doc );
02287 shadowCmd->execute();
02288 }
02289 else
02290 {
02291 _oldShadow.setAutoDelete( true );
02292 _oldShadow.clear();
02293 }
02294 return shadowCmd;
02295 }
02296
02297 QPtrList<KoTextObject> KPrPage::allTextObjects() const
02298 {
02299 QPtrList<KoTextObject> lst;
02300 addTextObjects( lst );
02301 return lst;
02302 }
02303
02304 void KPrPage::addTextObjects(QPtrList<KoTextObject>& lst) const
02305 {
02306 QPtrListIterator<KPrObject> it( m_objectList );
02307 for ( ; it.current() ; ++it )
02308 it.current()->addTextObjects( lst );
02309 }
02310
02311 KPrObject * KPrPage::getCursor( const QPoint &pos )
02312 {
02313 return getCursor( m_doc->zoomHandler()->unzoomPoint( pos ) );
02314 }
02315
02316 KPrObject * KPrPage::getCursor(const KoPoint &pos )
02317 {
02318 QPtrListIterator<KPrObject> it( m_objectList );
02319 KPrObject *kpobject = it.toLast();
02320 while ( kpobject ) {
02321 if ( kpobject->contains( pos ) && kpobject->isSelected() )
02322 return kpobject;
02323 kpobject = --it;
02324 }
02325 return 0L;
02326 }
02327
02328 KPrObject* KPrPage::getObjectAt( const KoPoint &pos, bool withoutProtected ) const
02329 {
02330 QPtrListIterator<KPrObject> it( m_objectList );
02331 KPrObject *o = it.toLast();
02332 while ( o ) {
02333 if ( o != m_doc->footer() ||
02334 o != m_doc->header() ||
02335 ( m_bHasFooter && o == m_doc->footer() ) ||
02336 ( m_bHasHeader && o == m_doc->header() ) )
02337 {
02338 if ( o->contains( pos ) && !( o->isProtect() && withoutProtected ) )
02339 return o;
02340 }
02341 o = --it;
02342 }
02343 return 0L;
02344 }
02345
02346 KPrPixmapObject * KPrPage::picViewOrigHelper() const
02347 {
02348 KPrPixmapObject *obj=0L;
02349 QPtrListIterator<KPrObject> it( m_objectList );
02350 for ( ; it.current() ; ++it )
02351 {
02352 if ( it.current()->isSelected() &&
02353 ( ( it.current()->getType() == OT_PICTURE )
02354 || ( it.current()->getType() == OT_CLIPART ) ) )
02355 {
02356 obj=(KPrPixmapObject*)it.current();
02357 break;
02358 }
02359 }
02360 return obj;
02361 }
02362
02363 void KPrPage::applyStyleChange( KoStyleChangeDefMap changed )
02364 {
02365 QPtrList<KPrObject> lst;
02366 getAllObjectSelectedList(lst,true );
02367 QPtrListIterator<KPrObject> it( lst );
02368
02369 for ( ; it.current() ; ++it )
02370 {
02371 KPrTextObject *obj=dynamic_cast<KPrTextObject*>(it.current());
02372 if( obj)
02373 obj->applyStyleChange( changed );
02374 }
02375 }
02376
02377 void KPrPage::reactivateBgSpellChecking(bool refreshTextObj)
02378 {
02379 QPtrList<KPrObject> lst;
02380 getAllObjectSelectedList(lst,true );
02381 QPtrListIterator<KPrObject> oIt( lst );
02382
02383 for ( ; oIt.current() ; ++oIt )
02384 {
02385 if(oIt.current()->getType()==OT_TEXT)
02386 {
02387 static_cast<KPrTextObject*>( oIt.current() )->textObject()->setNeedSpellCheck(true);
02388 if(refreshTextObj)
02389 m_doc->repaint( oIt.current() );
02390 }
02391 }
02392 }
02393
02394 bool KPrPage::canMoveOneObject() const
02395 {
02396 QPtrListIterator<KPrObject> it( m_objectList );
02397 for ( ; it.current() ; ++it )
02398 {
02399
02400 if ( it.current()== m_doc->header() || it.current()== m_doc->footer())
02401 continue;
02402 if(it.current()->isSelected()&& !it.current()->isProtect())
02403 return true;
02404 }
02405 return false;
02406 }
02407
02408 KCommand *KPrPage::alignVertical( VerticalAlignmentType _type )
02409 {
02410 KMacroCommand *macro = 0L;
02411 QPtrList<KPrObject> lst;
02412 getAllObjectSelectedList(lst );
02413 QPtrListIterator<KPrObject> it( lst );
02414 for ( ; it.current() ; ++it )
02415 {
02416 if(it.current()->getType()==OT_TEXT)
02417 {
02418 KPrTextObject *obj = dynamic_cast<KPrTextObject *>(it.current());
02419 if ( obj && !obj->isProtectContent())
02420 {
02421 KPrChangeVerticalAlignmentCommand * cmd = new KPrChangeVerticalAlignmentCommand( i18n("Change Vertical Alignment"),
02422 obj, obj->verticalAlignment(),_type, m_doc);
02423 if ( !macro )
02424 macro = new KMacroCommand( i18n("Change Vertical Alignment"));
02425 macro->addCommand( cmd );
02426 cmd->execute();
02427 }
02428 }
02429 }
02430 return macro;
02431 }
02432
02433 void KPrPage::changeTabStopValue ( double _tabStop )
02434 {
02435 QPtrList<KPrObject> lst;
02436 getAllObjectSelectedList(lst,true );
02437 QPtrListIterator<KPrObject> it( lst );
02438 for ( ; it.current() ; ++it )
02439 {
02440 if(it.current()->getType()==OT_TEXT)
02441 {
02442 KPrTextObject *obj = dynamic_cast<KPrTextObject *>(it.current());
02443 if ( obj )
02444 {
02445 obj->textDocument()->setTabStops( m_doc->zoomHandler()->ptToLayoutUnitPixX( _tabStop ));
02446 obj->layout();
02447 m_doc->repaint( obj );
02448 }
02449 }
02450 }
02451 }
02452
02453 KPrObject *KPrPage::nextTextObject(KPrTextObject *obj)
02454 {
02455 if ( m_objectList.count()==0 )
02456 return 0L;
02457 int pos = -1;
02458 if ( obj )
02459 pos = m_objectList.findNextRef(obj);
02460
02461 if (pos != -1 )
02462 {
02463 KPrObject *frm=0L;
02464 for ( frm=m_objectList.at(pos); frm != 0; frm=m_objectList.next() )
02465 {
02466 KPrTextObject *newObj = frm->nextTextObject();
02467 if(newObj && newObj->nextTextObject()->textObject()->needSpellCheck())
02468 return frm;
02469 }
02470 }
02471 else
02472 {
02473 KPrObject *frm=0L;
02474 for ( frm=m_objectList.at(0); frm != 0; frm=m_objectList.next() )
02475 {
02476 KPrTextObject *newObj = frm->nextTextObject();
02477 if(newObj && newObj->nextTextObject()->textObject()->needSpellCheck())
02478 return frm;
02479 }
02480 }
02481 return 0L;
02482 }
02483
02484 bool KPrPage::findTextObject( KPrObject *obj )
02485 {
02486 return (m_objectList.findRef( obj )>=0 );
02487 }
02488
02489 void KPrPage::getAllObjectSelectedList(QPtrList<KPrObject> &lst, bool force )
02490 {
02491 QPtrListIterator<KPrObject> it( m_objectList );
02492 for ( ; it.current() ; ++it )
02493 it.current()->getAllObjectSelectedList( lst,force );
02494 }
02495
02496 void KPrPage::getAllEmbeddedObjectSelected(QPtrList<KoDocumentChild> &embeddedObjects )
02497 {
02498 QPtrListIterator<KPrObject> it( m_objectList );
02499 for ( ; it.current() ; ++it )
02500 {
02501 if ( it.current()->isSelected() && it.current()->getType() == OT_PART )
02502 embeddedObjects.append( static_cast<KPrPartObject *>(it.current())->getChild() );
02503 }
02504 }
02505
02506 KPrPixmapObject* KPrPage::getSelectedImage() const
02507 {
02508 KPrPixmapObject *obj=0L;
02509 QPtrListIterator<KPrObject> it( m_objectList );
02510 for ( ; it.current() ; ++it )
02511 {
02512 if ( it.current()->isSelected() && it.current()->getType() == OT_PICTURE )
02513 {
02514 obj=dynamic_cast<KPrPixmapObject*>(it.current());
02515 break;
02516 }
02517 }
02518 return obj;
02519 }
02520
02521 KCommand * KPrPage::setImageEffect(ImageEffect eff, QVariant param1, QVariant param2, QVariant param3)
02522 {
02523 bool changed = false;
02524 KPrImageEffectCmd *imageEffectCmd = 0L;
02525 QPtrList<KPrObject> _objects;
02526 QPtrList<KPrImageEffectCmd::ImageEffectSettings> _oldSettings;
02527 KPrImageEffectCmd::ImageEffectSettings _newSettings, *tmp;
02528
02529 _objects.setAutoDelete( false );
02530 _oldSettings.setAutoDelete( false );
02531
02532 _newSettings.effect = eff;
02533 _newSettings.param1 = param1;
02534 _newSettings.param2 = param2;
02535 _newSettings.param3 = param3;
02536
02537 QPtrListIterator<KPrObject> it( m_objectList );
02538 for ( ; it.current(); ++it ) {
02539 if ( it.current()->getType() == OT_PICTURE && it.current()->isSelected()) {
02540 tmp = new KPrImageEffectCmd::ImageEffectSettings;
02541 tmp->effect = static_cast<KPrPixmapObject*>(it.current())->getImageEffect();
02542 tmp->param1 = static_cast<KPrPixmapObject*>(it.current())->getIEParam1();
02543 tmp->param2 = static_cast<KPrPixmapObject*>(it.current())->getIEParam2();
02544 tmp->param3 = static_cast<KPrPixmapObject*>(it.current())->getIEParam3();
02545 _oldSettings.append( tmp );
02546 _objects.append( it.current() );
02547
02548 if( !changed && ( tmp->effect != _newSettings.effect
02549 || tmp->param1 != _newSettings.param1
02550 || tmp->param2 != _newSettings.param2
02551 || tmp->param3 != _newSettings.param3 ) )
02552 changed = true;
02553 }
02554 }
02555
02556 if ( !_objects.isEmpty() && changed ) {
02557 imageEffectCmd = new KPrImageEffectCmd( i18n( "Change Image Effect" ), _oldSettings, _newSettings,
02558 _objects, m_doc );
02559 imageEffectCmd->execute();
02560 }
02561 else {
02562 _oldSettings.setAutoDelete( true );
02563 _oldSettings.clear();
02564 }
02565
02566 m_doc->setModified( true );
02567
02568 return imageEffectCmd;
02569 }
02570
02571 void KPrPage::setHeader( bool b, bool _updateDoc )
02572 {
02573 m_bHasHeader = b;
02574 if ( _updateDoc )
02575 m_doc->setHeader(b);
02576 }
02577
02578 void KPrPage::setFooter( bool b, bool _updateDoc )
02579 {
02580 m_bHasFooter = b;
02581 if ( _updateDoc )
02582 m_doc->setFooter( b );
02583 }
02584
02585 void KPrPage::setUseMasterBackground( bool useMasterBackground )
02586 {
02587 m_useMasterBackground = useMasterBackground;
02588 }
02589
02590 bool KPrPage::useMasterBackground() const
02591 {
02592 return m_useMasterBackground;
02593 }
02594
02595 bool KPrPage::isMasterPage() const
02596 {
02597 return ( m_masterPage==0 );
02598 }
02599
02600 void KPrPage::setDisplayObjectFromMasterPage( bool _b )
02601 {
02602 m_displayObjectFromMasterPage = _b;
02603 m_doc->setDisplayObjectMasterPage( _b );
02604 }
02605
02606 void KPrPage::setDisplayBackground( bool _b )
02607 {
02608 m_displayBackground = _b;
02609 m_doc->setDisplayBackground( _b );
02610 }
02611
02612