|
1 /* |
|
2 * Copyright (c) 2003, 2004 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: Class for displaying level indicator icons |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // USER |
|
20 #include "musuilevelindicator.h" |
|
21 #include "musuilevelindicatorobserver.h" |
|
22 #include "muslogger.h" |
|
23 #include "musresourcefinderutil.h" |
|
24 #include "musuiactivetimer.h" |
|
25 #include <musuiicons.mbg> |
|
26 #include <musui.rsg> |
|
27 |
|
28 // SYSTEM |
|
29 #include <aknslider.h> |
|
30 #include <barsread.h> |
|
31 #include <AknUtils.h> |
|
32 #include <AknsUtils.h> |
|
33 #include <data_caging_path_literals.hrh> |
|
34 #include <gulicon.h> |
|
35 #include <aknlayoutscalable_apps.cdl.h> |
|
36 #include <AknsDrawUtils.h> |
|
37 |
|
38 |
|
39 // CONSTANTS |
|
40 const TInt KMusUiLevelDisableTime = 4000000; |
|
41 const TInt KMusUiSliderEventDelay = 300000; |
|
42 |
|
43 |
|
44 _LIT( KMyBitmapRomFile, "Z:\\resource\\apps\\musuiicons.mif" ); |
|
45 //_LIT( KMyBitmapRamFile, "C:\\resource\\apps\\musuiicons.mif" ); |
|
46 |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 CMusUiLevelIndicator::CMusUiLevelIndicator( |
|
53 TInt aMinLevel, |
|
54 TInt aMaxLevel, |
|
55 MMusUiLevelIndicatorObserver* aObserver ) |
|
56 : iMinLevel( aMinLevel ), |
|
57 iMaxLevel( aMaxLevel ), |
|
58 iObserver( aObserver ) |
|
59 { |
|
60 MUS_LOG( "mus: mus: [MUSUI ] -> CMusUiLevelIndicator::CMusUiLevelIndicator()" ); |
|
61 // pass |
|
62 MUS_LOG( "mus: [MUSUI ] <- CMusUiLevelIndicator::CMusUiLevelIndicator()" ); |
|
63 } |
|
64 |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 CMusUiLevelIndicator* CMusUiLevelIndicator::NewL( |
|
71 TAknOrientation aLayout, |
|
72 TInt aMinLevel, |
|
73 TInt aMaxLevel, |
|
74 CCoeControl* aParent, |
|
75 const TRect& aRect, |
|
76 MMusUiLevelIndicatorObserver* aObserver ) |
|
77 { |
|
78 MUS_LOG( "mus: [MUSUI ] -> CMusUiLevelIndicator::NewL()" ); |
|
79 |
|
80 CMusUiLevelIndicator* self = NewLC( aLayout, |
|
81 aMinLevel, |
|
82 aMaxLevel, |
|
83 aParent, |
|
84 aRect, |
|
85 aObserver ); |
|
86 CleanupStack::Pop( self ); |
|
87 |
|
88 MUS_LOG( "mus: [MUSUI ] <- CMusUiLevelIndicator::NewL()" ); |
|
89 |
|
90 return self; |
|
91 } |
|
92 |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 CMusUiLevelIndicator* CMusUiLevelIndicator::NewLC( |
|
99 TAknOrientation aLayout, |
|
100 TInt aMinLevel, |
|
101 TInt aMaxLevel, |
|
102 CCoeControl* aParent, |
|
103 const TRect& aRect, |
|
104 MMusUiLevelIndicatorObserver* aObserver ) |
|
105 { |
|
106 MUS_LOG( "mus: [MUSUI ] -> CMusUiLevelIndicator::NewLC()" ); |
|
107 |
|
108 CMusUiLevelIndicator* self = new ( ELeave ) CMusUiLevelIndicator( |
|
109 aMinLevel, |
|
110 aMaxLevel, |
|
111 aObserver ); |
|
112 CleanupStack::PushL( self ); |
|
113 self->ConstructL( aLayout, aParent, aRect ); |
|
114 |
|
115 MUS_LOG( "mus: [MUSUI ] <- CMusUiLevelIndicator::NewLC()" ); |
|
116 |
|
117 return self; |
|
118 } |
|
119 |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 CMusUiLevelIndicator::~CMusUiLevelIndicator() |
|
126 { |
|
127 MUS_LOG( "mus: [MUSUI ] -> CMusUiLevelIndicator::~CMusUiLevelIndicator()" ); |
|
128 |
|
129 delete iSlider; |
|
130 delete iSliderEventTimer; |
|
131 delete iDisableLevelTimer; |
|
132 |
|
133 MUS_LOG( "mus: [MUSUI ] <- CMusUiLevelIndicator::~CMusUiLevelIndicator()" ); |
|
134 } |
|
135 |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // |
|
139 // ----------------------------------------------------------------------------- |
|
140 // |
|
141 void CMusUiLevelIndicator::ConstructL( TAknOrientation aLayout, |
|
142 CCoeControl* aParent, |
|
143 const TRect& aRect ) |
|
144 { |
|
145 MUS_LOG( "mus: [MUSUI ] -> CMusUiLevelIndicator::ConstructL()" ); |
|
146 |
|
147 SetRect(aRect); |
|
148 |
|
149 if( iMinLevel > iMaxLevel ) |
|
150 { |
|
151 User::Leave( KErrArgument ); |
|
152 } |
|
153 |
|
154 iDisableLevelTimer = CMusUiActiveTimer::NewL( this ); |
|
155 iSliderEventTimer = CMusUiActiveTimer::NewL( this ); |
|
156 |
|
157 iSlider = new CAknSlider(); |
|
158 |
|
159 TResourceReader reader; |
|
160 |
|
161 if( aLayout == EAknOrientationHorizontal ) |
|
162 { |
|
163 iEikonEnv->CreateResourceReaderLC( reader, R_MUS_SLIDER_HORIZONTAL ); |
|
164 MUS_LOG( "mus: [MUSUI ] -> ConstructFromResourceL" ); |
|
165 iSlider->ConstructFromResourceL( aParent, 0, reader); |
|
166 CleanupStack::PopAndDestroy(); // reader |
|
167 iSlider->SetRange( iMinLevel, iMaxLevel ); |
|
168 iSlider->SetRect( aRect ); |
|
169 } |
|
170 else |
|
171 { |
|
172 iEikonEnv->CreateResourceReaderLC( reader, R_MUS_SLIDER_VERTICAL ); |
|
173 iSlider->ConstructFromResourceL( aParent, 0 ,reader); |
|
174 CleanupStack::PopAndDestroy(); // reader |
|
175 TRect rect = TRect( TPoint( (aRect.iBr.iX - iSlider->Size().iWidth),(aRect.iTl.iY) ),TSize( iSlider->Size() ) ); |
|
176 iSlider->SetRect(rect); |
|
177 |
|
178 /* Draw the Min and Max Zoom */ |
|
179 TParse parse; |
|
180 parse.Set( KMyBitmapRomFile, &KDC_APP_RESOURCE_DIR, NULL ); |
|
181 CFbsBitmap* bitmap = NULL; |
|
182 CFbsBitmap* mask = NULL; |
|
183 AknsUtils::CreateIconL(AknsUtils::SkinInstance(), |
|
184 KAknsIIDQsnBgScreen, |
|
185 bitmap, |
|
186 mask, |
|
187 parse.FullName(), |
|
188 EMbmMusuiiconsQgn_indi_browser_tb_zoom_in, |
|
189 EMbmMusuiiconsQgn_indi_browser_tb_zoom_in_mask); |
|
190 iSlider->SetGraphics(CAknSlider::EElemEmptyLeftCap,bitmap,mask); |
|
191 AknsUtils::CreateIconL(AknsUtils::SkinInstance(), |
|
192 KAknsIIDQsnBgScreen, |
|
193 bitmap, |
|
194 mask, |
|
195 parse.FullName(), |
|
196 EMbmMusuiiconsQgn_indi_browser_tb_zoom_out, |
|
197 EMbmMusuiiconsQgn_indi_browser_tb_zoom_out_mask); |
|
198 iSlider->SetGraphics(CAknSlider::EElemEmptyRightCap,bitmap,mask); |
|
199 } |
|
200 |
|
201 iSlider->HandleResourceChange( |
|
202 KEikMessageCaptionedControlEditableStateChange ); |
|
203 iSlider->SetObserver( this ); |
|
204 iSlider->SetPositionIndicators( CAknSlider::EPosMarker ); |
|
205 iSlider->SetTicksEnabled( EFalse ); |
|
206 iSlider->EnableDrag(); |
|
207 iSlider->SetStepSize( 1 ); |
|
208 |
|
209 MUS_LOG( "mus: [MUSUI ] <- CMusUiLevelIndicator::ConstructL()" ); |
|
210 } |
|
211 |
|
212 |
|
213 // ----------------------------------------------------------------------------- |
|
214 // |
|
215 // ----------------------------------------------------------------------------- |
|
216 // |
|
217 void CMusUiLevelIndicator::SetLevelL( TMusUiIndicatorType aType, |
|
218 TInt aLevel, |
|
219 TBool aUseTimer ) |
|
220 { |
|
221 MUS_LOG1( "mus: [MUSUI ] -> CMusUiLevelIndicator::SetLevelL( %d ) ", |
|
222 aLevel ); |
|
223 if ( aLevel >= iMinLevel && aLevel <= iMaxLevel ) |
|
224 { |
|
225 switch(aType) |
|
226 { |
|
227 case EMusUiIndicatorTypeZoom: |
|
228 { |
|
229 iZoomLevel=aLevel; |
|
230 break; |
|
231 } |
|
232 case EMusUiIndicatorTypeBrightness: |
|
233 { |
|
234 iBrightnessLevel=aLevel; |
|
235 break; |
|
236 } |
|
237 case EMusUiIndicatorTypeDuration: |
|
238 { |
|
239 iDurationLevel=aLevel; |
|
240 break; |
|
241 } |
|
242 } |
|
243 } |
|
244 |
|
245 // Set it to the slider |
|
246 if ( !iSliderEventTimer->IsActive() ) |
|
247 { |
|
248 iSlider->SetValueL( aLevel ); |
|
249 } |
|
250 |
|
251 DrawNow(); |
|
252 |
|
253 if ( aUseTimer ) |
|
254 { |
|
255 iDisableLevelTimer->After( KMusUiLevelDisableTime ); |
|
256 } |
|
257 |
|
258 MUS_LOG( "mus: [MUSUI ] <- CMusUiLevelIndicator::SetLevelL()" ); |
|
259 } |
|
260 |
|
261 |
|
262 // ----------------------------------------------------------------------------- |
|
263 // |
|
264 // ----------------------------------------------------------------------------- |
|
265 // |
|
266 TInt CMusUiLevelIndicator::GetLevel( TMusUiIndicatorType aType ) |
|
267 { |
|
268 MUS_LOG( "mus: [MUSUI ] -> CMusUiLevelIndicator::GetLevel()" ); |
|
269 |
|
270 TInt ret=KErrNotFound; |
|
271 |
|
272 switch(aType) |
|
273 { |
|
274 case EMusUiIndicatorTypeZoom: |
|
275 { |
|
276 ret=iZoomLevel; |
|
277 break; |
|
278 } |
|
279 case EMusUiIndicatorTypeBrightness: |
|
280 { |
|
281 ret=iBrightnessLevel; |
|
282 break; |
|
283 } |
|
284 |
|
285 case EMusUiIndicatorTypeDuration: |
|
286 { |
|
287 ret = iSlider->Value(); |
|
288 break; |
|
289 } |
|
290 } |
|
291 |
|
292 MUS_LOG( "mus: [MUSUI ] <- CMusUiLevelIndicator::GetLevel()" ); |
|
293 return ret; |
|
294 } |
|
295 |
|
296 |
|
297 // ----------------------------------------------------------------------------- |
|
298 // |
|
299 // ----------------------------------------------------------------------------- |
|
300 // |
|
301 void CMusUiLevelIndicator::SetRange( TInt aMinLevel, |
|
302 TInt aMaxLevel, |
|
303 TBool aUseTimer) |
|
304 { |
|
305 MUS_LOG2( "mus: [MUSUI ] -> CMusUiLevelIndicator::SetRange( %d - %d ) ", |
|
306 aMinLevel, aMaxLevel ); |
|
307 |
|
308 if( aMinLevel < aMaxLevel ) |
|
309 { |
|
310 iMinLevel = aMinLevel; |
|
311 iMaxLevel = aMaxLevel; |
|
312 iSlider->SetRange( iMinLevel, iMaxLevel ); |
|
313 } |
|
314 |
|
315 if ( aUseTimer ) |
|
316 { |
|
317 iDisableLevelTimer->After( KMusUiLevelDisableTime ); |
|
318 } |
|
319 |
|
320 MUS_LOG( "mus: [MUSUI ] <- CMusUiLevelIndicator::SetRange()" ); |
|
321 } |
|
322 |
|
323 |
|
324 // ----------------------------------------------------------------------------- |
|
325 // |
|
326 // ----------------------------------------------------------------------------- |
|
327 // |
|
328 void CMusUiLevelIndicator::SetIndicatorType( TMusUiIndicatorType aType ) |
|
329 { |
|
330 iIndicatorType = aType; |
|
331 } |
|
332 |
|
333 |
|
334 // ----------------------------------------------------------------------------- |
|
335 // |
|
336 // ----------------------------------------------------------------------------- |
|
337 // |
|
338 void CMusUiLevelIndicator::SizeChanged() |
|
339 { |
|
340 MUS_LOG( "mus: [MUSUI ] -> CMusUiLevelIndicator::SizeChanged()" ); |
|
341 |
|
342 if ( iSlider ) |
|
343 { |
|
344 iSlider->SetRect( Rect() ); |
|
345 } |
|
346 |
|
347 DrawNow(); |
|
348 |
|
349 MUS_LOG( "mus: [MUSUI ] <- CMusUiLevelIndicator::SizeChanged()" ); |
|
350 } |
|
351 |
|
352 |
|
353 // ----------------------------------------------------------------------------- |
|
354 // |
|
355 // ----------------------------------------------------------------------------- |
|
356 void CMusUiLevelIndicator::Draw( const TRect& aRect ) const |
|
357 { |
|
358 CWindowGc& gc = SystemGc(); |
|
359 gc.SetBrushColor( iEikonEnv->ControlColor( EColorWindowBackground, *this ) ); |
|
360 gc.SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
361 gc.Clear( aRect ); |
|
362 } |
|
363 |
|
364 |
|
365 // ----------------------------------------------------------------------------- |
|
366 // |
|
367 // ----------------------------------------------------------------------------- |
|
368 // |
|
369 TInt CMusUiLevelIndicator::CountComponentControls() const |
|
370 { |
|
371 return 1; // return nbr of controls inside this container |
|
372 } |
|
373 |
|
374 |
|
375 // ----------------------------------------------------------------------------- |
|
376 // Called by framework to retrieve the control specified by index. |
|
377 // ----------------------------------------------------------------------------- |
|
378 // |
|
379 CCoeControl* CMusUiLevelIndicator::ComponentControl( TInt aIndex ) const |
|
380 { |
|
381 switch ( aIndex ) |
|
382 { |
|
383 case 0: |
|
384 { |
|
385 return iSlider; |
|
386 } |
|
387 default: |
|
388 { |
|
389 return NULL; |
|
390 } |
|
391 } |
|
392 } |
|
393 |
|
394 |
|
395 // ----------------------------------------------------------------------------- |
|
396 // |
|
397 // ----------------------------------------------------------------------------- |
|
398 // |
|
399 void CMusUiLevelIndicator::HandleResourceChange( TInt aType ) |
|
400 { |
|
401 MUS_LOG( "mus: [MUSUI ] -> CMusUiLevelIndicator::HandleResourceChange()" ); |
|
402 |
|
403 if( aType==KEikDynamicLayoutVariantSwitch ) |
|
404 { |
|
405 if ( iSlider ) // Force a re-layout |
|
406 { |
|
407 iSlider->SetRect( Rect() ); |
|
408 } |
|
409 } |
|
410 |
|
411 DrawNow(); |
|
412 |
|
413 MUS_LOG( "mus: [MUSUI ] <- CMusUiLevelIndicator::HandleResourceChange()" ); |
|
414 } |
|
415 |
|
416 |
|
417 // ----------------------------------------------------------------------------- |
|
418 // |
|
419 // ----------------------------------------------------------------------------- |
|
420 // |
|
421 void CMusUiLevelIndicator::HandleControlEventL( CCoeControl* aControl, |
|
422 TCoeEvent aEventType) |
|
423 { |
|
424 // No logging due to huge amount of events |
|
425 |
|
426 if ( aControl == iSlider && |
|
427 aEventType == MCoeControlObserver::EEventStateChanged ) |
|
428 { |
|
429 // Restart the disable timer if running |
|
430 if ( iDisableLevelTimer->IsActive() ) |
|
431 { |
|
432 iDisableLevelTimer->After( KMusUiLevelDisableTime ); |
|
433 } |
|
434 |
|
435 if ( iObserver ) |
|
436 { |
|
437 iSliderEventTimer->After( KMusUiSliderEventDelay ); |
|
438 } |
|
439 } |
|
440 |
|
441 // No logging due to huge amount of events |
|
442 } |
|
443 |
|
444 |
|
445 // ----------------------------------------------------------------------------- |
|
446 // |
|
447 // ----------------------------------------------------------------------------- |
|
448 // |
|
449 void CMusUiLevelIndicator::TimerComplete( CMusUiActiveTimer* aTimer ) |
|
450 { |
|
451 if ( aTimer == iSliderEventTimer ) |
|
452 { |
|
453 MUS_LOG( "mus: [MUSUI ] Slider event timer complete" ); |
|
454 |
|
455 if ( iObserver ) |
|
456 { |
|
457 iObserver->IndicatorLevelChanged( iSlider->Value() ); |
|
458 } |
|
459 } |
|
460 else if ( aTimer == iDisableLevelTimer ) |
|
461 { |
|
462 MUS_LOG( "mus: [MUSUI ] Slider visibility timer complete" ); |
|
463 |
|
464 if ( iObserver ) |
|
465 { |
|
466 iObserver->SetLevelIndicatorVisibility( EFalse ); |
|
467 } |
|
468 } |
|
469 else |
|
470 { |
|
471 // NOP |
|
472 } |
|
473 } |
|
474 |
|
475 |
|
476 |
|
477 // End of File |
|
478 |
|
479 |
|
480 |