imageeditor/ImageEditorUI/src/HorizontalSlider.cpp
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 *
       
    17 */
       
    18 
       
    19 
       
    20 //	INCLUDE
       
    21 #include <fbs.h>
       
    22 #include <aknutils.h>
       
    23 #include <ImageEditorUI.rsg>
       
    24 #include <AknLayoutScalable_Avkon.cdl.h>
       
    25 #include <AknLayoutScalable_Apps.cdl.h>
       
    26 
       
    27 #include <AknIconUtils.h>
       
    28 #include <ImageEditorUi.mbg>
       
    29 #include "ResolutionUtil.h"
       
    30 #include "ImageEditorUiDefs.h"
       
    31 #include "HorizontalSlider.h"
       
    32 #include "CustomControlPanics.h"
       
    33 
       
    34 // constants
       
    35 const TInt KBorderPartsNum = 9; 
       
    36 const TInt KSliderPartsNum = 4; 
       
    37 
       
    38 //=============================================================================
       
    39 EXPORT_C CHorizontalSlider* CHorizontalSlider::NewL(const TRect& aRect, const CCoeControl& aControl)
       
    40     {
       
    41     CHorizontalSlider* self = CHorizontalSlider::NewLC(aRect, aControl);
       
    42     CleanupStack::Pop(self);
       
    43     return self;
       
    44     }
       
    45 
       
    46 //=============================================================================
       
    47 EXPORT_C CHorizontalSlider* CHorizontalSlider::NewLC(const TRect& aRect, const CCoeControl& aControl)
       
    48     {
       
    49     CHorizontalSlider* self = new (ELeave) CHorizontalSlider;
       
    50     CleanupStack::PushL(self);
       
    51     self->ConstructL(aRect, aControl);
       
    52     return self;
       
    53     }
       
    54 
       
    55 //=============================================================================
       
    56 EXPORT_C CHorizontalSlider::~CHorizontalSlider()
       
    57     {
       
    58     iBorders.ResetAndDestroy();
       
    59     iScrollBar.ResetAndDestroy();
       
    60 	if (iIcon)
       
    61 		{
       
    62 	    delete iIcon;
       
    63 		}
       
    64     }
       
    65 
       
    66 //=============================================================================
       
    67 void CHorizontalSlider::ConstructL(const TRect& aRect, const CCoeControl& aControl)
       
    68     {
       
    69 	SetContainerWindowL(aControl);
       
    70     SetRect(aRect);
       
    71 
       
    72     TInt variant = 0;
       
    73     TFileName iconFile (KImageEditorUiMifFile);
       
    74 
       
    75 	// create popup and slider graphics
       
    76     for ( TInt i = 0; i < KBorderPartsNum; ++i )
       
    77         {
       
    78         CEikImage* image = new (ELeave) CEikImage;
       
    79 
       
    80 		image->CreatePictureFromFileL(iconFile,
       
    81 										EMbmImageeditoruiQgn_graf_popup_trans_center + 2*i,
       
    82 										EMbmImageeditoruiQgn_graf_popup_trans_center_mask + 2*i);
       
    83 
       
    84         CleanupStack::PushL( image );
       
    85         image->SetContainerWindowL( *this );
       
    86 //        image->SetPictureOwnedExternally( ETrue );
       
    87         iBorders.AppendL( image );
       
    88         CleanupStack::Pop( image );
       
    89         }
       
    90     for ( TInt i = 0; i < KSliderPartsNum; ++i )
       
    91         {
       
    92         CEikImage* image = new (ELeave) CEikImage;
       
    93 
       
    94 		image->CreatePictureFromFileL(iconFile,
       
    95 										EMbmImageeditoruiQgn_graf_nslider_imed_end_left + 2*i,
       
    96 										EMbmImageeditoruiQgn_graf_nslider_imed_end_left_mask + 2*i);
       
    97 
       
    98         CleanupStack::PushL( image );
       
    99         image->SetContainerWindowL( *this );
       
   100 //        image->SetPictureOwnedExternally( ETrue );
       
   101         iScrollBar.AppendL( image );
       
   102         CleanupStack::Pop( image );
       
   103         }
       
   104 
       
   105 	ActivateL();
       
   106     }
       
   107 
       
   108 //=============================================================================
       
   109 CHorizontalSlider::CHorizontalSlider()
       
   110     {
       
   111     // no implementation required
       
   112     }
       
   113 
       
   114 //=============================================================================
       
   115 EXPORT_C TInt CHorizontalSlider::CountComponentControls() const
       
   116     {
       
   117     TInt count = iBorders.Count();
       
   118     count += iScrollBar.Count();
       
   119 	if (iIcon)
       
   120 		{
       
   121 		count++;
       
   122 		}
       
   123 
       
   124     return count;
       
   125     }
       
   126 
       
   127 //=============================================================================
       
   128 void CHorizontalSlider::Draw(const TRect& /*aRect*/) const
       
   129 	{
       
   130 	// determine popup border layouts
       
   131     AknLayoutUtils::LayoutControl( iBorders[0], Rect(), AknLayoutScalable_Avkon::bg_tb_trans_pane_g1().LayoutLine() );
       
   132     AknLayoutUtils::LayoutControl( iBorders[1], Rect(), AknLayoutScalable_Avkon::bg_tb_trans_pane_g2().LayoutLine() );
       
   133     AknLayoutUtils::LayoutControl( iBorders[2], Rect(), AknLayoutScalable_Avkon::bg_tb_trans_pane_g3().LayoutLine() );
       
   134     AknLayoutUtils::LayoutControl( iBorders[3], Rect(), AknLayoutScalable_Avkon::bg_tb_trans_pane_g4().LayoutLine() );
       
   135     AknLayoutUtils::LayoutControl( iBorders[4], Rect(), AknLayoutScalable_Avkon::bg_tb_trans_pane_g5().LayoutLine() );
       
   136     AknLayoutUtils::LayoutControl( iBorders[5], Rect(), AknLayoutScalable_Avkon::bg_tb_trans_pane_g6().LayoutLine() );
       
   137     AknLayoutUtils::LayoutControl( iBorders[6], Rect(), AknLayoutScalable_Avkon::bg_tb_trans_pane_g7().LayoutLine() );
       
   138     AknLayoutUtils::LayoutControl( iBorders[7], Rect(), AknLayoutScalable_Avkon::bg_tb_trans_pane_g8().LayoutLine() );
       
   139     AknLayoutUtils::LayoutControl( iBorders[8], Rect(), AknLayoutScalable_Avkon::bg_tb_trans_pane_g9().LayoutLine() );
       
   140     // Images need to be resized separately, because the standard LayoutImage
       
   141     // tries to preserve the aspect ratio and we don't want that.
       
   142     //
       
   143     for ( TInt i = 0; i < iBorders.Count(); ++i )
       
   144         {
       
   145         AknIconUtils::SetSize(
       
   146             const_cast<CFbsBitmap*>( iBorders[i]->Bitmap() ),
       
   147             iBorders[i]->Size(), EAspectRatioNotPreserved );
       
   148         }
       
   149 
       
   150 	// determine icon layout
       
   151     AknLayoutUtils::LayoutControl( iIcon,  Rect(), AknLayoutScalable_Apps::popup_imed_adjust2_window_g1().LayoutLine() );
       
   152     AknIconUtils::SetSize(
       
   153         const_cast<CFbsBitmap*>( iIcon->Bitmap() ),
       
   154         iIcon->Size(), EAspectRatioNotPreserved );
       
   155 
       
   156 	// determine caption layout
       
   157     TAknLayoutText layoutText;
       
   158     layoutText.LayoutText( Rect(), AknLayoutScalable_Apps::popup_imed_adjust2_window_t1() );
       
   159     TRgb color = layoutText.Color();
       
   160     layoutText.DrawText( SystemGc(), iText, ETrue, color );
       
   161 
       
   162 	// determine scrollbar layouts
       
   163     TAknWindowComponentLayout l = AknLayoutScalable_Apps::slider_imed_adjust_pane();
       
   164     TAknWindowLineLayout lineLayout = l.LayoutLine();
       
   165     TAknLayoutRect layoutRect;
       
   166     layoutRect.LayoutRect(Rect(), lineLayout);
       
   167     AknLayoutUtils::LayoutControl( iScrollBar[0], layoutRect.Rect(), AknLayoutScalable_Apps::slider_imed_adjust_pane_g1().LayoutLine() );
       
   168     AknLayoutUtils::LayoutControl( iScrollBar[1], layoutRect.Rect(), AknLayoutScalable_Apps::slider_imed_adjust_pane_g2().LayoutLine() );
       
   169     AknLayoutUtils::LayoutControl( iScrollBar[2], layoutRect.Rect(), AknLayoutScalable_Apps::slider_imed_adjust_pane_g3().LayoutLine() );
       
   170     AknLayoutUtils::LayoutControl( iScrollBar[3], layoutRect.Rect(), AknLayoutScalable_Apps::slider_imed_adjust_pane_g4().LayoutLine() );
       
   171     for ( TInt i = 0; i < iScrollBar.Count(); ++i )
       
   172         {
       
   173         AknIconUtils::SetSize(
       
   174             const_cast<CFbsBitmap*>( iScrollBar[i]->Bitmap() ),
       
   175             iScrollBar[i]->Size(), EAspectRatioNotPreserved );
       
   176         }
       
   177 
       
   178 	// determine scrollbar marker layout
       
   179     if ( iMinimumValue <= iMaximumValue )
       
   180 	    {
       
   181         TUint length = iMaximumValue - iMinimumValue; // length of the slider
       
   182         TUint pixelsFromMin = iPosition - iMinimumValue; // tab position from the beginning
       
   183     
       
   184         TReal factor = 0.0;
       
   185         if (iMinimumValue < iMaximumValue )
       
   186         {
       
   187             factor = (TReal) pixelsFromMin / length; // tab position from the beginning in percentage
       
   188         }
       
   189 
       
   190         TUint sliderTabWidth = iScrollBar[KSliderPartsNum - 1]->Size().iWidth; // slider tab width
       
   191 
       
   192         // slider bitmap is actually a bit longer but this resolves the problem
       
   193         // where the tab is drawn outside of the slider when in maximum position
       
   194         TUint sliderBitmapWidth = layoutRect.Rect().Width() - sliderTabWidth;
       
   195     
       
   196         TInt tabPositionFromMinInPixels = (TInt) ((factor * sliderBitmapWidth + 0.5) - (sliderBitmapWidth / 2)); // calculate tab position
       
   197 
       
   198 		TRect markerRect = layoutRect.Rect();
       
   199 		markerRect.iTl.iX += tabPositionFromMinInPixels;
       
   200 
       
   201 	    AknLayoutUtils::LayoutControl( iScrollBar[KSliderPartsNum - 1], markerRect, AknLayoutScalable_Apps::slider_imed_adjust_pane_g4().LayoutLine() );
       
   202 
       
   203         AknIconUtils::SetSize(
       
   204             const_cast<CFbsBitmap*>( iScrollBar[KSliderPartsNum - 1]->Bitmap() ),
       
   205             iScrollBar[KSliderPartsNum - 1]->Size(), EAspectRatioNotPreserved );
       
   206 	    }
       
   207 	}
       
   208 
       
   209 //=============================================================================
       
   210 EXPORT_C CCoeControl* CHorizontalSlider::ComponentControl(TInt aIndex) const
       
   211     {
       
   212     if ( aIndex < iBorders.Count() )
       
   213         {
       
   214         return iBorders[aIndex];
       
   215         }
       
   216 
       
   217     if ( aIndex < iBorders.Count() + iScrollBar.Count())
       
   218         {
       
   219         return iScrollBar[aIndex - iBorders.Count()];
       
   220         }
       
   221     return iIcon;
       
   222     }
       
   223 
       
   224 // setters
       
   225 
       
   226 //=============================================================================
       
   227 EXPORT_C void CHorizontalSlider::SetIcon(CEikImage* aIcon)
       
   228 	{
       
   229 	iIcon = aIcon;
       
   230 	}
       
   231 
       
   232 //=============================================================================
       
   233 EXPORT_C void CHorizontalSlider::SetCaption(const TDesC& aText)
       
   234 	{
       
   235 	iText = aText;
       
   236 	}
       
   237 
       
   238 //=============================================================================
       
   239 EXPORT_C void CHorizontalSlider::SetMinimum(TInt aValue)
       
   240 	{
       
   241 	iMinimumValue = aValue;
       
   242 	}
       
   243 
       
   244 //=============================================================================
       
   245 EXPORT_C void CHorizontalSlider::SetMaximum(TInt aValue)
       
   246 	{
       
   247 	iMaximumValue = aValue;
       
   248 	}
       
   249 
       
   250 //=============================================================================
       
   251 EXPORT_C void CHorizontalSlider::SetStep(TUint aValue)
       
   252 	{
       
   253 	iStep = aValue;
       
   254 	}
       
   255 
       
   256 //=============================================================================
       
   257 EXPORT_C void CHorizontalSlider::SetStepAmount(TUint8 aValue)
       
   258 	{
       
   259 	iNumberOfSteps = aValue;
       
   260 	
       
   261 	if(aValue == 0)
       
   262 		{
       
   263 		iStep = 0;
       
   264 		}
       
   265 	else
       
   266 		{
       
   267 		iStep = (iMaximumValue-iMinimumValue) / aValue;
       
   268 		}
       
   269 	}
       
   270 
       
   271 //=============================================================================
       
   272 EXPORT_C void CHorizontalSlider::SetPosition(TInt aValue)
       
   273 	{
       
   274 	__ASSERT_ALWAYS( aValue >= iMinimumValue, Panic(EHorizontalSliderPanicIndexUnderflow) );
       
   275 	__ASSERT_ALWAYS( aValue <= iMaximumValue, Panic(EHorizontalSliderPanicIndexOverflow) );
       
   276 
       
   277 	iPosition = aValue;
       
   278 	}
       
   279 
       
   280 // getters
       
   281 
       
   282 //=============================================================================
       
   283 EXPORT_C TInt CHorizontalSlider::Minimum() const
       
   284 	{
       
   285 	return iMinimumValue;
       
   286 	}
       
   287 
       
   288 //=============================================================================
       
   289 EXPORT_C TInt CHorizontalSlider::Maximum() const
       
   290 	{
       
   291 	return iMaximumValue;
       
   292 	}
       
   293 
       
   294 //=============================================================================
       
   295 EXPORT_C TInt CHorizontalSlider::Step() const
       
   296 	{
       
   297 	return iStep;
       
   298 	}
       
   299 
       
   300 //=============================================================================
       
   301 EXPORT_C TInt CHorizontalSlider::Position() const
       
   302 	{
       
   303 	return iPosition;
       
   304 	}
       
   305 
       
   306 //=============================================================================
       
   307 EXPORT_C void CHorizontalSlider::Increment()
       
   308 	{
       
   309 	iPosition += iStep;
       
   310 	if(iPosition > iMaximumValue)
       
   311 		{
       
   312 		iPosition = iMaximumValue;
       
   313 		}
       
   314 	}
       
   315 
       
   316 //=============================================================================
       
   317 EXPORT_C void CHorizontalSlider::Decrement()
       
   318 	{
       
   319 	iPosition -= iStep;
       
   320 	if(iPosition < iMinimumValue)
       
   321 		{
       
   322 		iPosition = iMinimumValue;
       
   323 		}
       
   324 	}
       
   325 
       
   326 // End of File