|
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 * Utils class for helping in drawing. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // CAknTextQueryDialog |
|
22 #include <aknquerydialog.h> |
|
23 #include <aknwaitdialog.h> |
|
24 #include <eikprogi.h> |
|
25 #include <bautils.h> |
|
26 #include <AknUtils.h> |
|
27 #include <AknIconUtils.h> |
|
28 #include <AknInfoPopupNoteController.h> |
|
29 #include <gulalign.h> |
|
30 |
|
31 #include <ImageEditorUI.rsg> |
|
32 #include "ResolutionUtil.h" |
|
33 #include "ImageEditorUiDefs.h" |
|
34 #include "DrawUtils.h" |
|
35 #include "ColorSelectionGrid.h" |
|
36 #include "colorselectionpopup.h" |
|
37 #include "CMultiLineQueryDialog.h" |
|
38 |
|
39 //============================================================================= |
|
40 EXPORT_C void SDrawUtils::DrawGuide ( |
|
41 CGraphicsContext & aGc, |
|
42 const TRect & aRect, |
|
43 const TGuideType aType, |
|
44 const TRgb & aColor |
|
45 ) |
|
46 { |
|
47 |
|
48 // Set graphics context parameters |
|
49 aGc.SetPenStyle (CGraphicsContext::ESolidPen); |
|
50 aGc.SetPenColor (aColor); |
|
51 aGc.SetBrushStyle (CGraphicsContext::ESolidBrush); |
|
52 aGc.SetBrushColor (aColor); |
|
53 |
|
54 switch (aType) |
|
55 { |
|
56 case EGuideTypeUp: |
|
57 { |
|
58 TInt colstart = ((aRect.iBr.iX + aRect.iTl.iX) >> 1) + 1; |
|
59 TInt colstop = colstart + 1; |
|
60 for (TInt i = aRect.iTl.iY; i <= aRect.iBr.iY; ++i, --colstart, ++colstop) |
|
61 { |
|
62 aGc.DrawLine (TPoint (colstart, i), TPoint (colstop, i)); |
|
63 } |
|
64 break; |
|
65 } |
|
66 case EGuideTypeDown: |
|
67 { |
|
68 TInt colstart = ((aRect.iBr.iX + aRect.iTl.iX) >> 1) + 1; |
|
69 TInt colstop = colstart + 1; |
|
70 for (TInt i = aRect.iBr.iY; i >= aRect.iTl.iY; --i, --colstart, ++colstop) |
|
71 { |
|
72 aGc.DrawLine (TPoint (colstart, i), TPoint (colstop, i)); |
|
73 } |
|
74 break; |
|
75 } |
|
76 case EGuideTypeLeft: |
|
77 { |
|
78 TInt rowstart = ((aRect.iBr.iY + aRect.iTl.iY) >> 1) + 1; |
|
79 TInt rowstop = rowstart + 1; |
|
80 for (TInt i = aRect.iTl.iX; i <= aRect.iBr.iX; ++i, --rowstart, ++rowstop) |
|
81 { |
|
82 aGc.DrawLine (TPoint (i, rowstart), TPoint (i, rowstop)); |
|
83 } |
|
84 break; |
|
85 } |
|
86 case EGuideTypeRight: |
|
87 { |
|
88 TInt rowstart = ((aRect.iBr.iY + aRect.iTl.iY) >> 1) + 1; |
|
89 TInt rowstop = rowstart + 1; |
|
90 for (TInt i = aRect.iBr.iX; i >= aRect.iTl.iX; --i, --rowstart, ++rowstop) |
|
91 { |
|
92 aGc.DrawLine (TPoint (i, rowstart), TPoint (i, rowstop)); |
|
93 } |
|
94 break; |
|
95 } |
|
96 default: |
|
97 { |
|
98 break; |
|
99 } |
|
100 |
|
101 } |
|
102 } |
|
103 |
|
104 //============================================================================= |
|
105 EXPORT_C void SDrawUtils::DrawBeveledRect ( |
|
106 CGraphicsContext & aGc, |
|
107 const TRect & aRect, |
|
108 const TRgb & aColor, |
|
109 const TRgb & aLight, |
|
110 const TRgb & aShadow |
|
111 ) |
|
112 { |
|
113 // Set graphics context parameters |
|
114 aGc.SetPenStyle (CGraphicsContext::ESolidPen); |
|
115 aGc.SetPenColor (aShadow); |
|
116 aGc.SetBrushStyle (CGraphicsContext::ESolidBrush); |
|
117 aGc.SetBrushColor (aColor); |
|
118 |
|
119 // Draw shadow + rectangle area |
|
120 aGc.DrawRect (aRect); |
|
121 |
|
122 // Get corners |
|
123 TInt ulc = aRect.iTl.iX; |
|
124 TInt ulr = aRect.iTl.iY; |
|
125 TInt lrc = aRect.iBr.iX; |
|
126 TInt lrr = aRect.iBr.iY; |
|
127 |
|
128 // Draw light |
|
129 aGc.SetPenColor (aLight); |
|
130 aGc.DrawLine ( TPoint(lrc - 1, ulr + 1), TPoint(lrc - 1, lrr)); |
|
131 aGc.DrawLine ( TPoint(ulc + 1, lrr - 1), TPoint(lrc - 1, lrr - 1)); |
|
132 |
|
133 } |
|
134 |
|
135 //============================================================================= |
|
136 EXPORT_C void SDrawUtils::DrawFlatRect ( |
|
137 CGraphicsContext & aGc, |
|
138 const TRect & aRect, |
|
139 const TRgb & aColor, |
|
140 const TRgb & aLight, |
|
141 const TRgb & aShadow |
|
142 ) |
|
143 { |
|
144 // Set graphics context parameters |
|
145 aGc.SetPenStyle (CGraphicsContext::ESolidPen); |
|
146 aGc.SetPenColor (aShadow); |
|
147 aGc.SetBrushStyle (CGraphicsContext::ESolidBrush); |
|
148 aGc.SetBrushColor (aColor); |
|
149 |
|
150 // Get corners |
|
151 TInt ulc = aRect.iTl.iX; |
|
152 TInt ulr = aRect.iTl.iY; |
|
153 TInt lrc = aRect.iBr.iX; |
|
154 TInt lrr = aRect.iBr.iY; |
|
155 |
|
156 // Draw shadow + rectangle area |
|
157 aGc.DrawRect (TRect (ulc, ulr, lrc - 1, lrr - 1)); |
|
158 |
|
159 // Draw light |
|
160 aGc.SetPenColor (aLight); |
|
161 aGc.DrawLine ( TPoint(lrc - 1, ulr), TPoint(lrc - 1, lrr)); |
|
162 aGc.DrawLine ( TPoint(ulc, lrr - 1), TPoint(lrc, lrr - 1)); |
|
163 aGc.DrawLine ( TPoint(ulc + 1, ulr + 1), TPoint(lrc - 2, ulr + 1)); |
|
164 aGc.DrawLine ( TPoint(ulc + 1, ulr + 2), TPoint(ulc + 1, lrr - 2)); |
|
165 } |
|
166 |
|
167 //============================================================================= |
|
168 EXPORT_C TInt SDrawUtils::LaunchQueryDialogL (const TDesC & aPrompt) |
|
169 { |
|
170 CAknQueryDialog * dlg = |
|
171 new (ELeave) CAknQueryDialog ( const_cast<TDesC&>(aPrompt) ); |
|
172 |
|
173 return dlg->ExecuteLD (R_IMAGE_EDITOR_CONFIRMATION_QUERY); |
|
174 } |
|
175 |
|
176 //============================================================================= |
|
177 EXPORT_C TInt SDrawUtils::LaunchQueryDialogOkOnlyL (const TDesC & aPrompt) |
|
178 { |
|
179 CAknQueryDialog * dlg = |
|
180 new (ELeave) CAknQueryDialog ( const_cast<TDesC&>(aPrompt) ); |
|
181 |
|
182 return dlg->ExecuteLD (R_IMAGE_EDITOR_CONFIRMATION_QUERY_OK_ONLY); |
|
183 } |
|
184 |
|
185 //============================================================================= |
|
186 EXPORT_C TInt SDrawUtils::LaunchTextQueryDialogL ( |
|
187 TDes & aData, |
|
188 const TDesC & aPrompt |
|
189 ) |
|
190 { |
|
191 // Create a query dialog |
|
192 CAknTextQueryDialog * dlg = |
|
193 new (ELeave) CAknTextQueryDialog (aData); |
|
194 |
|
195 // Enable predictive input |
|
196 dlg->SetPredictiveTextInputPermitted(ETrue); |
|
197 |
|
198 // Execute query dialog |
|
199 return dlg->ExecuteLD (R_IMAGE_EDITOR_TEXT_QUERY, aPrompt); |
|
200 } |
|
201 |
|
202 //============================================================================= |
|
203 EXPORT_C TInt SDrawUtils::LaunchMultiLineTextQueryDialogL ( |
|
204 TDes & aData, |
|
205 const TDesC & aPrompt |
|
206 ) |
|
207 { |
|
208 // Create a query dialog |
|
209 CMultiLineQueryDialog* dlg = CMultiLineQueryDialog::NewL( aData ); |
|
210 |
|
211 // Enable predictive input |
|
212 dlg->SetPredictiveTextInputPermitted( ETrue ); |
|
213 |
|
214 // Execute query dialog |
|
215 return dlg->ExecuteLD ( R_IMAGE_EDITOR_TEXT_QUERY, aPrompt ); |
|
216 } |
|
217 |
|
218 //============================================================================= |
|
219 EXPORT_C TInt SDrawUtils::LaunchListQueryDialogL ( |
|
220 MDesCArray * aTextItems, |
|
221 const TDesC & aPrompt |
|
222 ) |
|
223 { |
|
224 // Selected text item index |
|
225 TInt index (-1); |
|
226 |
|
227 // Create a new list dialog |
|
228 CAknListQueryDialog * dlg = new (ELeave) CAknListQueryDialog (&index); |
|
229 |
|
230 // Prepare list query dialog |
|
231 dlg->PrepareLC (R_IMAGE_EDITOR_LIST_QUERY); |
|
232 |
|
233 // Set heading |
|
234 dlg->QueryHeading()->SetTextL (aPrompt); |
|
235 |
|
236 // Set text item array |
|
237 dlg->SetItemTextArray (aTextItems); |
|
238 |
|
239 // Set item ownership |
|
240 dlg->SetOwnershipType (ELbmDoesNotOwnItemArray); |
|
241 |
|
242 // Execute |
|
243 if (dlg->RunLD()) |
|
244 { |
|
245 return index; |
|
246 } |
|
247 else |
|
248 { |
|
249 return -1; |
|
250 } |
|
251 } |
|
252 |
|
253 //============================================================================= |
|
254 EXPORT_C void SDrawUtils::LaunchWaitNoteL ( |
|
255 CAknWaitDialog** aSelfPtr, |
|
256 TInt aResourceID, |
|
257 const TDesC & aPrompt, |
|
258 MProgressDialogCallback* aCallback |
|
259 ) |
|
260 { |
|
261 (*aSelfPtr) = new (ELeave) CAknWaitDialog ( (CEikDialog**)aSelfPtr, ETrue); |
|
262 (*aSelfPtr)->SetTextL ( aPrompt ); |
|
263 (*aSelfPtr)->ExecuteLD (aResourceID); |
|
264 if (aCallback) |
|
265 { |
|
266 (*aSelfPtr)->SetCallback (aCallback); |
|
267 } |
|
268 } |
|
269 |
|
270 //============================================================================= |
|
271 EXPORT_C void SDrawUtils::LaunchProgressNoteL ( |
|
272 CAknProgressDialog** aSelfPtr, |
|
273 TInt aResourceID, |
|
274 const TDesC & aPrompt, |
|
275 TInt aFinalValue, |
|
276 MProgressDialogCallback* aCallback |
|
277 ) |
|
278 { |
|
279 (*aSelfPtr) = new (ELeave) CAknWaitDialog ( (CEikDialog**)aSelfPtr, ETrue); |
|
280 (*aSelfPtr)->PrepareLC(aResourceID); |
|
281 (*aSelfPtr)->GetProgressInfoL()->SetFinalValue (aFinalValue); |
|
282 (*aSelfPtr)->SetTextL ( aPrompt ); |
|
283 if (aCallback) |
|
284 { |
|
285 (*aSelfPtr)->SetCallback (aCallback); |
|
286 } |
|
287 (*aSelfPtr)->RunLD(); |
|
288 } |
|
289 |
|
290 //============================================================================= |
|
291 EXPORT_C TInt SDrawUtils::LaunchColorSelectionGridL (TRgb & aColor) |
|
292 { |
|
293 |
|
294 CColorSelectionGrid * grid = new (ELeave) CColorSelectionGrid; |
|
295 CleanupStack::PushL(grid); |
|
296 |
|
297 CAknPopupList * popup_list = |
|
298 CAknPopupList::NewL (grid, R_AVKON_SOFTKEYS_SELECT_BACK__SELECT); |
|
299 CleanupStack::PushL (popup_list); |
|
300 |
|
301 grid->ConstructL (popup_list, CEikListBox::ELeftDownInViewRect); |
|
302 |
|
303 // Create dialog prompt |
|
304 HBufC * prompt = |
|
305 grid->ControlEnv()->AllocReadResourceLC (R_SELECT_COLOUR); |
|
306 |
|
307 popup_list->SetTitleL ( prompt->Des() ); |
|
308 |
|
309 CleanupStack::PopAndDestroy(); // prompt |
|
310 |
|
311 TInt popup_ok = popup_list->ExecuteLD(); |
|
312 CleanupStack::Pop(); // popupList |
|
313 if (popup_ok) |
|
314 { |
|
315 // Get the selected item descriptor from the grid |
|
316 TInt index = grid->CurrentDataIndex(); |
|
317 TPtrC ptr = grid->Model()->MatchableTextArray()->MdcaPoint (index); |
|
318 |
|
319 // Extract the color information from the descriptor |
|
320 TInt i = ptr.Locate (TChar('\t')); |
|
321 if( i != KErrNotFound ) |
|
322 { |
|
323 TBuf<32> colordes; |
|
324 colordes.Copy ( ptr.Mid ( i + 1 ) ); |
|
325 TLex val (colordes); |
|
326 val.SkipSpace(); |
|
327 TInt color = 0; |
|
328 val.Val (color); |
|
329 aColor.SetRed (color & 0xFF); |
|
330 aColor.SetGreen ((color >> 8) & 0xFF); |
|
331 aColor.SetBlue ((color >> 16) & 0xFF); |
|
332 } |
|
333 } |
|
334 CleanupStack::PopAndDestroy(); // grid |
|
335 |
|
336 return popup_ok; |
|
337 } |
|
338 |
|
339 //============================================================================= |
|
340 EXPORT_C TInt SDrawUtils::LaunchColorSelectionPopupL (const CFbsBitmap* aPreview, |
|
341 TRect aRect, |
|
342 TRgb & aColor) |
|
343 { |
|
344 TInt dialog_ok = CColorSelectionDialog::RunDlgLD( aPreview, aRect, aColor); |
|
345 |
|
346 return dialog_ok; |
|
347 } |
|
348 |
|
349 //============================================================================= |
|
350 EXPORT_C TInt SDrawUtils::GetIndicatorBitmapL ( |
|
351 CFbsBitmap *& aChBitmap, |
|
352 CFbsBitmap *& aChMask, |
|
353 TInt aBmpIndex, |
|
354 TInt aMaskIndex |
|
355 ) |
|
356 { |
|
357 |
|
358 // Get the icon file name |
|
359 TFileName iconFile (KImageEditorUiMifFile); |
|
360 User::LeaveIfError( CompleteWithAppPath(iconFile) ); |
|
361 |
|
362 // Create bitmap and mask |
|
363 AknIconUtils::CreateIconL ( |
|
364 aChBitmap, |
|
365 aChMask, |
|
366 iconFile, |
|
367 aBmpIndex, |
|
368 aMaskIndex |
|
369 ); |
|
370 |
|
371 // Get the screen mode from the Resolution Util |
|
372 TInt screenMode = CResolutionUtil::Self()->GetScreenMode(); |
|
373 TSize bitmapSize; |
|
374 |
|
375 switch( screenMode ) |
|
376 { |
|
377 // small screen sizes |
|
378 case CResolutionUtil::EStandard: |
|
379 case CResolutionUtil::EStandardFullScreen: |
|
380 case CResolutionUtil::EStandardLandscape: |
|
381 case CResolutionUtil::EStandardLandscapeFullScreen: |
|
382 case CResolutionUtil::ESquare: |
|
383 case CResolutionUtil::ESquareFullScreen: |
|
384 case CResolutionUtil::ESquareRotated: |
|
385 case CResolutionUtil::ESquareRotatedFullScreen: |
|
386 { |
|
387 bitmapSize = TSize (KStandardCrosshairWidth, KStandardCrosshairHeight); |
|
388 break; |
|
389 } |
|
390 |
|
391 // big screen sizes |
|
392 case CResolutionUtil::EQVGA: |
|
393 case CResolutionUtil::EQVGAFullScreen: |
|
394 case CResolutionUtil::EQVGALandscape: |
|
395 case CResolutionUtil::EQVGALandscapeFullScreen: |
|
396 { |
|
397 bitmapSize = TSize (KQVGACrosshairWidth, KQVGACrosshairHeight); |
|
398 break; |
|
399 } |
|
400 |
|
401 case CResolutionUtil::EDouble: |
|
402 case CResolutionUtil::EDoubleFullScreen: |
|
403 case CResolutionUtil::EDoubleLandscape: |
|
404 case CResolutionUtil::EDoubleLandscapeFullScreen: |
|
405 { |
|
406 bitmapSize = TSize (KDoubleCrosshairWidth, KDoubleCrosshairHeight); |
|
407 break; |
|
408 } |
|
409 |
|
410 // HVGA |
|
411 case CResolutionUtil::EHVGA: |
|
412 case CResolutionUtil::EHVGAFullScreen: |
|
413 case CResolutionUtil::EHVGALandscape: |
|
414 case CResolutionUtil::EHVGALandscapeFullScreen: |
|
415 { |
|
416 bitmapSize = TSize (KHVGACrosshairWidth, KHVGACrosshairHeight); |
|
417 break; |
|
418 } |
|
419 |
|
420 // VGA |
|
421 case CResolutionUtil::EVGA: |
|
422 case CResolutionUtil::EVGAFullScreen: |
|
423 case CResolutionUtil::EVGALandscape: |
|
424 case CResolutionUtil::EVGALandscapeFullScreen: |
|
425 { |
|
426 bitmapSize = TSize (KVGACrosshairWidth, KVGACrosshairHeight); |
|
427 break; |
|
428 } |
|
429 |
|
430 // QHD |
|
431 case CResolutionUtil::EQHD: |
|
432 case CResolutionUtil::EQHDFullScreen: |
|
433 case CResolutionUtil::EQHDLandscape: |
|
434 case CResolutionUtil::EQHDLandscapeFullScreen: |
|
435 { |
|
436 bitmapSize = TSize (KVGACrosshairWidth, KVGACrosshairHeight); |
|
437 break; |
|
438 } |
|
439 |
|
440 default: |
|
441 { |
|
442 bitmapSize = TSize (KStandardCrosshairWidth, KStandardCrosshairHeight); |
|
443 break; |
|
444 } |
|
445 } |
|
446 |
|
447 // Set size for scalable icons - MUST BE CALLED BEFORE ICON IS USABLE |
|
448 AknIconUtils::SetSize( aChBitmap, bitmapSize ); |
|
449 |
|
450 return KErrNone; |
|
451 } |
|
452 |
|
453 //============================================================================= |
|
454 EXPORT_C void SDrawUtils::ShowToolTip ( |
|
455 CAknInfoPopupNoteController* aPopupController, |
|
456 CCoeControl* aCallingControl, |
|
457 TRect aPositionRect, |
|
458 const TDesC& aText ) |
|
459 { |
|
460 TPoint controlPosition( 0, 0 ); |
|
461 if ( AknsUtils::GetControlPosition( aCallingControl, |
|
462 controlPosition ) != KErrNone ) |
|
463 { |
|
464 controlPosition = aCallingControl->PositionRelativeToScreen(); |
|
465 } |
|
466 |
|
467 // add calling control's relative position to rect coordinates |
|
468 TRect positionRect( TPoint( aPositionRect.iTl.iX + controlPosition.iX, |
|
469 aPositionRect.iTl.iY + controlPosition.iY ), |
|
470 aPositionRect.Size() ); |
|
471 if( aPopupController ) |
|
472 { |
|
473 aPopupController->SetTextL( aText ); |
|
474 aPopupController->SetTimePopupInView( KTimeTooltipInView ); |
|
475 aPopupController->SetTooltipModeL( ETrue ); |
|
476 aPopupController->SetPositionByHighlight( positionRect ); |
|
477 aPopupController->ShowInfoPopupNote(); |
|
478 } |
|
479 |
|
480 } |
|
481 |
|
482 //============================================================================= |
|
483 EXPORT_C void SDrawUtils::ShowToolTip ( |
|
484 CAknInfoPopupNoteController* aPopupController, |
|
485 CCoeControl* aCallingControl, |
|
486 TPoint aPosition, |
|
487 TGulAlignmentValue aAlignment, |
|
488 const TDesC& aText ) |
|
489 { |
|
490 TPoint controlPosition( 0, 0 ); |
|
491 if ( AknsUtils::GetControlPosition( aCallingControl, |
|
492 controlPosition ) != KErrNone ) |
|
493 { |
|
494 controlPosition = aCallingControl->PositionRelativeToScreen(); |
|
495 } |
|
496 |
|
497 // add calling control's relative position to coordinates |
|
498 TPoint finalPosition = TPoint( aPosition.iX + controlPosition.iX, |
|
499 aPosition.iY + controlPosition.iY ); |
|
500 if( aPopupController ) |
|
501 { |
|
502 aPopupController->SetTextL( aText ); |
|
503 aPopupController->SetTimePopupInView( KTimeTooltipInView ); |
|
504 aPopupController->SetTooltipModeL( ETrue ); |
|
505 aPopupController->SetPositionAndAlignment( finalPosition, aAlignment ); |
|
506 aPopupController->ShowInfoPopupNote(); |
|
507 } |
|
508 } |
|
509 // End of File |