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