|
1 /* |
|
2 * Copyright (c) 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDES |
|
20 #include <alf/AlfEnv.h> |
|
21 #include <alf/AlfTextureManager.h> |
|
22 #include <alf/AlfTextStyleManager.h> |
|
23 #include <alf/AlfTextStyle.h> |
|
24 #include <alf/AlfGridLayout.h> |
|
25 #include <alf/AlfImageVisual.h> |
|
26 #include <alf/AlfTextVisual.h> |
|
27 |
|
28 #include "AlfPerfAppSuitePeopleControl.h" |
|
29 #include "AlfPerfAppSuiteHelper.h" |
|
30 #include "AlfPerfAppSuiteTestCaseScroll.h" |
|
31 |
|
32 // MACROS |
|
33 #define KRgbSelectionBlue TRgb(0xE99517) |
|
34 |
|
35 // ============================= MEMBER FUNCTIONS ============================== |
|
36 |
|
37 CAlfPerfAppSuitePeopleControl::CAlfPerfAppSuitePeopleControl(CAlfPerfAppSuiteTestCaseScroll* aScrollControl) |
|
38 :iScrollControl(aScrollControl) |
|
39 { |
|
40 } |
|
41 |
|
42 CAlfPerfAppSuitePeopleControl::~CAlfPerfAppSuitePeopleControl() |
|
43 { |
|
44 #ifdef ENABLE_TEXTSTYLES |
|
45 CAlfTextStyleManager& styleManager = Env().TextStyleManager(); |
|
46 for( TInt i=0; i<iTextStyles.Count(); i++ ) |
|
47 { |
|
48 styleManager.DeleteTextStyle( iTextStyles[i] ); |
|
49 } |
|
50 iTextStyles.Close(); |
|
51 #endif |
|
52 } |
|
53 |
|
54 void CAlfPerfAppSuitePeopleControl::ConstructL( |
|
55 CAlfEnv& aEnv, |
|
56 const TSize& aVisibleArea, |
|
57 CAlfLayout* aParentLayout ) |
|
58 { |
|
59 iLoadedImages = 0; |
|
60 iVisibleArea = aVisibleArea; |
|
61 |
|
62 CAlfControl::ConstructL( aEnv ); |
|
63 |
|
64 #ifdef ENABLE_TEXTSTYLES |
|
65 CreateTextStylesL(); |
|
66 #endif |
|
67 |
|
68 // Construct a base layout to add a background |
|
69 CAlfLayout* baseLayout = CAlfLayout::AddNewL( *this, aParentLayout ); |
|
70 TAlfPerfAppSuiteHelper::AddGradientBrushL( baseLayout, KRgbBlack ); |
|
71 TAlfPerfAppSuiteHelper::AddDropShadowBrushL( baseLayout, KRgbGray, 1 ); |
|
72 |
|
73 // Create a grid layout as a base |
|
74 CAlfGridLayout* gridLayout = CAlfGridLayout::AddNewL( *this, 1, 1, baseLayout ); |
|
75 gridLayout->SetPadding( 4 ); |
|
76 |
|
77 // Add Header row |
|
78 RArray<TInt> rowHeights; |
|
79 rowHeights.Append( 100 ); |
|
80 |
|
81 // Images |
|
82 _LIT( KImage1, "people.png" ); |
|
83 |
|
84 CAlfTextureManager& textureManager = Env().TextureManager(); |
|
85 aEnv.TextureManager().AddLoadObserverL( this ); |
|
86 TAlfImage image( |
|
87 textureManager.LoadTextureL( |
|
88 KImage1, |
|
89 EAlfTextureFlagRetainResolution, |
|
90 KAlfAutoGeneratedTextureId ) ); |
|
91 ConstructListHeaderL( gridLayout, image, _L("People"), rowHeights[rowHeights.Count()-1] ); |
|
92 |
|
93 // Add list items |
|
94 rowHeights.Append( 120 ); // 1 |
|
95 ConstructListItemL( gridLayout, _L("Top contacts"), _L("4 contacts"), rowHeights[rowHeights.Count()-1], ETrue ); |
|
96 |
|
97 rowHeights.Append( 100 ); // 2 |
|
98 ConstructListItemL( gridLayout, _L("All contacts"), _L("247 contacts"), rowHeights[rowHeights.Count()-1] ); |
|
99 |
|
100 rowHeights.Append( 80 ); // 3 |
|
101 ConstructListItemL( gridLayout, _L("Communities"), _L("2 communities"), rowHeights[rowHeights.Count()-1] ); |
|
102 |
|
103 rowHeights.Append( 80 ); // 4 |
|
104 ConstructListItemL( gridLayout, _L("Work"), _L("40 contacts"), rowHeights[rowHeights.Count()-1] ); |
|
105 |
|
106 rowHeights.Append( 80 ); // 5 |
|
107 ConstructListItemL( gridLayout, _L("Friends"), _L("23 contacts"), rowHeights[rowHeights.Count()-1] ); |
|
108 |
|
109 rowHeights.Append( 80 ); // 6 |
|
110 ConstructListItemL( gridLayout, _L("Enemies"), _L("1 contact"), rowHeights[rowHeights.Count()-1] ); |
|
111 |
|
112 rowHeights.Append( 80 ); // 7 |
|
113 ConstructListItemL( gridLayout, _L("Fans"), _L("2 contacts"), rowHeights[rowHeights.Count()-1] ); |
|
114 |
|
115 rowHeights.Append( 80 ); // 8 |
|
116 ConstructListItemL( gridLayout, _L("Haters"), _L("1 contact"), rowHeights[rowHeights.Count()-1] ); |
|
117 |
|
118 rowHeights.Append( 80 ); // 9 |
|
119 ConstructListItemL( gridLayout, _L("Lovers"), _L("2 contacts"), rowHeights[rowHeights.Count()-1] ); |
|
120 |
|
121 rowHeights.Append( 80 ); // 10 |
|
122 ConstructListItemL( gridLayout, _L("The Others"), _L("31"), rowHeights[rowHeights.Count()-1] ); |
|
123 |
|
124 // Apply rows |
|
125 gridLayout->SetRows( rowHeights.Count() ); |
|
126 gridLayout->SetRowsL( rowHeights ); |
|
127 |
|
128 // Set grid size |
|
129 gridLayout->SetFlag( EAlfVisualFlagManualSize ); |
|
130 TAlfRealSize size; |
|
131 size.iWidth = iVisibleArea.iWidth; |
|
132 for( TInt i=0; i<rowHeights.Count(); i++ ) |
|
133 { |
|
134 size.iHeight += rowHeights[i]; |
|
135 } |
|
136 gridLayout->SetSize( size, 0 ); |
|
137 |
|
138 // Cleanup |
|
139 rowHeights.Close(); |
|
140 } |
|
141 |
|
142 #ifdef ENABLE_TEXTSTYLES |
|
143 void CAlfPerfAppSuitePeopleControl::CreateTextStylesL() |
|
144 { |
|
145 CAlfTextStyleManager& styleManager = Env().TextStyleManager(); |
|
146 |
|
147 // Create text styles |
|
148 for( TInt i=0; i<ENumberOfTextStyles; i++ ) |
|
149 { |
|
150 iTextStyles.Append( styleManager.CreatePlatformTextStyleL() ); |
|
151 } |
|
152 |
|
153 // NOTE: This will leak memory (S60 5.0 wk 20) |
|
154 // styles are destroyed in TextStyleManager destructor but this is not enough... |
|
155 |
|
156 CAlfTextStyle* style = NULL; |
|
157 style = styleManager.TextStyle( iTextStyles[ETextStyleHeader] ); |
|
158 style->SetTextSizeInTwips( 180 ); |
|
159 |
|
160 style = styleManager.TextStyle( iTextStyles[ETextStyleBig] ); |
|
161 style->SetTextSizeInTwips( 160 ); |
|
162 |
|
163 style = styleManager.TextStyle( iTextStyles[ETextStyleSmall] ); |
|
164 style->SetTextSizeInTwips( 110 ); |
|
165 } |
|
166 #endif |
|
167 |
|
168 const TInt KNumberOfImages = 1; |
|
169 // ----------------------------------------------------------------------------- |
|
170 // Notify observers that all images have been loaded. |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 void CAlfPerfAppSuitePeopleControl::TextureLoadingCompleted( |
|
174 CAlfTexture& /*aTexture*/, TInt /*aTextureId*/, TInt aErrorCode) |
|
175 { |
|
176 // inform if there is any error |
|
177 if( aErrorCode != KErrNone ) |
|
178 { |
|
179 iScrollControl->ImagesLoaded( aErrorCode ); |
|
180 } |
|
181 |
|
182 iLoadedImages++; |
|
183 if (iLoadedImages == KNumberOfImages) |
|
184 { |
|
185 iScrollControl->ImagesLoaded( KErrNone ); |
|
186 } |
|
187 } |
|
188 |
|
189 CAlfGridLayout* CAlfPerfAppSuitePeopleControl::ConstructListItemLayoutL( |
|
190 CAlfLayout* aParentLayout, |
|
191 TInt aHeight, |
|
192 TBool aSelected, |
|
193 TBool aBorders ) |
|
194 { |
|
195 // Define weights |
|
196 RArray<TInt> columnWeights; |
|
197 columnWeights.Append( 2 ); |
|
198 columnWeights.Append( 8 ); |
|
199 |
|
200 // Create a grid layout as a base |
|
201 CAlfGridLayout* gridLayout = CAlfGridLayout::AddNewL( |
|
202 *this, columnWeights.Count(), 1, aParentLayout ); |
|
203 gridLayout->SetColumnsL( columnWeights ); |
|
204 columnWeights.Close(); |
|
205 |
|
206 |
|
207 // Set gradient brush if selected |
|
208 if( aSelected ) |
|
209 { |
|
210 TAlfPerfAppSuiteHelper::AddGradientBrushL( gridLayout, KRgbSelectionBlue ); |
|
211 } |
|
212 |
|
213 // Set borders |
|
214 if( aBorders ) |
|
215 { |
|
216 TAlfPerfAppSuiteHelper::AddBorderBrushL( gridLayout, KRgbDarkGray, 0, 2 ); |
|
217 } |
|
218 |
|
219 // Define the size manually |
|
220 gridLayout->SetFlag( EAlfVisualFlagManualSize ); |
|
221 TAlfRealSize size; |
|
222 size.iWidth = iVisibleArea.iWidth; |
|
223 size.iHeight = aHeight; |
|
224 gridLayout->SetSize( size, 0 ); |
|
225 |
|
226 return gridLayout; |
|
227 } |
|
228 |
|
229 CAlfGridLayout* CAlfPerfAppSuitePeopleControl::ConstructListItemTextLayoutL( |
|
230 CAlfLayout* aParentLayout ) |
|
231 { |
|
232 // Define weights |
|
233 RArray<TInt> rowWeights; |
|
234 rowWeights.Append( 1 ); |
|
235 rowWeights.Append( 1 ); |
|
236 |
|
237 // Create a grid layout as a base |
|
238 CAlfGridLayout* gridLayout = CAlfGridLayout::AddNewL( |
|
239 *this, 1, rowWeights.Count(), aParentLayout ); |
|
240 gridLayout->SetRowsL( rowWeights ); |
|
241 rowWeights.Close(); |
|
242 |
|
243 return gridLayout; |
|
244 } |
|
245 |
|
246 void CAlfPerfAppSuitePeopleControl::ConstructListHeaderL( |
|
247 CAlfLayout* aParentLayout, |
|
248 const TAlfImage& aImage, |
|
249 const TDesC& aText, |
|
250 TInt aHeight ) |
|
251 { |
|
252 // Create list item layout |
|
253 CAlfGridLayout* listItemLayout = |
|
254 ConstructListItemLayoutL( aParentLayout, aHeight, EFalse, EFalse ); |
|
255 |
|
256 // Add image visual to first cell of list item layout |
|
257 CAlfImageVisual* imageVisual = CAlfImageVisual::AddNewL( *this, listItemLayout ); |
|
258 imageVisual->SetImage( aImage ); |
|
259 imageVisual->SetScaleMode( CAlfImageVisual::EScaleFitInside ); |
|
260 |
|
261 // Add text visual to second |
|
262 CAlfTextVisual* textVisual = CAlfTextVisual::AddNewL( *this, listItemLayout ); |
|
263 textVisual->SetTextL( aText ); |
|
264 textVisual->SetAlign( EAlfAlignHLeft, EAlfAlignVCenter ); |
|
265 #ifdef ENABLE_TEXTSTYLES |
|
266 textVisual->SetTextStyle( iTextStyles[ETextStyleHeader] ); |
|
267 #endif |
|
268 textVisual->SetColor( KRgbWhite ); |
|
269 } |
|
270 |
|
271 void CAlfPerfAppSuitePeopleControl::ConstructListItemL( |
|
272 CAlfLayout* aParentLayout, |
|
273 const TDesC& aName, |
|
274 const TDesC& aDescription, |
|
275 TInt aHeight, |
|
276 TBool aSelected ) |
|
277 { |
|
278 // Create list item layout |
|
279 CAlfGridLayout* listItemLayout = |
|
280 ConstructListItemLayoutL( aParentLayout, aHeight, aSelected ); |
|
281 |
|
282 // Add blank placeholder to first cell |
|
283 AppendVisualL( EAlfVisualTypeVisual, listItemLayout ); |
|
284 |
|
285 // Create a new layout for text |
|
286 CAlfGridLayout* textLayout = ConstructListItemTextLayoutL( listItemLayout ); |
|
287 |
|
288 // Add name visual to text layout |
|
289 CAlfTextVisual* nameVisual = CAlfTextVisual::AddNewL( *this, textLayout ); |
|
290 nameVisual->SetTextL( aName ); |
|
291 nameVisual->SetAlign( EAlfAlignHLeft, EAlfAlignVBottom ); |
|
292 #ifdef ENABLE_TEXTSTYLES |
|
293 nameVisual->SetTextStyle( iTextStyles[ETextStyleBig] ); |
|
294 #endif |
|
295 nameVisual->SetColor( KRgbWhite ); |
|
296 |
|
297 // Add description to text layout |
|
298 CAlfTextVisual* descriptionVisual = CAlfTextVisual::AddNewL( *this, textLayout ); |
|
299 descriptionVisual->SetTextL( aDescription ); |
|
300 descriptionVisual->SetAlign( EAlfAlignHLeft, EAlfAlignVTop ); |
|
301 #ifdef ENABLE_TEXTSTYLES |
|
302 descriptionVisual->SetTextStyle( iTextStyles[ETextStyleSmall] ); |
|
303 #endif |
|
304 descriptionVisual->SetColor( KRgbGray ); |
|
305 } |
|
306 |
|
307 // end of file |