camerauis/cameraapp/generic/src/CamCaptureSetupMenuListItemDrawer.cpp
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:  Draws a list item.*
       
    15 */
       
    16 
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include	<AknsDrawUtils.h>
       
    20 #include  <AknUtils.h>
       
    21 #include  <barsread.h>
       
    22 #include  <AknsFrameBackgroundControlContext.h>
       
    23 
       
    24 #include <cameraapp.rsg>
       
    25 #include <vgacamsettings.rsg>
       
    26 
       
    27 #include	"CamCaptureSetupMenuListItemDrawer.h"
       
    28 #include	"CamCaptureSetupMenuListBoxModel.h"
       
    29 
       
    30 #include "camlogging.h"
       
    31 
       
    32 // ================= MEMBER FUNCTIONS =======================
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // NewL
       
    36 // Two-phased constructor.
       
    37 // Returns: CCamCaptureSetupMenuListItemDrawer*: Pointer to the created list item drawer.
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CCamCaptureSetupMenuListItemDrawer* CCamCaptureSetupMenuListItemDrawer::NewL(
       
    41     CCamCaptureSetupMenuListBoxModel* aListBoxModel, // used to get content information about list item being drawn.
       
    42     TResourceReader& aReader ) // used to read layout information about list items to be drawn.
       
    43     {
       
    44     CCamCaptureSetupMenuListItemDrawer* self = 
       
    45         new (ELeave) CCamCaptureSetupMenuListItemDrawer( aListBoxModel );
       
    46     CleanupStack::PushL( self );
       
    47     self->ConstructFromResourceL( aReader );
       
    48     CleanupStack::Pop( self );
       
    49     return self;
       
    50     }
       
    51 
       
    52 
       
    53 // ---------------------------------------------------------
       
    54 // CCamCaptureSetupMenuListItemDrawer::DrawActualItem
       
    55 // Draws item and highlights if needed
       
    56 // ---------------------------------------------------------
       
    57 //
       
    58 void CCamCaptureSetupMenuListItemDrawer::DrawActualItem( 
       
    59     TInt aItemIndex,                // index of item
       
    60     const TRect& aActualItemRect,   // rectangular area of item
       
    61     TBool aItemIsCurrent,           // ETrue if current item
       
    62     TBool /*aViewIsEmphasized*/,        // ETrue if emphasized
       
    63 	TBool /*aViewIsDimmed*/,        // ETrue if dimmed
       
    64     TBool /*aItemIsSelected*/ ) const   // ETrue if selected
       
    65 	{
       
    66     // Draw unhighlighted rectangle that encapsulates the item text and bitmap.
       
    67 	DrawItemRect( aActualItemRect );       
       
    68 
       
    69     // ...if the item is the current item highlight it.
       
    70 	if ( aItemIsCurrent )
       
    71 		{
       
    72 		DrawHighlightedItemRect( aActualItemRect );
       
    73 		}
       
    74 
       
    75     // Draw the text.
       
    76     // ...Create a text layout object for drawing the text
       
    77     // ...inside of the list item's rectangle.
       
    78     TAknLayoutText layoutText;
       
    79     layoutText.LayoutText( aActualItemRect, iLayoutDataForText );
       
    80     // get the text color from the skin
       
    81     TRgb textColor;
       
    82     MAknsSkinInstance *skin = AknsUtils::SkinInstance();
       
    83     // default is list item text colour
       
    84     TAknsQsnTextColorsIndex index = EAknsCIQsnTextColorsCG7;
       
    85     if( Flags() & CListItemDrawer::ESingleClickDisabledHighlight )
       
    86         {
       
    87         aItemIsCurrent = EFalse;
       
    88         }
       
    89     if ( aItemIsCurrent )
       
    90 		{
       
    91         index = EAknsCIQsnTextColorsCG10; // list highlight text
       
    92         }
       
    93     AknsUtils::GetCachedColor( skin, textColor, KAknsIIDQsnTextColors, index );
       
    94     // ...Pass the text to be drawn, into the text layout object
       
    95     // ...and draw it.
       
    96     const TDesC& itemText = iModel->TextForItem( aItemIndex );
       
    97     layoutText.DrawText( *iGc, itemText, ETrue, textColor );
       
    98 
       
    99 	if ( !iModel->ItemHasIconText( aItemIndex ) )
       
   100 		{
       
   101 		// Draw the bitmap.
       
   102 		// Create a rect layout object for drawing the bitmap
       
   103 		//  inside of the list item's rectangle.
       
   104 		TAknLayoutRect layoutRect;
       
   105 		layoutRect.LayoutRect( aActualItemRect, iLayoutDataForBitmap );
       
   106 		// Pass the bitmap to be drawn, into the rect layout object and draw it.
       
   107 		CFbsBitmap* bitmap = iModel->BitmapForItem( aItemIndex, EFalse );
       
   108 		CFbsBitmap* mask = iModel->BitmapForItem( aItemIndex, ETrue );
       
   109     
       
   110 		AknIconUtils::SetSize( bitmap, TSize( iLayoutDataForBitmap.iW, 
       
   111 											  iLayoutDataForBitmap.iH ),
       
   112 											  EAspectRatioPreserved );
       
   113 
       
   114 		layoutRect.DrawImage( *iGc, bitmap, mask );
       
   115 		}
       
   116 	else
       
   117 		{
       
   118 		const TDesC& iconText = iModel->IconTextForItem( aItemIndex );
       
   119 		layoutText.LayoutText( aActualItemRect, iLayoutDataForIconText );
       
   120 	    layoutText.DrawText( *iGc, iconText, ETrue, textColor );
       
   121 		}
       
   122 	}
       
   123 
       
   124 // ---------------------------------------------------------
       
   125 // CCamCaptureSetupMenuListItemDrawer::CCamCaptureSetupMenuListItemDrawer
       
   126 // Constructor
       
   127 // ---------------------------------------------------------
       
   128 //
       
   129 CCamCaptureSetupMenuListItemDrawer::CCamCaptureSetupMenuListItemDrawer( 
       
   130     CCamCaptureSetupMenuListBoxModel* aListBoxModel ) // used to get information about item that drawing.
       
   131 	:iModel( aListBoxModel )
       
   132 	{
       
   133 	}
       
   134 
       
   135 // ---------------------------------------------------------
       
   136 // CCamCaptureSetupMenuListItemDrawer::~CCamCaptureSetupMenuListItemDrawer
       
   137 // Destructor
       
   138 // ---------------------------------------------------------
       
   139 //
       
   140 CCamCaptureSetupMenuListItemDrawer::~CCamCaptureSetupMenuListItemDrawer()
       
   141     {
       
   142     }
       
   143 
       
   144 // ---------------------------------------------------------
       
   145 // CCamCaptureSetupMenuListItemDrawer::ConstructL
       
   146 // 2nd phase constructor
       
   147 // ---------------------------------------------------------
       
   148 //
       
   149 void CCamCaptureSetupMenuListItemDrawer::ConstructFromResourceL
       
   150 ( TResourceReader& aReader )
       
   151     {
       
   152     // Read the text layout from resource.
       
   153     iLayoutDataForText.iFont = aReader.ReadInt16();
       
   154     iLayoutDataForText.iC = aReader.ReadInt16();
       
   155     iLayoutDataForText.iL = aReader.ReadInt16();
       
   156     iLayoutDataForText.iR = aReader.ReadInt16();
       
   157     iLayoutDataForText.iB = aReader.ReadInt16();
       
   158     iLayoutDataForText.iW = aReader.ReadInt16();
       
   159     iLayoutDataForText.iJ = aReader.ReadInt16();
       
   160 
       
   161     // Read the text layout from resource.
       
   162     iLayoutDataForBitmap.iC = aReader.ReadInt16();
       
   163     iLayoutDataForBitmap.iL = aReader.ReadInt16();
       
   164     iLayoutDataForBitmap.iT = aReader.ReadInt16();
       
   165     iLayoutDataForBitmap.iR = aReader.ReadInt16();
       
   166     iLayoutDataForBitmap.iB = aReader.ReadInt16();
       
   167     iLayoutDataForBitmap.iW = aReader.ReadInt16();
       
   168     iLayoutDataForBitmap.iH = aReader.ReadInt16();
       
   169 
       
   170     // Read the icon text layout from resource.
       
   171     iLayoutDataForIconText.iFont = aReader.ReadInt16();
       
   172     iLayoutDataForIconText.iC = aReader.ReadInt16();
       
   173     iLayoutDataForIconText.iL = aReader.ReadInt16();
       
   174     iLayoutDataForIconText.iR = aReader.ReadInt16();
       
   175     iLayoutDataForIconText.iB = aReader.ReadInt16();
       
   176     iLayoutDataForIconText.iW = aReader.ReadInt16();
       
   177     iLayoutDataForIconText.iJ = aReader.ReadInt16();
       
   178 
       
   179     // Read the highlight offset amount from resource.
       
   180     iHighlightOffset = aReader.ReadInt16();
       
   181     }
       
   182 
       
   183 // ---------------------------------------------------------
       
   184 // CCamCaptureSetupMenuListItemDrawer::DrawHighlightedRect
       
   185 // Draws a highlighted rectangle
       
   186 // ---------------------------------------------------------
       
   187 //
       
   188 void CCamCaptureSetupMenuListItemDrawer::DrawHighlightedItemRect( 
       
   189     const TRect& aActualItemRect ) // the rectangular area to be highlighted
       
   190     const
       
   191 	{
       
   192     if( Flags() & CListItemDrawer::ESingleClickDisabledHighlight )
       
   193         {
       
   194         return;
       
   195         }
       
   196 
       
   197 	MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   198 
       
   199     TRect innerRect( aActualItemRect );
       
   200     innerRect.Shrink( iHighlightOffset, iHighlightOffset );
       
   201     AknsDrawUtils::DrawFrame( skin, *iGc, aActualItemRect, innerRect, 
       
   202                               KAknsIIDQsnFrList, KAknsIIDDefault );
       
   203 	}
       
   204 
       
   205 
       
   206 // ---------------------------------------------------------
       
   207 // CCamCaptureSetupMenuListItemDrawer::DrawItemRect
       
   208 // Draws a rectangle for an item.
       
   209 // ---------------------------------------------------------
       
   210 //
       
   211 void CCamCaptureSetupMenuListItemDrawer::DrawItemRect( 
       
   212     const TRect& aActualItemRect ) // the rectangular area to be drawn
       
   213     const
       
   214     {
       
   215     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   216     MAknsControlContext *cc = AknsDrawUtils::ControlContext( iParentControl ); 
       
   217     AknsDrawUtils::Background( skin, cc, iParentControl, *iGc, aActualItemRect );
       
   218 #if 0
       
   219 	iGc->SetBrushColor( KRgbRed );
       
   220 	iGc->SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   221 	iGc->SetPenStyle( CGraphicsContext::ENullPen );	// shadow drawn later
       
   222     iGc->DrawRect( aActualItemRect );
       
   223 #endif
       
   224     }
       
   225 
       
   226 
       
   227 // ---------------------------------------------------------
       
   228 // CCamCaptureSetupMenuListItemDrawer::SetControl
       
   229 // Sets the parent control of the listbox
       
   230 // ---------------------------------------------------------
       
   231 //
       
   232 void CCamCaptureSetupMenuListItemDrawer::SetParentControl( 
       
   233     const CCoeControl* aControl )
       
   234     {
       
   235     iParentControl = aControl;
       
   236     }
       
   237 
       
   238 //End of file
       
   239 
       
   240