mmsharing/livecommsui/lcui/src/lceffecthandler.cpp
branchRCL_3
changeset 33 bc78a40cd63c
parent 32 73a1feb507fb
child 35 6c57ef9392d2
equal deleted inserted replaced
32:73a1feb507fb 33:bc78a40cd63c
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 //USER
       
    19 #include "lceffecthandler.h"
       
    20 #include "lclogger.h"
       
    21 #include "lcuidefs.h"
       
    22 #include "lcuiengine.h"
       
    23 
       
    24 //SYSTEM
       
    25 #include <hbinstance.h>
       
    26 #include <hbwidget.h>
       
    27 
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 LcEffectHandler::LcEffectHandler(LcUiEngine& engine,
       
    34                                  HbWidget* sharedVideo, 
       
    35                                  HbWidget* sharedVideoOverlay,
       
    36                                  HbWidget* receivedVideo,
       
    37                                  HbWidget* receivedVideoOverlay) :
       
    38     mEngine(engine),
       
    39     mSharedVideo(sharedVideo),
       
    40     mSharedVideoOverlay(sharedVideoOverlay),
       
    41     mReceivedVideo(receivedVideo),
       
    42     mReceivedVideoOverlay(receivedVideoOverlay),
       
    43     mSwapSharedCompleted(false),
       
    44     mSwapReceivedCompleted(false),
       
    45     mSwapInProgress(false)
       
    46 {
       
    47     HbEffect::add(lcEffectWinId, lcEffectWinDisappear, lcEffectWinDisappearId );
       
    48     HbEffect::add(lcEffectWinId, lcEffectWinAppear, lcEffectWinAppearId );
       
    49     HbEffect::add(lcEffectWinId, lcEffectWinFlip, lcEffectWinFlipId );
       
    50     HbEffect::add(lcEffectWinId, lcEffectWinSwapDown, lcEffectWinSwapDownId );
       
    51     HbEffect::add(lcEffectWinId, lcEffectWinSwapUp, lcEffectWinSwapUpId );
       
    52     
       
    53     mEffectCallBack = lcEffectWinDefaultCallback;
       
    54 }
       
    55 
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 LcEffectHandler::~LcEffectHandler()
       
    62 {
       
    63 }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 void LcEffectHandler::setVisibility(HbWidget* widget, bool visible)
       
    70 {
       
    71     if ( !HbEffect::effectRunning( widget )) {
       
    72         widget->setVisible( visible );
       
    73     }
       
    74 }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 void LcEffectHandler::setDissappearEffect( 
       
    81         LcEffectHandler::DissapperEffect aEffectType )
       
    82 {
       
    83     if ( aEffectType == LcEffectHandler::DissappearToFlip ) {
       
    84         mEffectCallBack = "windowDisappearToFlipComplete";
       
    85     } else if ( aEffectType == LcEffectHandler::NormalDissappear ) {
       
    86         mEffectCallBack = "windowDisappearComplete"; 
       
    87     } else {
       
    88         mEffectCallBack = lcEffectWinDefaultCallback;
       
    89     }
       
    90 }
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 void LcEffectHandler::showSendWindow()
       
    96 {
       
    97     LC_QDEBUG( "livecomms [UI] -> LcEffectHandler::showSendWindow()" )
       
    98     if ( mSharedVideo ) {
       
    99         if ( mSwapSharedCompleted || !HbEffect::effectRunning( mSharedVideoOverlay )) {
       
   100             startEffect( mSharedVideoOverlay, 
       
   101                          lcEffectWinAppearId, "windowAppearComplete" );
       
   102                          
       
   103             mSharedVideo->show();
       
   104         } else {
       
   105             LC_QDEBUG( "livecomms [UI] LcEffectHandler: postponed due ongoing animation" )        
       
   106         }
       
   107     }
       
   108     LC_QDEBUG( "livecomms [UI] <- LcEffectHandler::showSendWindow()" )
       
   109 }
       
   110 
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 void LcEffectHandler::showReceiveWindow()
       
   117 {
       
   118     LC_QDEBUG( "livecomms [UI] -> LcEffectHandler::showReceiveWindow()" )
       
   119     if ( mReceivedVideo ) {
       
   120         if ( mSwapReceivedCompleted || !HbEffect::effectRunning( mReceivedVideoOverlay )) {
       
   121             startEffect( mReceivedVideoOverlay, 
       
   122                          lcEffectWinAppearId, "windowAppearComplete" );
       
   123             mReceivedVideo->show();
       
   124         } else {
       
   125             LC_QDEBUG( "livecomms [UI] LcEffectHandler: postponed due ongoing animation" )        
       
   126         }
       
   127     }
       
   128    LC_QDEBUG( "livecomms [UI] <- LcEffectHandler::showReceiveWindow()" )
       
   129  }
       
   130 
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 void LcEffectHandler::hideSendWindow()
       
   137 {
       
   138     LC_QDEBUG( "livecomms [UI] -> LcEffectHandler::hideSendWindow()" )
       
   139     if ( mSharedVideo && mSharedVideo->isVisible() ) {
       
   140         startEffect( mSharedVideoOverlay, 
       
   141                      lcEffectWinDisappearId, mEffectCallBack.toAscii().data() );
       
   142         mSharedVideo->hide();
       
   143     }
       
   144 
       
   145     mEffectCallBack = lcEffectWinDefaultCallback;
       
   146     LC_QDEBUG( "livecomms [UI] <- LcEffectHandlerLcEffectHandler::hideSendWindow()" )
       
   147 }
       
   148 
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 void LcEffectHandler::hideReceiveWindow()
       
   155 {
       
   156     LC_QDEBUG( "livecomms [UI] -> LcEffectHandler::hideReceiveWindow()" )
       
   157     if ( mReceivedVideo && mReceivedVideo->isVisible() ) {
       
   158         startEffect( mReceivedVideoOverlay, 
       
   159                      lcEffectWinDisappearId, "windowDisappearComplete" );
       
   160         mReceivedVideo->hide();
       
   161     }
       
   162 
       
   163    LC_QDEBUG( "livecomms [UI] <- LcEffectHandler::hideReceiveWindow()" )
       
   164 }
       
   165 
       
   166 
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 // -----------------------------------------------------------------------------
       
   170 //
       
   171 void LcEffectHandler::swap()
       
   172 {
       
   173     LC_QDEBUG( "livecomms [UI] -> LcEffectHandler::swap()" )
       
   174 
       
   175     // Emit the signal which triggers to loading of new swapped section
       
   176     mSwapInProgress = true;
       
   177     emit loadSwapLayout();
       
   178 
       
   179     startEffects();
       
   180     
       
   181     LC_QDEBUG( "livecomms [UI] <- LcEffectHandler::swap()" )
       
   182 }
       
   183 
       
   184 // -----------------------------------------------------------------------------
       
   185 //
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 void LcEffectHandler::startEffects()
       
   189 {
       
   190     if( mSharedVideo && mReceivedVideo ) {
       
   191      
       
   192          mSwapSharedCompleted = false;
       
   193          mSwapReceivedCompleted = false;
       
   194      
       
   195          startEffect( mSharedVideoOverlay, lcEffectWinDisappearId, "windowSwapSharedComplete" );
       
   196          startEffect( mReceivedVideoOverlay, lcEffectWinDisappearId, "windowSwapReceivedComplete" );
       
   197              
       
   198          mSharedVideo->hide();
       
   199          mReceivedVideo->hide();
       
   200      }
       
   201     
       
   202 }    
       
   203 
       
   204 // -----------------------------------------------------------------------------
       
   205 //
       
   206 // -----------------------------------------------------------------------------
       
   207 //
       
   208 void LcEffectHandler::startEffect( 
       
   209     HbWidget* widget, const char *effectId, const char *callBack )
       
   210 {
       
   211     LC_QDEBUG( "livecomms [UI] -> LcEffectHandler::startEffect()" )
       
   212     if( widget ) {
       
   213         widget->setOpacity(1.0); // Previous effect might have set opacity to zero
       
   214         widget->show();
       
   215         LC_QDEBUG_2( "livecomms [UI] window: ",  widget->geometry() )
       
   216         LC_QDEBUG_2( "livecomms [UI] effect name: ",  QString(effectId) )
       
   217         HbEffect::start( widget, lcEffectWinId, effectId, this, callBack );
       
   218     }
       
   219     LC_QDEBUG( "livecomms [UI] <- LcEffectHandler::startEffect()" )
       
   220 }
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 //
       
   224 // -----------------------------------------------------------------------------
       
   225 //
       
   226 void LcEffectHandler::windowAppearComplete(HbEffect::EffectStatus status)
       
   227 {
       
   228     Q_UNUSED(status);
       
   229     LC_QDEBUG( "livecomms [UI] -> LcEffectHandler::windowAppearComplete()" )
       
   230     
       
   231     if ( status.item && status.item == mSharedVideoOverlay  && 
       
   232          !HbEffect::effectRunning( mSharedVideoOverlay ) ) {
       
   233         mSharedVideoOverlay->hide();
       
   234                 
       
   235     }
       
   236     if ( status.item && status.item == mReceivedVideoOverlay  && 
       
   237          !HbEffect::effectRunning( mReceivedVideoOverlay ) ) {
       
   238         mReceivedVideoOverlay->hide();
       
   239                 
       
   240     }
       
   241 
       
   242     LC_QDEBUG( "livecomms [UI] <- LcEffectHandler::windowAppearComplete()" )
       
   243 }
       
   244 
       
   245 // -----------------------------------------------------------------------------
       
   246 //
       
   247 // -----------------------------------------------------------------------------
       
   248 //
       
   249 void LcEffectHandler::windowDisappearComplete(HbEffect::EffectStatus status)
       
   250 {
       
   251     Q_UNUSED(status);
       
   252     LC_QDEBUG( "livecomms [UI] -> LcEffectHandler::windowDisappearComplete()" )
       
   253     LC_QDEBUG( "livecomms [UI] <- LcEffectHandler::windowDisappearComplete()" )
       
   254 }
       
   255 
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 // -----------------------------------------------------------------------------
       
   259 //
       
   260 void LcEffectHandler::windowDisappearToFlipComplete(HbEffect::EffectStatus status)
       
   261 {
       
   262     Q_UNUSED(status);
       
   263     LC_QDEBUG( "livecomms [UI] -> LcEffectHandler::windowDisappearToFlipComplete()" )
       
   264     if( mSharedVideo ) {
       
   265         mSharedVideo->hide();       
       
   266         startEffect( mSharedVideoOverlay, lcEffectWinFlipId, "windowFlipComplete" );
       
   267     }
       
   268     LC_QDEBUG( "livecomms [UI] <- LcEffectHandler::windowDisappearToFlipComplete()" )
       
   269 }
       
   270 
       
   271 // -----------------------------------------------------------------------------
       
   272 //
       
   273 // -----------------------------------------------------------------------------
       
   274 //
       
   275 void LcEffectHandler::windowFlipComplete(HbEffect::EffectStatus status)
       
   276 {
       
   277     Q_UNUSED(status);
       
   278     LC_QDEBUG( "livecomms [UI] -> LcEffectHandler::flipHideComplete()" )
       
   279     if( mEngine.isLocalPlayerPlaying() ) {
       
   280         showSendWindow();
       
   281     }
       
   282     LC_QDEBUG( "livecomms [UI] <- LcEffectHandler::flipHideComplete()" )
       
   283 }
       
   284 
       
   285 // -----------------------------------------------------------------------------
       
   286 //
       
   287 // -----------------------------------------------------------------------------
       
   288 //
       
   289 void LcEffectHandler::windowSwapSharedComplete(HbEffect::EffectStatus status)
       
   290 {
       
   291     Q_UNUSED(status);
       
   292     LC_QDEBUG( "livecomms [UI] -> LcEffectHandler::windowSwapSharedComplete()" )
       
   293     if( mSharedVideo ) {    
       
   294         LC_QDEBUG_2( "livecomms [UI] window: ",  mSharedVideo->geometry() )
       
   295         LC_QDEBUG_2( "livecomms [UI] effect window: ",  mSharedVideoOverlay->geometry() )
       
   296         
       
   297         mSwapSharedCompleted = true;
       
   298         
       
   299         handleSwapCompletion();
       
   300     }
       
   301     LC_QDEBUG( "livecomms [UI] <- LcEffectHandler::windowSwapSharedComplete()" )
       
   302 }
       
   303 
       
   304 // -----------------------------------------------------------------------------
       
   305 //
       
   306 // -----------------------------------------------------------------------------
       
   307 //
       
   308 void LcEffectHandler::windowSwapReceivedComplete(HbEffect::EffectStatus status)
       
   309 {
       
   310     Q_UNUSED(status);
       
   311     LC_QDEBUG( "livecomms [UI] -> LcEffectHandler::windowSwapReceivedComplete()" )
       
   312     if( mReceivedVideo ) {    
       
   313         LC_QDEBUG_2( "livecomms [UI] window: ",  mReceivedVideo->geometry() )
       
   314         LC_QDEBUG_2( "livecomms [UI] effect window: ",  mReceivedVideoOverlay->geometry() )
       
   315         
       
   316         mSwapReceivedCompleted = true;
       
   317         
       
   318         handleSwapCompletion();
       
   319     }
       
   320     LC_QDEBUG( "livecomms [UI] <- LcEffectHandler::windowSwapReceivedComplete()" )
       
   321 }
       
   322 
       
   323 // -----------------------------------------------------------------------------
       
   324 //
       
   325 // -----------------------------------------------------------------------------
       
   326 //
       
   327 bool LcEffectHandler::isSharedVideoAtTop() const
       
   328 {
       
   329     return ( mSharedVideo && mReceivedVideo &&
       
   330              mSharedVideo->geometry().top() < mReceivedVideo->geometry().top());
       
   331 }
       
   332 
       
   333 // -----------------------------------------------------------------------------
       
   334 //
       
   335 // -----------------------------------------------------------------------------
       
   336 //
       
   337 bool LcEffectHandler::videosSideBySide() const
       
   338 {
       
   339      return ( mSharedVideo && mReceivedVideo &&
       
   340               mSharedVideo->geometry().top() == mReceivedVideo->geometry().top() );
       
   341 }
       
   342 
       
   343 // -----------------------------------------------------------------------------
       
   344 //
       
   345 // -----------------------------------------------------------------------------
       
   346 //
       
   347 void LcEffectHandler::handleSwapCompletion()
       
   348 {
       
   349     LC_QDEBUG( "livecomms [UI] -> LcEffectHandler::handleSwapCompletion()" )
       
   350     if ( mSwapSharedCompleted && mSwapReceivedCompleted ){
       
   351         LC_QDEBUG( "livecomms [UI]  Both swaps done, complete" )
       
   352         
       
   353         emit swapCompleted();
       
   354         
       
   355         if( mEngine.isLocalPlayerPlaying() ) {
       
   356             showSendWindow();
       
   357         }
       
   358         if( mEngine.isRemotePlayerPlaying() ) {
       
   359             showReceiveWindow();
       
   360         }
       
   361 
       
   362     mSwapInProgress = false;
       
   363     }
       
   364     LC_QDEBUG( "livecomms [UI] <- LcEffectHandler::handleSwapCompletion()" )
       
   365 }
       
   366 
       
   367 
       
   368 // -----------------------------------------------------------------------------
       
   369 //
       
   370 // -----------------------------------------------------------------------------
       
   371 //
       
   372 bool LcEffectHandler::isSwapInProgress()
       
   373 {
       
   374     return mSwapInProgress;
       
   375 }
       
   376 
       
   377 
       
   378 // End of file
       
   379