|
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: Visualiser class for Control Bar component. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 //<cmail> SF |
|
20 #include "emailtrace.h" |
|
21 #include <alf/alfdecklayout.h> |
|
22 #include <alf/alfgradientbrush.h> |
|
23 #include <alf/alfimagevisual.h> |
|
24 #include <alf/alfborderbrush.h> |
|
25 #include <alf/alfframebrush.h> |
|
26 #include <alf/alfimagebrush.h> |
|
27 #include <alf/alfbrusharray.h> |
|
28 //</cmail> |
|
29 #include <AknUtils.h> |
|
30 |
|
31 #include "fslayoutmanager.h" |
|
32 #include "fscontrolbarvisualiser.h" |
|
33 #include "fscontrolbar.h" |
|
34 #include "fscontrolbarmodel.h" |
|
35 #include "fscontrolbutton.h" |
|
36 #include "fscontrolbuttonvisualiser.h" |
|
37 #include "fscontrolbuttonmodel.h" |
|
38 #include "fsgenericpanic.h" |
|
39 |
|
40 #define DEFAULT_SELECTOR KAknsIIDQsnFrList |
|
41 |
|
42 const TReal KFsSelectorOpacity = 1; |
|
43 const TInt KFsSelectorPaddingTop = 0; |
|
44 const TInt KFsSelectorPaddingBottom = 0; |
|
45 const TInt KFsSelectorPaddingLeft = 0; |
|
46 const TInt KFsSelectorPaddingRight = 0; |
|
47 |
|
48 |
|
49 // ======== MEMBER FUNCTIONS ======== |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // Constructor. |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 CFsControlBarVisualiser::CFsControlBarVisualiser( |
|
56 CFsControlBar& aParentControl, |
|
57 CFsControlBarModel& aModel ) : |
|
58 iModel( aModel ), |
|
59 iParent( aParentControl ), |
|
60 iLastSelectedButton( -1 ) |
|
61 { |
|
62 FUNC_LOG; |
|
63 } |
|
64 |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // Second phase constructor. |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 void CFsControlBarVisualiser::ConstructL() |
|
71 { |
|
72 FUNC_LOG; |
|
73 // creating layout and visual controls |
|
74 iBarLayout = CAlfDeckLayout::AddNewL( iParent ); |
|
75 iBarLayout->EnableBrushesL(); |
|
76 iBarLayout->SetFlags( EAlfVisualFlagLayoutUpdateNotification | |
|
77 EAlfVisualFlagManualPosition | |
|
78 EAlfVisualFlagManualSize ); |
|
79 iBarLayout->SetSize( iModel.Size() ); |
|
80 iBarLayout->SetClipping( ETrue ); |
|
81 |
|
82 // controlbar background color |
|
83 CAlfEnv& env( iParent.Env() ); |
|
84 iBgColor = CAlfGradientBrush::NewL( env ); |
|
85 iBgColor->SetColor( iModel.BarBgColor() ); |
|
86 iBarLayout->Brushes()->AppendL( iBgColor, EAlfDoesNotHaveOwnership ); |
|
87 |
|
88 // Background image |
|
89 iBgLayout = CAlfLayout::AddNewL( iParent, iBarLayout ); |
|
90 iBgLayout->EnableBrushesL(); |
|
91 |
|
92 TRect parentRect( TPoint( 0, 0 ), iBarLayout->Size().Target() ); |
|
93 TRect layoutRect( 0, 0, 0, 0 ); |
|
94 |
|
95 // Adjust the background image size and position. |
|
96 CFsLayoutManager::LayoutMetricsRect( parentRect, |
|
97 CFsLayoutManager::EFsLmBgSpFsCtrlbarPane, layoutRect, |
|
98 0 ); |
|
99 iBgLayout->SetSize( layoutRect.Size() ); |
|
100 iBgLayout->SetPos( layoutRect.iTl ); |
|
101 |
|
102 // Use image from skin. |
|
103 iDefaultBgBrush = CAlfFrameBrush::NewL( env, KAknsIIDQsnFrStatusFlat ); |
|
104 TSize size( |
|
105 iBarLayout->Size().Target().iX, iBarLayout->Size().Target().iY ); |
|
106 layoutRect = size; |
|
107 |
|
108 //<CMAIL> As a device user, I want Message List items to follow platform layouts to be consistent with other apps |
|
109 |
|
110 /* |
|
111 REMOVED: Not needed |
|
112 |
|
113 TRect childRect( layoutRect ); |
|
114 // LAF values needed |
|
115 childRect.Shrink( 4, 4 ); |
|
116 iDefaultBgBrush->SetFrameRectsL( childRect, layoutRect ); |
|
117 */ |
|
118 //</CMAIL> |
|
119 |
|
120 iBgLayout->Brushes()->AppendL( |
|
121 iDefaultBgBrush, EAlfDoesNotHaveOwnership ); |
|
122 } |
|
123 |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // Two-phased constructor. |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 CFsControlBarVisualiser* CFsControlBarVisualiser::NewL( |
|
130 CFsControlBar& aParentControl, |
|
131 CFsControlBarModel& aModel ) |
|
132 { |
|
133 FUNC_LOG; |
|
134 CFsControlBarVisualiser* self = |
|
135 new (ELeave) CFsControlBarVisualiser( aParentControl, aModel ); |
|
136 CleanupStack::PushL( self ); |
|
137 self->ConstructL(); |
|
138 CleanupStack::Pop( self ); |
|
139 return self; |
|
140 } |
|
141 |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // Destructor. |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 CFsControlBarVisualiser::~CFsControlBarVisualiser() |
|
148 { |
|
149 FUNC_LOG; |
|
150 ClearBackgroundImage(); |
|
151 delete iBgColor; |
|
152 delete iSelectorBrush; |
|
153 } |
|
154 |
|
155 |
|
156 // --------------------------------------------------------------------------- |
|
157 // Redraws control. |
|
158 // --------------------------------------------------------------------------- |
|
159 // |
|
160 void CFsControlBarVisualiser::RefreshL( TBool aScreenSizeChanged ) |
|
161 { |
|
162 FUNC_LOG; |
|
163 TInt focusedButton( -1 ); |
|
164 CFsControlButton* button = NULL; |
|
165 |
|
166 if ( aScreenSizeChanged ) |
|
167 { |
|
168 iBarLayout->SetSize( iModel.Size() ); |
|
169 } |
|
170 |
|
171 for( TInt i( 0 ); iModel.Count() > i; i++ ) |
|
172 { |
|
173 button = iModel.ButtonByIndex( i ); |
|
174 |
|
175 // draw only visible buttons |
|
176 if ( button->IsVisible() ) |
|
177 { |
|
178 if ( button->IsFocused() ) |
|
179 { |
|
180 focusedButton = i; |
|
181 } |
|
182 |
|
183 // size of bar changed -> update buttons |
|
184 button->Visualiser()->Refresh(); |
|
185 } |
|
186 } |
|
187 |
|
188 if( -1 != focusedButton ) |
|
189 { |
|
190 DrawSelectorL( focusedButton, aScreenSizeChanged ); |
|
191 } |
|
192 else |
|
193 { |
|
194 HideSelector(); |
|
195 } |
|
196 } |
|
197 |
|
198 |
|
199 // --------------------------------------------------------------------------- |
|
200 // Sets background color for controlbar. |
|
201 // --------------------------------------------------------------------------- |
|
202 // |
|
203 void CFsControlBarVisualiser::SetBackgroundColor( const TRgb& aColor ) |
|
204 { |
|
205 FUNC_LOG; |
|
206 // set color |
|
207 iBgColor->SetColor( aColor ); |
|
208 iBgColor->SetOpacity( 1 ); |
|
209 } |
|
210 |
|
211 |
|
212 // --------------------------------------------------------------------------- |
|
213 // Clears controlbar's background color. Controlbar becomes transparent. |
|
214 // --------------------------------------------------------------------------- |
|
215 // |
|
216 EXPORT_C void CFsControlBarVisualiser::ClearBackgroundColor() |
|
217 { |
|
218 FUNC_LOG; |
|
219 iBgColor->SetOpacity( 0 ); |
|
220 } |
|
221 |
|
222 |
|
223 // --------------------------------------------------------------------------- |
|
224 // Sets background image for controlbar. |
|
225 // --------------------------------------------------------------------------- |
|
226 // |
|
227 void CFsControlBarVisualiser::SetBackgroundImageL( CAlfTexture& aImage ) |
|
228 { |
|
229 FUNC_LOG; |
|
230 if ( iDefaultBgBrush ) |
|
231 { |
|
232 ClearBackgroundImage(); |
|
233 } |
|
234 |
|
235 if ( !iBgImage ) |
|
236 { |
|
237 CAlfEnv& env( iParent.Env() ); |
|
238 iBgImage = CAlfImageBrush::NewL( env, TAlfImage( aImage ) ); |
|
239 iBgLayout->Brushes()->AppendL( iBgImage, EAlfDoesNotHaveOwnership ); |
|
240 } |
|
241 else |
|
242 { |
|
243 iBgImage->SetImage( TAlfImage( aImage ) ); |
|
244 } |
|
245 } |
|
246 |
|
247 |
|
248 // --------------------------------------------------------------------------- |
|
249 // Clears background image for controlbar. |
|
250 // --------------------------------------------------------------------------- |
|
251 // |
|
252 void CFsControlBarVisualiser::ClearBackgroundImage() |
|
253 { |
|
254 FUNC_LOG; |
|
255 if ( iDefaultBgBrush ) |
|
256 { |
|
257 for ( TInt i( iBarLayout->Brushes()->Count() - 1 ); 0 <= i; i-- ) |
|
258 { |
|
259 if ( &iBgLayout->Brushes()->At( i ) == iDefaultBgBrush ) |
|
260 { |
|
261 iBgLayout->Brushes()->Remove( i ); |
|
262 delete iDefaultBgBrush; |
|
263 iDefaultBgBrush = NULL; |
|
264 break; |
|
265 } |
|
266 } |
|
267 } |
|
268 if ( iBgImage ) |
|
269 { |
|
270 for ( TInt i( iBarLayout->Brushes()->Count() - 1 ); 0 <= i; i-- ) |
|
271 { |
|
272 if ( &iBgLayout->Brushes()->At( i ) == iBgImage ) |
|
273 { |
|
274 iBgLayout->Brushes()->Remove( i ); |
|
275 delete iBgImage; |
|
276 iBgImage = NULL; |
|
277 break; |
|
278 } |
|
279 } |
|
280 } |
|
281 } |
|
282 |
|
283 |
|
284 // --------------------------------------------------------------------------- |
|
285 // Update the size of the controlbar layout. |
|
286 // --------------------------------------------------------------------------- |
|
287 // |
|
288 void CFsControlBarVisualiser::UpdateSizeL() |
|
289 { |
|
290 FUNC_LOG; |
|
291 iBarLayout->SetSize( iModel.Size() ); |
|
292 iBarLayout->SetPos( iModel.Pos() ); |
|
293 RefreshL(); |
|
294 } |
|
295 |
|
296 |
|
297 // --------------------------------------------------------------------------- |
|
298 // Retrieves controlbar's layout. |
|
299 // --------------------------------------------------------------------------- |
|
300 // |
|
301 CAlfDeckLayout* CFsControlBarVisualiser::Layout() |
|
302 { |
|
303 FUNC_LOG; |
|
304 return iBarLayout; |
|
305 } |
|
306 |
|
307 |
|
308 // --------------------------------------------------------------------------- |
|
309 // Sets transition time for selector. |
|
310 // --------------------------------------------------------------------------- |
|
311 // |
|
312 void CFsControlBarVisualiser::SetSelectorTransitionTimeL( |
|
313 TInt aTransitionTime ) |
|
314 { |
|
315 FUNC_LOG; |
|
316 iModel.SetSelectorTransitionTime( aTransitionTime ); |
|
317 RefreshL(); |
|
318 } |
|
319 |
|
320 |
|
321 // --------------------------------------------------------------------------- |
|
322 // Change the selector image. |
|
323 // Ownership of the brush is gained. |
|
324 // --------------------------------------------------------------------------- |
|
325 // |
|
326 void CFsControlBarVisualiser::SetSelectorImageL( |
|
327 CAlfBrush* aSelectorBrush, |
|
328 TReal32 aOpacity ) |
|
329 { |
|
330 FUNC_LOG; |
|
331 // Update the selector if it is visible. |
|
332 if ( iSelector ) |
|
333 { |
|
334 if ( iSelector->Brushes()->Count() ) |
|
335 { |
|
336 iSelector->Brushes()->Remove( iSelector->Brushes()->Count() - 1 ); |
|
337 } |
|
338 iSelector->Brushes()->AppendL( |
|
339 aSelectorBrush, EAlfDoesNotHaveOwnership ); |
|
340 iSelector->SetOpacity( aOpacity ); |
|
341 } |
|
342 |
|
343 // Release the old selector brush. |
|
344 delete iSelectorBrush; |
|
345 iSelectorBrush = aSelectorBrush; |
|
346 iSelectorOpacity = aOpacity; |
|
347 } |
|
348 |
|
349 |
|
350 // --------------------------------------------------------------------------- |
|
351 // Reorder the visuals. Button visual are build from two separate visual, |
|
352 // background and content. Those are arranged so that the background visual |
|
353 // are set at back and contents are to front. Selector visual is placed |
|
354 // between them. |
|
355 // --------------------------------------------------------------------------- |
|
356 // |
|
357 void CFsControlBarVisualiser::ReorderVisuals() |
|
358 { |
|
359 FUNC_LOG; |
|
360 if ( iSelector ) |
|
361 { |
|
362 TInt visualOrder( KErrNotFound ); |
|
363 if ( KErrNotFound == visualOrder ) |
|
364 { |
|
365 visualOrder = iBarLayout->FindVisual( iBgLayout ); |
|
366 } |
|
367 |
|
368 // Reorder the buttons. |
|
369 visualOrder++; |
|
370 for ( TInt i( 0 ); iModel.Count() > i; i++ ) |
|
371 { |
|
372 // Reorder visual so that the button background visuals get to |
|
373 // bottom and their contents get to the front. Selector will be |
|
374 // places between them. |
|
375 CFsControlButtonVisualiser* button( NULL ); |
|
376 button = iModel.ButtonByIndex( i )->Visualiser(); |
|
377 if ( button->IsVisible() ) |
|
378 { |
|
379 iBarLayout->MoveVisualToFront( *button->ContentLayout() ); |
|
380 iBarLayout->Reorder( *button->Layout(), visualOrder ); |
|
381 visualOrder++; |
|
382 } |
|
383 } |
|
384 |
|
385 // Move the selector after every button's background visual. |
|
386 iBarLayout->Reorder( *iSelector, visualOrder ); |
|
387 } |
|
388 } |
|
389 |
|
390 // --------------------------------------------------------------------------- |
|
391 // Hides\shows selector rectangle over selected button. |
|
392 // --------------------------------------------------------------------------- |
|
393 // |
|
394 void CFsControlBarVisualiser::MakeSelectorVisible( |
|
395 TBool aShow, TBool aFromTouch ) |
|
396 { |
|
397 FUNC_LOG; |
|
398 TReal32 opacity( 0 ); |
|
399 if( aShow ) |
|
400 { |
|
401 opacity = KFsSelectorOpacity; |
|
402 } |
|
403 if( iSelector ) |
|
404 { |
|
405 iTouchPressed = aFromTouch; |
|
406 CFsControlButton* button = NULL; |
|
407 const TInt buttonCount( iModel.Count() ); |
|
408 for( TInt buttonIndex( 0 ); buttonIndex < buttonCount; ++buttonIndex ) |
|
409 { |
|
410 button = iModel.ButtonByIndex( buttonIndex ); |
|
411 if( button->IsFocused() ) |
|
412 { |
|
413 button->MakeFocusVisible( aShow ); |
|
414 break; |
|
415 } |
|
416 } |
|
417 iSelector->SetOpacity( opacity ); |
|
418 } |
|
419 iSelectorOpacity = opacity; |
|
420 } |
|
421 |
|
422 // --------------------------------------------------------------------------- |
|
423 // Draws selector rectangle over selected button. |
|
424 // --------------------------------------------------------------------------- |
|
425 // |
|
426 void CFsControlBarVisualiser::DrawSelectorL( |
|
427 const TInt aSelectedButtonIndex, |
|
428 TBool aFastDraw ) |
|
429 { |
|
430 FUNC_LOG; |
|
431 CFsControlButtonVisualiser* vis = NULL; |
|
432 |
|
433 // set selector's delay |
|
434 TInt transitionTime( aFastDraw ? 0 : iModel.SelectorTransitionTime() ); |
|
435 TBool setDefaultBrushBorders( EFalse ); |
|
436 |
|
437 if ( !iSelector ) |
|
438 { |
|
439 // Flags used because otherwise it would generate a callback here |
|
440 // before the image visual is fully created. |
|
441 iBarLayout->SetFlag( EAlfVisualFlagFreezeLayout ); |
|
442 iSelector = iParent.AppendVisualL( EAlfVisualTypeVisual, iBarLayout ); |
|
443 |
|
444 ReorderVisuals(); |
|
445 |
|
446 iBarLayout->ClearFlag( EAlfVisualFlagFreezeLayout ); |
|
447 iSelector->SetFlag( EAlfVisualFlagManualPosition ); |
|
448 iSelector->SetFlag( EAlfVisualFlagManualSize ); |
|
449 |
|
450 iSelector->EnableBrushesL(); |
|
451 |
|
452 if ( !iSelectorBrush ) |
|
453 { |
|
454 // Use the default selector brush. |
|
455 CAlfFrameBrush* brush( |
|
456 CAlfFrameBrush::NewL( iParent.Env(), KAknsIIDQsnFrList ) ); |
|
457 // Ownership of the brush is transfered. |
|
458 SetSelectorImageL( brush, KFsSelectorOpacity ); |
|
459 // Brush rects are set later. |
|
460 setDefaultBrushBorders = ETrue; |
|
461 } |
|
462 else |
|
463 { |
|
464 // Use the custom selector brush. |
|
465 iSelector->Brushes()->AppendL( |
|
466 iSelectorBrush, EAlfDoesNotHaveOwnership ); |
|
467 iSelector->SetOpacity( iSelectorOpacity ); |
|
468 } |
|
469 |
|
470 // When making the selector visible then do it without any delays. |
|
471 transitionTime = 0; |
|
472 } |
|
473 |
|
474 // retieve button's visualiser |
|
475 vis = iModel.ButtonByIndex( aSelectedButtonIndex )->Visualiser(); |
|
476 |
|
477 // retieve button's pos and size |
|
478 TPoint point( vis->Pos().iX.Target(), vis->Pos().iY.Target() ); |
|
479 TSize size( vis->Size().iX.Target(), vis->Size().iY.Target() ); |
|
480 point.operator-=( |
|
481 TPoint( KFsSelectorPaddingLeft, KFsSelectorPaddingTop ) ); |
|
482 size += TSize( KFsSelectorPaddingLeft + KFsSelectorPaddingRight, |
|
483 KFsSelectorPaddingTop + KFsSelectorPaddingBottom ); |
|
484 |
|
485 // Hides transition when item selected via touch |
|
486 if( iTouchPressed ) |
|
487 { |
|
488 transitionTime = 0; |
|
489 iTouchPressed = EFalse; |
|
490 } |
|
491 |
|
492 iLastSelectedButton = aSelectedButtonIndex; |
|
493 // set new pos and size of selector |
|
494 iSelector->SetPos( TAlfRealPoint( point ), transitionTime ); |
|
495 iSelector->SetSize( TAlfRealSize( size ), transitionTime ); |
|
496 |
|
497 // Setting the selector skin to fit the selector visual size. |
|
498 if ( setDefaultBrushBorders ) |
|
499 { |
|
500 CAlfBrush& brush( |
|
501 iSelector->Brushes()->At( iSelector->Brushes()->Count() - 1 ) ); |
|
502 |
|
503 //<CMAIL> As a device user, I want Message List items to follow platform layouts to be consistent with other apps |
|
504 |
|
505 /* |
|
506 |
|
507 CAlfFrameBrush* defaultSelectorBrush( |
|
508 static_cast<CAlfFrameBrush*>( &brush ) ); |
|
509 TRect layoutRect( size ); |
|
510 |
|
511 |
|
512 REMOVED: Not needed |
|
513 |
|
514 TRect childRect( layoutRect ); |
|
515 // LAF values needed |
|
516 childRect.Shrink( 1, 1 ); |
|
517 defaultSelectorBrush->SetFrameRectsL( childRect, layoutRect ); |
|
518 */ |
|
519 //</CMAIL> |
|
520 |
|
521 } |
|
522 } |
|
523 |
|
524 |
|
525 // --------------------------------------------------------------------------- |
|
526 // Hides selector rectangle. |
|
527 // --------------------------------------------------------------------------- |
|
528 // |
|
529 void CFsControlBarVisualiser::HideSelector() |
|
530 { |
|
531 FUNC_LOG; |
|
532 iLastSelectedButton = KErrNotFound; |
|
533 if ( iSelector ) |
|
534 { |
|
535 // Flags used because otherwise it would generate a callback here |
|
536 // before the visual is fully destroyed. |
|
537 iBarLayout->SetFlag( EAlfVisualFlagFreezeLayout ); |
|
538 iSelector->RemoveAndDestroyAllD(); |
|
539 iSelector = NULL; |
|
540 iBarLayout->ClearFlag( EAlfVisualFlagFreezeLayout ); |
|
541 iBarLayout->UpdateChildrenLayout(); |
|
542 } |
|
543 } |
|
544 |