photosgallery/slideshow/view/src/shwslideshowvolumecontrol.cpp
changeset 0 4e91876724a2
child 16 0bc0ea26031e
child 18 bcb43dc84c44
equal deleted inserted replaced
-1:000000000000 0:4e91876724a2
       
     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 	// Get the icon file
       
   168 	TFileName mifFile( KDC_APP_BITMAP_DIR );
       
   169     mifFile.Append( KIconsFilename );
       
   170     User::LeaveIfError( CompleteWithAppPath( mifFile ) );
       
   171     // Get the texture manager
       
   172    	CGlxTextureManager& textureMgr = iUtility.GlxTextureManager();
       
   173     // Load the background texture
       
   174     
       
   175     // Below given icon ID is to be changed once the Capped_element Icon
       
   176     // is available in the build
       
   177     CAlfTexture& backgroundTexture = textureMgr.CreateIconTextureL
       
   178         ( EMbmGlxiconsQgn_graf_adapt_search_bg, mifFile );
       
   179     
       
   180     // apply an image brush to the visual
       
   181     iBrush = CAlfImageBrush::NewL(iAlfEnv, TAlfImage( backgroundTexture ) );
       
   182     iBackgroundImageVisual->Brushes()->AppendL( iBrush, EAlfHasOwnership );
       
   183 	iBackgroundImageVisual->SetScaleMode( CAlfImageVisual::EScaleFitInside );
       
   184 	// Muted visual
       
   185 	CAlfTexture& textureMuted = iUtility.GlxTextureManager().CreateIconTextureL
       
   186 	    ( EMbmGlxiconsQgn_indi_mup_speaker_muted, mifFile );										
       
   187 	iMuteImageVisual->SetImage( textureMuted );
       
   188     iMuteImageVisual->SetScaleMode( CAlfImageVisual::EScaleFitInside );
       
   189     
       
   190 	// Speaker visual
       
   191 	CAlfTexture& textureSpkr = iUtility.GlxTextureManager().CreateIconTextureL
       
   192         ( EMbmGlxiconsQgn_indi_mup_speaker, mifFile );
       
   193     iSpeakerImageVisual->SetImage( textureSpkr );
       
   194     iSpeakerImageVisual->SetScaleMode( CAlfImageVisual::EScaleFitInside );	
       
   195 	
       
   196 	//hide the volume level visualation by default
       
   197 	iMainVisual->SetOpacity(KOpacityTransperent);
       
   198 
       
   199 	// Only create the timer if an interval's been specified - 
       
   200 	// default is to not use one.
       
   201 	if ( iInterval.Int() != 0 )
       
   202 		{
       
   203         iTimer = CPeriodic::NewL( CActive::EPriorityStandard );
       
   204 		}
       
   205     }
       
   206 
       
   207 // ---------------------------------------------------------------------------
       
   208 // SetVolume
       
   209 // ---------------------------------------------------------------------------
       
   210 void CShwSlideshowVolumeControl::SetVolume(TInt aVolume, TInt aMaxVolume)
       
   211 	{
       
   212 	TRACER("CShwSlideshowVolumeControl::SetVolume");
       
   213 	// Only allow positive values and
       
   214 	// ensure that aVolume never exceeds aMaxVolume
       
   215 	if ( aMaxVolume >= 0 && aVolume >= 0 && aVolume <= aMaxVolume )
       
   216 		{
       
   217 		iVolume = aVolume;
       
   218 		iMaxVolume = aMaxVolume;
       
   219 		}
       
   220 	}
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // Refresh
       
   224 // ---------------------------------------------------------------------------
       
   225 void CShwSlideshowVolumeControl::RefreshL()
       
   226 	{
       
   227 	TRACER("CShwSlideshowVolumeControl::RefreshL");
       
   228 	if( ShowControlL() )
       
   229 	    {
       
   230 	    if ( iTimer )
       
   231 	        {
       
   232 	        // Restart the timer
       
   233 	        iTimer->Cancel();
       
   234 	        iTimer->Start( iInterval, iInterval,
       
   235 	                TShwCallBack< CShwSlideshowVolumeControl, TimerCallback>
       
   236 	        ( this ) );
       
   237 	        }
       
   238 	    }
       
   239 	}
       
   240 	
       
   241 // ---------------------------------------------------------------------------
       
   242 // Hide
       
   243 // ---------------------------------------------------------------------------
       
   244 void CShwSlideshowVolumeControl::Hide()
       
   245 	{
       
   246 	TRACER("CShwSlideshowVolumeControl::Hide");
       
   247 	// Hide our self
       
   248 	CAlfDisplay* display = iUtility.Display();
       
   249 	CAlfControlGroup* group = ControlGroup();
       
   250 
       
   251 	if ( display && group )
       
   252 		{
       
   253 		CAlfRoster& roster = display->Roster();
       
   254 		roster.Hide( *group );
       
   255 		}	
       
   256 	}
       
   257 // ---------------------------------------------------------------------------
       
   258 // ShowControlL
       
   259 // ---------------------------------------------------------------------------
       
   260 TBool CShwSlideshowVolumeControl::ShowControlL()
       
   261     {
       
   262     TRACER("CShwSlideshowVolumeControl::Refresh");
       
   263     TBool retVal = EFalse;
       
   264     // Hide and show our self
       
   265     CAlfDisplay* display = iUtility.Display();
       
   266     CAlfControlGroup* group = ControlGroup();
       
   267 
       
   268     if ( display && group )
       
   269         {
       
   270         CAlfRoster& roster = display->Roster();
       
   271         roster.Hide( *group );
       
   272         roster.ShowL( *group, KAlfRosterShowAtTop );
       
   273         retVal = ETrue;
       
   274         }  
       
   275     return retVal;  
       
   276     }
       
   277 	
       
   278 // ---------------------------------------------------------------------------
       
   279 // TimerCallback
       
   280 // ---------------------------------------------------------------------------
       
   281 TInt CShwSlideshowVolumeControl::TimerCallback()
       
   282     {
       
   283     TRACER("CShwSlideshowVolumeControl::TimerCallback");
       
   284     GLX_LOG_ENTRY_EXIT( "CShwSlideshowVolumeControl::TimerCallback" );
       
   285     // Timed out so hide ourself
       
   286     Hide();
       
   287     if ( iTimer )
       
   288         {
       
   289         // Cancel the timer
       
   290         iTimer->Cancel();
       
   291         }
       
   292     return 0;
       
   293     }
       
   294 
       
   295 // ---------------------------------------------------------------------------
       
   296 // NotifyControlVisibility
       
   297 // ---------------------------------------------------------------------------
       
   298 void CShwSlideshowVolumeControl::NotifyControlVisibility( TBool aIsVisible,
       
   299     CAlfDisplay& aDisplay )
       
   300 	{	
       
   301 	TRACER("CShwSlideshowVolumeControl::NotifyControlVisibility");
       
   302     GLX_LOG_ENTRY_EXIT
       
   303         ( "CShwSlideshowVolumeControl::NotifyControlVisibility" );
       
   304     GLX_LOG_INFO1
       
   305         ( "CShwSlideshowVolumeControl, is visible = %d", aIsVisible );
       
   306 	if ( !aIsVisible )
       
   307 		{
       
   308 		RemoveLayoutVisuals();
       
   309 		RemoveControlVisuals();
       
   310 		}
       
   311 	else
       
   312 		{
       
   313 		TRAP_IGNORE( SetAndLayoutVisualsL() );
       
   314 		}
       
   315 	}
       
   316 
       
   317 // ---------------------------------------------------------------------------
       
   318 // RemoveLayoutVisuals
       
   319 // ---------------------------------------------------------------------------	
       
   320 void CShwSlideshowVolumeControl::RemoveLayoutVisuals()
       
   321     {
       
   322     TRACER("CShwSlideshowVolumeControl::RemoveLayoutVisuals");
       
   323     GLX_LOG_ENTRY_EXIT( "CShwSlideshowVolumeControl::RemoveLayoutVisuals" );
       
   324 	//not required for now
       
   325     }
       
   326 
       
   327 // ---------------------------------------------------------------------------
       
   328 // RemoveControlVisuals
       
   329 // ---------------------------------------------------------------------------	
       
   330 void CShwSlideshowVolumeControl::RemoveControlVisuals()
       
   331     {
       
   332     TRACER("CShwSlideshowVolumeControl::RemoveControlVisuals");
       
   333     GLX_LOG_ENTRY_EXIT( "CShwSlideshowVolumeControl::RemoveControlVisuals" );
       
   334     // Remove the visuals visibility
       
   335     iMainVisual->SetOpacity(KOpacityTransperent);
       
   336     }
       
   337 	
       
   338 // ---------------------------------------------------------------------------
       
   339 // SetAndLayoutVisualsL
       
   340 // ---------------------------------------------------------------------------	
       
   341 void CShwSlideshowVolumeControl::SetAndLayoutVisualsL()
       
   342     {
       
   343     TRACER("CShwSlideshowVolumeControl::SetAndLayoutVisualsL");
       
   344     GLX_LOG_ENTRY_EXIT( "CShwSlideshowVolumeControl::SetAndLayoutVisualsL" );
       
   345 
       
   346 	iMainVisual->SetFlag(EAlfVisualFlagManualSize);
       
   347     iMainVisual->SetFlag(EAlfVisualFlagManualPosition);
       
   348 	//calculate control size
       
   349 	iControlSize  = iUtility.DisplaySize();
       
   350 	iControlSize.iHeight *= KControlHeightMultiplier;
       
   351 	iControlSize.iWidth *= KControlWidthMultiplier;
       
   352 	//set the control size
       
   353 	iMainVisual->SetSize(iControlSize);
       
   354 	
       
   355 	//calculate the control position
       
   356 	TInt xPos = ( iUtility.DisplaySize().iWidth - iControlSize.iWidth )
       
   357 		    / KShwVolumeControlWidthScaleFactor;
       
   358 	TAlfRealPoint pos( xPos, KShwVolumeControlXOffset );
       
   359 	iMainVisual->SetPos(pos);
       
   360 	
       
   361 	//set the anchors
       
   362 	User::LeaveIfError( iMainVisual->SetRelativeAnchorRect(
       
   363   	0, EAlfAnchorOriginLeft, EAlfAnchorOriginTop, TAlfRealPoint(),
       
   364 	 EAlfAnchorOriginRight, EAlfAnchorOriginBottom, TAlfRealPoint() ) );
       
   365 	//update the child visuals
       
   366 	 iMainVisual->UpdateChildrenLayout();
       
   367 	 iVisualDeck->UpdateChildrenLayout();
       
   368 	 iValueGridVisual->UpdateChildrenLayout();
       
   369 	 
       
   370     // Other visuals' layout depends on the volume
       
   371     TInt volume = CurrentVolumeAsPercentage();
       
   372     
       
   373     if (volume == 0)
       
   374         {
       
   375         // volume = 0% 
       
   376         // show muted icon (no %age value)
       
   377         SetMuteVisualVisibility();
       
   378         }
       
   379     else
       
   380         {
       
   381         // 0 < volume <= 100% 
       
   382         // show speaker and %age
       
   383         SetValueVisualVisibilityL( volume );
       
   384         }
       
   385     }
       
   386 
       
   387 // ---------------------------------------------------------------------------
       
   388 // SetMuteVisualVisibility
       
   389 // ---------------------------------------------------------------------------
       
   390 void CShwSlideshowVolumeControl::SetMuteVisualVisibility()
       
   391     {
       
   392     TRACER("CShwSlideshowVolumeControl::SetMuteVisualVisibilitys");
       
   393     GLX_LOG_ENTRY_EXIT( "CShwSlideshowVolumeControl::SetMuteVisualVisibility" );
       
   394 
       
   395 	// set the mute visual's visibility to 1 and the value visual to 0
       
   396     iValueGridVisual->SetOpacity(KOpacityTransperent);
       
   397     iMuteImageVisual->SetOpacity(KOpacityOpaque);
       
   398     iMainVisual->SetOpacity(KOpacityOpaque);
       
   399     }
       
   400 
       
   401 // ---------------------------------------------------------------------------
       
   402 // SetValueVisualVisibilityL
       
   403 // ---------------------------------------------------------------------------
       
   404 void CShwSlideshowVolumeControl::SetValueVisualVisibilityL(TInt aVolume)
       
   405     {
       
   406     TRACER("CShwSlideshowVolumeControl::SetValueVisualVisibilityL");
       
   407     GLX_LOG_ENTRY_EXIT( "CShwSlideshowVolumeControl::SetValueVisualVisibilityL" );
       
   408    	
       
   409    	// update the percentage visual
       
   410    	iPercentTextVisual->SetStyle( EAlfTextStyleSmall, EAlfBackgroundTypeDark );
       
   411     iPercentTextVisual->SetMaxLineCount( KShwVolumeTextMaxLineCount );
       
   412     iPercentTextVisual->SetWrapping( CAlfTextVisual::ELineWrapTruncate );
       
   413    
       
   414     // Load the localised string
       
   415     HBufC* text = StringLoader::LoadLC( R_SHW_VOLUME_PERCENTAGE, aVolume );
       
   416     TPtr ptr = text->Des();
       
   417     AknTextUtils::LanguageSpecificNumberConversion( ptr );
       
   418 
       
   419     iPercentTextVisual->SetTextL( *text );
       
   420     iPercentTextVisual->SetColor(KRgbBlack);
       
   421     
       
   422     CleanupStack::PopAndDestroy( text );
       
   423 
       
   424     iPercentTextVisual->EnableShadow(EFalse);    
       
   425     iPercentTextVisual->MoveToFront();
       
   426     
       
   427     // set the value grid visual's visibility to 1 and the mute visual to 0
       
   428     iMuteImageVisual->SetOpacity(KOpacityTransperent);
       
   429     iValueGridVisual->SetOpacity(KOpacityOpaque);
       
   430     // Text and speaker icon should come top on background
       
   431     // so making first in layout's visual list.
       
   432     iValueGridVisual->MoveToFront();
       
   433     iMainVisual->SetOpacity(KOpacityOpaque);
       
   434     }
       
   435 
       
   436 // ---------------------------------------------------------------------------
       
   437 // CurrentVolumeAsPercentage()
       
   438 // ---------------------------------------------------------------------------
       
   439 TInt CShwSlideshowVolumeControl::CurrentVolumeAsPercentage()
       
   440 	{
       
   441 	TRACER("CShwSlideshowVolumeControl::CurrentVolumeAsPercentage");
       
   442 	GLX_LOG_ENTRY_EXIT("CShwSlideshowVolumeControl::CurrentVolumeAsPercentage");
       
   443 	TInt retVal = iVolume;
       
   444 
       
   445 	// guard against any undefined numbers
       
   446 	if ( iVolume > 0 && iMaxVolume > 0 )
       
   447 		{
       
   448 		TReal numerator( iVolume );
       
   449 		TReal denominator( iMaxVolume );
       
   450 		TReal working = ( numerator / denominator ) * KShwVolumeMaxPercent;
       
   451 		retVal = TInt( working );
       
   452 		}
       
   453 	else if ( iVolume == iMaxVolume )
       
   454 		{
       
   455 		retVal = KShwVolumeMaxPercent;
       
   456 		}
       
   457 	return retVal;
       
   458 	}
       
   459 // End of File
       
   460 
       
   461