camerauis/cameraapp/generic/src/camcapturebuttoncontainer.cpp
branchRCL_3
changeset 24 bac7acad7cb3
equal deleted inserted replaced
23:61bc0f252b2b 24:bac7acad7cb3
       
     1 /*
       
     2 * Copyright (c) 2010 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:  Container for custom camera capture button 
       
    15 *
       
    16 */
       
    17 
       
    18 #include <AknIconUtils.h>
       
    19 #include <touchfeedback.h>
       
    20 
       
    21 #include "camcapturebuttoncontainer.h"
       
    22 #include "CamPreCaptureViewBase.h"
       
    23 #include "camlogging.h"
       
    24 #include "cameraapp.mbg"
       
    25 #include "CamAppUi.h"
       
    26 
       
    27 // CONSTANTS
       
    28 _LIT(KCamBitmapFile, "z:\\resource\\apps\\cameraapp.mif");
       
    29 const TSize KIconSize( 35, 35 );
       
    30 const TSize KAdditionalArea( 25, 11 );
       
    31 const TInt32 KCaptureIconDelta( 7 );
       
    32 const TUint32 KToolbarExtensionBgColor = 0x00000000;
       
    33 const TInt KToolBarExtensionBgAlpha = 0x7F;
       
    34 const TInt KCaptureButtonOrdinalPriority( 1 );
       
    35 const TSize KIconMargin( 7, 7 );
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CCamCaptureButtonContainer::CCamCaptureButtonContainer
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CCamCaptureButtonContainer::CCamCaptureButtonContainer( CCamAppController& aController,
       
    42                                                         CAknView& aView,
       
    43                                                         CCamPreCaptureContainerBase& aContainer,
       
    44                                                         TCamCameraMode aCameraMode ) 
       
    45     : iController( aController ), 
       
    46       iView( aView ),
       
    47       iParentContainer( aContainer ),
       
    48       iCameraMode( aCameraMode )
       
    49     {
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CCamCaptureButtonContainer::ConstructL
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 void CCamCaptureButtonContainer::ConstructL( const TRect& aRect )
       
    57     {
       
    58     PRINT( _L("Camera => CCamCaptureButtonContainer::ConstructL") );
       
    59     CreateWindowL();
       
    60     SetRect( aRect );
       
    61     Window().SetBackgroundColor( KRgbTransparent );
       
    62 
       
    63     // Keep hidden until explicitly made visible
       
    64     MakeVisible( EFalse );
       
    65     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
    66 
       
    67     // Load capture icon
       
    68     TInt bitmapId = EMbmCameraappQgn_indi_cam4_capture_image;
       
    69     TInt maskId   = EMbmCameraappQgn_indi_cam4_capture_image_mask;
       
    70     TInt bitmapPressedId = EMbmCameraappQgn_indi_cam4_capture_image_pressed;
       
    71     TInt maskPressedId = EMbmCameraappQgn_indi_cam4_capture_image_pressed_mask;
       
    72 
       
    73     if ( iCameraMode == ECamControllerVideo )
       
    74         {
       
    75         bitmapId = EMbmCameraappQgn_indi_cam4_capture_video;
       
    76         maskId   = EMbmCameraappQgn_indi_cam4_capture_video_mask;
       
    77         bitmapPressedId = EMbmCameraappQgn_indi_cam4_capture_video_pressed;
       
    78         maskPressedId = EMbmCameraappQgn_indi_cam4_capture_video_pressed_mask;
       
    79         }
       
    80     
       
    81     iCaptureRect = aRect;
       
    82     iCaptureRect.Move(-iCaptureRect.iTl.iX, -iCaptureRect.iTl.iY );
       
    83     iCaptureRect.Shrink( KIconMargin );
       
    84     
       
    85     AknIconUtils::CreateIconL(
       
    86              iCaptureIcon,
       
    87              iCaptureIconMask,
       
    88              KCamBitmapFile(),
       
    89              bitmapId,
       
    90              maskId );
       
    91     AknIconUtils::SetSize( iCaptureIcon, iCaptureRect.Size() );
       
    92     AknIconUtils::SetSize( iCaptureIconMask, iCaptureRect.Size() );
       
    93     
       
    94     AknIconUtils::CreateIconL(
       
    95                  iCaptureIconPressed,
       
    96                  iCaptureIconPressedMask,
       
    97                  KCamBitmapFile(),
       
    98                  bitmapPressedId,
       
    99                  maskPressedId );
       
   100     AknIconUtils::SetSize( iCaptureIconPressed, iCaptureRect.Size() );
       
   101     AknIconUtils::SetSize( iCaptureIconPressedMask, iCaptureRect.Size() );
       
   102     
       
   103     iFeedback = MTouchFeedback::Instance();
       
   104     PRINT( _L("Camera <= CCamCaptureButtonContainer::ConstructL") );
       
   105     }
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CCamCaptureButtonContainer::~CCamCaptureButtonContainer
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 CCamCaptureButtonContainer::~CCamCaptureButtonContainer()
       
   112     {
       
   113     delete iCaptureIcon;
       
   114     delete iCaptureIconMask;
       
   115     delete iCaptureIconPressed;
       
   116     delete iCaptureIconPressedMask;
       
   117     }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CCamCaptureButtonContainer::NewLC
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 CCamCaptureButtonContainer* CCamCaptureButtonContainer::NewLC( CCamAppController& aController,
       
   124                                                                CAknView& aView,
       
   125                                                                CCamPreCaptureContainerBase& aContainer,
       
   126                                                                const TRect& aRect,
       
   127                                                                TCamCameraMode aCameraMode )
       
   128     {
       
   129     CCamCaptureButtonContainer* self = new (ELeave) CCamCaptureButtonContainer( aController, 
       
   130                                                                                 aView,
       
   131                                                                                 aContainer,
       
   132                                                                                 aCameraMode );
       
   133     CleanupStack::PushL( self );
       
   134     self->ConstructL( aRect );
       
   135     return self;
       
   136     }
       
   137 
       
   138 // -----------------------------------------------------------------------------
       
   139 // CCamCaptureButtonContainer::NewL
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 CCamCaptureButtonContainer* CCamCaptureButtonContainer::NewL( CCamAppController& aController,
       
   143                                                               CAknView& aView,
       
   144                                                               CCamPreCaptureContainerBase& aContainer,
       
   145                                                               const TRect& aRect, 
       
   146                                                               TCamCameraMode aCameraMode )
       
   147     {
       
   148     CCamCaptureButtonContainer* self = CCamCaptureButtonContainer::NewLC( aController, 
       
   149                                                                           aView,
       
   150                                                                           aContainer,
       
   151                                                                           aRect,
       
   152                                                                           aCameraMode );
       
   153     CleanupStack::Pop(self);
       
   154     return self;
       
   155     }
       
   156 
       
   157 // -------------------------------------------------------------
       
   158 // CCamCaptureButtonContainer::HandlePointerEventL
       
   159 // -------------------------------------------------------------
       
   160 //
       
   161 void CCamCaptureButtonContainer::HandlePointerEventL( const TPointerEvent& aPointerEvent )
       
   162     {
       
   163     PRINT3( _L("Camera => CCamCaptureButtonContainer::HandlePointerEventL type:%d position:%d,%d"), 
       
   164                      aPointerEvent.iType, aPointerEvent.iPosition.iX, aPointerEvent.iPosition.iY );    
       
   165 
       
   166     if( iCaptureButtonShown )
       
   167         {
       
   168         PRINT( _L("Camera <> Capture button shown") );
       
   169         // Button down -> pressed (highlighted)
       
   170         if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   171             {
       
   172             SetPointerCapture( ETrue );
       
   173             ClaimPointerGrab( ETrue );
       
   174             iCaptureButtonPressed = ETrue;
       
   175             if ( !iFeedback )
       
   176                 {
       
   177                 iFeedback = MTouchFeedback::Instance();
       
   178                 }
       
   179             // Feedback on button press
       
   180             if ( iFeedback )
       
   181                 {
       
   182                 iFeedback->InstantFeedback( ETouchFeedbackBasicButton );        
       
   183                 }
       
   184             DrawNow();
       
   185             }
       
   186         // Button up after button down (within button area) -> start capture
       
   187         else if ( aPointerEvent.iType == TPointerEvent::EButton1Up
       
   188                   && iCaptureButtonPressed && Rect().Contains(aPointerEvent.iPosition) )
       
   189             {
       
   190             PRINT( _L("Camera <> starting capture") );
       
   191             ClaimPointerGrab( EFalse );
       
   192             SetPointerCapture( EFalse );
       
   193             iCaptureButtonPressed = EFalse;
       
   194 
       
   195             // Give feedback on button release
       
   196             if ( iFeedback )
       
   197                 {
       
   198                 iFeedback->InstantFeedback( ETouchFeedbackBasicButton );        
       
   199                 }
       
   200 
       
   201             iParentContainer.PrepareForCapture();
       
   202             if ( iCameraMode == ECamControllerVideo ) 
       
   203                 {
       
   204                 iView.HandleCommandL( ECamCmdRecord );
       
   205                 }
       
   206             else
       
   207                 {
       
   208                 iController.SetTouchCapture( ETrue );
       
   209                 iView.HandleCommandL( ECamCmdCaptureImage );
       
   210                 }
       
   211             }
       
   212         // Drags can potentially start from inside button area
       
   213         else if ( iCaptureButtonPressed && aPointerEvent.iType != TPointerEvent::EDrag )
       
   214             {
       
   215             PRINT( _L("Camera <> outside button region - button to not-pressed state") );
       
   216             ClaimPointerGrab( EFalse );
       
   217             SetPointerCapture( EFalse );
       
   218             iCaptureButtonPressed = EFalse;
       
   219             DrawNow();
       
   220             }
       
   221         else
       
   222             {
       
   223             PRINT( _L("Camera <> unhandled case") );
       
   224             // Avoid compiler warning
       
   225             }
       
   226         }
       
   227 
       
   228     PRINT( _L("Camera <= CCamCaptureButtonContainer::HandlePointerEventL") );
       
   229     }
       
   230 
       
   231 // -------------------------------------------------------------
       
   232 // CCamCaptureButtonContainer::SetCaptureButtonShown
       
   233 // -------------------------------------------------------------
       
   234 //
       
   235 void CCamCaptureButtonContainer::SetCaptureButtonShown( TBool aShown )
       
   236     {
       
   237     PRINT1( _L("Camera => CCamCaptureButtonContainer::SetCaptureButtonShown shown:%d"), aShown );
       
   238     iCaptureButtonShown = aShown;
       
   239 
       
   240     if ( !aShown )
       
   241         {
       
   242         MakeVisible( EFalse );
       
   243         }
       
   244     else if ( !IsVisible() )
       
   245         {
       
   246         // Ensure button is in non-pressed state when making visible 
       
   247         iCaptureButtonPressed = EFalse;
       
   248 
       
   249         PRINT( _L("Camera <> Making the capture button visible") );
       
   250         DrawableWindow()->SetOrdinalPosition( 0, KCaptureButtonOrdinalPriority );
       
   251         MakeVisible( ETrue );
       
   252         DrawDeferred();
       
   253         }
       
   254     else
       
   255         {
       
   256         PRINT( _L("Camera <> Already visible!") );
       
   257         }
       
   258 
       
   259     PRINT( _L("Camera <= CCamCaptureButtonContainer::SetCaptureButtonShown") );
       
   260     }
       
   261 
       
   262 // -----------------------------------------------------------------------------
       
   263 // CCamCaptureButtonContainer::Draw
       
   264 // -----------------------------------------------------------------------------
       
   265 //
       
   266 void CCamCaptureButtonContainer::Draw( const TRect& aRect ) const
       
   267     {
       
   268     PRINT( _L("Camera => CCamCaptureButtonContainer::Draw") );
       
   269 
       
   270     CWindowGc& gc = SystemGc();
       
   271     if ( iCaptureButtonShown )
       
   272         {
       
   273         DrawCaptureButton( gc );
       
   274         }
       
   275     else
       
   276         {
       
   277         PRINT( _L("Camera <> button hidden") );
       
   278         }
       
   279 
       
   280     PRINT( _L("Camera <= CCamCaptureButtonContainer::Draw") );
       
   281     }
       
   282 
       
   283 // -------------------------------------------------------------
       
   284 // CCamCaptureButtonContainer::DrawCaptureButton
       
   285 // -------------------------------------------------------------
       
   286 //
       
   287 void CCamCaptureButtonContainer::DrawCaptureButton( CBitmapContext& aGc ) const
       
   288     {
       
   289     PRINT( _L("Camera => CCamCaptureButtonContainer::DrawCaptureButton") );
       
   290     TRect boundingRect( iCaptureRect );
       
   291     boundingRect.Move( -boundingRect.iTl.iX, -boundingRect.iTl.iY );
       
   292 
       
   293     if ( iCaptureButtonPressed )
       
   294         {
       
   295         aGc.BitBltMasked( iCaptureRect.iTl, iCaptureIconPressed, boundingRect, iCaptureIconPressedMask, EFalse );
       
   296         }
       
   297     else
       
   298         {
       
   299         aGc.BitBltMasked( iCaptureRect.iTl, iCaptureIcon, boundingRect, iCaptureIconMask, EFalse );
       
   300 
       
   301         }
       
   302 
       
   303     PRINT( _L("Camera <= CCamCaptureButtonContainer::DrawCaptureButton") );
       
   304     }
       
   305