?? cameraappcontroller.cpp
字號:
/*
* ============================================================================
* Name : CCameraAppController from CameraAppController.cpp
* Part of : CameraApp
* Created : 05/06/2006 by Forum Nokia
* Version : 2.0
* Copyright: Nokia Corporation, 2006
* ============================================================================
*/
#include <AknViewAppUi.h>
#include <CameraApp.rsg>
#include <bautils.h>
#include <PathInfo.h>
#include "CameraAppController.h"
#include "CameraAppContainer.h"
#include "CameraAppBaseContainer.h"
#include "CameraAppView.h"
#include "CameraAppPortraitView.h"
#include "CameraAppAppUi.h"
#include "CameraCaptureEngine.h"
// Constants
const TInt KFileNameIndexMaxLength = 5;
_LIT(KCameraInUse, "Camera in use by another app.");
_LIT(KNoCamera, "Camera not available.");
_LIT(KSnapSoundFile, "Camera1a_2_8kHz.wav");
_LIT(KFocusedSoundFile, "focused.wav");
// For 2nd Edition emulator only
#ifdef __WINS__
_LIT(KEmulatorPath, "c:\\system\\Apps\\cameraapp\\");
#endif
/*
-----------------------------------------------------------------------------
CCameraAppController::CCameraAppController()
Description: C++ default constructor
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
CCameraAppController::CCameraAppController(CAknViewAppUi& aAppUi)
:iAppUi( aAppUi ),
iCameraMode( ECameraLandscapeMode ),
iCameraCaptureEngine( 0 ),
iContainer( 0 )
{
}
/*
-----------------------------------------------------------------------------
void CCameraAppController::PowerOff()
Description: powers off the camera
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
void CCameraAppController::PowerOff()
{
iCameraCaptureEngine->PowerOff();
}
/*
-----------------------------------------------------------------------------
CCameraAppController::~CCameraAppController()
Description: destructor, free allocated resources
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
CCameraAppController::~CCameraAppController()
{
// Power off the camera
PowerOff();
delete iCameraCaptureEngine;
delete iBitmapSnap;
delete iImagePath;
delete iPath;
if (iSoundPlayer)
{
iSoundPlayer->Close();
delete iSoundPlayer;
}
}
/*
-----------------------------------------------------------------------------
void CCameraAppController::ConstructL()
Description: Symbian OS second phase constructor
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
void CCameraAppController::ConstructL()
{
iEikEnv = CEikonEnv::Static();
iPath = new(ELeave) TFileName;
// Create the sound player here
CreateSoundPlayerL();
TFileName path = PathInfo::PhoneMemoryRootPath(); //Default
path.Append( PathInfo::ImagesPath() );
iImagePath = HBufC::NewL( path.Length() );
iImagePath->Des().Copy( path );
}
/*
-----------------------------------------------------------------------------
TCameraState CCameraAppController::CameraMode() const
Description: gets the camera mode
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
TCameraState CCameraAppController::CameraMode() const
{
return iCameraMode;
}
/*
-----------------------------------------------------------------------------
void CCameraAppController::SetCameraMode(TCameraState aCameraMode)
Description: Set the camera display mode
Comments :
Return value: N/A
-----------------------------------------------------------------------------
*/
void CCameraAppController::SetCameraMode(TCameraState aCameraMode)
{
iCameraMode = aCameraMode;
}
/*
-----------------------------------------------------------------------------
void SetCaptureModeL(const TSize& aSize, TInt aFormat)
Description: Set the capture mode,used for displaying information about
image size/format
Return value: N/A
-----------------------------------------------------------------------------
*/
void CCameraAppController::SetCaptureModeL(const TSize& aSize,
TInt aFormat,
TBool aAFSupported)
{
iCaptureFormat = aFormat;
TBuf<32> text;
text.Format( _L("[%1.1fM]"), TReal(aSize.iWidth * aSize.iHeight) / 1000000 );
if( iCaptureFormat == CCamera::EFormatExif )
{
text.Append(_L("EXIF"));
}
if( aAFSupported )
{
text.Append(_L("/AF"));
CCamAutoFocus::TAutoFocusRange range;
iCameraCaptureEngine->FocusRange(range);
switch( range )
{
case CCamAutoFocus::ERangeMacro:
text.Append(_L("(m)"));
break;
case CCamAutoFocus::ERangePortrait:
text.Append(_L("(p)"));
break;
case CCamAutoFocus::ERangeNormal:
text.Append(_L("(n)"));
break;
case CCamAutoFocus::ERangeInfinite:
text.Append(_L("(i)"));
break;
default:
break;
}
}
CCameraAppBaseContainer* baseCon =
static_cast<CCameraAppBaseContainer*>(iContainer);
baseCon->ShowCaptureModeL(text);
}
/*
-----------------------------------------------------------------------------
TBool IsPortraitModeSupported()
Description: Checks whether the engine supports capturing in portrait
mode. Currently this is not possible when capturing in
EXIF JPEG format.
Return value: TBool
-----------------------------------------------------------------------------
*/
TBool CCameraAppController::IsPortraitModeSupported()
{
return (iCaptureFormat != CCamera::EFormatExif);
}
/*
-----------------------------------------------------------------------------
TBool IsAutoFocusSupported()
Description: Checks if AF is supported
Return value: TBool
-----------------------------------------------------------------------------
*/
TBool CCameraAppController::IsAutoFocusSupported()
{
return iCameraCaptureEngine->IsAutoFocusSupported();
}
/*
-----------------------------------------------------------------------------
void CCameraAppController::SetFocusRangeL()
Description: Sets the autofocus range.
Return values: N/A
-----------------------------------------------------------------------------
*/
void CCameraAppController::SetFocusRangeL( CCamAutoFocus::TAutoFocusRange aRange )
{
iCameraCaptureEngine->SetFocusRangeL( aRange );
}
/*
-----------------------------------------------------------------------------
TDisplayMode CCameraAppController::DisplayMode() const
Description: Returns default display mode
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
TDisplayMode CCameraAppController::DisplayMode() const
{
return iCameraCaptureEngine->DisplayMode();
}
/*
-----------------------------------------------------------------------------
void CCameraAppController::InitializeCameraL()
Description: Initialize still image capture engine
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
void CCameraAppController::InitializeCameraL(const TRect& aRect)
{
if (!iCameraCaptureEngine)
{
iCameraCaptureEngine = CCameraCaptureEngine::NewL( *this, aRect );
//Create snap image
iBitmapSnap = new (ELeave) CWsBitmap(iEikEnv->WsSession());
User::LeaveIfError( iBitmapSnap->Create(aRect.Size(), DisplayMode()));
}
}
/*
-----------------------------------------------------------------------------
void CCameraAppController::ReleaseCamera()
Description: releases a reserved camera
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
void CCameraAppController::ReleaseCamera()
{
iCameraCaptureEngine->ReleaseCamera();
}
/*
-----------------------------------------------------------------------------
void CCameraAppController::StartViewFinderL()
Description: Starts the view finding operation
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
void CCameraAppController::StartViewFinderL()
{
if(iCameraCaptureEngine->GetEngineState() == EEngineNoHardware)
{
HandleError( KErrHardwareNotAvailable );
return;
}
if(iCameraCaptureEngine->IsViewFinderActive())
return;
iCameraCaptureEngine->SetMode( iCameraMode );
iCameraCaptureEngine->StartViewFinderL();
}
/*
-----------------------------------------------------------------------------
void CCameraAppController::SetAppContainer(CCoeControl* aAppContainer,
TCameraViewIds aViewId)
Description: Gives reference to Active view container to Controller
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
void CCameraAppController::SetAppContainer( CCoeControl* aAppContainer,
TCameraViewIds aViewId)
{
iContainer = aAppContainer;
iActiveView = aViewId;
}
/*
-----------------------------------------------------------------------------
const TDesC& CCameraAppController::ImagePath() const
Description: Returns the complete path of the saved image
Comments :
Return values: Returns the complete path of the saved image
-----------------------------------------------------------------------------
*/
const TDesC& CCameraAppController::ImagePath() const
{
return *iImagePath;
}
/*
-----------------------------------------------------------------------------
const TDesC& CCameraAppController::ImagePath() const
Description: Set the actual bitmap size
Comments :
Return values:
-----------------------------------------------------------------------------
*/
void CCameraAppController::SetActualVFSize( const TSize& /*aSize*/ )
{
if ( iContainer )
{
(STATIC_CAST(CCameraAppContainer*,iContainer))->
ReDrawOffScreenBitmap( );
}
}
/*
-----------------------------------------------------------------------------
void CCameraAppController::ViewFinding( CFbsBitmap& aFrame )
Description: Gets image from image capture engine, and displays it on
screen, called by the capture engine to display the bitmap
Comments :
Return values:
-----------------------------------------------------------------------------
*/
void CCameraAppController::ViewFinding( CFbsBitmap& aFrame )
{
// skip frames if it was requested
if ( iSkipFrames )
{
--iSkipFrames;
return;
}
if ( !iContainer )
{
return;
}
static_cast<CCameraAppBaseContainer*>(iContainer)->DrawImageNow( aFrame );
}
/*
-----------------------------------------------------------------------------
void CCameraAppController::StopViewFinder()
Description: Stops view finding
Comments :
Return values:
-----------------------------------------------------------------------------
*/
void CCameraAppController::StopViewFinder()
{
iCameraCaptureEngine->StopViewFinder();
}
/*
-----------------------------------------------------------------------------
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -