imageeditor/plugins/DrawPlugin/src/selectionpopup.cpp
changeset 8 18b321db4884
parent 1 edfc90759b9f
equal deleted inserted replaced
1:edfc90759b9f 8:18b321db4884
    31 #include <BidiText.h> 
    31 #include <BidiText.h> 
    32 
    32 
    33 #include <ImageEditorUi.mbg>
    33 #include <ImageEditorUi.mbg>
    34 #include <ImageEditorUI.rsg>
    34 #include <ImageEditorUI.rsg>
    35 #include <draw.rsg>
    35 #include <draw.rsg>
       
    36 #include <drawpath.h>
    36 
    37 
    37 #include "ResolutionUtil.h"
    38 #include "ResolutionUtil.h"
    38 #include "selectionpopup.h"
    39 #include "selectionpopup.h"
    39 #include "ImageEditorUiDefs.h"
    40 #include "ImageEditorUiDefs.h"
    40 
    41 
    41 // CONSTANTS
    42 // CONSTANTS
    42 const TInt KGridColumnCount = 5;
    43 const TInt KGridColumnCount = 5;
    43 const TInt KGridRowCount = 1;
    44 const TInt KGridRowCount = 1;
    44 
    45 const TInt KPenSizeOffset = 153;
    45 
    46 
    46 //=============================================================================
    47 
    47 CSelectionPopup::CSelectionPopup()
    48 //=============================================================================
       
    49 CSelectionPopup::CSelectionPopup(TRgb& aCurrentColor, const TRect& aImageRect)
    48     {    
    50     {    
    49     // Set values into an array
    51     // Set values into an array
       
    52     iItemArray.Append( 2 ); //default: 4
    50     iItemArray.Append( 4 );
    53     iItemArray.Append( 4 );
    51     iItemArray.Append( 8 );
    54     iItemArray.Append( 8 );
    52     iItemArray.Append( 16 );
    55     iItemArray.Append( 16 );
    53     iItemArray.Append( 32 );
    56     iItemArray.Append( 32 );
    54     iItemArray.Append( 64 );
    57     
       
    58     //set defalut color
       
    59     iCurrentColor = aCurrentColor;
       
    60     
       
    61     iImageRect = aImageRect;
    55     }
    62     }
    56 
    63 
    57 //=============================================================================
    64 //=============================================================================
    58 CSelectionPopup::~CSelectionPopup()
    65 CSelectionPopup::~CSelectionPopup()
    59     {
    66     {
    85 //=============================================================================
    92 //=============================================================================
    86 void CSelectionPopup::ConstructL (	CCoeControl* aParent )
    93 void CSelectionPopup::ConstructL (	CCoeControl* aParent )
    87     {
    94     {
    88 	// Set parent
    95 	// Set parent
    89 	SetContainerWindowL( *aParent );  
    96 	SetContainerWindowL( *aParent );  
       
    97 
    90     TFileName iconFile( KImageEditorUiMifFile );
    98     TFileName iconFile( KImageEditorUiMifFile );
    91     
    99     
    92     // Create trans popup window graphics
   100     // Create trans popup window graphics
    93     // Center
   101     // Center
    94     AknIconUtils::CreateIconL( iPopupCenter, iPopupCenterMask, iconFile, 
   102     AknIconUtils::CreateIconL( iPopupCenter, iPopupCenterMask, iconFile, 
   132 	
   140 	
   133 	// bottom side
   141 	// bottom side
   134     AknIconUtils::CreateIconL( iPopupSideB, iPopupSideBMask, iconFile, 
   142     AknIconUtils::CreateIconL( iPopupSideB, iPopupSideBMask, iconFile, 
   135             EMbmImageeditoruiQgn_graf_popup_trans_side_b, 
   143             EMbmImageeditoruiQgn_graf_popup_trans_side_b, 
   136 			EMbmImageeditoruiQgn_graf_popup_trans_side_b_mask );						                                   
   144 			EMbmImageeditoruiQgn_graf_popup_trans_side_b_mask );						                                   
   137                         					
   145                    					
   138 	//	Activate control
   146 	//	Activate control
   139     ActivateL();
   147     ActivateL();
   140     
   148     
   141     }
   149     }
   142 
   150 
   143 //=============================================================================
   151 //=============================================================================
   144 void CSelectionPopup::CreateColorBitmapsL( TSize aSize )
   152 void CSelectionPopup::CreateColorBitmapsL( TSize /* aSize */ )
   145     {    
   153     {    
       
   154     //TODO: to set icon here
   146     // Generate color bitmaps    
   155     // Generate color bitmaps    
   147     iColorBitmapsArray.Reset();    
   156     iColorBitmapsArray.Reset(); 
   148     for( TInt i = 0; i < iItemArray.Count(); i++ )
   157     
       
   158     TSize size(2,2);
       
   159     for( TInt i = iItemArray.Count(); i > 0 ; i-- )
   149         {
   160         {
   150         CFbsBitmap* bitmap = new ( ELeave ) CFbsBitmap;
   161         CFbsBitmap* bitmap = new ( ELeave ) CFbsBitmap;
   151         CleanupStack::PushL( bitmap );
   162         CleanupStack::PushL( bitmap );
   152         User::LeaveIfError ( bitmap->Create ( aSize, EColor64K ) );
   163         User::LeaveIfError ( bitmap->Create ( size, EColor64K ) );
   153 
   164         size.iHeight*=2;
       
   165         size.iWidth*=2;
   154         //  Compute color for bitmap
   166         //  Compute color for bitmap
   155         TRgb color( KRgbBlack );//iRGBArray[i] );		
   167         TRgb color( iCurrentColor );//iRGBArray[i] );		
   156          
   168          
   157     	//	Fill the bitmap with the correct color
   169     	//	Fill the bitmap with the correct color
   158     	TUint16 color_64k = ( TUint16 )
   170     	TUint16 color_64k = ( TUint16 )
   159     		(0 | 
   171     		(0 | 
   160     		((( TUint8 )color.Red() >> 3) << 11) | 
   172     		((( TUint8 )color.Red() >> 3) << 11) | 
   179         }    
   191         }    
   180     
   192     
   181     }
   193     }
   182     
   194     
   183 //=============================================================================
   195 //=============================================================================
   184 void CSelectionPopup::Draw( const TRect& /*aRect*/ ) const
   196 void CSelectionPopup::Draw( const TRect& aRect ) const
   185     {
   197     {
   186     const TRgb KHighlightCenterColor (229, 229, 229);
   198     const TRgb KHighlightCenterColor (229, 229, 229);
   187     
   199     
   188     CWindowGc& gc = SystemGc();
   200     CWindowGc& gc = SystemGc();
   189     
   201      
   190     CPreviewControlBase::DrawPreviewImage (Rect());
       
   191     
       
   192     // Change brush to null to enable transparent drawing
   202     // Change brush to null to enable transparent drawing
   193     gc.SetBrushStyle (CGraphicsContext::ENullBrush);
   203     gc.SetBrushStyle (CGraphicsContext::ENullBrush);
   194                 
   204                 
   195     // draw center of the borders
   205     // draw center of the borders
   196     gc.BitBltMasked( iPopupCenterRect.iTl, iPopupCenter, 
   206     gc.BitBltMasked( iPopupCenterRect.iTl, iPopupCenter, 
   235             gc.SetBrushStyle (CGraphicsContext::ENullBrush);            
   245             gc.SetBrushStyle (CGraphicsContext::ENullBrush);            
   236             }
   246             }
   237             
   247             
   238         // draw color bitmap    
   248         // draw color bitmap    
   239         TRect currentRect = iGridRectsArray[index];
   249         TRect currentRect = iGridRectsArray[index];
       
   250         currentRect.iTl.iX = currentRect.iTl.iX + (currentRect.iBr.iX - currentRect.iTl.iX)/2 - iItemArray[index]/2;
       
   251         currentRect.iTl.iY = currentRect.iTl.iY + (currentRect.iBr.iY - currentRect.iTl.iY)/2 - iItemArray[index]/2;
   240         gc.BitBlt(currentRect.iTl, iColorBitmapsArray[index]);
   252         gc.BitBlt(currentRect.iTl, iColorBitmapsArray[index]);
   241         }
   253         }
   242                   
   254                   
   243      // Draw heading  
   255      // Draw heading  
   244      // Convert the plug-in name to visual representation
   256      // Convert the plug-in name to visual representation
   254          visual,
   266          visual,
   255          *font,
   267          *font,
   256          iHeadingRect.Width(),
   268          iHeadingRect.Width(),
   257          iHeadingRect.Width()
   269          iHeadingRect.Width()
   258          );
   270          );
   259             
   271         
   260      CleanupStack::PopAndDestroy( heading );
   272      CleanupStack::PopAndDestroy( heading );
   261         
   273         
   262      gc.UseFont( font );
   274      gc.UseFont( font );
   263      gc.SetBrushStyle ( CGraphicsContext::ENullBrush );
   275      gc.SetBrushStyle ( CGraphicsContext::ENullBrush );
   264 
   276 
   267      // Check the directionality of the current language and set the alignment
   279      // Check the directionality of the current language and set the alignment
   268      // according the directionality
   280      // according the directionality
   269      TBidiText::TDirectionality dir = TBidiText::ScriptDirectionality(User::Language());
   281      TBidiText::TDirectionality dir = TBidiText::ScriptDirectionality(User::Language());
   270      CGraphicsContext::TTextAlign align = CGraphicsContext::ELeft;
   282      CGraphicsContext::TTextAlign align = CGraphicsContext::ELeft;
   271 
   283 
   272      if( dir == TBidiText::ERightToLeft )
   284      if (dir == TBidiText::ERightToLeft)
   273         {
   285 		{
   274         align = CGraphicsContext::ERight;
   286 		align = CGraphicsContext::ERight;
   275         }
   287 		}
   276         gc.SetPenColor(KRgbWhite);
   288 	gc.SetPenColor(KRgbWhite);
   277         gc.DrawText(
   289 	gc.DrawText(visual, iHeadingRect, baseline, align, 0);
   278             visual,
   290 
   279             iHeadingRect,
       
   280             baseline,
       
   281             align,
       
   282             0);
       
   283     }
   291     }
   284     
   292     
   285 //=============================================================================    
   293 //=============================================================================    
   286 void CSelectionPopup::SizeChanged()
   294 void CSelectionPopup::SizeChanged()
   287     {
   295     {
   288     
   296     
   289     TAknLayoutRect layoutRect;
   297     TAknLayoutRect layoutRect;
   290     layoutRect.LayoutRect( Rect(), AknLayoutScalable_Apps::popup_imed_trans_window(0) );
   298     layoutRect.LayoutRect( Rect(), AknLayoutScalable_Apps::popup_imed_trans_window(0) );
   291     TRect parentRect = layoutRect.Rect();
   299     TRect parentRect = layoutRect.Rect();
   292             
   300     
       
   301     if(parentRect.iTl.iX > parentRect.iTl.iY)
       
   302     	{
       
   303     	 parentRect.SetRect(parentRect.iTl.iX-KPenSizeOffset,parentRect.iTl.iY,parentRect.iBr.iX-KPenSizeOffset,parentRect.iBr.iY);      
       
   304     	}
       
   305    
   293 	TAknLayoutRect iconLayout;
   306 	TAknLayoutRect iconLayout;
   294 	iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g1());
   307 	iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g1());
   295 	iPopupCenterRect = iconLayout.Rect();
   308 	iPopupCenterRect = iconLayout.Rect();
   296 	
   309 	
   297 	iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g2());
   310 	iconLayout.LayoutRect( parentRect, AknLayoutScalable_Avkon::bg_tb_trans_pane_g2());
   322 	TRect listscrollPaneRect = iconLayout.Rect();
   335 	TRect listscrollPaneRect = iconLayout.Rect();
   323 	
   336 	
   324 	iconLayout.LayoutRect( listscrollPaneRect, AknLayoutScalable_Apps::grid_imed_colour_35_pane( 1 ));
   337 	iconLayout.LayoutRect( listscrollPaneRect, AknLayoutScalable_Apps::grid_imed_colour_35_pane( 1 ));
   325 	TRect gridPaneRect = iconLayout.Rect();
   338 	TRect gridPaneRect = iconLayout.Rect();
   326 	
   339 	
   327 	// Calculate grid's cell rects
       
   328 	iHighlightRectsArray.Reset();
   340 	iHighlightRectsArray.Reset();
   329 	iGridRectsArray.Reset();
   341 	iGridRectsArray.Reset();
   330 	for( TInt row = 0; row < KGridRowCount; row++ )
   342 	for( TInt row = 0; row < KGridRowCount; row++ )
   331 	    {
   343 	    {
   332 	    for( TInt column = 0; column < KGridColumnCount; column++ )
   344 	    for( TInt column = 0; column < KGridColumnCount; column++ )
   337 	        iHighlightRectsArray.Append( highlightRect );
   349 	        iHighlightRectsArray.Append( highlightRect );
   338 	        
   350 	        
   339 	        iconLayout.LayoutRect( highlightRect, 
   351 	        iconLayout.LayoutRect( highlightRect, 
   340 	                               AknLayoutScalable_Apps::cell_imed_colour_pane_g1(0) );	       
   352 	                               AknLayoutScalable_Apps::cell_imed_colour_pane_g1(0) );	       
   341 	        
   353 	        
   342 	        iGridRectsArray.Append( iconLayout.Rect() );
   354 	        iGridRectsArray.Append(iconLayout.Rect());
   343 	        
       
   344 	        }
   355 	        }
   345 	    }	
   356 	    }	
   346 
   357 
   347     CreateColorBitmapsL( iconLayout.Rect().Size() );
   358     CreateColorBitmapsL( iconLayout.Rect().Size() );
   348     
   359     
   606 
   617 
   607 
   618 
   608 //=============================================================================
   619 //=============================================================================
   609 // DIALOG
   620 // DIALOG
   610 //=============================================================================
   621 //=============================================================================
   611 TInt CSelectionDialog::RunDlgLD( const CFbsBitmap* aBitmap, 
   622 TInt CSelectionDialog::RunDlgLD( const CFbsBitmap* aBitmap,
   612                                       const TRect& aRect, 
   623                                       const TRect& aRect, 
   613                                       TInt& aSelection )
   624                                       TInt& aSelection,
       
   625                                       TRgb& aCurrentColor,
       
   626                                       const TRect& aImageRect)
   614     {
   627     {
   615     CSelectionDialog* dialog = 
   628     CSelectionDialog* dialog = 
   616         new (ELeave) CSelectionDialog ( aSelection );
   629         new (ELeave) CSelectionDialog ( aSelection);
   617     dialog->ConstructL( aBitmap, aRect);
   630     dialog->ConstructL( aBitmap, aRect, aCurrentColor, aImageRect);
   618     return dialog->ExecuteLD( R_IMAGE_EDITOR_COLOR_DIALOG );
   631     return dialog->ExecuteLD( R_IMAGE_EDITOR_COLOR_DIALOG );
   619     }
   632     }
   620 
   633 
   621 //=============================================================================
   634 //=============================================================================
   622 CSelectionDialog::CSelectionDialog( TInt& aSelection )
   635 CSelectionDialog::CSelectionDialog( TInt& aSelection)
   623 : iCurrentValue( aSelection )
   636 : iCurrentValue( aSelection )
   624     {
   637     {
   625     }
   638     }
   626     
   639     
   627 //=============================================================================
   640 //=============================================================================
   630     delete iPopup;
   643     delete iPopup;
   631     }
   644     }
   632 
   645 
   633 //=============================================================================
   646 //=============================================================================
   634 
   647 
   635 void CSelectionDialog::ConstructL( const CFbsBitmap* aBitmap,
   648 void CSelectionDialog::ConstructL( const CFbsBitmap* aBitmap,	
   636                                         const TRect& aRect )
   649                                         const TRect& aRect,
       
   650                                         TRgb& aCurrentColor,
       
   651                                         const TRect& aImageRect)
   637     {    
   652     {    
   638     iPopup = new ( ELeave ) CSelectionPopup();
   653     iPopup = new ( ELeave ) CSelectionPopup(aCurrentColor, aImageRect);
   639     iPopup->SetSelectedValue( iCurrentValue);
   654     iPopup->SetSelectedValue(iCurrentValue);
   640     iPopup->ConstructL( this );
   655     iPopup->ConstructL(this);
   641     
   656     
   642     SetRect(aRect);   
   657     SetRect(aRect);   
   643     
   658     
   644     // Not drawn correctly if calling SetRect()
   659     // Not drawn correctly if calling SetRect()
   645     iPopup->SetSize(aRect.Size());
   660     iPopup->SetSize(aRect.Size());
   646     iPopup->SetPosition(TPoint(0,0));
   661     iPopup->SetPosition(TPoint(0,0));
   647     iPopup->SetImageL( aBitmap );
   662     iPopup->SetImageL( aBitmap ); // set the image which we are editing
   648     }
   663     }
   649 
   664 
   650 //=============================================================================
   665 //=============================================================================
   651 TBool CSelectionDialog::OkToExitL( TInt aButtonId )
   666 TBool CSelectionDialog::OkToExitL( TInt aButtonId )
   652     {
   667     {
   742 void CSelectionDialog::HandlePointerEventL( 
   757 void CSelectionDialog::HandlePointerEventL( 
   743                                            const TPointerEvent &aPointerEvent )
   758                                            const TPointerEvent &aPointerEvent )
   744     {    
   759     {    
   745     if( AknLayoutUtils::PenEnabled() )
   760     if( AknLayoutUtils::PenEnabled() )
   746 	    {
   761 	    {
   747         TBool draw( EFalse );
       
   748         switch( aPointerEvent.iType )
   762         switch( aPointerEvent.iType )
   749 			{
   763 			{
   750 			case TPointerEvent::EButton1Down:
   764 			case TPointerEvent::EButton1Down:
   751 				{				
   765 				{				
   752 			    // forward event only if grid area was pressed    
   766 			    // forward event only if grid area was pressed    
   753 			    if ( iPopup->GridRect().Contains( aPointerEvent.iPosition ) )
   767 			    if ( iPopup->GridRect().Contains( aPointerEvent.iPosition ) )
   754 			        {			        
   768 			        {			        
   755 			        iPopup->HandlePointerEventL( aPointerEvent );			        
   769 			        iPopup->HandlePointerEventL( aPointerEvent );
   756 			        draw = ETrue;
       
   757 			        }    		        
   770 			        }    		        
   758 				break;
   771 				break;
   759 				}
   772 				}
   760 			case TPointerEvent::EDrag:
   773 			case TPointerEvent::EDrag:
   761 				{
   774 				{
   762 			    if ( iPopup->GridRect().Contains( aPointerEvent.iPosition ) )
   775 			    if ( iPopup->GridRect().Contains( aPointerEvent.iPosition ) )
   763 			        {
   776 			        {
   764 			        iPopup->HandlePointerEventL( aPointerEvent );
   777 			        iPopup->HandlePointerEventL( aPointerEvent );
   765 			        draw = ETrue;
       
   766 			        }
   778 			        }
   767 				break;		
   779 				break;		
   768 				}
   780 				}
   769 			case TPointerEvent::EButton1Up:
   781 			case TPointerEvent::EButton1Up:
   770 				{
   782 				{
   778 			default:
   790 			default:
   779 				{
   791 				{
   780 				break;	
   792 				break;	
   781 				}	
   793 				}	
   782 			}
   794 			}
   783 			
       
   784 	    if ( draw )
       
   785 	        {
       
   786 		    DrawDeferred();    
       
   787 	        }	
       
   788         }
   795         }
   789     }
   796     }
   790     
   797     
   791 // End of file 
   798 // End of file 
   792 
   799