camerauis/cameraapp/generic/src/camcapturebuttoncontainer.cpp
branchRCL_3
changeset 31 8f559c47d7fd
child 35 e32fcfe0045f
equal deleted inserted replaced
27:53c8aa5d97a3 31:8f559c47d7fd
       
     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 
       
    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;
       
    69     TInt maskId   = EMbmCameraappQgn_indi_cam4_capture_mask;
       
    70     if ( iCameraMode == ECamControllerVideo )
       
    71         {
       
    72         bitmapId = EMbmCameraappQgn_indi_cam4_video;
       
    73         maskId   = EMbmCameraappQgn_indi_cam4_video_mask;
       
    74         }
       
    75     AknIconUtils::CreateIconL(
       
    76              iCaptureIcon,
       
    77              iCaptureMask,
       
    78              KCamBitmapFile(),
       
    79              bitmapId,
       
    80              maskId );
       
    81     AknIconUtils::SetSize( iCaptureIcon, KIconSize, EAspectRatioPreserved );
       
    82     
       
    83     iCaptureRect = aRect;
       
    84     iFeedback = MTouchFeedback::Instance();
       
    85     PRINT( _L("Camera <= CCamCaptureButtonContainer::ConstructL") );
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CCamCaptureButtonContainer::~CCamCaptureButtonContainer
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 CCamCaptureButtonContainer::~CCamCaptureButtonContainer()
       
    93     {
       
    94     delete iCaptureIcon;
       
    95     delete iCaptureMask;
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CCamCaptureButtonContainer::NewLC
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 CCamCaptureButtonContainer* CCamCaptureButtonContainer::NewLC( CCamAppController& aController,
       
   103                                                                CAknView& aView,
       
   104                                                                CCamPreCaptureContainerBase& aContainer,
       
   105                                                                const TRect& aRect,
       
   106                                                                TCamCameraMode aCameraMode )
       
   107     {
       
   108     CCamCaptureButtonContainer* self = new (ELeave) CCamCaptureButtonContainer( aController, 
       
   109                                                                                 aView,
       
   110                                                                                 aContainer,
       
   111                                                                                 aCameraMode );
       
   112     CleanupStack::PushL( self );
       
   113     self->ConstructL( aRect );
       
   114     return self;
       
   115     }
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CCamCaptureButtonContainer::NewL
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 CCamCaptureButtonContainer* CCamCaptureButtonContainer::NewL( CCamAppController& aController,
       
   122                                                               CAknView& aView,
       
   123                                                               CCamPreCaptureContainerBase& aContainer,
       
   124                                                               const TRect& aRect, 
       
   125                                                               TCamCameraMode aCameraMode )
       
   126     {
       
   127     CCamCaptureButtonContainer* self = CCamCaptureButtonContainer::NewLC( aController, 
       
   128                                                                           aView,
       
   129                                                                           aContainer,
       
   130                                                                           aRect,
       
   131                                                                           aCameraMode );
       
   132     CleanupStack::Pop(self);
       
   133     return self;
       
   134     }
       
   135 
       
   136 // -------------------------------------------------------------
       
   137 // CCamCaptureButtonContainer::HandlePointerEventL
       
   138 // -------------------------------------------------------------
       
   139 //
       
   140 void CCamCaptureButtonContainer::HandlePointerEventL( const TPointerEvent& aPointerEvent )
       
   141     {
       
   142     PRINT3( _L("Camera => CCamCaptureButtonContainer::HandlePointerEventL type:%d position:%d,%d"), 
       
   143                      aPointerEvent.iType, aPointerEvent.iPosition.iX, aPointerEvent.iPosition.iY );    
       
   144 
       
   145     if( iCaptureButtonShown )
       
   146         {
       
   147         PRINT( _L("Camera <> Capture button shown") );
       
   148         // Button down -> pressed (highlighted)
       
   149         if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   150             {
       
   151             SetPointerCapture( ETrue );
       
   152             ClaimPointerGrab( ETrue );
       
   153             iCaptureButtonPressed = ETrue;
       
   154             if ( !iFeedback )
       
   155                 {
       
   156                 iFeedback = MTouchFeedback::Instance();
       
   157                 }
       
   158             // Feedback on button press
       
   159             if ( iFeedback )
       
   160                 {
       
   161                 iFeedback->InstantFeedback( ETouchFeedbackBasicButton );        
       
   162                 }
       
   163             DrawNow();
       
   164             }
       
   165         // Button up after button down (within button area) -> start capture
       
   166         else if ( aPointerEvent.iType == TPointerEvent::EButton1Up
       
   167                   && iCaptureButtonPressed && Rect().Contains(aPointerEvent.iPosition) )
       
   168             {
       
   169             PRINT( _L("Camera <> starting capture") );
       
   170             ClaimPointerGrab( EFalse );
       
   171             SetPointerCapture( EFalse );
       
   172             iCaptureButtonPressed = EFalse;
       
   173 
       
   174             // Give feedback on button release
       
   175             if ( iFeedback )
       
   176                 {
       
   177                 iFeedback->InstantFeedback( ETouchFeedbackBasicButton );        
       
   178                 }
       
   179 
       
   180             iParentContainer.PrepareForCapture();
       
   181             if ( iCameraMode == ECamControllerVideo ) 
       
   182                 {
       
   183                 iView.HandleCommandL( ECamCmdRecord );
       
   184                 }
       
   185             else
       
   186                 {
       
   187                 iView.HandleCommandL( ECamCmdCaptureImage );
       
   188                 }
       
   189             }
       
   190         // Drags can potentially start from inside button area
       
   191         else if ( iCaptureButtonPressed && aPointerEvent.iType != TPointerEvent::EDrag )
       
   192             {
       
   193             PRINT( _L("Camera <> outside button region - button to not-pressed state") );
       
   194             ClaimPointerGrab( EFalse );
       
   195             SetPointerCapture( EFalse );
       
   196             iCaptureButtonPressed = EFalse;
       
   197             DrawNow();
       
   198             }
       
   199         else
       
   200             {
       
   201             PRINT( _L("Camera <> unhandled case") );
       
   202             // Avoid compiler warning
       
   203             }
       
   204         }
       
   205 
       
   206     PRINT( _L("Camera <= CCamCaptureButtonContainer::HandlePointerEventL") );
       
   207     }
       
   208 
       
   209 // -------------------------------------------------------------
       
   210 // CCamCaptureButtonContainer::SetCaptureButtonShown
       
   211 // -------------------------------------------------------------
       
   212 //
       
   213 void CCamCaptureButtonContainer::SetCaptureButtonShown( TBool aShown )
       
   214     {
       
   215     PRINT1( _L("Camera => CCamCaptureButtonContainer::SetCaptureButtonShown shown:%d"), aShown );
       
   216     iCaptureButtonShown = aShown;
       
   217 
       
   218     if ( !aShown )
       
   219         {
       
   220         MakeVisible( EFalse );
       
   221         }
       
   222     else if ( !IsVisible() )
       
   223         {
       
   224         // Ensure button is in non-pressed state when making visible 
       
   225         iCaptureButtonPressed = EFalse;
       
   226 
       
   227         PRINT( _L("Camera <> Making the capture button visible") );
       
   228         DrawableWindow()->SetOrdinalPosition( 0, KCaptureButtonOrdinalPriority );
       
   229         MakeVisible( ETrue );
       
   230         DrawDeferred();
       
   231         }
       
   232     else
       
   233         {
       
   234         PRINT( _L("Camera <> Already visible!") );
       
   235         }
       
   236 
       
   237     PRINT( _L("Camera <= CCamCaptureButtonContainer::SetCaptureButtonShown") );
       
   238     }
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // CCamCaptureButtonContainer::Draw
       
   242 // -----------------------------------------------------------------------------
       
   243 //
       
   244 void CCamCaptureButtonContainer::Draw( const TRect& aRect ) const
       
   245     {
       
   246     PRINT( _L("Camera => CCamCaptureButtonContainer::Draw") );
       
   247 
       
   248     CWindowGc& gc = SystemGc();
       
   249     if ( iCaptureButtonShown )
       
   250         {
       
   251         DrawCaptureButton( gc );
       
   252         }
       
   253     else
       
   254         {
       
   255         PRINT( _L("Camera <> button hidden") );
       
   256         }
       
   257 
       
   258     PRINT( _L("Camera <= CCamCaptureButtonContainer::Draw") );
       
   259     }
       
   260 
       
   261 // -------------------------------------------------------------
       
   262 // CCamCaptureButtonContainer::DrawCaptureButton
       
   263 // -------------------------------------------------------------
       
   264 //
       
   265 void CCamCaptureButtonContainer::DrawCaptureButton( CBitmapContext& aGc ) const
       
   266     {
       
   267     PRINT( _L("Camera => CCamCaptureButtonContainer::DrawCaptureButton") );
       
   268 
       
   269     TRect boundingRect( iCaptureRect );
       
   270     boundingRect.Move( -iCaptureRect.iTl.iX, -iCaptureRect.iTl.iY );
       
   271     boundingRect.Shrink( KAdditionalArea );
       
   272     
       
   273     TPoint iconTl( boundingRect.iTl.iX + KCaptureIconDelta, 
       
   274                    boundingRect.iTl.iY + KCaptureIconDelta );
       
   275 
       
   276     aGc.SetDrawMode( CGraphicsContext::EDrawModeWriteAlpha );
       
   277     aGc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   278     aGc.SetPenStyle( CGraphicsContext::ENullPen );
       
   279     if ( iCaptureButtonPressed )
       
   280         {
       
   281         aGc.SetBrushColor( KRgbBlack );
       
   282         }
       
   283     else
       
   284         {
       
   285         aGc.SetBrushColor( TRgb( KToolbarExtensionBgColor, KToolBarExtensionBgAlpha ) );
       
   286         }
       
   287     aGc.DrawEllipse( boundingRect );
       
   288 
       
   289     TRect iconRect( KIconSize );
       
   290     aGc.SetPenStyle( CGraphicsContext::ESolidPen );
       
   291     aGc.SetBrushStyle( CGraphicsContext::ENullBrush );
       
   292     aGc.BitBltMasked( iconTl, iCaptureIcon, iconRect, iCaptureMask, EFalse );
       
   293 
       
   294     PRINT( _L("Camera <= CCamCaptureButtonContainer::DrawCaptureButton") );
       
   295     }
       
   296