videditor/VideoEditorUiComponents/src/VeiSlider.cpp
changeset 0 951a5db380a0
equal deleted inserted replaced
-1:000000000000 0:951a5db380a0
       
     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 "VeiSlider.h"
       
    21 #include "VeiSlider.pan"
       
    22 #include "VideoEditorDebugUtils.h"
       
    23 
       
    24 #include <VideoEditorUiComponents.mbg>
       
    25 #include <fbs.h>
       
    26 #include <aknutils.h>
       
    27 #include <AknIconUtils.h>
       
    28 #include <eikenv.h>
       
    29 
       
    30 // CONSTANTS
       
    31 _LIT(KSliderMifFile, "\\resource\\apps\\VideoEditorUiComponents.mif");
       
    32 
       
    33 const TInt KTabAspectRatioX = 10;
       
    34 const TInt KTabAspectRatioY = 24;
       
    35 
       
    36 //=============================================================================
       
    37 //
       
    38 //	class CVeiSlider member functions
       
    39 //
       
    40 //=============================================================================
       
    41 
       
    42 //=============================================================================
       
    43 EXPORT_C CVeiSlider::~CVeiSlider()
       
    44     {
       
    45     delete iSliderBg;
       
    46 	delete iSliderBgMask;
       
    47 	delete iSliderTab;
       
    48 	delete iSliderTabMask;
       
    49     }
       
    50 
       
    51 //=============================================================================
       
    52 CVeiSlider::CVeiSlider()
       
    53     {
       
    54     // no implementation required
       
    55     }
       
    56 
       
    57 //=============================================================================
       
    58 TInt CVeiSlider::CountComponentControls() const
       
    59     {
       
    60     return 0;
       
    61     }
       
    62 
       
    63 //=============================================================================
       
    64 CCoeControl* CVeiSlider::ComponentControl(TInt /*aIndex*/) const
       
    65     {
       
    66     return NULL;
       
    67     }
       
    68 
       
    69 // setters
       
    70 
       
    71 //=============================================================================
       
    72 EXPORT_C void CVeiSlider::SetMinimum(TInt aValue)
       
    73 	{
       
    74 	iMinimumValue = aValue;
       
    75 	}
       
    76 
       
    77 //=============================================================================
       
    78 EXPORT_C void CVeiSlider::SetMaximum(TInt aValue)
       
    79 	{
       
    80 	iMaximumValue = aValue;
       
    81 	}
       
    82 
       
    83 //=============================================================================
       
    84 EXPORT_C void CVeiSlider::SetStep(TUint aValue)
       
    85 	{
       
    86 	iStep = aValue;
       
    87 	}
       
    88 
       
    89 //=============================================================================
       
    90 EXPORT_C void CVeiSlider::SetStepAmount(TUint8 aValue)
       
    91 	{
       
    92 	iNumberOfSteps = aValue;
       
    93 	
       
    94 	if(aValue == 0)
       
    95 		{
       
    96 		iStep = 0;
       
    97 		}
       
    98 	else
       
    99 		{
       
   100 		iStep = (iMaximumValue-iMinimumValue) / aValue;
       
   101 		}
       
   102 	}
       
   103 
       
   104 //=============================================================================
       
   105 EXPORT_C void CVeiSlider::SetPosition(TInt aValue)
       
   106 	{
       
   107 	__ASSERT_ALWAYS( aValue >= iMinimumValue, Panic(EVeiSliderPanicIndexUnderflow) );
       
   108 	__ASSERT_ALWAYS( aValue <= iMaximumValue, Panic(EVeiSliderPanicIndexOverflow) );
       
   109 
       
   110 	iPosition = aValue;
       
   111 	}
       
   112 
       
   113 // getters
       
   114 
       
   115 //=============================================================================
       
   116 EXPORT_C TInt CVeiSlider::Minimum() const
       
   117 	{
       
   118 	return iMinimumValue;
       
   119 	}
       
   120 
       
   121 //=============================================================================
       
   122 EXPORT_C TInt CVeiSlider::Maximum() const
       
   123 	{
       
   124 	return iMaximumValue;
       
   125 	}
       
   126 
       
   127 //=============================================================================
       
   128 EXPORT_C TInt CVeiSlider::Step() const
       
   129 	{
       
   130 	return iStep;
       
   131 	}
       
   132 
       
   133 //=============================================================================
       
   134 EXPORT_C TInt CVeiSlider::SliderPosition() const
       
   135 	{
       
   136 	return iPosition;
       
   137 	}
       
   138 
       
   139 //=============================================================================
       
   140 EXPORT_C void CVeiSlider::Increment()
       
   141 	{
       
   142 	iPosition += iStep;
       
   143 	if(iPosition > iMaximumValue)
       
   144 		{
       
   145 		iPosition = iMaximumValue;
       
   146 		}
       
   147 	}
       
   148 
       
   149 //=============================================================================
       
   150 EXPORT_C void CVeiSlider::Decrement()
       
   151 	{
       
   152 	iPosition -= iStep;
       
   153 	if(iPosition < iMinimumValue)
       
   154 		{
       
   155 		iPosition = iMinimumValue;
       
   156 		}
       
   157 	}
       
   158 
       
   159 //=============================================================================
       
   160 void CVeiSlider::LoadBitmapL( CFbsBitmap*& aBitmap, CFbsBitmap*& aMask, TInt aBitmapId, TInt aMaskId ) const
       
   161 	{
       
   162     TFileName iconFile( KSliderMifFile );
       
   163   
       
   164     User::LeaveIfError( CompleteWithAppPath(iconFile) );
       
   165 
       
   166     // Get ids for bitmap and mask
       
   167     AknIconUtils::CreateIconL(
       
   168         aBitmap,
       
   169         aMask,
       
   170         iconFile,
       
   171         aBitmapId,
       
   172         aMaskId
       
   173         );                
       
   174 	}
       
   175 
       
   176 
       
   177 //=============================================================================
       
   178 //
       
   179 //	class CVeiVerticalSlider member functions
       
   180 //
       
   181 //=============================================================================
       
   182 
       
   183 //=============================================================================
       
   184 EXPORT_C CVeiVerticalSlider* CVeiVerticalSlider::NewL(const TRect& aRect, const CCoeControl& aControl)
       
   185 	{
       
   186 	CVeiVerticalSlider* self = CVeiVerticalSlider::NewLC(aRect, aControl);
       
   187 	CleanupStack::Pop(self);
       
   188 	return self;
       
   189 	}
       
   190 
       
   191 //=============================================================================
       
   192 EXPORT_C CVeiVerticalSlider* CVeiVerticalSlider::NewLC(const TRect& aRect, const CCoeControl& aControl)
       
   193     {
       
   194     CVeiVerticalSlider* self = new (ELeave) CVeiVerticalSlider;
       
   195     CleanupStack::PushL(self);
       
   196     self->ConstructL(aRect, aControl);
       
   197     return self;
       
   198     }
       
   199 
       
   200 //=============================================================================
       
   201 EXPORT_C CVeiVerticalSlider::~CVeiVerticalSlider()
       
   202     {
       
   203     }
       
   204 
       
   205 //=============================================================================
       
   206 void CVeiVerticalSlider::ConstructL(const TRect& aRect, const CCoeControl& aControl)
       
   207 	{
       
   208 	LOG(KVideoEditorLogFile, "CVeiVerticalSlider::ConstructL: in");
       
   209 
       
   210 	SetContainerWindowL(aControl);
       
   211 
       
   212     // Load the bitmaps 
       
   213     LoadBitmapL( iSliderBg, iSliderBgMask, EMbmVideoeditoruicomponentsQgn_graf_ied_vslider, EMbmVideoeditoruicomponentsQgn_graf_ied_vslider_mask );
       
   214     LoadBitmapL( iSliderTab, iSliderTabMask, EMbmVideoeditoruicomponentsQgn_graf_ied_vtab, EMbmVideoeditoruicomponentsQgn_graf_ied_vtab_mask );
       
   215 
       
   216 	SetRect(aRect);
       
   217 	ActivateL();
       
   218 
       
   219 	LOG(KVideoEditorLogFile, "CVeiVerticalSlider::ConstructL: out");
       
   220 	}
       
   221 
       
   222 //=============================================================================
       
   223 CVeiVerticalSlider::CVeiVerticalSlider()
       
   224     {
       
   225     // no implementation required
       
   226     }
       
   227 
       
   228 //=============================================================================
       
   229 void CVeiVerticalSlider::Draw(const TRect& aRect) const
       
   230 	{
       
   231     if ( Minimum() <= Maximum() )
       
   232     	{
       
   233         TUint height = Maximum() - Minimum(); // height of the slider
       
   234         TUint pixelsFromMin = SliderPosition() - Minimum(); // tab position from the beginning
       
   235     
       
   236         TReal factor = 0.0;
       
   237         if (Minimum() < Maximum() )
       
   238         	{
       
   239             factor = (TReal) pixelsFromMin / height; // tab position from the beginning in percentage
       
   240         	}
       
   241         TUint sliderTabHeight = iSliderTab->SizeInPixels().iHeight; // slider tab height
       
   242 
       
   243         // slider bitmap is actually a bit longer but this resolves the problem
       
   244         // where the tab is drawn outside of the slider when in maximum position
       
   245         TUint sliderBitmapHeight = iSliderBg->SizeInPixels().iHeight - sliderTabHeight;
       
   246     
       
   247         TUint tabPositionFromMinInPixels = (TUint) (factor * sliderBitmapHeight + 0.5); // calculate tab position
       
   248 
       
   249         // top left coordinate
       
   250         const TPoint tl = aRect.iTl;
       
   251 
       
   252         CWindowGc& gc = SystemGc();
       
   253 
       
   254         // draw actual slider using mask bitmap
       
   255         TRect bgRect(TPoint(0,0), iSliderBg->SizeInPixels());
       
   256         gc.BitBltMasked(tl, iSliderBg, bgRect, iSliderBgMask, ETrue);
       
   257 
       
   258         // draw the tab using mask bitmap
       
   259         TRect tabRect(TPoint(0,0), iSliderTab->SizeInPixels());
       
   260         gc.BitBltMasked(TPoint(tl.iX, tl.iY+tabPositionFromMinInPixels), iSliderTab, tabRect, iSliderTabMask, ETrue);
       
   261     	}
       
   262 	}
       
   263 
       
   264 //=============================================================================
       
   265 void CVeiVerticalSlider::SizeChanged()
       
   266 	{
       
   267 	LOG(KVideoEditorLogFile, "CVeiVerticalSlider::SizeChanged: in");
       
   268 
       
   269 	__ASSERT_ALWAYS( iSliderBg && iSliderTab, Panic(EVeiSliderPanicBitmapsNotLoaded) );
       
   270 
       
   271 	// Set size for scalable icons - MUST BE CALLED BEFORE ICON IS USABLE
       
   272 	TSize sliderSize;
       
   273 	TSize tabSize;
       
   274 
       
   275 	TInt w = Rect().Width();
       
   276 	TInt h = Rect().Height();
       
   277 
       
   278 	// NOTE: this assumes that the slider and the slider tab have the same width.
       
   279 	// If that is not the case, it should be handled with transparency in the SVG graphic.
       
   280 
       
   281 	// Set the slider bg to fill the whole rect
       
   282 	sliderSize.iWidth = w;
       
   283 	sliderSize.iHeight = h;
       
   284 	AknIconUtils::SetSize( iSliderBg, sliderSize, EAspectRatioNotPreserved);
       
   285 
       
   286 	// The slider tab is set to have the same width.
       
   287 	// The height is calculated from the aspect ratio (set based on the original SVG)
       
   288 	tabSize.iWidth = w;
       
   289 	tabSize.iHeight = (TInt)( w * KTabAspectRatioY / KTabAspectRatioX );
       
   290 	AknIconUtils::SetSize( iSliderTab, tabSize, EAspectRatioNotPreserved);
       
   291 
       
   292 	LOGFMT4(KVideoEditorLogFile, "CVeiVerticalSlider::SizeChanged: out: sliderSize(%d,%d), tabSize(%d,%d)", sliderSize.iWidth,sliderSize.iHeight,tabSize.iWidth,tabSize.iHeight);
       
   293 	}
       
   294 
       
   295 //=============================================================================
       
   296 TSize CVeiVerticalSlider::MinimumSize()
       
   297 	{
       
   298 	LOG(KVideoEditorLogFile, "CVeiVerticalSlider::MinimumSize()");
       
   299 
       
   300 	return iSliderBg->SizeInPixels();
       
   301 	}
       
   302 
       
   303 //=============================================================================
       
   304 //
       
   305 //	class CVeiHorizontalSlider member functions
       
   306 //
       
   307 //=============================================================================
       
   308 
       
   309 //=============================================================================
       
   310 EXPORT_C CVeiHorizontalSlider* CVeiHorizontalSlider::NewL(const TRect& aRect, const CCoeControl& aControl)
       
   311 	{
       
   312 	CVeiHorizontalSlider* self = CVeiHorizontalSlider::NewLC(aRect, aControl);
       
   313 	CleanupStack::Pop(self);
       
   314 	return self;
       
   315 	}
       
   316 
       
   317 //=============================================================================
       
   318 EXPORT_C CVeiHorizontalSlider* CVeiHorizontalSlider::NewLC(const TRect& aRect, const CCoeControl& aControl)
       
   319     {
       
   320     CVeiHorizontalSlider* self = new (ELeave) CVeiHorizontalSlider;
       
   321     CleanupStack::PushL(self);
       
   322     self->ConstructL(aRect, aControl);
       
   323     return self;
       
   324     }
       
   325 
       
   326 //=============================================================================
       
   327 EXPORT_C CVeiHorizontalSlider::~CVeiHorizontalSlider()
       
   328     {
       
   329     }
       
   330 
       
   331 //=============================================================================
       
   332 void CVeiHorizontalSlider::ConstructL(const TRect& aRect, const CCoeControl& aControl)
       
   333 	{
       
   334 	LOG(KVideoEditorLogFile, "CVeiVerticalSlider::ConstructL: in");
       
   335 
       
   336 	SetContainerWindowL(aControl);
       
   337 
       
   338     // Load the bitmaps 
       
   339     LoadBitmapL( iSliderBg, iSliderBgMask, EMbmVideoeditoruicomponentsQgn_graf_ied_hslider, EMbmVideoeditoruicomponentsQgn_graf_ied_hslider_mask );
       
   340     LoadBitmapL( iSliderTab, iSliderTabMask, EMbmVideoeditoruicomponentsQgn_graf_ied_htab, EMbmVideoeditoruicomponentsQgn_graf_ied_htab_mask );
       
   341 
       
   342 	SetRect(aRect);
       
   343 	ActivateL();
       
   344 
       
   345 	LOG(KVideoEditorLogFile, "CVeiVerticalSlider::ConstructL: out");
       
   346 	}
       
   347 
       
   348 //=============================================================================
       
   349 CVeiHorizontalSlider::CVeiHorizontalSlider()
       
   350     {
       
   351     // no implementation required
       
   352     }
       
   353 
       
   354 //=============================================================================
       
   355 void CVeiHorizontalSlider::Draw(const TRect& aRect) const
       
   356 	{
       
   357     if ( Minimum() <= Maximum() )
       
   358     	{
       
   359         TUint height = Maximum() - Minimum(); // height of the slider
       
   360         TUint pixelsFromMin = SliderPosition() - Minimum(); // tab position from the beginning
       
   361     
       
   362         TReal factor = 0.0;
       
   363         if (Minimum() < Maximum() )
       
   364         	{
       
   365             factor = (TReal) pixelsFromMin / height; // tab position from the beginning in percentage
       
   366         	}
       
   367         TUint sliderTabWidth = iSliderTab->SizeInPixels().iWidth; // slider tab width
       
   368 
       
   369         // slider bitmap is actually a bit longer but this resolves the problem
       
   370         // where the tab is drawn outside of the slider when in maximum position
       
   371         TUint sliderBitmapWidth = iSliderBg->SizeInPixels().iWidth - sliderTabWidth;
       
   372     
       
   373         TUint tabPositionFromMinInPixels = (TUint) (factor * sliderBitmapWidth + 0.5); // calculate tab position
       
   374 
       
   375         // top left coordinate
       
   376         const TPoint tl = aRect.iTl;
       
   377 
       
   378         CWindowGc& gc = SystemGc();
       
   379 
       
   380         // draw actual slider using mask bitmap
       
   381         TRect bgRect(TPoint(0,0), iSliderBg->SizeInPixels());
       
   382         gc.BitBltMasked(tl, iSliderBg, bgRect, iSliderBgMask, ETrue);
       
   383 
       
   384         // draw the tab using mask bitmap
       
   385         TRect tabRect(TPoint(0,0),iSliderTab->SizeInPixels());
       
   386         gc.BitBltMasked(TPoint(tl.iX + tabPositionFromMinInPixels, tl.iY), iSliderTab, tabRect, iSliderTabMask, ETrue);
       
   387     	}
       
   388 	}
       
   389 
       
   390 //=============================================================================
       
   391 void CVeiHorizontalSlider::SizeChanged()
       
   392 	{
       
   393 	LOG(KVideoEditorLogFile, "CVeiHorizontalSlider::SizeChanged: in");
       
   394 
       
   395 	__ASSERT_ALWAYS( iSliderBg && iSliderTab, Panic(EVeiSliderPanicBitmapsNotLoaded) );
       
   396 
       
   397 	// Set size for scalable icons - MUST BE CALLED BEFORE ICON IS USABLE
       
   398 	TSize sliderSize;
       
   399 	TSize tabSize;
       
   400 
       
   401 	TInt w = Rect().Width();
       
   402 	TInt h = Rect().Height();
       
   403 
       
   404 	// NOTE: this assumes that the slider and the slider tab have the same height.
       
   405 	// If that is not the case, it should be handled with transparency in the SVG graphic.
       
   406 
       
   407 	// Set the slider bg to fill the whole rect.
       
   408 	sliderSize.iWidth = w;
       
   409 	sliderSize.iHeight = h;
       
   410 	AknIconUtils::SetSize( iSliderBg, sliderSize, EAspectRatioNotPreserved);
       
   411 
       
   412 	// The slider tab is set to have the same height with the bg.
       
   413 	// The width is calculated from the aspect ratio (set based on the original SVG).
       
   414 	tabSize.iWidth = (TInt)( h * KTabAspectRatioY / KTabAspectRatioX );
       
   415 	tabSize.iHeight = h;
       
   416 	AknIconUtils::SetSize( iSliderTab, tabSize, EAspectRatioNotPreserved);
       
   417 
       
   418 	LOGFMT4(KVideoEditorLogFile, "CVeiHorizontalSlider::SizeChanged: out: sliderSize(%d,%d), tabSize(%d,%d)", sliderSize.iWidth,sliderSize.iHeight,tabSize.iWidth,tabSize.iHeight);
       
   419 	}
       
   420 
       
   421 //=============================================================================
       
   422 TSize CVeiHorizontalSlider::MinimumSize()
       
   423 	{
       
   424 	LOG(KVideoEditorLogFile, "CVeiHorizontalSlider::MinimumSize()");
       
   425 
       
   426 	return iSliderBg->SizeInPixels();
       
   427 	}
       
   428 
       
   429 // End of File