mmsharing/mmshui/src/musuizoomindicator.cpp
changeset 0 f0cf47e981f9
equal deleted inserted replaced
-1:000000000000 0:f0cf47e981f9
       
     1 /*
       
     2 * Copyright (c) 2003, 2004 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:  Class for displaying icons in viewfinder view
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // USER
       
    20 #include "musuizoomindicator.h"
       
    21 #include "muslogger.h"
       
    22 #include "musuizoomindicatorobserver.h"
       
    23 
       
    24 // SYSTEM
       
    25 #include <aknutils.h>
       
    26 #include <aknsutils.h>
       
    27 #include <data_caging_path_literals.hrh>
       
    28 #include <camcorder.mbg>
       
    29 #include <gulicon.h>
       
    30 #include <aknlayoutscalable_apps.cdl.h>
       
    31 #include <AknsDrawUtils.h>
       
    32 
       
    33 
       
    34 
       
    35 // CONSTANTS
       
    36 const TInt KMusUiZoomDisableTime = 3000000;
       
    37 
       
    38 
       
    39 using namespace AknLayoutScalable_Apps;
       
    40 
       
    41 _LIT( KMyMbmFileName, "z:Camcorder.mbm");
       
    42 
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CMusUiZoomIndicator::CMusUiZoomIndicator(
       
    49                         TInt aZoomMin,
       
    50                         TInt aZoomMax,
       
    51                         MMusUiZoomIndicatorObserver* aObserver )
       
    52     : iZoomMin( aZoomMin ),
       
    53       iZoomMax( aZoomMax ),
       
    54       iZoomLevel( aZoomMin ),
       
    55       iObserver( aObserver )
       
    56     {
       
    57     MUS_LOG( "mus: mus: [MUSUI ] -> CMusUiZoomIndicator::CMusUiZoomIndicator()" );
       
    58     // pass
       
    59     iDisableZoomTimer = NULL;
       
    60     iTopMargin =  5;
       
    61     iBottomMargin = 5;
       
    62 
       
    63     MUS_LOG( "mus: [MUSUI ] <- CMusUiZoomIndicator::CMusUiZoomIndicator()" );
       
    64     }
       
    65 
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 CMusUiZoomIndicator* CMusUiZoomIndicator::NewLC(
       
    72                         TInt aZoomMin,
       
    73                         TInt aZoomMax,
       
    74                         MMusUiZoomIndicatorObserver* aObserver )
       
    75     {
       
    76     MUS_LOG( "mus: [MUSUI ] -> CMusUiZoomIndicator::NewLC()" );
       
    77     CMusUiZoomIndicator* self = new ( ELeave ) CMusUiZoomIndicator(
       
    78                             aZoomMin,
       
    79                             aZoomMax,
       
    80                             aObserver );
       
    81     CleanupStack::PushL( self );
       
    82     self->ConstructL();
       
    83 
       
    84     MUS_LOG( "mus: [MUSUI ] <- CMusUiZoomIndicator::NewLC()" );
       
    85     return self;
       
    86     }
       
    87 
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 CMusUiZoomIndicator* CMusUiZoomIndicator::NewL(
       
    94                         TInt aZoomMin,
       
    95                         TInt aZoomMax,
       
    96                         MMusUiZoomIndicatorObserver* aObserver )
       
    97     {
       
    98     MUS_LOG( "mus: [MUSUI ] -> CMusUiZoomIndicator::NewL()" );
       
    99     CMusUiZoomIndicator* self = NewLC( aZoomMin,
       
   100                                        aZoomMax,
       
   101                                        aObserver );
       
   102     CleanupStack::Pop( self );
       
   103 
       
   104     MUS_LOG( "mus: [MUSUI ] <- CMusUiZoomIndicator::NewL()" );
       
   105     return self;
       
   106     }
       
   107 
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 void CMusUiZoomIndicator::ConstructL()
       
   114     {
       
   115     MUS_LOG( "mus: [MUSUI ] -> CMusUiZoomIndicator::ConstructL()" );
       
   116 
       
   117     if( iZoomMin > iZoomMax )
       
   118         {
       
   119         User::Leave( KErrArgument );
       
   120         }
       
   121 
       
   122     iIconElevator = new (ELeave) CEikImage();
       
   123     iIconElevator->SetContainerWindowL( *this );
       
   124 
       
   125     iIconMin = new (ELeave) CEikImage();
       
   126     iIconMin->SetContainerWindowL( *this );
       
   127 
       
   128     iIconMax = new (ELeave) CEikImage();
       
   129     iIconMax->SetContainerWindowL( *this );
       
   130 
       
   131     iIconBg = new (ELeave) CEikImage();
       
   132     iIconBg->SetContainerWindowL( *this );
       
   133 
       
   134     
       
   135     ConstructImageL( iIconMin,
       
   136                      AknsUtils::SkinInstance(),
       
   137                      KAknsIIDQsnIconColors,
       
   138                      EMbmCamcorderQgn_indi_cams_zoom_bg_min,
       
   139                      EMbmCamcorderQgn_indi_cams_zoom_bg_min);
       
   140 
       
   141     ConstructImageL( iIconMax,
       
   142                      AknsUtils::SkinInstance(),
       
   143                      KAknsIIDQsnIconColors,
       
   144                      EMbmCamcorderQgn_indi_cams_zoom_bg_max,
       
   145                      EMbmCamcorderQgn_indi_cams_zoom_bg_max);
       
   146 
       
   147     ConstructImageL( iIconBg,
       
   148                      AknsUtils::SkinInstance(),
       
   149                      KAknsIIDQsnIconColors,
       
   150                      EMbmCamcorderQgn_indi_cams_zoom_bg,
       
   151                      EMbmCamcorderQgn_indi_cams_zoom_bg);
       
   152 
       
   153     ConstructImageL( iIconElevator,
       
   154                      AknsUtils::SkinInstance(),
       
   155                      KAknsIIDQsnIconColors,
       
   156                      EMbmCamcorderQgn_indi_cams_zoom_elevator,
       
   157                      EMbmCamcorderQgn_indi_cams_zoom_elevator);
       
   158 
       
   159 
       
   160     UpdateZoomLayout();
       
   161 
       
   162     MUS_LOG( "mus: [MUSUI ]  <- CMusUiZoomIndicator::ConstructL()" );
       
   163     }
       
   164 
       
   165 
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 // -----------------------------------------------------------------------------
       
   169 //
       
   170 CMusUiZoomIndicator::~CMusUiZoomIndicator()
       
   171     {
       
   172     MUS_LOG( "mus: [MUSUI ] -> CMusUiZoomIndicator::~CMusUiZoomIndicator()" );
       
   173 
       
   174     DisableTimer();
       
   175     delete iDisableZoomTimer;
       
   176 
       
   177     delete iIconElevator;
       
   178     delete iIconMin;
       
   179     delete iIconMax;
       
   180     delete iIconBg;
       
   181 
       
   182     MUS_LOG( "mus: [MUSUI ] <- CMusUiZoomIndicator::~CMusUiZoomIndicator()" );
       
   183     }
       
   184 
       
   185 
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 // -----------------------------------------------------------------------------
       
   189 //
       
   190 void CMusUiZoomIndicator::SetZoomLevel( TInt aZoomLevel )
       
   191     {
       
   192     MUS_LOG1( "mus: [MUSUI ] -> CMusUiZoomIndicator::SetZoomLevel( %d ) ",
       
   193               aZoomLevel );
       
   194     if( aZoomLevel >= iZoomMin && aZoomLevel <= iZoomMax )
       
   195         {
       
   196         iZoomLevel = aZoomLevel;
       
   197         }
       
   198     DisableTimer();
       
   199     UpdateZoomLayout();
       
   200     EnableTimer();
       
   201     MUS_LOG( "mus: [MUSUI ] <- CMusUiZoomIndicator::SetZoomLevel()" );
       
   202     }
       
   203 
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 //
       
   207 // -----------------------------------------------------------------------------
       
   208 //
       
   209 TInt CMusUiZoomIndicator::GetZoomLevel()
       
   210     {
       
   211     MUS_LOG( "mus: [MUSUI ] -> CMusUiZoomIndicator::GetZoomLevel()" );
       
   212     MUS_LOG( "mus: [MUSUI ] <- CMusUiZoomIndicator::GetZoomLevel()" );
       
   213     return iZoomLevel;
       
   214     }
       
   215 
       
   216 
       
   217 // -----------------------------------------------------------------------------
       
   218 //
       
   219 // -----------------------------------------------------------------------------
       
   220 //
       
   221 void CMusUiZoomIndicator::SetZoomMin( TInt aZoomMin )
       
   222     {
       
   223     MUS_LOG1( "mus: [MUSUI ] -> CMusUiZoomIndicator::SetZoomMin( %d ) ", aZoomMin );
       
   224     if( aZoomMin >= 0 && aZoomMin < iZoomMax )
       
   225         {
       
   226         iZoomMin = aZoomMin;
       
   227         }
       
   228     DisableTimer();
       
   229     UpdateZoomLayout();
       
   230     EnableTimer();
       
   231     MUS_LOG( "mus: [MUSUI ] <- CMusUiZoomIndicator::SetZoomMin()" );
       
   232     }
       
   233 
       
   234 
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 // -----------------------------------------------------------------------------
       
   238 //
       
   239 void CMusUiZoomIndicator::SetZoomMax( TInt aZoomMax )
       
   240     {
       
   241     MUS_LOG1( "mus: [MUSUI ] -> CMusUiZoomIndicator::SetZoomMax( %d ) ", aZoomMax );
       
   242     if( aZoomMax >= iZoomMin )
       
   243         {
       
   244         iZoomMax = aZoomMax;
       
   245         }
       
   246     DisableTimer();
       
   247     UpdateZoomLayout();
       
   248     EnableTimer();
       
   249     MUS_LOG( "mus: [MUSUI ] <- CMusUiZoomIndicator::SetZoomMax()" );
       
   250     }
       
   251 
       
   252 // -----------------------------------------------------------------------------
       
   253 //
       
   254 // -----------------------------------------------------------------------------
       
   255 //
       
   256 void CMusUiZoomIndicator::SetFullRect( const TRect aRect  )
       
   257     {
       
   258     iFullRect = aRect;
       
   259     }
       
   260 
       
   261 
       
   262 // -----------------------------------------------------------------------------
       
   263 //
       
   264 // -----------------------------------------------------------------------------
       
   265 //
       
   266 void CMusUiZoomIndicator::SizeChanged()
       
   267     {
       
   268     MUS_LOG( "mus: [MUSUI ] -> CMusUiZoomIndicator::SizeChanged()" );
       
   269     UpdateZoomLayout();
       
   270     MUS_LOG( "mus: [MUSUI ] <- CMusUiZoomIndicator::SizeChanged()" );
       
   271     }
       
   272 
       
   273 
       
   274 // -----------------------------------------------------------------------------
       
   275 //
       
   276 // -----------------------------------------------------------------------------
       
   277 //
       
   278 void CMusUiZoomIndicator::Draw( const TRect& aRect ) const
       
   279     {
       
   280 
       
   281     CWindowGc& gc = SystemGc();
       
   282 
       
   283     TRect rect( 0,0, iFullRect.Width(), iFullRect.Height() );
       
   284     //TRect rect( iFullRect.Width()-20, iFullRect.iTl.iY, iFullRect.iBr.iX, iFullRect.iBr.iY ); //TRect( 40,0,380,382 ) );
       
   285 
       
   286 /*
       
   287     AknsUtils::RegisterControlPosition( this, TPoint( iFullRect.Width()-20, iFullRect.iTl.iY ) );
       
   288  //   gc.Clear( aRect );
       
   289     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   290     MAknsControlContext* cc = AknsDrawUtils::ControlContext( this );
       
   291     if(!AknsDrawUtils::Background( skin, cc,this,gc,rect,KAknsDrawParamDefault ))
       
   292         {
       
   293 */        
       
   294         MUS_LOG( "mus: [MUSUI ]     Skin not valid or not found" );
       
   295         gc.SetBrushColor( iEikonEnv->ControlColor( EColorWindowBackground, *this ) );
       
   296         gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   297         gc.Clear( aRect );
       
   298 //        }    
       
   299   
       
   300 }
       
   301 
       
   302 
       
   303 // -----------------------------------------------------------------------------
       
   304 // Draw all icons and texts to given graphics context.
       
   305 // -----------------------------------------------------------------------------
       
   306 //
       
   307 void CMusUiZoomIndicator::DrawIcons( const TRect& /*aRect*/ )
       
   308     {
       
   309     MUS_LOG( "mus: [MUSUI ] -> CMusUiZoomIndicator::DrawIcons()" );
       
   310     MUS_LOG( "mus: [MUSUI ] <- CMusUiZoomIndicator::DrawIcons()" );
       
   311     }
       
   312 
       
   313 
       
   314 // -----------------------------------------------------------------------------
       
   315 // Draw all icons and texts to given graphics context.
       
   316 // -----------------------------------------------------------------------------
       
   317 //
       
   318 void CMusUiZoomIndicator::UpdateZoomLayout()
       
   319     {
       
   320     MUS_LOG( "mus: [MUSUI ] -> CMusUiZoomIndicator::UpdateZoomLayout()" );
       
   321     
       
   322     TSize sz = iIconBg->MinimumSize();
       
   323     
       
   324     TRect rect = Rect();
       
   325     
       
   326     // TODO: Remove all magic constants!
       
   327     AknLayoutUtils::LayoutImage(iIconMax, Rect(), 0, 0, 0, 0, 0, 20, 20 );
       
   328     AknLayoutUtils::LayoutImage(iIconMin, Rect(), 0, 0, 68, 0, 0, 20, 20 );
       
   329     AknLayoutUtils::LayoutImage(iIconBg, Rect(), 0, 0, 20, 0, 0, 20, 48 );
       
   330     
       
   331     // 20 - 68
       
   332     iScaleStep = (  48 << 8 ) /
       
   333                  ( ( iZoomMax - iZoomMin ) );
       
   334     iScaleY = ( 58 ) -
       
   335                             ( ( iScaleStep * iZoomLevel ) >> 8 );
       
   336     
       
   337     
       
   338     AknLayoutUtils::LayoutImage(iIconElevator, Rect(), 0, 0, iScaleY, 0, 0, 20, 20 );
       
   339     
       
   340     DrawNow();
       
   341     
       
   342     MUS_LOG( "mus: [MUSUI ] <- CMusUiZoomIndicator::UpdateZoomLayout()" );
       
   343     }
       
   344 
       
   345 
       
   346 // -----------------------------------------------------------------------------
       
   347 //
       
   348 // -----------------------------------------------------------------------------
       
   349 //
       
   350 TInt CMusUiZoomIndicator::CountComponentControls() const
       
   351     {
       
   352     return 4; //iIconElevator ? 1 : 0; // return nbr of controls inside this container
       
   353     //return 0; // return nbr of controls inside this container
       
   354     }
       
   355 
       
   356 
       
   357 // --------------------------------------------------------------------------
       
   358 // Called by framework to retrieve the control specified by index.
       
   359 // --------------------------------------------------------------------------
       
   360 //
       
   361 CCoeControl* CMusUiZoomIndicator::ComponentControl( TInt aIndex ) const
       
   362     {
       
   363     switch ( aIndex )
       
   364         {
       
   365         
       
   366         case 0:
       
   367             return iIconMin;
       
   368         case 1:
       
   369             return iIconMax;
       
   370         case 2:
       
   371             return iIconBg;
       
   372         case 3:
       
   373             return iIconElevator;
       
   374         
       
   375         default:
       
   376             return NULL;
       
   377         }
       
   378     }
       
   379 
       
   380 
       
   381 // -----------------------------------------------------------------------------
       
   382 //
       
   383 // -----------------------------------------------------------------------------
       
   384 //
       
   385 void  CMusUiZoomIndicator::ConstructImageL( CEikImage* aImage,
       
   386                                          MAknsSkinInstance* aSkin,
       
   387                                          const TAknsItemID& aId,
       
   388                                          TInt aBitmapId,
       
   389                                          TInt aMaskId )
       
   390 
       
   391     {
       
   392     MUS_LOG( "mus: [MUSUI ] -> CMusUiZoomIndicator::ConstructIconL()" );
       
   393 
       
   394     CFbsBitmap* bitmap = NULL;
       
   395     CFbsBitmap* mask = NULL;
       
   396 
       
   397     TParse parse;
       
   398     parse.Set( KMyMbmFileName, &KDC_APP_RESOURCE_DIR, NULL );
       
   399 
       
   400     AknsUtils::CreateIconL(aSkin,
       
   401                            aId,
       
   402                            bitmap,
       
   403                            mask,
       
   404                            parse.FullName(),
       
   405                            aBitmapId,
       
   406                            aMaskId);
       
   407 
       
   408     aImage->SetPicture(bitmap, mask); // Owership transferred to CEikImage
       
   409 
       
   410 
       
   411 
       
   412     MUS_LOG( "mus: [MUSUI ] <- CMusUiZoomIndicator::ConstructIconL()" );
       
   413 
       
   414     }
       
   415 
       
   416 
       
   417 
       
   418 // -----------------------------------------------------------------------------
       
   419 // Callback for disable zoom indicator.
       
   420 // -----------------------------------------------------------------------------
       
   421 //
       
   422 TInt CMusUiZoomIndicator::DisableZoomIndicator( TAny* aThis )
       
   423     {
       
   424     MUS_LOG( "mus: [MUSUI ] -> CMusUiZoomIndicator::DisableZoomIndicator()" );
       
   425     CMusUiZoomIndicator* indicator =
       
   426                             static_cast< CMusUiZoomIndicator* > ( aThis );
       
   427     indicator->DisableTimer();
       
   428     if( indicator->iObserver )
       
   429         {
       
   430         indicator->iObserver->DisableZoomIndicator();
       
   431         }
       
   432     MUS_LOG( "mus: [MUSUI ] <- CMusUiZoomIndicator::DisableZoomIndicator()" );
       
   433     return KErrNone;
       
   434     }
       
   435 
       
   436 
       
   437 // -----------------------------------------------------------------------------
       
   438 //
       
   439 // -----------------------------------------------------------------------------
       
   440 //
       
   441 void CMusUiZoomIndicator::DisableTimer()
       
   442     {
       
   443     MUS_LOG( "mus: [MUSUI ] -> CMusUiZoomIndicator::DisableTimer()" );
       
   444     if ( iDisableZoomTimer )
       
   445         {
       
   446         if ( iDisableZoomTimer->IsActive() )
       
   447             {
       
   448             iDisableZoomTimer->Cancel();
       
   449             }
       
   450         }
       
   451     MUS_LOG( "mus: [MUSUI ] <- CMusUiZoomIndicator::DisableTimer()" );
       
   452     }
       
   453 
       
   454 
       
   455 // -----------------------------------------------------------------------------
       
   456 //
       
   457 // -----------------------------------------------------------------------------
       
   458 //
       
   459 void CMusUiZoomIndicator::EnableTimer()
       
   460     {
       
   461     MUS_LOG( "mus: [MUSUI ] -> CMusUiZoomIndicator::EnableTimer()" );
       
   462 
       
   463     if ( !iDisableZoomTimer )
       
   464         {
       
   465         TRAP_IGNORE( iDisableZoomTimer = CPeriodic::NewL( CActive::EPriorityStandard ) );
       
   466         }
       
   467     else
       
   468         {
       
   469         DisableTimer();
       
   470         }
       
   471 
       
   472     // Start disable timer; callback triggers exit.
       
   473     iDisableZoomTimer->Start( KMusUiZoomDisableTime,
       
   474                              KMusUiZoomDisableTime,
       
   475                              TCallBack( DisableZoomIndicator, this ) );
       
   476     MUS_LOG( "mus: [MUSUI ] <- CMusUiZoomIndicator::EnableTimer()" );
       
   477     }
       
   478     
       
   479 
       
   480 // End of File
       
   481 
       
   482 
       
   483