photosgallery/slideshow/view/src/shwslideshowvolumecontrol.cpp
branchRCL_3
changeset 60 5b3385a43d68
child 75 01504893d9cb
equal deleted inserted replaced
59:8e5f6eea9c9f 60:5b3385a43d68
       
     1 /*
       
     2 * Copyright (c) 2007 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:    Volume control implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "shwslideshowvolumecontrol.h"
       
    23 
       
    24 #include <alf/alfdisplay.h>
       
    25 #include <alf/alftexture.h>
       
    26 #include <alf/alfimage.h>
       
    27 #include <alf/alfimagevisual.h>
       
    28 #include <alf/alftextvisual.h>
       
    29 
       
    30 #include <alf/alfgridlayout.h>
       
    31 #include <alf/alfdecklayout.h>
       
    32 #include <alf/alfanchorlayout.h>
       
    33 #include <alf/alfanchorlayout.h>
       
    34 #include <alf/alfimagebrush.h>
       
    35 #include <alf/alfroster.h>
       
    36 #include <alf/alfbrusharray.h>
       
    37 
       
    38 #include <data_caging_path_literals.hrh>
       
    39 #include <AknsUtils.h>          // skins
       
    40 #include <glxicons.mbg>
       
    41 #include <avkon.mbg>
       
    42 #include <glxresourceutilities.h>   // for CGlxResourceUtilities
       
    43 
       
    44 #include <AknUtils.h>
       
    45 #include <StringLoader.h>
       
    46 
       
    47 #include <glxlog.h>
       
    48 #include <glxtracer.h>
       
    49 #include <shwslideshowview.rsg>
       
    50 
       
    51 #include "glxuiutility.h"
       
    52 #include "glxtexturemanager.h"
       
    53 #include "shwcallback.h"
       
    54 
       
    55 // CONSTANTS
       
    56 namespace
       
    57     {
       
    58     const TInt KShwVolumeControlXOffset = 0;
       
    59     _LIT( KIconsFilename, "glxicons.mif" );
       
    60     const TInt KShwVolumeControlWidthScaleFactor = 2;
       
    61     const TInt KShwVolumeMaxPercent = 100;
       
    62     const TInt KShwVolumeTextMaxLineCount = 1;   
       
    63     const TReal KControlWidthMultiplier = 0.2;
       
    64     const TReal KControlHeightMultiplier = 0.12;
       
    65     const TReal KOpacityOpaque = 1.0;
       
    66     const TReal KHalfOpacityOpaque = 0.4;
       
    67     const TReal KOpacityTransperent = 0.0;
       
    68     const TInt KValueGridCols = 2;
       
    69     const TInt KValueGridRows = 1;
       
    70     }
       
    71     
       
    72 //! NOTE : This implementation does not go with the current Slide Show UI Spec 1.1
       
    73 // UI specs need to be updated and a fine print needs to pe prepared about the 
       
    74 // LAF of this control
       
    75 // In that case the visual positioning can be adjusted by paddin and giving weights
       
    76 
       
    77 // ======== MEMBER FUNCTIONS ========
       
    78 // ---------------------------------------------------------------------------
       
    79 // CShwSlideshowVolumeControl()
       
    80 // ---------------------------------------------------------------------------
       
    81 inline CShwSlideshowVolumeControl::CShwSlideshowVolumeControl( CAlfEnv& aEnv,
       
    82 		CGlxUiUtility& aUtility, TTimeIntervalMicroSeconds32 aInterval)
       
    83 		: iUtility(aUtility), iInterval(aInterval),iAlfEnv(aEnv)
       
    84 	{
       
    85 	}
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // ~CShwSlideshowVolumeControl
       
    89 // ---------------------------------------------------------------------------
       
    90 CShwSlideshowVolumeControl::~CShwSlideshowVolumeControl()
       
    91 	{
       
    92 	TRACER("CShwSlideshowVolumeControl::~CShwSlideshowVolumeControl");
       
    93 	GLX_LOG_INFO("CShwSlideshowVolumeControl::~CShwSlideshowVolumeControl" );
       
    94 	// visuals
       
    95 	if (iMainVisual)
       
    96         {
       
    97         iMainVisual->RemoveAndDestroyAllD();
       
    98         iMainVisual = NULL;
       
    99         }
       
   100 	// timer
       
   101 	if ( iTimer )
       
   102 	    {
       
   103 	    iTimer->Cancel();
       
   104 	    }
       
   105 	delete iTimer;
       
   106 	}
       
   107 	
       
   108 // ---------------------------------------------------------------------------
       
   109 // NewL
       
   110 // ---------------------------------------------------------------------------	
       
   111 CShwSlideshowVolumeControl* CShwSlideshowVolumeControl::NewL(
       
   112 	CAlfEnv& aEnv,
       
   113 	CGlxUiUtility& aUtility,
       
   114     TTimeIntervalMicroSeconds32 aInterval)
       
   115 	{
       
   116 	TRACER("CShwSlideshowVolumeControl::NewL");
       
   117 	GLX_LOG_INFO("CShwSlideshowVolumeControl::NewL" );
       
   118 	CShwSlideshowVolumeControl* self = new( ELeave ) 
       
   119 	    CShwSlideshowVolumeControl( aEnv, aUtility, aInterval );
       
   120 	CleanupStack::PushL( self );
       
   121 	self->ConstructL();
       
   122 	CleanupStack::Pop( self );
       
   123 	return self;
       
   124 	}
       
   125 	
       
   126 // ---------------------------------------------------------------------------
       
   127 // ConstructL
       
   128 // ---------------------------------------------------------------------------
       
   129 void CShwSlideshowVolumeControl::ConstructL()
       
   130     {
       
   131     TRACER("CShwSlideshowVolumeControl::ConstructL");
       
   132     GLX_LOG_INFO("CShwSlideshowVolumeControl::ConstructL" );
       
   133 	// Construct the base class.
       
   134 	CAlfControl::ConstructL(iAlfEnv);
       
   135 	
       
   136 	//----------------------- LAYOUT HIERARCHY -------------------------------
       
   137 	//
       
   138 	//						 	 ->iBackgroundImageVisual
       
   139 	//							|
       
   140 	//							|					  ->iSpeakerImageVisual
       
   141 	//							|					 |
       
   142 	// iMainVisual-->iVisualDeck ->iValueGridVisual->
       
   143 	//							|					 |
       
   144 	//							|					  ->iPercentTextVisual
       
   145 	//							|
       
   146 	//							 ->iMuteImageVisual
       
   147 	//
       
   148 	//-------------------------------------------------------------------------
       
   149 	
       
   150     iMainVisual = CAlfAnchorLayout::AddNewL(*this);
       
   151     
       
   152     iVisualDeck = CAlfDeckLayout::AddNewL(*this,iMainVisual);
       
   153     
       
   154     iValueGridVisual = CAlfGridLayout::AddNewL(*this,KValueGridCols,
       
   155     										KValueGridRows,iVisualDeck);
       
   156     
       
   157     // The visual elements of the control
       
   158     iBackgroundImageVisual = CAlfImageVisual::AddNewL(*this,iVisualDeck);
       
   159     iMuteImageVisual = CAlfImageVisual::AddNewL(*this,iVisualDeck);
       
   160     iSpeakerImageVisual = CAlfImageVisual::AddNewL(*this,iValueGridVisual);
       
   161     iPercentTextVisual = CAlfTextVisual::AddNewL(*this,iValueGridVisual);
       
   162     
       
   163     // BackGround Visual
       
   164     iBackgroundImageVisual->EnableBrushesL();
       
   165     iBackgroundImageVisual->SetOpacity( KHalfOpacityOpaque );
       
   166 	
       
   167 	//hide the volume level visualation by default
       
   168 	iMainVisual->SetOpacity(KOpacityTransperent);
       
   169 
       
   170 	// Only create the timer if an interval's been specified - 
       
   171 	// default is to not use one.
       
   172 	if ( iInterval.Int() != 0 )
       
   173 		{
       
   174         iTimer = CPeriodic::NewL( CActive::EPriorityStandard );
       
   175 		}
       
   176     }
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // SetVolume
       
   180 // ---------------------------------------------------------------------------
       
   181 void CShwSlideshowVolumeControl::SetVolume(TInt aVolume, TInt aMaxVolume)
       
   182 	{
       
   183 	TRACER("CShwSlideshowVolumeControl::SetVolume");
       
   184 	// Only allow positive values and
       
   185 	// ensure that aVolume never exceeds aMaxVolume
       
   186 	if ( aMaxVolume >= 0 && aVolume >= 0 && aVolume <= aMaxVolume )
       
   187 		{
       
   188 		iVolume = aVolume;
       
   189 		iMaxVolume = aMaxVolume;
       
   190 		}
       
   191 	}
       
   192 
       
   193 // ---------------------------------------------------------------------------
       
   194 // Refresh
       
   195 // ---------------------------------------------------------------------------
       
   196 void CShwSlideshowVolumeControl::RefreshL()
       
   197 	{
       
   198 	TRACER("CShwSlideshowVolumeControl::RefreshL");
       
   199 	if( ShowControlL() )
       
   200 	    {
       
   201 	    if ( iTimer )
       
   202 	        {
       
   203 	        // Restart the timer
       
   204 	        iTimer->Cancel();
       
   205 	        iTimer->Start(iInterval, iInterval, TShwCallBack< 
       
   206 	                CShwSlideshowVolumeControl, 
       
   207 	                &CShwSlideshowVolumeControl::TimerCallback> (this));
       
   208 	        }
       
   209 	    }
       
   210 	}
       
   211 	
       
   212 // ---------------------------------------------------------------------------
       
   213 // Hide
       
   214 // ---------------------------------------------------------------------------
       
   215 void CShwSlideshowVolumeControl::Hide()
       
   216 	{
       
   217 	TRACER("CShwSlideshowVolumeControl::Hide");
       
   218 	// Hide our self
       
   219 	CAlfDisplay* display = iUtility.Display();
       
   220 	CAlfControlGroup* group = ControlGroup();
       
   221 
       
   222 	if ( display && group )
       
   223 		{
       
   224 		CAlfRoster& roster = display->Roster();
       
   225 		roster.Hide( *group );
       
   226 		}	
       
   227 	}
       
   228 
       
   229 // ---------------------------------------------------------------------------
       
   230 // InitControlTextureL
       
   231 // ---------------------------------------------------------------------------
       
   232 void CShwSlideshowVolumeControl::InitControlTextureL()
       
   233     {
       
   234     TRACER("CShwSlideshowVolumeControl::InitControlTextureL");
       
   235     // Get the icon file
       
   236     TFileName mifFile( KDC_APP_BITMAP_DIR );
       
   237     mifFile.Append( KIconsFilename );
       
   238     User::LeaveIfError( CompleteWithAppPath( mifFile ) );
       
   239     // Get the texture manager
       
   240     CGlxTextureManager& textureMgr = iUtility.GlxTextureManager();
       
   241     // Load the background texture
       
   242     
       
   243     // Below given icon ID is to be changed once the Capped_element Icon
       
   244     // is available in the build
       
   245     CAlfTexture& backgroundTexture = textureMgr.CreateIconTextureL
       
   246         ( EMbmGlxiconsQgn_graf_adapt_search_bg, mifFile );
       
   247     
       
   248     // apply an image brush to the visual
       
   249     iBrush = CAlfImageBrush::NewL(iAlfEnv, TAlfImage( backgroundTexture ) );
       
   250     iBackgroundImageVisual->Brushes()->AppendL( iBrush, EAlfHasOwnership );
       
   251     iBackgroundImageVisual->SetScaleMode( CAlfImageVisual::EScaleFitInside );
       
   252     // Muted visual
       
   253     CAlfTexture& textureMuted = iUtility.GlxTextureManager().CreateIconTextureL
       
   254         ( EMbmGlxiconsQgn_indi_mup_speaker_muted, mifFile );                                        
       
   255     iMuteImageVisual->SetImage( textureMuted );
       
   256     iMuteImageVisual->SetScaleMode( CAlfImageVisual::EScaleFitInside );
       
   257     
       
   258     // Speaker visual
       
   259     CAlfTexture& textureSpkr = iUtility.GlxTextureManager().CreateIconTextureL
       
   260         ( EMbmGlxiconsQgn_indi_mup_speaker, mifFile );
       
   261     iSpeakerImageVisual->SetImage( textureSpkr );
       
   262     iSpeakerImageVisual->SetScaleMode( CAlfImageVisual::EScaleFitInside );      
       
   263     }
       
   264 
       
   265 // ---------------------------------------------------------------------------
       
   266 // ShowControlL
       
   267 // ---------------------------------------------------------------------------
       
   268 TBool CShwSlideshowVolumeControl::ShowControlL()
       
   269     {
       
   270     TRACER("CShwSlideshowVolumeControl::Refresh");
       
   271     TBool retVal = EFalse;
       
   272     // Hide and show our self
       
   273     CAlfDisplay* display = iUtility.Display();
       
   274     CAlfControlGroup* group = ControlGroup();
       
   275 
       
   276     if ( display && group )
       
   277         {
       
   278         CAlfRoster& roster = display->Roster();
       
   279         roster.Hide( *group );
       
   280         roster.ShowL( *group, KAlfRosterShowAtTop );
       
   281         retVal = ETrue;
       
   282         }  
       
   283     return retVal;  
       
   284     }
       
   285 	
       
   286 // ---------------------------------------------------------------------------
       
   287 // TimerCallback
       
   288 // ---------------------------------------------------------------------------
       
   289 TInt CShwSlideshowVolumeControl::TimerCallback()
       
   290     {
       
   291     TRACER("CShwSlideshowVolumeControl::TimerCallback");
       
   292     GLX_LOG_ENTRY_EXIT( "CShwSlideshowVolumeControl::TimerCallback" );
       
   293     // Timed out so hide ourself
       
   294     Hide();
       
   295     if ( iTimer )
       
   296         {
       
   297         // Cancel the timer
       
   298         iTimer->Cancel();
       
   299         }
       
   300     return 0;
       
   301     }
       
   302 
       
   303 // ---------------------------------------------------------------------------
       
   304 // NotifyControlVisibility
       
   305 // ---------------------------------------------------------------------------
       
   306 void CShwSlideshowVolumeControl::NotifyControlVisibility( TBool aIsVisible,
       
   307     CAlfDisplay& /*aDisplay*/ )
       
   308 	{	
       
   309 	TRACER("CShwSlideshowVolumeControl::NotifyControlVisibility");
       
   310     GLX_LOG_ENTRY_EXIT
       
   311         ( "CShwSlideshowVolumeControl::NotifyControlVisibility" );
       
   312     GLX_LOG_INFO1
       
   313         ( "CShwSlideshowVolumeControl, is visible = %d", aIsVisible );
       
   314 	if ( !aIsVisible )
       
   315 		{
       
   316 		RemoveLayoutVisuals();
       
   317 		RemoveControlVisuals();
       
   318 		}
       
   319 	else
       
   320 		{
       
   321 		TRAP_IGNORE( SetAndLayoutVisualsL() );
       
   322 		}
       
   323 	}
       
   324 
       
   325 // ---------------------------------------------------------------------------
       
   326 // RemoveLayoutVisuals
       
   327 // ---------------------------------------------------------------------------	
       
   328 void CShwSlideshowVolumeControl::RemoveLayoutVisuals()
       
   329     {
       
   330     TRACER("CShwSlideshowVolumeControl::RemoveLayoutVisuals");
       
   331     GLX_LOG_ENTRY_EXIT( "CShwSlideshowVolumeControl::RemoveLayoutVisuals" );
       
   332 	//not required for now
       
   333     }
       
   334 
       
   335 // ---------------------------------------------------------------------------
       
   336 // RemoveControlVisuals
       
   337 // ---------------------------------------------------------------------------	
       
   338 void CShwSlideshowVolumeControl::RemoveControlVisuals()
       
   339     {
       
   340     TRACER("CShwSlideshowVolumeControl::RemoveControlVisuals");
       
   341     GLX_LOG_ENTRY_EXIT( "CShwSlideshowVolumeControl::RemoveControlVisuals" );
       
   342     // Remove the visuals visibility
       
   343     iMainVisual->SetOpacity(KOpacityTransperent);
       
   344     }
       
   345 	
       
   346 // ---------------------------------------------------------------------------
       
   347 // SetAndLayoutVisualsL
       
   348 // ---------------------------------------------------------------------------	
       
   349 void CShwSlideshowVolumeControl::SetAndLayoutVisualsL()
       
   350     {
       
   351     TRACER("CShwSlideshowVolumeControl::SetAndLayoutVisualsL");
       
   352     GLX_LOG_ENTRY_EXIT( "CShwSlideshowVolumeControl::SetAndLayoutVisualsL" );
       
   353 
       
   354 	iMainVisual->SetFlag(EAlfVisualFlagManualSize);
       
   355     iMainVisual->SetFlag(EAlfVisualFlagManualPosition);
       
   356 	//calculate control size
       
   357 	iControlSize  = iUtility.DisplaySize();
       
   358 	iControlSize.iHeight *= KControlHeightMultiplier;
       
   359 	iControlSize.iWidth *= KControlWidthMultiplier;
       
   360 	//set the control size
       
   361 	iMainVisual->SetSize(iControlSize);
       
   362 	
       
   363 	//calculate the control position
       
   364 	TInt xPos = ( iUtility.DisplaySize().iWidth - iControlSize.iWidth )
       
   365 		    / KShwVolumeControlWidthScaleFactor;
       
   366 	TAlfRealPoint pos( xPos, KShwVolumeControlXOffset );
       
   367 	iMainVisual->SetPos(pos);
       
   368 	
       
   369 	//set the anchors
       
   370 	User::LeaveIfError( iMainVisual->SetRelativeAnchorRect(
       
   371   	0, EAlfAnchorOriginLeft, EAlfAnchorOriginTop, TAlfRealPoint(),
       
   372 	 EAlfAnchorOriginRight, EAlfAnchorOriginBottom, TAlfRealPoint() ) );
       
   373 	//update the child visuals
       
   374 	 iMainVisual->UpdateChildrenLayout();
       
   375 	 iVisualDeck->UpdateChildrenLayout();
       
   376 	 iValueGridVisual->UpdateChildrenLayout();
       
   377 	 
       
   378     // Other visuals' layout depends on the volume
       
   379     TInt volume = CurrentVolumeAsPercentage();
       
   380     
       
   381     if (volume == 0)
       
   382         {
       
   383         // volume = 0% 
       
   384         // show muted icon (no %age value)
       
   385         SetMuteVisualVisibility();
       
   386         }
       
   387     else
       
   388         {
       
   389         // 0 < volume <= 100% 
       
   390         // show speaker and %age
       
   391         SetValueVisualVisibilityL( volume );
       
   392         }
       
   393     }
       
   394 
       
   395 // ---------------------------------------------------------------------------
       
   396 // SetMuteVisualVisibility
       
   397 // ---------------------------------------------------------------------------
       
   398 void CShwSlideshowVolumeControl::SetMuteVisualVisibility()
       
   399     {
       
   400     TRACER("CShwSlideshowVolumeControl::SetMuteVisualVisibilitys");
       
   401     GLX_LOG_ENTRY_EXIT( "CShwSlideshowVolumeControl::SetMuteVisualVisibility" );
       
   402 
       
   403 	// set the mute visual's visibility to 1 and the value visual to 0
       
   404     iValueGridVisual->SetOpacity(KOpacityTransperent);
       
   405     iMuteImageVisual->SetOpacity(KOpacityOpaque);
       
   406     iMainVisual->SetOpacity(KOpacityOpaque);
       
   407     }
       
   408 
       
   409 // ---------------------------------------------------------------------------
       
   410 // SetValueVisualVisibilityL
       
   411 // ---------------------------------------------------------------------------
       
   412 void CShwSlideshowVolumeControl::SetValueVisualVisibilityL(TInt aVolume)
       
   413     {
       
   414     TRACER("CShwSlideshowVolumeControl::SetValueVisualVisibilityL");
       
   415     GLX_LOG_ENTRY_EXIT( "CShwSlideshowVolumeControl::SetValueVisualVisibilityL" );
       
   416    	
       
   417    	// update the percentage visual
       
   418    	iPercentTextVisual->SetStyle( EAlfTextStyleSmall, EAlfBackgroundTypeDark );
       
   419     iPercentTextVisual->SetMaxLineCount( KShwVolumeTextMaxLineCount );
       
   420     iPercentTextVisual->SetWrapping( CAlfTextVisual::ELineWrapTruncate );
       
   421    
       
   422     // Load the localised string
       
   423     HBufC* text = StringLoader::LoadLC( R_SHW_VOLUME_PERCENTAGE, aVolume );
       
   424     TPtr ptr = text->Des();
       
   425     AknTextUtils::LanguageSpecificNumberConversion( ptr );
       
   426 
       
   427     iPercentTextVisual->SetTextL( *text );
       
   428     iPercentTextVisual->SetColor(KRgbBlack);
       
   429     
       
   430     CleanupStack::PopAndDestroy( text );
       
   431 
       
   432     iPercentTextVisual->EnableShadow(EFalse);    
       
   433     iPercentTextVisual->MoveToFront();
       
   434     
       
   435     // set the value grid visual's visibility to 1 and the mute visual to 0
       
   436     iMuteImageVisual->SetOpacity(KOpacityTransperent);
       
   437     iValueGridVisual->SetOpacity(KOpacityOpaque);
       
   438     // Text and speaker icon should come top on background
       
   439     // so making first in layout's visual list.
       
   440     iValueGridVisual->MoveToFront();
       
   441     iMainVisual->SetOpacity(KOpacityOpaque);
       
   442     }
       
   443 
       
   444 // ---------------------------------------------------------------------------
       
   445 // CurrentVolumeAsPercentage()
       
   446 // ---------------------------------------------------------------------------
       
   447 TInt CShwSlideshowVolumeControl::CurrentVolumeAsPercentage()
       
   448 	{
       
   449 	TRACER("CShwSlideshowVolumeControl::CurrentVolumeAsPercentage");
       
   450 	GLX_LOG_ENTRY_EXIT("CShwSlideshowVolumeControl::CurrentVolumeAsPercentage");
       
   451 	TInt retVal = iVolume;
       
   452 
       
   453 	// guard against any undefined numbers
       
   454 	if ( iVolume > 0 && iMaxVolume > 0 )
       
   455 		{
       
   456 		TReal numerator( iVolume );
       
   457 		TReal denominator( iMaxVolume );
       
   458 		TReal working = ( numerator / denominator ) * KShwVolumeMaxPercent;
       
   459 		retVal = TInt( working );
       
   460 		}
       
   461 	else if ( iVolume == iMaxVolume )
       
   462 		{
       
   463 		retVal = KShwVolumeMaxPercent;
       
   464 		}
       
   465 	return retVal;
       
   466 	}
       
   467 // End of File
       
   468 
       
   469