camerauis/cameraapp/generic/src/CamCaptureSetupMenu.cpp
changeset 0 1ddebce53859
child 31 8f559c47d7fd
equal deleted inserted replaced
-1:000000000000 0:1ddebce53859
       
     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 1; 
       
   177     }
       
   178 
       
   179 // ---------------------------------------------------------
       
   180 // CCamCaptureSetupMenu::ComponentControl(TInt aIndex) const
       
   181 // ---------------------------------------------------------
       
   182 //
       
   183 CCoeControl* CCamCaptureSetupMenu::ComponentControl(TInt /*aIndex*/) const
       
   184     {
       
   185 	return iCaptureSetupListBox;
       
   186     }
       
   187 
       
   188 // ---------------------------------------------------------
       
   189 // CCamCaptureSetupMenu::Draw(const TRect& aRect) const
       
   190 // ---------------------------------------------------------
       
   191 //
       
   192 void CCamCaptureSetupMenu::Draw(const TRect& /*aRect*/) const
       
   193     {
       
   194     }
       
   195 
       
   196 // ----------------------------------------------------
       
   197 // CCamCaptureSetupMenu::OfferKeyEventL
       
   198 // Handles this application view's command keys. Forwards
       
   199 // other keys to child control(s).
       
   200 // ----------------------------------------------------
       
   201 //
       
   202 TKeyResponse CCamCaptureSetupMenu::OfferKeyEventL(
       
   203     const TKeyEvent& aKeyEvent,
       
   204     TEventCode aType )
       
   205     {
       
   206     // now it's iListBox's job to process the key event
       
   207     TKeyResponse response = iCaptureSetupListBox->OfferKeyEventL( aKeyEvent, aType );
       
   208     // If it hasn't been processed pass up to the base class.
       
   209     if ( response == EKeyWasNotConsumed )
       
   210         {
       
   211         return CCamContainerBase::OfferKeyEventL( aKeyEvent, aType );
       
   212         }
       
   213 
       
   214     iController.StartIdleTimer();
       
   215     return response;
       
   216     }
       
   217 
       
   218 // ----------------------------------------------------
       
   219 // CCamCaptureSetupMenu::CreateCaptureSetupListBoxL
       
   220 // Creates the list box control.
       
   221 // ----------------------------------------------------
       
   222 //
       
   223 void 
       
   224 CCamCaptureSetupMenu::CreateCaptureSetupListBoxL( TRect& aRect, TInt aResourceId, TInt aSelectedItemIndex )
       
   225 	{
       
   226 	PRINT( _L("Camera => CCamCaptureSetupMenu::CreateCaptureSetupListBoxL") );
       
   227     // Determine the complete drawing rectangle.
       
   228     TRect appUiRect = aRect;
       
   229     appUiRect.iTl.iX = 0;
       
   230     appUiRect.iTl.iY = 0;
       
   231 
       
   232     // Create the resource reader for this list box.
       
   233     TResourceReader reader;                                                                                     
       
   234     iEikonEnv->CreateResourceReaderLC( reader, aResourceId );    
       
   235 
       
   236     // Read the layout for the list box.
       
   237     TAknLayoutRect listBoxLayoutRect;
       
   238     listBoxLayoutRect.LayoutRect( aRect, reader );
       
   239 
       
   240     // Create the listbox.
       
   241     iCaptureSetupListBox = CCamCaptureSetupMenuListBox::NewL
       
   242         ( this, reader, iController, aSelectedItemIndex );
       
   243 
       
   244     aRect = listBoxLayoutRect.Rect();
       
   245 
       
   246     // Set the layout for the list box control.
       
   247     const AknLayoutUtils::SAknLayoutControl listboxLayout =
       
   248         { ELayoutEmpty, 0, 0, ELayoutEmpty, ELayoutEmpty, aRect.Width(), aRect.Height() };
       
   249     AknLayoutUtils::LayoutControl( iCaptureSetupListBox, appUiRect, listboxLayout );
       
   250 
       
   251     // Set the height of a list item
       
   252     TInt listItemHeight = reader.ReadInt16();
       
   253     iCaptureSetupListBox->SetItemHeightL( listItemHeight );
       
   254 
       
   255     iCaptureSetupListBox->MakeVisible( ETrue );
       
   256     iCaptureSetupListBox->SetFocus( EFalse, EDrawNow );
       
   257 
       
   258     CleanupStack::PopAndDestroy(); // reader
       
   259 	PRINT( _L("Camera <= CCamCaptureSetupMenu::CreateCaptureSetupListBoxL") );
       
   260 	}
       
   261 
       
   262 // ----------------------------------------------------
       
   263 // CCamCaptureSetupMenu::CommandIdForActivatingCurrentItemControl
       
   264 // Returns the command id for activating the current list item control.
       
   265 // ----------------------------------------------------
       
   266 //
       
   267 TInt CCamCaptureSetupMenu::CommandIdForActivatingCurrentItemControl()
       
   268     {
       
   269     // Get the index of the currently selected item.
       
   270     TInt selectedItemIndex = iCaptureSetupListBox->CurrentItemIndex();
       
   271     // Get the setting model id for the currently selected item.
       
   272     TInt selectedItemSettingsId = iCaptureSetupListBox->ItemSettingsId( selectedItemIndex );
       
   273     // Convert settings model id to command id that activates the
       
   274     // control for the selected item.
       
   275     TInt commandId = -1;
       
   276     switch ( selectedItemSettingsId )
       
   277         {
       
   278         case ECamSettingItemDynamicPhotoScene:
       
   279             commandId = ECamCmdCaptureSetupSceneStill;
       
   280             break;
       
   281         case ECamSettingItemDynamicPhotoWhiteBalance:
       
   282             commandId = ECamCmdCaptureSetupWhiteBalanceStill;
       
   283             break;
       
   284 
       
   285         case ECamSettingItemDynamicPhotoExposure:
       
   286             commandId = ECamCmdCaptureSetupExposureStill;
       
   287             break;
       
   288 
       
   289         case ECamSettingItemDynamicPhotoColourFilter:
       
   290             commandId = ECamCmdCaptureSetupColourFilterStill;
       
   291             break;
       
   292         case ECamSettingItemDynamicPhotoFlash:
       
   293             commandId = ECamCmdCaptureSetupFlashStill;
       
   294             break;
       
   295         case ECamSettingItemDynamicVideoScene:
       
   296             commandId = ECamCmdCaptureSetupSceneVideo;
       
   297             break;
       
   298         case ECamSettingItemDynamicVideoWhiteBalance:
       
   299             commandId = ECamCmdCaptureSetupWhiteBalanceVideo;
       
   300             break;
       
   301         case ECamSettingItemDynamicVideoColourFilter:
       
   302             commandId = ECamCmdCaptureSetupColourFilterVideo;
       
   303             break;
       
   304         case ECamSettingItemDynamicPhotoBrightness:
       
   305             commandId = ECamCmdCaptureSetupBrightnessStill;
       
   306             break;
       
   307         case ECamSettingItemDynamicPhotoContrast:
       
   308             commandId = ECamCmdCaptureSetupContrastStill;
       
   309             break;
       
   310         case ECamSettingItemDynamicVideoBrightness:
       
   311             commandId = ECamCmdCaptureSetupBrightnessVideo;
       
   312             break;
       
   313         case ECamSettingItemDynamicVideoContrast:
       
   314             commandId = ECamCmdCaptureSetupContrastVideo;
       
   315             break;
       
   316         case ECamSettingItemDynamicPhotoImageSharpness:
       
   317             commandId = ECamCmdCaptureSetupImageSharpnessStill;
       
   318             break;
       
   319         default:
       
   320             CamPanic( ECamPanicCaptureSetupMenuUnknownItem );
       
   321         }
       
   322     return commandId;
       
   323     }
       
   324 
       
   325 // ----------------------------------------------------
       
   326 // CCamCaptureSetupMenu::HandleSelectionL
       
   327 // Handles the pressing of the softkey selection.
       
   328 // ----------------------------------------------------
       
   329 //
       
   330 void CCamCaptureSetupMenu::HandleSelectionL()
       
   331     {
       
   332     TInt CommandId = CommandIdForActivatingCurrentItemControl();
       
   333     iView.HandleCommandL( CommandId );
       
   334     }
       
   335 
       
   336 
       
   337 // End of File