voicerecorder/RecViewSrc/CVRStateInfoPanel.cpp
changeset 0 845549f293a7
child 13 4e5b531d23cb
equal deleted inserted replaced
-1:000000000000 0:845549f293a7
       
     1 /*
       
     2 * Copyright (c) 2002 - 2006 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 *     A compound control class. It is responsible for drawing and updating
       
    16 *     a set of labels, and a progress bar.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include <AknUtils.h>
       
    24 #include <AknsUtils.h>
       
    25 #include <eikprogi.h>
       
    26 #include <aknenv.h>
       
    27 #include <applayout.cdl.h>
       
    28 #include <aknview.h>
       
    29 #include <aknViewAppUi.h>
       
    30 #include <AknDef.h>
       
    31 #include <AknsConstants.h>
       
    32 #include <aknlayoutscalable_apps.cdl.h>
       
    33 
       
    34 #include "CVRLabel.h"
       
    35 #include "CVRStateInfoPanel.h"
       
    36 #include "MVRStateInfoModel.h"
       
    37 #include "voicerecorder.hrh"
       
    38 #include "VRConsts.h"
       
    39 
       
    40 // CONSTANTS
       
    41 const TInt KVRLabelMap[] =
       
    42 	{
       
    43 	CVRStateInfoPanel::ELabelName,
       
    44 	CVRStateInfoPanel::ELabelDate,
       
    45 	CVRStateInfoPanel::ELabelQuality,
       
    46 	CVRStateInfoPanel::ELabelStatus,
       
    47 	CVRStateInfoPanel::ELabelMax,
       
    48 	CVRStateInfoPanel::ELabelMin,
       
    49 	CVRStateInfoPanel::ELabelQualityText
       
    50 	};
       
    51 	
       
    52 _LIT( KVREmptyLabel, " " );
       
    53 
       
    54 
       
    55 // ================= MEMBER FUNCTIONS ========================================
       
    56 
       
    57 // ----------------------------------------------------------------------------
       
    58 // CVRStateInfoPanel::CVRStateInfoPanel
       
    59 // 
       
    60 // ----------------------------------------------------------------------------
       
    61 //		
       
    62 CVRStateInfoPanel::CVRStateInfoPanel( MVRStateInfoModel* aModel )
       
    63 	: iModel( aModel ), iLabels( ENumLabels ), iPBposition( 0 )
       
    64 	{
       
    65 	if ( iModel )
       
    66 		{
       
    67 		iModel->SetStateInfoObserver( this );
       
    68 		}
       
    69 	}
       
    70 
       
    71 
       
    72 // ----------------------------------------------------------------------------
       
    73 // CVRStateInfoPanel::CVRStateInfoPanel
       
    74 // 
       
    75 // ----------------------------------------------------------------------------
       
    76 //		
       
    77 CVRStateInfoPanel::CVRStateInfoPanel( MVRStateInfoModel* aModel,
       
    78                                				TUid aParentViewUid )
       
    79 	: iModel( aModel ), 
       
    80 	iLabels( ENumLabels ),
       
    81 	iParentViewUid( aParentViewUid ), 
       
    82 	iPBposition( 0 )
       
    83 	{
       
    84 	if ( iModel )
       
    85 		{
       
    86 		iModel->SetStateInfoObserver( this );
       
    87 		iModel->SetStateInfoPanelObserver( this );
       
    88 		}
       
    89 	}
       
    90 
       
    91 
       
    92 // ----------------------------------------------------------------------------
       
    93 // CVRStateInfoPanel::~CVRStateInfoPanel
       
    94 // 
       
    95 // ----------------------------------------------------------------------------
       
    96 //			
       
    97 CVRStateInfoPanel::~CVRStateInfoPanel()
       
    98 	{
       
    99 	if ( iModel )
       
   100 		{
       
   101 		iModel->SetStateInfoObserver( NULL );
       
   102 		}
       
   103 	iLabels.ResetAndDestroy();
       
   104 	delete iProgressBar;
       
   105 	iSkin = NULL;
       
   106 	}
       
   107 
       
   108 
       
   109 // ----------------------------------------------------------------------------
       
   110 // CVRStateInfoPanel::ConstructL
       
   111 // 
       
   112 // ----------------------------------------------------------------------------
       
   113 //		
       
   114 void CVRStateInfoPanel::ConstructL()
       
   115 	{
       
   116 	// New skin instance is loaded
       
   117 	iSkin = AknsUtils::SkinInstance();
       
   118 	
       
   119 	// Create labels
       
   120 	for ( TInt i = 0; i < ENumLabels; i++ )
       
   121 		{
       
   122 		CVRLabel* label = CVRLabel::NewLC( *this );
       
   123 
       
   124 		// Set the MOP-parent so that the labels can get the 
       
   125 		// skin context from rec view container
       
   126 		label->SetMopParent( this );
       
   127 		iLabels.AppendL( label );
       
   128 		CleanupStack::Pop(); // label;
       
   129 
       
   130 		// Set initial text for label
       
   131 		TBuf< VRLABELMAXLENGTH > str;
       
   132 		iModel->GetLabel( str, i );
       
   133 		label->SetText( str );
       
   134 		}
       
   135 
       
   136 	CreateProgressBarL();
       
   137 	UpdateLayoutL();
       
   138 	}
       
   139 
       
   140 
       
   141 // ----------------------------------------------------------------------------
       
   142 // CVRStateInfoPanel::CreateProgressBarL
       
   143 // 
       
   144 // ----------------------------------------------------------------------------
       
   145 //		
       
   146 void CVRStateInfoPanel::CreateProgressBarL()
       
   147 	{
       
   148 	delete iProgressBar;
       
   149 	iProgressBar = NULL;
       
   150 
       
   151 	// Create progress bar
       
   152 	CEikProgressInfo::SInfo info = ProgressInfo();
       
   153 
       
   154 	iProgressBar = new( ELeave ) CEikProgressInfo( info );
       
   155 	iProgressBar->SetContainerWindowL( *this );
       
   156 	
       
   157 	// Set the MOP-parent so that the progress bar can get the 
       
   158 	// skin context from rec view container
       
   159 	iProgressBar->SetMopParent( this );
       
   160 	iProgressBar->ConstructL();
       
   161 
       
   162 	iProgressBar->ActivateL();
       
   163 	AknLayoutUtils::LayoutControl( iProgressBar, Rect(),
       
   164 		AppLayout::Voice_Recorder_elements_Line_4() );
       
   165 	}
       
   166 
       
   167 
       
   168 // ----------------------------------------------------------------------------
       
   169 // CVRStateInfoPanel::SizeChanged
       
   170 // 
       
   171 // ----------------------------------------------------------------------------
       
   172 //		
       
   173 void CVRStateInfoPanel::SizeChanged()
       
   174 	{
       
   175 	
       
   176 	for ( TInt i = 0; i < ENumLabels; i++ )
       
   177 		{
       
   178 		TAknTextComponentLayout layoutText = AknLayoutScalable_Apps::vorec_t(
       
   179 			KVRLabelMap[i] );
       
   180 		AknLayoutUtils::LayoutLabel( iLabels.At( i ), Rect(), layoutText.LayoutLine() );
       
   181 		
       
   182 		if ( i != ELabelStatus )
       
   183 			{
       
   184 			// Get the correct text color from skin and override it
       
   185 			// The status label is always red, i guess
       
   186 			CCoeControl* label( iLabels.At( i ) );
       
   187 			TRgb color( KRgbBlack );
       
   188 			AknsUtils::GetCachedColor( iSkin, color, KAknsIIDQsnTextColors,
       
   189 				EAknsCIQsnTextColorsCG6 );		
       
   190 			// We can ignore the error, it only means we will have wrong color
       
   191 			TRAP_IGNORE( AknLayoutUtils::OverrideControlColorL( *label,
       
   192 				EColorLabelText, color ) );
       
   193 			}
       
   194 		}
       
   195 
       
   196 	// There's nothing rational to do here if it leaves
       
   197 	TRAP_IGNORE( CreateProgressBarL() );	
       
   198 	}
       
   199 
       
   200 
       
   201 // ----------------------------------------------------------------------------
       
   202 // CVRStateInfoPanel::Draw
       
   203 // 
       
   204 // ----------------------------------------------------------------------------
       
   205 //		
       
   206 void CVRStateInfoPanel::Draw( const TRect& /*aRect*/ ) const
       
   207 	{
       
   208 	}
       
   209 
       
   210 
       
   211 // ----------------------------------------------------------------------------
       
   212 // CVRStateInfoPanel::CountComponentControls
       
   213 // 
       
   214 // ----------------------------------------------------------------------------
       
   215 //		
       
   216 TInt CVRStateInfoPanel::CountComponentControls() const
       
   217 	{
       
   218 	TInt componentCount( 0 );
       
   219 	if ( iProgressBar )
       
   220 		{
       
   221 		componentCount = ENumLabels + 1;  // +1 means iProgressBar
       
   222 		}
       
   223 	return componentCount;
       
   224 	}
       
   225 
       
   226 
       
   227 // ----------------------------------------------------------------------------
       
   228 // CVRStateInfoPanel::ComponentControl
       
   229 // 
       
   230 // ----------------------------------------------------------------------------
       
   231 //		
       
   232 CCoeControl* CVRStateInfoPanel::ComponentControl( TInt aIndex ) const
       
   233 	{
       
   234 	if ( aIndex < ENumLabels )
       
   235 		{
       
   236 		return iLabels.At( aIndex );
       
   237 		}
       
   238 	else
       
   239 		{
       
   240 		return iProgressBar;
       
   241 		}
       
   242 	}
       
   243 
       
   244 
       
   245 // ----------------------------------------------------------------------------
       
   246 // CVRStateInfoPanel::Update
       
   247 // 
       
   248 // ----------------------------------------------------------------------------
       
   249 //		
       
   250 void CVRStateInfoPanel::Update( TVRUpdateCommand /*aCommand*/ )
       
   251 	{
       
   252 	for ( TInt i = 0; i < ENumLabels; i++ )
       
   253 		{
       
   254 		TBuf< VRLABELMAXLENGTH > str;
       
   255 		iModel->GetLabel( str, i );
       
   256 		if ( str.Length() < 1 )
       
   257 			{
       
   258 			// "" doesn't empty the label, so use space
       
   259 			str = KVREmptyLabel;
       
   260 			}
       
   261 		iLabels.At( i )->SetTextAndDraw( str );
       
   262 		}
       
   263 	
       
   264 	UpdateProgressBar();
       
   265 	
       
   266 	}
       
   267 
       
   268 
       
   269 // ----------------------------------------------------------------------------
       
   270 // CVRStateInfoPanel::UpdateLayoutL
       
   271 // 
       
   272 // ----------------------------------------------------------------------------
       
   273 //		
       
   274 void CVRStateInfoPanel::UpdateLayoutL()
       
   275 	{
       
   276 	SizeChanged();
       
   277 	}
       
   278 
       
   279 
       
   280 
       
   281 // ----------------------------------------------------------------------------
       
   282 // CVRStateInfoPanel::ProgressInfo
       
   283 // 
       
   284 // ----------------------------------------------------------------------------
       
   285 //		
       
   286 CEikProgressInfo::SInfo CVRStateInfoPanel::ProgressInfo()
       
   287 	{
       
   288 	CEikProgressInfo::SInfo info;
       
   289 
       
   290 	TAknWindowLineLayout infobarLayout =
       
   291 		AppLayout::Voice_Recorder_elements_Line_4();
       
   292     TAknLayoutRect infobarRect;
       
   293     infobarRect.LayoutRect( Rect(), infobarLayout );	
       
   294   
       
   295     info.iWidth = infobarRect.Rect().Width();
       
   296 	info.iHeight = infobarRect.Rect().Height();
       
   297 
       
   298 	return info;
       
   299 	}
       
   300 
       
   301 
       
   302 // ----------------------------------------------------------------------------
       
   303 // CVRStateInfoPanel::HandleResourceChangeL
       
   304 // 
       
   305 // ----------------------------------------------------------------------------
       
   306 //		
       
   307 void CVRStateInfoPanel::HandleResourceChangeL( TInt aType )
       
   308 	{
       
   309     if ( aType == KEikDynamicLayoutVariantSwitch )
       
   310         {
       
   311 		UpdateLayoutL();
       
   312         }
       
   313 	else if ( aType == KAknsMessageSkinChange )
       
   314 		{
       
   315 		// New skin instance is loaded
       
   316 		iSkin = AknsUtils::SkinInstance();
       
   317 		}
       
   318 	
       
   319 	for ( TInt i = 0; i < ENumLabels; i++ )
       
   320 		{
       
   321 		if ( i < iLabels.Count() )
       
   322 			{
       
   323 			iLabels.At( i )->HandleResourceChange( aType );	
       
   324 			}
       
   325 		}
       
   326 		
       
   327 	iProgressBar->HandleResourceChange( aType );
       
   328 	UpdateProgressBar();
       
   329 	
       
   330 	CCoeControl::HandleResourceChange( aType );
       
   331 	}
       
   332 
       
   333 
       
   334 // ----------------------------------------------------------------------------
       
   335 // CVRStateInfoPanel::UpdateProgressBar
       
   336 // 
       
   337 // ----------------------------------------------------------------------------
       
   338 //		
       
   339 void CVRStateInfoPanel::UpdateProgressBar()
       
   340 	{
       
   341 	
       
   342 	if ( iProgressBar )
       
   343 		{
       
   344 		if ( iModel->HasProgressBar() )
       
   345 			{
       
   346 			iProgressBar->SetFinalValue( I64INT( iModel->Duration().Int64() /
       
   347 										 KVRSecondAsMicroSeconds ) );
       
   348 			iProgressBar->SetAndDraw( I64INT( iModel->Position().Int64() /
       
   349 									  KVRSecondAsMicroSeconds ) );
       
   350 			iProgressBar->MakeVisible( ETrue );
       
   351 			
       
   352 			iPBposition = I64INT( iModel->Position().Int64() /
       
   353 									  KVRSecondAsMicroSeconds );
       
   354 			}
       
   355 		else
       
   356 			{
       
   357 			iProgressBar->MakeVisible( EFalse );
       
   358 			}
       
   359 		}
       
   360 	}
       
   361 
       
   362 
       
   363 // ----------------------------------------------------------------------------
       
   364 // CVRStateInfoPanel::HandlePointerEventL
       
   365 // From CCoeControl
       
   366 // ----------------------------------------------------------------------------
       
   367 //		
       
   368 void CVRStateInfoPanel::HandlePointerEventL( const TPointerEvent& 
       
   369 													aPointerEvent )
       
   370 	{
       
   371 	if( AknLayoutUtils::PenEnabled() && iModel->HasProgressBar() && 
       
   372 		iProgressBar )
       
   373 		{
       
   374 		CCoeControl::HandlePointerEventL( aPointerEvent );
       
   375 		
       
   376 		switch( aPointerEvent.iType )
       
   377 			{
       
   378 			case TPointerEvent::EButton1Down:
       
   379 				{
       
   380 				TRect progressBarRect( iProgressBar->Rect() );
       
   381 				// Check if pressed position is in progress bar's rect
       
   382 				if( progressBarRect.Contains( aPointerEvent.iPosition ) )
       
   383 					{
       
   384 					HandleProgressBarTouchL( progressBarRect, 
       
   385 											 aPointerEvent.iPosition.iX );
       
   386 					}
       
   387 				break;
       
   388 				}
       
   389 			case TPointerEvent::EDrag:
       
   390 				{
       
   391 				TRect progressBarRect( iProgressBar->Rect() );
       
   392 				if( progressBarRect.Contains( aPointerEvent.iPosition ) )
       
   393 					{
       
   394 					HandleProgressBarTouchL( progressBarRect, 
       
   395 											 aPointerEvent.iPosition.iX );
       
   396 					}
       
   397 				break;		
       
   398 				}
       
   399 			case TPointerEvent::EButton1Up:
       
   400 				{		
       
   401 				break;
       
   402 				}		
       
   403 			default:
       
   404 				{
       
   405 				break;	
       
   406 				}	
       
   407 			}
       
   408 		}
       
   409 	}
       
   410 
       
   411 
       
   412 // ----------------------------------------------------------------------------
       
   413 // CVRStateInfoPanel::HandleProgressBarTouchL
       
   414 // 
       
   415 // ----------------------------------------------------------------------------
       
   416 //	
       
   417 void CVRStateInfoPanel::HandleProgressBarTouchL( TRect aPBRect, 
       
   418 												 TInt aPressedPoint )
       
   419 	{
       
   420 	if ( AknLayoutUtils::PenEnabled() )
       
   421 		{
       
   422 #ifdef _DEBUG
       
   423 		RDebug::Print( _L( "VoiceRecorder: HandleProgressBarTouchL enter" ) );
       
   424 #endif
       
   425 		// Progress Bar start and end points
       
   426 		TInt pbEndPoint( aPBRect.iBr.iX );
       
   427 		TInt pbStartPoint( aPBRect.iTl.iX );
       
   428 		
       
   429 		TInt totalPBLength( pbEndPoint - pbStartPoint );
       
   430 		// calculate what is the time position that was pressed in 
       
   431 		// the progress bar
       
   432 		TTimeIntervalMicroSeconds newPosition( 
       
   433 										( ( aPressedPoint - pbStartPoint ) * 
       
   434 							  			iModel->Duration().Int64() ) / 
       
   435 							  			totalPBLength );
       
   436 							  			
       
   437 		// Round the position to the nearest second value
       
   438 		TInt roundedNewPosition( RoundMicroSecsToSecs( newPosition ) );
       
   439 
       
   440 		// Performace issue. Send command only if value has changed
       
   441 		if ( roundedNewPosition != iPBposition )
       
   442 			{
       
   443 			iPBposition = roundedNewPosition;
       
   444 
       
   445 			CAknViewAppUi* appUi = reinterpret_cast< CAknViewAppUi* >(
       
   446 											CEikonEnv::Static()->EikAppUi() );
       
   447 			CAknView* view = appUi->View( iParentViewUid );
       
   448 			
       
   449 			// inform the view that position has changed.
       
   450 			view->HandleCommandL( ECmdSetNewPosition );	
       
   451 			}	
       
   452 #ifdef _DEBUG
       
   453 		RDebug::Print( _L( "VoiceRecorder: HandleProgressBarTouchL exit" ) );
       
   454 #endif
       
   455 			
       
   456 		} // PenEnabled
       
   457 		
       
   458 	}
       
   459 	
       
   460 
       
   461 // ----------------------------------------------------------------------------
       
   462 // CVRStateInfoPanel::RoundMicroSecsToSecs
       
   463 // Rounds aMicroSecs value to nearest second value (Round)
       
   464 // ----------------------------------------------------------------------------
       
   465 //			
       
   466 TInt CVRStateInfoPanel::RoundMicroSecsToSecs( TTimeIntervalMicroSeconds 
       
   467 											  aMicroSecs )
       
   468 	{	
       
   469 	// Rounds to secondss resolution (Floor)
       
   470 	Int64 secondsInMicroSecs( ( ( aMicroSecs.Int64() / 
       
   471 								  KVRSecondAsMicroSeconds ) * 
       
   472 								  KVRSecondAsMicroSeconds ) );
       
   473 								  
       
   474 	// takes the leftover part in seconds resolution
       
   475 	Int64 leftoversInMicroSecs ( aMicroSecs.Int64() - secondsInMicroSecs );
       
   476 	
       
   477 	// Nearer to upper sec value
       
   478 	if ( leftoversInMicroSecs / ( KVRSecondAsMilliSeconds ) > 
       
   479 		 KVRHalfSecondAsMilliSeconds )
       
   480 		{
       
   481 		// + 1 sec
       
   482 		return ( ( secondsInMicroSecs + KVRSecondAsMicroSeconds ) / 
       
   483 													 KVRSecondAsMicroSeconds );
       
   484 		}
       
   485 	// Nearer to lower sec value	
       
   486 	else
       
   487 		{
       
   488 		return secondsInMicroSecs / KVRSecondAsMicroSeconds;
       
   489 		}	
       
   490 	}
       
   491 	
       
   492 
       
   493 // ----------------------------------------------------------------------------
       
   494 // CVRStateInfoPanel::ProgressBarPosition
       
   495 // Just returns the current progress bar position
       
   496 // ----------------------------------------------------------------------------
       
   497 //		
       
   498 TInt CVRStateInfoPanel::ProgressBarPosition() const
       
   499 	{
       
   500 	return iPBposition;
       
   501 	}
       
   502 	
       
   503 // End of file