camerauis/cameraapp/generic/src/cambatterypanedrawer.cpp
branchRCL_3
changeset 24 bac7acad7cb3
child 25 2c87b2808fd7
equal deleted inserted replaced
23:61bc0f252b2b 24:bac7acad7cb3
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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:  Implemantation for CCamBatteryPaneDrawer class.
       
    15 *
       
    16 *  Copyright © 2007-2008 Nokia.  All rights reserved.
       
    17 *  This material, including documentation and any related computer
       
    18 *  programs, is protected by copyright controlled by Nokia.  All
       
    19 *  rights are reserved.  Copying, including reproducing, storing,
       
    20 *  adapting or translating, any or all of this material requires the
       
    21 *  prior written consent of Nokia.  This material also contains
       
    22 *  confidential information which may not be disclosed to others
       
    23 *  without the prior written consent of Nokia.
       
    24 
       
    25 *
       
    26 *
       
    27 */
       
    28 
       
    29 
       
    30 #include "cambatterypanedrawer.h"
       
    31 
       
    32 #include <AknIconUtils.h>
       
    33 #include <AknUtils.h> 
       
    34 #include <cameraapp.mbg>
       
    35 #include <aknconsts.h> // KAvkonBitmapFile
       
    36 #include <fbs.h> // FbsBitmap
       
    37 #include <AknsUtils.h> 
       
    38 #include <AknIconUtils.h>
       
    39 #include <akniconconfig.h>
       
    40 #include <AknLayoutDef.h> // TAknWindowLineLayout
       
    41 #include <aknlayoutscalable_avkon.cdl.h>
       
    42 #include <aknlayoutscalable_apps.cdl.h>
       
    43 #include <layoutmetadata.cdl.h>
       
    44 
       
    45 #include <cameraapp.rsg>
       
    46 #include <vgacamsettings.rsg>
       
    47  
       
    48 #include "CamUtility.h"
       
    49 #include "cambitmapitem.h"
       
    50 
       
    51 const TInt KCamDefaultBatteryCellHeight = 3;
       
    52 const TInt KCamDefaultBatteryCellMargin = 1;
       
    53 
       
    54 const TInt KBatteryStrengthIcons[] = 
       
    55         {
       
    56                 EMbmCameraappQgn_indi_cam4_battery_strength_0,
       
    57                 EMbmCameraappQgn_indi_cam4_battery_strength_1,
       
    58                 EMbmCameraappQgn_indi_cam4_battery_strength_2,
       
    59                 EMbmCameraappQgn_indi_cam4_battery_strength_3,
       
    60                 EMbmCameraappQgn_indi_cam4_battery_strength_4,
       
    61                 EMbmCameraappQgn_indi_cam4_battery_strength_5,
       
    62                 EMbmCameraappQgn_indi_cam4_battery_strength_6,
       
    63                 EMbmCameraappQgn_indi_cam4_battery_strength_7
       
    64         };
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CCamBatteryPaneDrawer::CCamBatteryPaneDrawer
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 CCamBatteryPaneDrawer::CCamBatteryPaneDrawer()
       
    71     {
       
    72     }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // CCamBatteryPaneDrawer::~CCamBatteryPaneDrawer
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 CCamBatteryPaneDrawer::~CCamBatteryPaneDrawer()
       
    79   {
       
    80   PRINT ( _L("Camera => ~CCamBatteryPaneDrawer") ); 	
       
    81   
       
    82   DeleteIcons();       
       
    83   
       
    84   PRINT ( _L("Camera <= ~CCamBatteryPaneDrawer") ); 
       
    85   }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // CCamBatteryPaneDrawer::NewL
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 CCamBatteryPaneDrawer* CCamBatteryPaneDrawer::NewL()
       
    92     {
       
    93     PRINT ( _L("Camera => CCamBatteryPaneDrawer::NewL") ); 	    	
       
    94     
       
    95     CCamBatteryPaneDrawer* self = new (ELeave) CCamBatteryPaneDrawer();
       
    96 
       
    97     CleanupStack::PushL( self );
       
    98     self->ConstructL();
       
    99     CleanupStack::Pop(); // self
       
   100     PRINT ( _L("Camera <= CCamBatteryPaneDrawer::NewL") );    
       
   101     return self;
       
   102     }
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // CCamBatteryPaneDrawer::ConstructL
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 void CCamBatteryPaneDrawer::ConstructL()
       
   109     {
       
   110     PRINT( _L("Camera => CCamBatteryPaneDrawer::ConstructL") );	
       
   111     
       
   112     // Load icon bitmaps
       
   113     LoadIconsL();
       
   114     // Load/calculate layout data
       
   115     LoadLayoutsL();
       
   116 
       
   117     PRINT( _L("Camera <= CCamBatteryPaneDrawer::ConstructL") );	
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // CCamBatteryPaneDrawer::SetBatteryStrength
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 void CCamBatteryPaneDrawer::SetBatteryStrength( TInt aBatteryStrength )
       
   125     {
       
   126     iBatteryStrength = aBatteryStrength;
       
   127     }
       
   128     
       
   129 // ---------------------------------------------------------------------------
       
   130 // CCamBatteryPaneDrawer::SetLocation
       
   131 // ---------------------------------------------------------------------------    
       
   132 //
       
   133 void CCamBatteryPaneDrawer::SetLocation( const TPoint& aLocation )
       
   134     {
       
   135     iRect = TRect( aLocation, iRect.Size() );
       
   136     }
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // CCamBatteryPaneDrawer::LoadIconsL
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 void CCamBatteryPaneDrawer::LoadIconsL()
       
   143     {    
       
   144     PRINT( _L("Camera => CCamBatteryPaneDrawer::LoadIconsL") );	
       
   145     
       
   146     // Delete existing icon bitmaps
       
   147     DeleteIcons();
       
   148 
       
   149     for( TInt index = KMinBatteryStrength; index <= KMaxBatteryStrength; index++ )
       
   150         {
       
   151         iBatteryIcons.AppendL( CCamBitmapItem::NewL( KBatteryStrengthIcons[index], 
       
   152                 KBatteryStrengthIcons[index] + 1) );
       
   153         }
       
   154 
       
   155     PRINT( _L("Camera <= CCamBatteryPaneDrawer::LoadIconsL") );	       
       
   156     }
       
   157     
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 // CCamBatteryPaneDrawer::Rect
       
   161 // ---------------------------------------------------------------------------    
       
   162 //
       
   163 TRect CCamBatteryPaneDrawer::Rect() const
       
   164 	{		
       
   165 	return iRect;
       
   166 	}
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // CCamBatteryPaneDrawer::Draw
       
   170 // ---------------------------------------------------------------------------
       
   171 //
       
   172 void CCamBatteryPaneDrawer::Draw( CBitmapContext& aGc ) const
       
   173     {
       
   174     iBatteryIcons[ iBatteryStrength ]->Draw( aGc );
       
   175     }       
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // CCamBatteryPaneDrawer::ClearBattery
       
   179 // ---------------------------------------------------------------------------
       
   180 //
       
   181 void CCamBatteryPaneDrawer::ClearBattery( CBitmapContext& aGc ) const
       
   182     {   
       
   183     PRINT( _L("Camera => CCamBatteryPaneDrawer::ClearBattery") ); 
       
   184     
       
   185     // Get the battery pane rectangle   
       
   186     const TRect rect = Rect();                            
       
   187     aGc.SetPenStyle( CGraphicsContext::ENullPen );
       
   188     aGc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   189     aGc.SetDrawMode( CGraphicsContext::EDrawModeWriteAlpha );
       
   190     aGc.SetBrushColor( TRgb::Color16MA( 0 ) );
       
   191     aGc.Clear( rect ); //DrawRect( rect );
       
   192     PRINT( _L("Camera <= CCamBatteryPaneDrawer::ClearBattery") );  
       
   193     }
       
   194     
       
   195 // ---------------------------------------------------------------------------
       
   196 // CCamBatteryPaneDrawer::LoadLayoutsL
       
   197 // ---------------------------------------------------------------------------    
       
   198 //
       
   199 void CCamBatteryPaneDrawer::LoadLayoutsL()
       
   200     {    
       
   201     PRINT( _L("Camera => CCamBatteryPaneDrawer::LoadLayoutsL") );	    	
       
   202     if ( CamUtility::IsNhdDevice() )
       
   203         {
       
   204         TouchLayoutL();
       
   205         }
       
   206     else
       
   207         {
       
   208         NonTouchLayoutL();
       
   209         }       
       
   210     }
       
   211 
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 // CCamBatteryPaneDrawer::DeleteIcons
       
   215 // ---------------------------------------------------------------------------
       
   216 //
       
   217 void CCamBatteryPaneDrawer::DeleteIcons()
       
   218     {
       
   219     iBatteryIcons.ResetAndDestroy();
       
   220     }
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // CCamBatteryPaneDrawer::HandleResourceChange
       
   224 // ---------------------------------------------------------------------------    
       
   225 //   
       
   226 void CCamBatteryPaneDrawer::HandleResourceChange( TInt /* aType */ )
       
   227     {
       
   228     PRINT( _L("Camera => CCamBatteryPaneDrawer::HandleResourceChange") );	    	
       
   229     	
       
   230     // Called when either skin or color scheme has changed.
       
   231     // We need to reload icons and re-create the battery color bitmap.
       
   232     
       
   233         
       
   234     // Reload icons
       
   235     TRAP_IGNORE(LoadIconsL());
       
   236 	TRAP_IGNORE(LoadLayoutsL());	
       
   237       
       
   238     PRINT( _L("Camera <= CCamBatteryPaneDrawer::HandleResourceChange") );        
       
   239     }
       
   240 
       
   241 // ---------------------------------------------------------------------------
       
   242 // CCamBatteryPaneDrawer::NonTouchLayout
       
   243 // ---------------------------------------------------------------------------    
       
   244 void CCamBatteryPaneDrawer::NonTouchLayoutL() 
       
   245     {
       
   246     TRect screen;
       
   247     TAknLayoutRect indicatorsPane;
       
   248     TAknLayoutRect batteryPane;
       
   249     TInt cba =  AknLayoutUtils::CbaLocation() == 
       
   250                 AknLayoutUtils::EAknCbaLocationLeft? 
       
   251                 AknLayoutUtils::EAknCbaLocationLeft : 0;
       
   252  
       
   253     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EScreen, screen );
       
   254     indicatorsPane.LayoutRect( screen,
       
   255         AknLayoutScalable_Apps::cam6_indi_pane( cba ));
       
   256     batteryPane.LayoutRect( indicatorsPane.Rect(),
       
   257         AknLayoutScalable_Apps::cam6_battery_pane( cba ) );
       
   258     iRect = batteryPane.Rect();
       
   259 	
       
   260     TInt batteryIconsCount = iBatteryIcons.Count();
       
   261     for( TInt index = 0; index < batteryIconsCount; index++ )
       
   262         {
       
   263         iBatteryIcons[index]->SetLayoutL( iRect );
       
   264         }
       
   265     }
       
   266 
       
   267 // ---------------------------------------------------------------------------
       
   268 // CCamBatteryPaneDrawer::TouchLayoutL
       
   269 // ---------------------------------------------------------------------------    
       
   270 void CCamBatteryPaneDrawer::TouchLayoutL()
       
   271     {
       
   272     TRect screen;
       
   273     TAknLayoutRect indicatorsPane;
       
   274     TAknLayoutRect batteryPane;
       
   275     TInt var = Layout_Meta_Data::IsLandscapeOrientation();
       
   276 
       
   277     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EScreen, screen );
       
   278     indicatorsPane.LayoutRect( screen,
       
   279         AknLayoutScalable_Apps::cam4_indicators_pane( var ).LayoutLine() );
       
   280     batteryPane.LayoutRect( indicatorsPane.Rect(),
       
   281         AknLayoutScalable_Apps::cam4_battery_pane( var ).LayoutLine() );
       
   282     iRect = batteryPane.Rect();
       
   283 
       
   284     TInt batteryIconsCount = iBatteryIcons.Count();
       
   285     for( TInt index = 0; index < batteryIconsCount; index++ )
       
   286         {
       
   287         iBatteryIcons[index]->SetLayoutL( iRect );
       
   288         }
       
   289     
       
   290     }
       
   291 
       
   292 // End of file
       
   293