camerauis/cameraapp/generic/src/cambatterypanedrawer.cpp
changeset 19 d9aefe59d544
parent 3 8b2d6d0384b0
child 21 fa6d9f75d6a6
child 28 3075d9b614e6
equal deleted inserted replaced
3:8b2d6d0384b0 19:d9aefe59d544
     1 /*
       
     2 * Copyright (c) 2007-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 // ---------------------------------------------------------------------------
       
    55 // CCamBatteryPaneDrawer::CCamBatteryPaneDrawer
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 CCamBatteryPaneDrawer::CCamBatteryPaneDrawer()
       
    59     {
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // CCamBatteryPaneDrawer::~CCamBatteryPaneDrawer
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 CCamBatteryPaneDrawer::~CCamBatteryPaneDrawer()
       
    67   {
       
    68   PRINT ( _L("Camera => ~CCamBatteryPaneDrawer") ); 	
       
    69   
       
    70   DeleteIcons();       
       
    71   
       
    72   PRINT ( _L("Camera <= ~CCamBatteryPaneDrawer") ); 
       
    73   }
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // CCamBatteryPaneDrawer::NewL
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 CCamBatteryPaneDrawer* CCamBatteryPaneDrawer::NewL()
       
    80     {
       
    81     PRINT ( _L("Camera => CCamBatteryPaneDrawer::NewL") ); 	    	
       
    82     
       
    83     CCamBatteryPaneDrawer* self = new (ELeave) CCamBatteryPaneDrawer();
       
    84 
       
    85     CleanupStack::PushL( self );
       
    86     self->ConstructL();
       
    87     CleanupStack::Pop(); // self
       
    88     PRINT ( _L("Camera <= CCamBatteryPaneDrawer::NewL") );    
       
    89     return self;
       
    90     }
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // CCamBatteryPaneDrawer::ConstructL
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 void CCamBatteryPaneDrawer::ConstructL()
       
    97     {
       
    98     PRINT( _L("Camera => CCamBatteryPaneDrawer::ConstructL") );	
       
    99     
       
   100     // Load icon bitmaps
       
   101     LoadIconsL();
       
   102     // Load/calculate layout data
       
   103     LoadLayoutsL();
       
   104 
       
   105     PRINT( _L("Camera <= CCamBatteryPaneDrawer::ConstructL") );	
       
   106     }
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 // CCamBatteryPaneDrawer::SetBatteryStrength
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 void CCamBatteryPaneDrawer::SetBatteryStrength( TInt aBatteryStrength )
       
   113     {
       
   114     iBatteryStrength = aBatteryStrength;
       
   115     }
       
   116     
       
   117 // ---------------------------------------------------------------------------
       
   118 // CCamBatteryPaneDrawer::SetLocation
       
   119 // ---------------------------------------------------------------------------    
       
   120 //
       
   121 void CCamBatteryPaneDrawer::SetLocation( const TPoint& aLocation )
       
   122     {
       
   123     iRect = TRect( aLocation, iRect.Size() );
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // CCamBatteryPaneDrawer::LoadIconsL
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 void CCamBatteryPaneDrawer::LoadIconsL()
       
   131     {    
       
   132     PRINT( _L("Camera => CCamBatteryPaneDrawer::LoadIconsL") );	
       
   133     
       
   134     // Delete existing icon bitmaps
       
   135     DeleteIcons();
       
   136 
       
   137     // Load and resize battery icon and mask
       
   138     delete iBatteryIcon;
       
   139     iBatteryIcon = NULL;
       
   140     iBatteryIcon = CCamBitmapItem::NewL(
       
   141         EMbmCameraappQgn_prop_cam_battery_icon,
       
   142         EMbmCameraappQgn_prop_cam_battery_icon_mask );
       
   143     
       
   144     // Load and resize battery strength icon and mask    
       
   145     delete iBatteryStrengthIcon;
       
   146     iBatteryStrengthIcon = NULL;
       
   147     iBatteryStrengthIcon = CCamBitmapItem::NewL(
       
   148         EMbmCameraappQgn_indi_cam_battery_strength,
       
   149         EMbmCameraappQgn_indi_cam_battery_strength_mask );                            
       
   150 
       
   151     PRINT( _L("Camera <= CCamBatteryPaneDrawer::LoadIconsL") );	       
       
   152     }
       
   153     
       
   154 
       
   155 // ---------------------------------------------------------------------------
       
   156 // CCamBatteryPaneDrawer::Rect
       
   157 // ---------------------------------------------------------------------------    
       
   158 //
       
   159 TRect CCamBatteryPaneDrawer::Rect() const
       
   160 	{		
       
   161 	return iRect;
       
   162 	}
       
   163 
       
   164 // ---------------------------------------------------------------------------
       
   165 // CCamBatteryPaneDrawer::Draw
       
   166 // ---------------------------------------------------------------------------
       
   167 //
       
   168 void CCamBatteryPaneDrawer::Draw( CBitmapContext& aGc ) const
       
   169     {
       
   170     // Make sure that no brush is being used
       
   171     aGc.SetBrushStyle( CGraphicsContext::ENullBrush );    
       
   172 
       
   173     if( iBatteryStrengthIcon )
       
   174         {
       
   175         TSize iconSize = iBatteryStrengthIcon->BitmapSize();
       
   176 
       
   177         TRect strengthIconCropRect(
       
   178             0,
       
   179             iconSize.iHeight - BatteryStrengthIconHeight( iBatteryStrength ),
       
   180             iconSize.iWidth,
       
   181             iconSize.iHeight );
       
   182 
       
   183         // Draw the icon, with correct battery strength
       
   184         iBatteryStrengthIcon->DrawPartial( 
       
   185             aGc,
       
   186             iBatteryStrengthIcon->LayoutRect(),
       
   187             strengthIconCropRect );
       
   188         }
       
   189 
       
   190     if( iBatteryIcon )
       
   191         {
       
   192         iBatteryIcon->Draw( aGc );
       
   193         }    
       
   194     }       
       
   195 
       
   196 // ---------------------------------------------------------------------------
       
   197 // CCamBatteryPaneDrawer::ClearBattery
       
   198 // ---------------------------------------------------------------------------
       
   199 //
       
   200 void CCamBatteryPaneDrawer::ClearBattery( CBitmapContext& aGc ) const
       
   201     {   
       
   202     PRINT( _L("Camera => CCamBatteryPaneDrawer::ClearBattery") ); 
       
   203     
       
   204     // Get the battery pane rectangle   
       
   205     const TRect rect = Rect();                            
       
   206     aGc.SetPenStyle( CGraphicsContext::ENullPen );
       
   207     aGc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   208     aGc.SetDrawMode( CGraphicsContext::EDrawModeWriteAlpha );
       
   209     aGc.SetBrushColor( TRgb::Color16MA( 0 ) );
       
   210     aGc.Clear( rect ); //DrawRect( rect );
       
   211     PRINT( _L("Camera <= CCamBatteryPaneDrawer::ClearBattery") );  
       
   212     }
       
   213     
       
   214 // ---------------------------------------------------------------------------
       
   215 // CCamBatteryPaneDrawer::LoadLayoutsL
       
   216 // ---------------------------------------------------------------------------    
       
   217 //
       
   218 void CCamBatteryPaneDrawer::LoadLayoutsL()
       
   219     {    
       
   220     PRINT( _L("Camera => CCamBatteryPaneDrawer::LoadLayoutsL") );	    	
       
   221     if ( CamUtility::IsNhdDevice() )
       
   222         {
       
   223         TouchLayoutL();
       
   224         }
       
   225     else
       
   226         {
       
   227         NonTouchLayoutL();
       
   228         }       
       
   229     }
       
   230 
       
   231 
       
   232 // ---------------------------------------------------------------------------
       
   233 // CCamBatteryPaneDrawer::BatteryStrengthIconHeight
       
   234 // ---------------------------------------------------------------------------    
       
   235 //
       
   236 TInt CCamBatteryPaneDrawer::BatteryStrengthIconHeight( TInt aLevel ) const
       
   237     {
       
   238     TInt cellHeight = KCamDefaultBatteryCellHeight;
       
   239     if ( iBatteryStrengthIcon )
       
   240         {
       
   241         cellHeight = iBatteryStrengthIcon->BitmapSize().iHeight /
       
   242             KMaxBatteryStrength;
       
   243         }
       
   244     return ( aLevel * cellHeight ) + KCamDefaultBatteryCellMargin;
       
   245     }
       
   246 
       
   247 // ---------------------------------------------------------------------------
       
   248 // CCamBatteryPaneDrawer::DeleteIcons
       
   249 // ---------------------------------------------------------------------------
       
   250 //
       
   251 void CCamBatteryPaneDrawer::DeleteIcons()
       
   252     {
       
   253     delete iBatteryIcon;
       
   254     iBatteryIcon = NULL;
       
   255     delete iBatteryStrengthIcon;
       
   256     iBatteryStrengthIcon = NULL;
       
   257     }
       
   258 
       
   259 // ---------------------------------------------------------------------------
       
   260 // CCamBatteryPaneDrawer::HandleResourceChange
       
   261 // ---------------------------------------------------------------------------    
       
   262 //   
       
   263 void CCamBatteryPaneDrawer::HandleResourceChange( TInt /* aType */ )
       
   264     {
       
   265     PRINT( _L("Camera => CCamBatteryPaneDrawer::HandleResourceChange") );	    	
       
   266     	
       
   267     // Called when either skin or color scheme has changed.
       
   268     // We need to reload icons and re-create the battery color bitmap.
       
   269     
       
   270         
       
   271     // Reload icons
       
   272     TRAP_IGNORE(LoadIconsL());
       
   273 	TRAP_IGNORE(LoadLayoutsL());	
       
   274       
       
   275     PRINT( _L("Camera <= CCamBatteryPaneDrawer::HandleResourceChange") );        
       
   276     }
       
   277 
       
   278 // ---------------------------------------------------------------------------
       
   279 // CCamBatteryPaneDrawer::NonTouchLayout
       
   280 // ---------------------------------------------------------------------------    
       
   281 void CCamBatteryPaneDrawer::NonTouchLayoutL() 
       
   282     {
       
   283     TRect screen;
       
   284     TAknLayoutRect indicatorsPane;
       
   285     TAknLayoutRect batteryPane;
       
   286     TInt cba =  AknLayoutUtils::CbaLocation() == 
       
   287                 AknLayoutUtils::EAknCbaLocationLeft? 
       
   288                 AknLayoutUtils::EAknCbaLocationLeft : 0;
       
   289  
       
   290     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EScreen, screen );
       
   291     indicatorsPane.LayoutRect( screen,
       
   292         AknLayoutScalable_Apps::cam6_indi_pane( cba ));
       
   293     batteryPane.LayoutRect( indicatorsPane.Rect(),
       
   294         AknLayoutScalable_Apps::cam6_battery_pane( cba ) );
       
   295     iRect = batteryPane.Rect();
       
   296 
       
   297     // Battery icon
       
   298     if ( iBatteryIcon )
       
   299         {
       
   300         iBatteryIcon->SetLayoutL( iRect,
       
   301             AknLayoutScalable_Apps::cam6_battery_pane_g1( cba ));
       
   302         }
       
   303 
       
   304     // Battery strength icon    
       
   305     if ( iBatteryStrengthIcon )
       
   306         {
       
   307         iBatteryStrengthIcon->SetLayoutL( iRect,
       
   308             AknLayoutScalable_Apps::cam6_battery_pane_g2( cba ));
       
   309         }
       
   310     }
       
   311 
       
   312 // ---------------------------------------------------------------------------
       
   313 // CCamBatteryPaneDrawer::TouchLayoutL
       
   314 // ---------------------------------------------------------------------------    
       
   315 void CCamBatteryPaneDrawer::TouchLayoutL()
       
   316     {
       
   317     TRect screen;
       
   318     TAknLayoutRect indicatorsPane;
       
   319     TAknLayoutRect batteryPane;
       
   320     TInt var = Layout_Meta_Data::IsLandscapeOrientation();
       
   321 
       
   322     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EScreen, screen );
       
   323     indicatorsPane.LayoutRect( screen,
       
   324         AknLayoutScalable_Apps::cam4_indicators_pane( var ).LayoutLine() );
       
   325     batteryPane.LayoutRect( indicatorsPane.Rect(),
       
   326         AknLayoutScalable_Apps::cam4_battery_pane( var ).LayoutLine() );
       
   327     iRect = batteryPane.Rect();
       
   328 
       
   329     // Battery icon
       
   330     if ( iBatteryIcon )
       
   331         {
       
   332         iBatteryIcon->SetLayoutL( iRect,
       
   333             AknLayoutScalable_Apps::cam4_battery_pane_g2( var ).LayoutLine() );
       
   334         }
       
   335 
       
   336     // Battery strength icon    
       
   337     if ( iBatteryStrengthIcon )
       
   338         {
       
   339         iBatteryStrengthIcon->SetLayoutL( iRect,
       
   340             AknLayoutScalable_Apps::cam4_battery_pane_g1( var ).LayoutLine() );
       
   341         }
       
   342     }
       
   343 
       
   344 // End of file
       
   345