camerauis/cameraapp/generic/inc/CamZoomModel.h
changeset 0 1ddebce53859
child 18 51dda465e618
equal deleted inserted replaced
-1:000000000000 0:1ddebce53859
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Controls the state of the zoom*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 #ifndef CAMZOOMMODEL_H
       
    20 #define CAMZOOMMODEL_H
       
    21 
       
    22 //  INCLUDES
       
    23 #include <e32base.h>
       
    24 #include "CamPSI.h" 
       
    25 #include "CamAppController.h"
       
    26 #include "CamControllerObservers.h"    // MCamControllerObserver
       
    27 #include "CamZoomUpdateManager.h"
       
    28 
       
    29 // CONSTANTS
       
    30 
       
    31 // MACROS
       
    32 
       
    33 // DATA TYPES
       
    34 
       
    35 // FUNCTION PROTOTYPES
       
    36 
       
    37 // FORWARD DECLARATIONS
       
    38 class CCamZoomPane;
       
    39 
       
    40 // CLASS DECLARATION
       
    41 
       
    42 /**
       
    43 *  This class contains the logic for handling zoom operations
       
    44 *  with support for Optical, Digital and Extended Digital zoom
       
    45 *
       
    46 *  @since 3.0
       
    47 */
       
    48 class CCamZoomModel : public CBase,
       
    49                       public MCamControllerObserver
       
    50   {
       
    51   // =========================================================================
       
    52   // Types
       
    53   public: 
       
    54 
       
    55     enum TCamZoomModelState
       
    56         {
       
    57         ECamZoomModelStateZoomNone,
       
    58         ECamZoomModelStateZoomIn,
       
    59         ECamZoomModelStateZoomOut,
       
    60         ECamZoomModelStateZoomTo
       
    61         };
       
    62 
       
    63     /* Moved to CamSettingsInternal.hrh   
       
    64     // Used to represent the current zoom mode used with the Engine
       
    65     enum TCamZoomMode
       
    66         {
       
    67         ECamZoomModeUndefined,
       
    68         ECamZoomModeOptical,
       
    69         ECamZoomModeDigital, 
       
    70         ECamZoomModeExtended
       
    71         }; */
       
    72             
       
    73     // Used to describe the current zoom mode boundary.
       
    74     enum TCamZoomBoundary
       
    75         {
       
    76         ECamZoomBoundaryUndefined, // Not checked yet for current zoom step
       
    77         ECamZoomBoundaryNone,      // Checked, but not at a boundary
       
    78         ECamZoomBoundaryOptDig,    // Checked, and at Optical/Digital boundary
       
    79         ECamZoomBoundaryDigExt     // Checked, and at Digital/Extended boundary
       
    80         };
       
    81         
       
    82     // PauseState represents handling of pausing zooming in at
       
    83     // zoom mode boundarys (between optical/digital and digital/extended)
       
    84     enum TPauseState
       
    85         {
       
    86         EPauseStateNone,    // Not at a boundary
       
    87         EPauseStatePaused,  // Just hit a boundary, all zoom-in events ignored until released
       
    88         EPauseStateReleased // Just released zoom key, allow next zoom 
       
    89         };
       
    90 
       
    91   // =========================================================================
       
    92   // Methods
       
    93 
       
    94   // -------------------------------------------------------------------------
       
    95   // Constructors and destructor
       
    96   public:  
       
    97         
       
    98     /**
       
    99     * Two-phased constructor.
       
   100     */
       
   101     static CCamZoomModel* NewL( CCamAppController& aController, CCamZoomPane* aZoomPane );
       
   102     
       
   103     /**
       
   104     * Destructor.
       
   105     */
       
   106     virtual ~CCamZoomModel();
       
   107 
       
   108   // -------------------------------------------------------------------------
       
   109   // From CCamAppControllerBase
       
   110   public: 
       
   111 
       
   112     /**
       
   113     * Handle controller event.
       
   114     * @since 3.0
       
   115     * @param aEvent the controller event that has occurred
       
   116     * @param aError any reported error
       
   117     */
       
   118     virtual void HandleControllerEventL( TCamControllerEvent aEvent,
       
   119                                          TInt aError );
       
   120        
       
   121 
       
   122 
       
   123 
       
   124   // -------------------------------------------------------------------------
       
   125   // New functions
       
   126   public: 
       
   127         
       
   128     /**
       
   129     * Attempts to zoom in one step, if possible.
       
   130     * Zooming will continue until StopZoom() is called.
       
   131     * @since 3.0        
       
   132     */
       
   133     void ZoomIn( TBool aOneClick = EFalse );
       
   134     
       
   135     /**
       
   136     * Attempts to zoom out one step, if possible.
       
   137     * Zooming will continue until StopZoom() is called.
       
   138     * @since 3.0        
       
   139     */        
       
   140     void ZoomOut( TBool aOneClick = EFalse );
       
   141     
       
   142     /**
       
   143     * Attempts to zoom to a specific point, if possible.
       
   144     * 
       
   145     * @since 5.0        
       
   146     */   
       
   147     void ZoomTo( TInt aValue );
       
   148     
       
   149     /**
       
   150     * Stops an ongoing zoom in/out operation
       
   151     * @since 3.0        
       
   152     */
       
   153     void StopZoom();
       
   154     
       
   155     /**
       
   156     * Checks the current state of the Camera application, and adjusts the
       
   157     * min/max range of the zoom pane accordingly.        
       
   158     * @since 3.0        
       
   159     */                
       
   160     void RefreshSettings();
       
   161     
       
   162     /**
       
   163     * Timer callback, used during a zoom in/out to trigger repeat
       
   164     * zoom steps while the key is held down.
       
   165     * @param aObject Pointer to a CCamZoomModel object
       
   166     * @return TInt KErrNone if ok
       
   167     * @since 3.0        
       
   168     */                        
       
   169     static TInt ZoomTimerCallback( TAny* aObject );   
       
   170             
       
   171     /**
       
   172     * Returns whether the zoom model is currently zooming in or out
       
   173     * @since 3.0
       
   174     * @return ETrue if zooming, else EFalse
       
   175     */
       
   176     TBool IsCurrentlyZooming() const;
       
   177 
       
   178     /**
       
   179     * Returns zoom model state
       
   180     * @since S60 v5.0
       
   181     * @return TCamZoomModelState
       
   182     */
       
   183     TCamZoomModelState ZoomingState();  
       
   184     
       
   185     /**
       
   186     * Indicates that the zoom level should be reset to default
       
   187     * when the engine is next prepared
       
   188     * @since 2.8
       
   189     * @param aReset ETrue if the zoom pane should be reset, else EFalse
       
   190     */
       
   191     void ResetToDefaultAfterPrepare( TBool aReset );
       
   192     
       
   193     /**
       
   194     * Indicates whether or not the zoom level is waiting to be reset to default
       
   195     * @since 3.0
       
   196     * @return TBool ETrue if a reset is pending, othewise EFalse
       
   197     */       
       
   198     TBool IsResetPending() const;
       
   199     
       
   200     /***
       
   201     * Resets the zoom (digital, and, if available, optical) to 1x
       
   202     * @since 3.0
       
   203     */                        
       
   204     void ResetZoomTo1x();
       
   205 
       
   206   private:
       
   207     
       
   208     /**
       
   209     * Called by the timer callback function to perform 
       
   210     * the operation of one timer "tick". Will zoom in or out
       
   211     * one step to continue the ongoing zoom operation.
       
   212     * @since 3.0
       
   213     */        
       
   214     void ZoomTimerTick();
       
   215     
       
   216     /**
       
   217     * Starts the zoom timer if not already running.
       
   218     * @since 3.0
       
   219     */        
       
   220     void StartZoomTimer();
       
   221     
       
   222     /**
       
   223     * Returns the maximum zoom step from the supplied step array.
       
   224     * The returned step takes into account the currently active 
       
   225     * camera and capture mode.
       
   226     * @param aStepArray The step array from the PSI
       
   227     * @since 3.0
       
   228     * @return The maximum step from the array.
       
   229     */                
       
   230     TInt MaxZoomStep( const TCamMaxZoomSteps& aStepArray ) const;
       
   231     
       
   232     /***
       
   233     * Checks the zoom mode is that expected.  If not, will be set.
       
   234     * @param aMode The zoom mode to check for
       
   235     * @since 3.0
       
   236     */                        
       
   237     void CheckZoomMode( TCamZoomMode aMode );
       
   238     
       
   239     /***
       
   240     * Reads the digital zoom setting and updates internal state
       
   241     * @since 3.0
       
   242     */                                        
       
   243     void ReadDigitalZoomSetting();
       
   244     
       
   245     /***
       
   246     * Reads the optical zoom setting and updates internal state
       
   247     * @since 3.0
       
   248     */                                                
       
   249     void ReadOpticalZoomSetting();
       
   250     
       
   251     /***
       
   252     * Checks that the current zoom levels for optical/digital zoom
       
   253     * do not exceed current limits.  If they do, the level is set
       
   254     * to the available limit.
       
   255     * @since 3.0
       
   256     */                                        
       
   257     void CheckZoomLimit();
       
   258     
       
   259     /***
       
   260     * Returns whether EXTENDED zoom is allowed based on 
       
   261     * settings for the current resolution, and user options.
       
   262     * @since 3.0
       
   263     * @returns ETrue if allowed, else EFalse
       
   264     */           
       
   265     TBool AllowExtZoom() const;
       
   266     
       
   267     /***
       
   268     * Returns whether OPTICAL zoom is allowed based on 
       
   269     * settings for the current resolution, and user options.
       
   270     * @since 3.0
       
   271     * @returns ETrue if allowed, else EFalse
       
   272     */                   
       
   273     TBool AllowOptZoom() const;
       
   274     
       
   275     /***
       
   276     * Returns whether DIGITAL zoom is allowed based on 
       
   277     * settings for the current resolution, and user options.
       
   278     * @since 3.0
       
   279     * @returns ETrue if allowed, else EFalse
       
   280     */                           
       
   281     TBool AllowDigZoom() const;
       
   282     
       
   283     /***
       
   284     * Returns whether zooming should be paused at the 
       
   285     * specified zoom boundary.
       
   286     * @since 3.0
       
   287     * @param aBoundary
       
   288     * @returns ETrue if pause required, else EFalse
       
   289     */                           
       
   290     TBool PauseAtBoundary( TCamZoomBoundary aBoundary ) const;
       
   291     
       
   292     /***
       
   293     * Checks whether doing the next zoom operation will move 
       
   294     * from one type of zoom to another.
       
   295     * 
       
   296     * Will return any of: 
       
   297     *   - ECamZoomBoundaryNone (not on a boundary)
       
   298     *   - ECamZoomBoundaryOptDig (on optical/digital boundary)
       
   299     *   - ECamZoomBoundaryDigExt (on digital/extended boundary)
       
   300     *                              
       
   301     * @since 3.0
       
   302     * @returns The current zoom boundary state
       
   303     */                        
       
   304     TCamZoomBoundary CheckBoundary() const;
       
   305     
       
   306     /***
       
   307     * Returns the current zoom type (Optical/Digital/Extended), based
       
   308     * on the current zoom level.  Optionally takes a parameter, to 
       
   309     * see what zoom type would be used if zoom level adjusted by 
       
   310     * the stepmodifier (positive or negative)
       
   311     * @since 3.0
       
   312     * @param aStepModifier Value to add to current zoom
       
   313     * @returns The zoom mode of current zoom value + step modifier
       
   314     */                        
       
   315     TCamZoomMode CurrentZoomType( TInt aStepModifier = 0 ) const;
       
   316     
       
   317     /***
       
   318     * Returns the number of zoom steps that the next zoom will jump.
       
   319     * @since 3.0        
       
   320     * @returns The number of zoom steps to jump.
       
   321     */                        
       
   322     TInt ZoomStepsToJump() const;
       
   323     
       
   324     /***
       
   325     * Returns (via references) how the zoom steps should be split up
       
   326     * between the optical, digital and extended zoom modes.
       
   327     * @since 3.0
       
   328     * @param aOpt The optical steps to move.
       
   329     * @param aDig The digital steps to move.
       
   330     * @param aExt The extended steps to move.
       
   331     */                        
       
   332     void ZoomStepsToJump( TInt& aOpt, TInt& aDig, TInt& aExt ) const;
       
   333     
       
   334     /**
       
   335     * Returns the current combined (optical + digital) zoom         
       
   336     * for the current zoom model state.
       
   337     * @since 3.0
       
   338     * @returns The current combined zoom
       
   339     */
       
   340     TInt CurrentZoom() const;
       
   341     
       
   342     /**
       
   343     * Read the current resolution id.
       
   344     * 
       
   345     */
       
   346     void ReadCurrentResolution();
       
   347 
       
   348   // -------------------------------------------------------------------------
       
   349   // Private constructors
       
   350   private:
       
   351   
       
   352     /**
       
   353     * C++ default constructor.
       
   354     */
       
   355     CCamZoomModel( CCamAppController& aController, CCamZoomPane* aPane );
       
   356     
       
   357     /**
       
   358     * By default Symbian 2nd phase constructor is private.
       
   359     */
       
   360     void ConstructL();
       
   361 
       
   362   // =========================================================================
       
   363   // Data
       
   364   private:
       
   365 
       
   366     // Arrays from the PSI, describing maximum zoom steps for 
       
   367     // different zoom modes and different resolutions and media
       
   368     TCamMaxZoomSteps iOptZoomSteps; // Optical zoom steps
       
   369     TCamMaxZoomSteps iDigZoomSteps; // Standard digital zoom steps
       
   370     TCamMaxZoomSteps iExtZoomSteps; // Extended digital zoom steps
       
   371     
       
   372     // These values are the maximum zoom steps for different zoom modes.
       
   373     // Will be updated when RefreshSettings() is called.
       
   374     TInt iMaxZoomStepOpt;	// Max Optical step
       
   375     TInt iMaxZoomStepDig;	// Max Digital step
       
   376     TInt iMaxZoomStepExt;	// Max Extended step
       
   377     
       
   378     // Zoom setting: Allow digital and/or extended, where to pause.
       
   379     TCamSettingsDigitalZoom iZoomSetting;
       
   380     
       
   381     // Whether to allow Optical zoom during video
       
   382     TBool iAllowOptZoom;
       
   383     
       
   384     // The current optical and digital zoom steps
       
   385     TInt iCurZoomStepOptical;
       
   386     TInt iCurZoomStepDigital;
       
   387     
       
   388     // Max allowed zoom step (taking into account optical, digital and extended)
       
   389     TInt iMaxZoomStep;
       
   390     
       
   391     // Stores the current state of the model, and the last-notified
       
   392     // engine state.
       
   393     TCamZoomModelState iState;
       
   394     //        TCamEngineState iEngineState;
       
   395     TUint iCameraState;
       
   396 
       
   397     // Stores the latest video or image resolution id.
       
   398     TInt iCurrentResolution;
       
   399     
       
   400     // Reference to the controller used for setting the zoom step and mode.
       
   401     CCamAppController& iController;
       
   402     
       
   403     // Update manager is used to minimize amount of updates sent to driver.
       
   404     CCamZoomUpdateManager* iCamZoomUpdateManager;
       
   405     
       
   406     // Timer for zooming smoothly
       
   407     CPeriodic* iZoomTimer;   
       
   408     CCamZoomPane* iPane;
       
   409     
       
   410     // Keeps track of the current zoom mode
       
   411     TCamZoomMode iZoomMode;
       
   412     
       
   413     // Stores a look-and-feel structure for the zoom bar.         
       
   414     TCamZoomLAF iZoomLAF;
       
   415     
       
   416     // The current pause state (none/paused/released)
       
   417     TPauseState iPauseState;        
       
   418     
       
   419     // Whether the camera app is currently recording video
       
   420     // Used to identify when we *stop* recording
       
   421     TBool iRecordingVideo;
       
   422     
       
   423     // Whether or not the zoompane should reset to default value on next prepare
       
   424     TBool iResetPending;
       
   425 
       
   426   // =========================================================================
       
   427   };
       
   428 
       
   429 #endif      // CAMZOOMMODEL_H   
       
   430             
       
   431 // End of File