camerauis/cameraapp/generic/inc/CamBurstThumbnailGridModel.h
changeset 0 1ddebce53859
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:  Model class holding thumbnail grid state information*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 #ifndef CAMBURSTTHUMBNAILGRIDMODEL_H
       
    20 #define CAMBURSTTHUMBNAILGRIDMODEL_H
       
    21 
       
    22 //  INCLUDES
       
    23 #include    <e32base.h>
       
    24 #include    <e32std.h>
       
    25 #include    <coecntrl.h>
       
    26 
       
    27 #include    <eiksbobs.h>    // For Scroll component
       
    28 #include    <eikscrlb.h>    // For ScrollModel
       
    29 
       
    30 #include    "CamAppController.h"
       
    31 #include    "CamBurstThumbnailGridSizer.h"
       
    32 
       
    33 // CONSTANTS
       
    34 // The max number of items in the small grid layout
       
    35 const TInt KSmallGridCellCount = 6;
       
    36 
       
    37 // The height of the small grid in cells
       
    38 const TInt KSmallGridHeight = 2;
       
    39 
       
    40 // The height of the large grid in cells
       
    41 const TInt KLargeGridHeight = 3;
       
    42 
       
    43 // MACROS
       
    44 
       
    45 // DATA TYPES
       
    46 
       
    47 // FUNCTION PROTOTYPES
       
    48 
       
    49 // FORWARD DECLARATIONS
       
    50 class CCamThumbnailGridSizer;
       
    51 
       
    52 // CLASS DECLARATION
       
    53 
       
    54 /**
       
    55 *  Simple class representing a burst capture image's attributes
       
    56 *
       
    57 *  @since 2.8
       
    58 */
       
    59 class CThumbnailGridItem : public CBase
       
    60     {
       
    61 public:
       
    62     // Constructor
       
    63     CThumbnailGridItem();
       
    64 
       
    65     // Destructor
       
    66     ~CThumbnailGridItem();
       
    67             
       
    68 public:
       
    69     // Scaled-down thumbnail for display in the Grid control
       
    70     CFbsBitmap* iDisplayThumb;
       
    71 
       
    72     // Whether or not this item has been marked.
       
    73     TBool 		iMarked;
       
    74     };
       
    75 
       
    76 
       
    77 /**
       
    78 *  Mix-in class used for listening to GridModel events.
       
    79 *
       
    80 *  @since 2.8
       
    81 */
       
    82 class MThumbModelObserver
       
    83     {
       
    84 public: 
       
    85     /**
       
    86     * Called when the highlighted option changes
       
    87     * @since 2.8    
       
    88     */
       
    89     virtual void HighlightChanged();
       
    90 
       
    91     /**
       
    92     * Called when one or more images have been deleted
       
    93     * @since 2.8    
       
    94     */
       
    95     virtual void ImagesDeleted();
       
    96 
       
    97     /**
       
    98     * Called when a new thumbnail has been generated
       
    99     * @since 2.8    
       
   100     */
       
   101     virtual void ThumbnailGenerated();
       
   102     };
       
   103 
       
   104 
       
   105 /**
       
   106 *  Contains the state of the Burst Post-Capture control
       
   107 *
       
   108 *  @since 2.8
       
   109 */
       
   110 class CCamBurstThumbnailGridModel :  public CBase,
       
   111                                      public MBitmapScaler
       
   112     {
       
   113     public:
       
   114         // Bitmask used to identify the events to register for.
       
   115         enum TModelEvent
       
   116         {
       
   117             EModelEventHighlight = 0x1,
       
   118             EModelEventDeleted   = 0x2,
       
   119             EModelEventThumb     = 0x4
       
   120         };
       
   121 
       
   122         // Used to represent the direction of highlight movement
       
   123         enum TMoveSelect 
       
   124         {
       
   125             EMoveSelectUp,
       
   126             EMoveSelectDown,
       
   127             EMoveSelectLeft,
       
   128             EMoveSelectRight,
       
   129         };
       
   130 
       
   131         // Used to represent the internal state for the image resizing operation
       
   132         enum TTmbState
       
   133         {
       
   134             ETmbStateScaling,       // Currently scaling an image
       
   135             ETmbStateIdle           // Image finished, but more to do
       
   136         };
       
   137 
       
   138     public:        
       
   139         /**
       
   140         * Two-phased constructor.
       
   141         */
       
   142         static CCamBurstThumbnailGridModel* NewL();
       
   143 
       
   144         /**
       
   145         * Destructor.
       
   146         */
       
   147         ~CCamBurstThumbnailGridModel();  
       
   148         
       
   149     public: // New functions
       
   150         /**
       
   151         * Attempts to move the selection highlight a specified direction
       
   152         * @since 2.8
       
   153         * @param aDir The direction to move the hightlight
       
   154         * @return TBool indicating whether the move was possible or not
       
   155         */
       
   156         TBool MoveHighlight( TMoveSelect aDir );
       
   157         
       
   158         TBool SetHighlight( TInt aIndex );
       
   159 
       
   160     	/**
       
   161     	 * Sets new size for the scaling
       
   162     	 * @param aThumbSize The new size
       
   163     	 */
       
   164     	void SetThumbnailSize( const TSize aThumbSize );
       
   165 
       
   166         /**
       
   167         * Returns the number of valid (non-deleted) cells.  Used by thumbnail
       
   168         * grid to find how many cells it may need to draw.
       
   169         * @since 2.8       
       
   170         * @return Number of cells
       
   171         */        
       
   172         TInt NoOfValidCells();
       
   173 
       
   174         /**
       
   175         * Returns a specific grid item based on the supplied index.
       
   176         * @since 2.8
       
   177         * @param aValidIndex The index of the grid item to retrieve
       
   178         * @return Pointer to the required item
       
   179         */
       
   180         CThumbnailGridItem* GridItem( TInt aValidIndex );
       
   181 
       
   182         /**
       
   183         * Returns a specific bitmap based on the supplied index.
       
   184         * @since 2.8
       
   185         * @param aValidIndex The index of the bitmap to retrieve
       
   186         * @return Pointer to the required bitmap
       
   187         */
       
   188         const CFbsBitmap* Snapshot( TInt aValidIndex );
       
   189 
       
   190         /**
       
   191         * Set the burst array for the model to use
       
   192         * @since 2.8
       
   193         * @param aArray pointer to the burst array
       
   194         */
       
   195         void SetBurstArrayL( CCamBurstCaptureArray* aArray );
       
   196 
       
   197         /**
       
   198         * Returns the grid index for the cell in the top-left of the display
       
   199         * @since 2.8
       
   200         * @return The index to top left cell
       
   201         */
       
   202         TInt TopLeftGridIndex();
       
   203 
       
   204         /**
       
   205         * Returns the position of the highlight.  
       
   206         * @since 2.8
       
   207         * @return The index to the valid (non-deleted) list
       
   208         */
       
   209         TInt HighlightedGridIndex();
       
   210 
       
   211         /**
       
   212         * Returns the index of the hightlighted entry in the CONTROLLER's
       
   213         * burst array.  This array includes deleted and NON-DELETED items
       
   214         * @since 2.8
       
   215         * @return The index to the controller's burst array
       
   216         */
       
   217         TInt HighlightedBurstIndex();        
       
   218 
       
   219         /**
       
   220         * Sets (or clears) the selection 'mark' of the currently highlighted
       
   221         * cell item
       
   222         * @since 2.8
       
   223         * @param aSet Whether to set or clear the mark
       
   224         */
       
   225         void SetCurrentMark( TBool aSet );
       
   226 
       
   227         /**
       
   228         * Marks or un-marks all non-deleted items
       
   229         * @since 2.8
       
   230         * @param aMark ETrue to set the mark, EFalse to clear it.
       
   231         */
       
   232         void MarkAll( TBool aMark );
       
   233 
       
   234         /**
       
   235         * Returns the number of images that have been "marked"
       
   236         * @since 2.8
       
   237         * @return The number of marked images.
       
   238         */
       
   239         TInt NoOfMarkedImages() const;
       
   240 
       
   241         /**
       
   242         * Returns the total number of images including 'deleted' images
       
   243         * @since 2.8
       
   244         * @return The number of images.
       
   245         */
       
   246         TInt NoOfImages() const;
       
   247 
       
   248         /**
       
   249         * Returns whether the specified item is marked or not.
       
   250         * @since 2.8
       
   251         * @param  aIndex The index of the item to check
       
   252         * @return ETrue if it is marked, else EFalse
       
   253         */
       
   254         TInt IsMarkedL( TInt aIndex );
       
   255 
       
   256         /**
       
   257         * Deletes all marked items
       
   258         * @since 2.8        
       
   259         */        
       
   260         void DeleteMarkedL();
       
   261 
       
   262         /**
       
   263         * Deletes currently highlighted object
       
   264         * @since 2.8        
       
   265         */   
       
   266         void DeleteHighlightL();        
       
   267 
       
   268         /**
       
   269         * Adds an observer to a specified set of events
       
   270         * @since 2.8
       
   271         * @param aObserver The component to be notified
       
   272         * @param aBitMask The bitmask of events to be reported
       
   273         */
       
   274         void AddModelObserverL( MThumbModelObserver* aObserver, TInt aBitMask );
       
   275         
       
   276         /**
       
   277         * Remove an observer to a specified set of events
       
   278         * @since 2.8
       
   279         * @param aObserver The component to not be notified
       
   280         * @param aBitMask The bitmask of events to not be reported
       
   281         */
       
   282         void RemoveModelObserver( MThumbModelObserver* aObserver, TInt aBitMask );
       
   283 
       
   284         /**
       
   285         * Notify all observers to a specific event
       
   286         * @since 2.8
       
   287         * @param aEvent The event which has occurred.
       
   288         * @param aParam Optional parameter to be passed with the event
       
   289         */
       
   290         void NotifyModelObserver( TModelEvent aEvent, TInt aParam = 0 );
       
   291 
       
   292         /**
       
   293         * Returns the image name (no path or extension) of the currently 
       
   294         * highlighted item.
       
   295         * @since 2.8
       
   296         * @return The image name
       
   297         */
       
   298         TPtrC HighlightedImageName();       
       
   299         
       
   300         /**
       
   301         * Returns the height of the visible grid, typically 2 or 3 cells high.
       
   302         * @since 2.8
       
   303         * @returns the height of the visible grid.
       
   304         */
       
   305         TInt GridHeight();
       
   306         
       
   307         /**
       
   308         * Returns the image name (no path or extension) of an item.
       
   309         * @since 2.8
       
   310         * @param aIndex The index of the item.
       
   311         * @return The image name
       
   312         */
       
   313         TPtrC ImageName( TInt aIndex );
       
   314 
       
   315         /**
       
   316         * Returns the image name (with path and extension) of an item.
       
   317         * Uses the index in the global array (including deleted items)
       
   318         * @since 2.8
       
   319         * @param aIndex The index of the item (in the global array).
       
   320         * @return The image full name and path
       
   321         */
       
   322         TPtrC ImageFileName( TInt aIndex ) const;
       
   323         
       
   324         /**
       
   325         * Refreshes internal state by checking whether the currently
       
   326         * highlighted item has been deleted.  This may happen if an item
       
   327         * is viewed in post capture, then deleted.
       
   328         * @since 2.8
       
   329         */
       
   330         void RefreshL();
       
   331 
       
   332         /**
       
   333         * Used to update where the top-left view on the grid is located.
       
   334         * @since 2.8
       
   335         * @param aMovingUp whether the update is because the curor is moving up.
       
   336         */
       
   337         void UpdateViewableGrid( TBool aMovingUp );
       
   338 
       
   339         /**
       
   340         * Converts from the "valid-only" list of items to the global "AllThumb"
       
   341         * list.
       
   342         * @since 2.8
       
   343         * @param aValidIndex The valid index to convert from.
       
   344         * @return The global index, or KErrNotFound.
       
   345         */
       
   346         TInt ConvertFromValidToGlobalIndex( TInt aValidIndex );
       
   347         
       
   348         /**
       
   349          * 
       
   350          */
       
   351         void ScrollGrid( TBool aScrollDown, TInt aNewScrollPos );
       
   352 
       
   353         /**
       
   354         * Cancels the thumbnail scaling
       
   355         * @since 2.8
       
   356         */
       
   357         void CancelThumbnails();
       
   358         
       
   359         /**
       
   360          * Notifies model that images have been deleted outside of camera
       
   361          */
       
   362         void ImageFilesDeleted();
       
   363 
       
   364     public: // Functions from base classes
       
   365         /**
       
   366         * Called by sizer utility class when a bitmap rescale operation 
       
   367         * has completed.
       
   368         * @since 2.8
       
   369         * @param aErr Indicates the completion code (standard epoc error codes possible)
       
   370         * @param aBitmap The resized bitmap (called class takes ownership)
       
   371         */
       
   372         void BitmapScaleCompleteL( TInt aErr, CFbsBitmap* aBitmap, TInt32 aInfo );
       
   373 
       
   374     protected:  // New functions
       
   375 
       
   376     protected:  // Functions from base classes
       
   377 
       
   378     private:
       
   379 
       
   380         /**
       
   381         * C++ default constructor.
       
   382         */
       
   383         CCamBurstThumbnailGridModel();
       
   384 
       
   385         /**
       
   386         * By default Symbian 2nd phase constructor is private.
       
   387         */
       
   388         void ConstructL();
       
   389 
       
   390         /**
       
   391         * Adds the specified cell to the internal structures.  Takes ownership
       
   392         * of the supplied cell object
       
   393         * @since 2.8
       
   394         * @param aCell The grid item to add
       
   395         */
       
   396         void AddCellL( CThumbnailGridItem* aCell );
       
   397 
       
   398         /**
       
   399         * Used for the generation of the specified thumbnail
       
   400         * @since 2.8
       
   401         * @param aIndex The index (global) of the item to resize
       
   402         */
       
   403         void StartThumbnailL( TInt aIndex );
       
   404     
       
   405         /**
       
   406         * Force a check for thumbs; deleting those not visible and generating
       
   407         * new thumbs for newly visible cells.  
       
   408         * @since 2.8        
       
   409         */
       
   410         void RecalculateThumbs();
       
   411 
       
   412         /**
       
   413         * Queues thumbnails to be resized as required.
       
   414         * @since 2.8        
       
   415         */
       
   416         void QueueThumbnailsL();
       
   417 
       
   418         /**
       
   419         * Internal function used by the various delete functions
       
   420         * @since 2.8
       
   421         * @param aGlobalIndex The global index of the item to delete
       
   422         */
       
   423         void DeleteItemL( TInt aGlobalIndex );
       
   424 
       
   425         /**
       
   426         * Internal function used by the various delete functions
       
   427         * @since 2.8
       
   428         * @param aHighlightDeleted Whether the delete operation this call 
       
   429         *        followed involved the deletion of the highlight
       
   430         */
       
   431         void DoPostDeleteGridCheck( TBool aHighlightDeleted );
       
   432               
       
   433 
       
   434     private:    // Data
       
   435         TInt iCurrHighlight;    // Grid index of current highlight
       
   436         TInt iImagesMarked;     // Number of images marked
       
   437         TInt iTmpThumbIndex;    // The record we are creating a thumb for
       
   438 
       
   439         // An array of ALL thumbnail grid items, the "global" list.
       
   440         // Includes delete and non-deleted
       
   441         RPointerArray <CThumbnailGridItem> iAllThumbGrid;
       
   442 
       
   443         // An array of VALID (non-deleted) items only.
       
   444         RPointerArray <CThumbnailGridItem> iValidThumbGrid;
       
   445         
       
   446 
       
   447         // Pointer to the burst mode capture array.
       
   448         CCamBurstCaptureArray* iBurstArray;     // Not owned
       
   449 
       
   450         // Utility class used for resizing bitmaps
       
   451         CCamThumbnailGridSizer* iGridSizer;
       
   452 
       
   453         // Current internal state (referring to resizing)
       
   454         TTmbState iState;
       
   455 
       
   456         // List of objects requesting bitmap state updates
       
   457         RPointerArray <MThumbModelObserver> iThumbObserver;
       
   458 
       
   459         // Array of observers for the hightlight changed
       
   460         RPointerArray <MThumbModelObserver> iHighlightObserver;
       
   461 
       
   462         // Array of observers for the delete events
       
   463         RPointerArray <MThumbModelObserver> iDeleteObserver;
       
   464 
       
   465         // Grid index of "top left" cell.
       
   466         TInt iTopLeftIndex;
       
   467         
       
   468         // Either 2 (if upto 6 images) or 3 (if more than 6 images)
       
   469         TInt iGridHeight;
       
   470         
       
   471         // Size of the scaled thumbnails
       
   472         TSize iThumbSize;
       
   473     }; 
       
   474 
       
   475 
       
   476 #endif      // CAMBURSTTHUMBNAILGRIDMODEL_H
       
   477             
       
   478 // End of File
       
   479 
       
   480