imageeditor/plugins/DrawPlugin/src/imageeditordrawplugin.cpp
changeset 8 18b321db4884
parent 1 edfc90759b9f
equal deleted inserted replaced
1:edfc90759b9f 8:18b321db4884
     1 /*
     1 /*
     2 * Copyright (c) 2010 Ixonos Plc.
     2  * Copyright (c) 2010 Ixonos Plc.
     3 * All rights reserved.
     3  * All rights reserved.
     4 * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5 * under the terms of the "Eclipse Public License v1.0"
     5  * under the terms of the "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     8  *
     9 * Initial Contributors:
     9  * Initial Contributors:
    10 * Nokia Corporation - Initial contribution
    10  * Nokia Corporation - Initial contribution
    11 *
    11  *
    12 * Contributors:
    12  * Contributors:
    13 * Ixonos Plc
    13  * Ixonos Plc
    14 *
    14  *
    15 * Description: 
    15  * Description: 
    16 * Freehand draw UI plugin that sends UI commands to 
    16  * Freehand draw UI plugin that sends UI commands to 
    17 * corresponding filter plugin. (filterdraw.dll).
    17  * corresponding filter plugin. (filterdraw.dll).
    18 *
    18  *
    19 */
    19  */
    20 
       
    21 
       
    22 #include "ImageEditordrawPlugin.h"
    20 #include "ImageEditordrawPlugin.h"
    23 #include "ImageEditordrawControl.h"
    21 #include "ImageEditordrawControl.h"
    24 #include "ImageEditorPluginBaseDefs.h"
    22 #include "ImageEditorPluginBaseDefs.h"
    25 #include "DrawUtils.h"
    23 #include "DrawUtils.h"
    26 #include "SystemParameters.h"
    24 #include "SystemParameters.h"
    27 
    25 #include "drawpath.h"
    28 #ifdef TEXT_INSERTION_IN_PORTRAIT_ONLY
    26 #ifdef TEXT_INSERTION_IN_PORTRAIT_ONLY
    29 #include <aknappui.h>
    27 #include <aknappui.h>
    30 #endif
    28 #endif
    31 #include <aknquerydialog.h> 
    29 #include <aknquerydialog.h> 
    32 
       
    33 //	CONSTANTS
    30 //	CONSTANTS
    34 _LIT (KPgnResourceFile, "draw.rsc");
    31 _LIT (KPgnResourceFile, "draw.rsc");
    35 
       
    36 
    32 
    37 // ---------------------------------------------------------------------------
    33 // ---------------------------------------------------------------------------
    38 // CreateImageEditorPlugin
    34 // CreateImageEditorPlugin
    39 // ---------------------------------------------------------------------------
    35 // ---------------------------------------------------------------------------
    40 //
    36 //
    42 	{
    38 	{
    43 	CImageEditorDrawPlugin * plugin = new (ELeave) CImageEditorDrawPlugin;
    39 	CImageEditorDrawPlugin * plugin = new (ELeave) CImageEditorDrawPlugin;
    44 	CleanupStack::PushL(plugin);
    40 	CleanupStack::PushL(plugin);
    45 	plugin->ConstructL();
    41 	plugin->ConstructL();
    46 	CleanupStack::Pop(); // plugin
    42 	CleanupStack::Pop(); // plugin
    47     return plugin;
    43 	return plugin;
    48 	}
    44 	}
    49 
    45 
    50 // ---------------------------------------------------------------------------
    46 // ---------------------------------------------------------------------------
    51 // CImageEditorDrawPlugin
    47 // CImageEditorDrawPlugin
    52 // ---------------------------------------------------------------------------
    48 // ---------------------------------------------------------------------------
    53 //
    49 //
    54 CImageEditorDrawPlugin::CImageEditorDrawPlugin() : iLandscapeEnabled(EFalse)
    50 CImageEditorDrawPlugin::CImageEditorDrawPlugin() :
    55 	{}
    51 	iLandscapeEnabled(EFalse)
       
    52 	{
       
    53 	}
    56 
    54 
    57 // ---------------------------------------------------------------------------
    55 // ---------------------------------------------------------------------------
    58 // ConstructL
    56 // ConstructL
    59 // ---------------------------------------------------------------------------
    57 // ---------------------------------------------------------------------------
    60 //
    58 //
    61 inline void CImageEditorDrawPlugin::ConstructL()
    59 inline void CImageEditorDrawPlugin::ConstructL()
    62 	{
    60 	{
    63     CImageEditorPluginBase::ConstructL(KPgnResourcePath, KPgnResourceFile);
    61 	CImageEditorPluginBase::ConstructL(KPgnResourcePath, KPgnResourceFile);
       
    62 	iRgb = KRgbWhite;
       
    63 	iSize = TSize(8, 8);
    64 	}
    64 	}
    65 
    65 
    66 // ---------------------------------------------------------------------------
    66 // ---------------------------------------------------------------------------
    67 // ?description_if_needed
    67 // ?description_if_needed
    68 // ---------------------------------------------------------------------------
    68 // ---------------------------------------------------------------------------
    69 //
    69 //
    70 CImageEditorDrawPlugin::~CImageEditorDrawPlugin()
    70 CImageEditorDrawPlugin::~CImageEditorDrawPlugin()
    71 	{
    71 	{
    72     ReleasePlugin();
    72 	ReleasePlugin();
    73     iSysPars = NULL;
    73 	iSysPars = NULL;
       
    74 	iPaths.ResetAndDestroy();
    74 	}
    75 	}
    75 
    76 
    76 // ---------------------------------------------------------------------------
    77 // ---------------------------------------------------------------------------
    77 // SetProperty
    78 // SetProperty
    78 // ---------------------------------------------------------------------------
    79 // ---------------------------------------------------------------------------
    79 //
    80 //
    80 TInt CImageEditorDrawPlugin::SetProperty(
    81 TInt CImageEditorDrawPlugin::SetProperty(TInt aPropertyId,
    81 	TInt aPropertyId, TDesC& aPropertyValue)
    82 		TDesC& aPropertyValue)
    82 	{
    83 	{
    83     TInt err(KErrNone);
    84 	TInt err(KErrNone);
    84     TLex parser;
    85 	TLex parser;
    85 
    86 
    86 	//	Copy data
    87 	//	Copy data
    87 	switch (aPropertyId) 
    88 	switch (aPropertyId)
    88 		{
    89 		{
    89 		case KCapSystemParameters:
    90 		case KCapSystemParameters:
    90 			{
    91 			{
    91 			parser.Assign (aPropertyValue);
    92 			parser.Assign(aPropertyValue);
    92             TInt tempval = 0;
    93 			TInt tempval = 0;
    93             parser.Val (tempval);
    94 			parser.Val(tempval);
    94             iSysPars = (const CSystemParameters *)tempval;
    95 			iSysPars = (const CSystemParameters *) tempval;
    95 			err = KErrNone;
    96 			err = KErrNone;
    96             break;
    97 			break;
    97 			}
    98 			}
    98 		default:
    99 		default:
    99 			{
   100 			{
   100 			err = CImageEditorPluginBase::SetProperty(
   101 			err = CImageEditorPluginBase::SetProperty(aPropertyId,
   101 				aPropertyId, aPropertyValue);
   102 					aPropertyValue);
   102             break;
   103 			break;
   103 			}
   104 			}
   104 		}
   105 		}
   105     return err;
   106 	return err;
   106 	}
   107 	}
   107 
   108 
   108 // ---------------------------------------------------------------------------
   109 // ---------------------------------------------------------------------------
   109 // GetProperty
   110 // GetProperty
   110 // ---------------------------------------------------------------------------
   111 // ---------------------------------------------------------------------------
   111 //
   112 //
   112 TInt CImageEditorDrawPlugin::GetProperty(
   113 TInt CImageEditorDrawPlugin::GetProperty(TInt aPropertyId, TDes& aPropertyValue)
   113 	TInt aPropertyId, TDes& aPropertyValue)
       
   114 	{
   114 	{
   115 	//	Clean buffer
   115 	//	Clean buffer
   116 	aPropertyValue.Zero();
   116 	aPropertyValue.Zero();
   117 
   117 
   118 	//	Copy data
   118 	//	Copy data
   119 	switch (aPropertyId) 
   119 	switch (aPropertyId)
   120 		{
   120 		{
   121 		case KCapParamStruct:
   121 		case KCapParamStruct:
   122 			{
   122 			{
   123 			// Control found
   123 			// Control found
   124 			if (iControl)
   124 			if (iControl)
   125 				{
   125 				{
   126 				aPropertyValue.Copy( 
   126 				aPropertyValue.Copy(
   127 					((CImageEditorDrawControl *)iControl)->GetParam() );
   127 						((CImageEditorDrawControl *) iControl)->GetParam());
   128 				return KErrNone;
   128 				return KErrNone;
   129 				}
   129 				}
   130 
   130 
   131 			//	Control not found, return KErrNotReady
   131 			//	Control not found, return KErrNotReady
   132 			else
   132 			else
   133 				{
   133 				{
   134 				return KErrNotReady;
   134 				return KErrNotReady;
   135 				}
   135 				}
   136 			}
   136 			}
   137         case KCapReadyToRender:
   137 		case KCapReadyToRender:
   138 			{
   138 			{
   139             TBool readytorender = ETrue;
   139 			TBool readytorender = ETrue;
   140             if (iControl)
   140 			if (iControl)
   141                 {
   141 				{
   142                 readytorender = 
   142 				readytorender
   143                 	((CImageEditorDrawControl *)iControl)->IsReadyToRender();
   143 						= ((CImageEditorDrawControl *) iControl)->IsReadyToRender();
   144                 }
   144 				}
   145 			aPropertyValue.AppendNum ((TInt)readytorender);
   145 			aPropertyValue.AppendNum((TInt) readytorender);
   146 			return KErrNone;
   146 			return KErrNone;
   147 			}
   147 			}
   148         case KCapIsLandscapeEnabled:
   148 		case KCapIsLandscapeEnabled:
   149 			{
   149 			{
   150 			aPropertyValue.AppendNum ((TInt)iLandscapeEnabled);
   150 			aPropertyValue.AppendNum((TInt) iLandscapeEnabled);
   151 			return KErrNone;
   151 			return KErrNone;
   152 			}
   152 			}
   153         case KCapIsSlowPlugin:
   153 		case KCapIsSlowPlugin:
   154 			{
   154 			{
   155 			aPropertyValue.AppendNum ((TInt)ETrue);
   155 			aPropertyValue.AppendNum((TInt) ETrue);
   156 			return KErrNone;
   156 			return KErrNone;
   157 			}
   157 			}
   158 		default:
   158 		default:
   159 			{
   159 			{
   160 			return CImageEditorPluginBase::GetProperty(
   160 			return CImageEditorPluginBase::GetProperty(aPropertyId,
   161 				aPropertyId, aPropertyValue);
   161 					aPropertyValue);
   162 			}
   162 			}
   163 		}
   163 		}
   164 	}
   164 	}
   165 
   165 
   166 // ---------------------------------------------------------------------------
   166 // ---------------------------------------------------------------------------
   167 // InitPluginL
   167 // InitPluginL
   168 // ---------------------------------------------------------------------------
   168 // ---------------------------------------------------------------------------
   169 //
   169 //
   170 TInt CImageEditorDrawPlugin::InitPluginL(
   170 TInt CImageEditorDrawPlugin::InitPluginL(const TRect& aRect,
   171 	const TRect& aRect,
   171 		CCoeControl* aParent, CCoeControl*& aPluginControl)
   172 	CCoeControl* aParent,
   172 	{
   173 	CCoeControl*& aPluginControl)
   173 	//  Delete previous control
   174 	{
       
   175     //  Delete previous control
       
   176 	ReleasePlugin();
   174 	ReleasePlugin();
   177 
   175 
   178 	//	Get pointer to the parameter descriptor array
   176 	//	Get pointer to the parameter descriptor array
   179 	TBuf<256>  readbuf;  
   177 	TBuf<256> readbuf;
   180 	TLex       parser;
   178 	TLex parser;
   181 	User::LeaveIfError( CImageEditorPluginBase::GetProperty(
   179 	User::LeaveIfError(CImageEditorPluginBase::GetProperty(
   182 		KCapPluginParamNames, readbuf) );
   180 			KCapPluginParamNames, readbuf));
   183 	parser.Assign (readbuf);
   181 	parser.Assign(readbuf);
   184 	TInt tempval = 0;
   182 	TInt tempval = 0;
   185 	parser.Val( tempval );
   183 	parser.Val(tempval);
   186 	//CDesCArray * pars = (CDesCArray *)tempval;
   184 	//CDesCArray * pars = (CDesCArray *)tempval;
   187 
   185 
   188 #ifdef TEXT_INSERTION_IN_PORTRAIT_ONLY
   186 #ifdef TEXT_INSERTION_IN_PORTRAIT_ONLY
   189     // Text input is always insterted in portrait mode.
   187 	// Text input is always insterted in portrait mode.
   190 	// Store the original orientation before forcing to portrait.
   188 	// Store the original orientation before forcing to portrait.
   191     CAknAppUiBase* appUi = static_cast<CAknAppUiBase *>( 
   189 	CAknAppUiBase* appUi = static_cast<CAknAppUiBase *>(
   192     	CEikonEnv::Static()->EikAppUi() );
   190 			CEikonEnv::Static()->EikAppUi() );
   193 	CAknAppUiBase::TAppUiOrientation originalOrientation = 
   191 	CAknAppUiBase::TAppUiOrientation originalOrientation =
   194 		appUi->Orientation();
   192 	appUi->Orientation();
   195     appUi->SetOrientationL(CAknAppUiBase::EAppUiOrientationPortrait);
   193 	appUi->SetOrientationL(CAknAppUiBase::EAppUiOrientationPortrait);
   196 #endif
   194 #endif
   197 
   195 
   198     iControl = CImageEditorDrawControl::NewL (aRect, aParent);
   196 	CalculatePositionOnView();
   199     aPluginControl = iControl;
   197 
   200     
   198 	iControl = CImageEditorDrawControl::NewL(aRect, aParent, iPaths, iRgb, iSize,iDiplayToolPluginParam);
   201     //  Set system parameters
   199 	aPluginControl = iControl;
   202     ((CImageEditorDrawControl*)iControl)->SetSystemParameters (iSysPars);
   200 
   203 
   201 	//  Set system parameters
   204     iLandscapeEnabled = ETrue;
   202 	((CImageEditorDrawControl*) iControl)->SetSystemParameters(iSysPars);
   205     
   203 
       
   204 	iVisibleImageRectPrevFirst = iSysPars->VisibleImageRectPrev();
       
   205 
       
   206 	iLandscapeEnabled = ETrue;
   206 
   207 
   207 #ifdef TEXT_INSERTION_IN_PORTRAIT_ONLY
   208 #ifdef TEXT_INSERTION_IN_PORTRAIT_ONLY
   208     // Set always back to original orientation, even if leaves
   209 	// Set always back to original orientation, even if leaves
   209 	CAknAppUiBase::TAppUiOrientation orientation = appUi->Orientation();
   210 	CAknAppUiBase::TAppUiOrientation orientation = appUi->Orientation();
   210 
   211 
   211 	if (orientation != originalOrientation)
   212 	if (orientation != originalOrientation)
   212 		{
   213 		{
   213 		appUi->SetOrientationL(originalOrientation);
   214 		appUi->SetOrientationL(originalOrientation);
   215 		// Send screen device change event to validate screen
   216 		// Send screen device change event to validate screen
   216 		TWsEvent event;
   217 		TWsEvent event;
   217 
   218 
   218 		RWsSession& rws = CEikonEnv::Static()->WsSession();
   219 		RWsSession& rws = CEikonEnv::Static()->WsSession();
   219 		event.SetType( EEventScreenDeviceChanged );
   220 		event.SetType( EEventScreenDeviceChanged );
   220 		event.SetTimeNow(); 
   221 		event.SetTimeNow();
   221 		event.SetHandle( rws.WsHandle() ); 
   222 		event.SetHandle( rws.WsHandle() );
   222 
   223 
   223 		User::LeaveIfError( rws.SendEventToAllWindowGroups(event) );
   224 		User::LeaveIfError( rws.SendEventToAllWindowGroups(event) );
   224 		}
   225 		}
   225 #else
   226 #else
   226 #ifdef LANDSCAPE_ONLY
   227 #ifdef LANDSCAPE_ONLY
   230 	// Send screen device change event to validate screen
   231 	// Send screen device change event to validate screen
   231 	TWsEvent event;
   232 	TWsEvent event;
   232 
   233 
   233 	RWsSession& rws = CEikonEnv::Static()->WsSession();
   234 	RWsSession& rws = CEikonEnv::Static()->WsSession();
   234 	event.SetType( EEventScreenDeviceChanged );
   235 	event.SetType( EEventScreenDeviceChanged );
   235 	event.SetTimeNow(); 
   236 	event.SetTimeNow();
   236 	event.SetHandle( rws.WsHandle() ); 
   237 	event.SetHandle( rws.WsHandle() );
   237 
   238 
   238 	User::LeaveIfError( rws.SendEventToAllWindowGroups(event) );
   239 	User::LeaveIfError( rws.SendEventToAllWindowGroups(event) );
   239 	
   240 
   240 #endif
   241 #endif
   241 #endif
   242 #endif
   242 
   243 
   243     return KErrNone;
   244 	return KErrNone;
   244 	}
   245 	}
   245 
   246 
   246 // ---------------------------------------------------------------------------
   247 // ---------------------------------------------------------------------------
   247 // ProcessImageL
   248 // ProcessImageL
   248 // ---------------------------------------------------------------------------
   249 // ---------------------------------------------------------------------------
   249 //
   250 //
   250 void CImageEditorDrawPlugin::ProcessImageL(CEditorImage * /*aImage*/ )
   251 void CImageEditorDrawPlugin::ProcessImageL(CEditorImage * /*aImage*/)
   251 	{
   252 	{
   252 	}
   253 	}
   253 
   254 
   254 // ---------------------------------------------------------------------------
   255 // ---------------------------------------------------------------------------
   255 // ReleasePlugin
   256 // ReleasePlugin
   258 void CImageEditorDrawPlugin::ReleasePlugin()
   259 void CImageEditorDrawPlugin::ReleasePlugin()
   259 	{
   260 	{
   260 	delete iControl;
   261 	delete iControl;
   261 	iControl = NULL;
   262 	iControl = NULL;
   262 	}
   263 	}
       
   264 // ---------------------------------------------------------------------------
       
   265 // CalculatePositionOnView
       
   266 // ---------------------------------------------------------------------------
       
   267 //
       
   268 void CImageEditorDrawPlugin::CalculatePositionOnView()
       
   269 	{
       
   270 	if (iPaths.Count() > 0)
       
   271 		{
       
   272 		// new image rect on preview
       
   273 		TRect rectPrevLast = iSysPars->VisibleImageRectPrev(); 
       
   274 		//real image rect
       
   275 		TRect rectReal = iSysPars->VisibleImageRect();  
       
   276 		//the old position of old image rect
       
   277 		TInt xPositionPrevFirst = iVisibleImageRectPrevFirst.iTl.iX; 
       
   278 		TInt yPositionPrevFirst = iVisibleImageRectPrevFirst.iTl.iY;
       
   279 		//the old width and height of old image rect
       
   280 		TInt xPosFactorDivider = iVisibleImageRectPrevFirst.Width();
       
   281 		TInt yPosFactorDivider = iVisibleImageRectPrevFirst.Height();
       
   282 
       
   283 		for (TInt i(0); i < iPaths.Count(); ++i)
       
   284 			{
       
   285 			CDrawPath* path = iPaths[i];
       
   286 			CArrayFix<TPoint>* pathPoints = path->ItemArray();
       
   287 			if (pathPoints && (pathPoints->Count() > 0))
       
   288 				{
       
   289 				for (TInt i(0); i < pathPoints->Count(); ++i)
       
   290 					{
       
   291 					//the old absolute point on screen 
       
   292 					TPoint & point = (*pathPoints)[i];
       
   293 					//the relative position on old image rect
       
   294 					TInt xPositionCompareFirst = point.iX - xPositionPrevFirst;
       
   295 					TInt yPositionCompareFirst = point.iY - yPositionPrevFirst;
       
   296 					//the relative position on new image rect
       
   297 					TReal xPositionCompareLast = TReal(rectPrevLast.Width()
       
   298 							* xPositionCompareFirst)
       
   299 							/ iVisibleImageRectPrevFirst.Width();
       
   300 					TReal yPositionCompareLast = TReal(rectPrevLast.Height()
       
   301 							* yPositionCompareFirst)
       
   302 							/ iVisibleImageRectPrevFirst.Height();
       
   303 					//the new absolute position on screen
       
   304 					TInt xPositionOnView = rectPrevLast.iTl.iX
       
   305 							+ xPositionCompareLast;
       
   306 					TInt yPositionOnView = rectPrevLast.iTl.iY
       
   307 							+ yPositionCompareLast;
       
   308 					point.SetXY(xPositionOnView, yPositionOnView);
       
   309 					}
       
   310 				}
       
   311 			}
       
   312 		}
       
   313 	}
   263 
   314 
   264 // End of File
   315 // End of File