📄 cameraappappui.cpp
字号:
/*
* ============================================================================
* Name : CCameraAppAppUi from CameraAppAppUi.cpp
* Part of : CameraApp
* Created : 02/09/2004 by Forum Nokia
* Implementation notes:
* Version :
* Copyright: Nokia Corporation, 2004
* ============================================================================
*/
#include <avkon.hrh>
#include <eikmenup.h>
#include <CameraApp.rsg>
#include "CameraAppAppUi.h"
#include "CameraAppView.h"
#include "CameraAppPortraitView.h"
#include "Cameraapp.hrh"
#include "CameraAppController.h"
/*
-----------------------------------------------------------------------------
void CCameraAppAppUi::ConstructL()
Description: second phase constructor
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
void CCameraAppAppUi::ConstructL()
{
BaseConstructL();
// 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;
iController->ConstructL();
// Initialize the cmaera
iController->InitializeCameraL();
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()
{
delete iDecoratedTabGroup;
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 == NULL )
{
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 high 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 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 "C:\Nokia\images\" file 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()
{
// iController->StartViewFinderL();
// Gets viewId to Activate media Gallery view
TVwsViewId id = TVwsViewId( TUid::Uid(KMediaGalleryUID3),
TUid::Uid(KMediaGalleryListViewUID) );
TParsePtrC parse( iController->ImagePath() );
TFileName rootPath( parse.DriveAndPath() );
//Pass the 16-bit filename around in an 8-bit descriptor
TPtrC8 ptr8( ( TText8* )rootPath.Ptr(), rootPath.Size() );
ActivateViewL( id, TUid::Uid( KMediaGalleryCmdMoveFocusTo ), ptr8 );
}
/*
-----------------------------------------------------------------------------
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
iController->RedrawNaviTabsL();
iController->StartViewFinderL();
iCameraMode = EViewFinding;
}
}
/*
-----------------------------------------------------------------------------
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;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -