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