camerauis/cameraapp/generic/src/CamBurstThumbnailContainer.cpp
branchRCL_3
changeset 24 bac7acad7cb3
child 25 2c87b2808fd7
equal deleted inserted replaced
23:61bc0f252b2b 24:bac7acad7cb3
       
     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 class for burst thumbnail view*
       
    15 */
       
    16 
       
    17 // INCLUDE FILES
       
    18 #include <aknview.h> 
       
    19 #include <cameraapp.rsg>
       
    20 #include <vgacamsettings.rsg>
       
    21 #include <AknsUtils.h>
       
    22 #include <AknsDrawUtils.h>
       
    23 #include <touchfeedback.h>
       
    24 #include <aknlayoutscalable_apps.cdl.h> // AknLayoutScalable_Apps
       
    25 
       
    26  
       
    27 #include "CamBurstThumbnailContainer.h"
       
    28 #include "CamBurstThumbnailGrid.h"
       
    29 #include "camlogging.h"
       
    30 #include "CamUtility.h"
       
    31 
       
    32 
       
    33 
       
    34 // CONSTANTS
       
    35 
       
    36 // ================= MEMBER FUNCTIONS =======================
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // CCamBurstThumbnailContainer::NewL
       
    40 // Symbian OS two-phased constructor
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 CCamBurstThumbnailContainer* CCamBurstThumbnailContainer::NewL(
       
    44         CCamAppController& aController,
       
    45         CAknView& aView,
       
    46         const TRect& aRect,
       
    47         CCamBurstThumbnailGridModel& aGridModel )
       
    48     {
       
    49     CCamBurstThumbnailContainer* self = new( ELeave ) 
       
    50         CCamBurstThumbnailContainer( aController, aView, aGridModel );
       
    51     CleanupStack::PushL( self );
       
    52     self->ConstructL( aRect );
       
    53     CleanupStack::Pop( );
       
    54     // return newly created CCamBurstThumbnailContainer instance
       
    55     return self;
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // CCamBurstThumbnailContainer
       
    60 // Destructor
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 CCamBurstThumbnailContainer::~CCamBurstThumbnailContainer()
       
    64     {
       
    65     delete iGridControl;
       
    66     }
       
    67   
       
    68 // ---------------------------------------------------------
       
    69 // CCamBurstThumbnailContainer::ConstructL
       
    70 // Symbian OS 2nd phase constructor
       
    71 // ---------------------------------------------------------
       
    72 //
       
    73 void CCamBurstThumbnailContainer::ConstructL( const TRect& aRect )
       
    74     {
       
    75 
       
    76     PRINT( _L("Camera => CCamBurstThumbnailContainer::ConstructL") );
       
    77     CCamContainerBase::BaseConstructL( aRect );
       
    78     
       
    79     iGridControl = CCamBurstThumbnailGrid::NewL( this , iGridModel );
       
    80   
       
    81     TRect mainPaneRect;
       
    82     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane,
       
    83             mainPaneRect );
       
    84     TRect statusPaneRect;
       
    85     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EStatusPane,
       
    86             statusPaneRect );
       
    87 
       
    88     // layout area rectangle contains the area, where components need to be 
       
    89     // drawn to. the container size is the whole screen, but the layouts are 
       
    90     // for the client area. aRect is the container size that might include or
       
    91     // might not include statuspane area. calculating area self will
       
    92     // go around the problem
       
    93     TRect layoutAreaRect;
       
    94     layoutAreaRect = mainPaneRect;
       
    95     layoutAreaRect.BoundingRect( statusPaneRect );
       
    96     
       
    97 
       
    98     TAknLayoutRect burstPaneRect;           
       
    99     if ( CamUtility::IsNhdDevice() )
       
   100         {
       
   101         // use layoutAreaRect for nhd (contains the statuspane)
       
   102         burstPaneRect.LayoutRect( layoutAreaRect, AknLayoutScalable_Apps::main_cam4_burst_pane() );
       
   103         // SetRect( layoutAreaRect );
       
   104         }
       
   105     else
       
   106         {
       
   107         // use mainpane for vga
       
   108         burstPaneRect.LayoutRect( mainPaneRect,  AknLayoutScalable_Apps::main_cam4_burst_pane() );
       
   109 
       
   110         }
       
   111 
       
   112     
       
   113     // layout grid
       
   114     TInt gridSize = iGridModel.NoOfValidCells();   
       
   115     
       
   116     if ( gridSize <= KBurstGridDefaultThumbnails)
       
   117     	{
       
   118 	    AknLayoutUtils::LayoutControl( iGridControl, /*aRect*/
       
   119 	            burstPaneRect.Rect(), 
       
   120 	            AknLayoutScalable_Apps::grid_cam4_burst_pane(1) );
       
   121 	    }
       
   122 	else if ( gridSize <= KBurstGridMaxVisibleThumbnails )
       
   123 	    {
       
   124 	    AknLayoutUtils::LayoutControl( iGridControl, //aRect,
       
   125 	            burstPaneRect.Rect(), 
       
   126 	            AknLayoutScalable_Apps::grid_cam4_burst_pane(3) );
       
   127 	    }
       
   128 	else // gridSize > KBurstGridMaxVisibleThumbnails
       
   129 		{
       
   130 		AknLayoutUtils::LayoutControl( iGridControl, //aRect
       
   131 		        burstPaneRect.Rect(), 
       
   132 		        AknLayoutScalable_Apps::grid_cam4_burst_pane(5) );
       
   133 		}
       
   134     
       
   135     // scroll bar
       
   136     if ( gridSize > KBurstGridMaxVisibleThumbnails )       
       
   137         {
       
   138         // Will create the scrollbar if it is needed        
       
   139         iGridControl->SetMopParent( this );
       
   140         iGridControl->CreateScrollBarL();
       
   141         iGridControl->SetupScrollbarL( );        
       
   142         }        
       
   143        
       
   144     
       
   145     iFeedback = MTouchFeedback::Instance(); 
       
   146     
       
   147     // make sure that softkeys are shown
       
   148     DrawableWindow()->SetOrdinalPosition( KCamPostCaptureWindowOrdinalPos );
       
   149     
       
   150     PRINT( _L("Camera <= CCamBurstThumbnailContainer::ConstructL") );
       
   151     }
       
   152     
       
   153 // ---------------------------------------------------------------------------
       
   154 // CCamBurstThumbnailContainer::CCamBurstThumbnailContainer
       
   155 // C++ constructor
       
   156 // ---------------------------------------------------------------------------
       
   157 //
       
   158 CCamBurstThumbnailContainer::CCamBurstThumbnailContainer( 
       
   159                             CCamAppController& aController,
       
   160                             CAknView& aView,
       
   161                             CCamBurstThumbnailGridModel& aGridModel )
       
   162 : CCamContainerBase( aController, aView ), iGridModel( aGridModel )
       
   163     {
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------
       
   167 // CCamBurstThumbnailContainer::CountComponentControls 
       
   168 // Returns the number of controls owned
       
   169 // ---------------------------------------------------------
       
   170 //
       
   171 TInt CCamBurstThumbnailContainer::CountComponentControls() const
       
   172     {    
       
   173     return CCamContainerBase::CountComponentControls() + 1;   // Return the number of controls inside this container
       
   174     }
       
   175 
       
   176 // ---------------------------------------------------------
       
   177 // CCamBurstThumbnailContainer::ComponentControl
       
   178 // Return pointer to a contained control
       
   179 // ---------------------------------------------------------
       
   180 //
       
   181 CCoeControl* CCamBurstThumbnailContainer::ComponentControl( TInt aIndex ) const
       
   182     {
       
   183     CCoeControl* control = NULL;
       
   184     control = CCamContainerBase::ComponentControl( aIndex );
       
   185     if( control != NULL )
       
   186         return control;
       
   187     switch ( aIndex )
       
   188         {
       
   189         case 1:
       
   190             {
       
   191             control = iGridControl;
       
   192             }
       
   193             break;
       
   194         default: 
       
   195             break;                   
       
   196         }
       
   197     
       
   198     return control;
       
   199     }
       
   200 
       
   201 
       
   202 // ---------------------------------------------------------
       
   203 // CCamBurstThumbnailContainer::Draw
       
   204 // Draw control
       
   205 // ---------------------------------------------------------
       
   206 //
       
   207 void CCamBurstThumbnailContainer::Draw( const TRect& aRect ) const
       
   208     {
       
   209     
       
   210     CWindowGc& gc = SystemGc();
       
   211         
       
   212     // Draw skin background for the 
       
   213     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   214     MAknsControlContext* cc = AknsDrawUtils::ControlContext( this );
       
   215     AknsDrawUtils::Background( skin, cc, gc, aRect );
       
   216     
       
   217     //gc.Clear( Rect() );
       
   218     
       
   219     }
       
   220 
       
   221 // ----------------------------------------------------
       
   222 // CCamBurstThumbnailContainer::OfferKeyEventL
       
   223 // Handles this application view's command keys. Forwards other
       
   224 // keys to child control(s).
       
   225 // ----------------------------------------------------
       
   226 //
       
   227 TKeyResponse 
       
   228 CCamBurstThumbnailContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent,
       
   229                                                    TEventCode aType )
       
   230     {
       
   231     PRINT( _L("Camera => CCamBurstThumbnailContainer::OfferKeyEventL") );
       
   232     TKeyResponse response( EKeyWasNotConsumed );
       
   233     TBool captureKey = IsCaptureKeyL( aKeyEvent, aType );
       
   234 
       
   235     TBool embedded = static_cast<CCamAppUiBase*>( 
       
   236             CEikonEnv::Static()->AppUi() )->IsEmbedded();
       
   237 
       
   238     // If the back softkey is pressed
       
   239     if ( aKeyEvent.iScanCode == EStdKeyDevice1 )
       
   240         {
       
   241         response = EKeyWasNotConsumed; // indicate key press was not processed
       
   242         }
       
   243     else if ( aKeyEvent.iScanCode == EStdKeyDevice3 )   // Select key
       
   244         {
       
   245         // Will pass it on to the view
       
   246         response = CCamContainerBase::OfferKeyEventL( aKeyEvent, aType );
       
   247         }
       
   248     //make sure to unset DemandKeyRelease
       
   249     else if( aType == EEventKeyUp && !embedded )
       
   250         {
       
   251         iController.SetDemandKeyRelease( EFalse ); 
       
   252         }    
       
   253     else if ( captureKey // && aKeyEvent.iScanCode == EProductKeyCapture )
       
   254             || IsShutterKeyL( aKeyEvent, aType )
       
   255             )
       
   256         {
       
   257         if ( aType == EEventKeyDown ) 
       
   258             // check needed, since EEventFocusLost produces EEventKeyUp for shutterkey
       
   259             {
       
   260             if ( !embedded )
       
   261                 {
       
   262                     iGridModel.CancelThumbnails();
       
   263     
       
   264                     iView.HandleCommandL( ECamCmdNewPhoto );
       
   265                     // Demand to relese capture key in pre capture view
       
   266                     iController.SetDemandKeyRelease( ETrue ); 
       
   267                     response = EKeyWasConsumed;
       
   268                 }
       
   269         
       
   270             }
       
   271         }
       
   272     else if ( aType == EEventKey && 
       
   273             aKeyEvent.iScanCode == EStdKeyBackspace )  // Handle 'C' key
       
   274         {
       
   275         iView.HandleCommandL( ECamCmdDelete );
       
   276         response = EKeyWasConsumed;
       
   277         }
       
   278     else if ( aKeyEvent.iScanCode == EStdKeyYes 
       
   279             && aType == EEventKey && !AknLayoutUtils::PenEnabled() ) 
       
   280         {
       
   281         iView.HandleCommandL( ECamCmdQuickSend );
       
   282         response = EKeyWasConsumed; 
       
   283         }        
       
   284     else 
       
   285         {
       
   286         PRINT( _L("Camera <> CCamBurstThumbnailContainer: offer key to grid control..") );
       
   287         response = iGridControl->OfferKeyEventL( aKeyEvent, aType );        
       
   288         }
       
   289 
       
   290     PRINT1( _L("Camera <= CCamBurstThumbnailContainer::OfferKeyEventL, return %d"), response );
       
   291     return response;
       
   292   }
       
   293 
       
   294 void CCamBurstThumbnailContainer::HandlePointerEventL( const TPointerEvent& aPointerEvent ) 
       
   295 	{
       
   296 	//CCoeControl::HandlePointerEventL( aPointerEvent );  
       
   297 	
       
   298 	PRINT3( _L("Camera => CCamBurstThumbnailContainer::HandlePointerEventL iType=%d iPosition=(%d, %d)"),
       
   299 	        aPointerEvent.iType,
       
   300 	        aPointerEvent.iPosition.iX,
       
   301 	        aPointerEvent.iPosition.iY );
       
   302 	    
       
   303 	
       
   304 	if ( aPointerEvent.iType == TPointerEvent::EButton1Up)
       
   305 		{
       
   306 		// check if the pointer event should be handled as grid selection
       
   307 		if ( iGridControl && iGridControl->Rect().Contains( aPointerEvent.iPosition ) )
       
   308 			{
       
   309 			TInt gridItem = iGridControl->HitTestGridItems( aPointerEvent.iPosition );
       
   310 			
       
   311 			if ( gridItem >= 0 )
       
   312 				{
       
   313 				
       
   314 				if ( iFeedback )
       
   315 				    {
       
   316 				    iFeedback->InstantFeedback( ETouchFeedbackBasic );        
       
   317 				    }
       
   318 				// inform model about the new higlighted item
       
   319 				if ( iGridModel.SetHighlight( gridItem ) )
       
   320 					{
       
   321 					// highlight changed -> redraw
       
   322 					DrawDeferred();
       
   323 					}	
       
   324 				else 
       
   325 					{
       
   326 					// highlight item did not change -> open item in postcapture view
       
   327 					iView.HandleCommandL( EAknSoftkeySelect );
       
   328 					}
       
   329 				}
       
   330 			}       
       
   331 	
       
   332 		}
       
   333 	        
       
   334 	
       
   335 	PRINT( _L("Camera <= CCamBurstThumbnailContainer::HandlePointerEventL"));
       
   336 	
       
   337 	}
       
   338 
       
   339 // End of File