imageeditor/plugins/DrawPlugin/src/CustomerComponet.cpp
changeset 8 18b321db4884
equal deleted inserted replaced
1:edfc90759b9f 8:18b321db4884
       
     1 /*
       
     2  ============================================================================
       
     3  Name		: CustomerComponet.cpp
       
     4  Author	  : henry
       
     5  Version	 : 1.0
       
     6  Copyright   : Your copyright notice
       
     7  Description : CCustomerComponet implementation
       
     8  ============================================================================
       
     9  */
       
    10 
       
    11 #include "CustomerComponet.h"
       
    12 #include "gdi.h"
       
    13 #include <eikdef.h>
       
    14 #include "imageditorfilterdraw.mbg"
       
    15 #include <eikenv.h>
       
    16 #include <akniconutils.h>
       
    17 #include <aknnotewrappers.h>
       
    18 
       
    19 // ---------------------------------------------------------------------------
       
    20 // Default constructer
       
    21 // ---------------------------------------------------------------------------
       
    22 //
       
    23 CCustomerComponet::CCustomerComponet()
       
    24 	{
       
    25 	// No implementation required
       
    26 	}
       
    27 
       
    28 CCustomerComponet::~CCustomerComponet()
       
    29 	{
       
    30 	if (iMenu)
       
    31 		{
       
    32 		delete iMenu;
       
    33 		iMenu = NULL;
       
    34 		}
       
    35 	if (iRight)
       
    36 		{
       
    37 		delete iRight;
       
    38 		iRight = NULL;
       
    39 		}
       
    40 	if (iLeft)
       
    41 		{
       
    42 		delete iLeft;
       
    43 		iLeft = NULL;
       
    44 		}
       
    45 	if (iTop)
       
    46 		{
       
    47 		delete iTop;
       
    48 		iTop = NULL;
       
    49 		}
       
    50 	if (iBottom)
       
    51 		{
       
    52 		delete iBottom;
       
    53 		iBottom = NULL;
       
    54 		}
       
    55 	if (iMenuMask)
       
    56 		{
       
    57 		delete iMenuMask;
       
    58 		iMenuMask = NULL;
       
    59 		}
       
    60 	if (iRightMask)
       
    61 		{
       
    62 		delete iRightMask;
       
    63 		iRightMask = NULL;
       
    64 		}
       
    65 	if (iLeftMask)
       
    66 		{
       
    67 		delete iLeftMask;
       
    68 		iLeftMask = NULL;
       
    69 		}
       
    70 	if (iTopMask)
       
    71 		{
       
    72 		delete iTopMask;
       
    73 		iTopMask = NULL;
       
    74 		}
       
    75 	if (iBottomMask)
       
    76 		{
       
    77 		delete iBottomMask;
       
    78 		iBottomMask = NULL;
       
    79 		}
       
    80 	}
       
    81 // ---------------------------------------------------------------------------
       
    82 // NewLC
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 CCustomerComponet* CCustomerComponet::NewLC(TRect & aRect, CCoeControl* aParent)
       
    86 	{
       
    87 	CCustomerComponet* self = new (ELeave) CCustomerComponet();
       
    88 	CleanupStack::PushL(self);
       
    89 	self->ConstructL(aRect, aParent);
       
    90 	return self;
       
    91 	}
       
    92 // ---------------------------------------------------------------------------
       
    93 // NewL
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 CCustomerComponet* CCustomerComponet::NewL(TRect & aRect, CCoeControl* aParent)
       
    97 	{
       
    98 	CCustomerComponet* self = CCustomerComponet::NewLC(aRect, aParent);
       
    99 	CleanupStack::Pop(); // self;
       
   100 	return self;
       
   101 	}
       
   102 // ---------------------------------------------------------------------------
       
   103 // ConstructL()
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 void CCustomerComponet::ConstructL(TRect & aRect, CCoeControl* aParent)
       
   107 	{
       
   108 	SetContainerWindowL(*aParent);
       
   109 	EnableDragEvents();
       
   110 	SetRect(aRect);
       
   111 	TRgb color = KRgbBlue;
       
   112 	//Set transparent effect
       
   113 	if (KErrNone == Window().SetTransparencyAlphaChannel())
       
   114 		{
       
   115 		color.SetAlpha(0);
       
   116 		}
       
   117 	Window().SetBackgroundColor(color);
       
   118 
       
   119 	iDrawDirection = EFalse;
       
   120 	
       
   121 	//Load pictures and mask
       
   122 	_LIT(iconFileName, "\\resource\\apps\\imageditorfilterdraw.mbm");
       
   123 	TFileName iconFile(iconFileName);
       
   124 	//Menu
       
   125 	AknIconUtils::CreateIconL(iMenu, iMenuMask, iconFileName,
       
   126 			EMbmImageditorfilterdraw15a, EMbmImageditorfilterdrawMenumask);
       
   127 	//Right
       
   128 	AknIconUtils::CreateIconL(iRight, iRightMask, iconFileName,
       
   129 			EMbmImageditorfilterdrawRight, EMbmImageditorfilterdrawRightmask);
       
   130 	//Left
       
   131 	AknIconUtils::CreateIconL(iLeft, iLeftMask, iconFileName,
       
   132 			EMbmImageditorfilterdrawLeft, EMbmImageditorfilterdrawLeftmask);
       
   133 	//Top
       
   134 	AknIconUtils::CreateIconL(iTop, iTopMask, iconFileName,
       
   135 			EMbmImageditorfilterdrawTop, EMbmImageditorfilterdrawTopmask);
       
   136 	//Bottom
       
   137 	AknIconUtils::CreateIconL(iBottom, iBottomMask, iconFileName,
       
   138 			EMbmImageditorfilterdrawBottom, EMbmImageditorfilterdrawBottommask);
       
   139 	
       
   140 	ActivateL();
       
   141 	}
       
   142 // ---------------------------------------------------------------------------
       
   143 // Draw
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 void CCustomerComponet::Draw(const TRect& aRect) const
       
   147 	{
       
   148 	CWindowGc& gc = SystemGc();
       
   149 	gc.Clear(aRect);
       
   150 	//Create rect for showing pictures.
       
   151 	TRect menuRect, topRect, bottomRect, rightRect, leftRect;
       
   152 
       
   153 	menuRect = aRect;
       
   154 	//get the width of the rect
       
   155 	TInt wx = aRect.iBr.iX - aRect.iTl.iX;
       
   156 	// get the height of the screen
       
   157 	TInt hy = aRect.iBr.iY - aRect.iTl.iY;
       
   158 	//Set top rect.
       
   159 	topRect.SetRect(TPoint(wx / 3 + aRect.iTl.iX, aRect.iTl.iY), TPoint(
       
   160 			(wx / 3) * 2 + aRect.iTl.iX, hy / 3 + aRect.iTl.iY));
       
   161 	//Set bottom rect
       
   162 	bottomRect.SetRect(TPoint((wx/3)+aRect.iTl.iX,(hy/3)*2+aRect.iTl.iY),
       
   163 			TPoint((wx/3)*2+aRect.iTl.iX,aRect.iBr.iY));
       
   164 	//set right rect.
       
   165 	rightRect.SetRect(TPoint(aRect.iTl.iX,hy/3+aRect.iTl.iY), TPoint(wx/3+aRect.iTl.iX,(hy/3)*2+aRect.iTl.iY));
       
   166 
       
   167 	//set left  rect.
       
   168 	leftRect.SetRect(TPoint((wx/3)*2+aRect.iTl.iX,hy/3+aRect.iTl.iY),
       
   169 			TPoint(aRect.iBr.iX,(hy/3)*2+aRect.iTl.iY));
       
   170 	//Set set size for pictures
       
   171 	
       
   172 	AknIconUtils::SetSize(iMenu, aRect.Size(), EAspectRatioPreserved);
       
   173 	AknIconUtils::SetSize(iMenuMask, aRect.Size(), EAspectRatioPreserved);
       
   174 
       
   175 	AknIconUtils::SetSize(iTop, topRect.Size(), EAspectRatioPreserved);
       
   176 	AknIconUtils::SetSize(iTopMask, topRect.Size(), EAspectRatioPreserved);
       
   177 
       
   178 	AknIconUtils::SetSize(iBottom, bottomRect.Size(), EAspectRatioPreserved);
       
   179 	AknIconUtils::SetSize(iBottomMask, bottomRect.Size(), EAspectRatioPreserved);
       
   180 
       
   181 	AknIconUtils::SetSize(iRight, rightRect.Size(), EAspectRatioPreserved);
       
   182 	AknIconUtils::SetSize(iRightMask, rightRect.Size(), EAspectRatioPreserved);
       
   183 
       
   184 	AknIconUtils::SetSize(iLeft, leftRect.Size(), EAspectRatioPreserved);
       
   185 	AknIconUtils::SetSize(iLeftMask, leftRect.Size(), EAspectRatioPreserved);
       
   186 	
       
   187 	//Draw menu
       
   188 	gc.DrawBitmapMasked(menuRect, iMenu, TRect(TPoint(0, 0),
       
   189 			iMenu->SizeInPixels()), iMenuMask, ETrue);
       
   190 	//if the user press the menu bottom show direction rect.
       
   191 	if (iDrawDirection)
       
   192 		{
       
   193 		gc.DrawBitmapMasked(topRect, iTop, TRect(TPoint(0, 0),
       
   194 				iTop->SizeInPixels()), iTopMask, ETrue);
       
   195 
       
   196 		gc.DrawBitmapMasked(bottomRect, iBottom, TRect(TPoint(0, 0),
       
   197 				iBottom->SizeInPixels()), iBottomMask, ETrue);
       
   198 		gc.DrawBitmapMasked(leftRect, iRight, TRect(TPoint(0, 0),
       
   199 				iRight->SizeInPixels()), iRightMask, ETrue);
       
   200 		gc .DrawBitmapMasked(rightRect, iLeft, TRect(TPoint(0, 0),
       
   201 				iLeft->SizeInPixels()), iLeftMask, ETrue);
       
   202 		}
       
   203 	}
       
   204 // ---------------------------------------------------------------------------
       
   205 // SetRect
       
   206 // ---------------------------------------------------------------------------
       
   207 //
       
   208 void CCustomerComponet::SetRect(TRect& aRect)
       
   209 	{
       
   210 	DrawNow(aRect);
       
   211 	}
       
   212 // ---------------------------------------------------------------------------
       
   213 // SizeChanged()
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 void CCustomerComponet::SizeChanged()
       
   217 	{
       
   218 //Nothing done here.
       
   219 	}
       
   220 // ---------------------------------------------------------------------------
       
   221 // HandlePointerEventL()
       
   222 // ---------------------------------------------------------------------------
       
   223 //
       
   224 void CCustomerComponet::HandlePointerEventL(const TPointerEvent& aPointerEvent)
       
   225 	{
       
   226 	switch (aPointerEvent.iType)
       
   227 		{
       
   228 		
       
   229 		case TPointerEvent::EButton1Down:
       
   230 			{
       
   231 			iDrawDirection = ETrue;
       
   232 			iButtonFlag = ETrue;
       
   233 			iPointerObserver->HandlePointerNotify(this);
       
   234 			DrawNow();
       
   235 			}
       
   236 			break;
       
   237 		case TPointerEvent::EButton1Up:
       
   238 			{
       
   239 			iDrawDirection = EFalse;
       
   240 			iButtonFlag = EFalse;
       
   241 			iPointerObserver->HandlePointerNotify(this);
       
   242 			DrawNow();
       
   243 			}
       
   244 			break;
       
   245 		case TPointerEvent::EDrag:
       
   246 			{
       
   247 			DrawNow();
       
   248 			}
       
   249 			break;
       
   250 		default:
       
   251 			break;
       
   252 		}
       
   253 	}
       
   254 // ---------------------------------------------------------------------------
       
   255 // SetHandlePointerObserver()
       
   256 // ---------------------------------------------------------------------------
       
   257 //
       
   258 void CCustomerComponet::SetHandlePointerObserver(
       
   259 		MHandlePointerObserver* aHandlePointerObserver)
       
   260 	{
       
   261 	iPointerObserver = aHandlePointerObserver;
       
   262 
       
   263 	}
       
   264 // ---------------------------------------------------------------------------
       
   265 // GetButtonType()
       
   266 // ---------------------------------------------------------------------------
       
   267 //
       
   268 TBool CCustomerComponet::GetButtonType()
       
   269 	{
       
   270 	return iButtonFlag;
       
   271 	}