camerauis/cameraapp/generic/src/CamCaptureSetupMenu.cpp
branchRCL_3
changeset 53 61bc0f252b2b
parent 50 f54ad444594d
child 54 bac7acad7cb3
equal deleted inserted replaced
50:f54ad444594d 53:61bc0f252b2b
     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:  Container for the capture setup menu list box.*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <barsread.h>
       
    21 #include <AknsFrameBackgroundControlContext.h>
       
    22 #include <aknview.h>
       
    23 #include <AknUtils.h>
       
    24 
       
    25 #include <cameraapp.rsg>
       
    26 #include <vgacamsettings.rsg>
       
    27 
       
    28 #include "CamCaptureSetupMenu.h"
       
    29 #include "CamCaptureSetupMenuListBox.h"
       
    30 #include "CamAppController.h"
       
    31 #include "CamPanic.h"
       
    32 #include "CamSettings.hrh"
       
    33 #include "Cam.hrh"
       
    34 #include "camlogging.h"
       
    35 
       
    36 const TInt KNumComponentComtrols = 1;
       
    37 
       
    38 // ================= MEMBER FUNCTIONS =======================
       
    39 
       
    40 // ---------------------------------------------------------
       
    41 // CCamCaptureSetupMenu::NewL
       
    42 // Two-phased constructor.
       
    43 // ---------------------------------------------------------
       
    44 //
       
    45 CCamCaptureSetupMenu* CCamCaptureSetupMenu::NewL( 
       
    46     CCamAppController& aController,
       
    47     CAknView& aView,
       
    48     const TRect& aRect,
       
    49     TInt aResourceId,
       
    50     TInt aSelectedItemIndex )
       
    51     {
       
    52     CCamCaptureSetupMenu* self = new( ELeave ) CCamCaptureSetupMenu
       
    53         ( aController, aView );
       
    54     CleanupStack::PushL( self );
       
    55     self->ConstructL( aRect, aResourceId, aSelectedItemIndex );
       
    56     CleanupStack::Pop( self );
       
    57     return self;
       
    58     }
       
    59 
       
    60 // ---------------------------------------------------------
       
    61 // Destructor
       
    62 // ---------------------------------------------------------
       
    63 //
       
    64 CCamCaptureSetupMenu::~CCamCaptureSetupMenu()
       
    65   {
       
    66   PRINT( _L("Camera => ~CCamCaptureSetupMenu") );
       
    67   delete iCaptureSetupListBox;
       
    68   // iBgContext is deleted in base class
       
    69   PRINT( _L("Camera <= ~CCamCaptureSetupMenu") );
       
    70   }
       
    71 
       
    72 // ---------------------------------------------------------
       
    73 // Returns the list index of the currently selected item.
       
    74 // ---------------------------------------------------------
       
    75 //
       
    76 TInt CCamCaptureSetupMenu::CurrentItemIndex() const
       
    77     {
       
    78     return iCaptureSetupListBox->CurrentItemIndex();
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // CCamCaptureSetupMenu::FadeBehind
       
    83 // Fades everything behind this menu.
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 void CCamCaptureSetupMenu::FadeBehind( TBool aFade )
       
    87     {
       
    88     iPopupFader.FadeBehindPopup( this, this, aFade );
       
    89     }
       
    90 
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // CCamCaptureSetupMenu::CountFadedComponents
       
    94 // Returns the number of components that are not faded
       
    95 // when the fader object is active.
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 TInt CCamCaptureSetupMenu::CountFadedComponents()
       
    99     {
       
   100     return KNumComponentComtrols;
       
   101     }
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // CCamCaptureSetupMenu::FadedComponent
       
   105 // Returns a pointer to a non-faded component.
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 CCoeControl* CCamCaptureSetupMenu::FadedComponent(TInt aIndex)
       
   109     {
       
   110 	switch (aIndex)
       
   111 		{
       
   112 		case 0:
       
   113 			return this;
       
   114 		default:
       
   115 			return NULL;
       
   116         }
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // CCamCaptureSetupMenu::HandleCommandL
       
   121 // Handle commands
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 void CCamCaptureSetupMenu::HandleCommandL( TInt aCommand )
       
   125     {
       
   126     switch ( aCommand )
       
   127         {
       
   128         case EAknSoftkeySelect:
       
   129             {
       
   130             HandleSelectionL();
       
   131             break;
       
   132             }
       
   133         default:
       
   134             {
       
   135             CamPanic( ECamPanicUnhandledCommand );
       
   136             break;
       
   137             }
       
   138         }
       
   139     }
       
   140 
       
   141 
       
   142 
       
   143 // ---------------------------------------------------------
       
   144 // C++ constructor
       
   145 // ---------------------------------------------------------
       
   146 //
       
   147 CCamCaptureSetupMenu::CCamCaptureSetupMenu( CCamAppController& aController,
       
   148                           CAknView& aView )
       
   149 : CCamContainerBase( aController, aView )
       
   150     {
       
   151     }
       
   152 
       
   153 // ---------------------------------------------------------
       
   154 // CCamCaptureSetupMenu::ConstructL()
       
   155 // 2nd phase constructor
       
   156 // ---------------------------------------------------------
       
   157 //
       
   158 void CCamCaptureSetupMenu::ConstructL( const TRect& aRect, TInt aResourceId, TInt aSelectedItemIndex )
       
   159     {
       
   160     CreateWindowL();
       
   161     TRect listBoxRect = aRect;
       
   162 	CreateCaptureSetupListBoxL( listBoxRect, aResourceId, aSelectedItemIndex );
       
   163     SetRect( listBoxRect );
       
   164     // set up the skin background context
       
   165     iBgContext = CAknsFrameBackgroundControlContext::NewL( 
       
   166             KAknsIIDQsnFrPopup, Rect(), Rect(), EFalse );
       
   167     }
       
   168 
       
   169 // ---------------------------------------------------------
       
   170 // CCamCaptureSetupMenu::CountComponentControls() const
       
   171 // ---------------------------------------------------------
       
   172 //
       
   173 TInt CCamCaptureSetupMenu::CountComponentControls() const
       
   174     {
       
   175 	// this control contains a listbox
       
   176     return CCamContainerBase::CountComponentControls() + 1; 
       
   177     }
       
   178 
       
   179 // ---------------------------------------------------------
       
   180 // CCamCaptureSetupMenu::ComponentControl(TInt aIndex) const
       
   181 // ---------------------------------------------------------
       
   182 //
       
   183 CCoeControl* CCamCaptureSetupMenu::ComponentControl(TInt aIndex) const
       
   184     {
       
   185     CCoeControl* control = CCamContainerBase::ComponentControl( aIndex );
       
   186     if( control == NULL)
       
   187         {
       
   188         control = iCaptureSetupListBox;
       
   189         }
       
   190     return control;
       
   191 	}
       
   192 
       
   193 // ---------------------------------------------------------
       
   194 // CCamCaptureSetupMenu::Draw(const TRect& aRect) const
       
   195 // ---------------------------------------------------------
       
   196 //
       
   197 void CCamCaptureSetupMenu::Draw(const TRect& /*aRect*/) const
       
   198     {
       
   199     }
       
   200 
       
   201 // ----------------------------------------------------
       
   202 // CCamCaptureSetupMenu::OfferKeyEventL
       
   203 // Handles this application view's command keys. Forwards
       
   204 // other keys to child control(s).
       
   205 // ----------------------------------------------------
       
   206 //
       
   207 TKeyResponse CCamCaptureSetupMenu::OfferKeyEventL(
       
   208     const TKeyEvent& aKeyEvent,
       
   209     TEventCode aType )
       
   210     {
       
   211     // now it's iListBox's job to process the key event
       
   212     TKeyResponse response = iCaptureSetupListBox->OfferKeyEventL( aKeyEvent, aType );
       
   213     // If it hasn't been processed pass up to the base class.
       
   214     if ( response == EKeyWasNotConsumed )
       
   215         {
       
   216         return CCamContainerBase::OfferKeyEventL( aKeyEvent, aType );
       
   217         }
       
   218 
       
   219     iController.StartIdleTimer();
       
   220     return response;
       
   221     }
       
   222 
       
   223 // ----------------------------------------------------
       
   224 // CCamCaptureSetupMenu::CreateCaptureSetupListBoxL
       
   225 // Creates the list box control.
       
   226 // ----------------------------------------------------
       
   227 //
       
   228 void 
       
   229 CCamCaptureSetupMenu::CreateCaptureSetupListBoxL( TRect& aRect, TInt aResourceId, TInt aSelectedItemIndex )
       
   230 	{
       
   231 	PRINT( _L("Camera => CCamCaptureSetupMenu::CreateCaptureSetupListBoxL") );
       
   232     // Determine the complete drawing rectangle.
       
   233     TRect appUiRect = aRect;
       
   234     appUiRect.iTl.iX = 0;
       
   235     appUiRect.iTl.iY = 0;
       
   236 
       
   237     // Create the resource reader for this list box.
       
   238     TResourceReader reader;                                                                                     
       
   239     iEikonEnv->CreateResourceReaderLC( reader, aResourceId );    
       
   240 
       
   241     // Read the layout for the list box.
       
   242     TAknLayoutRect listBoxLayoutRect;
       
   243     listBoxLayoutRect.LayoutRect( aRect, reader );
       
   244 
       
   245     // Create the listbox.
       
   246     iCaptureSetupListBox = CCamCaptureSetupMenuListBox::NewL
       
   247         ( this, reader, iController, aSelectedItemIndex );
       
   248 
       
   249     aRect = listBoxLayoutRect.Rect();
       
   250 
       
   251     // Set the layout for the list box control.
       
   252     const AknLayoutUtils::SAknLayoutControl listboxLayout =
       
   253         { ELayoutEmpty, 0, 0, ELayoutEmpty, ELayoutEmpty, aRect.Width(), aRect.Height() };
       
   254     AknLayoutUtils::LayoutControl( iCaptureSetupListBox, appUiRect, listboxLayout );
       
   255 
       
   256     // Set the height of a list item
       
   257     TInt listItemHeight = reader.ReadInt16();
       
   258     iCaptureSetupListBox->SetItemHeightL( listItemHeight );
       
   259 
       
   260     iCaptureSetupListBox->MakeVisible( ETrue );
       
   261     iCaptureSetupListBox->SetFocus( EFalse, EDrawNow );
       
   262 
       
   263     CleanupStack::PopAndDestroy(); // reader
       
   264 	PRINT( _L("Camera <= CCamCaptureSetupMenu::CreateCaptureSetupListBoxL") );
       
   265 	}
       
   266 
       
   267 // ----------------------------------------------------
       
   268 // CCamCaptureSetupMenu::CommandIdForActivatingCurrentItemControl
       
   269 // Returns the command id for activating the current list item control.
       
   270 // ----------------------------------------------------
       
   271 //
       
   272 TInt CCamCaptureSetupMenu::CommandIdForActivatingCurrentItemControl()
       
   273     {
       
   274     // Get the index of the currently selected item.
       
   275     TInt selectedItemIndex = iCaptureSetupListBox->CurrentItemIndex();
       
   276     // Get the setting model id for the currently selected item.
       
   277     TInt selectedItemSettingsId = iCaptureSetupListBox->ItemSettingsId( selectedItemIndex );
       
   278     // Convert settings model id to command id that activates the
       
   279     // control for the selected item.
       
   280     TInt commandId = -1;
       
   281     switch ( selectedItemSettingsId )
       
   282         {
       
   283         case ECamSettingItemDynamicPhotoScene:
       
   284             commandId = ECamCmdCaptureSetupSceneStill;
       
   285             break;
       
   286         case ECamSettingItemDynamicPhotoWhiteBalance:
       
   287             commandId = ECamCmdCaptureSetupWhiteBalanceStill;
       
   288             break;
       
   289 
       
   290         case ECamSettingItemDynamicPhotoExposure:
       
   291             commandId = ECamCmdCaptureSetupExposureStill;
       
   292             break;
       
   293 
       
   294         case ECamSettingItemDynamicPhotoColourFilter:
       
   295             commandId = ECamCmdCaptureSetupColourFilterStill;
       
   296             break;
       
   297         case ECamSettingItemDynamicPhotoFlash:
       
   298             commandId = ECamCmdCaptureSetupFlashStill;
       
   299             break;
       
   300         case ECamSettingItemDynamicVideoScene:
       
   301             commandId = ECamCmdCaptureSetupSceneVideo;
       
   302             break;
       
   303         case ECamSettingItemDynamicVideoWhiteBalance:
       
   304             commandId = ECamCmdCaptureSetupWhiteBalanceVideo;
       
   305             break;
       
   306         case ECamSettingItemDynamicVideoColourFilter:
       
   307             commandId = ECamCmdCaptureSetupColourFilterVideo;
       
   308             break;
       
   309         case ECamSettingItemDynamicPhotoBrightness:
       
   310             commandId = ECamCmdCaptureSetupBrightnessStill;
       
   311             break;
       
   312         case ECamSettingItemDynamicPhotoContrast:
       
   313             commandId = ECamCmdCaptureSetupContrastStill;
       
   314             break;
       
   315         case ECamSettingItemDynamicVideoBrightness:
       
   316             commandId = ECamCmdCaptureSetupBrightnessVideo;
       
   317             break;
       
   318         case ECamSettingItemDynamicVideoContrast:
       
   319             commandId = ECamCmdCaptureSetupContrastVideo;
       
   320             break;
       
   321         case ECamSettingItemDynamicPhotoImageSharpness:
       
   322             commandId = ECamCmdCaptureSetupImageSharpnessStill;
       
   323             break;
       
   324         default:
       
   325             CamPanic( ECamPanicCaptureSetupMenuUnknownItem );
       
   326         }
       
   327     return commandId;
       
   328     }
       
   329 
       
   330 // ----------------------------------------------------
       
   331 // CCamCaptureSetupMenu::HandleSelectionL
       
   332 // Handles the pressing of the softkey selection.
       
   333 // ----------------------------------------------------
       
   334 //
       
   335 void CCamCaptureSetupMenu::HandleSelectionL()
       
   336     {
       
   337     TInt CommandId = CommandIdForActivatingCurrentItemControl();
       
   338     iView.HandleCommandL( CommandId );
       
   339     }
       
   340 
       
   341 
       
   342 // End of File