|
1 /* |
|
2 * Copyright (c) 2008-2009 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: A visual representing an image/video/etc thumbnail |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 /** |
|
22 * @internal reviewed 04/07/2007 by M Byrne |
|
23 */ |
|
24 |
|
25 #ifndef C_GLXITEMVISUAL_H |
|
26 #define C_GLXITEMVISUAL_H |
|
27 |
|
28 #include <e32base.h> |
|
29 #include <alf/alfimagevisual.h> // for CAlfImageVisual::TScaleMode |
|
30 #include <alf/alfanchorlayout.h> // for anchor types |
|
31 #include <alf/alfimage.h> // TAlfImage |
|
32 // FORWARD DECLARATIONS |
|
33 class CAlfAnchorLayout; |
|
34 class CAlfDeckLayout; |
|
35 class CAlfLayout; |
|
36 class CAlfControl; |
|
37 class CAlfBrush; |
|
38 |
|
39 class TMPXAttribute; |
|
40 |
|
41 |
|
42 class CAlfDisplay; |
|
43 class CAlfTexture; |
|
44 class CAlfImageBrush; |
|
45 class CGlxUiUtility; |
|
46 class TGlxMedia; |
|
47 class TGlxAnchors; |
|
48 // INCLUDES |
|
49 #include <e32base.h> |
|
50 #include <alf/alfanchorlayout.h> |
|
51 #include <alf/alfimage.h> // TAlfImage |
|
52 #include <alf/alfimagevisual.h> |
|
53 #include <glxlayouthelper.h> |
|
54 #include <glxmediaid.h> |
|
55 #include <mglxtextureobserver.h> |
|
56 class MGlxMediaList; |
|
57 #include "glxiconmgrdefs.h" |
|
58 |
|
59 class MGlxVisualObjectStatusObserver; |
|
60 class MGlxVisualObjectLayoutRefreshObserver; |
|
61 /** |
|
62 * MGlxVisualObjectParameterFactory |
|
63 * Interface for the CGlxVisualObject |
|
64 * to retrieve parameters for visual creation |
|
65 * |
|
66 * @author Kimmo Hoikka |
|
67 */ |
|
68 class MGlxVisualObjectParameterFactory |
|
69 { |
|
70 protected: |
|
71 |
|
72 /** |
|
73 * Destructor, dont allow deletion through this interface |
|
74 */ |
|
75 virtual ~MGlxVisualObjectParameterFactory() { }; |
|
76 |
|
77 public: |
|
78 |
|
79 /** |
|
80 * @return the HUI layout for the visual object |
|
81 */ |
|
82 virtual CAlfLayout* Layout() = 0; |
|
83 |
|
84 /** |
|
85 * @return the HUI control that owns the HUI object |
|
86 */ |
|
87 virtual CAlfControl& VisualOwner() = 0; |
|
88 |
|
89 /** |
|
90 * Ownership of the brush stays in the factory |
|
91 * |
|
92 * @return the Border brush for the Visual. |
|
93 */ |
|
94 virtual CAlfBrush* BorderBrush() = 0; |
|
95 |
|
96 /** |
|
97 * @return the scale mode to use for the thumbnails |
|
98 */ |
|
99 virtual CAlfImageVisual::TScaleMode ThumbnailScaleMode() = 0; |
|
100 }; |
|
101 |
|
102 /** |
|
103 * CGlxVisualObject |
|
104 * |
|
105 * A visual representing an image/video/etc thumbnail |
|
106 * |
|
107 * @author Kimmo Hoikka |
|
108 */ |
|
109 class CGlxVisualObject : public CBase, public MGlxTextureObserver |
|
110 { |
|
111 public: |
|
112 /** |
|
113 * Thumbnail/icon status of a visual. |
|
114 */ |
|
115 enum TVisualStatus |
|
116 { |
|
117 EHasDefaultIcon, EHasErrorIcon, EHasOtherIcon, EHasThumbnail |
|
118 }; |
|
119 |
|
120 public: |
|
121 /** |
|
122 * Constructor. |
|
123 * @param aParent the parent HUI control |
|
124 * @param aLayout the layout chain for the visual |
|
125 */ |
|
126 static CGlxVisualObject* NewLC( |
|
127 MGlxVisualObjectParameterFactory& aFactory, |
|
128 MGlxMediaList& aMediaList ); |
|
129 |
|
130 /** |
|
131 * Destructor |
|
132 */ |
|
133 ~CGlxVisualObject(); |
|
134 |
|
135 |
|
136 /** |
|
137 * Set the scale mode for the visual. |
|
138 * @param aMode The scale mode to be used. |
|
139 */ |
|
140 IMPORT_C void SetScaleMode(CAlfImageVisual::TScaleMode aMode); |
|
141 |
|
142 /** |
|
143 * @return the visual of this object |
|
144 */ |
|
145 CAlfVisual* Visual(); |
|
146 |
|
147 /** |
|
148 * Set the visual either visible or invisible |
|
149 * @param aVisible If true, set visible, otherwise invisible |
|
150 */ |
|
151 void SetVisible( TBool aVisible ); |
|
152 |
|
153 /** |
|
154 * Sets the index |
|
155 * @param aIndex, the index of this visual |
|
156 */ |
|
157 void SetIndex( TInt aIndex ); |
|
158 |
|
159 /** |
|
160 * Specifies the image for the visual |
|
161 * @param aImage the image |
|
162 * @param aImageId the image id |
|
163 */ |
|
164 void SetImage( TAlfImage aImage ); |
|
165 |
|
166 /** |
|
167 * @return the THuiImage that corresponds to the image |
|
168 */ |
|
169 TAlfImage Image(); |
|
170 |
|
171 /** |
|
172 * Notify that the display refresh has just started |
|
173 * @param aDisplay the HUI display |
|
174 */ |
|
175 void RefreshLayout( TSize aScreenSize ); |
|
176 |
|
177 /** |
|
178 * Handle new attributes recieved for the item |
|
179 * @param aIdSpaceId ID space ID of the media item |
|
180 * @param aItem Media item to check attributes |
|
181 * @param aAttributes Array of new attributes |
|
182 */ |
|
183 void HandleAttributesAvailableL( const TGlxIdSpaceId& aIdSpaceId, |
|
184 const TGlxMedia& aItem, |
|
185 const RArray<TMPXAttribute>& aAttributes); |
|
186 |
|
187 /** |
|
188 * Start an animation |
|
189 * @param aAnimatedTexture The animated texture to use |
|
190 */ |
|
191 void StartAnimation( CAlfTexture& aAnimatedTexture ); |
|
192 |
|
193 /** |
|
194 * Stop current animation |
|
195 */ |
|
196 void StopAnimation(); |
|
197 |
|
198 /** |
|
199 * Set a flag indicating whether an item should be animated |
|
200 * when all necessary attributes have been fetched |
|
201 * @param aFlag Value of the flag |
|
202 */ |
|
203 void SetAnimateWhenAttributesAvailable(TBool aFlag); |
|
204 |
|
205 /** |
|
206 * Try to start an item animation, if available |
|
207 * @param aItem Media item to animate |
|
208 */ |
|
209 void TryAnimateL(const TGlxMedia& aItem); |
|
210 |
|
211 /** |
|
212 * Add icon to visual |
|
213 * @param aTexture texture of icon to apply |
|
214 * @param aIconPos position of icon (centred or relative to a specific corner) |
|
215 * @param aForeground foreground or background icon |
|
216 * @param aStretch ETrue if texture scales to visual |
|
217 * @param aBorderMargin margin from specified corner |
|
218 * @param aWidth width as proportion of visual width |
|
219 * @param aHeight height as proportion of height width |
|
220 */ |
|
221 void AddIconL( const CAlfTexture& aTexture, NGlxIconMgrDefs::TGlxIconPosition aIconPos, |
|
222 TBool aForeground, TBool aStretch, TInt aBorderMargin, |
|
223 TReal32 aWidth, TReal32 aHeight ); |
|
224 |
|
225 /** |
|
226 * Remove icon from visual |
|
227 * @param aTexture texture of icon to remove |
|
228 */ |
|
229 TBool RemoveIcon( const CAlfTexture& aTexture ); |
|
230 |
|
231 /** |
|
232 * Hide or show icon if required |
|
233 * @param aTexture texture of icon |
|
234 * @param aVisible Set hidden or show |
|
235 */ |
|
236 void SetIconVisibility( const CAlfTexture& aTexture, TBool aVisible ); |
|
237 |
|
238 /** |
|
239 * Get thumbnail/icon status. |
|
240 * @return Current status. |
|
241 */ |
|
242 TVisualStatus Status() const; |
|
243 /** |
|
244 * Set thumbnail/icon status. |
|
245 * @param aStatus New status. |
|
246 */ |
|
247 void SetStatus( TVisualStatus aStatus ); |
|
248 |
|
249 /** |
|
250 * Set observer to be notified when the thumbnail texture gains or |
|
251 * loses content. |
|
252 * @param aObserver Observer for the thumbnail status. |
|
253 * @return Whether the thumbnail texture currently has content. |
|
254 */ |
|
255 TBool SetObserver( MGlxVisualObjectStatusObserver& aObserver ); |
|
256 |
|
257 |
|
258 /** |
|
259 * Set observer to be notified when the thumbnail texture gains or |
|
260 * loses content. |
|
261 * @param aObserver Observer for the thumbnail status. |
|
262 * @return Whether the thumbnail texture currently has content. |
|
263 */ |
|
264 void AddObserver( MGlxVisualObjectLayoutRefreshObserver* aObserver ); |
|
265 |
|
266 void RemoveObserver( MGlxVisualObjectLayoutRefreshObserver* aObserver ); |
|
267 |
|
268 void Reset(); |
|
269 void ResetLayout( CAlfVisual& aVisual ); |
|
270 |
|
271 private: // From MGlxTextureObserver |
|
272 void TextureContentChangedL( TBool aHasContent, CAlfTexture* aNewTexture ); |
|
273 |
|
274 private: |
|
275 // default constructor |
|
276 CGlxVisualObject( MGlxMediaList& aMediaList); |
|
277 |
|
278 // 2nd phase constructor |
|
279 void ConstructL( MGlxVisualObjectParameterFactory& aFactory); |
|
280 |
|
281 /** |
|
282 * Remove zoom tiles for attributes no longer available |
|
283 * @param aItem Media item to check attributes |
|
284 */ |
|
285 void RemoveOldZoomTiles(const TGlxMedia& aItem); |
|
286 /** |
|
287 * Add zoom tiles for new cropped thumbnail attributes |
|
288 * @param aIdSpaceId ID space ID of the media item |
|
289 * @param aItem Media item to check attributes |
|
290 * @param aAttributes Array of new attributes |
|
291 */ |
|
292 void AddNewZoomTilesL(TGlxIdSpaceId aIdSpaceId, const TGlxMedia& aItem, |
|
293 const RArray<TMPXAttribute>& aAttributes); |
|
294 |
|
295 /** |
|
296 * Remove a zoom tile visual from the array and delete it. |
|
297 * @param aIndex Which tile to remove. |
|
298 */ |
|
299 void RemoveZoomTile(TInt aIndex); |
|
300 |
|
301 /** |
|
302 * Create a zoom tile visual as a child of the anchor layout. |
|
303 * @param aItem Media item to check attributes |
|
304 * @param aAttribute Cropped thumbnail attribute |
|
305 * @param aIdSpaceId ID space ID of the media item |
|
306 * @param aCroppingRect Cropping rect for the tile. |
|
307 */ |
|
308 TInt AddZoomTileL( |
|
309 const TGlxMedia& aItem, const TMPXAttribute& aAttribute, |
|
310 TGlxIdSpaceId aIdSpaceId, const TRect& aCroppingRect ); |
|
311 |
|
312 /** |
|
313 * Reapply the anchors to tiles which have changed position (anchor |
|
314 * layout doesn't reorder the anchors when the child order changes). |
|
315 * @param aFirstPosition Index of first tile which has changed. |
|
316 */ |
|
317 void ReanchorZoomTiles( TInt aFirstPosition ); |
|
318 |
|
319 /** |
|
320 * Structure to hold icon anchor details |
|
321 */ |
|
322 class TGlxAnchorDetails |
|
323 { |
|
324 public: |
|
325 TAlfAnchorOrigin iAnchorHorizOrigin; |
|
326 TAlfAnchorOrigin iAnchorVertiOrigin; |
|
327 TAlfAnchorMetric iAnchorMetric; |
|
328 TAlfTimedPoint iPosition; |
|
329 }; |
|
330 |
|
331 /** |
|
332 * Structure to store both anchors for an icon |
|
333 */ |
|
334 class TGlxIconAnchors |
|
335 { |
|
336 public: |
|
337 /** |
|
338 * Helper method to compare two icons |
|
339 */ |
|
340 static TBool Match( const TGlxIconAnchors& aIcon1, |
|
341 const TGlxIconAnchors& aIcon2 ); |
|
342 |
|
343 /// The texture for this icon (not owned) |
|
344 const CAlfTexture* iTexture; |
|
345 TGlxAnchorDetails iTopLeftAnchor; |
|
346 TGlxAnchorDetails iBotRightAnchor; |
|
347 }; |
|
348 |
|
349 |
|
350 /** |
|
351 * Calculate anchors based on icon position and scaling |
|
352 * @param aAnchors Structure to hold anchor information |
|
353 * @param aTexture Texture used to create icon (need texture size) |
|
354 * @param aIconPos position of icon (relative to specified corner |
|
355 * or central) |
|
356 * @param aBorderMargin distance from corner of icon |
|
357 * @param aStretch is texture icon to scaled with layout or fixed size |
|
358 */ |
|
359 void GenerateAnchors( TGlxIconAnchors& aAnchors, |
|
360 const CAlfTexture& aTexture, |
|
361 NGlxIconMgrDefs::TGlxIconPosition aIconPos, |
|
362 TInt aBorderMargin, TBool aStretch, |
|
363 TReal32 aWidth, TReal32 aHeight ); |
|
364 |
|
365 /** |
|
366 * Set the anchors |
|
367 * @param aAnchors Structure to hold anchor information |
|
368 * @param aLayout Layout (foreground or background) |
|
369 * @param aPos position of icon in layout |
|
370 * @param aUseOffsets whether to apply horizontal and vertical offsets |
|
371 * to anchors |
|
372 */ |
|
373 void SetAnchors( TGlxIconAnchors& aAnchors, CAlfAnchorLayout& aLayout, |
|
374 TInt aPos, TBool aUseOffsets = EFalse ); |
|
375 |
|
376 |
|
377 /** |
|
378 * Find position in layout of icon with specified texture |
|
379 * @param aTexture Texture to search for |
|
380 * @param aForeground ETrue if icon is in foreground, EFalse if background |
|
381 * @return positon of icon in layout, KErrNotFound if icon not present |
|
382 */ |
|
383 TInt FindExistingTexture( const CAlfTexture& aTexture, TBool aForeground ); |
|
384 |
|
385 /** |
|
386 * Remove icon and reset anchors for following icons. |
|
387 * @param aLayout Layout (foreground or background) |
|
388 * @param aAnchorsArray Stored anchors for specified layout |
|
389 * @param aPos position in layout of icon that was removed |
|
390 */ |
|
391 void DoRemoveIcon( CAlfAnchorLayout& aLayout, |
|
392 RArray<TGlxIconAnchors>& aAnchorsArray, |
|
393 TInt aPos ); |
|
394 |
|
395 /** |
|
396 * If visual has resized calcuate offsets for overlay icons (so we can |
|
397 * ensure icons are positioned over thumbnail if thumbnail dos not fill visual) |
|
398 * @param aTexture texture for image |
|
399 * @param aVisSize size of visual |
|
400 */ |
|
401 void UpdateIconAnchors( const CAlfTexture& aTexture, TSize aVisSize ); |
|
402 |
|
403 |
|
404 |
|
405 private: // Data |
|
406 /** |
|
407 * Structure to hold information about a zoom tile visual. |
|
408 */ |
|
409 class TZoomTile |
|
410 { |
|
411 public: |
|
412 /** Visual to display the tile (not owned) */ |
|
413 CAlfImageVisual* iVisual; |
|
414 /** Attribute ID of the cropped thumbnail */ |
|
415 TUint iAttributeId; |
|
416 /** Zoom level of the cropped thumbnail */ |
|
417 TInt iZoomLevel; |
|
418 /** Anchor point for top left of tile */ |
|
419 TAlfRealPoint iTopLeft; |
|
420 /** Anchor point for bottom right of tile */ |
|
421 TAlfRealPoint iBottomRight; |
|
422 }; |
|
423 |
|
424 /// Own: the index |
|
425 TInt iIndex; |
|
426 MGlxMediaList& iMediaList; |
|
427 |
|
428 /// Top-level visual |
|
429 CAlfAnchorLayout* iVisual; |
|
430 |
|
431 /// The visual that handles the drawing of image(not owned) |
|
432 CAlfAnchorLayout* iMainVisual; |
|
433 |
|
434 /// The visual that handles the drawing of background underlay icons |
|
435 /// (not owned) |
|
436 CAlfImageVisual* iBackgroundOverlayVisual; |
|
437 |
|
438 /// Child visual for normal image items (not owned) |
|
439 CAlfImageVisual* iImageVisual; |
|
440 |
|
441 /// Own: the HUI image |
|
442 TAlfImage iImage; |
|
443 TBool iImageValid; |
|
444 /// Own: the HUI animated texture |
|
445 CAlfTexture* iAnimatedTexture; |
|
446 /// Whether this item should be animated when the correct attributes |
|
447 /// are available |
|
448 TBool iAnimateWhenAttributesAvailable; |
|
449 /// Own: The HUI utility |
|
450 CGlxUiUtility* iUiUtility; |
|
451 /// Own: Array of tiles for zoomed image |
|
452 RArray<TZoomTile> iZoomTiles; |
|
453 /// Original image dimensions |
|
454 TSize iDimensions; |
|
455 |
|
456 /// Anchor details for foreground overlay icons |
|
457 RArray<TGlxIconAnchors> iForegroundIconAnchors; |
|
458 |
|
459 // Anchor details for background 'underlay' icons |
|
460 RArray<TGlxIconAnchors> iBackgroundIconAnchors; |
|
461 |
|
462 // vertical offset for overlay icons |
|
463 TReal32 iVertIconOffset; |
|
464 |
|
465 // horizontal offset for overlay icons |
|
466 TReal32 iHoriIconOffset; |
|
467 |
|
468 // Store size of visual |
|
469 TSize iVisSize; |
|
470 |
|
471 /// Current thumbnail/icon status |
|
472 TVisualStatus iStatus; |
|
473 |
|
474 /// Observer of this visual object. |
|
475 MGlxVisualObjectStatusObserver* iObserver; |
|
476 |
|
477 // The id of the zoom texture from the texture manager |
|
478 TInt iZoomTextureId; |
|
479 |
|
480 /** Array of observers (owned) */ |
|
481 RPointerArray<MGlxVisualObjectLayoutRefreshObserver> iObservers; |
|
482 |
|
483 }; |
|
484 |
|
485 #endif // C_GLXITEMVISUAL_H |