⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cameraappappui.cpp

📁 SYMBIAN camera 样例程序如果需要了解更多或缺少什么文件可以邮件联系我
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CCameraAppAppUi from CameraAppAppUi.cpp
*  Part of  : CameraApp
*  Created  : 05/06/2006 by Forum Nokia
*  Version  : 2.0
*  Copyright: Nokia Corporation, 2006
* ============================================================================
*/

#include <avkon.hrh>
#include <eikmenup.h>
#include <CameraApp.rsg>
#include <apgcli.h>
#include <hal.h>


#include "CameraAppAppUi.h"
#include "CameraAppView.h"
#include "CameraAppPortraitView.h"
#include "Cameraapp.hrh"
#include "CameraAppController.h"
#include "CameraApp.pan"

/*
-----------------------------------------------------------------------------

	CCameraAppAppUi::CCameraAppAppUi()

	Description: Constructor
	Comments   : Init member variables and call base class constructor

-----------------------------------------------------------------------------
*/
CCameraAppAppUi::CCameraAppAppUi()
: CAknViewAppUi(),
  iNaviPane( 0 ),
  iTabGroup( 0 ),
  iDecoratedTabGroup( 0 ),
  iController( 0 )
  {
  }
  
/*
-----------------------------------------------------------------------------

	void CCameraAppAppUi::ConstructL()

	Description: Symbian OS 2nd phase constructor
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/  
void CCameraAppAppUi::ConstructL()
    {
    // Try to resolve the best orientation for the app
    BaseConstructL(EAknEnableSkin|ResolveCameraOrientation());
    
    // Resolve the Media Gallery application's UID (a native app)
#ifdef __SERIES60_3X__
        iMediaGalleryUid3 = KMediaGalleryUID3PostFP1;
#else
        // In 2nd Edition we need to resolve which of the two UID3s is valid
        RApaLsSession lsSession;
        User::LeaveIfError(lsSession.Connect());
        CleanupClosePushL(lsSession);
        lsSession.GetAllApps();  // Prepare the server
        TApaAppInfo aInfo;
        // Try to get the Media Gallery application info
        if (lsSession.GetAppInfo(aInfo, TUid::Uid(KMediaGalleryUID3PreFP1)) ==
            KErrNotFound)
            {
            // Media Gallery was not found with UID3 KMediaGalleryUID3PreFP1, 
            // the platform is thus 2nd Edition, FP2 or newer
            iMediaGalleryUid3 = KMediaGalleryUID3PostFP1;
            }
        else
            {
            // The platform is 2nd Edition, FP1 or older
            iMediaGalleryUid3 = KMediaGalleryUID3PreFP1;
            }
        CleanupStack::PopAndDestroy(&lsSession);
#endif

    // Show tabs for main views from resources
    CEikStatusPane* sp = StatusPane();

    // Fetch pointer to the default navi pane control
    iNaviPane = (CAknNavigationControlContainer*)sp->ControlL( 
        TUid::Uid(EEikStatusPaneUidNavi));

    // Tabgroup has been read from resource and it were pushed to the navi 
    // pane. Get pointer to the navigation decorator with the 
    // ResourceDecorator() function. Application owns the decorator and it 
    // has responsibility to delete the object.
    iDecoratedTabGroup = iNaviPane->ResourceDecorator();
    if (iDecoratedTabGroup)
        {
        iTabGroup = (CAknTabGroup*) iDecoratedTabGroup->DecoratedControl();
        }
        
    // Create a camera controller
    iController = new (ELeave) CCameraAppController(*this);
    iController->ConstructL();  

    CCameraAppView* view1 = CCameraAppView::NewLC( *iController );
    AddViewL( view1 );      // transfer ownership to CAknViewAppUi
    CleanupStack::Pop(view1);

    CCameraAppPortraitView* view2 = 
        CCameraAppPortraitView::NewLC( *iController );
    AddViewL( view2 );      // transfer ownership to CAknViewAppUi
    CleanupStack::Pop(view2);

    SetDefaultViewL(*view1);

    // Default mode is viewfinding
    iCameraMode = EViewFinding;
    
    // enable screen change events, so we can react to orientation changes
    iEikonEnv->RootWin().EnableScreenChangeEvents();
    
    // try to capture events from the camera shutter key 
    // (SwEvent capability required)
    iCameraKeyHandle = iCoeEnv->RootWin().CaptureKey( EKeyCameraShutter, 0, 0 );
    }

/*
-----------------------------------------------------------------------------

	CCameraAppAppUi::~CCameraAppAppUi()

	Description: destructor, Frees reserved resources

	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
CCameraAppAppUi::~CCameraAppAppUi()
    {
    if (iDecoratedTabGroup)
        delete iDecoratedTabGroup;
    if (iController)
        delete iController;
        
    if ( iCameraKeyHandle >= 0 )
        {
        iCoeEnv->RootWin().CancelCaptureKey( iCameraKeyHandle );
        }
    }

/*
-----------------------------------------------------------------------------

	void CCameraAppAppUi::DynInitMenuPaneL(
			TInt aResourceId,CEikMenuPane* aMenuPane)

	Description: This function is called by the EIKON framework just before 
				 it displays a menu pane. Its default implementation is empty, 
				 and by overriding it, the application can set the state of menu 
				 items dynamically according to the state of application data.
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraAppAppUi::DynInitMenuPaneL(
    TInt /*aResourceId*/, CEikMenuPane* /*aMenuPane*/ )
    {
    }

/*
-----------------------------------------------------------------------------

	TKeyResponse CCameraAppAppUi::HandleKeyEventL(
			const TKeyEvent& aKeyEvent,TEventCode aType)

	Description: takes care of key event handling
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
TKeyResponse CCameraAppAppUi::HandleKeyEventL(
    const TKeyEvent& aKeyEvent,TEventCode aType)
    {
    if( !iTabGroup || !iController)
      {
      return EKeyWasNotConsumed;
      }

    if(iController->IsCameraUsedByAnotherApp())
      {      
      return EKeyWasNotConsumed;
      }
        
    // handle autofocus requests
    if( aKeyEvent.iScanCode == EStdKeyCameraFocus )
        {
        TEngineState state = iController->GetEngineState();
        if( state != EEngineIdle && state != EFocusing )
            {
            return EKeyWasConsumed;
            }
        switch( aType )
            {
            case EEventKeyDown:
                iController->StartFocusL();
                break;
            case EEventKeyUp:
                iController->FocusCancel();
                break;
            default:
                break;
            }
        return EKeyWasConsumed;
        }

    TInt active = iTabGroup->ActiveTabIndex();
    TInt count = iTabGroup->TabCount();

    switch ( aKeyEvent.iCode )
        {
        case EKeyUpArrow:  
            {
            // Increase the zoom factor if possible. It has reached the high 
            // limit then it will not change.
            if ( iCameraMode == EViewFinding )
                iController->SetZoomL( ETrue );

            return EKeyWasConsumed;
            }
        case EKeyDownArrow:  
            {
            // Decrease the zoom factor if possible. It has reached the low 
            // limit then it will not change.
            if ( iCameraMode == EViewFinding )
                iController->SetZoomL( EFalse );

            return EKeyWasConsumed;
            }
            
        // we have only two views, so both left and right navi keys
        // simply toggle between each other
        case EKeyLeftArrow:
        case EKeyRightArrow:
            {
            // do nothing if engine is busy
            if ( iController->GetEngineState() != EEngineIdle )
                return EKeyWasConsumed;
                
            // do nothing if changing to portrait mode is not supported
            if ( !iController->IsPortraitModeSupported() )
                return EKeyWasConsumed;
                
            active = ++active % count;
            
            // We need to stop the view finder as well.
            iController->StopViewFinder();
            iTabGroup->SetActiveTabByIndex( active );
            ActivateLocalViewL(TUid::Uid(iTabGroup->TabIdFromIndex(active)));
			
            // Set the next mode for display
            iController->SetCameraMode( STATIC_CAST(TCameraState, active));

            // Start viewfinding again
            iController->StartViewFinderL();
            iCameraMode = EViewFinding;
            return EKeyWasConsumed;
            }
        
        case EKeyOK: 
        case EKeyCamera:
        case EKeyCameraShutter:
            {
            DoSnapL();
            return EKeyWasConsumed;
            }
        default:
            break;
        }
        
    return EKeyWasNotConsumed;
    }

/*
-----------------------------------------------------------------------------

	void CCameraAppAppUi::HandleCommandL(TInt aCommand)

	Description: takes care of command handling
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraAppAppUi::HandleCommandL(TInt aCommand)
    {
    switch ( aCommand )
        {
        case EAknSoftkeyExit:
        case EAknSoftkeyBack:
        case EEikCmdExit:
            {
            // If the image saving is in progress, we should not exit. We 
            // have to wait for the conversion to be finished just in case 
            // we will get a partially converted image in the 
            // default images folder
            if ( iController->IsImageConversionInProgress() )
                return;

            Exit();
            break;
            }
        case ECameraAppCmdSnap:
            {
            DoSnapL();
            break;
            }
        case ECameraAppCmdNewImage:
            {
            DoNewImageL();
            break;
            }
        case ECameraAppCmdGotoGallery:
            {
            GoToMediaGalleryL();
            break;
			}
	    case ECameraAppCmdFRNormal:
	        iController->SetFocusRangeL( CCamAutoFocus::ERangeNormal );
	        break;
	    case ECameraAppCmdFRMacro:
	        iController->SetFocusRangeL( CCamAutoFocus::ERangeMacro );
	        break;
	    case ECameraAppCmdFRPortrait:
	        iController->SetFocusRangeL( CCamAutoFocus::ERangePortrait );
	        break;
	    case ECameraAppCmdFRInfinite:
	        iController->SetFocusRangeL( CCamAutoFocus::ERangeInfinite );
	        break;
        default:
            break;      
        }
    }

/*
-----------------------------------------------------------------------------

	void CCameraAppAppUi::GoToMediaGalleryL()

	Description: Go to the media gallery
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraAppAppUi::GoToMediaGalleryL()
    {
    // Gets viewId to activate Media Gallery view 
    TVwsViewId id = TVwsViewId( TUid::Uid(iMediaGalleryUid3), 
                    TUid::Uid(KMediaGalleryListViewUID) );

    TDesC temp = iController->ImagePath();
    HBufC8* buf = HBufC8::NewL(temp.Length());
    CleanupStack::PushL(buf);
    buf->Des().Copy(temp);
    ActivateViewL( id, TUid::Uid( KMediaGalleryCmdMoveFocusTo ), buf->Des());
    CleanupStack::PopAndDestroy(buf);
    }

/*
-----------------------------------------------------------------------------

	void CCameraAppAppUi::DoSnapL()

	Description: take a picture if possible
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraAppAppUi::DoSnapL()
    {    
    // If the image is still being converted, then stop going further.
    TEngineState state = iController->GetEngineState();
    
    if ( state != EEngineIdle && state != EConverted )
        return;

    if ( iController->IsCameraUsedByAnotherApp() )
        return;

    // Snap the picture and save the image into the specific location
    if ( iCameraMode == EViewFinding )  
        {
        iController->PlaySound(ESoundIdSnap);
        iController->SnapL();
        iCameraMode = EImageSnapped;        
        }
    else if ( iCameraMode == EImageSnapped )
        {
        // Since the camera has taken one picture, then do the viewfinding 
        // again
        DoNewImageL();
        }
    }

/*
-----------------------------------------------------------------------------

	void CCameraAppAppUi::DoNewImageL()

	Description: start viewfinder after taking a picture. Update the navi tabs
				 as well.
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/



void CCameraAppAppUi::DoNewImageL()
    {
    // Redisplay the default navi pane
    iController->RedrawNaviPaneL();

    //Start the viewfinder
    iController->StartViewFinderL();

    iCameraMode = EViewFinding;
    }

/*
-----------------------------------------------------------------------------

    CAknNavigationDecorator* CCameraAppAppUi::GetDecoratedTabGroup()

    Description: Returns a pointer to the decorated tab group owned by this 
                 AppUi
    Comments   :

    Return values: A pointer to the decorated tab group

-----------------------------------------------------------------------------
*/
CAknNavigationDecorator* CCameraAppAppUi::GetDecoratedTabGroup()
    {
        return iDecoratedTabGroup;
    }
    

/*
-----------------------------------------------------------------------------

    TUint32 CCameraAppAppUi::ResolveCameraOrientation()

    Description: Returns KAppOrientationLandscape for devices where the 
                 camera is designed to work in landscape orientation, 0
                 for others.
    Comments   : 

    Return values: TUint32 (flag to be passed to CAknAppUi::BaseConstructL)

-----------------------------------------------------------------------------
*/    
TUint32 CCameraAppAppUi::ResolveCameraOrientation()
    {
    TUint32 ret = 0;
    TInt mUid;
    
    HAL::Get(HAL::EMachineUid, mUid);    
    
    // for S60 3rd Edition devices (MachineUID == 0x20??????), assume landscape
    if( mUid > 0x20000000 )        
        ret = KAppOrientationLandscape;
        
    // ...with these exceptions:    
    switch( mUid )
        {
        case 0x200005FF: // N71
        case 0x20001857: // E70 (orientation follows cover position)        
        case 0x20002495: // E50
        case 0x200005FC: // N91
        case 0x20000602: // 5500
            return 0;
        case 0x10200F98: // N90 (2nd Ed, FP3)
            return KAppOrientationLandscape;
        default:
            break;
        }
    
    return ret;
    }
    
// end of file

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -