|
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 * Talk bubble plugin control implementation. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 // INCLUDES |
|
23 #include <fbs.h> |
|
24 #include <badesca.h> |
|
25 #include <bautils.h> |
|
26 #include <gdi.h> |
|
27 #include <eikenv.h> |
|
28 #include <bitdev.h> |
|
29 #include <aknview.h> |
|
30 #include <aknutils.h> |
|
31 #include <e32math.h> |
|
32 |
|
33 #ifdef RD_TACTILE_FEEDBACK |
|
34 #include <touchfeedback.h> |
|
35 #endif /* RD_TACTILE_FEEDBACK */ |
|
36 |
|
37 #include <ImageEditorUI.mbg> |
|
38 |
|
39 #include <aknquerydialog.h> |
|
40 #include <avkon.rsg> |
|
41 #include <AknInfoPopupNoteController.h> |
|
42 #include <bubble.rsg> |
|
43 #include <bautils.h> |
|
44 #include <ConeResLoader.h> |
|
45 #include <csxhelp/sie.hlp.hrh> |
|
46 |
|
47 #include "ImageEditorUI.hrh" |
|
48 #include "ImageEditorPluginBase.hrh" |
|
49 #include "Bubble.hrh" |
|
50 #include "JpTimer.h" |
|
51 #include "PluginInfo.h" |
|
52 #include "ImageEditorUids.hrh" |
|
53 #include "ImageEditorUiDefs.h" |
|
54 #include "iepb.h" |
|
55 #include "SystemParameters.h" |
|
56 #include "ResolutionUtil.h" |
|
57 |
|
58 #include "ImageEditorBubbleControl.h" |
|
59 #include "BubbleSelectionGrid.h" |
|
60 |
|
61 //#include "platform_security_literals.hrh" |
|
62 |
|
63 // debug log |
|
64 #include "imageeditordebugutils.h" |
|
65 _LIT(KBubblePluginLogFile,"BubblePlugin.log"); |
|
66 |
|
67 // CONSTANTS |
|
68 |
|
69 // TIMER WAIT |
|
70 const TInt KWait = 100; |
|
71 |
|
72 // Bubble POSITION |
|
73 const TInt KPosParamStep = 8; |
|
74 |
|
75 // Bubble SCALE |
|
76 const TInt KScaleParamStep = 50; |
|
77 const TInt KTouchScaleMaxStepCount = 20; |
|
78 |
|
79 // Bubble ANGLE |
|
80 const TInt KDegreeMultiplier = 1000; |
|
81 const TInt KAngleParamMax = 359000; |
|
82 const TInt KAngleParam90Deg = 90000; |
|
83 const TInt KAngleParamDef = 0; |
|
84 const TInt KAngleParamStep = 2000; |
|
85 |
|
86 // RESOURCE INDICES |
|
87 const TInt KSelectBubbleIndex = 0; |
|
88 const TInt KMainBubbleIndex = 1; |
|
89 const TInt KMoveBubbleIndex = 2; |
|
90 const TInt KResizeBubbleIndex = 3; |
|
91 const TInt KRotateBubbleIndex = 4; |
|
92 |
|
93 _LIT (KPgnResourceFile, "Bubble.rsc"); |
|
94 _LIT(KComponentName, "ImageEditorBubblePlugin"); |
|
95 |
|
96 //============================================================================= |
|
97 CImageEditorBubbleControl * CImageEditorBubbleControl::NewL ( |
|
98 const TRect & aRect, |
|
99 CCoeControl * aParent |
|
100 ) |
|
101 { |
|
102 CImageEditorBubbleControl * self = new (ELeave) CImageEditorBubbleControl; |
|
103 CleanupStack::PushL (self); |
|
104 self->ConstructL (aRect, aParent); |
|
105 CleanupStack::Pop (); // self |
|
106 return self; |
|
107 } |
|
108 |
|
109 //============================================================================= |
|
110 CImageEditorBubbleControl::CImageEditorBubbleControl () : |
|
111 iState (EInsertBubbleStateMin), |
|
112 iResLoader ( * ControlEnv() ), |
|
113 iTickCount (0), |
|
114 iNaviStepMultiplier (KDefaultSmallNavigationStepMultiplier), |
|
115 iDisplayingOkOptionsMenu(EFalse), |
|
116 iReadyToRender(EFalse) |
|
117 { |
|
118 |
|
119 } |
|
120 |
|
121 //============================================================================= |
|
122 CImageEditorBubbleControl::~CImageEditorBubbleControl () |
|
123 { |
|
124 delete iIndicator; |
|
125 delete iIndicatorMask; |
|
126 delete iTimer; |
|
127 iResLoader.Close(); |
|
128 iSysPars = NULL; |
|
129 iEditorView = NULL; |
|
130 iItem = NULL; |
|
131 if (iPopupList) |
|
132 { |
|
133 delete iPopupList; |
|
134 iPopupList = NULL; |
|
135 } |
|
136 delete iPopupController; |
|
137 delete iTooltipResize; |
|
138 delete iTooltipMove; |
|
139 delete iTooltipRotate; |
|
140 } |
|
141 |
|
142 //============================================================================= |
|
143 void CImageEditorBubbleControl::ConstructL ( |
|
144 const TRect & /*aRect*/, |
|
145 CCoeControl * aParent |
|
146 ) |
|
147 { |
|
148 LOG(KBubblePluginLogFile, "CImageEditorBubbleControl::ConstructL()"); |
|
149 |
|
150 // Set parent window |
|
151 SetContainerWindowL (*aParent); |
|
152 |
|
153 // Create resource utility |
|
154 TFileName resFile; |
|
155 resFile.Append(KPgnResourcePath); |
|
156 resFile.Append(KPgnResourceFile); |
|
157 |
|
158 User::LeaveIfError( CompleteWithAppPath( resFile ) ); |
|
159 // Implementation of RConeResourceLoader uses BaflUtils::NearestLanguageFile |
|
160 // to search for a localised resource in proper search order |
|
161 iResLoader.OpenL ( resFile ); |
|
162 |
|
163 // Create timer for fast key repeat |
|
164 iTimer = CJPTimer::NewL( this ); |
|
165 |
|
166 iPopupController = CAknInfoPopupNoteController::NewL(); |
|
167 |
|
168 TFileName resourcefile; |
|
169 resourcefile.Append(KPgnResourcePath); |
|
170 resourcefile.Append(KPgnResourceFile); |
|
171 User::LeaveIfError( CompleteWithAppPath( resourcefile ) ); |
|
172 |
|
173 // Read tooltip resources |
|
174 // (RConeResourceLoader selects the language using BaflUtils::NearestLanguageFile) |
|
175 RConeResourceLoader resLoader ( *CEikonEnv::Static() ); |
|
176 CleanupClosePushL ( resLoader ); |
|
177 resLoader.OpenL ( resourcefile ); |
|
178 |
|
179 iTooltipResize = CEikonEnv::Static()->AllocReadResourceL(R_TOOLTIP_BUBBLE_RESIZE); |
|
180 iTooltipMove = CEikonEnv::Static()->AllocReadResourceL(R_TOOLTIP_BUBBLE_MOVE); |
|
181 iTooltipRotate = CEikonEnv::Static()->AllocReadResourceL(R_TOOLTIP_BUBBLE_ROTATE); |
|
182 CleanupStack::PopAndDestroy(); // resLoader |
|
183 |
|
184 #ifdef RD_TACTILE_FEEDBACK |
|
185 iTouchFeedBack = MTouchFeedback::Instance(); |
|
186 #endif /* RD_TACTILE_FEEDBACK */ |
|
187 |
|
188 // Activate control |
|
189 ActivateL(); |
|
190 |
|
191 EnableDragEvents(); |
|
192 |
|
193 } |
|
194 |
|
195 //============================================================================= |
|
196 void CImageEditorBubbleControl::PrepareL () |
|
197 { |
|
198 LOG(KBubblePluginLogFile, "CImageEditorBubbleControl::PrepareL()"); |
|
199 |
|
200 // Set busy flag untill the bitmap has been decoded |
|
201 SetBusy(); |
|
202 |
|
203 // Main view navi pane text |
|
204 iNaviPaneText.Copy ( iItem->Parameters()[KSelectBubbleIndex] ); |
|
205 |
|
206 // Popup list to contain the grid |
|
207 iPopupList = new (ELeave) CBubbleSelectionDialog(iBubbleFileName, iBubbleFileNameIndex); |
|
208 iPopupList->ConstructL(this); |
|
209 |
|
210 } |
|
211 |
|
212 //============================================================================= |
|
213 TBool CImageEditorBubbleControl::IsReadyToRender() const |
|
214 { |
|
215 return iReadyToRender; |
|
216 } |
|
217 |
|
218 |
|
219 //============================================================================= |
|
220 void CImageEditorBubbleControl::HandleControlEventL(CCoeControl* /*aControl*/ ,TCoeEvent aEventType) |
|
221 { |
|
222 LOG(KBubblePluginLogFile, "CImageEditorBubbleControl::HandleControlEventL()"); |
|
223 |
|
224 // When the icons have been decoded, launch the grid. |
|
225 if (aEventType == EEventStateChanged) |
|
226 { |
|
227 __ASSERT_ALWAYS( iPopupList, User::Panic( KComponentName, KErrNotReady)); |
|
228 |
|
229 TBool fullscreen = CResolutionUtil::Self()->GetFullScreen(); |
|
230 if (fullscreen) |
|
231 { |
|
232 iEditorView->HandleCommandL (EImageEditorMenuCmdNormalScreen); |
|
233 } |
|
234 TInt popupOk = iPopupList->ExecuteLD(R_BUBBLE_SELECTION_DIALOG); |
|
235 iPopupList = NULL; |
|
236 |
|
237 if (fullscreen) |
|
238 { |
|
239 iEditorView->HandleCommandL (EImageEditorMenuCmdFullScreen); |
|
240 } |
|
241 |
|
242 if (popupOk) |
|
243 { |
|
244 ToMoveStateL(); |
|
245 SelectBubbleL(); |
|
246 StoreTempParams(); |
|
247 ResetBusy(); |
|
248 } |
|
249 else |
|
250 { |
|
251 LOG(KBubblePluginLogFile, "HandleControlEventL: Plugin cancelled from popup."); |
|
252 iState = EInsertBubbleStateMin; |
|
253 iEditorView->HandleCommandL (EImageEditorCancelPlugin); |
|
254 } |
|
255 } |
|
256 |
|
257 // Cancelled the grid |
|
258 else if (aEventType == EEventRequestCancel) |
|
259 { |
|
260 LOG(KBubblePluginLogFile, "HandleControlEventL: Grid cancelled."); |
|
261 iState = EInsertBubbleStateMin; |
|
262 iEditorView->HandleCommandL (EImageEditorCancelPlugin); |
|
263 } |
|
264 } |
|
265 |
|
266 //============================================================================= |
|
267 void CImageEditorBubbleControl::HandleListBoxEventL(CEikListBox* /*aListBox*/, |
|
268 TListBoxEvent /*aEventType*/) |
|
269 { |
|
270 } |
|
271 |
|
272 |
|
273 |
|
274 //============================================================================= |
|
275 void CImageEditorBubbleControl::SelectBubbleL() |
|
276 { |
|
277 LOG(KBubblePluginLogFile, "CImageEditorBubbleControl::SelectBubbleL()"); |
|
278 |
|
279 TRect rect = iSysPars->VisibleImageRect(); |
|
280 |
|
281 // Set default position |
|
282 iX = (rect.iTl.iX + rect.iBr.iX) / 2; |
|
283 iY = (rect.iTl.iY + rect.iBr.iY) / 2; |
|
284 |
|
285 // Set default angle |
|
286 iAngle = KAngleParamDef; |
|
287 |
|
288 // Set default scale |
|
289 if ( rect.Width() > rect.Height() ) |
|
290 { |
|
291 iScale = rect.Height() / 2; |
|
292 iScaleMin = rect.Height() / 10; |
|
293 iScaleMax = rect.Height(); |
|
294 iScaleToHeight = ETrue; |
|
295 } |
|
296 else |
|
297 { |
|
298 iScale = rect.Width() / 2; |
|
299 iScaleMin = rect.Width() / 10; |
|
300 iScaleMax = rect.Width(); |
|
301 iScaleToHeight = EFalse; |
|
302 } |
|
303 |
|
304 iParam.Copy (_L("file \"")); |
|
305 iParam.Append (iBubbleFileName); |
|
306 iParam.Append (_L("\"")); |
|
307 |
|
308 iParam.Append (_L(" bubble ")); |
|
309 iParam.AppendNum (iBubbleFileNameIndex); |
|
310 iParam.Append (_L(" mask ")); |
|
311 iParam.AppendNum (iBubbleFileNameIndex + 1); |
|
312 iParam.Append (_L(" load")); |
|
313 |
|
314 iParam.Append (_L(" x ")); |
|
315 iParam.AppendNum (iX); |
|
316 |
|
317 iParam.Append (_L(" y ")); |
|
318 iParam.AppendNum (iY); |
|
319 |
|
320 iParam.Append (_L(" angle ")); |
|
321 iParam.AppendNum (iAngle); |
|
322 |
|
323 if ( iScaleToHeight ) |
|
324 { |
|
325 iParam.Append (_L(" height ")); |
|
326 iParam.AppendNum (iScale); |
|
327 } |
|
328 else |
|
329 { |
|
330 iParam.Append (_L(" width ")); |
|
331 iParam.AppendNum (iScale); |
|
332 } |
|
333 |
|
334 ToMoveStateL(); |
|
335 |
|
336 LOGDES(KBubblePluginLogFile, iParam); |
|
337 |
|
338 LOG(KBubblePluginLogFile, "SelectBubbleL: Ready to render"); |
|
339 |
|
340 iReadyToRender = ETrue; |
|
341 |
|
342 iEditorView->HandleCommandL (EImageEditorCmdRender); |
|
343 |
|
344 LOG(KBubblePluginLogFile, "SelectBubbleL: Rendered"); |
|
345 |
|
346 } |
|
347 |
|
348 //============================================================================= |
|
349 void CImageEditorBubbleControl::SetView (CAknView * aView) |
|
350 { |
|
351 iEditorView = aView; |
|
352 } |
|
353 |
|
354 //============================================================================= |
|
355 void CImageEditorBubbleControl::SetSelectedUiItemL (CPluginInfo * aItem) |
|
356 { |
|
357 iItem = aItem; |
|
358 } |
|
359 |
|
360 //============================================================================= |
|
361 void CImageEditorBubbleControl::SetBusy () |
|
362 { |
|
363 CImageEditorControlBase::SetBusy(); |
|
364 if ( iPopupList ) |
|
365 { |
|
366 iPopupList->SetBusy(ETrue); |
|
367 } |
|
368 } |
|
369 |
|
370 //============================================================================= |
|
371 void CImageEditorBubbleControl::ResetBusy () |
|
372 { |
|
373 // Reset busy flag only if selection grid is constructed |
|
374 if (iState != EInsertBubbleStateMin) |
|
375 { |
|
376 CImageEditorControlBase::ResetBusy(); |
|
377 |
|
378 if (iPopupList) |
|
379 { |
|
380 iPopupList->SetBusy(EFalse); |
|
381 } |
|
382 |
|
383 } |
|
384 } |
|
385 |
|
386 //============================================================================= |
|
387 TKeyResponse CImageEditorBubbleControl::OfferKeyEventL ( |
|
388 const TKeyEvent & aKeyEvent, |
|
389 TEventCode aType |
|
390 ) |
|
391 { |
|
392 LOG(KBubblePluginLogFile, "CImageEditorBubbleControl::OfferKeyEventL()"); |
|
393 #ifdef VERBOSE |
|
394 LOGFMT(KBubblePluginLogFile, "\taType: %d", aType); |
|
395 LOGFMT(KBubblePluginLogFile, "\tiTickCount: %d", iTickCount); |
|
396 #endif |
|
397 |
|
398 TKeyResponse response = EKeyWasNotConsumed; |
|
399 |
|
400 // If busy, do not handle anything |
|
401 if ( Busy() ) |
|
402 { |
|
403 response = EKeyWasConsumed; |
|
404 } |
|
405 |
|
406 // In main state handle the OK Options menu |
|
407 else if ( aKeyEvent.iCode == EKeyOK && |
|
408 (iState == EInsertBubbleStateMain || iState == EInsertBubbleStateFirst ) ) |
|
409 { |
|
410 iDisplayingOkOptionsMenu = ETrue; |
|
411 iEditorView->HandleCommandL (EImageEditorTryDisplayMenuBar); |
|
412 response = EKeyWasConsumed; |
|
413 } |
|
414 |
|
415 // We handle only event keys |
|
416 else if (EEventKey == aType) |
|
417 { |
|
418 |
|
419 switch (aKeyEvent.iCode) |
|
420 { |
|
421 // Just consume keys |
|
422 case EKeyDownArrow: |
|
423 case EKeyUpArrow: |
|
424 case EKeyRightArrow: |
|
425 case EKeyLeftArrow: |
|
426 { |
|
427 response = EKeyWasConsumed; |
|
428 break; |
|
429 } |
|
430 |
|
431 case EKeyOK: |
|
432 { |
|
433 if (iState == EInsertBubbleStateMove || |
|
434 iState == EInsertBubbleStateRotate || |
|
435 iState == EInsertBubbleStateResize) |
|
436 { |
|
437 ToMainStateL(); |
|
438 DrawNow(); |
|
439 response = EKeyWasConsumed; |
|
440 } |
|
441 break; |
|
442 } |
|
443 |
|
444 case EKeyEnter: |
|
445 { |
|
446 if (iState == EInsertBubbleStateMove || |
|
447 iState == EInsertBubbleStateRotate || |
|
448 iState == EInsertBubbleStateResize) |
|
449 { |
|
450 ToMainStateL(); |
|
451 DrawNow(); |
|
452 } |
|
453 else if ( iState == EInsertBubbleStateMain ) |
|
454 { |
|
455 // Show context sensitive menu |
|
456 iEditorView->HandleCommandL( EImageEditorOpenContextMenu ); |
|
457 } |
|
458 response = EKeyWasConsumed; |
|
459 break; |
|
460 |
|
461 } |
|
462 |
|
463 case 0x31: // 1 |
|
464 { |
|
465 // Rotate only in rotate state |
|
466 if ( iState == EInsertBubbleStateRotate ) |
|
467 { |
|
468 iAngle -= KAngleParam90Deg; |
|
469 StoreParameters(); |
|
470 TRAP_IGNORE( iEditorView->HandleCommandL (EImageEditorCmdRender) ); |
|
471 } |
|
472 break; |
|
473 } |
|
474 |
|
475 case 0x33: // 3 |
|
476 { |
|
477 // Rotate only in rotate state |
|
478 if ( iState == EInsertBubbleStateRotate ) |
|
479 { |
|
480 iAngle += KAngleParam90Deg; |
|
481 StoreParameters(); |
|
482 TRAP_IGNORE( iEditorView->HandleCommandL (EImageEditorCmdRender) ); |
|
483 } |
|
484 break; |
|
485 } |
|
486 |
|
487 case 0x30: // 0 |
|
488 case 0x32: // 2 |
|
489 case 0x34: // 4 |
|
490 case 0x36: // 6 |
|
491 case 0x38: // 8 |
|
492 case EStdKeyDecVolume: // zoom out key |
|
493 case 0x23: // # |
|
494 { |
|
495 StorePosAndScaleRelScreen(); |
|
496 break; |
|
497 } |
|
498 |
|
499 case 0x35: // 5 |
|
500 case 0x2a: // * |
|
501 case EStdKeyIncVolume: // zoom in key |
|
502 { |
|
503 StorePosAndScaleRelScreen(); |
|
504 break; |
|
505 } |
|
506 |
|
507 default: |
|
508 { |
|
509 break; |
|
510 } |
|
511 } |
|
512 } |
|
513 |
|
514 // Key pressed down, mark pressed key |
|
515 else if (aType == EEventKeyDown) |
|
516 { |
|
517 switch (aKeyEvent.iScanCode) |
|
518 { |
|
519 case EStdKeyUpArrow: |
|
520 { |
|
521 iKeyCode = 1; |
|
522 response = EKeyWasConsumed; |
|
523 break; |
|
524 } |
|
525 case EStdKeyDownArrow: |
|
526 { |
|
527 iKeyCode = 2; |
|
528 response = EKeyWasConsumed; |
|
529 break; |
|
530 } |
|
531 case EStdKeyLeftArrow: |
|
532 { |
|
533 iKeyCode = 3; |
|
534 response = EKeyWasConsumed; |
|
535 break; |
|
536 } |
|
537 case EStdKeyRightArrow: |
|
538 { |
|
539 iKeyCode = 4; |
|
540 response = EKeyWasConsumed; |
|
541 break; |
|
542 } |
|
543 default: |
|
544 { |
|
545 iKeyCode = 0; |
|
546 break; |
|
547 } |
|
548 } |
|
549 |
|
550 if ( iKeyCode != 0 ) |
|
551 { |
|
552 iNaviStepMultiplier = KDefaultSmallNavigationStepMultiplier; |
|
553 iTickCount = 0; |
|
554 iTimer->Call( KWait ); |
|
555 } |
|
556 } |
|
557 |
|
558 // Key released, mark all keys to zero |
|
559 else if (aType == EEventKeyUp) |
|
560 { |
|
561 switch (aKeyEvent.iScanCode) |
|
562 { |
|
563 case EStdKeyUpArrow: |
|
564 case EStdKeyDownArrow: |
|
565 case EStdKeyLeftArrow: |
|
566 case EStdKeyRightArrow: |
|
567 { |
|
568 iKeyCode = 0; |
|
569 response = EKeyWasConsumed; |
|
570 ShowTooltip(); |
|
571 |
|
572 break; |
|
573 } |
|
574 default: |
|
575 { |
|
576 iKeyCode = 0; |
|
577 break; |
|
578 } |
|
579 } |
|
580 } |
|
581 |
|
582 return response; |
|
583 } |
|
584 |
|
585 //============================================================================= |
|
586 TDesC & CImageEditorBubbleControl::GetParam () |
|
587 { |
|
588 return iParam; |
|
589 } |
|
590 |
|
591 //============================================================================= |
|
592 void CImageEditorBubbleControl::SetSystemParameters (const CSystemParameters * aPars) |
|
593 { |
|
594 iSysPars = aPars; |
|
595 } |
|
596 |
|
597 //============================================================================= |
|
598 void CImageEditorBubbleControl::HandlePluginCommandL (const TInt aCommand) |
|
599 { |
|
600 LOG(KBubblePluginLogFile, "CImageEditorBubbleControl::HandlePluginCommandL()"); |
|
601 |
|
602 switch (aCommand) |
|
603 { |
|
604 case EPgnSoftkeyIdCancel: |
|
605 { |
|
606 iPopupController->HideInfoPopupNote(); |
|
607 if (iState == EInsertBubbleStateMin) |
|
608 { |
|
609 // ignore if the plugin is not ready yet |
|
610 } |
|
611 else if (iState == EInsertBubbleStateMain || |
|
612 iState == EInsertBubbleStateFirst) |
|
613 { |
|
614 if ( !CImageEditorControlBase::Busy() ) |
|
615 |
|
616 { |
|
617 LOG(KBubblePluginLogFile, "HandleControlEventL: Plug-in cancelled."); |
|
618 |
|
619 // Cancel plugin |
|
620 iState = EInsertBubbleStateMin; |
|
621 iEditorView->HandleCommandL (EImageEditorCancelPlugin); |
|
622 |
|
623 } |
|
624 } |
|
625 else |
|
626 { |
|
627 // Return to plugin main view |
|
628 RestoreTempParams(); |
|
629 StoreParameters(); |
|
630 ToMainStateL(); |
|
631 iEditorView->HandleCommandL (EImageEditorCmdRender); |
|
632 } |
|
633 break; |
|
634 } |
|
635 case EPgnSoftkeyIdOk: |
|
636 { |
|
637 iPopupController->HideInfoPopupNote(); |
|
638 if (iState != EInsertBubbleStateMin) |
|
639 { |
|
640 ToMainStateL(); |
|
641 DrawNow(); |
|
642 } |
|
643 break; |
|
644 } |
|
645 case EPgnSoftkeyIdDone: |
|
646 case EBubblePgnMenuCmdDone: |
|
647 { |
|
648 if (iState != EInsertBubbleStateMin) |
|
649 { |
|
650 iState = EInsertBubbleStateMin; |
|
651 iEditorView->HandleCommandL (EImageEditorApplyPlugin); |
|
652 } |
|
653 break; |
|
654 } |
|
655 case EBubblePgnMenuCmdMove: |
|
656 { |
|
657 ToMoveStateL(); |
|
658 DrawDeferred(); |
|
659 break; |
|
660 } |
|
661 case EBubblePgnMenuCmdResize: |
|
662 { |
|
663 ToResizeStateL(); |
|
664 DrawDeferred(); |
|
665 break; |
|
666 } |
|
667 case EBubblePgnMenuCmdRotate: |
|
668 { |
|
669 ToRotateStateL(); |
|
670 DrawDeferred(); |
|
671 break; |
|
672 } |
|
673 case EBubblePgnMenuCmdCancel: |
|
674 { |
|
675 LOG(KBubblePluginLogFile, "HandleControlEventL: Plug-in cancelled from menu."); |
|
676 iState = EInsertBubbleStateMin; |
|
677 iEditorView->HandleCommandL (EImageEditorCancelPlugin); |
|
678 break; |
|
679 } |
|
680 |
|
681 case EImageEditorPreGlobalZoomChange: |
|
682 case EImageEditorPreGlobalPanChange: |
|
683 { |
|
684 StorePosAndScaleRelScreen(); |
|
685 break; |
|
686 } |
|
687 |
|
688 case EImageEditorGlobalZoomChanged: |
|
689 case EImageEditorGlobalPanChanged: |
|
690 { |
|
691 |
|
692 RestorePosAndScaleRelScreen(); |
|
693 ClipPosition(); |
|
694 LOGFMT(KBubblePluginLogFile, "\tiX = %d", iX); |
|
695 LOGFMT(KBubblePluginLogFile, "\tiY = %d", iY); |
|
696 |
|
697 StoreParameters(); |
|
698 StoreTempParams(); |
|
699 iEditorView->HandleCommandL (EImageEditorCmdRender); |
|
700 |
|
701 DrawNow(); |
|
702 break; |
|
703 } |
|
704 |
|
705 case EImageEditorPreScreenModeChange: |
|
706 { |
|
707 if (iState != EInsertBubbleStateMin) |
|
708 { |
|
709 StorePosAndScaleRelImage(); |
|
710 } |
|
711 break; |
|
712 } |
|
713 case EImageEditorPostScreenModeChange: |
|
714 { |
|
715 if (iState != EInsertBubbleStateMin) |
|
716 { |
|
717 RestorePosAndScaleRelImage(); |
|
718 ClipPosition(); |
|
719 StoreParameters(); |
|
720 StoreTempParams(); |
|
721 iEditorView->HandleCommandL (EImageEditorCmdRender); |
|
722 DrawNow(); |
|
723 } |
|
724 break; |
|
725 } |
|
726 |
|
727 default: |
|
728 { |
|
729 break; |
|
730 } |
|
731 } |
|
732 } |
|
733 |
|
734 //============================================================================= |
|
735 TInt CImageEditorBubbleControl::GetSoftkeyIndexL() |
|
736 { |
|
737 LOG(KBubblePluginLogFile, "CImageEditorBubbleControl::GetSoftkeyIndexL()"); |
|
738 |
|
739 TInt state = 0; |
|
740 |
|
741 switch (iState) |
|
742 { |
|
743 case EInsertBubbleStateFirst: |
|
744 { |
|
745 state = 0; // Options - Cancel |
|
746 break; |
|
747 } |
|
748 case EInsertBubbleStateMove: |
|
749 case EInsertBubbleStateRotate: |
|
750 case EInsertBubbleStateResize: |
|
751 { |
|
752 state = 1; // Ok - Cancel |
|
753 break; |
|
754 } |
|
755 case EInsertBubbleStateMain: |
|
756 { |
|
757 state = 2; // Options - Done |
|
758 break; |
|
759 } |
|
760 case EInsertBubbleStateMin: |
|
761 default: |
|
762 { |
|
763 state = 3; // Empty |
|
764 break; |
|
765 } |
|
766 |
|
767 } |
|
768 |
|
769 |
|
770 return state; |
|
771 } |
|
772 |
|
773 //============================================================================= |
|
774 TInt CImageEditorBubbleControl::GetContextMenuResourceId() |
|
775 { |
|
776 return R_BUBBLE_CONTEXT_MENUBAR; |
|
777 } |
|
778 |
|
779 //============================================================================= |
|
780 TBitField CImageEditorBubbleControl::GetDimmedMenuItems() |
|
781 { |
|
782 |
|
783 LOG(KBubblePluginLogFile, "CImageEditorBubbleControl::GetDimmedMenuItems()"); |
|
784 |
|
785 TBitField dimmedMenuItems; |
|
786 TInt count = iItem->MenuItems().Count(); |
|
787 |
|
788 if ( iDisplayingOkOptionsMenu ) |
|
789 { |
|
790 // Dim the command EBubblePgnMenuCmdCancel |
|
791 for ( TInt i = 0; i < count; i++) |
|
792 { |
|
793 // get the menu item id |
|
794 TInt menuItem = iItem->MenuItems().At(i).iCommandId; |
|
795 if ( menuItem == EBubblePgnMenuCmdCancel ) |
|
796 { |
|
797 dimmedMenuItems.SetBit( i ); |
|
798 } |
|
799 } |
|
800 iDisplayingOkOptionsMenu = EFalse; |
|
801 } |
|
802 |
|
803 return dimmedMenuItems; |
|
804 } |
|
805 |
|
806 //============================================================================= |
|
807 TPtrC CImageEditorBubbleControl::GetNaviPaneTextL ( |
|
808 TBool& aLeftNaviPaneScrollButtonVisibile, |
|
809 TBool& aRightNaviPaneScrollButtonVisible ) |
|
810 { |
|
811 LOG(KBubblePluginLogFile, "CImageEditorBubbleControl::GetNaviPaneTextL()"); |
|
812 |
|
813 aLeftNaviPaneScrollButtonVisibile = EFalse; |
|
814 aRightNaviPaneScrollButtonVisible = EFalse; |
|
815 return iNaviPaneText; |
|
816 } |
|
817 |
|
818 //============================================================================= |
|
819 void CImageEditorBubbleControl::Draw (const TRect & aRect) const |
|
820 { |
|
821 LOG(KBubblePluginLogFile, "CImageEditorBubbleControl::Draw()"); |
|
822 |
|
823 CPreviewControlBase::DrawPreviewImage (aRect); |
|
824 |
|
825 if ( iIndicator && iIndicator->Handle() && |
|
826 iIndicatorMask && iIndicatorMask->Handle() ) |
|
827 { |
|
828 CWindowGc & gc = SystemGc(); |
|
829 |
|
830 gc.SetPenStyle (CGraphicsContext::ENullPen); |
|
831 gc.SetBrushStyle (CGraphicsContext::ENullBrush); |
|
832 |
|
833 gc.BitBltMasked ( |
|
834 ComputeIndicatorPosition(), |
|
835 iIndicator, |
|
836 TRect (iIndicator->SizeInPixels()), |
|
837 iIndicatorMask, |
|
838 EFalse |
|
839 ); |
|
840 } |
|
841 } |
|
842 |
|
843 //============================================================================= |
|
844 void CImageEditorBubbleControl::NaviDown() |
|
845 { |
|
846 LOG(KBubblePluginLogFile, "CImageEditorBubbleControl::NaviDown()"); |
|
847 |
|
848 switch (iState) |
|
849 { |
|
850 |
|
851 case EInsertBubbleStateMove: |
|
852 { |
|
853 iY += (KPosParamStep * iNaviStepMultiplier); |
|
854 if ( iY > iSysPars->VisibleImageRect().iBr.iY ) |
|
855 { |
|
856 iY = iSysPars->VisibleImageRect().iBr.iY - 1; |
|
857 } |
|
858 break; |
|
859 } |
|
860 |
|
861 case EInsertBubbleStateResize: |
|
862 { |
|
863 iScale -= KScaleParamStep; |
|
864 if (iScale < iScaleMin) |
|
865 { |
|
866 iScale = iScaleMin; |
|
867 } |
|
868 break; |
|
869 } |
|
870 |
|
871 case EInsertBubbleStateRotate: |
|
872 { |
|
873 iAngle -= (KAngleParamStep * iNaviStepMultiplier) % KAngleParamMax; |
|
874 break; |
|
875 } |
|
876 |
|
877 default: |
|
878 { |
|
879 break; |
|
880 } |
|
881 } |
|
882 } |
|
883 |
|
884 //============================================================================= |
|
885 void CImageEditorBubbleControl::NaviUp() |
|
886 { |
|
887 LOG(KBubblePluginLogFile, "CImageEditorBubbleControl::NaviUp()"); |
|
888 |
|
889 switch (iState) |
|
890 { |
|
891 |
|
892 case EInsertBubbleStateMove: |
|
893 { |
|
894 iY -= (KPosParamStep * iNaviStepMultiplier); |
|
895 if ( iY < iSysPars->VisibleImageRect().iTl.iY ) |
|
896 { |
|
897 iY = iSysPars->VisibleImageRect().iTl.iY; |
|
898 } |
|
899 break; |
|
900 } |
|
901 |
|
902 case EInsertBubbleStateResize: |
|
903 { |
|
904 iScale += KScaleParamStep; |
|
905 if (iScale > iScaleMax) |
|
906 { |
|
907 iScale = iScaleMax; |
|
908 } |
|
909 break; |
|
910 } |
|
911 |
|
912 case EInsertBubbleStateRotate: |
|
913 { |
|
914 iAngle += (KAngleParamStep * iNaviStepMultiplier) % KAngleParamMax; |
|
915 break; |
|
916 } |
|
917 |
|
918 default: |
|
919 { |
|
920 break; |
|
921 } |
|
922 } |
|
923 } |
|
924 |
|
925 //============================================================================= |
|
926 void CImageEditorBubbleControl::NaviRight() |
|
927 { |
|
928 |
|
929 LOG(KBubblePluginLogFile, "CImageEditorBubbleControl::NaviRight()"); |
|
930 |
|
931 switch (iState) |
|
932 { |
|
933 |
|
934 case EInsertBubbleStateMove: |
|
935 { |
|
936 iX += (KPosParamStep * iNaviStepMultiplier); |
|
937 if ( iX >= iSysPars->VisibleImageRect().iBr.iX ) |
|
938 { |
|
939 iX = iSysPars->VisibleImageRect().iBr.iX - 1; |
|
940 } |
|
941 break; |
|
942 } |
|
943 |
|
944 case EInsertBubbleStateResize: |
|
945 { |
|
946 iScale += KScaleParamStep; |
|
947 if (iScale > iScaleMax) |
|
948 { |
|
949 iScale = iScaleMax; |
|
950 } |
|
951 break; |
|
952 } |
|
953 |
|
954 case EInsertBubbleStateRotate: |
|
955 { |
|
956 iAngle += (KAngleParamStep * iNaviStepMultiplier) % KAngleParamMax; |
|
957 break; |
|
958 } |
|
959 |
|
960 default: |
|
961 { |
|
962 break; |
|
963 } |
|
964 } |
|
965 } |
|
966 |
|
967 //============================================================================= |
|
968 void CImageEditorBubbleControl::NaviLeft() |
|
969 { |
|
970 LOG(KBubblePluginLogFile, "CImageEditorBubbleControl::NaviLeft()"); |
|
971 |
|
972 switch (iState) |
|
973 { |
|
974 |
|
975 case EInsertBubbleStateMove: |
|
976 { |
|
977 iX -= (KPosParamStep * iNaviStepMultiplier); |
|
978 if ( iX < iSysPars->VisibleImageRect().iTl.iX ) |
|
979 { |
|
980 iX = iSysPars->VisibleImageRect().iTl.iX; |
|
981 } |
|
982 break; |
|
983 } |
|
984 |
|
985 case EInsertBubbleStateResize: |
|
986 { |
|
987 iScale -= KScaleParamStep; |
|
988 if (iScale < iScaleMin) |
|
989 { |
|
990 iScale = iScaleMin; |
|
991 } |
|
992 break; |
|
993 } |
|
994 |
|
995 case EInsertBubbleStateRotate: |
|
996 { |
|
997 iAngle -= (KAngleParamStep * iNaviStepMultiplier) % KAngleParamMax; |
|
998 break; |
|
999 } |
|
1000 |
|
1001 default: |
|
1002 { |
|
1003 break; |
|
1004 } |
|
1005 } |
|
1006 } |
|
1007 |
|
1008 //============================================================================= |
|
1009 void CImageEditorBubbleControl::ToMoveStateL() |
|
1010 { |
|
1011 LOG(KBubblePluginLogFile, "CImageEditorBubbleControl::ToMoveStateL()"); |
|
1012 |
|
1013 iState = EInsertBubbleStateMove; |
|
1014 iNaviPaneText.Copy ( iItem->Parameters()[KMoveBubbleIndex] ); |
|
1015 StoreTempParams(); |
|
1016 iEditorView->HandleCommandL (EImageEditorUpdateNavipane); |
|
1017 iEditorView->HandleCommandL (EImageEditorUpdateSoftkeys); |
|
1018 LoadIndicatorL ( |
|
1019 EMbmImageeditoruiQgn_indi_imed_move_super, |
|
1020 EMbmImageeditoruiQgn_indi_imed_move_super_mask |
|
1021 ); |
|
1022 ShowTooltip(); |
|
1023 } |
|
1024 |
|
1025 //============================================================================= |
|
1026 void CImageEditorBubbleControl::ToResizeStateL() |
|
1027 { |
|
1028 LOG(KBubblePluginLogFile, "CImageEditorBubbleControl::ToResizeStateL()"); |
|
1029 |
|
1030 iState = EInsertBubbleStateResize; |
|
1031 iNaviPaneText.Copy ( iItem->Parameters()[KResizeBubbleIndex] ); |
|
1032 StoreTempParams(); |
|
1033 iEditorView->HandleCommandL (EImageEditorUpdateNavipane); |
|
1034 iEditorView->HandleCommandL (EImageEditorUpdateSoftkeys); |
|
1035 LoadIndicatorL ( |
|
1036 EMbmImageeditoruiQgn_indi_imed_resize_super, |
|
1037 EMbmImageeditoruiQgn_indi_imed_resize_super_mask |
|
1038 ); |
|
1039 ShowTooltip(); |
|
1040 } |
|
1041 |
|
1042 //============================================================================= |
|
1043 void CImageEditorBubbleControl::ToRotateStateL() |
|
1044 { |
|
1045 LOG(KBubblePluginLogFile, "CImageEditorBubbleControl::ToRotateStateL()"); |
|
1046 |
|
1047 iState = EInsertBubbleStateRotate; |
|
1048 iNaviPaneText.Copy ( iItem->Parameters()[KRotateBubbleIndex] ); |
|
1049 StoreTempParams(); |
|
1050 iEditorView->HandleCommandL (EImageEditorUpdateNavipane); |
|
1051 iEditorView->HandleCommandL (EImageEditorUpdateSoftkeys); |
|
1052 LoadIndicatorL ( |
|
1053 EMbmImageeditoruiQgn_indi_imed_rotate_left_super, |
|
1054 EMbmImageeditoruiQgn_indi_imed_rotate_left_super_mask |
|
1055 ); |
|
1056 ShowTooltip(); |
|
1057 } |
|
1058 |
|
1059 //============================================================================= |
|
1060 void CImageEditorBubbleControl::ToMainStateL() |
|
1061 { |
|
1062 |
|
1063 LOG(KBubblePluginLogFile, "CImageEditorBubbleControl::ToMainStateL()"); |
|
1064 |
|
1065 // Delete old indicator |
|
1066 delete iIndicator; |
|
1067 iIndicator = 0; |
|
1068 delete iIndicatorMask; |
|
1069 iIndicatorMask = 0; |
|
1070 |
|
1071 iState = EInsertBubbleStateMain; |
|
1072 iPopupController->HideInfoPopupNote(); |
|
1073 iNaviPaneText.Copy ( iItem->Parameters()[KMainBubbleIndex] ); |
|
1074 iEditorView->HandleCommandL (EImageEditorUpdateSoftkeys); |
|
1075 iEditorView->HandleCommandL (EImageEditorUpdateNavipane); |
|
1076 } |
|
1077 |
|
1078 //============================================================================= |
|
1079 void CImageEditorBubbleControl::StoreTempParams() |
|
1080 { |
|
1081 LOG(KBubblePluginLogFile, "CImageEditorBubbleControl::StoreTempParams()"); |
|
1082 iTempX = iX; |
|
1083 iTempY = iY; |
|
1084 iTempScale = iScale; |
|
1085 iTempAngle = iAngle; |
|
1086 } |
|
1087 |
|
1088 //============================================================================= |
|
1089 void CImageEditorBubbleControl::RestoreTempParams() |
|
1090 { |
|
1091 LOG(KBubblePluginLogFile, "CImageEditorBubbleControl::RestoreTempParams()"); |
|
1092 iX = iTempX; |
|
1093 iY = iTempY; |
|
1094 iScale = iTempScale; |
|
1095 iAngle = iTempAngle; |
|
1096 } |
|
1097 |
|
1098 //============================================================================= |
|
1099 void CImageEditorBubbleControl::GetHelpContext(TCoeHelpContext& aContext) const |
|
1100 { |
|
1101 aContext.iMajor = TUid::Uid(UID_IMAGE_EDITOR); |
|
1102 aContext.iContext = KSIE_HLP_EDIT_CLIPART; |
|
1103 } |
|
1104 |
|
1105 //============================================================================= |
|
1106 void CImageEditorBubbleControl::LoadIndicatorL ( |
|
1107 TInt aBitmapInd, |
|
1108 TInt aMaskInd |
|
1109 ) |
|
1110 { |
|
1111 LOG(KBubblePluginLogFile, "CImageEditorBubbleControl::LoadIndicatorL()"); |
|
1112 |
|
1113 // Delete old indicator |
|
1114 delete iIndicator; |
|
1115 iIndicator = 0; |
|
1116 delete iIndicatorMask; |
|
1117 iIndicatorMask = 0; |
|
1118 |
|
1119 SDrawUtils::GetIndicatorBitmapL ( |
|
1120 iIndicator, |
|
1121 iIndicatorMask, |
|
1122 aBitmapInd, |
|
1123 aMaskInd |
|
1124 ); |
|
1125 } |
|
1126 |
|
1127 //============================================================================= |
|
1128 TPoint CImageEditorBubbleControl::ComputeIndicatorPosition() const |
|
1129 { |
|
1130 LOG(KBubblePluginLogFile, "CImageEditorBubbleControl::ComputeIndicatorPosition()"); |
|
1131 |
|
1132 TInt x( 0 ); |
|
1133 TInt y( 0 ); |
|
1134 // check if there is no indicator |
|
1135 if ( !iIndicator ) |
|
1136 { |
|
1137 return TPoint ( x, y ); |
|
1138 } |
|
1139 |
|
1140 TRect vprect = iSysPars->VisibleImageRect(); |
|
1141 TRect vpprect = iSysPars->VisibleImageRectPrev(); |
|
1142 |
|
1143 TInt s = 0; |
|
1144 if (iScaleToHeight) |
|
1145 { |
|
1146 s = (iScale * vpprect.Height()) / vprect.Height(); |
|
1147 |
|
1148 } |
|
1149 else |
|
1150 { |
|
1151 s = (iScale * vpprect.Width()) / vprect.Width(); |
|
1152 } |
|
1153 |
|
1154 x = ((iX - vprect.iTl.iX)* vpprect.Width()) / vprect.Width(); |
|
1155 x += vpprect.iTl.iX; |
|
1156 x -= iIndicator->SizeInPixels().iWidth / 2; |
|
1157 x -= s / 2; |
|
1158 |
|
1159 y = ((iY - vprect.iTl.iY) * vpprect.Height()) / vprect.Height(); |
|
1160 y += vpprect.iTl.iY; |
|
1161 y -= iIndicator->SizeInPixels().iHeight / 2; |
|
1162 y += s / 2; |
|
1163 |
|
1164 LOGFMT (KBubblePluginLogFile, "ComputeIndicatorPosition --- (iX == %d)", iX); |
|
1165 LOGFMT (KBubblePluginLogFile, "ComputeIndicatorPosition --- (iY == %d)", iY); |
|
1166 LOGFMT (KBubblePluginLogFile, "ComputeIndicatorPosition --- (x == %d)", x); |
|
1167 LOGFMT (KBubblePluginLogFile, "ComputeIndicatorPosition --- (y == %d)", y); |
|
1168 |
|
1169 return TPoint (x,y); |
|
1170 } |
|
1171 |
|
1172 //============================================================================= |
|
1173 void CImageEditorBubbleControl::StoreParameters() |
|
1174 { |
|
1175 LOG(KBubblePluginLogFile, "CImageEditorBubbleControl::StoreParameters()"); |
|
1176 iParam.Copy (_L("x ")); |
|
1177 iParam.AppendNum (iX); |
|
1178 iParam.Append (_L(" y ")); |
|
1179 iParam.AppendNum (iY); |
|
1180 iParam.Append (_L(" angle ")); |
|
1181 iParam.AppendNum (iAngle); |
|
1182 |
|
1183 if ( iScaleToHeight ) |
|
1184 { |
|
1185 iParam.Append (_L(" height ")); |
|
1186 iParam.AppendNum (iScale); |
|
1187 } |
|
1188 else |
|
1189 { |
|
1190 iParam.Append (_L(" width ")); |
|
1191 iParam.AppendNum (iScale); |
|
1192 } |
|
1193 LOGDES(KBubblePluginLogFile, iParam); |
|
1194 } |
|
1195 |
|
1196 //============================================================================= |
|
1197 void CImageEditorBubbleControl::TimerCallBack() |
|
1198 { |
|
1199 LOGFMT(KBubblePluginLogFile, "CImageEditorBubbleControl::TimerCallBack() (iTickCount == %d)", iTickCount); |
|
1200 |
|
1201 if (iTickCount > KDefaultFastKeyTimerMultiplyThresholdInTicks) |
|
1202 { |
|
1203 LOG(KBubblePluginLogFile, "CImageEditorBubbleControl::TimerCallBack: switching to big steps"); |
|
1204 iNaviStepMultiplier = KDefaultBigNavigationStepMultiplier; |
|
1205 } |
|
1206 else |
|
1207 { |
|
1208 iTickCount++; |
|
1209 } |
|
1210 |
|
1211 if (iKeyCode) |
|
1212 { |
|
1213 |
|
1214 switch (iKeyCode) |
|
1215 { |
|
1216 case 1: |
|
1217 { |
|
1218 NaviUp(); |
|
1219 break; |
|
1220 } |
|
1221 case 2: |
|
1222 { |
|
1223 NaviDown(); |
|
1224 break; |
|
1225 } |
|
1226 case 3: |
|
1227 { |
|
1228 NaviLeft(); |
|
1229 break; |
|
1230 } |
|
1231 case 4: |
|
1232 { |
|
1233 NaviRight(); |
|
1234 break; |
|
1235 } |
|
1236 default: |
|
1237 break; |
|
1238 } |
|
1239 LOG(KBubblePluginLogFile, "\tTimerCallBack: Render..."); |
|
1240 StoreParameters(); |
|
1241 TRAP_IGNORE( iEditorView->HandleCommandL (EImageEditorCmdRender) ); |
|
1242 |
|
1243 iTimer->Call (KWait); |
|
1244 } |
|
1245 } |
|
1246 |
|
1247 //============================================================================= |
|
1248 void CImageEditorBubbleControl::StorePosAndScaleRelScreen() |
|
1249 { |
|
1250 |
|
1251 LOG(KBubblePluginLogFile, "CImageEditorBubbleControl::StorePosAndScaleRelScreen()"); |
|
1252 |
|
1253 TReal relscale = iSysPars->Scale(); |
|
1254 TRect virect = iSysPars->VisibleImageRect(); |
|
1255 virect.iTl.iX = (TInt)((virect.iTl.iX / relscale) + 0.5); |
|
1256 virect.iTl.iY = (TInt)((virect.iTl.iY / relscale) + 0.5); |
|
1257 virect.iBr.iX = (TInt)((virect.iBr.iX / relscale) + 0.5); |
|
1258 virect.iBr.iY = (TInt)((virect.iBr.iY / relscale) + 0.5); |
|
1259 |
|
1260 TInt viwidth = virect.iBr.iX - virect.iTl.iX; |
|
1261 TInt viheight = virect.iBr.iY - virect.iTl.iY; |
|
1262 |
|
1263 TRect viprect = iSysPars->VisibleImageRectPrev(); |
|
1264 |
|
1265 TInt vipwidth = viprect.iBr.iX - viprect.iTl.iX; |
|
1266 TInt vipheight = viprect.iBr.iY - viprect.iTl.iY; |
|
1267 |
|
1268 // Scale |
|
1269 TInt dimold_pix = (TInt)((iScale / relscale) + 0.5); |
|
1270 if ( iScaleToHeight ) |
|
1271 { |
|
1272 iScaleOld = (TReal)(dimold_pix * vipheight) / viheight; |
|
1273 } |
|
1274 else |
|
1275 { |
|
1276 iScaleOld = (TReal)(dimold_pix * vipwidth) / viwidth; |
|
1277 } |
|
1278 |
|
1279 // Position |
|
1280 TInt xCurrent = (TInt)((iX / relscale) + 0.5); |
|
1281 TInt yCurrent = (TInt)((iY / relscale) + 0.5); |
|
1282 iPosXOld = viprect.iTl.iX + (TReal)((xCurrent - virect.iTl.iX) * vipwidth) / viwidth; |
|
1283 iPosYOld = viprect.iTl.iY + (TReal)((yCurrent - virect.iTl.iY) * vipheight) / viheight; |
|
1284 |
|
1285 LOGFMT(KBubblePluginLogFile, "\tiPosXOld = %d", iPosXOld); |
|
1286 LOGFMT(KBubblePluginLogFile, "\tiPosYOld = %d", iPosYOld); |
|
1287 |
|
1288 iParam.Copy(_L("nop")); |
|
1289 |
|
1290 } |
|
1291 |
|
1292 //============================================================================= |
|
1293 void CImageEditorBubbleControl::RestorePosAndScaleRelScreen() |
|
1294 { |
|
1295 LOG(KBubblePluginLogFile, "CImageEditorBubbleControl::RestorePosAndScaleRelScreen()"); |
|
1296 |
|
1297 TReal relscale = iSysPars->Scale(); |
|
1298 |
|
1299 TRect virect = iSysPars->VisibleImageRect(); |
|
1300 virect.iTl.iX = (TInt)((virect.iTl.iX / relscale) + 0.5); |
|
1301 virect.iTl.iY = (TInt)((virect.iTl.iY / relscale) + 0.5); |
|
1302 virect.iBr.iX = (TInt)((virect.iBr.iX / relscale) + 0.5); |
|
1303 virect.iBr.iY = (TInt)((virect.iBr.iY / relscale) + 0.5); |
|
1304 |
|
1305 TInt viwidth = virect.iBr.iX - virect.iTl.iX; |
|
1306 TInt viheight = virect.iBr.iY - virect.iTl.iY; |
|
1307 |
|
1308 TRect viprect = iSysPars->VisibleImageRectPrev(); |
|
1309 TInt vipwidth = viprect.iBr.iX - viprect.iTl.iX; |
|
1310 TInt vipheight = viprect.iBr.iY - viprect.iTl.iY; |
|
1311 |
|
1312 // Scale |
|
1313 if (iScaleToHeight) |
|
1314 { |
|
1315 iScale = (TInt)((iScaleOld * viheight) / vipheight + 0.5); |
|
1316 } |
|
1317 else |
|
1318 { |
|
1319 iScale = (TInt)((iScaleOld * viwidth) / vipwidth + 0.5); |
|
1320 } |
|
1321 iScale = (TInt)(iScale * relscale + 0.5); |
|
1322 |
|
1323 // Position |
|
1324 iX = (TInt)(virect.iTl.iX + (TReal)((iPosXOld - viprect.iTl.iX) * viwidth) / vipwidth + 0.5); |
|
1325 iY = (TInt)(virect.iTl.iY + (TReal)((iPosYOld - viprect.iTl.iY) * viheight) / vipheight + 0.5); |
|
1326 |
|
1327 } |
|
1328 |
|
1329 //============================================================================= |
|
1330 void CImageEditorBubbleControl::StorePosAndScaleRelImage() |
|
1331 { |
|
1332 LOG(KBubblePluginLogFile, "CImageEditorBubbleControl::StorePosAndScaleRelImage()"); |
|
1333 |
|
1334 TReal relscale = iSysPars->RelScale(); |
|
1335 |
|
1336 iPosXOld = (TInt)((iX / relscale) + 0.5); |
|
1337 iPosYOld = (TInt)((iY / relscale) + 0.5); |
|
1338 iScaleOld = (TInt)(iScale / relscale + 0.5); |
|
1339 |
|
1340 iParam.Copy(_L("nop")); |
|
1341 } |
|
1342 |
|
1343 //============================================================================= |
|
1344 void CImageEditorBubbleControl::RestorePosAndScaleRelImage() |
|
1345 { |
|
1346 LOG(KBubblePluginLogFile, "CImageEditorBubbleControl::RestorePosAndScaleRelImage()"); |
|
1347 |
|
1348 TReal relscale = iSysPars->RelScale(); |
|
1349 |
|
1350 iX = (TInt)(iPosXOld * relscale + 0.5); |
|
1351 iY = (TInt)(iPosYOld * relscale + 0.5); |
|
1352 iScale = TInt(iScaleOld * relscale + 0.5); |
|
1353 } |
|
1354 |
|
1355 //============================================================================= |
|
1356 void CImageEditorBubbleControl::ClipPosition() |
|
1357 { |
|
1358 if ( iX < iSysPars->VisibleImageRect().iTl.iX ) |
|
1359 { |
|
1360 iX = iSysPars->VisibleImageRect().iTl.iX; |
|
1361 } |
|
1362 else if ( iX > iSysPars->VisibleImageRect().iBr.iX ) |
|
1363 { |
|
1364 iX = iSysPars->VisibleImageRect().iBr.iX; |
|
1365 } |
|
1366 |
|
1367 if ( iY < iSysPars->VisibleImageRect().iTl.iY ) |
|
1368 { |
|
1369 iY = iSysPars->VisibleImageRect().iTl.iY; |
|
1370 } |
|
1371 else if ( iY > iSysPars->VisibleImageRect().iBr.iY ) |
|
1372 { |
|
1373 iY = iSysPars->VisibleImageRect().iBr.iY; |
|
1374 } |
|
1375 } |
|
1376 |
|
1377 //============================================================================= |
|
1378 void CImageEditorBubbleControl::HandlePointerEventL( |
|
1379 const TPointerEvent &aPointerEvent) |
|
1380 { |
|
1381 if( AknLayoutUtils::PenEnabled() ) |
|
1382 { |
|
1383 // If busy, do not handle anything |
|
1384 if ( Busy() ) |
|
1385 { |
|
1386 return; |
|
1387 } |
|
1388 |
|
1389 TBool render = ETrue; |
|
1390 switch( aPointerEvent.iType ) |
|
1391 { |
|
1392 case TPointerEvent::EButton1Down: |
|
1393 { |
|
1394 if ( iState == EInsertBubbleStateMove ) |
|
1395 { |
|
1396 iPopupController->HideInfoPopupNote(); |
|
1397 SetBubblePosition( aPointerEvent.iPosition ); |
|
1398 } |
|
1399 else if ( iState == EInsertBubbleStateRotate ) |
|
1400 { |
|
1401 iPopupController->HideInfoPopupNote(); |
|
1402 // Store current position. Rotating is handled in drag-event |
|
1403 // is pen position has changed |
|
1404 iPointerPosition = aPointerEvent.iPosition; |
|
1405 } |
|
1406 else if ( iState == EInsertBubbleStateResize ) |
|
1407 { |
|
1408 iPopupController->HideInfoPopupNote(); |
|
1409 iPointerPosition = aPointerEvent.iPosition; |
|
1410 } |
|
1411 #ifdef RD_TACTILE_FEEDBACK |
|
1412 if ( iTouchFeedBack ) |
|
1413 { |
|
1414 iTouchFeedBack->InstantFeedback( ETouchFeedbackBasic ); |
|
1415 RDebug::Printf( "ImageEditor::ImageEditorBubbleControl: ETouchFeedback" ); |
|
1416 } |
|
1417 #endif /* RD_TACTILE_FEEDBACK */ |
|
1418 |
|
1419 break; |
|
1420 } |
|
1421 case TPointerEvent::EDrag: |
|
1422 { |
|
1423 if ( iState == EInsertBubbleStateMove ) |
|
1424 { |
|
1425 SetBubblePosition( aPointerEvent.iPosition ); |
|
1426 iPointerPosition = aPointerEvent.iPosition; |
|
1427 TRect clientRect; |
|
1428 CResolutionUtil::Self()->GetClientRect( clientRect ); |
|
1429 TPoint tempPoint = iPointerPosition; |
|
1430 tempPoint.iY += iY; |
|
1431 if ( !clientRect.Contains( tempPoint ) ) |
|
1432 { |
|
1433 ShowTooltip(); |
|
1434 } |
|
1435 } |
|
1436 else if ( iState == EInsertBubbleStateRotate ) |
|
1437 { |
|
1438 if ( CalculateRotation( iPointerPosition, |
|
1439 aPointerEvent.iPosition ) ) |
|
1440 { |
|
1441 // store current position for next round |
|
1442 iPointerPosition = aPointerEvent.iPosition; |
|
1443 } |
|
1444 else |
|
1445 { |
|
1446 render = EFalse; |
|
1447 } |
|
1448 } |
|
1449 else if ( iState == EInsertBubbleStateResize ) |
|
1450 { |
|
1451 if ( CalculateResize( iPointerPosition, |
|
1452 aPointerEvent.iPosition ) ) |
|
1453 { |
|
1454 // store current position for next round |
|
1455 iPointerPosition = aPointerEvent.iPosition; |
|
1456 } |
|
1457 else |
|
1458 { |
|
1459 render = EFalse; |
|
1460 } |
|
1461 } |
|
1462 |
|
1463 break; |
|
1464 } |
|
1465 case TPointerEvent::EButton1Up: |
|
1466 { |
|
1467 if ( iState == EInsertBubbleStateMain ) |
|
1468 { |
|
1469 // Show context sensitive menu |
|
1470 iEditorView->HandleCommandL( EImageEditorOpenContextMenu ); |
|
1471 } |
|
1472 else |
|
1473 { |
|
1474 ShowTooltip(); |
|
1475 } |
|
1476 break; |
|
1477 } |
|
1478 |
|
1479 default: |
|
1480 { |
|
1481 break; |
|
1482 } |
|
1483 } |
|
1484 |
|
1485 StoreParameters(); |
|
1486 |
|
1487 if ( render ) |
|
1488 { |
|
1489 TRAP_IGNORE( iEditorView->HandleCommandL (EImageEditorCmdRender) ); |
|
1490 } |
|
1491 |
|
1492 CCoeControl::HandlePointerEventL( aPointerEvent ); |
|
1493 |
|
1494 } |
|
1495 } |
|
1496 |
|
1497 //============================================================================= |
|
1498 void CImageEditorBubbleControl::SetBubblePosition( TPoint aPointedPosition ) |
|
1499 { |
|
1500 |
|
1501 // Get system parameters |
|
1502 TRect visibleImageRect( iSysPars->VisibleImageRect() ); |
|
1503 TRect visibleImageRectPrev( iSysPars->VisibleImageRectPrev() ); |
|
1504 |
|
1505 TInt xPosFactorDivider |
|
1506 ( visibleImageRectPrev.iBr.iX - visibleImageRectPrev.iTl.iX ); |
|
1507 TInt yPosFactorDivider |
|
1508 ( visibleImageRectPrev.iBr.iY - visibleImageRectPrev.iTl.iY ); |
|
1509 |
|
1510 // Dividing by zero will cause panic -> check |
|
1511 if ( xPosFactorDivider == 0 || yPosFactorDivider == 0 ) |
|
1512 { |
|
1513 // Set default position |
|
1514 iX = (visibleImageRect.iTl.iX + visibleImageRect.iBr.iX) / 2; |
|
1515 iY = (visibleImageRect.iTl.iY + visibleImageRect.iBr.iY) / 2; |
|
1516 } |
|
1517 else |
|
1518 { |
|
1519 // Calculate relative position on the screen |
|
1520 TReal xPositionFactor |
|
1521 ( TReal( aPointedPosition.iX - visibleImageRectPrev.iTl.iX ) / |
|
1522 xPosFactorDivider ); |
|
1523 |
|
1524 TReal yPositionFactor |
|
1525 ( TReal( aPointedPosition.iY - visibleImageRectPrev.iTl.iY ) / |
|
1526 yPosFactorDivider ); |
|
1527 |
|
1528 // Calculate position on visible image |
|
1529 iX = visibleImageRect.iTl.iX + |
|
1530 ( visibleImageRect.iBr.iX - visibleImageRect.iTl.iX ) * |
|
1531 xPositionFactor; |
|
1532 |
|
1533 iY = visibleImageRect.iTl.iY + |
|
1534 ( visibleImageRect.iBr.iY - visibleImageRect.iTl.iY ) * |
|
1535 yPositionFactor; |
|
1536 } |
|
1537 |
|
1538 // Check that not out of bounds |
|
1539 ClipPosition(); |
|
1540 |
|
1541 } |
|
1542 |
|
1543 //============================================================================= |
|
1544 void CImageEditorBubbleControl::ShowTooltip() |
|
1545 { |
|
1546 iPopupController->HideInfoPopupNote(); |
|
1547 |
|
1548 if ( iState != EInsertBubbleStateMove && |
|
1549 iState != EInsertBubbleStateResize && |
|
1550 iState != EInsertBubbleStateRotate ) |
|
1551 { |
|
1552 return; |
|
1553 } |
|
1554 |
|
1555 TPoint iconPosition = ComputeIndicatorPosition(); |
|
1556 |
|
1557 if ( iState == EInsertBubbleStateMove ) |
|
1558 { |
|
1559 SDrawUtils::ShowToolTip( iPopupController, |
|
1560 this, |
|
1561 iconPosition, |
|
1562 EHRightVBottom, |
|
1563 *iTooltipMove ); |
|
1564 } |
|
1565 // resize |
|
1566 else if ( iState == EInsertBubbleStateResize ) |
|
1567 { |
|
1568 SDrawUtils::ShowToolTip( iPopupController, |
|
1569 this, |
|
1570 iconPosition, |
|
1571 EHRightVBottom, |
|
1572 *iTooltipResize ); |
|
1573 } |
|
1574 // rotate |
|
1575 else if ( iState == EInsertBubbleStateRotate ) |
|
1576 { |
|
1577 SDrawUtils::ShowToolTip( iPopupController, |
|
1578 this, |
|
1579 iconPosition, |
|
1580 EHRightVBottom, |
|
1581 *iTooltipRotate ); |
|
1582 } |
|
1583 |
|
1584 } |
|
1585 |
|
1586 //============================================================================= |
|
1587 TBool CImageEditorBubbleControl::CalculateResize( TPoint aStartPoint, |
|
1588 TPoint aEndPoint ) |
|
1589 { |
|
1590 // Whether bubble is resized in this function or not |
|
1591 TBool bubbleResized( EFalse ); |
|
1592 // Store old scale value |
|
1593 TInt oldScale = iScale; |
|
1594 |
|
1595 // Get system parameters |
|
1596 TRect visibleImageRectPrev( iSysPars->VisibleImageRectPrev() ); |
|
1597 |
|
1598 // Compute change on the screen |
|
1599 TInt deltaX = aEndPoint.iX - aStartPoint.iX; |
|
1600 TInt deltaY = aEndPoint.iY - aStartPoint.iY; |
|
1601 |
|
1602 // Use bigger dimension |
|
1603 TInt maxChangeInPixels; |
|
1604 if ( visibleImageRectPrev.Height() > visibleImageRectPrev.Width() ) |
|
1605 { |
|
1606 maxChangeInPixels = visibleImageRectPrev.Height(); |
|
1607 } |
|
1608 else |
|
1609 { |
|
1610 maxChangeInPixels = visibleImageRectPrev.Width(); |
|
1611 } |
|
1612 |
|
1613 TInt oneStepInPixels = maxChangeInPixels / KTouchScaleMaxStepCount; |
|
1614 TInt scaleStep = ( iScaleMax - iScaleMin ) / KTouchScaleMaxStepCount + 1; |
|
1615 |
|
1616 // Relates to second and fourth corners. Defines how steep/gentle the |
|
1617 // moving angle has to be in order to scale. |
|
1618 TInt slopeAngleFactor = 3; |
|
1619 |
|
1620 // The first quarter (movement towards upper-right corner) |
|
1621 if( ( deltaX > 0 && deltaY <= 0 ) || ( deltaX >= 0 && deltaY < 0 ) ) |
|
1622 { |
|
1623 // use bigger value |
|
1624 if (Abs( deltaX ) >= Abs( deltaY) ) |
|
1625 { |
|
1626 iScale += scaleStep * ( Abs( deltaX ) / oneStepInPixels ); |
|
1627 } |
|
1628 else |
|
1629 { |
|
1630 iScale += scaleStep * ( Abs( deltaY ) / oneStepInPixels ); |
|
1631 } |
|
1632 } |
|
1633 // The second (movement towards lower-right corner) |
|
1634 else if( ( deltaX > 0 && deltaY >= 0 ) || ( deltaX >= 0 && deltaY > 0 ) ) |
|
1635 { |
|
1636 if( deltaX > slopeAngleFactor * deltaY ) |
|
1637 { |
|
1638 iScale += scaleStep * ( Abs( deltaX ) / oneStepInPixels ); |
|
1639 } |
|
1640 |
|
1641 else if ( slopeAngleFactor * deltaX < deltaY ) |
|
1642 { |
|
1643 iScale -= scaleStep * ( Abs( deltaY ) / oneStepInPixels ); |
|
1644 } |
|
1645 } |
|
1646 // The third (movement towards lower-left corner) |
|
1647 else if( ( deltaX < 0 && deltaY >= 0 ) || ( deltaX <= 0 && deltaY > 0 ) ) |
|
1648 { |
|
1649 if (Abs( deltaX ) >= Abs( deltaY) ) |
|
1650 { |
|
1651 iScale -= scaleStep * ( Abs( deltaX ) / oneStepInPixels ); |
|
1652 } |
|
1653 else |
|
1654 { |
|
1655 iScale -= scaleStep * ( Abs( deltaY ) / oneStepInPixels ); |
|
1656 } |
|
1657 } |
|
1658 // The fourth (movement towards upper-left corner) |
|
1659 else if( ( deltaX < 0 && deltaY <= 0 ) || ( deltaX <= 0 && deltaY < 0 ) ) |
|
1660 { |
|
1661 if( slopeAngleFactor * Abs( deltaX ) < Abs( deltaY ) ) |
|
1662 { |
|
1663 iScale += scaleStep * ( Abs( deltaY ) / oneStepInPixels ); |
|
1664 } |
|
1665 else if ( Abs( deltaX ) > slopeAngleFactor * Abs( deltaY ) ) |
|
1666 { |
|
1667 iScale -= scaleStep * ( Abs( deltaX ) / oneStepInPixels ); |
|
1668 } |
|
1669 } |
|
1670 |
|
1671 // Check the limits |
|
1672 if (iScale > iScaleMax) |
|
1673 { |
|
1674 iScale = iScaleMax; |
|
1675 bubbleResized = ETrue; |
|
1676 } |
|
1677 if (iScale < iScaleMin) |
|
1678 { |
|
1679 iScale = iScaleMin; |
|
1680 bubbleResized = ETrue; |
|
1681 } |
|
1682 |
|
1683 if ( oldScale != iScale ) |
|
1684 { |
|
1685 bubbleResized = ETrue; |
|
1686 } |
|
1687 |
|
1688 return bubbleResized; |
|
1689 |
|
1690 } |
|
1691 |
|
1692 //============================================================================= |
|
1693 TBool CImageEditorBubbleControl::CalculateRotation( TPoint aStartPoint, |
|
1694 TPoint aEndPoint ) |
|
1695 { |
|
1696 TBool angleChanged( EFalse ); |
|
1697 TInt oldAngle = iAngle; |
|
1698 |
|
1699 // Get system parameters |
|
1700 TRect visibleImageRect( iSysPars->VisibleImageRect() ); |
|
1701 TRect visibleImageRectPrev( iSysPars->VisibleImageRectPrev() ); |
|
1702 |
|
1703 // Calculate TalkBubble real center point on the screen |
|
1704 // (physical coordinates) |
|
1705 TReal posFactorX( TReal( iX - visibleImageRect.iTl.iX ) / |
|
1706 visibleImageRect.Width() ); |
|
1707 TInt bubbleCenterX = posFactorX * visibleImageRectPrev.Width() + |
|
1708 visibleImageRectPrev.iTl.iX; |
|
1709 |
|
1710 TReal posFactorY( TReal( iY - visibleImageRect.iTl.iY ) / |
|
1711 visibleImageRect.Height() ); |
|
1712 TInt bubbleCenterY = posFactorY * visibleImageRectPrev.Height() + |
|
1713 visibleImageRectPrev.iTl.iY; |
|
1714 |
|
1715 // Calculate start and end positions of the movement assuming that |
|
1716 // clipart centre is in origo. |
|
1717 // Note! y-axis is mirrored on screen coordinates compared to standard 2-d |
|
1718 // co-ordinates->mirror y-axis to ease the calculation |
|
1719 TPoint startPos( ( aStartPoint.iX - bubbleCenterX ), |
|
1720 ( bubbleCenterY - aStartPoint.iY ) ); |
|
1721 TPoint endPos( ( aEndPoint.iX - bubbleCenterX ), |
|
1722 ( bubbleCenterY - aEndPoint.iY ) ); |
|
1723 |
|
1724 TReal angleInRadStart; |
|
1725 TReal angleInRadEnd; |
|
1726 |
|
1727 // Calculate start and end angles in radians |
|
1728 TInt err1 = Math::ATan( angleInRadStart, startPos.iY, startPos.iX ); |
|
1729 TInt err2 = Math::ATan( angleInRadEnd, endPos.iY, endPos.iX ); |
|
1730 |
|
1731 if( !err1 && !err2 ) |
|
1732 { |
|
1733 // Calculate change in angle and convert it to degrees |
|
1734 TReal changeInDegrees = |
|
1735 ( angleInRadEnd - angleInRadStart ) * KRadToDeg; |
|
1736 |
|
1737 iAngle -= ( KDegreeMultiplier * TInt( changeInDegrees ) ) |
|
1738 % KAngleParamMax; |
|
1739 } |
|
1740 |
|
1741 if ( iAngle != oldAngle ) |
|
1742 { |
|
1743 angleChanged = ETrue; |
|
1744 } |
|
1745 |
|
1746 return angleChanged; |
|
1747 } |
|
1748 |
|
1749 // End of file |
|
1750 |