videoplayback/videoplaybackcontrols/src/mpxvideoplaybackbutton.cpp
changeset 0 96612d01cf9f
child 6 7d91903f795f
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "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 *
       
    14 * Description: Button control
       
    15 *
       
    16 */
       
    17 
       
    18 // Version : %version: 8 %
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include <eikenv.h>
       
    24 #include <gulicon.h>
       
    25 #include <AknUtils.h>
       
    26 #include <AknIconUtils.h>
       
    27 #include <AknsDrawUtils.h>
       
    28 
       
    29 #include "mpxvideoplaybackbutton.h"
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===================================================
       
    32 
       
    33 CMPXVideoPlaybackButton::CMPXVideoPlaybackButton()
       
    34 {
       
    35 }
       
    36 
       
    37 // -------------------------------------------------------------------------------------------------
       
    38 // CMPXVideoPlaybackButton::ConstructL()
       
    39 // Symbian 2nd phase constructor can leave.
       
    40 // -------------------------------------------------------------------------------------------------
       
    41 //
       
    42 void CMPXVideoPlaybackButton::ConstructL( TRect aRect, const TDesC &aIconPath )
       
    43 {
       
    44     MPX_DEBUG(_L("CMPXVideoPlaybackButton::ConstructL()"));
       
    45 
       
    46     iIConPath = aIconPath.AllocL();
       
    47 
       
    48     SetRect( aRect );
       
    49 }
       
    50 
       
    51 // -------------------------------------------------------------------------------------------------
       
    52 // CMPXVideoPlaybackButton::NewL()
       
    53 // Two-phased constructor.
       
    54 // -------------------------------------------------------------------------------------------------
       
    55 //
       
    56 CMPXVideoPlaybackButton* CMPXVideoPlaybackButton::NewL( TRect aRect, const TDesC &aIconPath)
       
    57 {
       
    58     MPX_DEBUG(_L("CMPXVideoPlaybackButton::NewL()"));
       
    59 
       
    60     CMPXVideoPlaybackButton* self = new ( ELeave ) CMPXVideoPlaybackButton();
       
    61 
       
    62     CleanupStack::PushL( self );
       
    63     self->ConstructL( aRect, aIconPath );
       
    64     CleanupStack::Pop();
       
    65     return self;
       
    66 }
       
    67 
       
    68 // -------------------------------------------------------------------------------------------------
       
    69 // CMPXVideoPlaybackButton::~CMPXVideoPlaybackButton()
       
    70 // Destructor.
       
    71 // -------------------------------------------------------------------------------------------------
       
    72 //
       
    73 CMPXVideoPlaybackButton::~CMPXVideoPlaybackButton()
       
    74 {
       
    75     MPX_DEBUG(_L("CMPXVideoPlaybackButton::~CMPXVideoPlaybackButton()"));
       
    76 
       
    77     if ( iIConPath )
       
    78     {
       
    79         delete iIConPath;
       
    80         iIConPath = NULL;
       
    81     }
       
    82 
       
    83     if ( iDefaultButton )
       
    84     {
       
    85         delete iDefaultButton;
       
    86         iDefaultButton = NULL;
       
    87     }
       
    88 
       
    89     if ( iDimmedButton )
       
    90     {
       
    91         delete iDimmedButton;
       
    92         iDimmedButton = NULL;
       
    93     }
       
    94 
       
    95     if ( iPressedButton )
       
    96     {
       
    97         delete iPressedButton;
       
    98         iPressedButton = NULL;
       
    99     }
       
   100 }
       
   101 
       
   102 // -------------------------------------------------------------------------------------------------
       
   103 // CMPXVideoPlaybackButton::CreateDefaultButtonL()
       
   104 // -------------------------------------------------------------------------------------------------
       
   105 //
       
   106 void CMPXVideoPlaybackButton::CreateDefaultButtonL( const TAknsItemID &aID,
       
   107                                                     const TInt aFileIndex,
       
   108                                                     const TInt aFileMaskIndex )
       
   109 {
       
   110     MPX_DEBUG(_L("CMPXVideoPlaybackButton::CreateDefaultButtonL()"));
       
   111 
       
   112     if ( iDefaultButton )
       
   113     {
       
   114         delete iDefaultButton;
       
   115         iDefaultButton = NULL;
       
   116     }
       
   117 
       
   118     iDefaultButton = CreateButtonL( aID, aFileIndex, aFileMaskIndex );
       
   119 }
       
   120 
       
   121 // -------------------------------------------------------------------------------------------------
       
   122 // CMPXVideoPlaybackButton::CreateButtonL()
       
   123 // -------------------------------------------------------------------------------------------------
       
   124 //
       
   125 void CMPXVideoPlaybackButton::CreateDimmedButtonL( const TAknsItemID &aID,
       
   126                                                    const TInt aFileIndex,
       
   127                                                    const TInt aFileMaskIndex )
       
   128 {
       
   129     MPX_DEBUG(_L("CMPXVideoPlaybackButton::CreateDimmedButtonL()"));
       
   130 
       
   131     if ( iDimmedButton )
       
   132     {
       
   133         delete iDimmedButton;
       
   134         iDimmedButton = NULL;
       
   135     }
       
   136 
       
   137     iDimmedButton = CreateButtonL( aID, aFileIndex, aFileMaskIndex );
       
   138 }
       
   139 
       
   140 // -------------------------------------------------------------------------------------------------
       
   141 // CMPXVideoPlaybackButton::CreatePressedButtonL()
       
   142 // -------------------------------------------------------------------------------------------------
       
   143 //
       
   144 void CMPXVideoPlaybackButton::CreatePressedButtonL( const TAknsItemID &aID,
       
   145                                                     const TInt aFileIndex,
       
   146                                                     const TInt aFileMaskIndex )
       
   147 {
       
   148     MPX_DEBUG(_L("CMPXVideoPlaybackButton::CreatePressedButtonL()"));
       
   149 
       
   150     if ( iPressedButton )
       
   151     {
       
   152         delete iPressedButton;
       
   153         iPressedButton = NULL;
       
   154     }
       
   155 
       
   156     iPressedButton = CreateButtonL( aID, aFileIndex, aFileMaskIndex );
       
   157 }
       
   158 
       
   159 // -------------------------------------------------------------------------------------------------
       
   160 // CMPXVideoPlaybackButton::CreateButtonL()
       
   161 // -------------------------------------------------------------------------------------------------
       
   162 //
       
   163 CGulIcon* CMPXVideoPlaybackButton::CreateButtonL( const TAknsItemID &aID,
       
   164                                                   const TInt aFileIndex,
       
   165                                                   const TInt aFileMaskIndex )
       
   166 {
       
   167     MPX_DEBUG(_L("CMPXVideoPlaybackButton::CreateButtonL()"));
       
   168 
       
   169     CGulIcon* icon = AknsUtils::CreateGulIconL( AknsUtils::SkinInstance(),
       
   170                                                 aID,
       
   171                                                 iIConPath->Des(),
       
   172                                                 aFileIndex,
       
   173                                                 aFileMaskIndex );
       
   174 
       
   175     if ( icon )
       
   176     {
       
   177         AknIconUtils::SetSize( icon->Bitmap(),
       
   178                                Rect().Size(),
       
   179                                EAspectRatioNotPreserved );
       
   180     }
       
   181 
       
   182     return icon;
       
   183 }
       
   184 
       
   185 // -------------------------------------------------------------------------------------------------
       
   186 //   CMPXVideoPlaybackButton::Draw()
       
   187 // -------------------------------------------------------------------------------------------------
       
   188 //
       
   189 void CMPXVideoPlaybackButton::Draw( const TRect& aRect ) const
       
   190 {
       
   191     MPX_DEBUG(_L("CMPXVideoPlaybackButton::Draw()"));
       
   192 
       
   193     CWindowGc& gc = SystemGc();
       
   194     gc.SetClippingRect( aRect );
       
   195 
       
   196     if ( Window().DisplayMode() == EColor16MAP )
       
   197     {
       
   198         gc.SetDrawMode( CGraphicsContext::EDrawModeWriteAlpha );
       
   199         gc.SetBrushColor( TRgb::Color16MAP( 255 ) );
       
   200         gc.Clear( aRect );
       
   201     }
       
   202     else if ( Window().DisplayMode() == EColor16MA )
       
   203     {
       
   204         gc.SetDrawMode( CGraphicsContext::EDrawModeWriteAlpha );
       
   205         gc.SetBrushColor( TRgb::Color16MA( 0 ) );
       
   206         gc.Clear( aRect );
       
   207     }
       
   208     else
       
   209     {
       
   210         // draw a solid background so that the entire progress
       
   211         // bar is shown not just the area representing the
       
   212         // portion that has been played.
       
   213         gc.SetBrushColor( KRgbBlack );
       
   214         gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   215         gc.DrawRect( aRect );
       
   216         gc.SetBrushStyle( CGraphicsContext::ENullBrush );
       
   217     }
       
   218 
       
   219     switch( iState )
       
   220     {
       
   221         case EMPXButtonNormal:
       
   222         {
       
   223             gc.BitBltMasked( Rect().iTl,
       
   224                              iDefaultButton->Bitmap(),
       
   225                              TRect( Rect().Size() ),
       
   226                              iDefaultButton->Mask(),
       
   227                              ETrue );
       
   228             break;
       
   229         }
       
   230         case EMPXButtonDimmed:
       
   231         {
       
   232             gc.BitBltMasked( Rect().iTl,
       
   233                              iDimmedButton->Bitmap(),
       
   234                              TRect( Rect().Size() ),
       
   235                              iDimmedButton->Mask(),
       
   236                              ETrue );
       
   237             break;
       
   238         }
       
   239         case EMPXButtonPressed:
       
   240         {
       
   241             gc.BitBltMasked( Rect().iTl,
       
   242                              iPressedButton->Bitmap(),
       
   243                              TRect( Rect().Size() ),
       
   244                              iPressedButton->Mask(),
       
   245                              ETrue );
       
   246             break;
       
   247         }
       
   248     }
       
   249 }
       
   250 
       
   251 // -------------------------------------------------------------------------------------------------
       
   252 // CMPXVideoPlaybackButton::CountComponentControls()
       
   253 // -------------------------------------------------------------------------------------------------
       
   254 //
       
   255 TInt CMPXVideoPlaybackButton::CountComponentControls() const
       
   256 {
       
   257     return 0;
       
   258 }
       
   259 
       
   260 // -------------------------------------------------------------------------------------------------
       
   261 // CMPXVideoPlaybackButton::SetDimmed
       
   262 // -------------------------------------------------------------------------------------------------
       
   263 //
       
   264 void CMPXVideoPlaybackButton::SetDimmed( TBool aDimmed )
       
   265 {
       
   266     MPX_DEBUG(_L("CMPXVideoPlaybackButton::SetDimmed() (%d)"), aDimmed);
       
   267 
       
   268     if ( aDimmed && iDimmedButton )
       
   269     {
       
   270         iState = EMPXButtonDimmed;
       
   271     }
       
   272     else if ( iState == EMPXButtonDimmed )
       
   273     {
       
   274         iState = EMPXButtonNormal;
       
   275     }
       
   276 
       
   277     if ( IsVisible() )
       
   278     {
       
   279         DrawNow();
       
   280     }
       
   281 }
       
   282 
       
   283 // -------------------------------------------------------------------------------------------------
       
   284 // CMPXVideoPlaybackButton::SetPressed
       
   285 // -------------------------------------------------------------------------------------------------
       
   286 //
       
   287 void CMPXVideoPlaybackButton::SetPressed( TBool aPressed )
       
   288 {
       
   289     MPX_DEBUG(_L("CMPXVideoPlaybackButton::SetPressed() (%d)"), aPressed);
       
   290 
       
   291     if ( aPressed && iPressedButton )
       
   292     {
       
   293         iState = EMPXButtonPressed;
       
   294     }
       
   295     else if ( iState == EMPXButtonPressed )
       
   296     {
       
   297         iState = EMPXButtonNormal;
       
   298     }
       
   299 
       
   300     if ( IsVisible() )
       
   301     {
       
   302         DrawDeferred();
       
   303     }
       
   304 }
       
   305 
       
   306 //  End of File