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

📄 cameraappappui.cpp

📁 Symbian智能手机操作系统源代码值的参考_摄像头
💻 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 "CameraAppAppUi.h"
#include "CameraAppView.h"
#include "CameraAppPortraitView.h"
#include "Cameraapp.hrh"
#include "CameraAppController.h"
#include "CameraApp.pan"

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

	void CCameraAppAppUi::ConstructL()

	Description: second phase constructor
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraAppAppUi::ConstructL()
    {
    BaseConstructL(EAknEnableSkin);
    // 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;
    }

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

	CCameraAppAppUi::~CCameraAppAppUi()

	Description: destructor, Frees reserved resources

	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
CCameraAppAppUi::~CCameraAppAppUi()
    {
    if (iDecoratedTabGroup)
        delete iDecoratedTabGroup;
    if (iController)
        delete iController;
    }

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

	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 )
        {
        return EKeyWasNotConsumed;
        }

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

    switch ( aKeyEvent.iCode )
        {
        case EKeyUpArrow:  
            {
            // If the camera is being used by another application, do not go
            // further
            if ( iController->IsCameraUsedByAnotherApp() )
                return EKeyWasConsumed;

            // 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;
            break;
            }
        case EKeyDownArrow:  
            {
            // If the camera is being used by another application, do not go
            // further
            if ( iController->IsCameraUsedByAnotherApp() )
                return EKeyWasConsumed;

            // 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;
            break;
            }
        case EKeyLeftArrow:
            {
            // If an image is being converted, then do not change the tab until
            // the image has been converted. Otherwise, we may get a partially
            // coverted image
            TEngineState state = iController->GetEngineState();
            if ( ( state == EStartToSaveImage ) || 
                ( state == EConvertingImage ) ||
                ( state == ESnappingPicture ) )
                return EKeyWasConsumed;
			
            if ( state == EConverted )
                {
                // If the engine has been the "Converted" state, then, set it
                // to idle state to let it switch to other view.
                iController->SetEngineState( EEngineIdle );
                }

            if ( active > 0 )
                {
                // We need to stop the view finder as well.
                iController->StopViewFinder();
                active--;
                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;
                }
            break;
            }
        case EKeyRightArrow:
            {
            // If an image is being converted, then do not change the tab until
            // the image has been converted. Otherwise, we may get partially
            // coverted image
            TEngineState state = iController->GetEngineState();
            if ( ( state == EStartToSaveImage ) || 
                ( state == EConvertingImage ) ||
                ( state == ESnappingPicture ) )
                return EKeyWasConsumed;
			
            if ( state == EConverted )
                {
                // If the engine has been the "Converted" state, then, set it
                // to idle state to let it switch to other view.
                iController->SetEngineState( EEngineIdle );
                }
			
            if( ( active + 1) < count )
                {
                // We need to stop the view finder as well.
                iController->StopViewFinder();

                active++;
                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;
                }
            break;
            }
        case EKeyOK: //Snap
            {
            DoSnapL();
            break;
            }
        default:
            return EKeyWasNotConsumed;
            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;
			}
        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->PlaySnapSound();
        iController->SnapL();
        iCameraMode = EImageSnapped;
        iController->SetEngineState( ESnappingPicture );
        }
    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 "Standard" and "Portrait" tabs
    iController->RedrawNaviTabsL();

    //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;
    }

⌨️ 快捷键说明

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