mulwidgets/mulcoverflowwidget/src/mulcoverflowtemplate.cpp
changeset 17 3eca7e70b1b8
parent 3 4526337fb576
equal deleted inserted replaced
3:4526337fb576 17:3eca7e70b1b8
     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:  CoverFlow templates Implementation
       
    15  *
       
    16 */
       
    17 
       
    18 //  Include Files
       
    19 
       
    20 #include <AknUtils.h>
       
    21 
       
    22 // Alf Headers
       
    23 #include <alf/alfenv.h>
       
    24 #include <alf/alfbrusharray.h>
       
    25 #include <alf/alfgradientbrush.h>
       
    26 #include <alf/alftextvisual.h>
       
    27 
       
    28 // Class Header
       
    29 #include "mulcoverflowtemplate.h"
       
    30 
       
    31 // Local Headers
       
    32 #include "mulcoverflowcontrol.h"
       
    33 #include "mulbaseelement.h"
       
    34 #include "mulleave.h"
       
    35 #include "mullog.h" //for logs
       
    36 
       
    37 namespace Alf
       
    38     {
       
    39   
       
    40 // ---------------------------------------------------------------------------
       
    41 // MulCoverFlowTemplate
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 MulCoverFlowTemplate::MulCoverFlowTemplate(MulCoverFlowControl &aControl, 
       
    45         MulBaseElement &aBaseElement)
       
    46     {
       
    47     MUL_LOG_ENTRY_EXIT("Mul::MulCoverFlowTemplate::MulCoverFlowTemplate");
       
    48   
       
    49     mData.reset( new (EMM)TMulCoverFlowTemplateImpl);
       
    50     mData->mControl = &aControl;
       
    51     mData->mBaseElement = &aBaseElement;   
       
    52     }
       
    53 
       
    54 
       
    55  void MulCoverFlowTemplate::CreateVisualisation(bool /*aIsLandscape*/,bool /*aIsOrientationChange*/)
       
    56 	{
       
    57 	
       
    58 	}
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // ~MulCoverFlowWidget
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 MulCoverFlowTemplate::~MulCoverFlowTemplate()
       
    65     {
       
    66 
       
    67     }
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // ApplyBrush
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 void MulCoverFlowTemplate::ApplyBrush( CAlfTextVisual& aVisual,
       
    74      const TRgb& aBrushColour, float aBrushOpacity )
       
    75     {
       
    76     MUL_LOG_ENTRY_EXIT("Mul::MulCoverFlowTemplate::ApplyBrush");
       
    77     
       
    78     // Enable brush on the text visual
       
    79     aVisual.EnableBrushesL( ETrue );
       
    80     CAlfBrushArray* brushArray = aVisual.Brushes();
       
    81     if(brushArray)
       
    82 			{
       
    83 			if( brushArray->Count()!=0)
       
    84 				{
       
    85 				//brushArray->Reset();
       
    86 				CAlfGradientBrush& brush = static_cast<CAlfGradientBrush&>(
       
    87 						brushArray->At(0)); 
       
    88 				brush.SetColor( aBrushColour ); 
       
    89 				brush.SetOpacity(aBrushOpacity);
       
    90 				}
       
    91 			else
       
    92 			{
       
    93 			THROW_IF_LEAVES
       
    94 					(
       
    95 					CAlfGradientBrush* brush = CAlfGradientBrush::NewL(
       
    96 					    mData->mControl->Env()  );
       
    97 					// Set the brush colour
       
    98 					brush->SetColor( aBrushColour );
       
    99 					// Apply brush and set the opacity .
       
   100 					aVisual.Brushes()->AppendL( brush, EAlfHasOwnership );    
       
   101 					brush->SetOpacity(aBrushOpacity);   
       
   102 					);
       
   103 				}    
       
   104 			} 
       
   105     }       
       
   106 
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 // GetFontId
       
   110 // ---------------------------------------------------------------------------
       
   111 // 
       
   112 TInt MulCoverFlowTemplate::GetFontId(const UString &aFontStyle,CAlfTextStyleManager& manager)const
       
   113     {
       
   114     MUL_LOG_ENTRY_EXIT("Mul::MulCoverFlowTemplate::GetFontId");
       
   115     TInt fontId = 0;
       
   116     if ( aFontStyle == "qfn_secondary" )
       
   117         {
       
   118         THROW_IF_LEAVES            
       
   119         (
       
   120         fontId = manager.CreatePlatformTextStyleL(EAknLogicalFontSecondaryFont, -1);                    
       
   121         );
       
   122         }
       
   123     else // by default it assumes the primary font.
       
   124         {               
       
   125         THROW_IF_LEAVES            
       
   126         (
       
   127         fontId = manager.CreatePlatformTextStyleL(EAknLogicalFontPrimaryFont, -1);                    
       
   128         );
       
   129         } 
       
   130     return fontId;      
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // IconWindowRect
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 TRect MulCoverFlowTemplate::IconWindowRect(
       
   138         const TAknWindowLineLayout &aLayout,
       
   139         const TRect& aParentRect)
       
   140     {
       
   141     TAknLayoutRect layoutRect ;
       
   142     layoutRect.LayoutRect( aParentRect, aLayout );
       
   143     TRect rect(layoutRect.Rect());
       
   144     return rect;
       
   145     }
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // TextWindowRect
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 TRect MulCoverFlowTemplate::TextWindowRect(
       
   152         const TAknTextLineLayout& aLayout,
       
   153         const TRect& aParentRect)
       
   154     {
       
   155     TAknLayoutText layoutText;
       
   156     layoutText.LayoutText( aParentRect, aLayout );
       
   157     TRect rect(layoutText.TextRect());
       
   158     return rect;
       
   159     }
       
   160 
       
   161 
       
   162 // ---------------------------------------------------------------------------
       
   163 //  UpdateMaxFontWidth
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 int MulCoverFlowTemplate ::UpdateMaxFontWidth(CAlfTextVisual* textVisual)
       
   167     {
       
   168     int maxCharWidth = 0;
       
   169     int fontId = textVisual->TextStyle();
       
   170     const CFont* font = AknLayoutUtils::FontFromId(fontId, NULL);
       
   171     TFontSpec curfontSpec = font->FontSpecInTwips();
       
   172     curfontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightNormal); 
       
   173     maxCharWidth = font->MaxCharWidthInPixels();
       
   174     return maxCharWidth;
       
   175     }
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // SetTextStyle
       
   179 // ---------------------------------------------------------------------------
       
   180 //
       
   181 void MulCoverFlowTemplate:: SetTextStyle(int aTextFontId, CAlfTextVisual& aTextVisual)
       
   182     {
       
   183     MUL_LOG_ENTRY_EXIT("Mul::MulCoverFlowTemplate::SetTextStyle");
       
   184     UString textStyle;
       
   185     switch(aTextFontId)
       
   186         {    
       
   187         case 0: textStyle=UString("qfn_primary");
       
   188         break;
       
   189         
       
   190         case 1: textStyle=UString("qfn_primary");
       
   191         break;
       
   192         
       
   193         case 2: textStyle=UString("qfn_secondary");
       
   194         break;
       
   195         
       
   196         } 
       
   197     CAlfTextStyleManager& manager = aTextVisual.Env().TextStyleManager();
       
   198     aTextVisual.SetTextStyle(GetFontId(textStyle, manager));
       
   199     }
       
   200 
       
   201   }//namespace Alf
       
   202 
       
   203 // End of file.