|
1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "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 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * Color selection popup dialog that shows a color grid. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDES |
|
22 #include <ImageEditorUI.rsg> |
|
23 #include <avkon.hrh> |
|
24 #include <AknLayoutScalable_Avkon.cdl.h> |
|
25 #include <AknLayoutScalable_Apps.cdl.h> |
|
26 #include <fbs.h> |
|
27 #include <AknIconUtils.h> |
|
28 #include <AknUtils.h> |
|
29 |
|
30 #include <AknBidiTextUtils.h> |
|
31 #include <BidiText.h> |
|
32 |
|
33 #ifdef RD_TACTILE_FEEDBACK |
|
34 #include <touchfeedback.h> |
|
35 #endif /* RD_TACTILE_FEEDBACK */ |
|
36 |
|
37 #include <ImageEditorUi.mbg> |
|
38 #include <ImageEditorUI.rsg> |
|
39 |
|
40 #include "ResolutionUtil.h" |
|
41 #include "ColorSelectionPopup.h" |
|
42 #include "ImageEditorUiDefs.h" |
|
43 |
|
44 // CONSTANTS |
|
45 const TInt KGridColumnCount = 7; |
|
46 const TInt KGridRowCount = 5; |
|
47 const TInt KInitialItemIndex = 0; |
|
48 |
|
49 //============================================================================= |
|
50 CColorSelectionPopup::CColorSelectionPopup() |
|
51 { |
|
52 |
|
53 } |
|
54 |
|
55 //============================================================================= |
|
56 CColorSelectionPopup::~CColorSelectionPopup() |
|
57 { |
|
58 |
|
59 delete iPopupCenter; |
|
60 delete iPopupCenterMask; |
|
61 delete iPopupCornerTL; |
|
62 delete iPopupCornerTLMask; |
|
63 delete iPopupCornerTR; |
|
64 delete iPopupCornerTRMask; |
|
65 delete iPopupCornerBL; |
|
66 delete iPopupCornerBLMask; |
|
67 delete iPopupCornerBR; |
|
68 delete iPopupCornerBRMask; |
|
69 delete iPopupSideL; |
|
70 delete iPopupSideLMask; |
|
71 delete iPopupSideR; |
|
72 delete iPopupSideRMask; |
|
73 delete iPopupSideT; |
|
74 delete iPopupSideTMask; |
|
75 delete iPopupSideB; |
|
76 delete iPopupSideBMask; |
|
77 |
|
78 iHighlightRectsArray.Close(); |
|
79 iGridRectsArray.Close(); |
|
80 iColorBitmapsArray.ResetAndDestroy(); |
|
81 iRGBArray.Close(); |
|
82 } |
|
83 |
|
84 //============================================================================= |
|
85 void CColorSelectionPopup::ConstructL ( CCoeControl* aParent ) |
|
86 { |
|
87 // Set parent |
|
88 SetContainerWindowL( *aParent ); |
|
89 TFileName iconFile( KImageEditorUiMifFile ); |
|
90 |
|
91 // Create trans popup window graphics |
|
92 // Center |
|
93 AknIconUtils::CreateIconL( iPopupCenter, iPopupCenterMask, iconFile, |
|
94 EMbmImageeditoruiQgn_graf_popup_trans_center, |
|
95 EMbmImageeditoruiQgn_graf_popup_trans_center_mask ); |
|
96 |
|
97 // Top-left corner |
|
98 AknIconUtils::CreateIconL( iPopupCornerTL, iPopupCornerTLMask, iconFile, |
|
99 EMbmImageeditoruiQgn_graf_popup_trans_corner_tl, |
|
100 EMbmImageeditoruiQgn_graf_popup_trans_corner_tl_mask ); |
|
101 |
|
102 // Top-right corner |
|
103 AknIconUtils::CreateIconL( iPopupCornerTR, iPopupCornerTRMask, iconFile, |
|
104 EMbmImageeditoruiQgn_graf_popup_trans_corner_tr, |
|
105 EMbmImageeditoruiQgn_graf_popup_trans_corner_tr_mask ); |
|
106 |
|
107 // Bottom-left corner |
|
108 AknIconUtils::CreateIconL( iPopupCornerBL, iPopupCornerBLMask, iconFile, |
|
109 EMbmImageeditoruiQgn_graf_popup_trans_corner_bl, |
|
110 EMbmImageeditoruiQgn_graf_popup_trans_corner_bl_mask ); |
|
111 |
|
112 // Bottom-right corner |
|
113 AknIconUtils::CreateIconL( iPopupCornerBR, iPopupCornerBRMask, iconFile, |
|
114 EMbmImageeditoruiQgn_graf_popup_trans_corner_br, |
|
115 EMbmImageeditoruiQgn_graf_popup_trans_corner_br_mask ); |
|
116 |
|
117 // left side |
|
118 AknIconUtils::CreateIconL( iPopupSideL, iPopupSideLMask, iconFile, |
|
119 EMbmImageeditoruiQgn_graf_popup_trans_side_l, |
|
120 EMbmImageeditoruiQgn_graf_popup_trans_side_l_mask ); |
|
121 |
|
122 // left side |
|
123 AknIconUtils::CreateIconL( iPopupSideR, iPopupSideRMask, iconFile, |
|
124 EMbmImageeditoruiQgn_graf_popup_trans_side_r, |
|
125 EMbmImageeditoruiQgn_graf_popup_trans_side_r_mask ); |
|
126 |
|
127 // top side |
|
128 AknIconUtils::CreateIconL( iPopupSideT, iPopupSideTMask, iconFile, |
|
129 EMbmImageeditoruiQgn_graf_popup_trans_side_t, |
|
130 EMbmImageeditoruiQgn_graf_popup_trans_side_t_mask ); |
|
131 |
|
132 // bottom side |
|
133 AknIconUtils::CreateIconL( iPopupSideB, iPopupSideBMask, iconFile, |
|
134 EMbmImageeditoruiQgn_graf_popup_trans_side_b, |
|
135 EMbmImageeditoruiQgn_graf_popup_trans_side_b_mask ); |
|
136 |
|
137 iCurrentItem = KInitialItemIndex; |
|
138 |
|
139 // Activate control |
|
140 ActivateL(); |
|
141 |
|
142 } |
|
143 |
|
144 //============================================================================= |
|
145 void CColorSelectionPopup::CreateColorBitmapsL( TSize aSize ) |
|
146 { |
|
147 // Color constants shown on the grid |
|
148 // R indicates the row index and C the column index |
|
149 const TRgb KColor_R1C1 (0, 0, 0); |
|
150 const TRgb KColor_R1C2 (65, 0, 175); |
|
151 const TRgb KColor_R1C3 (0, 30, 128); |
|
152 const TRgb KColor_R1C4 (0, 80, 100); |
|
153 const TRgb KColor_R1C5 (0, 65, 0); |
|
154 const TRgb KColor_R1C6 (85, 55, 0); |
|
155 const TRgb KColor_R1C7 (120, 0, 0); |
|
156 const TRgb KColor_R2C1 (75, 75, 75); |
|
157 const TRgb KColor_R2C2 (128, 0, 255); |
|
158 const TRgb KColor_R2C3 (0, 65, 175); |
|
159 const TRgb KColor_R2C4 (0, 145, 165); |
|
160 const TRgb KColor_R2C5 (0, 128, 0); |
|
161 const TRgb KColor_R2C6 (128, 65, 0); |
|
162 const TRgb KColor_R2C7 (128, 0, 65); |
|
163 const TRgb KColor_R3C1 (150, 150, 150); |
|
164 const TRgb KColor_R3C2 (255, 0, 128); |
|
165 const TRgb KColor_R3C3 (0, 50, 255); |
|
166 const TRgb KColor_R3C4 (0, 165, 255); |
|
167 const TRgb KColor_R3C5 (0, 255, 0); |
|
168 const TRgb KColor_R3C6 (255, 128, 0); |
|
169 const TRgb KColor_R3C7 (255, 0, 0); |
|
170 const TRgb KColor_R4C1 (225, 225, 225); |
|
171 const TRgb KColor_R4C2 (255, 0, 255); |
|
172 const TRgb KColor_R4C3 (50, 145, 255); |
|
173 const TRgb KColor_R4C4 (0, 255, 255); |
|
174 const TRgb KColor_R4C5 (128, 255, 0); |
|
175 const TRgb KColor_R4C6 (255, 255, 0); |
|
176 const TRgb KColor_R4C7 (255, 115, 115); |
|
177 const TRgb KColor_R5C1 (255, 255, 255); |
|
178 const TRgb KColor_R5C2 (255, 128, 255); |
|
179 const TRgb KColor_R5C3 (180, 210, 255); |
|
180 const TRgb KColor_R5C4 (128, 255, 255); |
|
181 const TRgb KColor_R5C5 (180, 255, 180); |
|
182 const TRgb KColor_R5C6 (255, 255, 128); |
|
183 const TRgb KColor_R5C7 (255, 128, 180); |
|
184 |
|
185 // Read rgb values into an array |
|
186 iRGBArray.Reset(); |
|
187 iRGBArray.Append( KColor_R1C1 ); |
|
188 iRGBArray.Append( KColor_R1C2 ); |
|
189 iRGBArray.Append( KColor_R1C3 ); |
|
190 iRGBArray.Append( KColor_R1C4 ); |
|
191 iRGBArray.Append( KColor_R1C5 ); |
|
192 iRGBArray.Append( KColor_R1C6 ); |
|
193 iRGBArray.Append( KColor_R1C7 ); |
|
194 iRGBArray.Append( KColor_R2C1 ); |
|
195 iRGBArray.Append( KColor_R2C2 ); |
|
196 iRGBArray.Append( KColor_R2C3 ); |
|
197 iRGBArray.Append( KColor_R2C4 ); |
|
198 iRGBArray.Append( KColor_R2C5 ); |
|
199 iRGBArray.Append( KColor_R2C6 ); |
|
200 iRGBArray.Append( KColor_R2C7 ); |
|
201 iRGBArray.Append( KColor_R3C1 ); |
|
202 iRGBArray.Append( KColor_R3C2 ); |
|
203 iRGBArray.Append( KColor_R3C3 ); |
|
204 iRGBArray.Append( KColor_R3C4 ); |
|
205 iRGBArray.Append( KColor_R3C5 ); |
|
206 iRGBArray.Append( KColor_R3C6 ); |
|
207 iRGBArray.Append( KColor_R3C7 ); |
|
208 iRGBArray.Append( KColor_R4C1 ); |
|
209 iRGBArray.Append( KColor_R4C2 ); |
|
210 iRGBArray.Append( KColor_R4C3 ); |
|
211 iRGBArray.Append( KColor_R4C4 ); |
|
212 iRGBArray.Append( KColor_R4C5 ); |
|
213 iRGBArray.Append( KColor_R4C6 ); |
|
214 iRGBArray.Append( KColor_R4C7 ); |
|
215 iRGBArray.Append( KColor_R5C1 ); |
|
216 iRGBArray.Append( KColor_R5C2 ); |
|
217 iRGBArray.Append( KColor_R5C3 ); |
|
218 iRGBArray.Append( KColor_R5C4 ); |
|
219 iRGBArray.Append( KColor_R5C5 ); |
|
220 iRGBArray.Append( KColor_R5C6 ); |
|
221 iRGBArray.Append( KColor_R5C7 ); |
|
222 |
|
223 // Generate color bitmaps |
|
224 iColorBitmapsArray.ResetAndDestroy(); |
|
225 for( TInt i = 0; i < iRGBArray.Count(); i++ ) |
|
226 { |
|
227 CFbsBitmap* bitmap = new ( ELeave ) CFbsBitmap; |
|
228 CleanupStack::PushL( bitmap ); |
|
229 User::LeaveIfError ( bitmap->Create ( aSize, EColor64K ) ); |
|
230 |
|
231 // Compute color for bitmap |
|
232 TRgb color( iRGBArray[i] ); |
|
233 |
|
234 // Fill the bitmap with the correct color |
|
235 TUint16 color_64k = ( TUint16 ) |
|
236 (0 | |
|
237 ((( TUint8 )color.Red() >> 3) << 11) | |
|
238 ((( TUint8 )color.Green() >> 2) << 5) | |
|
239 (( TUint8 )color.Blue() >> 3)); |
|
240 |
|
241 bitmap->LockHeapLC(); |
|
242 TUint16 * pd = (TUint16 *)bitmap->DataAddress(); |
|
243 TSize size = bitmap->SizeInPixels(); |
|
244 TInt w = (bitmap->ScanLineLength(size.iWidth, EColor64K) >> 1) |
|
245 * size.iHeight; |
|
246 for( TInt k = w; k != 0; --k) |
|
247 { |
|
248 *pd++ = color_64k; |
|
249 } |
|
250 |
|
251 iColorBitmapsArray.Append( bitmap ); |
|
252 |
|
253 CleanupStack::PopAndDestroy(); // LockHeapLC() |
|
254 CleanupStack::Pop(); // bitmap |
|
255 |
|
256 } |
|
257 |
|
258 } |
|
259 |
|
260 //============================================================================= |
|
261 void CColorSelectionPopup::Draw( const TRect& /*aRect*/ ) const |
|
262 { |
|
263 const TRgb KHighlightCenterColor (229, 229, 229); |
|
264 |
|
265 CWindowGc& gc = SystemGc(); |
|
266 |
|
267 CPreviewControlBase::DrawPreviewImage (Rect()); |
|
268 |
|
269 // Change brush to null to enable transparent drawing |
|
270 gc.SetBrushStyle (CGraphicsContext::ENullBrush); |
|
271 |
|
272 // draw center of the borders |
|
273 gc.BitBltMasked( iPopupCenterRect.iTl, iPopupCenter, |
|
274 iPopupCenterRect.Size(), iPopupCenterMask, EFalse ); |
|
275 // draw Top left corner |
|
276 gc.BitBltMasked( iPopupCornerTLRect.iTl, iPopupCornerTL, |
|
277 iPopupCornerTLRect.Size(), iPopupCornerTLMask, EFalse ); |
|
278 // draw Top right corner |
|
279 gc.BitBltMasked( iPopupCornerTRRect.iTl, iPopupCornerTR, |
|
280 iPopupCornerTRRect.Size(), iPopupCornerTRMask, EFalse ); |
|
281 // draw Bottom left corner |
|
282 gc.BitBltMasked( iPopupCornerBLRect.iTl, iPopupCornerBL, |
|
283 iPopupCornerBLRect.Size(), iPopupCornerBLMask, EFalse ); |
|
284 // draw Bottom right corner |
|
285 gc.BitBltMasked( iPopupCornerBRRect.iTl, iPopupCornerBR, |
|
286 iPopupCornerBRRect.Size(), iPopupCornerBRMask, EFalse ); |
|
287 // draw Left side |
|
288 gc.BitBltMasked( iPopupSideLRect.iTl, iPopupSideL, |
|
289 iPopupSideLRect.Size(), iPopupSideLMask, EFalse ); |
|
290 // draw Right side |
|
291 gc.BitBltMasked( iPopupSideRRect.iTl, iPopupSideR, |
|
292 iPopupSideRRect.Size(), iPopupSideRMask, EFalse ); |
|
293 // draw Top side |
|
294 gc.BitBltMasked( iPopupSideTRect.iTl, iPopupSideT, |
|
295 iPopupSideTRect.Size(), iPopupSideTMask, EFalse ); |
|
296 // draw Bottom side |
|
297 gc.BitBltMasked( iPopupSideBRect.iTl, iPopupSideB, |
|
298 iPopupSideBRect.Size(), iPopupSideBMask, EFalse ); |
|
299 |
|
300 // Draw color items and selection indicator |
|
301 for( TInt index = 0; index < iGridRectsArray.Count(); index++ ) |
|
302 { |
|
303 // Draw selection indicator for current item |
|
304 if( index == iCurrentItem ) |
|
305 { |
|
306 gc.SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
307 gc.SetBrushColor( KHighlightCenterColor ); |
|
308 gc.SetPenColor( KRgbBlack ); |
|
309 |
|
310 // a trick that sets the highligh more or less to correct position in |
|
311 // right-to-left languages. |
|
312 if ( !AknLayoutUtils::LayoutMirrored() ) |
|
313 { |
|
314 gc.SetPenSize( TSize(2,2) ); |
|
315 } |
|
316 else |
|
317 { |
|
318 gc.SetPenSize( TSize(1,1) ); |
|
319 } |
|
320 |
|
321 gc.DrawRect( iHighlightRectsArray[ iCurrentItem ] ); |
|
322 |
|
323 gc.SetBrushStyle (CGraphicsContext::ENullBrush); |
|
324 } |
|
325 |
|
326 // draw color bitmap |
|
327 TRect currentRect = iGridRectsArray[index]; |
|
328 gc.BitBlt(currentRect.iTl, iColorBitmapsArray[index]); |
|
329 } |
|
330 |
|
331 // Draw heading |
|
332 // Convert the plug-in name to visual representation |
|
333 // (in case would be right-to-left) |
|
334 const CFont* font = NULL; |
|
335 font = AknLayoutUtils::FontFromId( EAknLogicalFontPrimaryFont ); |
|
336 TBuf<256> visual; |
|
337 // Text to be converted |
|
338 HBufC * heading = CEikonEnv::Static()->AllocReadResourceLC ( R_SELECT_COLOUR ); |
|
339 |
|
340 AknBidiTextUtils::ConvertToVisualAndClip( |
|
341 heading->Des(), |
|
342 visual, |
|
343 *font, |
|
344 iHeadingRect.Width(), |
|
345 iHeadingRect.Width() |
|
346 ); |
|
347 |
|
348 CleanupStack::PopAndDestroy( heading ); |
|
349 |
|
350 gc.UseFont( font ); |
|
351 gc.SetBrushStyle ( CGraphicsContext::ENullBrush ); |
|
352 |
|
353 TInt baseline = iHeadingRect.Height() / 2 + font->AscentInPixels() / 2; |
|
354 |
|
355 // Check the directionality of the current language and set the alignment |
|
356 // according the directionality |
|
357 TBidiText::TDirectionality dir = TBidiText::ScriptDirectionality(User::Language()); |
|
358 CGraphicsContext::TTextAlign align = CGraphicsContext::ELeft; |
|
359 |
|
360 if( dir == TBidiText::ERightToLeft ) |
|
361 { |
|
362 align = CGraphicsContext::ERight; |
|
363 } |
|
364 gc.SetPenColor(KRgbWhite); |
|
365 gc.DrawText( |
|
366 visual, |
|
367 iHeadingRect, |
|
368 baseline, |
|
369 align, |
|
370 0); |
|
371 } |
|
372 |
|
373 //============================================================================= |
|
374 void CColorSelectionPopup::SizeChanged() |
|
375 { |
|
376 |
|
377 TAknLayoutRect layoutRect; |
|
378 layoutRect.LayoutRect( Rect(), AknLayoutScalable_Apps::popup_imed_trans_window(0) ); |
|
379 TRect parentRect = layoutRect.Rect(); |
|
380 |
|
381 TAknLayoutRect iconLayout; |
|
382 if ( !AknLayoutUtils::LayoutMirrored() ) |
|
383 { |
|
384 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g1()); |
|
385 iPopupCenterRect = iconLayout.Rect(); |
|
386 |
|
387 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g2()); |
|
388 iPopupCornerTLRect = iconLayout.Rect(); |
|
389 |
|
390 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g3()); |
|
391 iPopupCornerTRRect = iconLayout.Rect(); |
|
392 |
|
393 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g4()); |
|
394 iPopupCornerBLRect = iconLayout.Rect(); |
|
395 |
|
396 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g5()); |
|
397 iPopupCornerBRRect = iconLayout.Rect(); |
|
398 |
|
399 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g6()); |
|
400 iPopupSideLRect = iconLayout.Rect(); |
|
401 |
|
402 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g7()); |
|
403 iPopupSideRRect = iconLayout.Rect(); |
|
404 |
|
405 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g8()); |
|
406 iPopupSideTRect = iconLayout.Rect(); |
|
407 |
|
408 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g9()); |
|
409 iPopupSideBRect = iconLayout.Rect(); |
|
410 } |
|
411 else |
|
412 { |
|
413 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g1()); |
|
414 iPopupCenterRect = iconLayout.Rect(); |
|
415 |
|
416 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g3()); |
|
417 iPopupCornerTLRect = iconLayout.Rect(); |
|
418 |
|
419 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g2()); |
|
420 iPopupCornerTRRect = iconLayout.Rect(); |
|
421 |
|
422 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g5()); |
|
423 iPopupCornerBLRect = iconLayout.Rect(); |
|
424 |
|
425 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g4()); |
|
426 iPopupCornerBRRect = iconLayout.Rect(); |
|
427 |
|
428 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g7()); |
|
429 iPopupSideLRect = iconLayout.Rect(); |
|
430 |
|
431 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g6()); |
|
432 iPopupSideRRect = iconLayout.Rect(); |
|
433 |
|
434 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g8()); |
|
435 iPopupSideTRect = iconLayout.Rect(); |
|
436 |
|
437 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g9()); |
|
438 iPopupSideBRect = iconLayout.Rect(); |
|
439 } |
|
440 |
|
441 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Apps::listscroll_imed_pane()); |
|
442 TRect listscrollPaneRect = iconLayout.Rect(); |
|
443 |
|
444 iconLayout.LayoutRect( listscrollPaneRect, AknLayoutScalable_Apps::grid_imed_colour_35_pane( 1 )); |
|
445 TRect gridPaneRect = iconLayout.Rect(); |
|
446 |
|
447 // Calculate grid's cell rects |
|
448 iHighlightRectsArray.Reset(); |
|
449 iGridRectsArray.Reset(); |
|
450 for( TInt row = 0; row < KGridRowCount; row++ ) |
|
451 { |
|
452 for( TInt column = 0; column < KGridColumnCount; column++ ) |
|
453 { |
|
454 iconLayout.LayoutRect( gridPaneRect, |
|
455 AknLayoutScalable_Apps::cell_imed_colour_pane(0 , column, row )); |
|
456 TRect cellRect = iconLayout.Rect(); |
|
457 |
|
458 iconLayout.LayoutRect( cellRect, |
|
459 AknLayoutScalable_Apps::hgihlgiht_grid_pane_cp016(0)); |
|
460 |
|
461 TRect highlightRect = iconLayout.Rect(); |
|
462 iHighlightRectsArray.Append( highlightRect ); |
|
463 |
|
464 iconLayout.LayoutRect( cellRect, |
|
465 AknLayoutScalable_Apps::cell_imed_colour_pane_g1(0) ); |
|
466 |
|
467 iGridRectsArray.Append( iconLayout.Rect() ); |
|
468 |
|
469 } |
|
470 } |
|
471 |
|
472 CreateColorBitmapsL( iconLayout.Rect().Size() ); |
|
473 |
|
474 //Heading rect |
|
475 iconLayout.LayoutRect( parentRect, AknLayoutScalable_Apps::heading_imed_pane()); |
|
476 TRect heading = iconLayout.Rect(); |
|
477 |
|
478 TAknLayoutText layoutText; |
|
479 layoutText.LayoutText( heading, AknLayoutScalable_Apps::heading_imed_pane_t1() ); |
|
480 iHeadingRect = layoutText.TextRect(); |
|
481 iLayoutTextHeading = layoutText; |
|
482 |
|
483 // Resize graphics to correct size |
|
484 AknIconUtils::SetSize( iPopupCenter, iPopupCenterRect.Size(), EAspectRatioNotPreserved); |
|
485 AknIconUtils::SetSize( iPopupCornerTL, iPopupCornerTLRect.Size(), EAspectRatioNotPreserved); |
|
486 AknIconUtils::SetSize( iPopupCornerTR, iPopupCornerTRRect.Size(), EAspectRatioNotPreserved); |
|
487 AknIconUtils::SetSize( iPopupCornerBL, iPopupCornerBLRect.Size(), EAspectRatioNotPreserved); |
|
488 AknIconUtils::SetSize( iPopupCornerBR, iPopupCornerBRRect.Size(), EAspectRatioNotPreserved); |
|
489 AknIconUtils::SetSize( iPopupSideL, iPopupSideLRect.Size(), EAspectRatioNotPreserved); |
|
490 AknIconUtils::SetSize( iPopupSideR, iPopupSideRRect.Size(), EAspectRatioNotPreserved); |
|
491 AknIconUtils::SetSize( iPopupSideT, iPopupSideTRect.Size(), EAspectRatioNotPreserved); |
|
492 AknIconUtils::SetSize( iPopupSideB, iPopupSideBRect.Size(), EAspectRatioNotPreserved); |
|
493 |
|
494 } |
|
495 |
|
496 //============================================================================= |
|
497 TKeyResponse CColorSelectionPopup::OfferKeyEventL( const TKeyEvent& aKeyEvent, |
|
498 TEventCode aType ) |
|
499 { |
|
500 TKeyResponse res = EKeyWasNotConsumed; |
|
501 |
|
502 if (aType == EEventKey) |
|
503 { |
|
504 // If in landscape mode, do different mapping for the number keys. |
|
505 TUint keyCode = aKeyEvent.iCode; |
|
506 TBool landscape = CResolutionUtil::Self()->GetLandscape(); |
|
507 if (landscape) |
|
508 { |
|
509 switch (keyCode) |
|
510 { |
|
511 case 49: // numeric keypad '1' |
|
512 keyCode = 55; |
|
513 break; |
|
514 case 50: // numeric keypad '2' |
|
515 keyCode = 52; |
|
516 break; |
|
517 case 51: // numeric keypad '3' |
|
518 keyCode = 49; |
|
519 break; |
|
520 case 52: // numeric keypad '4' |
|
521 keyCode = 56; |
|
522 break; |
|
523 case 54: // numeric keypad '6' |
|
524 keyCode = 50; |
|
525 break; |
|
526 case 55: // numeric keypad '7' |
|
527 keyCode = 57; |
|
528 break; |
|
529 case 56: // numeric keypad '8' |
|
530 keyCode = 54; |
|
531 break; |
|
532 case 57: // numeric keypad '9' |
|
533 keyCode = 51; |
|
534 break; |
|
535 default: |
|
536 break; |
|
537 } |
|
538 } |
|
539 |
|
540 switch (keyCode) |
|
541 { |
|
542 case EKeyLeftArrow: |
|
543 case 52: // numeric keypad '4' |
|
544 { |
|
545 if ( !AknLayoutUtils::LayoutMirrored() ) |
|
546 { |
|
547 if (iCurrentItem == 0) |
|
548 { |
|
549 iCurrentItem = iGridRectsArray.Count() - 1; |
|
550 } |
|
551 else |
|
552 { |
|
553 iCurrentItem--; |
|
554 } |
|
555 } |
|
556 else |
|
557 { |
|
558 iCurrentItem++; |
|
559 if (iCurrentItem >= iGridRectsArray.Count()) |
|
560 { |
|
561 iCurrentItem = 0; |
|
562 } |
|
563 } |
|
564 |
|
565 res = EKeyWasConsumed; |
|
566 break; |
|
567 } |
|
568 |
|
569 case EKeyRightArrow: |
|
570 case 54: // numeric keypad '6' |
|
571 { |
|
572 if ( !AknLayoutUtils::LayoutMirrored() ) |
|
573 { |
|
574 iCurrentItem++; |
|
575 if (iCurrentItem >= iGridRectsArray.Count()) |
|
576 { |
|
577 iCurrentItem = 0; |
|
578 } |
|
579 } |
|
580 else |
|
581 { |
|
582 if (iCurrentItem == 0) |
|
583 { |
|
584 iCurrentItem = iGridRectsArray.Count() - 1; |
|
585 } |
|
586 else |
|
587 { |
|
588 iCurrentItem--; |
|
589 } |
|
590 } |
|
591 |
|
592 res = EKeyWasConsumed; |
|
593 break; |
|
594 } |
|
595 |
|
596 case EKeyDownArrow: |
|
597 case 56: // numeric keypad '8' |
|
598 { |
|
599 iCurrentItem += KGridColumnCount; |
|
600 if (iCurrentItem >= iGridRectsArray.Count()) |
|
601 { |
|
602 iCurrentItem = iCurrentItem - iGridRectsArray.Count(); |
|
603 } |
|
604 |
|
605 res = EKeyWasConsumed; |
|
606 break; |
|
607 } |
|
608 |
|
609 case EKeyUpArrow: |
|
610 case 50: // numeric keypad '2' |
|
611 { |
|
612 iCurrentItem -= KGridColumnCount; |
|
613 if (iCurrentItem < 0) |
|
614 { |
|
615 iCurrentItem = iGridRectsArray.Count() + iCurrentItem; |
|
616 } |
|
617 |
|
618 res = EKeyWasConsumed; |
|
619 break; |
|
620 } |
|
621 |
|
622 case 49: // numeric keypad '1' |
|
623 { |
|
624 // Move up and left |
|
625 iCurrentItem -= KGridColumnCount; |
|
626 iCurrentItem --; |
|
627 if (iCurrentItem < 0) |
|
628 { |
|
629 iCurrentItem = iGridRectsArray.Count() + iCurrentItem; |
|
630 } |
|
631 res = EKeyWasConsumed; |
|
632 break; |
|
633 } |
|
634 |
|
635 case 51: // numeric keypad '3' |
|
636 { |
|
637 // Move up and right |
|
638 iCurrentItem -= KGridColumnCount; |
|
639 iCurrentItem ++; |
|
640 if (iCurrentItem < 0) |
|
641 { |
|
642 iCurrentItem = iGridRectsArray.Count() + iCurrentItem; |
|
643 } |
|
644 res = EKeyWasConsumed; |
|
645 break; |
|
646 } |
|
647 |
|
648 case 55: // numeric keypad '7' |
|
649 { |
|
650 // Move down and left |
|
651 iCurrentItem += KGridColumnCount; |
|
652 iCurrentItem--; |
|
653 if (iCurrentItem >= iGridRectsArray.Count()) |
|
654 { |
|
655 iCurrentItem = iCurrentItem - iGridRectsArray.Count(); |
|
656 } |
|
657 res = EKeyWasConsumed; |
|
658 break; |
|
659 } |
|
660 |
|
661 case 57: // numeric keypad '9' |
|
662 { |
|
663 // Move down and left |
|
664 iCurrentItem += KGridColumnCount; |
|
665 iCurrentItem++; |
|
666 if (iCurrentItem >= iGridRectsArray.Count()) |
|
667 { |
|
668 iCurrentItem = iCurrentItem - iGridRectsArray.Count(); |
|
669 } |
|
670 res = EKeyWasConsumed; |
|
671 break; |
|
672 } |
|
673 |
|
674 default: |
|
675 { |
|
676 break; |
|
677 } |
|
678 } |
|
679 } |
|
680 |
|
681 return res; |
|
682 |
|
683 } |
|
684 |
|
685 //============================================================================= |
|
686 void CColorSelectionPopup::HandlePointerEventL( const TPointerEvent &aPointerEvent ) |
|
687 { |
|
688 if( AknLayoutUtils::PenEnabled() ) |
|
689 { |
|
690 switch( aPointerEvent.iType ) |
|
691 { |
|
692 case TPointerEvent::EButton1Down: |
|
693 case TPointerEvent::EDrag: |
|
694 { |
|
695 // calculate which one of the grid items was pressed by |
|
696 // by comparing item rects and pressed position |
|
697 for (TInt i = 0; i < iHighlightRectsArray.Count(); ++i) |
|
698 { |
|
699 TRect iconRect( iHighlightRectsArray[i] ); |
|
700 |
|
701 if( iconRect.Contains( aPointerEvent.iPosition ) ) |
|
702 { |
|
703 // set new highlighted item |
|
704 iCurrentItem = i; |
|
705 break; |
|
706 } |
|
707 } |
|
708 break; |
|
709 } |
|
710 case TPointerEvent::EButton1Up: |
|
711 { |
|
712 break; |
|
713 } |
|
714 default: |
|
715 { |
|
716 break; |
|
717 } |
|
718 } |
|
719 } |
|
720 } |
|
721 |
|
722 //============================================================================= |
|
723 TRect CColorSelectionPopup::GridRect() const |
|
724 { |
|
725 return iPopupCenterRect; |
|
726 } |
|
727 |
|
728 //============================================================================= |
|
729 TBool CColorSelectionPopup::HighlightedItemPressed( TPoint aPosition ) const |
|
730 { |
|
731 TRect iconRect = iHighlightRectsArray[ iCurrentItem ]; |
|
732 |
|
733 if (iconRect.Contains( aPosition )) |
|
734 { |
|
735 return ETrue; |
|
736 } |
|
737 else |
|
738 { |
|
739 return EFalse; |
|
740 } |
|
741 } |
|
742 |
|
743 //============================================================================= |
|
744 TRgb CColorSelectionPopup::GetSelectedColor() const |
|
745 { |
|
746 return iRGBArray[iCurrentItem]; |
|
747 } |
|
748 |
|
749 //============================================================================= |
|
750 void CColorSelectionPopup::SetSelectedColor(TRgb aRgb) |
|
751 { |
|
752 for( TInt i = 0; i < iRGBArray.Count(); i++ ) |
|
753 { |
|
754 if (iRGBArray[i] == aRgb) |
|
755 { |
|
756 iCurrentItem = i; |
|
757 break; |
|
758 } |
|
759 } |
|
760 } |
|
761 |
|
762 |
|
763 //============================================================================= |
|
764 // DIALOG |
|
765 //============================================================================= |
|
766 TInt CColorSelectionDialog::RunDlgLD( const CFbsBitmap* aBitmap, |
|
767 const TRect& aRect, |
|
768 TRgb& aRgb ) |
|
769 { |
|
770 CColorSelectionDialog* dialog = |
|
771 new (ELeave) CColorSelectionDialog ( aRgb ); |
|
772 dialog->ConstructL( aBitmap, aRect); |
|
773 return dialog->ExecuteLD( R_IMAGE_EDITOR_COLOR_DIALOG ); |
|
774 } |
|
775 |
|
776 //============================================================================= |
|
777 CColorSelectionDialog::CColorSelectionDialog( TRgb& aRgb ) |
|
778 : iCurrentRgb( aRgb ) |
|
779 { |
|
780 } |
|
781 |
|
782 //============================================================================= |
|
783 CColorSelectionDialog::~CColorSelectionDialog() |
|
784 { |
|
785 delete iPopup; |
|
786 } |
|
787 |
|
788 //============================================================================= |
|
789 |
|
790 void CColorSelectionDialog::ConstructL( const CFbsBitmap* aBitmap, |
|
791 const TRect& aRect ) |
|
792 { |
|
793 iPopup = new ( ELeave ) CColorSelectionPopup(); |
|
794 iPopup->ConstructL( this ); |
|
795 |
|
796 SetRect(aRect); |
|
797 |
|
798 // Not drawn correctly if calling SetRect() |
|
799 iPopup->SetSize(aRect.Size()); |
|
800 iPopup->SetPosition(TPoint(0,0)); |
|
801 iPopup->SetImageL( aBitmap ); |
|
802 iPopup->SetSelectedColor( iCurrentRgb ); |
|
803 |
|
804 #ifdef RD_TACTILE_FEEDBACK |
|
805 iTouchFeedBack = MTouchFeedback::Instance(); |
|
806 #endif /* RD_TACTILE_FEEDBACK */ |
|
807 } |
|
808 |
|
809 //============================================================================= |
|
810 TBool CColorSelectionDialog::OkToExitL( TInt aButtonId ) |
|
811 { |
|
812 if ( aButtonId == EAknSoftkeyOk || aButtonId == EAknSoftkeySelect) |
|
813 { |
|
814 iCurrentRgb = iPopup->GetSelectedColor(); |
|
815 return ETrue; |
|
816 } |
|
817 else |
|
818 { |
|
819 return EFalse; |
|
820 } |
|
821 } |
|
822 |
|
823 //============================================================================= |
|
824 void CColorSelectionDialog::Draw(const TRect& /*aRect*/) const |
|
825 { |
|
826 } |
|
827 |
|
828 //============================================================================= |
|
829 void CColorSelectionDialog::SizeChanged() |
|
830 { |
|
831 iPopup->SetSize( Rect().Size() ); |
|
832 } |
|
833 |
|
834 //============================================================================= |
|
835 void CColorSelectionDialog::PreLayoutDynInitL() |
|
836 { |
|
837 } |
|
838 |
|
839 |
|
840 //============================================================================= |
|
841 TInt CColorSelectionDialog::CountComponentControls() const |
|
842 { |
|
843 return 1; |
|
844 } |
|
845 |
|
846 //============================================================================= |
|
847 CCoeControl* CColorSelectionDialog::ComponentControl(TInt /*aIndex*/) const |
|
848 { |
|
849 return iPopup; |
|
850 } |
|
851 |
|
852 //============================================================================= |
|
853 TKeyResponse CColorSelectionDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) |
|
854 { |
|
855 // Selection key or numeric keypad '5' close the dialog |
|
856 TKeyResponse res = EKeyWasNotConsumed; |
|
857 if (aType == EEventKey && |
|
858 (aKeyEvent.iCode == EKeyOK || aKeyEvent.iCode == 53 || aKeyEvent.iScanCode == EStdKeyEnter) ) |
|
859 { |
|
860 TryExitL (EAknSoftkeyOk); |
|
861 res = EKeyWasConsumed; |
|
862 } |
|
863 else if (aType == EEventKey && aKeyEvent.iCode == EKeyNo || aKeyEvent.iCode == EKeyEscape) // Do not exit if dialog active |
|
864 { |
|
865 TryExitL (EAknSoftkeyCancel); |
|
866 res = EKeyWasNotConsumed; |
|
867 } |
|
868 #ifdef FULLSCREEN_AVAILABLE |
|
869 else if (aType == EEventKey && aKeyEvent.iCode == 48 ) // 0 |
|
870 { |
|
871 // Switch normal screen / full screen |
|
872 if (CResolutionUtil::Self()->GetFullScreen()) |
|
873 { |
|
874 iEikonEnv->EikAppUi()->HandleCommandL(EImageEditorMenuCmdNormalScreen); |
|
875 SetRect(iEikonEnv->EikAppUi()->ClientRect()); |
|
876 SizeChanged(); |
|
877 DrawNow(); |
|
878 } |
|
879 else |
|
880 { |
|
881 iEikonEnv->EikAppUi()->HandleCommandL(EImageEditorMenuCmdFullScreen); |
|
882 SetExtentToWholeScreen(); |
|
883 SizeChanged(); |
|
884 DrawNow(); |
|
885 } |
|
886 res = EKeyWasConsumed; |
|
887 } |
|
888 #endif // FULLSCREEN_AVAILABLE |
|
889 else |
|
890 { |
|
891 res = iPopup->OfferKeyEventL(aKeyEvent, aType); |
|
892 if (res == EKeyWasConsumed) |
|
893 { |
|
894 DrawDeferred(); |
|
895 } |
|
896 } |
|
897 |
|
898 return res; |
|
899 } |
|
900 |
|
901 //============================================================================= |
|
902 void CColorSelectionDialog::HandlePointerEventL( |
|
903 const TPointerEvent &aPointerEvent ) |
|
904 { |
|
905 if( AknLayoutUtils::PenEnabled() ) |
|
906 { |
|
907 TBool draw( EFalse ); |
|
908 switch( aPointerEvent.iType ) |
|
909 { |
|
910 case TPointerEvent::EButton1Down: |
|
911 { |
|
912 // forward event only if grid area was pressed |
|
913 if ( iPopup->GridRect().Contains( aPointerEvent.iPosition ) ) |
|
914 { |
|
915 #ifdef RD_TACTILE_FEEDBACK |
|
916 if ( iTouchFeedBack ) |
|
917 { |
|
918 iTouchFeedBack->InstantFeedback( ETouchFeedbackBasic ); |
|
919 RDebug::Printf( "ImageEditor::CColorSelectionDialog: ETouchFeedback" ); |
|
920 } |
|
921 #endif /* RD_TACTILE_FEEDBACK */ |
|
922 iPopup->HandlePointerEventL( aPointerEvent ); |
|
923 draw = ETrue; |
|
924 } |
|
925 break; |
|
926 } |
|
927 case TPointerEvent::EDrag: |
|
928 { |
|
929 if ( iPopup->GridRect().Contains( aPointerEvent.iPosition ) ) |
|
930 { |
|
931 #ifdef RD_TACTILE_FEEDBACK |
|
932 if ( iTouchFeedBack ) |
|
933 { |
|
934 iTouchFeedBack->InstantFeedback( ETouchFeedbackSensitive ); |
|
935 RDebug::Printf( "ImageEditor::CColorSelectionDialog: ETouchFeedbackSensitive" ); |
|
936 } |
|
937 #endif /* RD_TACTILE_FEEDBACK */ |
|
938 iPopup->HandlePointerEventL( aPointerEvent ); |
|
939 draw = ETrue; |
|
940 } |
|
941 break; |
|
942 } |
|
943 case TPointerEvent::EButton1Up: |
|
944 { |
|
945 // already highlighted item is pressed |
|
946 if ( iPopup->HighlightedItemPressed( aPointerEvent.iPosition ) ) |
|
947 { |
|
948 TryExitL (EAknSoftkeyOk); |
|
949 } |
|
950 break; |
|
951 } |
|
952 default: |
|
953 { |
|
954 break; |
|
955 } |
|
956 } |
|
957 |
|
958 if ( draw ) |
|
959 { |
|
960 DrawDeferred(); |
|
961 } |
|
962 } |
|
963 } |
|
964 |
|
965 // End of file |
|
966 |