camerauis/cameraapp/generic/src/CamZoomModel.cpp
branchRCL_3
changeset 54 bac7acad7cb3
equal deleted inserted replaced
53:61bc0f252b2b 54: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:  Controls the state of the zoom*
       
    15 */
       
    16 
       
    17 
       
    18 // Defining this will reduce the wait period between repeated
       
    19 // zoom in/out events being sent.  This is just a development
       
    20 // test feature.
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include    "CamZoomModel.h"
       
    24 #include    "CamZoomPane.h"
       
    25 #include    "CamPSI.h"
       
    26 #include    "CamUtility.h"
       
    27 #include    "CamAppUi.h"
       
    28 
       
    29 // CONSTANTS
       
    30 
       
    31 // MACROS
       
    32 
       
    33 // LOCAL CONSTANTS AND MACROS
       
    34 
       
    35 // MODULE DATA STRUCTURES
       
    36 
       
    37 // LOCAL FUNCTION PROTOTYPES
       
    38 
       
    39 // FORWARD DECLARATIONS
       
    40 
       
    41 // ============================ MEMBER FUNCTIONS ===============================
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CCamZoomModel::CCamZoomModel
       
    45 // C++ default constructor can NOT contain any code, that
       
    46 // might leave.
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CCamZoomModel::CCamZoomModel( CCamAppController& aController, 
       
    50                               CCamZoomPane*      aPane ) 
       
    51   : iCurrentResolution( KErrNotReady ),
       
    52     iController( aController ),
       
    53     iPane( aPane )
       
    54   {
       
    55   }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CCamZoomModel::ConstructL
       
    59 // Symbian 2nd phase constructor can leave.
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 void CCamZoomModel::ConstructL()
       
    63     {    
       
    64     PRINT( _L( "Camera => CCamZoomModel::ConstructL " ) );
       
    65     
       
    66     // Retrieve the max digital zoom levels
       
    67     TPckgBuf <TCamMaxZoomSteps> pckg;
       
    68     CamUtility::GetPsiAnyL( ECamPsiMaxZoomSteps, &pckg );
       
    69     iDigZoomSteps = pckg();
       
    70 
       
    71     // Retrieve the max EXTENDED zoom levels
       
    72     TPckgBuf <TCamMaxZoomSteps> pckg2;
       
    73     CamUtility::GetPsiAnyL( ECamPsiMaxExtendedZoomSteps, &pckg2 );
       
    74     iExtZoomSteps = pckg2();
       
    75         
       
    76     // Retrieve the max OPTICAL zoom levels
       
    77     TPckgBuf <TCamMaxZoomSteps> pckg3;
       
    78     CamUtility::GetPsiAnyL( ECamPsiMaxOpticalZoomSteps, &pckg3 );
       
    79     iOptZoomSteps = pckg3();
       
    80 
       
    81     // Retrieve the timing and step values for each of the zoom bar 
       
    82     // modes for Optical/Digital/Extended    
       
    83     TPckgBuf <TCamZoomLAF> pckg4;
       
    84     CamUtility::GetPsiAnyL( ECamPsiZoomBarLAF, &pckg4);
       
    85     iZoomLAF = pckg4();
       
    86     
       
    87     // Setting up initial internal values for zoom levels
       
    88     iCurZoomStepOptical = 0;
       
    89     iCurZoomStepDigital = 0;        
       
    90 
       
    91     // Default zoom jump multiplier
       
    92     iZoomStepMultiplier = 1;
       
    93 
       
    94     // Timer used to give smooth zooming    
       
    95     iZoomTimer = CPeriodic::NewL( CActive::EPriorityHigh );          
       
    96     
       
    97     // Register for controller events
       
    98     iController.AddControllerObserverL( this );
       
    99     
       
   100     // Create Zoom Update manager, which is used to 
       
   101     // minimize the amount of times we send updates to
       
   102     // the camera driver.
       
   103     iCamZoomUpdateManager = CCamZoomUpdateManager::NewL( iController );
       
   104     
       
   105     // This class and zoom pane are created on application start.
       
   106     // On app start, we should be setting the zoom to 1x, to 
       
   107     // tidy up incase a previous app has not reset to defaults.
       
   108     ResetZoomTo1x();
       
   109     
       
   110     PRINT( _L( "Camera <= CCamZoomModel::ConstructL " ) );
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CCamZoomModel::NewL
       
   115 // Two-phased constructor.
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 CCamZoomModel* CCamZoomModel::NewL( CCamAppController& aController, CCamZoomPane* aPane )
       
   119     {
       
   120     CCamZoomModel* self = new( ELeave ) CCamZoomModel( aController, aPane );
       
   121     
       
   122     CleanupStack::PushL( self );
       
   123     self->ConstructL();
       
   124     CleanupStack::Pop();
       
   125 
       
   126     return self;
       
   127     }
       
   128 
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // CCamZoomModel::~CCamZoomModel
       
   132 // Destructor.
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 CCamZoomModel::~CCamZoomModel()
       
   136   {
       
   137   PRINT( _L("Camera => ~CCamZoomModel" ))  
       
   138   
       
   139   iController.RemoveControllerObserver( this );
       
   140   if ( iZoomTimer && iZoomTimer->IsActive() )
       
   141     {    
       
   142     iZoomTimer->Cancel();
       
   143     }
       
   144   delete iZoomTimer;    
       
   145   
       
   146   if ( iCamZoomUpdateManager && iCamZoomUpdateManager->IsActive() )
       
   147     {    
       
   148     iCamZoomUpdateManager->Cancel();
       
   149     }
       
   150   delete iCamZoomUpdateManager;    
       
   151     
       
   152   iPane = NULL;   // Not owned
       
   153   PRINT( _L("Camera <= ~CCamZoomModel" ))  
       
   154   }
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // CCamZoomModel::ZoomTo
       
   158 // Attempts to zoom to a specified value.
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 void CCamZoomModel::ZoomTo( TInt aValue )
       
   162     {    
       
   163     PRINT( _L( "Camera => CCamZoomModel::ZoomTo " ) );
       
   164     // Note: The following code only supports digital or 
       
   165     // digital+extended zoom combinations.  
       
   166     // Optical zoom is not taken into consideration.
       
   167     
       
   168     // avoid mixups between button and touch presses
       
   169     if ( ZoomingState() != ECamZoomModelStateZoomNone )
       
   170         {
       
   171         PRINT( _L( "Camera <> CCamZoomModel::ZoomTo stopping keypress zoom" ) );
       
   172         StopZoom();
       
   173         }
       
   174     
       
   175     // Start the zoom state
       
   176     iState = ECamZoomModelStateZoomTo;
       
   177     
       
   178     // We don't support pausing between boundaries.  If the 
       
   179     // user experience so requires, it should be implemented here.
       
   180      
       
   181     // Update the zoom values
       
   182     // Note: Both digital and extended zoom are represented by iCurZoomStepDigital.
       
   183     // We assume the maximum value is already checked 
       
   184     // in CCamZoomPane::StartTouchZoomL
       
   185     PRINT1( _L( "Camera <> CCamZoomModel::ZoomTo iMaxZoomStepDig=%d" ), iMaxZoomStepDig ); 
       
   186     PRINT1( _L( "Camera <> CCamZoomModel::ZoomTo iMaxZoomStepExt=%d" ), iMaxZoomStepExt ); 
       
   187     PRINT1( _L( "Camera <> CCamZoomModel::ZoomTo iCurZoomStepDigital=%d" ), iCurZoomStepDigital ); 
       
   188     iCurZoomStepDigital = aValue;
       
   189     if ( iCurZoomStepDigital < iMaxZoomStepDig )
       
   190         {
       
   191         CheckZoomMode( ECamZoomModeExtended );
       
   192         }
       
   193     else
       
   194         {
       
   195         CheckZoomMode( ECamZoomModeDigital );
       
   196         }
       
   197             
       
   198     // Notify the camera driver
       
   199     PRINT1( _L( "Camera <> CCamZoomModel::ZoomTo to (aValue) %d" ), aValue );
       
   200     iCamZoomUpdateManager->SetZoomValue( iCurZoomStepDigital );
       
   201     
       
   202     // Tell the zoom pane the value to show.
       
   203     PRINT1( _L( "CCamZoomModel::ZoomTo set zoom pane %d" ), CurrentZoom() );
       
   204     iPane->SetZoomValue( CurrentZoom() );
       
   205         
       
   206     // Clear the zoom state
       
   207     iState = ECamZoomModelStateZoomNone; 
       
   208                     
       
   209     PRINT( _L( "Camera <= CCamZoomModel::ZoomTo " ) );
       
   210     }
       
   211     
       
   212 // -----------------------------------------------------------------------------
       
   213 // CCamZoomModel::ZoomIn
       
   214 // Attempts to zoom in one step (if one more step available).
       
   215 // -----------------------------------------------------------------------------
       
   216 //
       
   217 void CCamZoomModel::ZoomIn( TBool aOneClick )
       
   218     {    
       
   219     PRINT( _L( "Camera => CCamZoomModel::ZoomIn " ) );
       
   220     iState = ECamZoomModelStateZoomIn;
       
   221     TInt optZoomJump = 0;
       
   222     TInt digZoomJump = 0;    
       
   223     TInt extZoomJump = 0;
       
   224     
       
   225     ZoomStepsToJump( optZoomJump, digZoomJump, extZoomJump );
       
   226     PRINT3( _L( "CCamZoomModel::ZoomIn steps opt(%d) dig(%d) ext(%d) " ), optZoomJump, digZoomJump, extZoomJump );
       
   227     
       
   228     // First of all, check what the current boundary condition is
       
   229     // then check if we need to pause at that boundary.
       
   230     PRINT( _L( "ZoomIn boundary check start" ) );
       
   231     
       
   232     TCamZoomBoundary boundary = CheckBoundary();
       
   233     if ( PauseAtBoundary( boundary ) )
       
   234         {        
       
   235         if ( iPauseState == EPauseStateNone )
       
   236             {
       
   237             PRINT( _L( "ZoomIn at boundary EPauseStateNone return" ) );
       
   238             // If this is a new pause, update the state and return
       
   239             // (no zoom allowed until release)
       
   240             iPauseState = EPauseStatePaused;
       
   241             return;
       
   242             }
       
   243         else if ( iPauseState == EPauseStatePaused )
       
   244             {
       
   245             PRINT( _L( "ZoomIn at boundary EPauseStatePaused return" ) );
       
   246             // If still paused, return (no zoom allowed until release)
       
   247             return;
       
   248             }
       
   249         else // EPauseStateReleased
       
   250             {
       
   251             PRINT( _L( "ZoomIn at boundary EPauseStateReleased allow" ) );
       
   252             // If released, allow the zoom, but set the state
       
   253             // back to none.  
       
   254             iPauseState = EPauseStateNone;
       
   255             }
       
   256         }
       
   257         
       
   258     PRINT( _L( "ZoomIn at boundary EPauseStateNone boundary check end" ) );
       
   259         
       
   260     if ( optZoomJump )        
       
   261         {
       
   262         CheckZoomMode( ECamZoomModeOptical );
       
   263         iCurZoomStepOptical += optZoomJump;
       
   264         PRINT1( _L( "Camera => CCamZoomModel::ZoomIn opt to %d" ), iCurZoomStepOptical );
       
   265         //iController.SetZoomValue( iCurZoomStepOptical );            
       
   266         iCamZoomUpdateManager->SetZoomValue( iCurZoomStepOptical );
       
   267         }
       
   268         
       
   269     if ( digZoomJump )        
       
   270         {
       
   271         CheckZoomMode( ECamZoomModeDigital );
       
   272         iCurZoomStepDigital += digZoomJump;
       
   273         PRINT1( _L( "Camera => CCamZoomModel::ZoomIn dig to %d" ), iCurZoomStepDigital );
       
   274         //iController.SetZoomValue( iCurZoomStepDigital );              
       
   275         iCamZoomUpdateManager->SetZoomValue( iCurZoomStepDigital );
       
   276         }
       
   277         
       
   278     if ( extZoomJump )
       
   279         {
       
   280         CheckZoomMode( ECamZoomModeExtended );
       
   281         iCurZoomStepDigital += extZoomJump;
       
   282         PRINT1( _L( "Camera => CCamZoomModel::ZoomIn ext to %d" ), iCurZoomStepDigital );
       
   283         //iController.SetZoomValue( iCurZoomStepDigital );              
       
   284         iCamZoomUpdateManager->SetZoomValue( iCurZoomStepDigital );
       
   285         }
       
   286 
       
   287     // Tell the zoom pane the value to show.
       
   288     PRINT1( _L( "CCamZoomModel::ZoomIn set zoom pane %d" ), CurrentZoom() );
       
   289     iPane->SetZoomValue( CurrentZoom() );
       
   290                     
       
   291     if ( aOneClick )
       
   292         {
       
   293         // Do not start zoom timer
       
   294         PRINT( _L( "CCamZoomModel::ZoomIn one click" ) );
       
   295         iState = ECamZoomModelStateZoomNone;
       
   296         }
       
   297     else
       
   298         {
       
   299         // Don't restart timer (Auto-stop) timer when no zoom was done
       
   300         if( optZoomJump || digZoomJump || extZoomJump )
       
   301             {
       
   302             // Start the timer to zoom-in again when timer expires
       
   303             PRINT( _L( "CCamZoomModel::ZoomIn start zoom timer" ) );
       
   304             StartZoomTimer();
       
   305             }
       
   306         else
       
   307             {
       
   308             PRINT( _L("Camera <> CCamZoomModel::ZoomOut - stopping zoom at boundary") );
       
   309             StopZoom();
       
   310             }
       
   311         }
       
   312     
       
   313     PRINT( _L( "Camera <= CCamZoomModel::ZoomIn " ) );
       
   314     }
       
   315 
       
   316 // ---------------------------------------------------------------------------
       
   317 // CCamZoomModel::CheckBoundary
       
   318 // Checks whether the next zoom operation will cross a zoom mode boundary.
       
   319 // For example from Optical to Digital or from Digital to Extended
       
   320 // ---------------------------------------------------------------------------
       
   321 //    
       
   322 CCamZoomModel::TCamZoomBoundary CCamZoomModel::CheckBoundary() const
       
   323     {
       
   324     PRINT( _L( "Camera => CCamZoomModel::CheckBoundary " ) );
       
   325     
       
   326     TCamZoomBoundary retVal = ECamZoomBoundaryNone;        
       
   327     
       
   328     TCamZoomMode modeBefore = CurrentZoomType();
       
   329     TCamZoomMode modeAfter  = CurrentZoomType( ZoomStepsToJump() );
       
   330     
       
   331     if ( modeBefore != modeAfter )
       
   332         {
       
   333         if ( modeBefore == ECamZoomModeOptical && modeAfter  == ECamZoomModeDigital ||
       
   334              modeBefore == ECamZoomModeDigital && modeAfter  == ECamZoomModeOptical )
       
   335             {
       
   336             PRINT( _L( "Camera <> CCamZoomModel::CheckBoundary ECamZoomBoundaryOptDig" ) );
       
   337             retVal = ECamZoomBoundaryOptDig;
       
   338             }
       
   339         else if ( modeBefore == ECamZoomModeExtended && modeAfter  == ECamZoomModeDigital ||
       
   340                   modeBefore == ECamZoomModeDigital && modeAfter  == ECamZoomModeExtended )
       
   341             {
       
   342             PRINT( _L( "Camera <> CCamZoomModel::CheckBoundary ECamZoomBoundaryDigExt" ) );
       
   343             retVal = ECamZoomBoundaryDigExt;
       
   344             }        
       
   345         else
       
   346             {
       
   347             // Undefined boundary, should not allow further zooming
       
   348             PRINT( _L( "Camera <> CCamZoomModel::CheckBoundary ECamZoomBoundaryUndefined" ) );
       
   349             retVal = ECamZoomBoundaryUndefined;
       
   350             }
       
   351         }
       
   352      else
       
   353         {
       
   354         PRINT( _L( "Camera <> CCamZoomModel::CheckBoundary ECamZoomBoundaryNone" ) );
       
   355         retVal = ECamZoomBoundaryNone;
       
   356         }
       
   357     
       
   358     PRINT( _L( "Camera <= CCamZoomModel::CheckBoundary " ) );
       
   359     return retVal;   
       
   360     }
       
   361     
       
   362     
       
   363 // ---------------------------------------------------------------------------
       
   364 // CCamZoomModel::ZoomStepsToJump
       
   365 // Returns the total number of zoom steps to jump based on the current 
       
   366 // zoom mode (opt/dig/ext). Does not break these steps into optical/digital
       
   367 // steps to jump, as may be the case on a boundary.
       
   368 // ---------------------------------------------------------------------------
       
   369 //      
       
   370 TInt CCamZoomModel::ZoomStepsToJump() const
       
   371     {      
       
   372     PRINT( _L( "Camera => CCamZoomModel::ZoomStepsToJump " ) );
       
   373     
       
   374     TInt steps = 0;
       
   375     
       
   376     if ( iController.ActiveCamera() == ECamActiveCameraPrimary )    
       
   377         {            
       
   378         // Works out the current zoom mode (opt/dig/ext)
       
   379         TCamZoomMode mode = CurrentZoomType();    
       
   380         PRINT1( _L( "Camera <> CCamZoomModel::ZoomStepsToJump mode = %d" ), mode );
       
   381         
       
   382         if ( mode == ECamZoomModeOptical )
       
   383             {        
       
   384             steps = iZoomLAF.iZoomStepsOpt;
       
   385             PRINT1( _L( "Camera <> CCamZoomModel::ZoomStepsToJump ECamZoomModeOptical steps = %d" ), steps );
       
   386             }
       
   387         else if ( mode == ECamZoomModeDigital )
       
   388             {
       
   389             steps = iZoomLAF.iZoomStepsDig;
       
   390             PRINT1( _L( "Camera <> CCamZoomModel::ZoomStepsToJump ECamZoomModeDigital steps = %d" ), steps );
       
   391             }
       
   392         else if ( mode == ECamZoomModeExtended )    
       
   393             {
       
   394             steps = iZoomLAF.iZoomStepsExt;
       
   395             PRINT1( _L( "Camera <> CCamZoomModel::ZoomStepsToJump ECamZoomModeExtended steps = %d" ), steps );
       
   396             }    
       
   397         else
       
   398             {
       
   399             steps = 0;            
       
   400             }   
       
   401         }
       
   402     else if ( iController.ActiveCamera() == ECamActiveCameraSecondary )
       
   403         {
       
   404         //steps = K2ndCamZoomStepSize;
       
   405         steps = iZoomLAF.iSecondCameraZoomSteps;
       
   406         PRINT1( _L( "Camera <> CCamZoomModel::ZoomStepsToJump K2ndCamZoomStepSize steps = %d" ), steps );
       
   407         }
       
   408     else
       
   409         {            
       
   410         }
       
   411         
       
   412         
       
   413     if ( iState == ECamZoomModelStateZoomOut )        
       
   414         {
       
   415         steps = -steps;    
       
   416         PRINT1( _L( "Camera <> CCamZoomModel::ZoomStepsToJump Inverse, since ZoomOut: steps = %d" ), steps );
       
   417         }
       
   418         
       
   419     PRINT( _L( "Camera <= CCamZoomModel::ZoomStepsToJump " ) );
       
   420     return steps;                           
       
   421     }
       
   422 
       
   423 // ---------------------------------------------------------------------------
       
   424 // CCamZoomModel::ZoomStepsToJump
       
   425 // Returns the number of Optical, Digital and Extended zoom steps to jump
       
   426 // ---------------------------------------------------------------------------
       
   427 //  
       
   428 void CCamZoomModel::ZoomStepsToJump( TInt& aOpt, TInt& aDig, TInt& aExt ) const
       
   429     {  
       
   430     PRINT( _L( "Camera => CCamZoomModel::ZoomStepsToJump (by reference)" ) );
       
   431     
       
   432     TInt steps = iZoomStepMultiplier * ZoomStepsToJump();
       
   433 
       
   434     TCamZoomBoundary boundary = CheckBoundary();
       
   435     
       
   436     // If jumping this number of steps will make us cross the boundary, 
       
   437     // we need to split the steps up into the composite opt/dig steps.
       
   438     // Depending on if we are pausing or not, we may not want to cross
       
   439     // the boundary yet
       
   440     if ( boundary == ECamZoomBoundaryOptDig )
       
   441         {
       
   442         if ( iState == ECamZoomModelStateZoomIn )
       
   443             {
       
   444             // Zooming in, then assign what we can to Optical, to get to max step
       
   445             // any remainder then goes to digital
       
   446             TInt optJumpMax = iMaxZoomStepOpt - iCurZoomStepOptical;
       
   447             aOpt = optJumpMax;
       
   448             aDig = steps - optJumpMax;
       
   449             
       
   450             // If the zoom in was going to take the digital zoom beyond the max
       
   451             // allowed, clip it
       
   452             if ( aDig > iMaxZoomStepDig )
       
   453                 aDig = iMaxZoomStepDig;
       
   454             }
       
   455         else if ( iState == ECamZoomModelStateZoomOut )        
       
   456             {
       
   457             // Zooming out, then assign what we can to Digital, to get to min step
       
   458             // any remainder then goes to optical            
       
   459             aDig = -iCurZoomStepDigital;                
       
   460             aOpt = steps + iCurZoomStepDigital; // zooming out, steps is -ve
       
   461             }
       
   462 		else
       
   463 			{
       
   464 			// Lint
       
   465 			}
       
   466         }
       
   467     else if ( boundary == ECamZoomBoundaryDigExt )
       
   468         {
       
   469         if ( iState == ECamZoomModelStateZoomIn )
       
   470             {
       
   471             // Zooming in, then assign what we can to Optical, to get to max step
       
   472             // any remainder then goes to digital
       
   473             TInt digJumpMax = iMaxZoomStepDig - iCurZoomStepDigital;
       
   474             aDig = digJumpMax;
       
   475             aExt = steps - digJumpMax;
       
   476             
       
   477             // If the zoom in was going to take the digital zoom beyond the max
       
   478             // allowed, clip it
       
   479             if ( aExt > iMaxZoomStepExt )
       
   480                 aExt = iMaxZoomStepExt;            
       
   481             }
       
   482         else if ( iState == ECamZoomModelStateZoomOut )        
       
   483             {
       
   484             // Zooming out, then assign what we can to Digital, to get to min step
       
   485             // any remainder then goes to optical            
       
   486             //aDig = iCurZoomStepDigital;
       
   487             aDig = steps;
       
   488             //aExt = steps - iCurZoomStepDigital;                            
       
   489             }
       
   490         else
       
   491         	{
       
   492         	// Lint
       
   493         	}
       
   494         }        
       
   495     else if ( boundary == ECamZoomBoundaryNone )
       
   496         {
       
   497         // No boundary crossed.  Can assign the steps to the current
       
   498         // mode        
       
   499         TCamZoomMode mode = CurrentZoomType();
       
   500         
       
   501         if ( iState == ECamZoomModelStateZoomIn )
       
   502             {           
       
   503             if ( mode == ECamZoomModeOptical && AllowOptZoom() )
       
   504                 {
       
   505                 aOpt = steps;
       
   506                 if ( iCurZoomStepOptical + aOpt > iMaxZoomStepOpt )
       
   507                     {
       
   508                     aOpt = iMaxZoomStepOpt - iCurZoomStepOptical;                            
       
   509                     }                    
       
   510                 }
       
   511             else if ( mode == ECamZoomModeDigital && AllowDigZoom() )
       
   512                 {
       
   513                 aDig = steps;    
       
   514                 if ( iCurZoomStepDigital + aDig > iMaxZoomStepDig )
       
   515                     {
       
   516                     aDig = iMaxZoomStepDig - iCurZoomStepDigital;                
       
   517                     }                    
       
   518                 }
       
   519             else if ( mode == ECamZoomModeExtended && AllowExtZoom() )
       
   520                 {
       
   521                 aExt = steps;                        
       
   522                 if ( iCurZoomStepDigital + aExt > iMaxZoomStepExt )
       
   523                     {
       
   524                     aExt = iMaxZoomStepExt - iCurZoomStepDigital;    
       
   525                     }                    
       
   526                 }               
       
   527             else
       
   528                 {
       
   529                 // Do nothing (as invalid state)
       
   530                 }                                             
       
   531             }
       
   532         else if ( iState == ECamZoomModelStateZoomOut ) 
       
   533             {                
       
   534             if ( mode == ECamZoomModeOptical && AllowOptZoom() )
       
   535                 {
       
   536                 aOpt = steps;
       
   537                 if ( iCurZoomStepOptical + aOpt < 0 )
       
   538                     {
       
   539                     aOpt = -iCurZoomStepOptical;                            
       
   540                     }                    
       
   541                 }
       
   542             else if ( mode == ECamZoomModeDigital && AllowDigZoom() )
       
   543                 {
       
   544                 aDig = steps;    
       
   545                 if ( iCurZoomStepDigital + aDig < 0 )
       
   546                     {
       
   547                     aDig = -iCurZoomStepDigital;                
       
   548                     }                    
       
   549                 }
       
   550             else if ( mode == ECamZoomModeExtended && AllowExtZoom() )
       
   551                 {
       
   552                 aExt = steps;                        
       
   553                 if ( iCurZoomStepDigital + aExt < iMaxZoomStepDig )
       
   554 					{
       
   555                     aExt = iMaxZoomStepDig - iCurZoomStepDigital;
       
   556 					}
       
   557                 }        
       
   558             else
       
   559                 {
       
   560                 // Do nothing (as invalid state)
       
   561                 }                        
       
   562             }
       
   563 		else
       
   564 			{
       
   565 			// Lint
       
   566 			}            
       
   567         }       
       
   568     else // ECamZoomBoundaryUndefined
       
   569         {
       
   570         // If undefined boundary, this would result in an invalid
       
   571         // zoom valid if we zoom, so set all steps to zero.        
       
   572         // This will stop any zoom operation from changing state.
       
   573         aOpt = 0;
       
   574         aDig = 0;
       
   575         aExt = 0;
       
   576         }
       
   577         
       
   578     PRINT( _L( "Camera <= CCamZoomModel::ZoomStepsToJump " ) );
       
   579     }
       
   580     
       
   581     
       
   582 // ---------------------------------------------------------------------------
       
   583 // CCamZoomModel::CurrentZoomType
       
   584 // Returns the zoom type (opt/dig/ext) based on current zoom levels modified
       
   585 // by the specified optical/digital valies
       
   586 // ---------------------------------------------------------------------------
       
   587 //   
       
   588 TCamZoomMode CCamZoomModel::CurrentZoomType( TInt aStepModifier ) const
       
   589     {
       
   590     PRINT( _L( "Camera => CCamZoomModel::CurrentZoomType " ) );
       
   591     
       
   592     TInt maxOptZoomStep = ( iMaxZoomStepOpt == KErrNotSupported || !AllowOptZoom() )? 0 : iMaxZoomStepOpt;
       
   593     TInt maxStdZoomStep = ( iMaxZoomStepDig == KErrNotSupported || !AllowDigZoom() )? maxOptZoomStep : maxOptZoomStep + iMaxZoomStepDig;
       
   594     TInt maxExtZoomStep = ( iMaxZoomStepExt == KErrNotSupported || !AllowExtZoom() )? maxStdZoomStep : maxStdZoomStep + iMaxZoomStepExt;   
       
   595     
       
   596     // 
       
   597     TInt step = CurrentZoom() + aStepModifier;    
       
   598         
       
   599     // Optical runs from step 0 to maxOptZoomStep
       
   600     if ( step <= maxOptZoomStep && // Not at max opt zoom level        
       
   601          AllowOptZoom() )          // ... and optical zoom is allowed        
       
   602         {
       
   603         PRINT( _L( "Camera <= CCamZoomModel::CurrentZoomType ECamZoomModeOptical" ) );
       
   604         return ECamZoomModeOptical;
       
   605         }
       
   606     // Digital runs from maxOptZoomStep to maxOptZoomStep+maxStdZoomStep
       
   607     else if ( step >= maxOptZoomStep &&
       
   608               step <= maxStdZoomStep && // Inside std zoom step limits
       
   609               AllowDigZoom() )          // ...and is allowed by user setting
       
   610         {
       
   611         PRINT( _L( "Camera <= CCamZoomModel::CurrentZoomType ECamZoomModeDigital" ) );
       
   612         return ECamZoomModeDigital;
       
   613         }
       
   614     // Extended runs from maxOptZoomStep+maxStdZoomStep to maxOptZoomStep+maxStdZoomStep        
       
   615     else if ( step >= maxStdZoomStep &&
       
   616               step <= maxExtZoomStep &&   // Inside ext zoom step limits
       
   617               AllowExtZoom() )            // ...and ext zoom is allowed by user
       
   618         {
       
   619         PRINT( _L( "Camera <= CCamZoomModel::CurrentZoomType ECamZoomModeExtended" ) );
       
   620         return ECamZoomModeExtended;
       
   621         }
       
   622     else
       
   623         {
       
   624         PRINT( _L( "Camera <= CCamZoomModel::CurrentZoomType ECamZoomModeUndefined" ) );
       
   625         return ECamZoomModeUndefined;
       
   626         }                   
       
   627     }
       
   628 
       
   629 // -----------------------------------------------------------------------------
       
   630 // CCamZoomModel::ZoomOut
       
   631 // Attempts to zoom out one step (if one more step available).
       
   632 // -----------------------------------------------------------------------------
       
   633 //
       
   634 void CCamZoomModel::ZoomOut( TBool aOneClick )
       
   635     {        
       
   636     PRINT( _L( "Camera => CCamZoomModel::ZoomOut " ) );
       
   637     iState = ECamZoomModelStateZoomOut;
       
   638     TInt optZoomJump = 0;
       
   639     TInt digZoomJump = 0;    
       
   640     TInt extZoomJump = 0; 
       
   641     
       
   642     ZoomStepsToJump( optZoomJump, digZoomJump, extZoomJump );
       
   643     PRINT3( _L( "CCamZoomModel::ZoomOut steps opt(%d) dig(%d) ext(%d) " ), optZoomJump, digZoomJump, extZoomJump );
       
   644     
       
   645     if ( optZoomJump )        
       
   646         {
       
   647         CheckZoomMode( ECamZoomModeOptical );
       
   648         iCurZoomStepOptical += optZoomJump;
       
   649         PRINT1( _L( "Camera => CCamZoomModel::ZoomOut opt to %d" ), iCurZoomStepOptical );
       
   650         //iController.SetZoomValue( iCurZoomStepOptical );            
       
   651         iCamZoomUpdateManager->SetZoomValue( iCurZoomStepOptical );
       
   652         }
       
   653         
       
   654     if ( digZoomJump )        
       
   655         {
       
   656         CheckZoomMode( ECamZoomModeDigital );
       
   657         iCurZoomStepDigital += digZoomJump;
       
   658         PRINT1( _L( "Camera => CCamZoomModel::ZoomOut dig to %d" ), iCurZoomStepDigital );
       
   659         //iController.SetZoomValue( iCurZoomStepDigital );              
       
   660         iCamZoomUpdateManager->SetZoomValue( iCurZoomStepDigital );
       
   661         }
       
   662         
       
   663     if ( extZoomJump )
       
   664         {
       
   665         CheckZoomMode( ECamZoomModeExtended );
       
   666         iCurZoomStepDigital += extZoomJump;
       
   667         PRINT1( _L( "Camera => CCamZoomModel::ZoomOut ext to %d" ), iCurZoomStepDigital );
       
   668         //iController.SetZoomValue( iCurZoomStepDigital );           
       
   669         iCamZoomUpdateManager->SetZoomValue( iCurZoomStepDigital );   
       
   670         }    
       
   671 
       
   672     // Tell the zoom pane the value to show.
       
   673     PRINT1( _L( "ZoomOut set zoom pane %d" ), CurrentZoom() );
       
   674     iPane->SetZoomValue( CurrentZoom() );    
       
   675 
       
   676     if ( aOneClick )
       
   677         {
       
   678         // Do not start zoom timer
       
   679         PRINT( _L( "CCamZoomModel::ZoomIn one click" ) );
       
   680         iState = ECamZoomModelStateZoomNone;
       
   681         }
       
   682     else
       
   683         {
       
   684         // Don't restart timer (auto-stop) timer when no zoom was done
       
   685         if( optZoomJump || digZoomJump || extZoomJump )
       
   686             {
       
   687             // Start the timer to zoom-in again when timer expires
       
   688             PRINT( _L( "CCamZoomModel::ZoomIn start zoom timer" ) );
       
   689             StartZoomTimer();
       
   690             }
       
   691         else
       
   692             {
       
   693             PRINT( _L("Camera <> CCamZoomModel::ZoomOut - stopping zoom at boundary") );
       
   694             StopZoom();
       
   695             }
       
   696         }
       
   697     
       
   698     PRINT( _L( "Camera <= CCamZoomModel::ZoomOut " ) );
       
   699     }
       
   700 
       
   701 // -----------------------------------------------------------------------------
       
   702 // CCamZoomModel::CheckZoomMode
       
   703 // Checks to see if the zoom mode needs to be changed.
       
   704 // The purpose is to avoid unneccessary calls to SetZoomMode where possible
       
   705 // -----------------------------------------------------------------------------
       
   706 //
       
   707 void CCamZoomModel::CheckZoomMode( TCamZoomMode aMode )
       
   708   {
       
   709   PRINT( _L( "Camera => CCamZoomModel::CheckZoomMode " ) );
       
   710   if ( iZoomMode             != aMode 
       
   711     && ECamZoomModeUndefined != aMode )
       
   712     {
       
   713     //iController.SetZoomMode( aMode );
       
   714     PRINT2( _L( "Camera <> CCamZoomModel::CheckZoomMode iZoomMode changed (%d) -> (%d) " ), aMode, iZoomMode );
       
   715     iZoomMode = aMode;
       
   716     }
       
   717   PRINT( _L( "Camera <= CCamZoomModel::CheckZoomMode " ) );  
       
   718   }
       
   719 
       
   720 // -----------------------------------------------------------------------------
       
   721 // CCamZoomModel::RefreshSettings
       
   722 // Checks the current state of the Camera application, and adjusts the min/max
       
   723 // range of the zoom pane accordingly.
       
   724 // -----------------------------------------------------------------------------
       
   725 //
       
   726 void CCamZoomModel::RefreshSettings()
       
   727   {
       
   728   PRINT( _L("Camera => CCamZoomModel::RefreshSettings") );
       
   729   // If there is no active camera yet, or engine is not 
       
   730   // in a prepared state yet, do not try to refresh settings
       
   731   // as we can't work out what to base it on.
       
   732 
       
   733   // <CAMERAAPP_CAPI_V2_MIGRATION/>
       
   734   if( iController.ActiveCamera() == ECamActiveCameraNone 
       
   735    || !( iCameraState & (ECamImageOn|ECamVideoOn) ) 
       
   736     ) 
       
   737     {
       
   738     return;
       
   739     }        
       
   740 
       
   741   // Cache the current resolution to be used when 
       
   742   // determining zoom limits and steps.
       
   743   ReadCurrentResolution();      
       
   744 
       
   745   // Read settings to update internal state        
       
   746   ReadOpticalZoomSetting();
       
   747   ReadDigitalZoomSetting();
       
   748 
       
   749   iMaxZoomStepOpt = MaxZoomStep( iOptZoomSteps );
       
   750   iMaxZoomStepDig = MaxZoomStep( iDigZoomSteps );
       
   751   iMaxZoomStepExt = MaxZoomStep( iExtZoomSteps );
       
   752       
       
   753   iMaxZoomStep = 0;
       
   754 
       
   755   PRINT3( _L("Camera <> CCamZoomModel: max steps opt:%d dig:%d ext:%d"), iMaxZoomStepOpt, iMaxZoomStepDig, iMaxZoomStepExt );
       
   756 
       
   757   if ( AllowOptZoom() )
       
   758     {        
       
   759     iMaxZoomStep += iMaxZoomStepOpt;        
       
   760     }
       
   761     
       
   762   // Check if Digital zoom is allowed
       
   763   if ( AllowDigZoom() )
       
   764     {                
       
   765     // Check if EXTENDED zoom is allowed by user setting
       
   766     // and the value is valid.  For secondary camera, it may
       
   767     // be that it is not supported.
       
   768     if ( AllowExtZoom() ) // done in AllowExtZoom: && iMaxZoomStepExt != KErrNotSupported)
       
   769       {                                        
       
   770       iMaxZoomStep += iMaxZoomStepExt;        
       
   771       }
       
   772     else
       
   773       {            
       
   774       iMaxZoomStep += iMaxZoomStepDig;        
       
   775       }
       
   776     }
       
   777 
       
   778   TInt optSteps = ( AllowOptZoom() ) ? iMaxZoomStepOpt : 0; 
       
   779   TInt stdSteps = ( AllowDigZoom() ) ? iMaxZoomStepDig : 0;
       
   780   TInt extSteps = ( AllowExtZoom() ) ? Max( (iMaxZoomStepExt - iMaxZoomStepDig), 0 ) : 0;
       
   781           
       
   782   // Check that the max zoom is within (possibly new) limits
       
   783   CheckZoomLimit();
       
   784   
       
   785   if ( iPane )
       
   786     {
       
   787     // Inform the zoom pane of the new range of zoom steps
       
   788     iPane->SetZoomRange( 0, iMaxZoomStep ); 
       
   789     iPane->SetZoomSteps( optSteps, stdSteps, extSteps );        
       
   790     iPane->SetZoomValue( CurrentZoom() );
       
   791     }
       
   792 
       
   793   PRINT( _L("Camera <= CCamZoomModel::RefreshSettings") );
       
   794   }
       
   795     
       
   796     
       
   797 // -----------------------------------------------------------------------------
       
   798 // CCamZoomModel::ReadDigitalZoomSetting
       
   799 // Updates the setting for digital/extended zoom or not depending if user 
       
   800 // setting for it is on AND we have a valid setting for it.
       
   801 // -----------------------------------------------------------------------------
       
   802 //    
       
   803 void CCamZoomModel::ReadDigitalZoomSetting()
       
   804     {        
       
   805     iZoomSetting = static_cast<TCamSettingsDigitalZoom>(
       
   806         iController.IntegerSettingValue( ECamSettingItemPhotoDigitalZoom ) );    
       
   807     }
       
   808 
       
   809 
       
   810 
       
   811 // -----------------------------------------------------------------------------
       
   812 // CCamZoomModel::ReadOpticalZoomSetting
       
   813 // Reads whether optical zoom is allowed
       
   814 // -----------------------------------------------------------------------------
       
   815 //    
       
   816 void CCamZoomModel::ReadOpticalZoomSetting()
       
   817     {     
       
   818     }    
       
   819     
       
   820     
       
   821 // -----------------------------------------------------------------------------
       
   822 // CCamZoomModel::CheckZoomLimit
       
   823 // Checks whether the current zoom level is too great for the limits.
       
   824 // This can happen if the resolution is changed, as this may result in new limits
       
   825 // The zoom level should be cropped to where appropriate
       
   826 // -----------------------------------------------------------------------------
       
   827 //      
       
   828 void CCamZoomModel::CheckZoomLimit()
       
   829     {    
       
   830     TInt maxOptZoomStep = MaxZoomStep( iOptZoomSteps );
       
   831     TInt maxStdZoomStep = MaxZoomStep( iDigZoomSteps );
       
   832     TInt maxExtZoomStep = MaxZoomStep( iExtZoomSteps );
       
   833 
       
   834     if ( AllowOptZoom() &&                      // If settings allow optical zoom, 
       
   835          iCurZoomStepOptical > maxOptZoomStep ) // ...and value now too high
       
   836         {
       
   837         iCurZoomStepOptical = maxOptZoomStep;
       
   838         // iController.SetZoomMode ( ECamZoomModeOptical );
       
   839         iController.SetZoomValue( iCurZoomStepOptical );                                         
       
   840         }
       
   841 
       
   842     if ( AllowDigZoom()                        // If digital zoom is allowed
       
   843       && iCurZoomStepDigital > maxStdZoomStep  // and value now too high
       
   844       && !AllowExtZoom() )                     // and extended not allowed
       
   845         {
       
   846         // If we get here, digital zoom IS allowed, but extended isn't
       
   847         // and the digital zoom is too high.
       
   848         iCurZoomStepDigital = maxStdZoomStep;
       
   849         //iController.SetZoomMode ( ECamZoomModeDigital );
       
   850         iController.SetZoomValue( iCurZoomStepDigital );                                                        
       
   851         }
       
   852     else if ( AllowExtZoom()                         // If extended digitial zoom is allowed
       
   853            && iCurZoomStepDigital > maxExtZoomStep ) // but over the max extended range
       
   854         {        
       
   855         iCurZoomStepDigital = maxExtZoomStep;
       
   856         // iController.SetZoomMode ( ECamZoomModeDigital );
       
   857         iController.SetZoomValue( iCurZoomStepDigital );                                                                    
       
   858         }
       
   859     // otherwise, do nothing
       
   860     else
       
   861         {
       
   862         // empty statement to remove Lint error.
       
   863         }
       
   864         
       
   865     // If we have had to manually set the mode and value of zoom, 
       
   866     // make sure that the zoom mode is still set to what internal state
       
   867     // dictates it should be.    
       
   868 
       
   869     /*
       
   870     if ( iZoomMode == ECamZoomModeOptical )
       
   871         {
       
   872         iController.SetZoomMode( ECamZoomModeOptical );
       
   873         }
       
   874     else if ( iZoomMode == ECamZoomModeDigital ||
       
   875               iZoomMode == ECamZoomModeExtended )
       
   876         {
       
   877         iController.SetZoomMode( ECamZoomModeDigital );
       
   878         }            
       
   879     // otherwise, do nothing
       
   880     else
       
   881         {
       
   882         // empty statement to remove Lint error.
       
   883     */
       
   884     }
       
   885  
       
   886 // -----------------------------------------------------------------------------
       
   887 // CCamZoomModel::ResetZoomTo1x
       
   888 // Resets the zoom level to 1x.
       
   889 // -----------------------------------------------------------------------------
       
   890 //    
       
   891 void CCamZoomModel::ResetZoomTo1x()
       
   892   {
       
   893   PRINT( _L( "Camera => CCamZoomModel::ResetZoomTo1x " ) );
       
   894   // Recalculates the min/max values for the zoom pane and
       
   895   // forwards them to the control.
       
   896   RefreshSettings();        
       
   897   
       
   898   // Reset the actual values used by the engine
       
   899   iCurZoomStepOptical = 0;
       
   900   iCurZoomStepDigital = 0;
       
   901   
       
   902   iZoomMode = ECamZoomModeUndefined;
       
   903   
       
   904   // Only digital mode supported for now.        
       
   905   //iController.SetZoomMode( ECamZoomModeDigital );
       
   906   iController.SetZoomValue( iCurZoomStepDigital );                                
       
   907   if ( iPane )
       
   908     {
       
   909     iPane->SetZoomValue( 0 );
       
   910     iPane->MakeVisible( EFalse, EFalse );
       
   911     }
       
   912     
       
   913   PRINT( _L( "Camera <= CCamZoomModel::ResetZoomTo1x " ) );
       
   914   }        
       
   915         
       
   916 
       
   917 // -----------------------------------------------------------------------------
       
   918 // CCamZoomModel::MaxZoomStep
       
   919 // Returns the maximum zoom step for the supplied step array 
       
   920 // (optical/digital/extended), based on current camera state.
       
   921 // -----------------------------------------------------------------------------
       
   922 //
       
   923 TInt CCamZoomModel::MaxZoomStep( const TCamMaxZoomSteps& aStepArray ) const
       
   924     {        
       
   925     PRINT( _L( "Camera => CCamZoomModel::MaxZoomStep " ) );
       
   926     
       
   927     TInt maxStep = KErrNotSupported;
       
   928     if ( iCameraState & ECamImageOn )
       
   929         {                
       
   930         // TCamPhotoSizeId  sizeId = iController.GetCurrentImageResolution();
       
   931         TCamActiveCamera camera = iController.ActiveCamera();
       
   932         if ( ECamActiveCameraPrimary == camera )
       
   933             {
       
   934             // switch ( sizeId )
       
   935             switch ( iCurrentResolution )
       
   936                 {
       
   937                 case ECamPhotoSizeVGA:       // 640 x 480
       
   938                     maxStep = aStepArray.iMaxPhotoStepVGA;
       
   939                     break;
       
   940                 case ECamPhotoSizeXGA: 	// 0.8MegaPixel (1024 x 768 )
       
   941                     maxStep = aStepArray.iMaxPhotoStep0_8MP;
       
   942                     break;
       
   943                 case ECamPhotoSize1MP:
       
   944                     maxStep = aStepArray.iMaxPhotoStep1MP;
       
   945                     break;
       
   946                 case ECamPhotoSize1_3MP:     // 1280x960
       
   947                     maxStep = aStepArray.iMaxPhotoStep1_3MP;
       
   948                     break;
       
   949                 case ECamPhotoSize2MP:       // 1600x1200
       
   950                     maxStep = aStepArray.iMaxPhotoStep2MP;
       
   951                     break;
       
   952                 case ECamPhotoSize3MP:       // 
       
   953                     maxStep = aStepArray.iMaxPhotoStep3MP;
       
   954                     break;  
       
   955                 case ECamPhotoSize5MP:
       
   956                     maxStep = aStepArray.iMaxPhotoStep5MP;
       
   957                     break;
       
   958                 case ECamPhotoSize8MP:
       
   959                     maxStep = aStepArray.iMaxPhotoStep8MP;
       
   960                     break;                    
       
   961                 case ECamPhotoSize12MP:
       
   962                     maxStep = aStepArray.iMaxPhotoStep12MP;
       
   963                     break;
       
   964                 case ECamPhotoSizeW6MP: // 3264x1832
       
   965                     maxStep = aStepArray.iMaxPhotoStepW6MP;
       
   966                     break;                    
       
   967                 case ECamPhotoSizeW9MP: // 4000x2248
       
   968                     maxStep = aStepArray.iMaxPhotoStepW9MP;
       
   969                     break;                    
       
   970                 default: 
       
   971                     break;
       
   972                 }                
       
   973             }
       
   974         else if ( ECamActiveCameraSecondary == camera  )
       
   975             {
       
   976             maxStep = aStepArray.iMax2ndCamPhotoStep;
       
   977             }  
       
   978         // otherwise, do nothing
       
   979         else
       
   980             {
       
   981             // empty statement to remove Lint error.
       
   982             }      
       
   983         }
       
   984     else if ( iCameraState & ECamVideoOn )
       
   985         {
       
   986         // TCamVideoResolution resId = iController.GetCurrentVideoResolution();        
       
   987 
       
   988         if ( iController.ActiveCamera() == ECamActiveCameraPrimary )
       
   989             {        
       
   990             // switch ( resId )
       
   991             switch ( iCurrentResolution )            
       
   992                 {
       
   993                 case ECamVideoResolutionSubQCIF:     // Small (128 x 96)
       
   994                     maxStep = aStepArray.iMaxVideoStepSQCIF;
       
   995                     break;
       
   996                 case ECamVideoResolutionQCIF:        // Medium (176 x 144)
       
   997                     maxStep = aStepArray.iMaxVideoStepQCIF;
       
   998                     break;
       
   999                 case ECamVideoResolutionCIF:         // Large (352 x 288) (Default)
       
  1000                     maxStep = aStepArray.iMaxVideoStepCIF;
       
  1001                     break;            
       
  1002                 case ECamVideoResolutionVGA:         // VGA (640 x 480)
       
  1003                     maxStep = aStepArray.iMaxVideoStepVGA;            
       
  1004                     break;            
       
  1005                 case ECamVideoResolutionQVGA:         // QVGA ( 320 x 240 )
       
  1006                     maxStep = aStepArray.iMaxVideoStepQVGA;
       
  1007                     break;                                        
       
  1008                 case ECamVideoResolutionNHD:         // NHD ( 640 x 352 )
       
  1009                     maxStep = aStepArray.iMaxVideoStepNHD;
       
  1010                     break;                                            
       
  1011                 case ECamVideoResolutionWVGA:         // WVGA ( 864 x 480 )
       
  1012                     maxStep = aStepArray.iMaxVideoStepWVGA;
       
  1013                     break;                                                
       
  1014                 case ECamVideoResolutionHD:           // HD ( 1280 x 720 )
       
  1015                     maxStep = aStepArray.iMaxVideoStepHD;
       
  1016                     break;                                                
       
  1017                 default: 
       
  1018                     break;
       
  1019                 }
       
  1020             }
       
  1021         else if ( iController.ActiveCamera() == ECamActiveCameraSecondary )
       
  1022             {
       
  1023             switch ( iCurrentResolution )
       
  1024                 {
       
  1025                 case ECamVideoResolutionCIF:         // Large (352 x 288) (Default)
       
  1026                     maxStep = aStepArray.iMax2ndCamVideoStepCIF;
       
  1027                     break;
       
  1028                 case ECamVideoResolutionQCIF:        // Medium (176 x 144)
       
  1029                     maxStep = aStepArray.iMax2ndCamVideoStepQCIF;
       
  1030                     break;
       
  1031                 case ECamVideoResolutionSubQCIF:     // Small (128 x 96)
       
  1032                     maxStep = aStepArray.iMax2ndCamVideoStepSQCIF;
       
  1033                     break;
       
  1034                 default:
       
  1035                     break;
       
  1036                 }                        
       
  1037             }  
       
  1038         // otherwise, do nothing
       
  1039         else
       
  1040             {
       
  1041             // empty statement to remove Lint error.
       
  1042             }      
       
  1043         }                
       
  1044     // otherwise, do nothing
       
  1045     else
       
  1046         {
       
  1047         // empty statement to remove Lint error.
       
  1048         }
       
  1049 
       
  1050     PRINT1( _L( "Camera <= CCamZoomModel::MaxZoomStep maxStep=%d" ), maxStep );
       
  1051     return maxStep;
       
  1052     }
       
  1053 
       
  1054 
       
  1055     
       
  1056 
       
  1057 // -----------------------------------------------------------------------------
       
  1058 // CCamZoomModel::StopZoom
       
  1059 // Called when the user releases the zoom key to stop an ongoing zoom operation.
       
  1060 // -----------------------------------------------------------------------------
       
  1061 //
       
  1062 void CCamZoomModel::StopZoom()
       
  1063     {    
       
  1064     PRINT( _L( "Camera => CCamZoomModel::StopZoom " ) );
       
  1065     
       
  1066     if ( iZoomTimer->IsActive() )
       
  1067         {
       
  1068         iZoomTimer->Cancel();
       
  1069         }
       
  1070 
       
  1071     // Clear the zoom state
       
  1072     iState = ECamZoomModelStateZoomNone;
       
  1073 
       
  1074     // Reset zoom multiplier
       
  1075     iZoomStepMultiplier = 1;
       
  1076 
       
  1077     if ( iPauseState == EPauseStatePaused )
       
  1078         {
       
  1079         iPauseState = EPauseStateReleased;
       
  1080         }
       
  1081     else
       
  1082         {
       
  1083         iPauseState = EPauseStateNone;
       
  1084         }
       
  1085         
       
  1086     PRINT( _L( "Camera <= CCamZoomModel::StopZoom " ) );
       
  1087     }
       
  1088 
       
  1089 // -----------------------------------------------------------------------------
       
  1090 // CCamZoomModel::HandleControllerEventL
       
  1091 // Called when a controller event occurs
       
  1092 // -----------------------------------------------------------------------------
       
  1093 //
       
  1094 void CCamZoomModel::HandleControllerEventL( TCamControllerEvent aEvent, 
       
  1095                                             TInt /*aError*/ )
       
  1096   {
       
  1097   PRINT( _L( "Camera => CCamZoomModel::HandleControllerEventL " ) );
       
  1098   switch( aEvent )
       
  1099     {
       
  1100     // -----------------------------------------
       
  1101     case ECamEventEngineStateChanged:
       
  1102       {
       
  1103       iCameraState = iController.CameraControllerState();  
       
  1104       
       
  1105       // If a reset is waiting. This happens if the application 'pretends to exit' 
       
  1106       // but this occurred when the engine was not prepared e.g. in standby.
       
  1107       // The zoom needs to be set back to default when prepared, and the engine has
       
  1108       // now entered a prepared state
       
  1109       if ( iResetPending 
       
  1110         && ( iCameraState & (ECamImageOn|ECamVideoOn) ) )
       
  1111           {
       
  1112           // The zoom pane will not be redrawn while the iResetPending flag is on.
       
  1113           // This calls RefreshSettings()
       
  1114           ResetZoomTo1x();
       
  1115           // In this situation the zoom pane should not be shown.
       
  1116           /*if ( iPane->IsVisible() )
       
  1117               {
       
  1118               iPane->MakeVisible( EFalse, ETrue );
       
  1119               }*/
       
  1120           iResetPending = EFalse;                
       
  1121           }     
       
  1122       else
       
  1123           {
       
  1124           // If state changes (video <-> photo) refresh settings
       
  1125           RefreshSettings();
       
  1126           }
       
  1127       }
       
  1128       break;
       
  1129     // -----------------------------------------
       
  1130     case ECamEventCameraChanged:
       
  1131       {        
       
  1132       // If state changes (camera change) refresh settings
       
  1133       RefreshSettings();
       
  1134       
       
  1135       ResetZoomTo1x();
       
  1136       }       
       
  1137       break;
       
  1138     // -----------------------------------------
       
  1139     // Zoom settings now involve basic digital zoom too.
       
  1140     // Event name changed ECamEventExtZoomStateChanged => ECamEventZoomSetupChanged
       
  1141     case ECamEventImageQualityChanged:
       
  1142     case ECamEventZoomSetupChanged:    // Digital/Extended zoom turned on/off/paused/continuous
       
  1143       {
       
  1144       // If image quality has changed, this may update zoom levels.
       
  1145       RefreshSettings();
       
  1146       }
       
  1147       break;
       
  1148     // -----------------------------------------
       
  1149     case ECamEventOperationStateChanged:
       
  1150       {
       
  1151       // As the iRecordingVideo state has changed, need to update
       
  1152       // the settings, as this may disable the optical zoom 
       
  1153       RefreshSettings();                                            
       
  1154       }
       
  1155       break;
       
  1156     // -----------------------------------------
       
  1157     // otherwise, do nothing
       
  1158     default:
       
  1159       break;
       
  1160     } // switch
       
  1161     
       
  1162   PRINT( _L( "Camera <= CCamZoomModel::HandleControllerEventL " ) );
       
  1163   }
       
  1164 
       
  1165 // ---------------------------------------------------------------------------
       
  1166 // CCamZoomModel::ZoomTimerCallback
       
  1167 // Callback for Zoom Pane timer, used to give smooth zooming
       
  1168 // ---------------------------------------------------------------------------
       
  1169 //
       
  1170 TInt CCamZoomModel::ZoomTimerCallback( TAny* aObject )
       
  1171     {    
       
  1172     CCamZoomModel* model = static_cast< CCamZoomModel* >( aObject );
       
  1173     model->ZoomTimerTick();
       
  1174     return KErrNone;
       
  1175     }
       
  1176 
       
  1177 // ---------------------------------------------------------------------------
       
  1178 // CCamZoomModel::ZoomTimerTick
       
  1179 // Called each timer period while the zoom in/out key is held down.
       
  1180 // ---------------------------------------------------------------------------
       
  1181 //
       
  1182 void CCamZoomModel::ZoomTimerTick()
       
  1183     {        
       
  1184     PRINT( _L("Camera => CCamZoomModel::ZoomTimerTick") );
       
  1185     TCamZoomMode modeBefore = iZoomMode;
       
  1186                    
       
  1187     // Continue the ongoing zoom operation
       
  1188     if ( iState == ECamZoomModelStateZoomIn )
       
  1189         {
       
  1190         ZoomIn();
       
  1191         }
       
  1192     else if ( iState == ECamZoomModelStateZoomOut )
       
  1193         {
       
  1194         ZoomOut();
       
  1195         }    
       
  1196     else
       
  1197         {
       
  1198         // Do nothing
       
  1199         }               
       
  1200     
       
  1201     // Check if we're currently on a boundary, in which case we need 
       
  1202     // to stop and re-initialise the timer for the (potentially) new
       
  1203     // interval.                            
       
  1204     TCamZoomMode modeAfter = iZoomMode;
       
  1205     
       
  1206     if ( modeBefore != modeAfter )
       
  1207         {
       
  1208         // Restart zoom;
       
  1209         if ( iZoomTimer->IsActive() )
       
  1210             {
       
  1211             iZoomTimer->Cancel();
       
  1212             }
       
  1213         StartZoomTimer();
       
  1214         }   
       
  1215     PRINT( _L("Camera <= CCamZoomModel::ZoomTimerTick") );
       
  1216     }        
       
  1217 
       
  1218 
       
  1219 
       
  1220 // ---------------------------------------------------------------------------
       
  1221 // CCamZoomModel::StartZoomTimer
       
  1222 // Called each timer period while the zoom in/out key is held down.
       
  1223 // ---------------------------------------------------------------------------
       
  1224 //
       
  1225 void CCamZoomModel::StartZoomTimer()
       
  1226     {
       
  1227     PRINT( _L( "Camera => CCamZoomModel::StartZoomTimer " ) );
       
  1228     
       
  1229     if ( iZoomTimer->IsActive() )
       
  1230         {
       
  1231         return; // If only one speed, we're already running so just return.        
       
  1232         }
       
  1233           
       
  1234     TCamZoomMode mode = CurrentZoomType();                
       
  1235     
       
  1236     TInt stepPeriod = 0;
       
  1237     
       
  1238     switch ( mode )
       
  1239         {            
       
  1240         case ECamZoomModeOptical:
       
  1241             {
       
  1242             stepPeriod = iZoomLAF.iZoomSpeedOpt * 1000;
       
  1243             break;        
       
  1244             }
       
  1245         
       
  1246         case ECamZoomModeDigital:
       
  1247             {
       
  1248             if( iCameraState & ECamImageOn )
       
  1249                 {    
       
  1250                 stepPeriod = iZoomLAF.iZoomSpeedDig * 1000;
       
  1251                 }
       
  1252             else
       
  1253                 {
       
  1254                 // use slower speed for videomode        
       
  1255                 stepPeriod = iZoomLAF.iZoomSpeedDig * 2500;
       
  1256                 }
       
  1257             break;        
       
  1258             }
       
  1259         
       
  1260         case ECamZoomModeExtended:
       
  1261             {
       
  1262             stepPeriod = iZoomLAF.iZoomSpeedExt * 1000;
       
  1263             break;        
       
  1264             }
       
  1265                     
       
  1266         case ECamZoomModeUndefined:
       
  1267         default:
       
  1268             {
       
  1269             stepPeriod = 1000000;
       
  1270             break;        
       
  1271             }        
       
  1272         }
       
  1273     
       
  1274     
       
  1275     iZoomTimer->Start( stepPeriod, stepPeriod, TCallBack( ZoomTimerCallback , this) );
       
  1276     iZoomMode = mode;
       
  1277     
       
  1278     PRINT( _L( "Camera <= CCamZoomModel::StartZoomTimer " ) );
       
  1279     }
       
  1280 
       
  1281 // ---------------------------------------------------------------------------
       
  1282 // CCamZoomModel::AllowExtZoom
       
  1283 // Returns whether extended zoom is allowed or not, based on current settings
       
  1284 // ---------------------------------------------------------------------------
       
  1285 //
       
  1286 TBool CCamZoomModel::AllowExtZoom() const
       
  1287     {
       
  1288     PRINT( _L( "Camera => CCamZoomModel::AllowExtZoom " ) );
       
  1289     
       
  1290     TInt extendedStep = MaxZoomStep( iExtZoomSteps );    
       
  1291     
       
  1292     // Check there is a valid extended zoom step to allow to first, and that
       
  1293     // we are not in embedded mode (extended zoom not allowed in embedded)
       
  1294     if (  KErrNotSupported != extendedStep )
       
  1295         {
       
  1296         if ( iZoomSetting == ECamSettDigZoomExtendPause
       
  1297           || iZoomSetting == ECamSettDigZoomExtendCont )
       
  1298             {
       
  1299             // If setting allows extended zoom, return true
       
  1300             PRINT( _L( "Camera <= CCamZoomModel::AllowExtZoom ETrue" ) );
       
  1301             return ETrue;
       
  1302             }
       
  1303         else
       
  1304             {
       
  1305             // else user setting disallows it, so return false
       
  1306             PRINT( _L( "Camera <= CCamZoomModel::AllowExtZoom EFalse" ) );
       
  1307             return EFalse;
       
  1308             }
       
  1309         }
       
  1310     else
       
  1311         {
       
  1312         // No valid extended zoom, so not allowed even if user said so.
       
  1313         PRINT( _L( "Camera <= CCamZoomModel::AllowExtZoom EFalse" ) );
       
  1314         return EFalse;
       
  1315         }
       
  1316     }
       
  1317     
       
  1318 // ---------------------------------------------------------------------------
       
  1319 // CCamZoomModel::AllowOptZoom
       
  1320 // Returns whether optical zoom is allowed
       
  1321 // ---------------------------------------------------------------------------
       
  1322 // 
       
  1323 TBool CCamZoomModel::AllowOptZoom() const
       
  1324     {        
       
  1325     PRINT( _L( "Camera => CCamZoomModel::AllowOptZoom " ) ); 
       
  1326     TInt maxOptZoomStep = MaxZoomStep( iOptZoomSteps );
       
  1327     if ( KErrNotSupported == maxOptZoomStep // Zoom is NOT supported or
       
  1328       || ( !iAllowOptZoom                   // Settings dont allow zoom during recording 
       
  1329         && iRecordingVideo ) )              // ...and we're recording now
       
  1330         {
       
  1331         PRINT( _L( "Camera <= CCamZoomModel::AllowOptZoom EFalse" ) );
       
  1332         return EFalse;   
       
  1333         }
       
  1334     else
       
  1335         {
       
  1336         PRINT( _L( "Camera <= CCamZoomModel::AllowOptZoom ETrue" ) );
       
  1337         return ETrue;                 
       
  1338         }      
       
  1339     }
       
  1340 
       
  1341 // ---------------------------------------------------------------------------
       
  1342 // CCamZoomModel::AllowDigZoom
       
  1343 // Returns whether digital zoom is allowed
       
  1344 // ---------------------------------------------------------------------------
       
  1345 //
       
  1346 TBool CCamZoomModel::AllowDigZoom() const
       
  1347     {         
       
  1348     PRINT( _L( "Camera => CCamZoomModel::AllowDigZoom " ) );
       
  1349     TInt maxStdZoomStep = MaxZoomStep( iDigZoomSteps );
       
  1350 
       
  1351     if ( KErrNotSupported    != maxStdZoomStep   // Zoom is supported in current state         
       
  1352       && ECamSettDigZoomNone != iZoomSetting   ) // ...and is allowed by user setting
       
  1353         {
       
  1354         PRINT( _L( "Camera <= CCamZoomModel::AllowDigZoom ETrue" ) );
       
  1355         return ETrue;         
       
  1356         }
       
  1357     else
       
  1358         {
       
  1359         PRINT( _L( "Camera <= CCamZoomModel::AllowDigZoom False" ) );
       
  1360         return EFalse;   
       
  1361         }      
       
  1362     }
       
  1363 
       
  1364 
       
  1365 // ---------------------------------------------------------------------------
       
  1366 // CCamZoomModel::CurrentZoom
       
  1367 // Returns the current zoom level, taking into account optical (if allowed)
       
  1368 // *and* digital zooms.
       
  1369 // ---------------------------------------------------------------------------
       
  1370 //
       
  1371 TInt CCamZoomModel::CurrentZoom() const
       
  1372     {
       
  1373     PRINT( _L( "Camera => CCamZoomModel::CurrentZoom" ) );
       
  1374     // If we are recording video, and optical isn't allowed while recording
       
  1375     // then we only need to represent the Digital zoom in the zoom pane.    
       
  1376     if ( iRecordingVideo && !iAllowOptZoom )
       
  1377         {
       
  1378         // Only use digital value if optical not allowed
       
  1379         PRINT( _L( "Camera <= CCamZoomModel::CurrentZoom digital" ) );
       
  1380         return iCurZoomStepDigital;
       
  1381         }
       
  1382     else
       
  1383         {
       
  1384         // Return the combined zoom value
       
  1385         PRINT( _L( "Camera <= CCamZoomModel::CurrentZoom optical+digital" ) );
       
  1386         return (iCurZoomStepOptical + iCurZoomStepDigital);
       
  1387         }
       
  1388     }
       
  1389 
       
  1390 
       
  1391 // ---------------------------------------------------------------------------
       
  1392 // CCamZoomModel::PauseAtBoundary
       
  1393 // Returns whether to pause at the specified boundary
       
  1394 // ---------------------------------------------------------------------------
       
  1395 //
       
  1396 TBool CCamZoomModel::PauseAtBoundary( TCamZoomBoundary aBoundary ) const
       
  1397   {
       
  1398   PRINT( _L( "Camera => CCamZoomModel::PauseAtBoundary" ) );
       
  1399   if ( iCameraState & ECamVideoOn )
       
  1400   	{
       
  1401     // Always return false for video, as we do not want to 
       
  1402     // force the zoom operation to pause at any boundary
       
  1403     // in video mode. 
       
  1404     PRINT( _L( "Camera <= CCamZoomModel::PauseAtBoundary EFalse" ) );  
       
  1405     return EFalse;
       
  1406     }
       
  1407   else
       
  1408   	{
       
  1409   	if ( ECamZoomBoundaryOptDig == aBoundary )
       
  1410       {
       
  1411       // Reason to *not* pause at the optical/digital boundary is if
       
  1412       // user set the "On (continuous)" or "Extended on (continuous) setting
       
  1413       if ( ECamSettDigZoomNormalCont == iZoomSetting
       
  1414         || ECamSettDigZoomExtendCont == iZoomSetting )
       
  1415         {
       
  1416         PRINT( _L( "Camera <= CCamZoomModel::PauseAtBoundary EFalse" ) );  
       
  1417         return EFalse;            
       
  1418         }
       
  1419       else 
       
  1420         {
       
  1421         PRINT( _L( "Camera <= CCamZoomModel::PauseAtBoundary ETrue" ) );  
       
  1422         return ETrue;
       
  1423         }
       
  1424       }
       
  1425     else if ( ECamZoomBoundaryDigExt == aBoundary ) 
       
  1426       {
       
  1427       // Only reason *not* to pause in digital/extended boundary is if
       
  1428       // user zoom setting states "extended on without pauses".
       
  1429       if ( ECamSettDigZoomExtendCont == iZoomSetting )
       
  1430         {
       
  1431         PRINT( _L( "Camera <= CCamZoomModel::PauseAtBoundary EFalse" ) );  
       
  1432         return EFalse;
       
  1433         }
       
  1434       else
       
  1435         {
       
  1436         PRINT( _L( "Camera <= CCamZoomModel::PauseAtBoundary ETrue" ) );  
       
  1437         return ETrue;    
       
  1438         }
       
  1439       }
       
  1440     else // No other boundaries known, return "no pause".
       
  1441       {
       
  1442       PRINT( _L( "Camera <= CCamZoomModel::PauseAtBoundary EFalse" ) );  
       
  1443       return EFalse;
       
  1444       }     
       
  1445     }	
       
  1446   }
       
  1447   
       
  1448     
       
  1449 // -----------------------------------------------------------------------------
       
  1450 // CCamZoomPane::IsCurrentlyZooming
       
  1451 // Returns ETrue if the zoom model is currently zooming in/out,
       
  1452 // else returns EFalse
       
  1453 // -----------------------------------------------------------------------------
       
  1454 //
       
  1455 TBool CCamZoomModel::IsCurrentlyZooming() const
       
  1456     {    
       
  1457     PRINT( _L( "Camera => CCamZoomModel::IsCurrentlyZooming" ) );
       
  1458     if ( ECamZoomModelStateZoomIn  == iState 
       
  1459       || ECamZoomModelStateZoomOut == iState )
       
  1460         {
       
  1461         PRINT( _L( "Camera <= CCamZoomModel::IsCurrentlyZooming ETrue" ) );
       
  1462         return ETrue;
       
  1463         }
       
  1464     else
       
  1465         {
       
  1466         PRINT( _L( "Camera <= CCamZoomModel::IsCurrentlyZooming EFalse" ) );
       
  1467         return EFalse;
       
  1468         }
       
  1469     }
       
  1470     
       
  1471 // -----------------------------------------------------------------------------
       
  1472 // CCamZoomModel::ZoomingState
       
  1473 // -----------------------------------------------------------------------------
       
  1474 //
       
  1475 CCamZoomModel::TCamZoomModelState CCamZoomModel::ZoomingState()
       
  1476     {    
       
  1477     return iState;  
       
  1478     }
       
  1479  
       
  1480 
       
  1481 // -----------------------------------------------------------------------------
       
  1482 // CCamZoomPane::ResetToDefaultAfterPrepare
       
  1483 // Sets the zoompane to reset the zoom level to default values
       
  1484 // next time the engine is prepared
       
  1485 // -----------------------------------------------------------------------------
       
  1486 //
       
  1487 void CCamZoomModel::ResetToDefaultAfterPrepare( TBool aReset )
       
  1488     {
       
  1489     iResetPending = aReset;
       
  1490     }     
       
  1491 
       
  1492 // -----------------------------------------------------------------------------
       
  1493 // CCamZoomPane::IsResetPending
       
  1494 // Whether or not the zoom level is waiting to be reset to default
       
  1495 // -----------------------------------------------------------------------------
       
  1496 //
       
  1497 TBool CCamZoomModel::IsResetPending() const
       
  1498     {
       
  1499     return iResetPending;
       
  1500     }
       
  1501 
       
  1502 // -----------------------------------------------------------------------------
       
  1503 // ReadCurrentResolution
       
  1504 // -----------------------------------------------------------------------------
       
  1505 //
       
  1506 void 
       
  1507 CCamZoomModel::ReadCurrentResolution()
       
  1508   {
       
  1509   PRINT1( _L("Camera => CCamZoomModel::ReadCurrentResolution, now:%d"), iCurrentResolution );
       
  1510   if ( iCameraState & ECamImageOn )
       
  1511     {                
       
  1512     iCurrentResolution = iController.GetCurrentImageResolution();
       
  1513     }
       
  1514   else if( iCameraState & ECamVideoOn )
       
  1515     {
       
  1516     iCurrentResolution = iController.GetCurrentVideoResolution();
       
  1517     }
       
  1518   else
       
  1519     {
       
  1520     iCurrentResolution = KErrNotReady;
       
  1521     }
       
  1522   PRINT1( _L("Camera <= CCamZoomModel::ReadCurrentResolution, got:%d"), iCurrentResolution );
       
  1523   }
       
  1524 
       
  1525 // -----------------------------------------------------------------------------
       
  1526 // SetZoomMultiplier
       
  1527 // -----------------------------------------------------------------------------
       
  1528 //
       
  1529 void CCamZoomModel::SetZoomMultiplier( TInt aZoomStepMultiplier )
       
  1530     {
       
  1531     iZoomStepMultiplier = aZoomStepMultiplier;
       
  1532     if ( iCameraState & ECamVideoOn )
       
  1533         {
       
  1534         iZoomStepMultiplier *= 2;
       
  1535         }
       
  1536     }
       
  1537 
       
  1538 //  End of File