kpresenter

KPrEffectHandler.cpp

00001 // -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; -*-
00002 /* This file is part of the KDE project
00003    Copyright (C) 2004 Thorsten Zachmann <zachmann@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "KPrEffectHandler.h"
00022 
00023 #include "KPrObject.h"
00024 #include "KPrDocument.h"
00025 #include "KPrView.h"
00026 #include "KPrCanvas.h"
00027 
00028 #include <KoZoomHandler.h>
00029 #include <kapplication.h>
00030 
00031 #include <qpainter.h>
00032 #include <qpaintdevice.h>
00033 
00034 #include <unistd.h>
00035 
00036 
00037 KPrEffectHandler::KPrEffectHandler( PresStep step, bool back, QPaintDevice *dst, QPixmap *src,
00038                               const QPtrList<KPrObject> &objects, KPrView *view, int _presSpeed )
00039 : m_effectStep(0), m_step(step), m_back(back), m_dst(dst),
00040   m_paint(*src), m_objects(objects), m_view(view), m_soundEffect(QString::null),
00041   m_objectTimer(1)
00042 {
00043     m_src = new QPixmap( *src );
00044 
00045     QPtrListIterator<KPrObject> it( m_objects );
00046     for ( ; it.current(); ++it )
00047     {
00048         KPrObject *object = it.current();
00049         if ( object->getAppearStep() == m_step.m_step
00050           && ( m_step.m_subStep == 0
00051             || ( object->getType() == OT_TEXT
00052               && object->getEffect2() == EF2T_PARA ) ) )
00053         {
00054             m_appearEffectObjects.append( object );
00055             if ( object->getAppearSoundEffect() )
00056             {
00057                 m_soundEffect = object->getAppearSoundEffectFileName();
00058             }
00059 
00060             if ( object->getAppearTimer() > m_objectTimer )
00061             {
00062                 m_objectTimer = object->getAppearTimer();
00063             }
00064         }
00065         else if ( object->getDisappear() && object->getDisappearStep() == m_step.m_step )
00066         {
00067             m_disappearEffectObjects.append( object );
00068             if ( object->getDisappearSoundEffect() )
00069             {
00070                 m_soundEffect = object->getDisappearSoundEffectFileName();
00071             }
00072 
00073             if ( object->getDisappearTimer() > m_objectTimer )
00074             {
00075                 m_objectTimer = object->getDisappearTimer();
00076             }
00077         }
00078     }
00079 
00080     float speedFactor = 150.0 / static_cast<float>( _presSpeed + 2 );
00081     m_stepWidth = static_cast<int>( m_src->width() / speedFactor );
00082     m_stepHeight = static_cast<int>( m_src->height() / speedFactor );
00083     m_lastRepaintRects.setAutoDelete( true );
00084 }
00085 
00086 
00087 KPrEffectHandler::~KPrEffectHandler()
00088 {
00089     delete m_src;
00090 }
00091 
00092 
00093 bool KPrEffectHandler::doEffect()
00094 {
00095     if ( m_effectStep == 0 )
00096     {
00097         if ( !m_view->kPresenterDoc()->spManualSwitch() )
00098         {
00099             m_view->stopAutoPresTimer();
00100         }
00101 
00102         if ( !m_soundEffect.isNull() )
00103         {
00104             m_view->getCanvas()->stopSound();
00105             m_view->getCanvas()->playSound( m_soundEffect );
00106         }
00107     }
00108     if ( !m_appearEffectObjects.isEmpty() || !m_disappearEffectObjects.isEmpty() )
00109     {
00110         QPtrList<QRect> m_removeRects;
00111         KPrObject *appearObject = m_appearEffectObjects.first();
00112         KPrObject *disappearObject = m_disappearEffectObjects.first();
00113         QPtrListIterator<KPrObject> it( m_objects );
00114         KPrObject *object;
00115 
00116         while ( ( object = it.current() ) != 0 )
00117         {
00118             int speed[] = { 50, 35, 20 };
00119             
00120             ++it;
00121             if ( object == appearObject )
00122             {
00123                 bool next = true;
00124 
00125                 double speedFactor = speed[object->getAppearSpeed()];
00126                 
00127                 m_stepWidth = static_cast<int>( m_src->width() / speedFactor );
00128                 m_stepHeight = static_cast<int>( m_src->height() / speedFactor );
00129 
00130                 if ( doAppearEffectStep( object ) )
00131                 {
00132                     m_removeRects.append( m_repaintRects.getLast() );
00133                     if ( appearObject != m_appearEffectObjects.getLast() )
00134                     {
00135                         next = false;
00136                     }
00137                     m_appearEffectObjects.remove();
00138 
00139                     // add object to src
00140                     drawObject( object, 0, 0, m_src );
00141                 }
00142                 if ( next )
00143                     appearObject = m_appearEffectObjects.next();
00144                 else
00145                     appearObject = m_appearEffectObjects.current();
00146             }
00147             else if ( object == disappearObject )
00148             {
00149                 bool next = true;
00150 
00151                 double speedFactor = speed[object->getDisappearSpeed()];
00152                 
00153                 m_stepWidth = static_cast<int>( m_src->width() / speedFactor );
00154                 m_stepHeight = static_cast<int>( m_src->height() / speedFactor );
00155 
00156                 if ( doDisappearEffectStep( object ) )
00157                 {
00158                     if ( disappearObject != m_disappearEffectObjects.getLast() )
00159                     {
00160                         next = false;
00161                     }
00162                     m_disappearEffectObjects.remove();
00163                 }
00164 
00165                 if ( next )
00166                     disappearObject = m_disappearEffectObjects.next();
00167                 else
00168                     disappearObject = m_disappearEffectObjects.current();
00169             }
00170         }
00171 
00172         ++m_effectStep;
00173         QRect *r;
00174 #if 0 // used for debugging effects
00175         QPtrListIterator<QRect> it_debug(m_repaintRects);
00176         while( ( r = it_debug.current() ) != 0 )
00177         {
00178             ++it_debug;
00179             QPainter p( &m_paint );
00180             QPen pen = QPen( Qt::red, 1, Qt::DashLine );
00181             p.setPen( pen );
00182             p.drawRect( *r );
00183         }
00184 
00185         QPtrListIterator<QRect> it_debug2(m_lastRepaintRects);
00186         while( ( r = it_debug2.current() ) != 0 )
00187         {
00188             ++it_debug2;
00189             QPainter p( &m_paint );
00190             QPen pen = QPen( Qt::green, 1, Qt::DashLine );
00191             p.setPen( pen );
00192             p.drawRect( *r );
00193         }
00194         sleep( 1 );
00195 #endif
00196 
00197         QPtrListIterator<QRect> it_r(m_repaintRects);
00198 #if 1
00199         while( ( r = it_r.current() ) != 0 )
00200         {
00201             ++it_r;
00202             //bitBlt( m_dst, r->x(), r->y(), &m_paint, r->x(), r->y(), r->width(), r->height() );
00203             bitBlt( m_dst, r->x() - 5, r->y() - 5, &m_paint, r->x() - 5, r->y() - 5, r->width() + 10, r->height() + 10 );
00204         }
00205         QPtrListIterator<QRect> it2(m_lastRepaintRects);
00206         while( ( r = it2.current() ) != 0 )
00207         {
00208             ++it2;
00209             //bitBlt( m_dst, r->x(), r->y(), &m_paint, r->x(), r->y(), r->width(), r->height() );
00210             bitBlt( m_dst, r->x() - 5, r->y() - 5, &m_paint, r->x() - 5, r->y() - 5, r->width() + 10, r->height() + 10 );
00211         }
00212 #else
00213         bitBlt( m_dst, 0, 0, &m_paint);
00214 #endif
00215 
00216         m_lastRepaintRects = m_repaintRects;
00217         QPtrListIterator<QRect> it3(m_removeRects);
00218         while( ( r = it3.current() ) != 0 )
00219         {
00220             ++it3;
00221             m_lastRepaintRects.remove( r );
00222         }
00223 
00224         m_repaintRects.clear();
00225 
00226         m_paint = *m_src;
00227 
00228     }
00229     bool retval = ( m_appearEffectObjects.isEmpty() && m_disappearEffectObjects.isEmpty() );
00230 
00231     if ( retval && !m_view->kPresenterDoc()->spManualSwitch() )
00232     {
00233         m_view->setAutoPresTimer( m_objectTimer );
00234     }
00235     return retval;
00236 }
00237 
00238 
00239 void KPrEffectHandler::finish()
00240 {
00241     KPrObject *appearObject = m_appearEffectObjects.first();
00242     KPrObject *disappearObject = m_disappearEffectObjects.first();
00243     QPtrListIterator<KPrObject> it( m_objects );
00244     KPrObject *object;
00245 
00246     while ( ( object = it.current() ) != 0 )
00247     {
00248         ++it;
00249         if ( object == appearObject )
00250         {
00251             bool next = true;
00252 
00253             QRect objectRect = m_view->zoomHandler()->zoomRect( object->getRealRect() );
00254             m_repaintRects.append( new QRect( objectRect ) );
00255 
00256             if ( appearObject != m_appearEffectObjects.getLast() )
00257             {
00258                 next = false;
00259             }
00260             m_appearEffectObjects.remove();
00261 
00262             // add object to src
00263             drawObject( object, 0, 0, m_src );
00264 
00265             if ( next )
00266                 appearObject = m_appearEffectObjects.next();
00267             else
00268                 appearObject = m_appearEffectObjects.current();
00269         }
00270         else if ( object == disappearObject )
00271         {
00272             bool next = true;
00273 
00274             if ( disappearObject != m_disappearEffectObjects.getLast() )
00275             {
00276                 next = false;
00277             }
00278             m_disappearEffectObjects.remove();
00279 
00280             if ( next )
00281                 disappearObject = m_disappearEffectObjects.next();
00282             else
00283                 disappearObject = m_disappearEffectObjects.current();
00284         }
00285     }
00286     bitBlt( m_dst, 0, 0, m_src );
00287 
00288     if ( !m_view->kPresenterDoc()->spManualSwitch() && m_objectTimer > 0 )
00289     {
00290         m_view->setAutoPresTimer( m_objectTimer );
00291     }
00292 }
00293 
00294 
00295 bool KPrEffectHandler::doAppearEffectStep( KPrObject *object )
00296 {
00297     bool positionReached = true;
00298 
00299     switch( object->getEffect() )
00300     {
00301         case EF_NONE:
00302             positionReached = appearNone( object );
00303             break;
00304         case EF_COME_LEFT:
00305             positionReached = appearComeLeft( object );
00306             break;
00307         case EF_COME_TOP:
00308             positionReached = appearComeTop( object );
00309             break;
00310         case EF_COME_RIGHT:
00311             positionReached = appearComeRight( object );
00312             break;
00313         case EF_COME_BOTTOM:
00314             positionReached = appearComeBottom( object );
00315             break;
00316         case EF_COME_LEFT_TOP:
00317             positionReached = appearComeLeftTop( object );
00318             break;
00319         case EF_COME_LEFT_BOTTOM:
00320             positionReached = appearComeLeftBottom( object );
00321             break;
00322         case EF_COME_RIGHT_TOP:
00323             positionReached = appearComeRightTop( object );
00324             break;
00325         case EF_COME_RIGHT_BOTTOM:
00326             positionReached = appearComeRightBottom( object );
00327             break;
00328         case EF_WIPE_LEFT:
00329             positionReached = appearWipeLeft( object );
00330             break;
00331         case EF_WIPE_RIGHT:
00332             positionReached = appearWipeRight( object );
00333             break;
00334         case EF_WIPE_TOP:
00335             positionReached = appearWipeTop( object );
00336             break;
00337         case EF_WIPE_BOTTOM:
00338             positionReached = appearWipeBottom( object );
00339             break;
00340         default:
00341             break;
00342     }
00343     return positionReached;
00344 }
00345 
00346 
00347 bool KPrEffectHandler::doDisappearEffectStep( KPrObject *object )
00348 {
00349     bool positionReached = true;
00350 
00351     switch( object->getEffect3() )
00352     {
00353         case EF3_NONE:
00354             break;
00355         case EF3_GO_LEFT:
00356             positionReached = disappearGoLeft( object );
00357             break;
00358         case EF3_GO_TOP:
00359             positionReached = disappearGoTop( object );
00360             break;
00361         case EF3_GO_RIGHT:
00362             positionReached = disappearGoRight( object );
00363             break;
00364         case EF3_GO_BOTTOM:
00365             positionReached = disappearGoBottom( object );
00366             break;
00367         case EF3_GO_LEFT_TOP:
00368             positionReached = disappearGoLeftTop( object );
00369             break;
00370         case EF3_GO_LEFT_BOTTOM:
00371             positionReached = disappearGoLeftBottom( object );
00372             break;
00373         case EF3_GO_RIGHT_TOP:
00374             positionReached = disappearGoRightTop( object );
00375             break;
00376         case EF3_GO_RIGHT_BOTTOM:
00377             positionReached = disappearGoRightBottom( object );
00378             break;
00379         case EF3_WIPE_LEFT:
00380             positionReached = disappearWipeLeft( object );
00381             break;
00382         case EF3_WIPE_RIGHT:
00383             positionReached = disappearWipeRight( object );
00384             break;
00385         case EF3_WIPE_TOP:
00386             positionReached = disappearWipeTop( object );
00387             break;
00388         case EF3_WIPE_BOTTOM:
00389             positionReached = disappearWipeBottom( object );
00390             break;
00391         default:
00392             break;
00393     }
00394     return positionReached;
00395 }
00396 
00397 bool KPrEffectHandler::appearNone( KPrObject *object )
00398 {
00399     QRect objectRect = m_view->zoomHandler()->zoomRect( object->getRealRect() );
00400     m_repaintRects.append( new QRect( objectRect ) );
00401     drawObject( object, 0, 0, &m_paint );
00402     return true;
00403 }
00404 
00405 
00406 bool KPrEffectHandler::appearComeLeft( KPrObject *object )
00407 {
00408     QRect objectRect = m_view->zoomHandler()->zoomRect( object->getRealRect() );
00409     QRect repaintRect = m_view->zoomHandler()->zoomRect( object->getRepaintRect() );
00410     int ox = objectRect.x();
00411     int xdiff = repaintRect.x() - ox;
00412 
00413     bool positionReached = false;
00414     int x = m_effectStep * m_stepWidth - objectRect.width();
00415     if ( x >= ox )
00416     {
00417         x = ox;
00418         positionReached = true;
00419     }
00420     repaintRect.moveLeft( x + xdiff );
00421     m_repaintRects.append( new QRect( repaintRect ) );
00422 
00423     //kdDebug(33001) << "KPrEffectHandler appearComeLeft x = " << x << " " << positionReached << endl;
00424     drawObject( object, x - ox, 0, &m_paint );
00425 
00426     return positionReached;
00427 }
00428 
00429 
00430 bool KPrEffectHandler::appearComeTop( KPrObject *object )
00431 {
00432     QRect objectRect = m_view->zoomHandler()->zoomRect( object->getRealRect() );
00433     QRect repaintRect = m_view->zoomHandler()->zoomRect( object->getRepaintRect() );
00434     int oy = objectRect.y();
00435     int ydiff = repaintRect.y() - oy;
00436 
00437     bool positionReached = false;
00438     int y = m_effectStep * m_stepHeight - objectRect.height();
00439     if ( y >= oy )
00440     {
00441         y = oy;
00442         positionReached = true;
00443     }
00444     repaintRect.moveTop( y + ydiff );
00445     m_repaintRects.append( new QRect( repaintRect ) );
00446 
00447     //kdDebug(33001) << "KPrEffectHandler appearComeTop y = " << y << " " << positionReached << endl;
00448     drawObject( object, 0, y - oy, &m_paint );
00449 
00450     return positionReached;
00451 }
00452 
00453 
00454 bool KPrEffectHandler::appearComeRight( KPrObject *object )
00455 {
00456     QRect objectRect = m_view->zoomHandler()->zoomRect( object->getRealRect() );
00457     QRect repaintRect = m_view->zoomHandler()->zoomRect( object->getRepaintRect() );
00458     int ox = objectRect.x();
00459     int xdiff = repaintRect.x() - ox;
00460 
00461     bool positionReached = false;
00462     int x = m_src->width() - m_effectStep * m_stepWidth;
00463     if ( x <= ox )
00464     {
00465         x = ox;
00466         positionReached = true;
00467     }
00468     repaintRect.moveLeft( x + xdiff );
00469     m_repaintRects.append( new QRect( repaintRect ) );
00470 
00471     //kdDebug(33001) << "KPrEffectHandler appearComeRight x = " << x << " " << positionReached << endl;
00472     drawObject( object, x - ox, 0, &m_paint );
00473 
00474     return positionReached;
00475 }
00476 
00477 
00478 bool KPrEffectHandler::appearComeBottom( KPrObject *object )
00479 {
00480     QRect objectRect = m_view->zoomHandler()->zoomRect( object->getRealRect() );
00481     QRect repaintRect = m_view->zoomHandler()->zoomRect( object->getRepaintRect() );
00482     int oy = objectRect.y();
00483     int ydiff = repaintRect.y() - oy;
00484 
00485     bool positionReached = false;
00486     int y = m_src->height() - m_effectStep * m_stepHeight;
00487     if ( y <= oy )
00488     {
00489         y = oy;
00490         positionReached = true;
00491     }
00492     repaintRect.moveTop( y + ydiff );
00493     m_repaintRects.append( new QRect( repaintRect ) );
00494 
00495     //kdDebug(33001) << "KPrEffectHandler appearComeBottom y = " << y << " " << positionReached << endl;
00496     drawObject( object, 0, y - oy, &m_paint );
00497 
00498     return positionReached;
00499 }
00500 
00501 
00502 bool KPrEffectHandler::appearComeLeftTop( KPrObject *object )
00503 {
00504     QRect objectRect = m_view->zoomHandler()->zoomRect( object->getRealRect() );
00505     QRect repaintRect = m_view->zoomHandler()->zoomRect( object->getRepaintRect() );
00506     int ox = objectRect.x();
00507     int oy = objectRect.y();
00508     int xdiff = repaintRect.x() - ox;
00509     int ydiff = repaintRect.y() - oy;
00510 
00511     bool positionReached = false;
00512     int x = m_effectStep * m_stepWidth - objectRect.width();
00513     int y = m_effectStep * m_stepHeight - objectRect.height();
00514 
00515     if ( x >= ox )
00516         x = ox;
00517 
00518     if ( y >= oy )
00519         y = oy;
00520 
00521     if ( x == ox && y == oy )
00522         positionReached = true;
00523 
00524     repaintRect.moveLeft( x + xdiff );
00525     repaintRect.moveTop( y + ydiff );
00526     m_repaintRects.append( new QRect( repaintRect ) );
00527 
00528     //kdDebug(33001) << "KPrEffectHandler appearComeLeftTop x = " << x << ",y = " << y << " " <<  positionReached << endl;
00529     drawObject( object, x - ox, y - oy, &m_paint );
00530 
00531     return positionReached;
00532 }
00533 
00534 
00535 bool KPrEffectHandler::appearComeLeftBottom( KPrObject *object )
00536 {
00537     QRect objectRect = m_view->zoomHandler()->zoomRect( object->getRealRect() );
00538     QRect repaintRect = m_view->zoomHandler()->zoomRect( object->getRepaintRect() );
00539     int ox = objectRect.x();
00540     int oy = objectRect.y();
00541     int xdiff = repaintRect.x() - ox;
00542     int ydiff = repaintRect.y() - oy;
00543 
00544     bool positionReached = false;
00545     int x = m_effectStep * m_stepWidth - objectRect.width();
00546     int y = m_src->height() - m_effectStep * m_stepHeight;
00547 
00548     if ( x >= ox )
00549         x = ox;
00550 
00551     if ( y <= oy )
00552         y = oy;
00553 
00554     if ( x == ox && y == oy )
00555         positionReached = true;
00556 
00557     repaintRect.moveLeft( x + xdiff );
00558     repaintRect.moveTop( y + ydiff );
00559     m_repaintRects.append( new QRect( repaintRect ) );
00560 
00561     //kdDebug(33001) << "KPrEffectHandler appearComeLeftBottom x = " << x << ",y = " << y << " " <<  positionReached << endl;
00562     drawObject( object, x - ox, y - oy, &m_paint );
00563 
00564     return positionReached;
00565 }
00566 
00567 
00568 bool KPrEffectHandler::appearComeRightTop( KPrObject *object )
00569 {
00570     QRect objectRect = m_view->zoomHandler()->zoomRect( object->getRealRect() );
00571     QRect repaintRect = m_view->zoomHandler()->zoomRect( object->getRepaintRect() );
00572     int ox = objectRect.x();
00573     int oy = objectRect.y();
00574     int xdiff = repaintRect.x() - ox;
00575     int ydiff = repaintRect.y() - oy;
00576 
00577     bool positionReached = false;
00578     int x = m_src->width() - m_effectStep * m_stepWidth;
00579     int y = m_effectStep * m_stepHeight - objectRect.height();
00580 
00581     if ( x <= ox )
00582         x = ox;
00583 
00584     if ( y >= oy )
00585         y = oy;
00586 
00587     if ( x == ox && y == oy )
00588         positionReached = true;
00589 
00590     repaintRect.moveLeft( x + xdiff );
00591     repaintRect.moveTop( y + ydiff );
00592     m_repaintRects.append( new QRect( repaintRect ) );
00593 
00594     //kdDebug(33001) << "KPrEffectHandler appearComeRightTop x = " << x << ",y = " << y << " " <<  positionReached << endl;
00595     drawObject( object, x - ox, y - oy, &m_paint );
00596 
00597     return positionReached;
00598 }
00599 
00600 
00601 bool KPrEffectHandler::appearComeRightBottom( KPrObject *object )
00602 {
00603     QRect objectRect = m_view->zoomHandler()->zoomRect( object->getRealRect() );
00604     QRect repaintRect = m_view->zoomHandler()->zoomRect( object->getRepaintRect() );
00605     int ox = objectRect.x();
00606     int oy = objectRect.y();
00607     int xdiff = repaintRect.x() - ox;
00608     int ydiff = repaintRect.y() - oy;
00609 
00610     bool positionReached = false;
00611     int x = m_src->width() - m_effectStep * m_stepWidth;
00612     int y = m_src->height() - m_effectStep * m_stepHeight;
00613 
00614     if ( x <= ox )
00615         x = ox;
00616 
00617     if ( y <= oy )
00618         y = oy;
00619 
00620     if ( x == ox && y == oy )
00621         positionReached = true;
00622 
00623     repaintRect.moveLeft( x + xdiff );
00624     repaintRect.moveTop( y + ydiff );
00625     m_repaintRects.append( new QRect( repaintRect ) );
00626 
00627     //kdDebug(33001) << "KPrEffectHandler appearComeRightBottom x = " << x << ",y = " << y << " " <<  positionReached << endl;
00628     drawObject( object, x - ox, y - oy, &m_paint );
00629 
00630     return positionReached;
00631 }
00632 
00633 
00634 bool KPrEffectHandler::appearWipeLeft( KPrObject *object )
00635 {
00636     QRect repaintRect = m_view->zoomHandler()->zoomRect( object->getRepaintRect() );
00637     int ow = repaintRect.width();
00638 
00639     bool positionReached = false;
00640     int w = m_effectStep * m_stepWidth;
00641     if ( w >= ow )
00642     {
00643         w = ow;
00644         positionReached = true;
00645     }
00646 
00647     repaintRect.setWidth( w );
00648     m_repaintRects.append( new QRect( repaintRect ) );
00649     drawObject( object, 0, 0, &m_paint, &repaintRect );
00650     //kdDebug(33001) << "KPrEffectHandler appearWipeLeft w = " << w << positionReached << endl;
00651     return positionReached;
00652 }
00653 
00654 bool KPrEffectHandler::appearWipeRight( KPrObject *object )
00655 {
00656     QRect repaintRect = m_view->zoomHandler()->zoomRect( object->getRepaintRect() );
00657     int ow = repaintRect.width();
00658 
00659     bool positionReached = false;
00660     int w = m_effectStep * m_stepWidth;
00661     if ( w >= ow )
00662     {
00663         w = ow;
00664         positionReached = true;
00665     }
00666 
00667     repaintRect.setLeft( repaintRect.right() - w );
00668     m_repaintRects.append( new QRect( repaintRect ) );
00669     drawObject( object, 0, 0, &m_paint, &repaintRect );
00670     //kdDebug(33001) << "KPrEffectHandler appearWipeLeft w = " << w << positionReached << endl;
00671     return positionReached;
00672 }
00673 
00674 
00675 bool KPrEffectHandler::appearWipeTop( KPrObject *object )
00676 {
00677     QRect repaintRect = m_view->zoomHandler()->zoomRect( object->getRepaintRect() );
00678     int oh = repaintRect.height();
00679 
00680     bool positionReached = false;
00681     int h = m_effectStep * m_stepHeight;
00682     if ( h >= oh )
00683     {
00684         h = oh;
00685         positionReached = true;
00686     }
00687 
00688     repaintRect.setHeight( h );
00689     m_repaintRects.append( new QRect( repaintRect ) );
00690     drawObject( object, 0, 0, &m_paint, &repaintRect );
00691     //kdDebug(33001) << "KPrEffectHandler appearWipeLeft h = " << h << positionReached << endl;
00692     return positionReached;
00693 }
00694 
00695 
00696 bool KPrEffectHandler::appearWipeBottom( KPrObject *object )
00697 {
00698     QRect repaintRect = m_view->zoomHandler()->zoomRect( object->getRepaintRect() );
00699     int oh = repaintRect.height();
00700 
00701     bool positionReached = false;
00702     int h = m_effectStep * m_stepHeight;
00703     if ( h >= oh )
00704     {
00705         h = oh;
00706         positionReached = true;
00707     }
00708 
00709     repaintRect.setTop( repaintRect.bottom() - h );
00710     m_repaintRects.append( new QRect( repaintRect ) );
00711     drawObject( object, 0, 0, &m_paint, &repaintRect );
00712     //kdDebug(33001) << "KPrEffectHandler appearWipeLeft h = " << h << positionReached << endl;
00713     return positionReached;
00714 }
00715 
00716 
00717 bool KPrEffectHandler::disappearGoLeft( KPrObject *object )
00718 {
00719     QRect objectRect = m_view->zoomHandler()->zoomRect( object->getRealRect() );
00720     QRect repaintRect = m_view->zoomHandler()->zoomRect( object->getRepaintRect() );
00721     int ox = objectRect.x();
00722 
00723     bool positionReached = false;
00724     int x = m_effectStep * m_stepWidth;
00725     if ( ox - x <= -objectRect.width() )
00726     {
00727         positionReached = true;
00728     }
00729     else
00730     {
00731         repaintRect.moveBy( -x, 0 );
00732         m_repaintRects.append( new QRect( repaintRect ) );
00733         //kdDebug(33001) << "KPrEffectHandler disappearGoLeft x = " << -x + ox << " " << positionReached << endl;
00734         drawObject( object, -x, 0, &m_paint );
00735     }
00736 
00737     return positionReached;
00738 }
00739 
00740 
00741 bool KPrEffectHandler::disappearGoTop( KPrObject *object )
00742 {
00743     QRect objectRect = m_view->zoomHandler()->zoomRect( object->getRealRect() );
00744     QRect repaintRect = m_view->zoomHandler()->zoomRect( object->getRepaintRect() );
00745     int oy = objectRect.y();
00746 
00747     bool positionReached = false;
00748     int y = m_effectStep * m_stepHeight;
00749     if ( oy - y <= -objectRect.height() )
00750     {
00751         positionReached = true;
00752     }
00753     else
00754     {
00755         repaintRect.moveBy( 0, -y );
00756         m_repaintRects.append( new QRect( repaintRect ) );
00757         //kdDebug(33001) << "KPrEffectHandler disappearGoTop y = " << -y + oy << " " << positionReached << endl;
00758         drawObject( object, 0, -y, &m_paint );
00759     }
00760 
00761     return positionReached;
00762 }
00763 
00764 
00765 bool KPrEffectHandler::disappearGoRight( KPrObject *object )
00766 {
00767     int ox = m_view->zoomHandler()->zoomItX( object->getRealRect().x() );
00768     QRect repaintRect = m_view->zoomHandler()->zoomRect( object->getRepaintRect() );
00769 
00770     bool positionReached = false;
00771     int x = m_effectStep * m_stepWidth;
00772     if ( x + ox >= m_src->width() )
00773     {
00774         positionReached = true;
00775     }
00776     else
00777     {
00778         repaintRect.moveBy( x, 0 );
00779         m_repaintRects.append( new QRect( repaintRect ) );
00780         //kdDebug(33001) << "KPrEffectHandler disappearGoRight x = " << x + ox << " " << positionReached << endl;
00781         drawObject( object, x, 0, &m_paint );
00782     }
00783 
00784     return positionReached;
00785 }
00786 
00787 
00788 bool KPrEffectHandler::disappearGoBottom( KPrObject *object )
00789 {
00790     int oy = m_view->zoomHandler()->zoomItY( object->getRealRect().y() );
00791     QRect repaintRect = m_view->zoomHandler()->zoomRect( object->getRepaintRect() );
00792 
00793     bool positionReached = false;
00794     int y = m_effectStep * m_stepHeight;
00795     if ( oy + y >= m_src->height() )
00796     {
00797         positionReached = true;
00798     }
00799     else
00800     {
00801         repaintRect.moveBy( 0, y );
00802         m_repaintRects.append( new QRect( repaintRect ) );
00803         //kdDebug(33001) << "KPrEffectHandler disappearGoBottom y = " << y + oy << " " << positionReached << endl;
00804         drawObject( object, 0, y, &m_paint );
00805     }
00806 
00807     return positionReached;
00808 }
00809 
00810 
00811 bool KPrEffectHandler::disappearGoLeftTop( KPrObject *object )
00812 {
00813     QRect objectRect = m_view->zoomHandler()->zoomRect( object->getRealRect() );
00814     QRect repaintRect = m_view->zoomHandler()->zoomRect( object->getRepaintRect() );
00815     int ox = objectRect.x();
00816     int oy = objectRect.y();
00817 
00818     bool positionReached = false;
00819     int x = m_effectStep * m_stepWidth;
00820     int y = m_effectStep * m_stepHeight;
00821     if ( ox - x <= -objectRect.width() || oy - y <= -objectRect.height() )
00822     {
00823         positionReached = true;
00824     }
00825     else
00826     {
00827         repaintRect.moveBy( -x, -y );
00828         m_repaintRects.append( new QRect( repaintRect ) );
00829         //kdDebug(33001) << "KPrEffectHandler disappearGoLeftTop x = " << -x + ox << ", y = " << -y + oy << positionReached << endl;
00830         drawObject( object, -x, -y, &m_paint );
00831     }
00832 
00833     return positionReached;
00834 }
00835 
00836 
00837 bool KPrEffectHandler::disappearGoLeftBottom( KPrObject *object )
00838 {
00839     QRect objectRect = m_view->zoomHandler()->zoomRect( object->getRealRect() );
00840     QRect repaintRect = m_view->zoomHandler()->zoomRect( object->getRepaintRect() );
00841     int ox = objectRect.x();
00842     int oy = objectRect.y();
00843 
00844     bool positionReached = false;
00845     int x = m_effectStep * m_stepWidth;
00846     int y = m_effectStep * m_stepHeight;
00847     if ( ox - x <= -objectRect.width() || oy + y >= m_src->height() )
00848     {
00849         positionReached = true;
00850     }
00851     else
00852     {
00853         repaintRect.moveBy( -x, y );
00854         m_repaintRects.append( new QRect( repaintRect ) );
00855         //kdDebug(33001) << "KPrEffectHandler disappearGoLeftTop x = " << -x + ox << ", y = " << y + oy << positionReached << endl;
00856         drawObject( object, -x, y, &m_paint );
00857     }
00858 
00859     return positionReached;
00860 }
00861 
00862 
00863 bool KPrEffectHandler::disappearGoRightTop( KPrObject *object )
00864 {
00865     QRect objectRect = m_view->zoomHandler()->zoomRect( object->getRealRect() );
00866     QRect repaintRect = m_view->zoomHandler()->zoomRect( object->getRepaintRect() );
00867     int ox = objectRect.x();
00868     int oy = objectRect.y();
00869 
00870     bool positionReached = false;
00871     int x = m_effectStep * m_stepWidth;
00872     int y = m_effectStep * m_stepHeight;
00873     if ( ox + x >= m_src->width() || oy - y <= -objectRect.height() )
00874     {
00875         positionReached = true;
00876     }
00877     else
00878     {
00879         repaintRect.moveBy( x, -y );
00880         m_repaintRects.append( new QRect( repaintRect ) );
00881         //kdDebug(33001) << "KPrEffectHandler disappearGoLeftTop x = " << x + ox << ", y = " << -y + oy << positionReached << endl;
00882         drawObject( object, x, -y, &m_paint );
00883     }
00884 
00885     return positionReached;
00886 }
00887 
00888 
00889 bool KPrEffectHandler::disappearGoRightBottom( KPrObject *object )
00890 {
00891     QRect objectRect = m_view->zoomHandler()->zoomRect( object->getRealRect() );
00892     QRect repaintRect = m_view->zoomHandler()->zoomRect( object->getRepaintRect() );
00893     int ox = objectRect.x();
00894     int oy = objectRect.y();
00895 
00896     bool positionReached = false;
00897     int x = m_effectStep * m_stepWidth;
00898     int y = m_effectStep * m_stepHeight;
00899     if ( ox + x >= m_src->width() || oy + y >= m_src->height() )
00900     {
00901         positionReached = true;
00902     }
00903     else
00904     {
00905         repaintRect.moveBy( x, y );
00906         m_repaintRects.append( new QRect( repaintRect ) );
00907         //kdDebug(33001) << "KPrEffectHandler disappearGoLeftTop x = " << x + ox << ", y = " << y + oy << positionReached << endl;
00908         drawObject( object, x, y, &m_paint );
00909     }
00910 
00911     return positionReached;
00912 }
00913 
00914 
00915 bool KPrEffectHandler::disappearWipeLeft( KPrObject *object )
00916 {
00917     QRect repaintRect = m_view->zoomHandler()->zoomRect( object->getRepaintRect() );
00918     int ow = repaintRect.width();
00919 
00920     bool positionReached = false;
00921     int w = ow - m_effectStep * m_stepWidth;
00922     if ( w <= 0 )
00923     {
00924         positionReached = true;
00925     }
00926     else
00927     {
00928         repaintRect.setWidth( w );
00929         m_repaintRects.append( new QRect( repaintRect ) );
00930         drawObject( object, 0, 0, &m_paint, &repaintRect );
00931         //kdDebug(33001) << "KPrEffectHandler appearWipeLeft w = " << w << positionReached << endl;
00932     }
00933     return positionReached;
00934 }
00935 
00936 
00937 bool KPrEffectHandler::disappearWipeRight( KPrObject *object )
00938 {
00939     QRect repaintRect = m_view->zoomHandler()->zoomRect( object->getRepaintRect() );
00940     int ow = repaintRect.width();
00941 
00942     bool positionReached = false;
00943     int w = ow - m_effectStep * m_stepWidth;
00944     if ( w <= 0 )
00945     {
00946         positionReached = true;
00947     }
00948     else
00949     {
00950         repaintRect.setLeft( repaintRect.right() - w );
00951         m_repaintRects.append( new QRect( repaintRect ) );
00952         drawObject( object, 0, 0, &m_paint, &repaintRect );
00953         //kdDebug(33001) << "KPrEffectHandler appearWipeLeft w = " << w << positionReached << endl;
00954     }
00955     return positionReached;
00956 }
00957 
00958 
00959 bool KPrEffectHandler::disappearWipeTop( KPrObject *object )
00960 {
00961     QRect repaintRect = m_view->zoomHandler()->zoomRect( object->getRepaintRect() );
00962     int oh = repaintRect.height();
00963 
00964     bool positionReached = false;
00965     int h = oh - m_effectStep * m_stepHeight;
00966     if ( h <= 0 )
00967     {
00968         positionReached = true;
00969     }
00970     else
00971     {
00972         repaintRect.setHeight( h );
00973         m_repaintRects.append( new QRect( repaintRect ) );
00974         drawObject( object, 0, 0, &m_paint, &repaintRect );
00975         //kdDebug(33001) << "KPrEffectHandler appearWipeLeft h = " << h << positionReached << endl;
00976     }
00977     return positionReached;
00978 }
00979 
00980 
00981 bool KPrEffectHandler::disappearWipeBottom( KPrObject *object )
00982 {
00983     QRect repaintRect = m_view->zoomHandler()->zoomRect( object->getRepaintRect() );
00984     int oh = repaintRect.height();
00985 
00986     bool positionReached = false;
00987     int h = oh - m_effectStep * m_stepHeight;
00988     if ( h <= 0 )
00989     {
00990         positionReached = true;
00991     }
00992     else
00993     {
00994         repaintRect.setTop( repaintRect.bottom() - h );
00995         m_repaintRects.append( new QRect( repaintRect ) );
00996         drawObject( object, 0, 0, &m_paint, &repaintRect );
00997         //kdDebug(33001) << "KPrEffectHandler appearWipeLeft h = " << h << positionReached << endl;
00998     }
00999     return positionReached;
01000 }
01001 
01002 
01003 void KPrEffectHandler::drawObject( KPrObject *object, int x, int y, QPixmap *screen, QRect *clipRect )
01004 {
01005     QPainter p;
01006     p.begin( screen );
01007     if ( clipRect )
01008     {
01009         p.setClipRect( *clipRect, QPainter::CoordPainter );
01010     }
01011 
01012     p.translate( x, y );
01013 
01014     if ( object->getAppearStep() == m_step.m_step && ! m_back )
01015     {
01016         object->setSubPresStep( m_step.m_subStep );
01017         object->doSpecificEffects( true );
01018     }
01019 
01020     object->draw( &p, m_view->zoomHandler(), m_step.m_pageNumber, SM_NONE, false );
01021 
01022     if ( object->getAppearStep() == m_step.m_step && ! m_back )
01023     {
01024         object->setSubPresStep( 0 );
01025         object->doSpecificEffects( false );
01026     }
01027 
01028     p.translate( -x, -y );
01029 
01030     // redraw objects which lie above the currenty drawn
01031     m_objects.findRef( object );
01032     KPrObject *obj;
01033     while ( ( obj = m_objects.next() ) != 0 )
01034     {
01035         if ( ( obj->getAppearStep() < m_step.m_step
01036             || obj->getAppearStep() == m_step.m_step && !m_appearEffectObjects.containsRef( obj ) )
01037             && ( ( obj->getDisappear() && obj->getDisappearStep() > m_step.m_step ) || ! obj->getDisappear() )
01038             && m_view->zoomHandler()->zoomRect( obj->getRealRect()).intersects(*m_repaintRects.getLast()) )
01039         {
01040             if ( obj->getAppearStep() == m_step.m_step && ! m_back )
01041             {
01042                 obj->setSubPresStep( m_step.m_subStep );
01043                 obj->doSpecificEffects( true );
01044             }
01045             obj->draw( &p, m_view->zoomHandler(), m_step.m_pageNumber, SM_NONE, false );
01046             if ( obj->getAppearStep() == m_step.m_step && ! m_back )
01047             {
01048                 obj->setSubPresStep( 0 );
01049                 obj->doSpecificEffects( false );
01050             }
01051         }
01052     }
01053 
01054     p.end();
01055 }
KDE Home | KDE Accessibility Home | Description of Access Keys