camerauis/cameraapp/generic/src/CamBurstThumbnailContainer.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 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 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     switch ( aIndex )
       
   184         {
       
   185         case 0:
       
   186             {
       
   187             return iGridControl;
       
   188             }            
       
   189         default: 
       
   190             break;                   
       
   191         }
       
   192     
       
   193     // Should never get here
       
   194     return NULL;
       
   195     }
       
   196 
       
   197 
       
   198 // ---------------------------------------------------------
       
   199 // CCamBurstThumbnailContainer::Draw
       
   200 // Draw control
       
   201 // ---------------------------------------------------------
       
   202 //
       
   203 void CCamBurstThumbnailContainer::Draw( const TRect& aRect ) const
       
   204     {
       
   205     
       
   206     CWindowGc& gc = SystemGc();
       
   207         
       
   208     // Draw skin background for the 
       
   209     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   210     MAknsControlContext* cc = AknsDrawUtils::ControlContext( this );
       
   211     AknsDrawUtils::Background( skin, cc, gc, aRect );
       
   212     
       
   213     //gc.Clear( Rect() );
       
   214     
       
   215     }
       
   216 
       
   217 // ----------------------------------------------------
       
   218 // CCamBurstThumbnailContainer::OfferKeyEventL
       
   219 // Handles this application view's command keys. Forwards other
       
   220 // keys to child control(s).
       
   221 // ----------------------------------------------------
       
   222 //
       
   223 TKeyResponse 
       
   224 CCamBurstThumbnailContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent,
       
   225                                                    TEventCode aType )
       
   226     {
       
   227     PRINT( _L("Camera => CCamBurstThumbnailContainer::OfferKeyEventL") );
       
   228     TKeyResponse response( EKeyWasNotConsumed );
       
   229     TBool captureKey = IsCaptureKeyL( aKeyEvent, aType );
       
   230 
       
   231     TBool embedded = static_cast<CCamAppUiBase*>( 
       
   232             CEikonEnv::Static()->AppUi() )->IsEmbedded();
       
   233 
       
   234     // If the back softkey is pressed
       
   235     if ( aKeyEvent.iScanCode == EStdKeyDevice1 )
       
   236         {
       
   237         response = EKeyWasNotConsumed; // indicate key press was not processed
       
   238         }
       
   239     else if ( aKeyEvent.iScanCode == EStdKeyDevice3 )   // Select key
       
   240         {
       
   241         // Will pass it on to the view
       
   242         response = CCamContainerBase::OfferKeyEventL( aKeyEvent, aType );
       
   243         }
       
   244     //make sure to unset DemandKeyRelease
       
   245     else if( aType == EEventKeyUp && !embedded )
       
   246         {
       
   247         iController.SetDemandKeyRelease( EFalse ); 
       
   248         }    
       
   249     else if ( captureKey // && aKeyEvent.iScanCode == EProductKeyCapture )
       
   250             || IsShutterKeyL( aKeyEvent, aType )
       
   251             )
       
   252         {
       
   253         if ( aType == EEventKeyDown ) 
       
   254             // check needed, since EEventFocusLost produces EEventKeyUp for shutterkey
       
   255             {
       
   256             if ( !embedded )
       
   257                 {
       
   258                     iGridModel.CancelThumbnails();
       
   259     
       
   260                     iView.HandleCommandL( ECamCmdNewPhoto );
       
   261                     // Demand to relese capture key in pre capture view
       
   262                     iController.SetDemandKeyRelease( ETrue ); 
       
   263                     response = EKeyWasConsumed;
       
   264                 }
       
   265         
       
   266             }
       
   267         }
       
   268     else if ( aType == EEventKey && 
       
   269             aKeyEvent.iScanCode == EStdKeyBackspace )  // Handle 'C' key
       
   270         {
       
   271         iView.HandleCommandL( ECamCmdDelete );
       
   272         response = EKeyWasConsumed;
       
   273         }
       
   274     else if ( aKeyEvent.iScanCode == EStdKeyYes 
       
   275             && aType == EEventKey && !AknLayoutUtils::PenEnabled() ) 
       
   276         {
       
   277         iView.HandleCommandL( ECamCmdQuickSend );
       
   278         response = EKeyWasConsumed; 
       
   279         }        
       
   280     else 
       
   281         {
       
   282         PRINT( _L("Camera <> CCamBurstThumbnailContainer: offer key to grid control..") );
       
   283         response = iGridControl->OfferKeyEventL( aKeyEvent, aType );        
       
   284         }
       
   285 
       
   286     PRINT1( _L("Camera <= CCamBurstThumbnailContainer::OfferKeyEventL, return %d"), response );
       
   287     return response;
       
   288   }
       
   289 
       
   290 void CCamBurstThumbnailContainer::HandlePointerEventL( const TPointerEvent& aPointerEvent ) 
       
   291 	{
       
   292 	//CCoeControl::HandlePointerEventL( aPointerEvent );  
       
   293 	
       
   294 	PRINT3( _L("Camera => CCamBurstThumbnailContainer::HandlePointerEventL iType=%d iPosition=(%d, %d)"),
       
   295 	        aPointerEvent.iType,
       
   296 	        aPointerEvent.iPosition.iX,
       
   297 	        aPointerEvent.iPosition.iY );
       
   298 	    
       
   299 	
       
   300 	if ( aPointerEvent.iType == TPointerEvent::EButton1Up)
       
   301 		{
       
   302 		// check if the pointer event should be handled as grid selection
       
   303 		if ( iGridControl && iGridControl->Rect().Contains( aPointerEvent.iPosition ) )
       
   304 			{
       
   305 			TInt gridItem = iGridControl->HitTestGridItems( aPointerEvent.iPosition );
       
   306 			
       
   307 			if ( gridItem >= 0 )
       
   308 				{
       
   309 				
       
   310 				if ( iFeedback )
       
   311 				    {
       
   312 				    iFeedback->InstantFeedback( ETouchFeedbackBasic );        
       
   313 				    }
       
   314 				// inform model about the new higlighted item
       
   315 				if ( iGridModel.SetHighlight( gridItem ) )
       
   316 					{
       
   317 					// highlight changed -> redraw
       
   318 					DrawDeferred();
       
   319 					}	
       
   320 				else 
       
   321 					{
       
   322 					// highlight item did not change -> open item in postcapture view
       
   323 					iView.HandleCommandL( EAknSoftkeySelect );
       
   324 					}
       
   325 				}
       
   326 			}       
       
   327 	
       
   328 		}
       
   329 	        
       
   330 	
       
   331 	PRINT( _L("Camera <= CCamBurstThumbnailContainer::HandlePointerEventL"));
       
   332 	
       
   333 	}
       
   334 
       
   335 // End of File