imageeditor/plugins/CropPlugin/inc/ImageEditorCropControl.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 * Crop plugin control class header.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #ifndef IMAGEEDITORCROPCONTROL_H
       
    22 #define IMAGEEDITORCROPCONTROL_H
       
    23 
       
    24 //  INCLUDES
       
    25 #include <coecntrl.h>
       
    26 
       
    27 #include "PreviewControlBase.h"
       
    28 
       
    29 //  FORWARD DECLARATIONS
       
    30 class CAknView;
       
    31 class CFbsBitmap;
       
    32 class CPluginInfo;
       
    33 class CSystemParameters;
       
    34 class CPeriodic;
       
    35 class CAknInfoPopupNoteController;
       
    36 
       
    37 #ifdef RD_TACTILE_FEEDBACK 
       
    38 class MTouchFeedback;
       
    39 #endif /* RD_TACTILE_FEEDBACK  */
       
    40 
       
    41 /*	CLASS: CImageEditorCropControl
       
    42 *
       
    43 *   CImageEditorCropControl is a control for crop plug-in.
       
    44 *
       
    45 */
       
    46 class CImageEditorCropControl :		public CPreviewControlBase
       
    47 {
       
    48 
       
    49 public:
       
    50 
       
    51 /** @name Methods:*/
       
    52 //@{
       
    53 
       
    54 	/** NewL factory method, pops cleanupstack
       
    55 	*
       
    56 	*	@param aRect - control rectangle
       
    57 	*	@param aParent - pointer to window owning control
       
    58 	*	@return pointer to created CImageEditorCropControl object
       
    59 	*/
       
    60 	static CImageEditorCropControl * NewL (
       
    61 		const TRect &		aRect,
       
    62 		CCoeControl	*		aParent
       
    63 		);
       
    64 
       
    65 	/** DancingAntsCallback
       
    66 	*
       
    67 	*	Static callback for rotating dancing ants.
       
    68 	*
       
    69 	*	@param aPtr - parameter given for TCallBack
       
    70 	*	@return TInt
       
    71 	*/
       
    72 	static TInt DancingAntsCallback (TAny * aPtr);
       
    73 
       
    74 	/** FastKeyCallback
       
    75 	*
       
    76 	*	Static callback for triggering keys faster.
       
    77 	*
       
    78 	*	@param aPtr - parameter given for TCallBack
       
    79 	*	@return TInt
       
    80 	*/
       
    81 	static TInt FastKeyCallback (TAny * aPtr);
       
    82 
       
    83 	/** Destructor
       
    84 	*
       
    85 	*	@param -
       
    86 	*	@return -
       
    87 	*/
       
    88 	virtual ~CImageEditorCropControl ();
       
    89 
       
    90 	/** Second phase constructor
       
    91 	*
       
    92 	*	@see CImageEditorControlBase
       
    93 	*
       
    94     */
       
    95 	virtual void ConstructL (
       
    96 		const TRect &		aRect,
       
    97 		CCoeControl	*		aParent
       
    98 		);
       
    99 
       
   100 	/*	Setter for view reference
       
   101 	*
       
   102 	*	@see CImageEditorControlBase
       
   103 	*
       
   104     */
       
   105     virtual void SetView (CAknView * aView);
       
   106 
       
   107     /*	SetSelectedUiItemL
       
   108 	*
       
   109 	*	@see CImageEditorControlBase
       
   110 	*
       
   111     */
       
   112     virtual void SetSelectedUiItemL (CPluginInfo * aItem);
       
   113 
       
   114 #ifdef DOUBLE_BUFFERED_CROP
       
   115 
       
   116     /*	SetImage
       
   117 	*
       
   118 	*	@see CImageEditorControlBase
       
   119 	*
       
   120     */
       
   121     virtual void SetImageL (CFbsBitmap *	aBitmap);
       
   122 
       
   123 #endif
       
   124 
       
   125     /*	OfferKeyEventL
       
   126 	*
       
   127 	*	@see CImageEditorControlBase
       
   128 	*
       
   129     */
       
   130     virtual TKeyResponse OfferKeyEventL (
       
   131         const TKeyEvent &   aKeyEvent,
       
   132         TEventCode          aType
       
   133         );   
       
   134     
       
   135     /*	HandlePointerEventL
       
   136     *
       
   137     *	@see CImageEditorControlBase
       
   138     *
       
   139     */
       
   140 	virtual void HandlePointerEventL( const TPointerEvent &aPointerEvent );
       
   141 	
       
   142 	/*	HandlePluginCommandL
       
   143 	*
       
   144 	*	@see CImageEditorControlBase
       
   145 	*
       
   146     */
       
   147     virtual void HandlePluginCommandL (const TInt aCommand);
       
   148 
       
   149 	/*	GetSoftkeyIndexL
       
   150 	*
       
   151 	*	@see CImageEditorControlBase
       
   152     */
       
   153     virtual TInt GetSoftkeyIndexL();
       
   154 
       
   155 	/*	GetNaviPaneTextL
       
   156 	*
       
   157 	*	@see CImageEditorControlBase
       
   158 	*/
       
   159 	virtual TPtrC GetNaviPaneTextL (
       
   160 		TBool& aLeftNaviPaneScrollButtonVisibile, 
       
   161 		TBool& aRightNaviPaneScrollButtonVisible);
       
   162 
       
   163 	/*	GetParam
       
   164 	*
       
   165 	*	Gets pointer to the parameter struct.
       
   166 	*
       
   167 	*	@param -
       
   168 	*	@return - pointer to MIA parameter struct
       
   169 	*/
       
   170     TDesC & GetParam ();
       
   171 
       
   172 	/*	SetSysteParameters
       
   173 	*
       
   174 	*	Sets reference to system parameters to plug-in.
       
   175 	*
       
   176 	*	@param aWidth - image width
       
   177 	*	@return - 
       
   178 	*/
       
   179     void SetSystemParameters (const CSystemParameters * aSysPars);
       
   180 
       
   181 	/*	SetCropModeL
       
   182 	*
       
   183 	*	Sets cropping mode and aspect ratio.
       
   184 	*
       
   185 	*	@param aRatio - crop aspect ratio
       
   186 	*	@return - 
       
   187 	*/
       
   188     void SetCropModeL (
       
   189         const TInt      aMode,
       
   190         const float     aRatio
       
   191         );
       
   192 
       
   193 	/*	IsReadyToRender
       
   194 	*
       
   195 	*	Returns boolean value indicating when the parameters
       
   196     *   are set and filter is ready to be rendered
       
   197 	*
       
   198 	*	@param  - 
       
   199 	*	@return TBool - is ready to render?
       
   200 	*/
       
   201     TBool IsReadyToRender () const;
       
   202 
       
   203 
       
   204 //@}
       
   205 
       
   206 protected:
       
   207 
       
   208 /** @name Methods:*/
       
   209 //@{
       
   210 	/*	SizeChanged
       
   211 	*
       
   212 	*	@see CImageEditorControlBase
       
   213 	*
       
   214     */
       
   215 	virtual void SizeChanged();
       
   216 
       
   217 //@}
       
   218 
       
   219 /** @name Members:*/
       
   220 //@{
       
   221 
       
   222 //@}
       
   223 
       
   224 private:
       
   225 
       
   226 /** @name Methods:*/
       
   227 //@{
       
   228 
       
   229 	/** Default constructor
       
   230 	*
       
   231 	*	@param -
       
   232 	*	@return -
       
   233 	*/
       
   234 	CImageEditorCropControl ();
       
   235 
       
   236 	/**	Draw
       
   237 	*
       
   238 	*	@see CImageEditorControlBase
       
   239 	*
       
   240     */
       
   241 	virtual void Draw (const TRect & aRect) const;
       
   242 
       
   243 	/**	DrawDancingAnts
       
   244 	*
       
   245 	*	Drawing function for dancing ants crop rectangle.
       
   246 	*
       
   247 	*	@param aRect - control rectangle in need of refreshing 
       
   248 	*	@return -
       
   249     */
       
   250 	void DrawDancingAnts (const TRect & aRect) const;
       
   251     
       
   252     /**	DrawCursors
       
   253 	*
       
   254 	*	Drawing function for both of the cropping cursors.
       
   255 	*
       
   256 	*	@param aCropRect - cropping rectangle which indicates
       
   257 	*                      top left and bottom right corners (i.e.
       
   258 	*                      places for the cursors.)
       
   259 	*	@return -
       
   260     */
       
   261     void DrawCursors ( const TRect& aCropRect ) const;
       
   262     
       
   263 	/**	ComputeCropParams
       
   264 	*
       
   265 	*	Computes cropping parameters.
       
   266 	*
       
   267 	*	@param -
       
   268 	*	@return -
       
   269 	*/
       
   270 	void ComputeCropParams ();
       
   271 
       
   272 	/**	NaviDownL
       
   273 	*
       
   274 	*	Handles navi key down event.
       
   275 	*
       
   276 	*	@param -
       
   277 	*	@return -
       
   278 	*/
       
   279     void NaviDownL();
       
   280 
       
   281 	/**	NaviUpL
       
   282 	*
       
   283 	*	Handles nave key up event.
       
   284 	*
       
   285 	*	@param -
       
   286 	*	@return -
       
   287 	*/
       
   288     void NaviUpL();
       
   289 
       
   290 	/**	NaviRightL
       
   291 	*
       
   292 	*	Handles nave key right event.
       
   293 	*
       
   294 	*	@param -
       
   295 	*	@return -
       
   296 	*/
       
   297     void NaviRightL();
       
   298 
       
   299 	/**	NaviLeftL
       
   300 	*
       
   301 	*	Handles nave key left event.
       
   302 	*
       
   303 	*	@param -
       
   304 	*	@return -
       
   305 	*/
       
   306     void NaviLeftL();
       
   307 
       
   308 	/**	SetInitialPointsL
       
   309 	*
       
   310 	*	Sets initial crop points based on wanted cropping aspect 
       
   311     *   ratio (crop mode).
       
   312 	*
       
   313 	*	@param -
       
   314 	*	@return -
       
   315 	*/
       
   316     void SetInitialPointsL ();
       
   317 
       
   318 	/**	StartDancingAntsTimer
       
   319 	*
       
   320 	*	Starts dancing ants timer. 
       
   321 	*
       
   322 	*	@param -
       
   323 	*	@return -
       
   324 	*/
       
   325 	void StartDancingAntsTimer();
       
   326 
       
   327 	/**	StartDancingAntsTimer
       
   328 	*
       
   329 	*	Starts dancing ants timer. 
       
   330 	*
       
   331 	*	@param -
       
   332 	*	@return -
       
   333 	*/
       
   334 	void StartFastKeyTimer();
       
   335 
       
   336 	/**	OnDancingAntsCallBack
       
   337 	*
       
   338 	*	Timer event handler for dancing ants.
       
   339 	*
       
   340 	*	@param -
       
   341 	*	@return -
       
   342 	*/
       
   343 	void OnDancingAntsCallBack();
       
   344 
       
   345 	/**	OnFastKeyCallBackL
       
   346 	*
       
   347 	*	Timer event handler for fast keys.
       
   348 	*
       
   349 	*	@param -
       
   350 	*	@return -
       
   351 	*/
       
   352 	void OnFastKeyCallBackL();
       
   353 
       
   354 	/**	CalculateMinCrop
       
   355 	*
       
   356 	*	Calculates minimum crop area
       
   357 	*
       
   358 	*	@param -
       
   359 	*	@return -
       
   360 	*/
       
   361     void CalculateMinCrop();
       
   362 
       
   363 	/**	ComputePreservedULC
       
   364 	*
       
   365 	*	Computes aspect ratio preserver ULC coordinate.
       
   366 	*
       
   367 	*	@param -
       
   368 	*	@return -
       
   369 	*/
       
   370     void ComputePreservedULC();
       
   371 
       
   372 	/**	ComputePreservedULC
       
   373 	*
       
   374 	*	Computes aspect ratio preserver LRC coordinate.
       
   375 	*
       
   376 	*	@param -
       
   377 	*	@return -
       
   378 	*/
       
   379     void ComputePreservedLRC();
       
   380 
       
   381 	/**	ComputePreservedULR
       
   382 	*
       
   383 	*	Computes aspect ratio preserver ULR coordinate.
       
   384 	*
       
   385 	*	@param -
       
   386 	*	@return -
       
   387 	*/
       
   388     void ComputePreservedULR();
       
   389 
       
   390 	/**	ComputePreservedLRR
       
   391 	*
       
   392 	*	Computes aspect ratio preserver LRR coordinate.
       
   393 	*
       
   394 	*	@param -
       
   395 	*	@return -
       
   396 	*/
       
   397     void ComputePreservedLRR();
       
   398 
       
   399 #ifdef DOUBLE_BUFFERED_CROP
       
   400 
       
   401 	/**	ClonePreviewBitmapL
       
   402 	*
       
   403 	*	Copy preview image data to buffer.
       
   404 	*
       
   405 	*	@param -
       
   406 	*	@return -
       
   407 	*/
       
   408 	void ClonePreviewBitmapL();
       
   409 
       
   410 	/**	DarkenUnselectedAreaL
       
   411 	*
       
   412 	*	Darkens the area outside crop region in the buffer.
       
   413 	*
       
   414 	*	@param -
       
   415 	*	@return -
       
   416 	*/
       
   417 	void DarkenUnselectedAreaL();
       
   418 
       
   419 #endif
       
   420 
       
   421 	/**	UpdateCropRectangle
       
   422 	*
       
   423 	*	Update crop rectangle after cropping.
       
   424 	*
       
   425 	*	@param -
       
   426 	*	@return -
       
   427 	*/
       
   428 	void UpdateCropRectangle();
       
   429 
       
   430 	void StoreCropRelScreen();
       
   431 	void RestoreCropRelScreen();
       
   432 	void StoreCropRelImage();
       
   433 	void RestoreCropRelImage();
       
   434 	
       
   435 	/**	SetTLPosition
       
   436 	*
       
   437 	*	Touch related function.
       
   438 	*   Calculates the stylus movement according to the given parameters 
       
   439 	*   and moves top-left corner respectively. 
       
   440 	*
       
   441 	*	@param  aOldPosition Previous pointer position.
       
   442 	*           aNewPosition Current pointer position.
       
   443 	*	@return -
       
   444 	*/
       
   445 	void SetTLPosition( TPoint aOldPosition, TPoint aNewPosition );
       
   446 	
       
   447 	/**	SetBRPosition
       
   448 	*
       
   449 	*	Touch related function.
       
   450 	*   Calculates the stylus movement according to the given parameters 
       
   451 	*   and moves bottom-right corner respectively. 
       
   452 	*
       
   453 	*	@param  aOldPosition Previous pointer position.
       
   454 	*           aNewPosition Current pointer position.
       
   455 	*	@return -
       
   456 	*/
       
   457 	void SetBRPosition( TPoint aOldPosition, TPoint aNewPosition );
       
   458     
       
   459     /**	IsCursorTapped
       
   460 	*
       
   461 	*   Touch related function.
       
   462 	*   Checks if user has tapped inside the cursor area 
       
   463 	*
       
   464 	*	@param aTappedPosition A position value to check
       
   465 	*	@return ETrue if cursor area contains tapped position, EFalse otherwise
       
   466 	*/
       
   467     TBool IsCursorTapped( TPoint aTappedPosition ) const;
       
   468     
       
   469     /**	IsOppositeCornerTapped
       
   470 	*
       
   471 	*	Touch related function.
       
   472 	*   Checks if user has tapped opposite corner to the current 
       
   473 	*   cursor corner. 
       
   474 	*    	
       
   475 	*	@param aTappedPosition A position value to check
       
   476 	*	@return ETrue if cursor area in opposite corner contains tapped position, 
       
   477 	*           EFalse otherwise
       
   478 	*/
       
   479     TBool IsOppositeCornerTapped( TPoint aTappedPosition ) const;
       
   480     
       
   481     /**	IsCropAreaTapped
       
   482 	*
       
   483 	*	Touch related function.
       
   484 	*   Checks if user has tapped inside the crop rectangle
       
   485 	*
       
   486 	*	@param aTappedPosition A position value to check
       
   487 	*	@return ETrue if current crop rectangle contains tapped position, 
       
   488 	*           EFalse otherwise
       
   489 	*/
       
   490     TBool IsCropAreaTapped( TPoint aTappedPosition ) const;
       
   491     
       
   492     /**	IsMinCropAreaTapped
       
   493 	*
       
   494 	*	Touch related function.
       
   495 	*   Checks if user has tapped inside the minimum crop rectangle.
       
   496 	*   Minimum crop rectangle is inside crop regtacgle. A smallest
       
   497 	*   possible rectangle to crop.
       
   498 	*
       
   499 	*	@param aTappedPosition A position value to check
       
   500 	*	@return ETrue if current minimum crop rectangle contains 
       
   501 	                  tapped position, 
       
   502 	*           EFalse otherwise
       
   503 	*/
       
   504     TBool IsMinCropAreaTapped( TPoint aTappedPosition ) const;
       
   505            
       
   506     /**	IsCornerTapped
       
   507 	*
       
   508 	*	Touch related function.
       
   509 	*   Checks if either Top-Left or Bottom-Right corner is tapped. 
       
   510 	*
       
   511 	*	@param aTappedPosition Pointer position to check
       
   512 	*          aTappedCorner Possible tapped corner index is returned here.
       
   513 	*	@return ETrue if either one of the corners is tapped, EFalse otherwise
       
   514 	*/
       
   515     TBool IsCornerTapped( TPoint aTappedPosition, TInt& aTappedCorner ) const;
       
   516     
       
   517     /**	MoveCropArea
       
   518 	*
       
   519 	*	Touch related function.
       
   520 	*   Calculates the movement according to the given parameters and moves 
       
   521 	*   current crop rect respectively.   
       
   522 	*
       
   523 	*	@param  aOldPosition Previous pointer position.
       
   524 	*           aNewPosition Current pointer position.
       
   525 	*	@return -
       
   526 	*/
       
   527     void MoveCropArea( TPoint aOldPosition, TPoint aNewPosition );
       
   528             
       
   529     /**	ShowTooltip
       
   530     *
       
   531     *	Show tooltip text on the screen. Tooltip text is set based 
       
   532     *   on the current state.
       
   533     *
       
   534     *	@param -
       
   535     *	@return -
       
   536     */
       
   537     void ShowTooltip();
       
   538     
       
   539 //@}
       
   540 
       
   541 /** @name Typedefs:*/
       
   542 //@{
       
   543     enum TCropState
       
   544     {
       
   545         //  Invalid
       
   546         ECropStateMin = 0,
       
   547         //  ULC
       
   548         ECropStateFirst,
       
   549         //  LRC
       
   550         ECropStateSecond,
       
   551         //  Move
       
   552         ECropStateMove,
       
   553         //  Minimum crop
       
   554         ECropStateMinCrop,
       
   555         //  Invalid
       
   556         ECropStateMax
       
   557     } iState;
       
   558 
       
   559 	enum TFastKeyTimerState
       
   560     {
       
   561         // Inactive
       
   562         ETimerInactive,
       
   563         // Started but has not yet run
       
   564         ETimerStarted,
       
   565         // Started and running
       
   566         ETimerRunning
       
   567     } iFastKeyTimerState;
       
   568     
       
   569     enum TCropRectCorner
       
   570         {
       
   571         ETLCorner,
       
   572         EBRCorner,
       
   573         EInvalidCorner
       
   574         };
       
   575 //@}
       
   576 
       
   577 
       
   578 /** @name Members:*/
       
   579 //@{
       
   580     
       
   581     /// Editor view
       
   582     CAknView *					iEditorView;
       
   583 
       
   584     /// Plug-in info
       
   585     CPluginInfo *               iItem;
       
   586 
       
   587     /// Navigation pane text
       
   588     TBuf<64>                    iNaviPaneText;
       
   589 
       
   590     /// Cross hair icon
       
   591     CFbsBitmap *				iCrossHair;
       
   592     CFbsBitmap *				iCrossHairMask;
       
   593     
       
   594     /// Secondary cross hair icon
       
   595     CFbsBitmap *                iSecondaryCrossHair;
       
   596     CFbsBitmap *                iSecondaryCrossHairMask;
       
   597     
       
   598     /// Periodic timer for dancing ants and fast key events
       
   599 	CPeriodic *					iTimer;
       
   600 
       
   601 	/// Dancing ants flag
       
   602 	TBool						iAntFlag;
       
   603 
       
   604 	/// Pressed key event code
       
   605 	TInt 						iPressedKeyScanCode;
       
   606 
       
   607 	/// Are event keys handled
       
   608 	TBool						iHandleEventKeys;
       
   609 
       
   610     /// Number of ticks since timer start
       
   611     TInt						iTickCount;
       
   612 
       
   613     /// Multiplier to control the navigation movement speed
       
   614     TInt						iNaviStepMultiplier;
       
   615 
       
   616     /// Ready to render
       
   617     TBool                       iReadyToRender;
       
   618     
       
   619     const CSystemParameters *   iSysPars;
       
   620 
       
   621     /// Relative crop rect coordinates
       
   622     float                       iULC;
       
   623     float                       iULR;
       
   624     float                       iLRC;
       
   625     float                       iLRR;
       
   626 
       
   627     /// Minimum crop parameters
       
   628     float                       iMinX;
       
   629     float                       iMinY;
       
   630 
       
   631     /// Wanted aspect ratio
       
   632     float                       iCropRatio;
       
   633 
       
   634     /// Crop mode
       
   635 	TBool                       iIsCropModeManual;
       
   636 
       
   637     /// Is input image too small
       
   638 	TBool                       iIsCropDisabled;
       
   639 
       
   640 #ifdef DOUBLE_BUFFERED_CROP
       
   641 
       
   642 	///	Double buffer bitmap
       
   643 	CFbsBitmap *				iPrevBitmap;
       
   644 	CFbsBitmap *				iBufBitmap;
       
   645 
       
   646 #endif
       
   647 
       
   648 	TRect						iOldCropRectPrev;
       
   649 	TBool						iBackground;
       
   650 	
       
   651 	TBuf<256>					iParam;
       
   652 	TInt						iCropX;
       
   653 	TInt						iCropY;
       
   654 	TInt						iCropW;
       
   655 	TInt						iCropH;
       
   656 	// Popup controller
       
   657 	CAknInfoPopupNoteController* iPopupController;
       
   658 	// Tooltip texts
       
   659 	HBufC * 					iTooltipResize;
       
   660 	HBufC * 					iTooltipMove;
       
   661 	
       
   662 	// Indicates whether touch dragging is allowed or not
       
   663 	// (cursor or the whole crop rect)
       
   664 	TBool                       iTouchDragEnabled;
       
   665 	// Stores the position for previously tapped screen point (touch enabler)
       
   666 	TPoint                      iTappedPosition;
       
   667 	
       
   668 	// Feedback for screen touch:
       
   669 #ifdef RD_TACTILE_FEEDBACK 
       
   670 	MTouchFeedback* iTouchFeedBack;
       
   671 #endif /* RD_TACTILE_FEEDBACK  */	
       
   672 //@}
       
   673 
       
   674 };
       
   675 
       
   676 
       
   677 #endif