imageeditor/plugins/ClipartPlugin/inc/ImageEditorClipartControl.h
changeset 1 edfc90759b9f
equal deleted inserted replaced
0:57d4cdd99204 1:edfc90759b9f
       
     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 #ifndef IMAGEEDITORCROPCONTROL_H
       
    22 #define IMAGEEDITORCROPCONTROL_H
       
    23 
       
    24 //  INCLUDES
       
    25 #include <coecntrl.h>
       
    26 #include <eiklbo.h>
       
    27 #include <coecobs.h>
       
    28 #include <ConeResLoader.h>
       
    29 
       
    30 #include "PreviewControlBase.h"
       
    31 #include "MTimerCallBack.h"
       
    32 #include "ClipartSelectionDialog.h"
       
    33 
       
    34 //  FORWARD DECLARATIONS
       
    35 class CAknView;
       
    36 class CFbsBitmap;
       
    37 class CPluginInfo;
       
    38 class CSystemParameters;
       
    39 class CClipartSelectionGrid;
       
    40 class CJPTimer;
       
    41 class CAknInfoPopupNoteController; 
       
    42 
       
    43 #ifdef RD_TACTILE_FEEDBACK 
       
    44 class MTouchFeedback;
       
    45 #endif /* RD_TACTILE_FEEDBACK  */
       
    46 
       
    47 /*	CLASS: CImageEditorClipartControl
       
    48 *
       
    49 *   CImageEditorClipartControl is a control for clipart insertion plug-in.
       
    50 *
       
    51 */
       
    52 class CImageEditorClipartControl : public CPreviewControlBase,
       
    53                                    public MCoeControlObserver,  
       
    54                                    public MEikListBoxObserver,
       
    55                                    public MTimerCallBack
       
    56                                    
       
    57 {
       
    58 
       
    59 public:
       
    60 
       
    61 /** @name Methods:*/
       
    62 //@{
       
    63 
       
    64 	/** NewL factory method, pops cleanupstack
       
    65 	*
       
    66 	*	@param aRect - control rectangle
       
    67 	*	@param aParent - pointer to window owning control
       
    68 	*	@return pointer to created CImageEditorClipartControl object
       
    69 	*/
       
    70 	static CImageEditorClipartControl * NewL (
       
    71 		const TRect &		aRect,
       
    72 		CCoeControl	*		aParent
       
    73 		);
       
    74 
       
    75 	/** Destructor
       
    76 	*
       
    77 	*	@param -
       
    78 	*	@return -
       
    79 	*/
       
    80 	virtual ~CImageEditorClipartControl ();
       
    81 
       
    82 	/** Second phase constructor
       
    83 	*
       
    84 	*	@see CImageEditorControlBase
       
    85 	*
       
    86     */
       
    87 	virtual void ConstructL (
       
    88 		const TRect &		aRect,
       
    89 		CCoeControl	*		aParent
       
    90 		);
       
    91 
       
    92 	/*	Setter for view reference
       
    93 	*
       
    94 	*	@see CImageEditorControlBase
       
    95 	*
       
    96     */
       
    97     virtual void SetView (CAknView * aView);
       
    98 
       
    99     /*	SetSelectedUiItem
       
   100 	*
       
   101 	*	@see CImageEditorControlBase
       
   102 	*
       
   103     */
       
   104     virtual void SetSelectedUiItemL (CPluginInfo * aItem);
       
   105 
       
   106 	/** PrepareL
       
   107 	*
       
   108 	*	@see CImageEditorControlBase
       
   109 	*
       
   110     */
       
   111 	virtual void PrepareL ();
       
   112 
       
   113     /*	OfferKeyEventL
       
   114 	*
       
   115 	*	@see CImageEditorControlBase
       
   116 	*
       
   117     */
       
   118     virtual TKeyResponse OfferKeyEventL (
       
   119         const TKeyEvent &   aKeyEvent,
       
   120         TEventCode          aType
       
   121         );   
       
   122 
       
   123 	/*	HandlePluginCommandL
       
   124 	*
       
   125 	*	@see CImageEditorControlBase
       
   126 	*
       
   127     */
       
   128     virtual void HandlePluginCommandL (const TInt aCommand);
       
   129 
       
   130 	/*	GetSoftkeyIndexL
       
   131 	*
       
   132 	*	@see CImageEditorControlBase
       
   133     */
       
   134     virtual TInt GetSoftkeyIndexL();
       
   135     
       
   136     /*	GetContextMenuResourceId
       
   137 	*
       
   138 	*	@see CImageEditorControlBase
       
   139 	*/
       
   140     virtual TInt GetContextMenuResourceId();
       
   141 
       
   142 	/*	GetDimmedMenuItems
       
   143 	*
       
   144 	*	@see CImageEditorControlBase
       
   145 	*/
       
   146 	virtual TBitField GetDimmedMenuItems();
       
   147     
       
   148 	/*	GetNaviPaneTextL
       
   149 	*
       
   150 	*	@see CImageEditorControlBase
       
   151 	*/
       
   152 	virtual TPtrC GetNaviPaneTextL (
       
   153 		TBool& aLeftNaviPaneScrollButtonVisibile, 
       
   154 		TBool& aRightNaviPaneScrollButtonVisible);
       
   155 
       
   156 	/*	GetParam
       
   157 	*
       
   158 	*	Gets pointer to the parameter struct.
       
   159 	*
       
   160 	*	@param -
       
   161 	*	@return - pointer to MIA parameter struct
       
   162 	*/
       
   163     TDesC & GetParam ();
       
   164 
       
   165 	/*	SetSysteParameters
       
   166 	*
       
   167 	*	Sets reference to system parameters to plug-in.
       
   168 	*
       
   169 	*	@param aSysPars - System parameters instance
       
   170 	*	@return - 
       
   171 	*/
       
   172     void SetSystemParameters (const CSystemParameters * aSysPars);
       
   173 
       
   174 	/**	IsReadyToRender
       
   175 	*
       
   176     *   Return ETrue if all parameters have valid value and filter
       
   177     *   can be rendered.
       
   178 	*
       
   179 	*	@param -
       
   180 	*	@return - ETrue if ready to render, otherwise EFalse
       
   181 	*/
       
   182     TBool IsReadyToRender() const;
       
   183 
       
   184     /*	GetHelpContext
       
   185 	*
       
   186 	*	@see CCoeControl
       
   187 	*
       
   188     */
       
   189 	virtual void GetHelpContext(TCoeHelpContext& aContext) const;
       
   190 
       
   191     /*	TimerCallBack
       
   192 	*
       
   193 	*	@see MTimerCallBack
       
   194 	*
       
   195     */
       
   196 	virtual void TimerCallBack();
       
   197 
       
   198 //@}
       
   199 
       
   200 protected:
       
   201 
       
   202 /** @name Methods:*/
       
   203 //@{
       
   204 
       
   205 	/*	HandleListBoxEventL
       
   206 	*
       
   207 	*	@see CImageEditorControlBase
       
   208 	*
       
   209     */
       
   210     void HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType);
       
   211 
       
   212 	/*	HandleControlEventL
       
   213 	*
       
   214 	*	@see CImageEditorControlBase
       
   215 	*
       
   216     */
       
   217     void HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType);
       
   218 
       
   219 	/*	SetBitmapL
       
   220 	*
       
   221 	*	Sets clip-art bitmap to filter paramerters object
       
   222 	*
       
   223     */
       
   224     void SetBitmapL();
       
   225 
       
   226 	/*	SetBusy
       
   227 	*
       
   228 	*	@see CImageEditorControlBase
       
   229 	*
       
   230     */
       
   231     void SetBusy();
       
   232 
       
   233     /*	ResetBusy
       
   234 	*
       
   235 	*	@see CImageEditorControlBase
       
   236 	*
       
   237     */
       
   238     void ResetBusy();
       
   239     
       
   240     /*	HandlePointerEventL
       
   241 	*
       
   242 	*	@see CImageEditorControlBase
       
   243 	*
       
   244     */
       
   245 	virtual void HandlePointerEventL( const TPointerEvent &aPointerEvent );
       
   246 
       
   247 
       
   248 //@}
       
   249 
       
   250 /** @name Members:*/
       
   251 //@{
       
   252 
       
   253 //@}
       
   254 
       
   255 private:
       
   256 
       
   257 /** @name Methods:*/
       
   258 //@{
       
   259 
       
   260 	/** Default constructor
       
   261 	*
       
   262 	*	@param -
       
   263 	*	@return -
       
   264 	*/
       
   265 	CImageEditorClipartControl ();
       
   266 
       
   267 	/**	Draw
       
   268 	*
       
   269 	*	@see CImageEditorControlBase
       
   270 	*
       
   271     */
       
   272 	virtual void Draw (const TRect & aRect) const;
       
   273 
       
   274 	/**	NaviDown
       
   275 	*
       
   276 	*	Handles navi key down event.
       
   277 	*
       
   278 	*	@param -
       
   279 	*	@return -
       
   280 	*/
       
   281     void NaviDown();
       
   282 
       
   283 	/**	NaviUp
       
   284 	*
       
   285 	*	Handles nave key up event.
       
   286 	*
       
   287 	*	@param -
       
   288 	*	@return -
       
   289 	*/
       
   290     void NaviUp();
       
   291 
       
   292 	/**	NaviRight
       
   293 	*
       
   294 	*	Handles nave key right event.
       
   295 	*
       
   296 	*	@param -
       
   297 	*	@return -
       
   298 	*/
       
   299     void NaviRight();
       
   300 
       
   301 	/**	NaviLeft
       
   302 	*
       
   303 	*	Handles nave key left event.
       
   304 	*
       
   305 	*	@param -
       
   306 	*	@return -
       
   307 	*/
       
   308     void NaviLeft();
       
   309 
       
   310 	/**	ToMoveState
       
   311 	*
       
   312     *   Handles transition to Move state.
       
   313 	*
       
   314 	*	@param -
       
   315 	*	@return -
       
   316 	*/
       
   317     void ToMoveStateL();
       
   318 
       
   319 	/**	ToResizeState
       
   320 	*
       
   321     *   Handles transition to Resize state.
       
   322 	*
       
   323 	*	@param -
       
   324 	*	@return -
       
   325 	*/
       
   326     void ToResizeStateL();
       
   327 
       
   328 	/**	ToRotateState
       
   329 	*
       
   330     *   Handles transition to Rotate state.
       
   331 	*
       
   332 	*	@param -
       
   333 	*	@return -
       
   334 	*/
       
   335     void ToRotateStateL();
       
   336 
       
   337 	/**	ToMainStateL
       
   338 	*
       
   339     *   Handles transition to Main state.
       
   340 	*
       
   341 	*	@param -
       
   342 	*	@return -
       
   343 	*/
       
   344     void ToMainStateL();
       
   345   
       
   346     /**	StoreTempParams
       
   347 	*
       
   348     *   Store all parameters to temp variables.
       
   349 	*
       
   350 	*	@param -
       
   351 	*	@return -
       
   352 	*/
       
   353     void StoreTempParams();
       
   354 
       
   355     /**	RestoreTempParams
       
   356 	*
       
   357     *   Restore parameters from temp variables.
       
   358 	*
       
   359 	*	@param -
       
   360 	*	@return -
       
   361 	*/
       
   362     void RestoreTempParams();
       
   363 
       
   364     /**	SelectClipartL
       
   365 	*
       
   366 	*	Select clipart and set to the parameter object
       
   367 	*
       
   368 	*	@param -
       
   369 	*	@return -
       
   370 	*/
       
   371     void SelectClipartL();
       
   372 
       
   373 	/**	LoadIndicatorL
       
   374 	*
       
   375 	*	Loads indicator.
       
   376 	*
       
   377 	*	@param aBitmapInd - indicator bitmap MBM index
       
   378 	*	@param aMaskInd - indicator mask MBM index
       
   379 	*	@return -
       
   380 	*/
       
   381     void LoadIndicatorL (
       
   382         TInt    aBitmapInd,
       
   383         TInt    aMaskInd
       
   384         );
       
   385 
       
   386 	/**	ComputeIndicatorPosition
       
   387 	*
       
   388 	*	Computes indicator position.
       
   389 	*
       
   390 	*	@param -
       
   391 	*	@return -
       
   392 	*/
       
   393     TPoint ComputeIndicatorPosition() const;
       
   394 
       
   395 	/**	StoreParameters
       
   396 	*
       
   397 	*	Stores parameters to command line.
       
   398 	*
       
   399 	*	@param -
       
   400 	*	@return -
       
   401 	*/
       
   402 	void StoreParameters();
       
   403 
       
   404 
       
   405 	/**	StorePosAndScaleRelScreen
       
   406 	*
       
   407 	*	Stores clipart position and scale relative to
       
   408 	*	screen.
       
   409 	*
       
   410 	*	@param -
       
   411 	*	@return -
       
   412 	*/
       
   413 	void StorePosAndScaleRelScreen();
       
   414 
       
   415 	/**	RestorePosAndScaleRelScreen
       
   416 	*
       
   417 	*	Restores clipart position and scale relative to
       
   418 	*	screen.
       
   419 	*
       
   420 	*	@param -
       
   421 	*	@return -
       
   422 	*/
       
   423 	void RestorePosAndScaleRelScreen();
       
   424 
       
   425 	/**	StorePosAndScaleRelImage
       
   426 	*
       
   427 	*	Stores scale and pan
       
   428 	*
       
   429 	*	@param -
       
   430 	*	@return -
       
   431 	*/
       
   432 	void StorePosAndScaleRelImage();
       
   433 
       
   434 	/**	RestorePosAndScaleRelImage
       
   435 	*
       
   436 	*	Stores scale and pan
       
   437 	*
       
   438 	*	@param -
       
   439 	*	@return -
       
   440 	*/
       
   441 	void RestorePosAndScaleRelImage();
       
   442 
       
   443 	/**	ClipPosition
       
   444 	*
       
   445 	*	Clips clipart position after screen mode change.
       
   446 	*
       
   447 	*	@param -
       
   448 	*	@return -
       
   449 	*/
       
   450 	void ClipPosition();
       
   451     
       
   452     /**	SetClipPosition
       
   453 	*
       
   454 	*	Sets current clipart to a new position
       
   455 	*
       
   456 	*	@param - aPointedPosition Middle point position on the screen where 
       
   457 	*                             clip art should should be moved
       
   458 	*	@return -
       
   459 	*/
       
   460     void SetClipPosition( TPoint aPointedPosition );
       
   461     
       
   462     /** ShowTooltip
       
   463     *
       
   464     *   Show tooltip text on the screen. Tooltip text is set based 
       
   465     *   on the current state.
       
   466     *
       
   467     *   @param -
       
   468     *   @return -
       
   469     */
       
   470     void ShowTooltip();
       
   471     
       
   472     /** CalculateResize
       
   473     *
       
   474     *   Function is used to calculate a new scale value when clipart is resized
       
   475     *   with touch. The value is calculated based on dragging start
       
   476     *   and end points. This function also changes scale variable member after
       
   477     *   calculation.
       
   478     *
       
   479     *   @param - aStartPoint - A position where dragging started
       
   480     *   @param - aEndPoint - A position where dragging ended
       
   481     *   @return - TBool - ETrue if scale value is changed in the function
       
   482     */
       
   483     TBool CalculateResize( TPoint aStartPoint, TPoint aEndPoint );
       
   484     
       
   485     /** CalculateRotation
       
   486     *
       
   487     *   Function is used to calculate rotation when clipart is rotated
       
   488     *   with touch. Needed rotation is calculated based on dragging start
       
   489     *   and end points. This function also changes rotation variables after
       
   490     *   calculation.
       
   491     *
       
   492     *   @param - aStartPoint - A position where dragging started
       
   493     *   @param - aEndPoint - A position where dragging ended
       
   494     *   @return - TBool - ETrue if rotate value is changed in the function
       
   495     */
       
   496     TBool CalculateRotation( TPoint aStartPoint, TPoint aEndPoint );
       
   497     
       
   498 //@}
       
   499 
       
   500 /** @name Typedefs:*/
       
   501 //@{
       
   502     enum TInsertClipartState
       
   503     {
       
   504         //  Invalid
       
   505         EInsertClipartStateMin      = 0,
       
   506         //  Select clipart
       
   507         EInsertClipartStateSelect   = 1<<1,
       
   508         //  Convert
       
   509         EInsertClipartStateConvert  = 1<<2,
       
   510         //  First time in main
       
   511         EInsertClipartStateFirst    = 1<<3,
       
   512         //  Main view
       
   513         EInsertClipartStateMain     = 1<<4,
       
   514         //  Move
       
   515         EInsertClipartStateMove     = 1<<5,
       
   516         //  Rotate
       
   517         EInsertClipartStateRotate   = 1<<6,
       
   518         //  Resize
       
   519         EInsertClipartStateResize   = 1<<7,
       
   520         //  Invalid
       
   521         EInsertClipartStateMax      = 1<<8
       
   522     } iState;
       
   523 
       
   524 //@}
       
   525 
       
   526 
       
   527 /** @name Members:*/
       
   528 //@{
       
   529 
       
   530     /// Editor view
       
   531     CAknView *					iEditorView;
       
   532 
       
   533     /// System parameters
       
   534     const CSystemParameters*    iSysPars;
       
   535 
       
   536     /// Plug-in info
       
   537     CPluginInfo *               iItem;
       
   538 
       
   539     /// Navigation pane text
       
   540     TBuf<64>                    iNaviPaneText;
       
   541     
       
   542     /// Clipart x position
       
   543     TInt						iX;
       
   544     /// Clipart y position
       
   545     TInt						iY;
       
   546 	/// Clipart scale	
       
   547     TInt                        iScale;
       
   548     /// Clipart scale minimum
       
   549     TInt						iScaleMin;
       
   550     /// Clipart scale maximum
       
   551     TInt						iScaleMax;
       
   552     /// Clipart angle 
       
   553     TInt						iAngle;
       
   554 	///	Do we scale clipart to maximum height
       
   555 	TBool						iScaleToHeight;
       
   556     
       
   557     TInt						iScaleOld;
       
   558     TInt						iPosXOld;
       
   559     TInt						iPosYOld;
       
   560     
       
   561 	/// Temp params
       
   562     TInt						iTempX;
       
   563     TInt						iTempY;
       
   564     TInt                        iTempScale;
       
   565     TInt                        iTempAngle;
       
   566 
       
   567     /// Popup list
       
   568     CClipartSelectionDialog*    iPopupList;
       
   569 	
       
   570 	/// Clipart filename
       
   571 	TFileName					iClipartFileName;
       
   572 	
       
   573 	/// Clipart filename index
       
   574 	TInt						iClipartFileNameIndex;
       
   575 	
       
   576 	/// Resource reader
       
   577 	RConeResourceLoader         iResLoader;
       
   578 
       
   579     /// Timer for fast key events
       
   580 	CJPTimer *					iTimer;
       
   581 	TUint32						iKeyCode;
       
   582     
       
   583     /// Number of ticks since timer start
       
   584     TInt						iTickCount;
       
   585 
       
   586     /// Multiplier to control the navigation movement speed
       
   587     TInt						iNaviStepMultiplier;
       
   588 
       
   589     /// Showing Ok options menu, where some items are dimmed
       
   590     TBool                       iDisplayingOkOptionsMenu;
       
   591 
       
   592     /// Plug-in is ready to render the image
       
   593     TBool                       iReadyToRender;
       
   594 
       
   595     /// State indicator glyph
       
   596     CFbsBitmap *                iIndicator;
       
   597     CFbsBitmap *                iIndicatorMask;
       
   598 
       
   599 	/// Clipart parameter
       
   600 	TBuf<256>					iParam;
       
   601 	
       
   602 
       
   603 	// Popup controller
       
   604 	CAknInfoPopupNoteController* iPopupController;
       
   605 	// Tooltip texts
       
   606 	HBufC * 					iTooltipResize;
       
   607 	HBufC * 					iTooltipMove;	
       
   608 	HBufC * 					iTooltipRotate;	
       
   609 	
       
   610 	// Previous pen position. Make touch rotating and resizing possible
       
   611 	TPoint                      iPointerPosition;
       
   612 
       
   613 	// Feedback for screen touch:
       
   614 #ifdef RD_TACTILE_FEEDBACK 
       
   615 	MTouchFeedback* iTouchFeedBack;
       
   616 #endif /* RD_TACTILE_FEEDBACK  */
       
   617 		
       
   618 //@}
       
   619 
       
   620 };
       
   621 
       
   622 
       
   623 #endif