|
1 /* |
|
2 * Copyright (c) 2006 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: Music Player album art editor dialog implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <AknUtils.h> |
|
21 #include <eiklabel.h> |
|
22 #include <StringLoader.h> |
|
23 #include <mpxalbumarteditordialog.rsg> |
|
24 #include <AknsDrawUtils.h> |
|
25 #include <AknsBasicBackgroundControlContext.h> |
|
26 #include <mpxlog.h> |
|
27 |
|
28 #include "mpxalbumarteventobserver.h" |
|
29 #include "mpxalbumarteditordialogcustomcontrol.h" |
|
30 |
|
31 // CONSTANTS |
|
32 const TInt KMPXLabelCount = 2; |
|
33 |
|
34 // ============================ MEMBER FUNCTIONS =============================== |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CMPXAlbumArtEditorDialogCustomControl::NewLC |
|
38 // Two-phased constructor. |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CMPXAlbumArtEditorDialogCustomControl* |
|
42 CMPXAlbumArtEditorDialogCustomControl::NewLC( |
|
43 const CCoeControl& aParent, |
|
44 const TRect &aRect, |
|
45 MMPXAlbumArtEventObserver* aObserver ) |
|
46 { |
|
47 MPX_FUNC( "CMPXAlbumArtEditorDialogCustomControl::NewLC" ); |
|
48 CMPXAlbumArtEditorDialogCustomControl* self = |
|
49 new ( ELeave ) CMPXAlbumArtEditorDialogCustomControl(); |
|
50 CleanupStack::PushL( self ); |
|
51 self->ConstructL( aParent, aRect, aObserver ); |
|
52 return self; |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CMPXAlbumArtEditorDialogCustomControl::NewL |
|
57 // Two-phased constructor. |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 CMPXAlbumArtEditorDialogCustomControl* |
|
61 CMPXAlbumArtEditorDialogCustomControl::NewL( |
|
62 const CCoeControl& aParent, |
|
63 const TRect &aRect, |
|
64 MMPXAlbumArtEventObserver* aObserver ) |
|
65 { |
|
66 MPX_FUNC( "CMPXAlbumArtEditorDialogCustomControl::NewL" ); |
|
67 CMPXAlbumArtEditorDialogCustomControl* self = NewLC( |
|
68 aParent, aRect, aObserver ); |
|
69 CleanupStack::Pop( self ); |
|
70 return self; |
|
71 } |
|
72 |
|
73 // Destructor |
|
74 CMPXAlbumArtEditorDialogCustomControl::~CMPXAlbumArtEditorDialogCustomControl() |
|
75 { |
|
76 MPX_FUNC( "CMPXAlbumArtEditorDialogCustomControl::~CMPXAlbumArtEditorDialogCustomControl" ); |
|
77 delete iImage; |
|
78 delete iLabel; |
|
79 delete iBackground; |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // CMPXAlbumArtEditorDialogCustomControl::CMPXAlbumArtEditorDialogCustomControl |
|
84 // C++ default constructor can NOT contain any code, that |
|
85 // might leave. |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 CMPXAlbumArtEditorDialogCustomControl::CMPXAlbumArtEditorDialogCustomControl() : |
|
89 iLabel( NULL ), iObserver( NULL ) |
|
90 { |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // CMPXAlbumArtEditorDialogCustomControl::ConstructL |
|
95 // Symbian 2nd phase constructor can leave. |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 void CMPXAlbumArtEditorDialogCustomControl::ConstructL( |
|
99 const CCoeControl& aParent, |
|
100 const TRect &aRect, |
|
101 MMPXAlbumArtEventObserver* aObserver ) |
|
102 { |
|
103 MPX_FUNC( "CMPXAlbumArtEditorDialogCustomControl::ConstructL" ); |
|
104 SetMopParent( const_cast < CCoeControl* >( &aParent ) ); |
|
105 CreateWindowL(); |
|
106 |
|
107 iImage = new ( ELeave ) CEikImage(); |
|
108 iImage->SetContainerWindowL( *this ); |
|
109 |
|
110 iLabel = new ( ELeave ) CEikLabel; |
|
111 iLabel->SetContainerWindowL( *this ); |
|
112 iLabel->SetTextL( _L( "" ) ); |
|
113 iLabel->MakeVisible ( EFalse ); |
|
114 |
|
115 iObserver = aObserver; |
|
116 |
|
117 iMode = EMPXAlbumArtEditorDialogBlank; |
|
118 SetRect( aRect ); |
|
119 HandleSkinChangedL(); |
|
120 ActivateL(); |
|
121 MakeVisible( ETrue ); |
|
122 } |
|
123 |
|
124 // ----------------------------------------------------------------------------- |
|
125 // CMPXAlbumArtEditorDialogCustomControl::UpdateAlbumArt |
|
126 // Updates new image to CEikImage |
|
127 // ----------------------------------------------------------------------------- |
|
128 // |
|
129 void CMPXAlbumArtEditorDialogCustomControl::UpdateAlbumArt( |
|
130 TMPXAlbumArtEditorDialogMode aMode, |
|
131 CFbsBitmap* aNewAlbumArt ) |
|
132 { |
|
133 MPX_FUNC( "CMPXAlbumArtEditorDialogCustomControl::UpdateAlbumArt" ); |
|
134 switch ( aMode ) |
|
135 { |
|
136 case EMPXAlbumArtEditorDialogAlbumArt: |
|
137 { |
|
138 iImage->SetPictureOwnedExternally( EFalse) ; |
|
139 iImage->SetNewBitmaps( aNewAlbumArt, NULL ); |
|
140 iImage->SetSize( iImage->MinimumSize() ); |
|
141 iImage->SetPictureOwnedExternally( EFalse ); |
|
142 iImage->SetAlignment( EHCenterVCenter ); |
|
143 iImage->MakeVisible( ETrue ); |
|
144 |
|
145 TRect myRect = Rect(); |
|
146 TSize bSize = aNewAlbumArt->SizeInPixels(); |
|
147 AknLayoutUtils::LayoutImage( |
|
148 iImage, myRect, EColor256, |
|
149 ( myRect.Width() - bSize.iWidth ) / 2 , |
|
150 ( myRect.Height() - bSize.iHeight ) / 2, |
|
151 NULL, NULL, bSize.iWidth, bSize.iHeight ); |
|
152 |
|
153 // layout border |
|
154 TInt tX = ( myRect.Width() - bSize.iWidth ) / 2; |
|
155 TInt tY = ( myRect.Height() - bSize.iHeight ) / 2; |
|
156 iBorder.iTl.iX = tX - 1; |
|
157 iBorder.iTl.iY = tY - 1; |
|
158 iBorder.iBr.iX = tX + bSize.iWidth + 1; |
|
159 iBorder.iBr.iY = tY + bSize.iHeight + 1; |
|
160 |
|
161 TRAP_IGNORE( SetModeL( EMPXAlbumArtEditorDialogAlbumArt ) ); |
|
162 break; |
|
163 } |
|
164 default: |
|
165 { |
|
166 TRAP_IGNORE( SetModeL( aMode ) ); |
|
167 break; |
|
168 } |
|
169 } |
|
170 } |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // CMPXAlbumArtEditorDialogCustomControl::SetModeL |
|
174 // Displays image in a specific mode, either Album Art/No Album Art or Various |
|
175 // ----------------------------------------------------------------------------- |
|
176 // |
|
177 void CMPXAlbumArtEditorDialogCustomControl::SetModeL( |
|
178 TMPXAlbumArtEditorDialogMode aMode ) |
|
179 { |
|
180 MPX_FUNC( "CMPXAlbumArtEditorDialogCustomControl::SetModeL" ); |
|
181 iMode = aMode; |
|
182 switch( iMode ) |
|
183 { |
|
184 case EMPXAlbumArtEditorDialogAlbumArt: |
|
185 { |
|
186 iLabel->MakeVisible( EFalse ); |
|
187 iImage->MakeVisible( ETrue ); |
|
188 DrawDeferred(); |
|
189 break; |
|
190 } |
|
191 case EMPXAlbumArtEditorDialogNoAlbumArt: |
|
192 { |
|
193 if(iImage->Bitmap()) |
|
194 { |
|
195 iImage->MakeVisible( EFalse ); |
|
196 } |
|
197 iLabel->MakeVisible( EFalse ); |
|
198 |
|
199 HBufC* labeltext = StringLoader::LoadLC( |
|
200 R_MPX_CUI_ALBUM_ART_NO_ART_TEXT ); |
|
201 iLabel->SetTextL( *labeltext ); |
|
202 CleanupStack::PopAndDestroy( labeltext ); |
|
203 |
|
204 iLabel->MakeVisible( ETrue ); |
|
205 DrawDeferred(); |
|
206 break; |
|
207 } |
|
208 case EMPXAlbumArtEditorDialogBlank: |
|
209 iImage->MakeVisible( EFalse ); |
|
210 break; |
|
211 default: // some error |
|
212 { |
|
213 break; |
|
214 } |
|
215 } |
|
216 } |
|
217 |
|
218 // ----------------------------------------------------------------------------- |
|
219 // CMPXAlbumArtEditorDialogCustomControl::HandleSkinChangedL |
|
220 // updates skin color |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 void CMPXAlbumArtEditorDialogCustomControl::HandleSkinChangedL() |
|
224 { |
|
225 MPX_FUNC( "CMPXAlbumArtEditorDialogCustomControl::HandleSkinChangedL" ); |
|
226 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
227 TRgb color = KRgbBlack; |
|
228 // Color is not updated if it not found from the skin |
|
229 AknsUtils::GetCachedColor( |
|
230 skin, |
|
231 color, |
|
232 KAknsIIDQsnTextColors, |
|
233 EAknsCIQsnTextColorsCG6 ); |
|
234 |
|
235 AknLayoutUtils::OverrideControlColorL( |
|
236 *iLabel, |
|
237 EColorLabelText, |
|
238 color ); |
|
239 } |
|
240 |
|
241 // --------------------------------------------------------------------------- |
|
242 // From MMPXAlbumArtUtilObserver |
|
243 // Notify that extraction of album art started. |
|
244 // --------------------------------------------------------------------------- |
|
245 // |
|
246 void CMPXAlbumArtEditorDialogCustomControl::ExtractAlbumArtStarted() |
|
247 { |
|
248 // Do Nothing |
|
249 } |
|
250 |
|
251 // --------------------------------------------------------------------------- |
|
252 // From MMPXAlbumArtUtilObserver |
|
253 // Album art is extracted from file and ready to use. |
|
254 // --------------------------------------------------------------------------- |
|
255 // |
|
256 void CMPXAlbumArtEditorDialogCustomControl::ExtractAlbumArtCompleted( |
|
257 CFbsBitmap* aBitmap, |
|
258 TInt aErr ) |
|
259 { |
|
260 MPX_DEBUG3( "CMPXAlbumArtEditorDialogCustomControl::ExtractAlbumArtCompleted(bitmap:0x%x, err:%d)", |
|
261 aBitmap, aErr ); |
|
262 |
|
263 if ( !aErr ) |
|
264 { |
|
265 UpdateAlbumArt( EMPXAlbumArtEditorDialogAlbumArt, aBitmap ); |
|
266 } |
|
267 else |
|
268 { |
|
269 // error case, do not display album art |
|
270 UpdateAlbumArt( EMPXAlbumArtEditorDialogNoAlbumArt ); |
|
271 } |
|
272 if ( iObserver ) |
|
273 { |
|
274 TRAP_IGNORE ( |
|
275 iObserver->HandleAlbumArtEventL( |
|
276 EMPXAlbumArtEventExtractCompleted, aErr ) ); |
|
277 } |
|
278 } |
|
279 |
|
280 // ----------------------------------------------------------------------------- |
|
281 // CMPXAlbumArtEditorDialogCustomControl::Draw |
|
282 // Draws to the display |
|
283 // ----------------------------------------------------------------------------- |
|
284 // |
|
285 void CMPXAlbumArtEditorDialogCustomControl::Draw( const TRect& aRect ) const |
|
286 { |
|
287 MPX_FUNC( "CMPXAlbumArtEditorDialogCustomControl::Draw" ); |
|
288 CWindowGc& gc = SystemGc(); |
|
289 if ( iBackground ) |
|
290 { |
|
291 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
292 AknsDrawUtils::DrawBackground( |
|
293 skin, |
|
294 iBackground, |
|
295 this, |
|
296 gc, |
|
297 aRect.iTl, |
|
298 aRect, |
|
299 KAknsDrawParamDefault ); |
|
300 } |
|
301 else |
|
302 { |
|
303 gc.Clear( aRect ); |
|
304 } |
|
305 gc.SetClippingRect( aRect ); |
|
306 switch( iMode ) |
|
307 { |
|
308 case EMPXAlbumArtEditorDialogAlbumArt: |
|
309 { |
|
310 gc.SetBrushColor( KRgbBlack ); |
|
311 gc.SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
312 gc.DrawRect( iBorder ); |
|
313 break; |
|
314 } |
|
315 case EMPXAlbumArtEditorDialogBlank: |
|
316 { |
|
317 break; |
|
318 } |
|
319 default: // either various of no album art |
|
320 { |
|
321 break; |
|
322 } |
|
323 } |
|
324 } |
|
325 |
|
326 // ----------------------------------------------------------------------------- |
|
327 // CMPXAlbumArtEditorDialogCustomControl::CountComponentControls |
|
328 // Returns the number of components in the container. |
|
329 // ----------------------------------------------------------------------------- |
|
330 // |
|
331 TInt CMPXAlbumArtEditorDialogCustomControl::CountComponentControls() const |
|
332 { |
|
333 MPX_FUNC( "CMPXAlbumArtEditorDialogCustomControl::CountComponentControls" ); |
|
334 return KMPXLabelCount; |
|
335 } |
|
336 |
|
337 // ----------------------------------------------------------------------------- |
|
338 // CMPXAlbumArtEditorDialogCustomControl::ComponentControl |
|
339 // Returns the control given the index. |
|
340 // ----------------------------------------------------------------------------- |
|
341 // |
|
342 CCoeControl* CMPXAlbumArtEditorDialogCustomControl::ComponentControl( |
|
343 TInt aIndex ) const |
|
344 { |
|
345 MPX_FUNC( "CMPXAlbumArtEditorDialogCustomControl::ComponentControl" ); |
|
346 switch ( aIndex ) |
|
347 { |
|
348 case 0: |
|
349 return iImage; |
|
350 case 1: |
|
351 return iLabel; |
|
352 default: |
|
353 return NULL; |
|
354 } |
|
355 } |
|
356 |
|
357 // ----------------------------------------------------------------------------- |
|
358 // CMPXAlbumArtEditorDialogCustomControl::SizeChanged |
|
359 // Resizes controls. |
|
360 // ----------------------------------------------------------------------------- |
|
361 // |
|
362 void CMPXAlbumArtEditorDialogCustomControl::SizeChanged() |
|
363 { |
|
364 MPX_FUNC( "CMPXAlbumArtEditorDialogCustomControl::SizeChanged" ); |
|
365 delete iBackground; |
|
366 iBackground = NULL; |
|
367 TRect appRect = iEikonEnv->EikAppUi()->ApplicationRect(); |
|
368 MPX_TRAPD( error, |
|
369 iBackground = CAknsBasicBackgroundControlContext::NewL( |
|
370 KAknsIIDQsnBgAreaMain, appRect, EFalse ) ); |
|
371 if ( error == KErrNone && iLabel ) |
|
372 { |
|
373 TRect coeRect = Rect(); |
|
374 AknLayoutUtils::LayoutLabel( iLabel, coeRect, |
|
375 R_MPX_CUI_ALBUM_ART_LAYOUT ); |
|
376 TRAP_IGNORE( HandleSkinChangedL() ); |
|
377 } |
|
378 } |
|
379 |
|
380 // End of File |