videoplayback/hbvideoplaybackview/controlsrc/mpxvideoplaybacktoolbar.cpp
changeset 39 f6d44a0cd476
parent 38 ff53afa8ad05
child 41 229f037ce963
equal deleted inserted replaced
38:ff53afa8ad05 39:f6d44a0cd476
    13 *
    13 *
    14 * Description:  Implementation of QMPXVideoPlaybackToolBar
    14 * Description:  Implementation of QMPXVideoPlaybackToolBar
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 // Version : %version:  4 %
    18 // Version : %version:  6 %
    19 
    19 
    20 
    20 
    21 
    21 
    22 #include <QTimer>
    22 #include <QTimer>
    23 #include <QGraphicsLayout>
    23 #include <QGraphicsLayout>
    49     : mController( controller )
    49     : mController( controller )
    50     , mSeekStartTimer( NULL )
    50     , mSeekStartTimer( NULL )
    51     , mRetrieveButtonTimer( NULL )
    51     , mRetrieveButtonTimer( NULL )
    52     , mSeekingState( EMPXNotSeeking )
    52     , mSeekingState( EMPXNotSeeking )
    53     , mInitialized( false )
    53     , mInitialized( false )
    54     , mNeverVisibled( true )
       
    55     , mPosition( 0 )
    54     , mPosition( 0 )
    56     , mDuration( 0 )
    55     , mDuration( 0 )
    57     , mAspectRatio( EMPXPbvCmdNaturalAspectRatio )
    56     , mAspectRatio( EMPXPbvCmdNaturalAspectRatio )
    58 {
    57 {
    59     MPX_ENTER_EXIT(_L("QMPXVideoPlaybackToolBar::QMPXVideoPlaybackToolBar"));
    58     MPX_ENTER_EXIT(_L("QMPXVideoPlaybackToolBar::QMPXVideoPlaybackToolBar"));
   204         //   if device is in landscape mode, width < height
   203         //   if device is in landscape mode, width < height
   205         //
   204         //
   206         TReal32 width = (TReal32) displayRect.Width();
   205         TReal32 width = (TReal32) displayRect.Width();
   207         TReal32 height = (TReal32) displayRect.Height();            
   206         TReal32 height = (TReal32) displayRect.Height();            
   208         mDisplayAspectRatio = (width > height)? (width / height) : (height / width);
   207         mDisplayAspectRatio = (width > height)? (width / height) : (height / width);
   209         
       
   210     }
   208     }
   211 }
   209 }
   212 
   210 
   213 // -------------------------------------------------------------------------------------------------
   211 // -------------------------------------------------------------------------------------------------
   214 // QMPXVideoPlaybackToolBar::playPause()
   212 // QMPXVideoPlaybackToolBar::playPause()
   406 {
   404 {
   407     MPX_DEBUG(_L("QMPXVideoPlaybackToolBar::aspectRatioChanged() aspectRatio = %d"), aspectRatio );
   405     MPX_DEBUG(_L("QMPXVideoPlaybackToolBar::aspectRatioChanged() aspectRatio = %d"), aspectRatio );
   408 
   406 
   409     mAspectRatio = aspectRatio;
   407     mAspectRatio = aspectRatio;
   410 
   408 
   411     if ( ! mController->isAttachOperation() )
   409     //
       
   410     // If we are in attach service or audio only view, then don't update the icon.
       
   411 	// Aspect ratio icon slots are shared with attach and share icon.
       
   412 	// Just update the mAspectRatio 
       
   413 	// and once we go back to full screen, we will show the correct aspect ratio icon
       
   414 	//
       
   415     if ( ! mController->isAttachOperation() && mController->viewMode() == EFullScreenView )
   412     {
   416     {
   413         switch( mAspectRatio )
   417         switch( mAspectRatio )
   414         {
   418         {
   415             case EMMFNatural:
   419             case EMMFNatural:
   416             {
   420             {
   588     else
   592     else
   589     {
   593     {
   590         mButtonActions[EMPX5thButton]->setEnabled( true );
   594         mButtonActions[EMPX5thButton]->setEnabled( true );
   591     }
   595     }
   592 
   596 
   593     if ( ! details->mSeekable )
   597     if ( details->mSeekable && details->mPausableStream )
       
   598     {
       
   599         mButtonActions[EMPX2ndButton]->setEnabled( true );
       
   600         mButtonActions[EMPX4thButton]->setEnabled( true );
       
   601     }
       
   602     else
   594     {
   603     {
   595         mButtonActions[EMPX2ndButton]->setEnabled( false );
   604         mButtonActions[EMPX2ndButton]->setEnabled( false );
   596         mButtonActions[EMPX4thButton]->setEnabled( false );
   605         mButtonActions[EMPX4thButton]->setEnabled( false );
   597     }
   606     }
       
   607 
       
   608     if ( details->mPausableStream )
       
   609     {
       
   610         mButtonActions[EMPX3rdButton]->setEnabled( true );
       
   611     }
   598     else
   612     else
   599     {
   613     {
   600         mButtonActions[EMPX2ndButton]->setEnabled( true );
       
   601         mButtonActions[EMPX4thButton]->setEnabled( true );
       
   602     }
       
   603 
       
   604     if ( ! details->mPausableStream )
       
   605     {
       
   606         mButtonActions[EMPX3rdButton]->setEnabled( false );
   614         mButtonActions[EMPX3rdButton]->setEnabled( false );
   607     }
   615     }
       
   616 
       
   617     //
       
   618     // toolbar creates button once it gets visible, so we don't know exact timing when toolbar 
       
   619     // creates button, so start timer to get layout information once the toolbar gets visible.
       
   620     // This is needed since we don't use toolbar in proper way.
       
   621     //
       
   622     if ( ! mRetrieveButtonTimer && ! mButtons.count() )
       
   623     {
       
   624         mRetrieveButtonTimer = new QTimer();
       
   625         mRetrieveButtonTimer->setSingleShot( false );
       
   626         mRetrieveButtonTimer->setInterval( KRetrieveButtonTimeOut );
       
   627         connect( mRetrieveButtonTimer, SIGNAL( timeout() ), this, SLOT( retrieveButtons() ) );            
       
   628 
       
   629         mRetrieveButtonTimer->start();        
       
   630     }
       
   631 
       
   632     durationChanged( (qreal)mController->fileDetails()->mDuration / (qreal)KPbMilliMultiplier );
       
   633 }
       
   634 
       
   635 // -------------------------------------------------------------------------------------------------
       
   636 // QMPXVideoPlaybackToolBar::openDetailsView()
       
   637 // -------------------------------------------------------------------------------------------------
       
   638 //
       
   639 void QMPXVideoPlaybackToolBar::openDetailsView()
       
   640 {
       
   641     MPX_ENTER_EXIT(_L("QMPXVideoPlaybackToolBar::openDetailsView()"));
       
   642 
       
   643     TPlaybackViewMode viewMode = mController->viewMode();
       
   644 
       
   645     if ( viewMode == EFullScreenView )
       
   646     {
       
   647         mController->changeViewMode( EDetailsView );
       
   648     }
       
   649 }
       
   650 
       
   651 // -------------------------------------------------------------------------------------------------
       
   652 // QMPXVideoPlaybackToolBar::positionChanged
       
   653 // -------------------------------------------------------------------------------------------------
       
   654 //
       
   655 void QMPXVideoPlaybackToolBar::positionChanged( int position )
       
   656 {
       
   657     MPX_DEBUG(_L("QMPXVideoPlaybackToolBar::positionChanged position = %d"), position );
       
   658 
       
   659     mPosition = position;
       
   660 }
       
   661 
       
   662 // -------------------------------------------------------------------------------------------------
       
   663 // QMPXVideoPlaybackToolBar::durationChanged
       
   664 // -------------------------------------------------------------------------------------------------
       
   665 //
       
   666 void QMPXVideoPlaybackToolBar::durationChanged( int duration )
       
   667 {
       
   668     MPX_DEBUG(_L("QMPXVideoPlaybackToolBar::durationChanged duration = %d"), duration );
       
   669 
       
   670     mDuration = duration;
       
   671 }
       
   672 
       
   673 // -------------------------------------------------------------------------------------------------
       
   674 // QMPXVideoPlaybackToolBar::setVisible
       
   675 // -------------------------------------------------------------------------------------------------
       
   676 //
       
   677 void QMPXVideoPlaybackToolBar::setVisible( bool visible )
       
   678 {
       
   679     MPX_DEBUG(_L("QMPXVideoPlaybackToolBar::setVisible visible = %d"), visible );
       
   680 
       
   681     if ( visible )
       
   682     {
       
   683         mController->view()->showItems( Hb::ToolBarItem );
       
   684     }
   608     else
   685     else
   609     {
   686     {
   610         mButtonActions[EMPX3rdButton]->setEnabled( true );
       
   611     }        
       
   612 }
       
   613 
       
   614 // -------------------------------------------------------------------------------------------------
       
   615 // QMPXVideoPlaybackToolBar::openDetailsView()
       
   616 // -------------------------------------------------------------------------------------------------
       
   617 //
       
   618 void QMPXVideoPlaybackToolBar::openDetailsView()
       
   619 {
       
   620     MPX_ENTER_EXIT(_L("QMPXVideoPlaybackToolBar::openDetailsView()"));
       
   621 
       
   622     TPlaybackViewMode viewMode = mController->viewMode();
       
   623 
       
   624     if ( viewMode == EFullScreenView )
       
   625     {
       
   626         mController->changeViewMode( EDetailsView );
       
   627     }
       
   628 }
       
   629 
       
   630 // -------------------------------------------------------------------------------------------------
       
   631 // QMPXVideoPlaybackToolBar::positionChanged
       
   632 // -------------------------------------------------------------------------------------------------
       
   633 //
       
   634 void QMPXVideoPlaybackToolBar::positionChanged( int position )
       
   635 {
       
   636     MPX_DEBUG(_L("QMPXVideoPlaybackToolBar::positionChanged position = %d"), position );
       
   637 
       
   638     mPosition = position;
       
   639     retrieveButtons();
       
   640 }
       
   641 
       
   642 // -------------------------------------------------------------------------------------------------
       
   643 // QMPXVideoPlaybackToolBar::durationChanged
       
   644 // -------------------------------------------------------------------------------------------------
       
   645 //
       
   646 void QMPXVideoPlaybackToolBar::durationChanged( int duration )
       
   647 {
       
   648     MPX_DEBUG(_L("QMPXVideoPlaybackToolBar::durationChanged duration = %d"), duration );
       
   649 
       
   650     mDuration = duration;
       
   651 }
       
   652 
       
   653 // -------------------------------------------------------------------------------------------------
       
   654 // QMPXVideoPlaybackToolBar::setVisible
       
   655 // -------------------------------------------------------------------------------------------------
       
   656 //
       
   657 void QMPXVideoPlaybackToolBar::setVisible( bool visible )
       
   658 {
       
   659     MPX_DEBUG(_L("QMPXVideoPlaybackToolBar::setVisible visible = %d"), visible );
       
   660 
       
   661     if ( visible )
       
   662     {
       
   663         mController->view()->showItems( Hb::ToolBarItem );
       
   664 
       
   665         if ( mNeverVisibled )
       
   666         {
       
   667             mNeverVisibled = false;
       
   668 
       
   669 
       
   670             //
       
   671             // toolbar creates button once it gets visible, so we don't know exact timing when toolbar 
       
   672             // creates button, so start timer to get layout information once the toolbar gets visible.
       
   673             // This is needed since we don't use toolbar in proper way.
       
   674             //
       
   675             mRetrieveButtonTimer = new QTimer();
       
   676             mRetrieveButtonTimer->setSingleShot( false );
       
   677             mRetrieveButtonTimer->setInterval( KRetrieveButtonTimeOut );
       
   678             connect( mRetrieveButtonTimer, SIGNAL( timeout() ), this, SLOT( retrieveButtons() ) );
       
   679 
       
   680             mRetrieveButtonTimer->start();
       
   681         }
       
   682     }
       
   683     else
       
   684     {
       
   685         mController->view()->hideItems( Hb::ToolBarItem );
   687         mController->view()->hideItems( Hb::ToolBarItem );
   686     }
   688     }
   687 }
   689 }
   688 
   690 
   689 // -------------------------------------------------------------------------------------------------
   691 // -------------------------------------------------------------------------------------------------
   698     {
   700     {
   699         QGraphicsLayout *layout = mToolBar->layout();
   701         QGraphicsLayout *layout = mToolBar->layout();
   700 
   702 
   701         if ( layout )
   703         if ( layout )
   702         {
   704         {
   703 		    disconnect( mRetrieveButtonTimer, SIGNAL( timeout() ), this, SLOT( retrieveButtons() ) );
   705             if ( mRetrieveButtonTimer )
   704             if ( mRetrieveButtonTimer->isActive() )
   706             {
   705             {
   707                 disconnect( mRetrieveButtonTimer, SIGNAL( timeout() ), this, SLOT( retrieveButtons() ) );
   706                 mRetrieveButtonTimer->stop();
   708                 if ( mRetrieveButtonTimer->isActive() )
       
   709                 {
       
   710                     mRetrieveButtonTimer->stop();
       
   711                 }                
   707             }
   712             }
   708 
   713 
   709             for ( int i = 0 ; i < layout->count() ; i++ )
   714             for ( int i = 0 ; i < layout->count() ; i++ )
   710             {
   715             {
   711                 mButtons.append( dynamic_cast<HbToolButton*>( layout->itemAt( i ) ) );
   716                 mButtons.append( dynamic_cast<HbToolButton*>( layout->itemAt( i ) ) );