|
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: Class for displaying the images captured by a Burst session.* |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <coecntrl.h> |
|
21 #include <fbs.h> |
|
22 #include <eikscrlb.h> // For CEikScrollBar |
|
23 #include <bitmaptransforms.h> // For CBitmapScaler |
|
24 #include <eikenv.h> |
|
25 #include <eiksbfrm.h> |
|
26 #include <barsread.h> // For TResourceReader |
|
27 #include <cameraapp.mbg> |
|
28 #include <AknIconArray.h> |
|
29 #include <AknIconUtils.h> |
|
30 #include <avkon.mbg> // EMbmAvkonQgn_indi_marked_grid_add |
|
31 |
|
32 #include <cameraapp.rsg> |
|
33 #include <vgacamsettings.rsg> |
|
34 |
|
35 #include <AknsUtils.h> |
|
36 #include <AknsDrawUtils.h> |
|
37 #include <aknlayoutscalable_apps.cdl.h> // AknLayoutScalable_Apps |
|
38 |
|
39 #include "camuiconstants.h" |
|
40 |
|
41 #include "CamUtility.h" |
|
42 #include "CamBurstThumbnailGrid.h" |
|
43 #include "CamAppUi.h" |
|
44 #include "CamPanic.h" |
|
45 |
|
46 // EXTERNAL DATA STRUCTURES |
|
47 |
|
48 // EXTERNAL FUNCTION PROTOTYPES |
|
49 |
|
50 // CONSTANTS |
|
51 |
|
52 // MACROS |
|
53 |
|
54 // LOCAL CONSTANTS AND MACROS |
|
55 |
|
56 // MODULE DATA STRUCTURES |
|
57 |
|
58 // LOCAL FUNCTION PROTOTYPES |
|
59 |
|
60 // FORWARD DECLARATIONS |
|
61 |
|
62 // ============================= LOCAL FUNCTIONS =============================== |
|
63 |
|
64 |
|
65 // ============================ MEMBER FUNCTIONS =============================== |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CCamBurstThumbnailGrid::CCamBurstThumbnailGrid |
|
69 // C++ default constructor can NOT contain any code, that |
|
70 // might leave. |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 CCamBurstThumbnailGrid::CCamBurstThumbnailGrid( CCamBurstThumbnailGridModel& aModel ) : |
|
74 iModel( aModel ) |
|
75 { |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CCamBurstThumbnailGrid::ConstructL |
|
80 // Symbian 2nd phase constructor can leave. |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 void CCamBurstThumbnailGrid::ConstructL( const CCoeControl* aParent ) |
|
84 {// Fill in the model |
|
85 |
|
86 SetContainerWindowL( *aParent ); |
|
87 |
|
88 // Generate the grid size (either 6 for 3x2 or 9 for 3x3 grid) |
|
89 iGridSize = iModel.GridHeight() * KGridWidth; |
|
90 |
|
91 |
|
92 |
|
93 // Create component bitmaps |
|
94 // TFileName resFileName; |
|
95 //CamUtility::ResourceFileName( resFileName ); |
|
96 //TPtrC resname = resFileName; |
|
97 |
|
98 iBitmapMark = NULL; |
|
99 iBitmapMarkMask = NULL; |
|
100 |
|
101 AknIconUtils::CreateIconL( iBitmapMark, |
|
102 iBitmapMarkMask, |
|
103 AknIconUtils::AvkonIconFileName(), |
|
104 EMbmAvkonQgn_indi_marked_grid_add, |
|
105 EMbmAvkonQgn_indi_marked_grid_add_mask ); |
|
106 |
|
107 // Request notification of Deletion and new Thumbnail events |
|
108 iModel.AddModelObserverL( this, CCamBurstThumbnailGridModel::EModelEventDeleted | |
|
109 CCamBurstThumbnailGridModel::EModelEventThumb ); |
|
110 |
|
111 |
|
112 UpdateLayout(); |
|
113 } |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // CCamBurstThumbnailGrid::NewL |
|
117 // Two-phased constructor. |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 CCamBurstThumbnailGrid* CCamBurstThumbnailGrid::NewL( const CCoeControl* aParent, CCamBurstThumbnailGridModel& aModel ) |
|
121 { |
|
122 CCamBurstThumbnailGrid* self = new( ELeave ) CCamBurstThumbnailGrid( aModel ); |
|
123 |
|
124 CleanupStack::PushL( self ); |
|
125 self->ConstructL( aParent ); |
|
126 CleanupStack::Pop(); |
|
127 |
|
128 return self; |
|
129 } |
|
130 |
|
131 |
|
132 // Destructor |
|
133 CCamBurstThumbnailGrid::~CCamBurstThumbnailGrid() |
|
134 { |
|
135 delete iBitmapMark; |
|
136 delete iBitmapMarkMask; |
|
137 |
|
138 // Remove notification of Deletion and new Thumbnail events |
|
139 iModel.RemoveModelObserver( this, CCamBurstThumbnailGridModel::EModelEventDeleted | |
|
140 CCamBurstThumbnailGridModel::EModelEventThumb ); |
|
141 |
|
142 DeleteScrollBar(); |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CCamBurstThumbnailGrid::Draw |
|
147 // The control's drawing function |
|
148 // ----------------------------------------------------------------------------- |
|
149 // |
|
150 void CCamBurstThumbnailGrid::Draw( const TRect& aRect ) const |
|
151 { |
|
152 PRINT( _L("Camera => CCamBurstThumbnailGrid::Draw") ); |
|
153 |
|
154 CWindowGc& gc = SystemGc(); |
|
155 |
|
156 // Draw skin background |
|
157 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
158 MAknsControlContext* cc = AknsDrawUtils::ControlContext( this ); |
|
159 AknsDrawUtils::Background( skin, cc, gc, Rect() ); |
|
160 |
|
161 TInt index = 0; |
|
162 TInt visibleIndex = iModel.TopLeftGridIndex(); // first visible item index |
|
163 TInt y = 0; |
|
164 TInt x = 0; |
|
165 for ( y = 0; y < iModel.GridHeight(); y++ ) // height of visible grid |
|
166 { |
|
167 for ( x = 0; x < KGridWidth; x++ ) |
|
168 { |
|
169 |
|
170 if ( visibleIndex >= iModel.NoOfValidCells() ) |
|
171 { |
|
172 break; // only breaks the inner for-loop |
|
173 } |
|
174 |
|
175 // Draw the outline rectangle for the Cell |
|
176 //gc.SetPenColor( KGreyOutline ); // From the screenshot |
|
177 TRect r = iGridCellLayout[ index ].iCellRect.Rect(); |
|
178 |
|
179 // draw background highlight for the focused item |
|
180 if ( iModel.HighlightedGridIndex() == visibleIndex ) |
|
181 { |
|
182 #ifdef _DEBUG |
|
183 TRect _cell = iGridCellLayout[ index ].iCellRect.Rect(); |
|
184 TRect _high = iGridCellLayout[ index ].iHighRect.Rect(); |
|
185 TRect _thmb = iGridCellLayout[ index ].iThmbRect.Rect(); |
|
186 PRINT4( _L("Camera <> CCamBurstThumbnailGrid - grid cell rect[x:%d y:%d w:%d h%d]"), |
|
187 _cell.iTl.iX, _cell.iTl.iY, _cell.Width(), _cell.Height() ); |
|
188 PRINT4( _L("Camera <> CCamBurstThumbnailGrid - highlight rect[x:%d y:%d w:%d h%d]"), |
|
189 _high.iTl.iX, _high.iTl.iY, _high.Width(), _high.Height() ); |
|
190 PRINT4( _L("Camera <> CCamBurstThumbnailGrid - thumbnail rect[x:%d y:%d w:%d h%d]"), |
|
191 _thmb.iTl.iX, _thmb.iTl.iY, _thmb.Width(), _thmb.Height() ); |
|
192 #endif // _DEBUG |
|
193 |
|
194 TRgb highlight; |
|
195 AknsUtils::GetCachedColor( skin, highlight, KAknsIIDQsnHighlightColors, |
|
196 EAknsCIQsnHighlightColorsCG1 ); |
|
197 PRINT1( _L("Camera <> CCamBurstThumbnailGrid::Draw - highlight color: 0x%08x"), highlight.Internal() ); |
|
198 gc.SetBrushColor( highlight ); |
|
199 gc.Clear( r ); |
|
200 } |
|
201 |
|
202 |
|
203 CThumbnailGridItem* item = iModel.GridItem( visibleIndex ); |
|
204 |
|
205 if ( item ) |
|
206 { |
|
207 |
|
208 TRect trgRect( iGridCellLayout[ index ].iThmbRect.Rect() ); |
|
209 if ( item->iDisplayThumb ) |
|
210 { |
|
211 PRINT( _L("Camera <> CCamBurstThumbnailGrid::Draw - prescaled thumb available") ); |
|
212 |
|
213 // Thumbnail grid sizer provides an image that fits |
|
214 // to the given rect by one dimension and is larger in the other. |
|
215 // (If aspect ratios don't match.) Crop the oversize area. |
|
216 gc.SetClippingRect( trgRect ); |
|
217 |
|
218 const TSize& bmpSize( item->iDisplayThumb->SizeInPixels() ); |
|
219 PRINT2( _L("Camera <> CCamBurstThumbnailGrid - bmp size [w:%d h%d]"), |
|
220 bmpSize.iWidth, bmpSize.iHeight ); |
|
221 |
|
222 PRINT2( _L("Camera <> CCamBurstThumbnailGrid - cell size [w:%d h%d]"), |
|
223 trgRect.Width(), trgRect.Height() ); |
|
224 |
|
225 // Move the start of drawing so, that the image stays centered to the available area. |
|
226 TInt widthDif = bmpSize.iWidth - trgRect.Width(); |
|
227 TInt heightDif = bmpSize.iHeight - trgRect.Height(); |
|
228 TPoint drawTl = trgRect.iTl - TPoint( widthDif/2, heightDif/2 ); |
|
229 PRINT2( _L("Camera <> CCamBurstThumbnailGrid - draw start offset [x:%d y%d]"), |
|
230 widthDif, heightDif ); |
|
231 |
|
232 gc.BitBlt( drawTl, item->iDisplayThumb ); |
|
233 gc.SetClippingRect( aRect ); |
|
234 } |
|
235 else // no rescaled bitmap exists, and we can fast-rescale snapshot |
|
236 { |
|
237 PRINT( _L("Camera <> CCamBurstThumbnailGrid::Draw - prescaled thumb NOT available") ); |
|
238 const CFbsBitmap* bmp = iModel.Snapshot( iModel.TopLeftGridIndex() + index ); |
|
239 |
|
240 if ( bmp ) |
|
241 { |
|
242 TSize bmpSize( bmp->SizeInPixels() ); |
|
243 TRect srcRect( bmpSize ); |
|
244 |
|
245 TReal bmpRatio( TReal( bmpSize.iWidth ) / TReal( bmpSize.iHeight ) ); |
|
246 TReal trgRatio( TReal( trgRect.Width() ) / TReal( trgRect.Height() ) ); |
|
247 |
|
248 if( bmpRatio > trgRatio ) |
|
249 { |
|
250 // Thumbnail aspect ratio is wider than the target cell area. |
|
251 // Crop some of the thumbnail width off and fill the target rect. |
|
252 const TInt width = Max( bmpSize.iHeight * trgRatio, 1 ); |
|
253 const TInt crop = ( bmpSize.iWidth - width ) / 2; |
|
254 srcRect.Shrink( crop, 0 ); |
|
255 } |
|
256 if( bmpRatio < trgRatio ) |
|
257 { |
|
258 // Bitmap is higher than the screen. |
|
259 // Crop some of the thumbnail height off and fill the target rect. |
|
260 const TInt height = Max( bmpSize.iWidth * trgRatio, 1 ); |
|
261 const TInt crop = ( bmpSize.iHeight - height ) / 2; |
|
262 srcRect.Shrink( 0, crop ); |
|
263 } |
|
264 |
|
265 PRINT2( _L("Camera <> CCamBurstThumbnailGrid - bmp size [w:%d h%d]"), |
|
266 bmpSize.iWidth, bmpSize.iHeight ); |
|
267 PRINT4( _L("Camera <> CCamBurstThumbnailGrid - bmp cropped [x:%d y:%d w:%d h%d]"), |
|
268 srcRect.iTl.iX, srcRect.iTl.iY, srcRect.Width(), srcRect.Height() ); |
|
269 PRINT4( _L("Camera <> CCamBurstThumbnailGrid - trg rect [x:%d y:%d w:%d h%d]"), |
|
270 trgRect.iTl.iX, trgRect.iTl.iY, trgRect.Width(), trgRect.Height() ); |
|
271 |
|
272 gc.DrawBitmap( trgRect, bmp, srcRect ); |
|
273 } |
|
274 |
|
275 } |
|
276 |
|
277 // Draw the marked symbol |
|
278 if ( item->iMarked ) |
|
279 { |
|
280 PRINT2(_L("CAMERA <> CCamBurstThumbnailGrid::Draw (item marked) x:%d y:%d"), x, y ) |
|
281 |
|
282 TRect mark = iGridCellLayout[ index ].iMarkRect.Rect(); |
|
283 |
|
284 gc.SetBrushStyle( CGraphicsContext::ENullBrush ); // Make sure background isn't drawn |
|
285 gc.BitBltMasked( iGridCellLayout[ index ].iMarkRect.Rect().iTl, |
|
286 iBitmapMark, |
|
287 iBitmapMark->SizeInPixels(), |
|
288 iBitmapMarkMask, |
|
289 EFalse ); |
|
290 |
|
291 } |
|
292 |
|
293 } // end of: if ( item ) |
|
294 |
|
295 index++; |
|
296 visibleIndex++; |
|
297 } // for x |
|
298 } // for y |
|
299 |
|
300 PRINT( _L("Camera <= CCamBurstThumbnailGrid::Draw") ); |
|
301 } |
|
302 |
|
303 // --------------------------------------------------------- |
|
304 // CCamBurstThumbnailGrid::CountComponentControls |
|
305 // Returns the number of component controls |
|
306 // --------------------------------------------------------- |
|
307 // |
|
308 TInt CCamBurstThumbnailGrid::CountComponentControls() const |
|
309 { |
|
310 TInt count = 0; // Return the number of controls inside this container |
|
311 if ( iScrollFrame ) |
|
312 { |
|
313 count = iScrollFrame->CountComponentControls(); |
|
314 } |
|
315 return count; |
|
316 } |
|
317 |
|
318 // --------------------------------------------------------- |
|
319 // CCamBurstThumbnailGrid::SizeChanged |
|
320 // Constructs the grid layout structure |
|
321 // --------------------------------------------------------- |
|
322 // |
|
323 void CCamBurstThumbnailGrid::SizeChanged() |
|
324 { |
|
325 |
|
326 PRINT( _L("Camera => CCamBurstThumbnailGrid::SizeChanged()") ); |
|
327 |
|
328 ReadLayout(); |
|
329 |
|
330 // set the new thumbnail size for gridmodel (to be used with thumbnail scaling) |
|
331 // use layout for the first cell (all thumbnails are same size) |
|
332 iModel.SetThumbnailSize( iGridCellLayout[0].iThmbRect.Rect().Size() ); |
|
333 |
|
334 AknIconUtils::SetSize( iBitmapMark, iGridCellLayout[0].iMarkRect.Rect().Size() ); |
|
335 AknIconUtils::SetSize( iBitmapMarkMask, iGridCellLayout[0].iMarkRect.Rect().Size() ); |
|
336 |
|
337 PRINT( _L("Camera <= CCamBurstThumbnailGrid::SizeChanged()") ); |
|
338 } |
|
339 |
|
340 // --------------------------------------------------------- |
|
341 // CCamBurstThumbnailGrid::ResourceId |
|
342 // Returns the ID of the resource to use for the grid structure |
|
343 // --------------------------------------------------------- |
|
344 // |
|
345 TInt CCamBurstThumbnailGrid::ResourceId() |
|
346 { |
|
347 TInt resource = 0; |
|
348 if ( iModel.NoOfValidCells() > KSmallGridCellCount ) |
|
349 { |
|
350 if ( !AknLayoutUtils::LayoutMirrored() ) |
|
351 { |
|
352 resource = R_CAM_BURST_POST_CAPTURE_GRID_ARRAY; |
|
353 } |
|
354 else |
|
355 { |
|
356 resource = R_CAM_BURST_POST_CAPTURE_GRID_ARRAY; |
|
357 } |
|
358 } |
|
359 else // Else six or less image to be used |
|
360 { |
|
361 if ( !AknLayoutUtils::LayoutMirrored() ) |
|
362 { |
|
363 resource = R_CAM_BURST_POST_CAPTURE_GRID_ARRAY_UPTO_SIX; |
|
364 } |
|
365 else |
|
366 { |
|
367 resource = R_CAM_BURST_POST_CAPTURE_GRID_ARRAY_UPTO_SIX_AH; |
|
368 } |
|
369 } |
|
370 return resource; |
|
371 } |
|
372 |
|
373 // --------------------------------------------------------- |
|
374 // CCamBurstThumbnailGrid::ReadLayoutL |
|
375 // --------------------------------------------------------- |
|
376 // |
|
377 void CCamBurstThumbnailGrid::ReadLayout() |
|
378 { |
|
379 PRINT( _L("Camera => CCamBurstThumbnailGrid::ReadLayout() ") ); |
|
380 |
|
381 |
|
382 TInt layoutVariantForThumbnail = 0; |
|
383 TInt layoutVariantForCell = 1; |
|
384 |
|
385 if ( iModel.NoOfValidCells() <= KBurstGridDefaultThumbnails) |
|
386 { |
|
387 layoutVariantForThumbnail = 0; |
|
388 layoutVariantForCell = 1; |
|
389 } |
|
390 else if ( iModel.NoOfValidCells() <= KBurstGridMaxVisibleThumbnails ) |
|
391 { |
|
392 layoutVariantForThumbnail = 1; |
|
393 layoutVariantForCell = 3; |
|
394 } |
|
395 else // iModel.NoOfValidCells() > KBurstGridMaxVisibleThumbnails |
|
396 { |
|
397 layoutVariantForThumbnail = 2; |
|
398 layoutVariantForCell = 5; |
|
399 } |
|
400 |
|
401 TInt i = 0; |
|
402 TInt y = 0; |
|
403 TInt x = 0; |
|
404 |
|
405 // set all layout entries for cells |
|
406 for ( y = 0; y < iModel.GridHeight(); y++ ) |
|
407 { |
|
408 for ( x = 0; x < KGridWidth; x++ ) |
|
409 { |
|
410 iGridCellLayout[i].iCellRect.LayoutRect( Rect(), |
|
411 AknLayoutScalable_Apps::cell_cam4_burst_pane( layoutVariantForCell, x, y ) ); |
|
412 iGridCellLayout[i].iThmbRect.LayoutRect( iGridCellLayout[i].iCellRect.Rect(), |
|
413 AknLayoutScalable_Apps::cell_cam4_burst_pane_g1( layoutVariantForThumbnail, 0, 0 ) ); |
|
414 iGridCellLayout[i].iMarkRect.LayoutRect( iGridCellLayout[i].iThmbRect.Rect(), |
|
415 AknLayoutScalable_Apps::cell_cam4_burst_pane_g2( layoutVariantForThumbnail ) ); |
|
416 i++; |
|
417 } |
|
418 } |
|
419 |
|
420 PRINT( _L("Camera <= CCamBurstThumbnailGrid::ReadLayout() ") ); |
|
421 } |
|
422 |
|
423 // --------------------------------------------------------- |
|
424 // CCamBurstThumbnailGrid::ComponentControl |
|
425 // Returns the requested component control |
|
426 // --------------------------------------------------------- |
|
427 // |
|
428 CCoeControl* CCamBurstThumbnailGrid::ComponentControl( TInt aIndex ) const |
|
429 { |
|
430 if ( iScrollFrame ) |
|
431 { |
|
432 return iScrollFrame->ComponentControl( aIndex ); |
|
433 } |
|
434 else |
|
435 { |
|
436 return NULL; |
|
437 } |
|
438 } |
|
439 |
|
440 // --------------------------------------------------------- |
|
441 // CCamBurstThumbnailGrid::ThumbnailGenerated |
|
442 // Called when a thumbnail has been scaled |
|
443 // --------------------------------------------------------- |
|
444 // |
|
445 void CCamBurstThumbnailGrid::ThumbnailGenerated() |
|
446 { |
|
447 DrawDeferred(); |
|
448 } |
|
449 |
|
450 // --------------------------------------------------------- |
|
451 // CCamBurstThumbnailGrid::HandleScrollEventL |
|
452 // --------------------------------------------------------- |
|
453 // |
|
454 void CCamBurstThumbnailGrid::HandleScrollEventL( CEikScrollBar* aScrollBar, TEikScrollEvent aEventType ) |
|
455 { |
|
456 |
|
457 // compare to old position, set correct starting point for drawing the grid |
|
458 |
|
459 TInt numOfRows = ( iModel.NoOfValidCells() / KGridWidth ) ; |
|
460 if ( iModel.NoOfValidCells() % KGridWidth != 0 ) |
|
461 { |
|
462 numOfRows++; |
|
463 } |
|
464 |
|
465 TInt oldRow = ( iModel.TopLeftGridIndex() / KGridWidth ); |
|
466 if ( iModel.TopLeftGridIndex() % KGridWidth != 0 ) |
|
467 { |
|
468 oldRow++; |
|
469 } |
|
470 |
|
471 TInt newRow = aScrollBar->ThumbPosition(); |
|
472 PRINT1( _L("Camera <> CCamBurstThumbnailGrid::HandleScrollEventL - thumb postition %d"), newRow ); |
|
473 |
|
474 |
|
475 if ( oldRow != newRow ) |
|
476 { |
|
477 iModel.ScrollGrid( ETrue, newRow); |
|
478 DrawDeferred(); |
|
479 } |
|
480 } |
|
481 |
|
482 // --------------------------------------------------------- |
|
483 // CCamBurstThumbnailGrid::ImagesDeleted |
|
484 // Called when one or more images have been deleted |
|
485 // --------------------------------------------------------- |
|
486 // |
|
487 void CCamBurstThumbnailGrid::ImagesDeleted() |
|
488 { |
|
489 // Check if scrollbar frame exists, and if it's currently visible, and |
|
490 // we now have only enough elements for one screen, then hide the bar |
|
491 if ( iScrollFrame && |
|
492 iScrollFrame->ScrollBarVisibility( CEikScrollBar::EVertical ) == CEikScrollBarFrame::EOn ) |
|
493 { |
|
494 if ( iModel.NoOfValidCells() <= iGridSize ) |
|
495 { |
|
496 DeleteScrollBar(); |
|
497 } |
|
498 else // Check if need to adjust scrollbar proportions |
|
499 { |
|
500 // This will adjust the proportions |
|
501 TRAPD( ignore, SetupScrollbarL() ); |
|
502 if ( ignore ) |
|
503 { |
|
504 // Do nothing ( removes build warning ) |
|
505 } |
|
506 } |
|
507 } |
|
508 |
|
509 if ( iModel.NoOfValidCells() <= KBurstGridMaxVisibleThumbnails ) |
|
510 { |
|
511 UpdateLayout(); |
|
512 // draw parent because size of the control might have been changed |
|
513 Parent()->DrawDeferred(); |
|
514 } |
|
515 DrawDeferred(); |
|
516 } |
|
517 |
|
518 // ----------------------------------------------------------------------------- |
|
519 // CCamBurstThumbnailGrid::OfferKeyEventL |
|
520 // Handles key events |
|
521 // ----------------------------------------------------------------------------- |
|
522 // |
|
523 TKeyResponse CCamBurstThumbnailGrid::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
524 { |
|
525 TInt startTopIndex = iModel.TopLeftGridIndex(); |
|
526 |
|
527 if ( aType == EEventKey ) |
|
528 { |
|
529 TBool changed = EFalse; |
|
530 switch ( aKeyEvent.iScanCode ) |
|
531 { |
|
532 case EStdKeyUpArrow: |
|
533 { |
|
534 if ( iModel.MoveHighlight( CCamBurstThumbnailGridModel::EMoveSelectUp ) ) |
|
535 { |
|
536 changed = ETrue; |
|
537 } |
|
538 break; |
|
539 } |
|
540 |
|
541 case EStdKeyDownArrow: |
|
542 { |
|
543 if ( iModel.MoveHighlight( CCamBurstThumbnailGridModel::EMoveSelectDown ) ) |
|
544 { |
|
545 changed = ETrue; |
|
546 } |
|
547 |
|
548 break; |
|
549 } |
|
550 |
|
551 case EStdKeyLeftArrow: |
|
552 { |
|
553 CCamBurstThumbnailGridModel::TMoveSelect direction; |
|
554 if ( !AknLayoutUtils::LayoutMirrored() ) |
|
555 { |
|
556 direction = CCamBurstThumbnailGridModel::EMoveSelectLeft; |
|
557 } |
|
558 else |
|
559 { |
|
560 direction = CCamBurstThumbnailGridModel::EMoveSelectRight; |
|
561 } |
|
562 |
|
563 if ( iModel.MoveHighlight( direction ) ) |
|
564 { |
|
565 changed = ETrue; |
|
566 } |
|
567 break; |
|
568 } |
|
569 |
|
570 case EStdKeyRightArrow: |
|
571 { |
|
572 CCamBurstThumbnailGridModel::TMoveSelect direction; |
|
573 if ( !AknLayoutUtils::LayoutMirrored() ) |
|
574 { |
|
575 direction = CCamBurstThumbnailGridModel::EMoveSelectRight; |
|
576 } |
|
577 else |
|
578 { |
|
579 direction = CCamBurstThumbnailGridModel::EMoveSelectLeft; |
|
580 } |
|
581 |
|
582 if ( iModel.MoveHighlight( direction ) ) |
|
583 { |
|
584 changed = ETrue; |
|
585 } |
|
586 break; |
|
587 } |
|
588 |
|
589 default: |
|
590 { |
|
591 break; |
|
592 } |
|
593 |
|
594 } // end of switch |
|
595 |
|
596 // Update scroll bar if visible screen proportions changed |
|
597 if ( iScrollFrame ) |
|
598 { |
|
599 // Work out whether the 3x2 view has moved |
|
600 TInt endTopIndex = iModel.TopLeftGridIndex(); |
|
601 TInt indexDiff = endTopIndex - startTopIndex; |
|
602 |
|
603 if ( indexDiff != 0 ) |
|
604 { |
|
605 iScrollFrame->MoveVertThumbTo( endTopIndex / KGridWidth ); |
|
606 } |
|
607 } |
|
608 |
|
609 // If a change was made, update the display |
|
610 if ( changed ) |
|
611 { |
|
612 DrawDeferred(); |
|
613 } |
|
614 } |
|
615 return EKeyWasNotConsumed; |
|
616 } |
|
617 |
|
618 // ----------------------------------------------------------------------------- |
|
619 // CCamBurstThumbnailGrid::SetupScrollbarL |
|
620 // Checks if a scroll bar is needed, and if so, creates one. |
|
621 // ----------------------------------------------------------------------------- |
|
622 // |
|
623 void CCamBurstThumbnailGrid::SetupScrollbarL() |
|
624 { |
|
625 PRINT(_L("Camera => CCamBurstThumbnailGrid::SetupScrollbarL()") ); |
|
626 __ASSERT_DEBUG( iScrollFrame, CamPanic( ECamPanicNullPointer ) ); |
|
627 |
|
628 |
|
629 // Work out the number of scrollable rows we need. Take into account |
|
630 // the rounding errors with integer maths with a modulus check too. |
|
631 TInt numOfRows = ( iModel.NoOfValidCells() / KGridWidth ) ; |
|
632 if ( iModel.NoOfValidCells() % KGridWidth != 0 ) |
|
633 { |
|
634 numOfRows ++; |
|
635 } |
|
636 |
|
637 TInt startRow = ( iModel.TopLeftGridIndex() / KGridWidth ); |
|
638 if ( iModel.TopLeftGridIndex() % KGridWidth != 0 ) |
|
639 { |
|
640 startRow ++; |
|
641 } |
|
642 iScrollFrame->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOn ); |
|
643 |
|
644 |
|
645 // Set up the model accordingly |
|
646 ivModel.SetScrollSpan( numOfRows ); |
|
647 ivModel.SetFocusPosition( startRow ); |
|
648 ivModel.SetWindowSize( iModel.GridHeight() ); |
|
649 iScrollFrame->CreateDoubleSpanScrollBarsL( ETrue, EFalse ); // was true, false |
|
650 |
|
651 TRect rect = iScrollLayout.Rect(); |
|
652 iScrollFrame->Tile( &ivModel, rect ); |
|
653 iScrollFrame->MoveVertThumbTo( startRow ); |
|
654 |
|
655 |
|
656 PRINT(_L("Camera <= CCamBurstThumbnailGrid::SetupScrollbarL()") ); |
|
657 } |
|
658 |
|
659 |
|
660 |
|
661 // --------------------------------------------------------- |
|
662 // CCamBurstThumbnailGrid::DeleteScrollBar |
|
663 // Hides and deletes the scrollbar frame |
|
664 // --------------------------------------------------------- |
|
665 // |
|
666 void CCamBurstThumbnailGrid::DeleteScrollBar() |
|
667 { |
|
668 if ( iScrollFrame ) |
|
669 { |
|
670 // Hide the scrollbar |
|
671 TRAPD( ignore, iScrollFrame->SetScrollBarVisibilityL( |
|
672 CEikScrollBarFrame::EOff, |
|
673 CEikScrollBarFrame::EOff ) ); |
|
674 if ( ignore ) |
|
675 { |
|
676 // Do nothing ( removes build warning ) |
|
677 } |
|
678 } |
|
679 |
|
680 // Delete the frame |
|
681 delete iScrollFrame; |
|
682 iScrollFrame = NULL; |
|
683 } |
|
684 |
|
685 // --------------------------------------------------------- |
|
686 // CCamBurstThumbnailGrid::CreateScrollBarL |
|
687 // Creates the scrollbar frame object |
|
688 // --------------------------------------------------------- |
|
689 // |
|
690 void CCamBurstThumbnailGrid::CreateScrollBarL() |
|
691 { |
|
692 // Create scrollbar frame |
|
693 iScrollFrame = new ( ELeave ) CEikScrollBarFrame( this, this, ETrue ); |
|
694 } |
|
695 |
|
696 |
|
697 // --------------------------------------------------------- |
|
698 // CCamBurstThumbnailGrid::GridSize |
|
699 // Returns the height of the thumbnail grid, in cells |
|
700 // --------------------------------------------------------- |
|
701 // |
|
702 TInt CCamBurstThumbnailGrid::GridSize() const |
|
703 { |
|
704 return iGridSize; |
|
705 } |
|
706 |
|
707 // --------------------------------------------------------- |
|
708 // CCamBurstThumbnailGrid::UpdateLayout() |
|
709 // Updates layouts. Used to reload layouts when images are deleted. |
|
710 // --------------------------------------------------------- |
|
711 // |
|
712 void CCamBurstThumbnailGrid::UpdateLayout() |
|
713 { |
|
714 TInt gridSize = iModel.NoOfValidCells(); |
|
715 |
|
716 TRect mainPaneRect; |
|
717 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, |
|
718 mainPaneRect ); |
|
719 TRect statusPaneRect; |
|
720 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EStatusPane, |
|
721 statusPaneRect ); |
|
722 |
|
723 // layout area rectangle contains the area, where components need to be |
|
724 // drawn to. the container size is the whole screen, but the layouts are |
|
725 // for the client area. aRect is the container size that might include or |
|
726 // might not include statuspane area. calculating area self will |
|
727 // go around the problem |
|
728 TRect layoutAreaRect; |
|
729 layoutAreaRect = mainPaneRect; |
|
730 layoutAreaRect.BoundingRect( statusPaneRect ); |
|
731 |
|
732 // CCamAppUi* appUi = static_cast<CCamAppUi*>( iEikonEnv->AppUi() ); |
|
733 |
|
734 TAknLayoutRect burstPaneRect; |
|
735 if ( CamUtility::IsNhdDevice() ) |
|
736 { |
|
737 // use layoutAreaRect for nhd (contains the statuspane) |
|
738 burstPaneRect.LayoutRect( layoutAreaRect, AknLayoutScalable_Apps::main_cam4_burst_pane() ); |
|
739 // SetRect( layoutAreaRect ); |
|
740 } |
|
741 else |
|
742 { |
|
743 // use mainpane for vga |
|
744 burstPaneRect.LayoutRect( mainPaneRect, AknLayoutScalable_Apps::main_cam4_burst_pane() ); |
|
745 // SetRect( mainPaneRect ); |
|
746 } |
|
747 |
|
748 |
|
749 TRect rect; |
|
750 if ( gridSize <= KBurstGridDefaultThumbnails) |
|
751 { |
|
752 AknLayoutUtils::LayoutControl( this, |
|
753 burstPaneRect.Rect(), |
|
754 AknLayoutScalable_Apps::grid_cam4_burst_pane(1) ); |
|
755 } |
|
756 else if ( gridSize <= KBurstGridMaxVisibleThumbnails ) |
|
757 { |
|
758 AknLayoutUtils::LayoutControl( this, |
|
759 burstPaneRect.Rect(), |
|
760 AknLayoutScalable_Apps::grid_cam4_burst_pane(3) ); |
|
761 } |
|
762 else |
|
763 { |
|
764 AknLayoutUtils::LayoutControl( this, |
|
765 burstPaneRect.Rect(), |
|
766 AknLayoutScalable_Apps::grid_cam4_burst_pane(5) ); |
|
767 } |
|
768 |
|
769 |
|
770 // set scrollbar layout |
|
771 iScrollLayout.LayoutRect( burstPaneRect.Rect(), |
|
772 AknLayoutScalable_Apps::scroll_pane_cp30(1) ); |
|
773 |
|
774 |
|
775 ReadLayout(); |
|
776 |
|
777 // set the new thumbnail size for gridmodel (to be used with thumbnail scaling) |
|
778 // use layout for the first cell (all thumbnails are same size) |
|
779 iModel.SetThumbnailSize( iGridCellLayout[0].iThmbRect.Rect().Size() ); |
|
780 |
|
781 AknIconUtils::SetSize( iBitmapMark, iGridCellLayout[0].iMarkRect.Rect().Size() ); |
|
782 AknIconUtils::SetSize( iBitmapMarkMask, iGridCellLayout[0].iMarkRect.Rect().Size() ); |
|
783 } |
|
784 // --------------------------------------------------------- |
|
785 // CCamBurstThumbnailGrid::HitTestGridItems( TPoint aPosition ) |
|
786 // returns the grid item index that the position corresponds |
|
787 // if position does not match to any grid item return value is negative |
|
788 // --------------------------------------------------------- |
|
789 TInt CCamBurstThumbnailGrid::HitTestGridItems( const TPoint aPosition ) |
|
790 { |
|
791 |
|
792 TInt retVal = -1; |
|
793 |
|
794 for ( TInt i = 0; i < KGridSize; i++ ) |
|
795 { |
|
796 if ( iGridCellLayout[i].iCellRect.Rect().Contains( aPosition ) ) |
|
797 { |
|
798 retVal = i; |
|
799 break; |
|
800 } |
|
801 } // end for |
|
802 |
|
803 // check if the scrollbar position affects to the grid item index |
|
804 if ( iScrollFrame ) |
|
805 { |
|
806 retVal = retVal + iScrollFrame->VerticalScrollBar()->ThumbPosition()*KGridWidth; |
|
807 } |
|
808 |
|
809 return retVal < iModel.NoOfValidCells() ? retVal : -1; |
|
810 } |
|
811 |
|
812 // ----------------------------------------------------------------------------- |
|
813 // CCamBurstThumbnailGrid::HighlightChanged |
|
814 // Sets the grid to be redrawn |
|
815 // ----------------------------------------------------------------------------- |
|
816 // |
|
817 void CCamBurstThumbnailGrid::HighlightChanged() |
|
818 { |
|
819 // does nothing at the moment |
|
820 } |
|
821 |
|
822 // --------------------------------------------------------- |
|
823 // TCamBurstGridCellLayout::ConstructFromResource |
|
824 // Constructs the layout entries from the specified resource |
|
825 // --------------------------------------------------------- |
|
826 // |
|
827 void TCamBurstGridCellLayout::ConstructFromResource( TResourceReader& aReader, TRect& aRect ) |
|
828 { |
|
829 iCellRect.LayoutRect( aRect, aReader ); |
|
830 iHighRect.LayoutRect( aRect, aReader ); |
|
831 iMarkRect.LayoutRect( aRect, aReader ); |
|
832 iThmbRect.LayoutRect( aRect, aReader ); |
|
833 } |
|
834 |
|
835 // End of File |