videoplayback/hbvideoplaybackview/controlsrc/mpxvideoplaybacktoolbar.cpp
changeset 41 229f037ce963
parent 39 f6d44a0cd476
equal deleted inserted replaced
40:13331705e488 41:229f037ce963
    13 *
    13 *
    14 * Description:  Implementation of QMPXVideoPlaybackToolBar
    14 * Description:  Implementation of QMPXVideoPlaybackToolBar
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 // Version : %version:  6 %
    18 // Version : %version:  7 %
    19 
    19 
    20 
    20 
    21 
    21 
    22 #include <QTimer>
    22 #include <QTimer>
    23 #include <QGraphicsLayout>
    23 #include <QGraphicsLayout>
    24 
    24 
    25 #include <hbeffect.h>
       
    26 #include <hbaction.h>
    25 #include <hbaction.h>
    27 #include <hbtoolbar.h>
    26 #include <hbtoolbar.h>
    28 #include <hbinstance.h>
    27 #include <hbinstance.h>
    29 #include <hbtoolbutton.h>
    28 #include <hbtoolbutton.h>
    30 #include <w32std.h>
    29 #include <w32std.h>
    42 
    41 
    43 // -------------------------------------------------------------------------------------------------
    42 // -------------------------------------------------------------------------------------------------
    44 // QMPXVideoPlaybackToolBar::QMPXVideoPlaybackToolBar()
    43 // QMPXVideoPlaybackToolBar::QMPXVideoPlaybackToolBar()
    45 // -------------------------------------------------------------------------------------------------
    44 // -------------------------------------------------------------------------------------------------
    46 //
    45 //
    47 QMPXVideoPlaybackToolBar::QMPXVideoPlaybackToolBar( 
    46 QMPXVideoPlaybackToolBar::QMPXVideoPlaybackToolBar(
    48         QMPXVideoPlaybackControlsController* controller )
    47         QMPXVideoPlaybackControlsController* controller )
    49     : mController( controller )
    48     : mController( controller )
    50     , mSeekStartTimer( NULL )
    49     , mSeekStartTimer( NULL )
    51     , mRetrieveButtonTimer( NULL )
    50     , mRetrieveButtonTimer( NULL )
    52     , mSeekingState( EMPXNotSeeking )
    51     , mSeekingState( EMPXNotSeeking )
    57 {
    56 {
    58     MPX_ENTER_EXIT(_L("QMPXVideoPlaybackToolBar::QMPXVideoPlaybackToolBar"));
    57     MPX_ENTER_EXIT(_L("QMPXVideoPlaybackToolBar::QMPXVideoPlaybackToolBar"));
    59 
    58 
    60     mToolBar = mController->view()->toolBar();
    59     mToolBar = mController->view()->toolBar();
    61     mToolBar->setOrientation( Qt::Horizontal );
    60     mToolBar->setOrientation( Qt::Horizontal );
    62     HbEffect::disable( mToolBar );
    61 
    63     
       
    64     mController->view()->hideItems( Hb::ToolBarItem );
    62     mController->view()->hideItems( Hb::ToolBarItem );
    65 
    63 
    66     initialize();
    64     initialize();
    67 }
    65 }
    68 
    66 
    72 //
    70 //
    73 QMPXVideoPlaybackToolBar::~QMPXVideoPlaybackToolBar()
    71 QMPXVideoPlaybackToolBar::~QMPXVideoPlaybackToolBar()
    74 {
    72 {
    75     MPX_DEBUG(_L("QMPXVideoPlaybackToolBar::~QMPXVideoPlaybackToolBar()"));
    73     MPX_DEBUG(_L("QMPXVideoPlaybackToolBar::~QMPXVideoPlaybackToolBar()"));
    76 
    74 
    77     HbEffect::enable( mToolBar );
       
    78     mToolBar->clearActions();
    75     mToolBar->clearActions();
    79 
    76 
    80     for ( int i = 0 ; i < mButtonIcons.count() ; i++ )
    77     for ( int i = 0 ; i < mButtonIcons.count() ; i++ )
    81     {
    78     {
    82         if ( mButtonIcons[i] )
    79         if ( mButtonIcons[i] )
   168         mButtonIcons[EMPXStretchIcon]->setIconName( "qtg_mono_aspect_ratio_stretched" );
   165         mButtonIcons[EMPXStretchIcon]->setIconName( "qtg_mono_aspect_ratio_stretched" );
   169         mButtonIcons[EMPXZoomIcon]->setIconName( "qtg_mono_aspect_ratio_zoom" );
   166         mButtonIcons[EMPXZoomIcon]->setIconName( "qtg_mono_aspect_ratio_zoom" );
   170         mButtonActions[EMPX1stButton]->setIcon( *mButtonIcons[EMPXNaturalIcon] );
   167         mButtonActions[EMPX1stButton]->setIcon( *mButtonIcons[EMPXNaturalIcon] );
   171 
   168 
   172         //
   169         //
   173         // Attach/Share button 
   170         // Attach/Share button
   174         //
   171         //
   175         mButtonIcons[EMPXAttachIcon]->setIconName( "qtg_mono_attach" );
   172         mButtonIcons[EMPXAttachIcon]->setIconName( "qtg_mono_attach" );
   176         mButtonIcons[EMPXShareIcon]->setIconName( "qtg_mono_share" );
   173         mButtonIcons[EMPXShareIcon]->setIconName( "qtg_mono_share" );
   177 
   174 
   178         for ( int i = 0 ; i < EMPXButtonCount ; i++ )
   175         for ( int i = 0 ; i < EMPXButtonCount ; i++ )
   182         }
   179         }
   183 
   180 
   184         mDuration = (qreal)mController->fileDetails()->mDuration / (qreal)KPbMilliMultiplier;
   181         mDuration = (qreal)mController->fileDetails()->mDuration / (qreal)KPbMilliMultiplier;
   185 
   182 
   186         //
   183         //
   187         // Create a timer for seeking. 
   184         // Create a timer for seeking.
   188         // We will issue SetPosition every KSeekingTimeOut msec to show the current frame to user
   185         // We will issue SetPosition every KSeekingTimeOut msec to show the current frame to user
   189         //
   186         //
   190         mSeekStartTimer = new QTimer();
   187         mSeekStartTimer = new QTimer();
   191         mSeekStartTimer->setSingleShot( true );
   188         mSeekStartTimer->setSingleShot( true );
   192         mSeekStartTimer->setInterval( KSeekStartTimeOut );
   189         mSeekStartTimer->setInterval( KSeekStartTimeOut );
   193         
   190 
   194         //
   191         //
   195         // get window size
   192         // get window size
   196         //
   193         //
   197         RWindow *window = mController->view()->getWindow();            
   194         RWindow *window = mController->view()->getWindow();
   198         TRect displayRect = TRect( TPoint( window->Position() ), TSize( window->Size() ) );
   195         TRect displayRect = TRect( TPoint( window->Position() ), TSize( window->Size() ) );
   199         
   196 
   200         //
   197         //
   201         // get window aspect ratio
   198         // get window aspect ratio
   202         //   if device is in portrait mode, width > height
   199         //   if device is in portrait mode, width > height
   203         //   if device is in landscape mode, width < height
   200         //   if device is in landscape mode, width < height
   204         //
   201         //
   205         TReal32 width = (TReal32) displayRect.Width();
   202         TReal32 width = (TReal32) displayRect.Width();
   206         TReal32 height = (TReal32) displayRect.Height();            
   203         TReal32 height = (TReal32) displayRect.Height();
   207         mDisplayAspectRatio = (width > height)? (width / height) : (height / width);
   204         mDisplayAspectRatio = (width > height)? (width / height) : (height / width);
   208     }
   205     }
   209 }
   206 }
   210 
   207 
   211 // -------------------------------------------------------------------------------------------------
   208 // -------------------------------------------------------------------------------------------------
   231 
   228 
   232     if ( mSeekingState == EMPXNotSeeking )
   229     if ( mSeekingState == EMPXNotSeeking )
   233     {
   230     {
   234         mSeekingState = EMPXFastForwarding;
   231         mSeekingState = EMPXFastForwarding;
   235 
   232 
   236         mController->handleCommand( EMPXPbvCmdSeekForward );        
   233         mController->handleCommand( EMPXPbvCmdSeekForward );
   237     }
   234     }
   238 }
   235 }
   239 
   236 
   240 // -------------------------------------------------------------------------------------------------
   237 // -------------------------------------------------------------------------------------------------
   241 // QMPXVideoPlaybackToolBar::rwPressing()
   238 // QMPXVideoPlaybackToolBar::rwPressing()
   270         mSeekStartTimer->stop();
   267         mSeekStartTimer->stop();
   271     }
   268     }
   272 
   269 
   273     if ( mSeekingState == EMPXFastForwarding )
   270     if ( mSeekingState == EMPXFastForwarding )
   274     {
   271     {
   275         mController->handleCommand( EMPXPbvCmdEndSeek );        
   272         mController->handleCommand( EMPXPbvCmdEndSeek );
   276     }
   273     }
   277     else
   274     else
   278     {
   275     {
   279         int temp = mPosition + KMPXFastForward;
   276         int temp = mPosition + KMPXFastForward;
   280         MPX_DEBUG(_L("QMPXVideoPlaybackToolBar::ffReleased() temp position = %d"), temp);
   277         MPX_DEBUG(_L("QMPXVideoPlaybackToolBar::ffReleased() temp position = %d"), temp);
   308         mSeekStartTimer->stop();
   305         mSeekStartTimer->stop();
   309     }
   306     }
   310 
   307 
   311     if ( mSeekingState == EMPXRewinding )
   308     if ( mSeekingState == EMPXRewinding )
   312     {
   309     {
   313         mController->handleCommand( EMPXPbvCmdEndSeek );        
   310         mController->handleCommand( EMPXPbvCmdEndSeek );
   314     }
   311     }
   315     else
   312     else
   316     {
   313     {
   317         int temp = mPosition + KMPXRewind;
   314         int temp = mPosition + KMPXRewind;
   318         MPX_DEBUG(_L("QMPXVideoPlaybackToolBar::rwReleased() temp position = %d"), temp);
   315         MPX_DEBUG(_L("QMPXVideoPlaybackToolBar::rwReleased() temp position = %d"), temp);
   339 void QMPXVideoPlaybackToolBar::changeAspectRatio()
   336 void QMPXVideoPlaybackToolBar::changeAspectRatio()
   340 {
   337 {
   341     MPX_DEBUG(_L("QMPXVideoPlaybackToolBar::changeAspectRatio()"));
   338     MPX_DEBUG(_L("QMPXVideoPlaybackToolBar::changeAspectRatio()"));
   342 
   339 
   343     mController->resetDisappearingTimers( EMPXTimerReset );
   340     mController->resetDisappearingTimers( EMPXTimerReset );
   344     
   341 
   345     TMPXVideoPlaybackViewCommandIds cmd = EMPXPbvCmdStretchAspectRatio;
   342     TMPXVideoPlaybackViewCommandIds cmd = EMPXPbvCmdStretchAspectRatio;
   346 
   343 
   347     switch( mAspectRatio )
   344     switch( mAspectRatio )
   348     {
   345     {
   349         case EMMFZoom:
   346         case EMMFZoom:
   407     mAspectRatio = aspectRatio;
   404     mAspectRatio = aspectRatio;
   408 
   405 
   409     //
   406     //
   410     // If we are in attach service or audio only view, then don't update the icon.
   407     // 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.
   408 	// Aspect ratio icon slots are shared with attach and share icon.
   412 	// Just update the mAspectRatio 
   409 	// Just update the mAspectRatio
   413 	// and once we go back to full screen, we will show the correct aspect ratio icon
   410 	// and once we go back to full screen, we will show the correct aspect ratio icon
   414 	//
   411 	//
   415     if ( ! mController->isAttachOperation() && mController->viewMode() == EFullScreenView )
   412     if ( ! mController->isAttachOperation() && mController->viewMode() == EFullScreenView )
   416     {
   413     {
   417         switch( mAspectRatio )
   414         switch( mAspectRatio )
   429             default:
   426             default:
   430             {
   427             {
   431                 mButtonActions[EMPX1stButton]->setIcon( *mButtonIcons[EMPXNaturalIcon] );
   428                 mButtonActions[EMPX1stButton]->setIcon( *mButtonIcons[EMPXNaturalIcon] );
   432                 break;
   429                 break;
   433             }
   430             }
   434         }    
   431         }
   435     }
   432     }
   436 }
   433 }
   437 
   434 
   438 // -------------------------------------------------------------------------------------------------
   435 // -------------------------------------------------------------------------------------------------
   439 // QMPXVideoPlaybackToolBar::handleButtonPressed()
   436 // QMPXVideoPlaybackToolBar::handleButtonPressed()
   529                 mButtonActions[EMPX1stButton]->setEnabled( false );
   526                 mButtonActions[EMPX1stButton]->setEnabled( false );
   530             }
   527             }
   531             else
   528             else
   532             {
   529             {
   533                 //
   530                 //
   534                 // check if video clip has same aspect ratio as display window 
   531                 // check if video clip has same aspect ratio as display window
   535                 //
   532                 //
   536                 TReal32 videoAspectRatio = (TReal32) details->mVideoWidth / (TReal32) details->mVideoHeight; 
   533                 TReal32 videoAspectRatio = (TReal32) details->mVideoWidth / (TReal32) details->mVideoHeight;
   537                 bool enabled = ( mDisplayAspectRatio == videoAspectRatio )? false : true;
   534                 bool enabled = ( mDisplayAspectRatio == videoAspectRatio )? false : true;
   538                 
   535 
   539                 //
   536                 //
   540                 // enable or dim 'aspect ratio' buttons accordingly
   537                 // enable or dim 'aspect ratio' buttons accordingly
   541                 //
   538                 //
   542                 mButtonActions[EMPX1stButton]->setEnabled( enabled );
   539                 mButtonActions[EMPX1stButton]->setEnabled( enabled );
   543 
   540 
   546                     disconnect( mButtons[EMPX1stButton], SIGNAL( released() ), 0, 0 );
   543                     disconnect( mButtons[EMPX1stButton], SIGNAL( released() ), 0, 0 );
   547                     connect( mButtons[EMPX1stButton], SIGNAL( released() ),
   544                     connect( mButtons[EMPX1stButton], SIGNAL( released() ),
   548                              this, SLOT( changeAspectRatio() ) );
   545                              this, SLOT( changeAspectRatio() ) );
   549                 }
   546                 }
   550             }
   547             }
   551         }                
   548         }
   552         else if ( mController->viewMode() == EAudioOnlyView )
   549         else if ( mController->viewMode() == EAudioOnlyView )
   553         {
   550         {
   554             //
   551             //
   555             // Show share button
   552             // Show share button
   556             //
   553             //
   572                 mButtonActions[EMPX1stButton]->setEnabled( true );
   569                 mButtonActions[EMPX1stButton]->setEnabled( true );
   573 
   570 
   574                 if ( mButtons.count() )
   571                 if ( mButtons.count() )
   575                 {
   572                 {
   576                     disconnect( mButtons[EMPX1stButton], SIGNAL( released() ), 0, 0 );
   573                     disconnect( mButtons[EMPX1stButton], SIGNAL( released() ), 0, 0 );
   577                     connect( mButtons[EMPX1stButton], SIGNAL( released() ), 
   574                     connect( mButtons[EMPX1stButton], SIGNAL( released() ),
   578                              mController, SLOT( sendVideo() ) );
   575                              mController, SLOT( sendVideo() ) );
   579                 }
   576                 }
   580             }
   577             }
   581         }
   578         }
   582     }
   579     }
   613     {
   610     {
   614         mButtonActions[EMPX3rdButton]->setEnabled( false );
   611         mButtonActions[EMPX3rdButton]->setEnabled( false );
   615     }
   612     }
   616 
   613 
   617     //
   614     //
   618     // toolbar creates button once it gets visible, so we don't know exact timing when toolbar 
   615     // 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.
   616     // 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.
   617     // This is needed since we don't use toolbar in proper way.
   621     //
   618     //
   622     if ( ! mRetrieveButtonTimer && ! mButtons.count() )
   619     if ( ! mRetrieveButtonTimer && ! mButtons.count() )
   623     {
   620     {
   624         mRetrieveButtonTimer = new QTimer();
   621         mRetrieveButtonTimer = new QTimer();
   625         mRetrieveButtonTimer->setSingleShot( false );
   622         mRetrieveButtonTimer->setSingleShot( false );
   626         mRetrieveButtonTimer->setInterval( KRetrieveButtonTimeOut );
   623         mRetrieveButtonTimer->setInterval( KRetrieveButtonTimeOut );
   627         connect( mRetrieveButtonTimer, SIGNAL( timeout() ), this, SLOT( retrieveButtons() ) );            
   624         connect( mRetrieveButtonTimer, SIGNAL( timeout() ), this, SLOT( retrieveButtons() ) );
   628 
   625 
   629         mRetrieveButtonTimer->start();        
   626         mRetrieveButtonTimer->start();
   630     }
   627     }
   631 
   628 
   632     durationChanged( (qreal)mController->fileDetails()->mDuration / (qreal)KPbMilliMultiplier );
   629     durationChanged( (qreal)mController->fileDetails()->mDuration / (qreal)KPbMilliMultiplier );
   633 }
   630 }
   634 
   631 
   706             {
   703             {
   707                 disconnect( mRetrieveButtonTimer, SIGNAL( timeout() ), this, SLOT( retrieveButtons() ) );
   704                 disconnect( mRetrieveButtonTimer, SIGNAL( timeout() ), this, SLOT( retrieveButtons() ) );
   708                 if ( mRetrieveButtonTimer->isActive() )
   705                 if ( mRetrieveButtonTimer->isActive() )
   709                 {
   706                 {
   710                     mRetrieveButtonTimer->stop();
   707                     mRetrieveButtonTimer->stop();
   711                 }                
   708                 }
   712             }
   709             }
   713 
   710 
   714             for ( int i = 0 ; i < layout->count() ; i++ )
   711             for ( int i = 0 ; i < layout->count() ; i++ )
   715             {
   712             {
   716                 mButtons.append( dynamic_cast<HbToolButton*>( layout->itemAt( i ) ) );
   713                 mButtons.append( dynamic_cast<HbToolButton*>( layout->itemAt( i ) ) );
   742             {
   739             {
   743                 if ( mController->viewMode() == EFullScreenView )
   740                 if ( mController->viewMode() == EFullScreenView )
   744                 {
   741                 {
   745                     connect( mButtons[EMPX1stButton], SIGNAL( released() ),
   742                     connect( mButtons[EMPX1stButton], SIGNAL( released() ),
   746                              this, SLOT( changeAspectRatio() ) );
   743                              this, SLOT( changeAspectRatio() ) );
   747                 }                
   744                 }
   748                 else if ( mController->viewMode() == EAudioOnlyView )
   745                 else if ( mController->viewMode() == EAudioOnlyView )
   749                 {
   746                 {
   750                     connect( mButtons[EMPX1stButton], SIGNAL( released() ), 
   747                     connect( mButtons[EMPX1stButton], SIGNAL( released() ),
   751                              mController, SLOT( sendVideo() ) );
   748                              mController, SLOT( sendVideo() ) );
   752                 }
   749                 }
   753             }
   750             }
   754         }
   751         }
   755     }
   752     }