camerauis/cameraapp/generic/src/CamUserSceneSetupContainer.cpp
changeset 19 d9aefe59d544
parent 3 8b2d6d0384b0
child 21 fa6d9f75d6a6
child 28 3075d9b614e6
equal deleted inserted replaced
3:8b2d6d0384b0 19:d9aefe59d544
     1 /*
       
     2 * Copyright (c) 2007-2010 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:  Implements container for the user scene setup list.*
       
    15 */
       
    16 
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "CamUserSceneSetupContainer.h"
       
    20 #include "CamUserSceneSetupItemArray.h"
       
    21 #include "CamAppController.h"
       
    22 #include "CamSettings.hrh"
       
    23 #include "Cam.hrh"
       
    24 #include "CamPanic.h"
       
    25 #include <aknlists.h>
       
    26 #include <AknIconArray.h>
       
    27 #include <barsread.h>
       
    28 #include <aknview.h>
       
    29 
       
    30 #include "CamUtility.h"
       
    31 
       
    32 
       
    33 // ================= MEMBER FUNCTIONS =======================
       
    34 
       
    35 // ---------------------------------------------------------
       
    36 // CCamUserSceneSetupContainer::NewLC
       
    37 // Symbian two-phased constructor.
       
    38 // ---------------------------------------------------------
       
    39 //
       
    40 CCamUserSceneSetupContainer* CCamUserSceneSetupContainer::NewLC
       
    41 ( const TRect& aRect, TInt aResourceId, 
       
    42     CCamAppController& aController, 
       
    43     CAknView& aView )
       
    44     {
       
    45     CCamUserSceneSetupContainer* self =
       
    46         new ( ELeave ) CCamUserSceneSetupContainer( aController, 
       
    47         aView );
       
    48     CleanupStack::PushL( self );
       
    49     self->ConstructL( aRect, aResourceId );
       
    50     return self;
       
    51     }
       
    52 
       
    53 // ---------------------------------------------------------
       
    54 // CCamUserSceneSetupContainer::NewL
       
    55 // Symbian two-phased constructor.
       
    56 // ---------------------------------------------------------
       
    57 //
       
    58 CCamUserSceneSetupContainer* CCamUserSceneSetupContainer::NewL
       
    59 ( const TRect& aRect, TInt aResourceId, 
       
    60     CCamAppController& aController, 
       
    61     CAknView& aView )
       
    62     {
       
    63     CCamUserSceneSetupContainer* self = 
       
    64         CCamUserSceneSetupContainer::NewLC
       
    65         ( aRect, aResourceId, aController, 
       
    66        aView );
       
    67     CleanupStack::Pop( self );
       
    68     return self;
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------
       
    72 // CCamUserSceneSetupContainer::~CCamUserSceneSetupContainer
       
    73 // Destructor
       
    74 // ---------------------------------------------------------
       
    75 //
       
    76 CCamUserSceneSetupContainer::~CCamUserSceneSetupContainer()
       
    77   {
       
    78   PRINT( _L("Camera => ~CCamUserSceneSetupContainer" ))  
       
    79   delete iUserSceneSetupList;
       
    80   delete iUserSceneSetupItemArray;
       
    81   PRINT( _L("Camera <= ~CCamUserSceneSetupContainer" ))  
       
    82   }
       
    83 
       
    84 // ---------------------------------------------------------
       
    85 // CCamUserSceneSetupContainer::HandleChangeInItemArrayOrVisibilityL
       
    86 // Handles a change in the item list visibility.
       
    87 // ---------------------------------------------------------
       
    88 //
       
    89 void CCamUserSceneSetupContainer::UpdateDisplayL()
       
    90     {
       
    91     ListBox()->DrawNow();
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------
       
    95 // CCamUserSceneSetupContainer::TitlePaneTextResourceId
       
    96 // Returns the resource Id of the title for this container.
       
    97 // ---------------------------------------------------------
       
    98 //
       
    99 TInt CCamUserSceneSetupContainer::TitlePaneTextResourceId()
       
   100     {
       
   101     return iTitleResourceId;
       
   102     }
       
   103 
       
   104 // ---------------------------------------------------------
       
   105 // CCamUserSceneSetupContainer::UpdateListItems
       
   106 // Updates the list items with the settings model values.
       
   107 // ---------------------------------------------------------
       
   108 //
       
   109 void CCamUserSceneSetupContainer::UpdateListItems( void )
       
   110     {
       
   111     TInt listItemCount = iUserSceneSetupItemArray->Count();
       
   112     TInt i;
       
   113     for ( i = 0; i < listItemCount; ++i )
       
   114         {
       
   115         UpdateListItem( i );
       
   116         }
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------
       
   120 // CCamUserSceneSetupContainer::UpdateCurrentListItem
       
   121 // Updates the current list item with it's associated
       
   122 // settings model value.
       
   123 // ---------------------------------------------------------
       
   124 //
       
   125 void CCamUserSceneSetupContainer::UpdateCurrentListItem()
       
   126     {
       
   127     CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current();   
       
   128     if ( cba )
       
   129         {
       
   130         CEikCba* eikCba = static_cast<CEikCba*>( cba->ButtonGroup() );
       
   131         if( eikCba )
       
   132             {
       
   133             // Hide LSK for single clickable settings
       
   134             eikCba->EnableItemSpecificSoftkey( ETrue );
       
   135             }
       
   136         }  
       
   137     TInt selectedItemIndex = iUserSceneSetupList->CurrentItemIndex();
       
   138     UpdateListItem( selectedItemIndex );
       
   139     }
       
   140     
       
   141 // ---------------------------------------------------------
       
   142 // CCamUserSceneSetupContainer::HandleListBoxEventL
       
   143 // Handles a list box event.
       
   144 // ---------------------------------------------------------
       
   145 //
       
   146 void CCamUserSceneSetupContainer::HandleListBoxEventL
       
   147 ( CEikListBox* /*aListBox*/, TListBoxEvent aEventType )
       
   148 	{
       
   149 	switch( aEventType )
       
   150 		{
       
   151 		case EEventEnterKeyPressed: // fallthrough
       
   152 		case EEventItemDoubleClicked: 
       
   153         case EEventItemSingleClicked:
       
   154 			{
       
   155             HandleSelectionL();
       
   156             }
       
   157 			break;
       
   158 
       
   159 		default:
       
   160 			break;			
       
   161 		}
       
   162 	}
       
   163 
       
   164 // ---------------------------------------------------------
       
   165 // CCamUserSceneSetupContainer::HandleSelectionL
       
   166 // Handles the user selection of a list item.
       
   167 // ---------------------------------------------------------
       
   168 //
       
   169 void CCamUserSceneSetupContainer::HandleSelectionL( void )
       
   170     {
       
   171     TInt CommandId = CommandIdForActivatingCurrentItemControl();
       
   172     CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current();
       
   173     if ( cba && CommandId != ECamCmdCaptureSetupFlashUser )
       
   174         {
       
   175         CEikCba* eikCba = static_cast<CEikCba*>( cba->ButtonGroup() );
       
   176         if( eikCba )
       
   177             {
       
   178             // Make LSK visible for the sliders.
       
   179             // Sliders, like exposure compensation, are not listboxes, 
       
   180             // thus single click cannot be disabled for those.
       
   181             // All setting items, except flash, are double clickable and
       
   182             // they have a visible LSK
       
   183             eikCba->EnableItemSpecificSoftkey( EFalse );
       
   184             }    
       
   185         }
       
   186     iView.HandleCommandL( CommandId );
       
   187     }
       
   188     
       
   189 
       
   190 
       
   191 // ---------------------------------------------------------
       
   192 // CCamUserSceneSetupContainer::CCamUserSceneSetupContainer
       
   193 // C++ constructor
       
   194 // ---------------------------------------------------------
       
   195 //
       
   196 CCamUserSceneSetupContainer::CCamUserSceneSetupContainer
       
   197 ( CCamAppController& aController, 
       
   198     CAknView& aView )
       
   199 : CCamContainerBase( aController, aView )
       
   200     {
       
   201 
       
   202     }
       
   203 
       
   204 // ---------------------------------------------------------
       
   205 // CCamUserSceneSetupContainer::ConstructL
       
   206 // 2nd phase constructor
       
   207 // ---------------------------------------------------------
       
   208 //
       
   209 void CCamUserSceneSetupContainer::ConstructL
       
   210 ( const TRect& aRect, TInt aResourceId )
       
   211     {
       
   212     const TInt KSettingItemArrayGranularity = 5;
       
   213 
       
   214     CreateWindowL();
       
   215 
       
   216     // Create the listbox in the right style
       
   217     iUserSceneSetupList = new ( ELeave ) CAknSettingStyleListBox;
       
   218     iUserSceneSetupList->ConstructL( this, CEikListBox::ELeftDownInViewRect );
       
   219 
       
   220     TPoint pos = iEikonEnv->EikAppUi()->ClientRect().iTl;
       
   221     TSize size = iUserSceneSetupList->MinimumSize();
       
   222     SetExtent( pos, size ); 
       
   223 
       
   224 
       
   225     // Setup the scroll bar
       
   226     iUserSceneSetupList->CreateScrollBarFrameL( ETrue );
       
   227     iUserSceneSetupList->ScrollBarFrame()->
       
   228     SetScrollBarVisibilityL( CEikScrollBarFrame::EOn, 
       
   229             CEikScrollBarFrame::EAuto );
       
   230             
       
   231     iTitleResourceId = aResourceId;
       
   232 
       
   233             
       
   234     // get array of supported resources from psi
       
   235     RArray<TInt> userSceneResourceIds;
       
   236     CleanupClosePushL( userSceneResourceIds );
       
   237     
       
   238     User::LeaveIfError( CamUtility::GetPsiIntArrayL( ECamPsiUserSceneResourceIds, userSceneResourceIds ) );
       
   239 
       
   240     // ...get the number of items in this user scene setup list.
       
   241     TInt itemCount = userSceneResourceIds.Count(); 
       
   242 	iUserSceneSetupItemArray = new ( ELeave ) 
       
   243         CCamUserSceneSetupItemArray( itemCount );
       
   244     iUserSceneSetupItemArray->ConstructL();
       
   245 	
       
   246 	// Make the icon array
       
   247 	CArrayPtrFlat<CGulIcon>* iconArray = new ( ELeave )
       
   248         CAknIconArray( KSettingItemArrayGranularity );
       
   249 	CleanupStack::PushL( iconArray );
       
   250 
       
   251     // Create all the user scene setup list items defined in the resource.
       
   252 	TInt i;
       
   253 	for ( i=0; i < itemCount; ++i )
       
   254 		{
       
   255         CCamUserSceneSetupListItem* listItem = 
       
   256             CCamUserSceneSetupListItem::NewL( userSceneResourceIds[i] );
       
   257         CleanupStack::PushL( listItem );
       
   258         // Ownership is transferred
       
   259         iUserSceneSetupItemArray->AppendL( listItem ); 
       
   260         CleanupStack::Pop( listItem );
       
   261 		}
       
   262 		
       
   263 	
       
   264 	// Update the display
       
   265 	UpdateDisplayL();
       
   266 
       
   267 	// Looks like we have no choice but to give ownership 
       
   268     // of this to the listbox.
       
   269 	// There is no flag as there is for the item data
       
   270 	ListBox()->ItemDrawer()->FormattedCellData()->SetIconArrayL( iconArray ); 
       
   271 
       
   272     // iconArray now has ownership transferred
       
   273 	CleanupStack::Pop( iconArray );  
       
   274     
       
   275     CleanupStack::PopAndDestroy( &userSceneResourceIds );	
       
   276 
       
   277 	CTextListBoxModel* model= iUserSceneSetupList->Model();
       
   278 	model->SetItemTextArray( iUserSceneSetupItemArray );
       
   279     // Ownership retained by SettingItemList
       
   280 	model->SetOwnershipType( ELbmDoesNotOwnItemArray ); 
       
   281 
       
   282    	TAknLayoutRect layoutRect;
       
   283 	layoutRect.LayoutRect( TRect( 
       
   284         TPoint( 0, 0 ), iAvkonAppUi->ClientRect().Size() ), 
       
   285         AKN_LAYOUT_WINDOW_list_gen_pane( 0 ) );
       
   286 	iUserSceneSetupList->SetRect( layoutRect.Rect() );
       
   287 
       
   288 	ListBox()->SetCurrentItemIndex( 0 );
       
   289 	ListBox()->SetListBoxObserver( this );
       
   290 	ListBox()->UpdateScrollBarsL();
       
   291 
       
   292     SetRect( aRect );
       
   293     ActivateL();
       
   294 
       
   295     UpdateListItems();
       
   296     }
       
   297 
       
   298 
       
   299 
       
   300 // ---------------------------------------------------------
       
   301 // CCamUserSceneSetupContainer::UpdateListItem
       
   302 // Updates a list item with its corresponding settings model value.
       
   303 // ---------------------------------------------------------
       
   304 //
       
   305 void CCamUserSceneSetupContainer::UpdateListItem( TInt aIndex )
       
   306     {     
       
   307     // Get the current value for this list item from the settings model.
       
   308     // ...get settings model id for list item.
       
   309     TInt settingsModelId = 
       
   310             iUserSceneSetupItemArray->At( aIndex )->SettingsModelTypeId();
       
   311     if ( settingsModelId != ECamSettingItemUserSceneReset )
       
   312         {
       
   313         // ...use id to get current value.
       
   314         TInt currentVal = iController.IntegerSettingValue( settingsModelId );
       
   315     
       
   316         // Update list item with the current value.
       
   317         iUserSceneSetupItemArray->At( aIndex )->SetCurrentValue( currentVal );
       
   318         }
       
   319     }
       
   320 
       
   321 
       
   322 // ----------------------------------------------------
       
   323 // CCamUserSceneSetupContainer::CommandIdForActivatingCurrentItemControl
       
   324 // Returns the command id for activating the current list item control.
       
   325 // ----------------------------------------------------
       
   326 //
       
   327 TInt CCamUserSceneSetupContainer::CommandIdForActivatingCurrentItemControl()
       
   328     {
       
   329     // Get the settings model type id for the selected item.
       
   330     // ...get settings model id for list item.  
       
   331     TInt currentIndex = iUserSceneSetupList->CurrentItemIndex();
       
   332     
       
   333     // ...get settings model id for list item.
       
   334     TInt settingsModelId = 
       
   335         iUserSceneSetupItemArray->At( currentIndex )->
       
   336             SettingsModelTypeId();
       
   337     // Convert settings model id to command id that activates the
       
   338     // control for the selected item.
       
   339     TInt commandId = -1;
       
   340     switch ( settingsModelId )
       
   341         {
       
   342         case ECamSettingItemUserSceneBasedOnScene:
       
   343             {
       
   344             commandId = ECamCmdCaptureSetupSceneUser;
       
   345             }
       
   346             break;
       
   347         case ECamSettingItemUserSceneWhitebalance:
       
   348             {
       
   349             commandId = ECamCmdCaptureSetupWhiteBalanceUser;
       
   350             }
       
   351             break;
       
   352         case ECamSettingItemUserSceneExposure:
       
   353             {
       
   354             commandId = ECamCmdCaptureSetupExposureUser;
       
   355             }
       
   356             break;
       
   357         case ECamSettingItemUserSceneColourFilter:
       
   358             {
       
   359             commandId = ECamCmdCaptureSetupColourFilterUser;
       
   360             }
       
   361             break;
       
   362         case ECamSettingItemUserSceneFlash:
       
   363             {
       
   364             commandId = ECamCmdCaptureSetupFlashUser;
       
   365             }
       
   366             break;
       
   367         case ECamSettingItemUserSceneReset:
       
   368             {
       
   369             commandId = ECamCmdUserSceneReset;
       
   370             }
       
   371             break;
       
   372         case ECamSettingItemUserSceneBrightness:
       
   373             {
       
   374             commandId = ECamCmdCaptureSetupBrightnessUser;
       
   375             }
       
   376             break;
       
   377         case ECamSettingItemUserSceneContrast:
       
   378             {
       
   379             commandId = ECamCmdCaptureSetupContrastUser;
       
   380             }
       
   381             break;
       
   382 
       
   383         case ECamSettingItemUserSceneImageSharpness:
       
   384             {
       
   385             commandId = ECamCmdCaptureSetupImageSharpnessUser;
       
   386             }
       
   387             break;
       
   388 
       
   389         case ECamSettingItemUserSceneLightSensitivity:
       
   390             {
       
   391             commandId = ECamCmdCaptureSetupLightSensitivityUser;
       
   392             }
       
   393             break;
       
   394         default:
       
   395             {
       
   396             CamPanic( ECamPanicCaptureSetupMenuUnknownItem );
       
   397             }
       
   398         }
       
   399     return commandId;
       
   400     }
       
   401 
       
   402 
       
   403 
       
   404 // ---------------------------------------------------------
       
   405 // CCamUserSceneSetupContainer::CountComponentControls
       
   406 // ---------------------------------------------------------
       
   407 //
       
   408 TInt CCamUserSceneSetupContainer::CountComponentControls() const
       
   409     {
       
   410 	return 1;
       
   411 	}
       
   412 
       
   413 // ---------------------------------------------------------
       
   414 // CCamUserSceneSetupContainer::ComponentControl
       
   415 // ---------------------------------------------------------
       
   416 //
       
   417 CCoeControl* CCamUserSceneSetupContainer::ComponentControl
       
   418 ( TInt aIndex ) const
       
   419     {
       
   420     switch( aIndex )
       
   421         {
       
   422         case 0:
       
   423             return iUserSceneSetupList;
       
   424         default:
       
   425             return NULL;            
       
   426         }
       
   427         
       
   428     // Should never get here
       
   429     }
       
   430 
       
   431 // ---------------------------------------------------------------------------
       
   432 // CCamUserSceneSetupContainer::OfferKeyEventL
       
   433 // Key event handling
       
   434 // ---------------------------------------------------------------------------
       
   435 //
       
   436 TKeyResponse CCamUserSceneSetupContainer::OfferKeyEventL(
       
   437     const TKeyEvent& aKeyEvent,
       
   438     TEventCode aType )
       
   439     {
       
   440 	return iUserSceneSetupList->OfferKeyEventL( aKeyEvent, aType );
       
   441     }
       
   442 
       
   443 // ---------------------------------------------------------------------------
       
   444 // CCamUserSceneSetupContainer::ListBox
       
   445 // Returns a pointer to the list box
       
   446 // ---------------------------------------------------------------------------
       
   447 //
       
   448 CEikFormattedCellListBox* CCamUserSceneSetupContainer::ListBox()
       
   449 	{
       
   450 	return ( iUserSceneSetupList );
       
   451 	}
       
   452 
       
   453 // ---------------------------------------------------------------------------
       
   454 // CCamUserSceneSetupContainer::IsUserSceneResetHighlighted
       
   455 // Returns wheather user scene restore is highlighted
       
   456 // ---------------------------------------------------------------------------
       
   457 //
       
   458 TBool CCamUserSceneSetupContainer::IsUserSceneResetHighlighted()
       
   459 	{
       
   460     TInt currentIndex = iUserSceneSetupList->CurrentItemIndex();
       
   461     // ...get settings model id for list item.
       
   462     TInt settingsModelId = 
       
   463         iUserSceneSetupItemArray->At( currentIndex )->SettingsModelTypeId();
       
   464     if ( settingsModelId == ECamSettingItemUserSceneReset )
       
   465         {
       
   466         return ETrue;
       
   467         }
       
   468     else 
       
   469         {
       
   470         return EFalse;
       
   471         }
       
   472 	}
       
   473 
       
   474 // End of File