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

📄 cameraappbasecontainer.cpp

📁 S60官方摄像头程序
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CCameraAppBaseContainer from CameraAppContainer.h
*  Part of  : CameraApp
*  Created  : 02/09/2004 by Forum Nokia
*  Implementation notes:
*     Initial content was generated by Series 60 AppWizard.
*  Version  :
*  Copyright: Nokia Cooperation
* ============================================================================
*/

#include <w32std.h>
#include <coemain.h>
#include <aknsutils.h>
#include <aknnavide.h>
#include <barsread.h>
#include <akntabgrp.h>
#include <CameraApp.rsg>

#include "CameraAppBaseContainer.h"
#include "CameraAppController.h"

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

	void CCameraAppBaseContainer::ConstructL(const TRect& aRect)

	Description: second phase constructor
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraAppBaseContainer::ConstructL(const TRect& aRect)
    {
	iNaviLabel = NULL;
	iNaviDecorator = NULL;

    CreateWindowL();

    SetRect(aRect);
    ActivateL();

	// This should be called after the windows has been activated
	CreateOffScreenBitmapL();
    iController.StartViewFinderL();
    }

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

	CCameraAppBaseContainer::~CCameraAppBaseContainer()

	Description: destructor, free allocated resources
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
CCameraAppBaseContainer::~CCameraAppBaseContainer()
    {
    delete iOffScreenBitmap;
    delete iFbsBitGc;
    delete iBmpDevice;
	iBitmap = NULL;

	// Remove the navi label if it is not removed.
	if ( iNaviLabel )    
		delete (iNaviLabel);

	if ( iNaviDecorator )
		delete iNaviDecorator;
    }

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

	CCameraViewFinderContainer::DrawImage(CWindowGc& aGc ,const TRect& aRect) 
								const

	Description: render bitmap image onto a real screen
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraAppBaseContainer::DrawImage(CWindowGc& aGc ,const TRect& aRect) const
    {
    TSize bmpSizeInPixels( iBitmap->SizeInPixels() );
    TInt xDelta = (aRect.Width() - bmpSizeInPixels.iWidth) / 2;
    TInt yDelta = (aRect.Height() - bmpSizeInPixels.iHeight) / 2;
    TPoint pos( xDelta, yDelta ); // displacement vector
    pos += aRect.iTl; // bitmap top left corner position

    // Drawing viewfinder image to bitmap
    iFbsBitGc->BitBlt( pos, iBitmap, TRect( TPoint( 0, 0 ), bmpSizeInPixels ) );

    // Draws bitmap with indicators on the screen
    TSize size( iOffScreenBitmap->SizeInPixels() );
    aGc.BitBlt( TPoint(0,0), iOffScreenBitmap, TRect( TPoint(0,0), size ) );
    }


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

	void CCameraAppBaseContainer::HandleControlEventL(
		CCoeControl* aControl,TCoeEvent aEventType )

	Description: Called by framework to handle control event
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraAppBaseContainer::HandleControlEventL(
    CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
    {
    }


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

	void CCameraAppBaseContainer::CreateOffScreenBitmapL()

	Description: Creates the data member off screen bitmap
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraAppBaseContainer::CreateOffScreenBitmapL()
    {
    iOffScreenBitmap = new (ELeave) CWsBitmap( iCoeEnv->WsSession() );
    
	TSize size = Rect().Size();

    TInt createError = iOffScreenBitmap->Create( size, iController.DisplayMode() );
    User::LeaveIfError( createError );

    iFbsBitGc = CFbsBitGc::NewL(); //graphic context
    iBmpDevice = CFbsBitmapDevice::NewL(iOffScreenBitmap);
    iFbsBitGc->Activate(iBmpDevice);
    iFbsBitGc->SetBrushColor( AKN_LAF_COLOR( KWhiteColor ) );

    MAknsSkinInstance* skin = AknsUtils::SkinInstance();
    CFbsBitmap* bitmap = AknsUtils::GetCachedBitmap( skin, KAknsIIDQsnBgAreaMain );
    if ( bitmap ) 
        {
        iFbsBitGc->BitBlt( TPoint(0,0), bitmap );
        }

    iOffScreenBitmapCreated = ETrue;
    }

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

	void CCameraViewFinderContainer::DrawImageNow(CFbsBitmap& aBitmap)

	Description: Gets the image to draw from Controller and calls DrawNow()
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraAppBaseContainer::DrawImageNow(CFbsBitmap& aBitmap)
    {
    iBitmap = &aBitmap;
    DrawNow();
    }


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

	void CCameraViewFinderContainer::ReDrawOffScreenBitmap()

	Description: Redraws offscreen bitmap with Landscape focus indicators
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraAppBaseContainer::ReDrawOffScreenBitmap()
    {
    iOffScreenBitmapCreated = ETrue;

    iFbsBitGc->SetBrushColor( AKN_LAF_COLOR( KWhiteColor ) );
    iFbsBitGc->Clear();

    MAknsSkinInstance* skin = AknsUtils::SkinInstance();
    CFbsBitmap* bitmap = AknsUtils::GetCachedBitmap( skin, KAknsIIDQsnBgAreaMain );
    if ( bitmap ) 
        {
        iFbsBitGc->BitBlt( TPoint(0,0), bitmap );
        }

    DrawNow();  // clear screen 
    }

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

	TKeyResponse CCameraAppBaseContainer::OfferKeyEventL(
					const TKeyEvent& aKeyEvent,TEventCode aType)

	Description: Called by framework when a key is pressed, Handles this 
				 application view's command keys. Forwards other keys to child 
				 control(s).
	Comments   :

    Return values: whether the key has been consumed or not.

-----------------------------------------------------------------------------
*/
TKeyResponse CCameraAppBaseContainer::OfferKeyEventL(const TKeyEvent& /*aKeyEvent*/,
													 TEventCode /*aType*/)
	{
    TKeyResponse keyConsumed = EKeyWasNotConsumed;
	return keyConsumed;
	}

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

	void CCameraAppBaseContainer::ShowConversionStatusL(const TDesC &aStatus)

	Description: show the conversion status according to status "Saving image"
				 or "Image saved"
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraAppBaseContainer::ShowConversionStatusL(const TDesC &aStatus)
	{
        
	// Fetch pointer to the default navi pane control
    CEikStatusPane* sp = (STATIC_CAST(CAknAppUi*, iEikonEnv->EikAppUi()))->StatusPane();
    CAknNavigationControlContainer* naviContainer = 
				(STATIC_CAST(CAknNavigationControlContainer*, 
				sp->ControlL(TUid::Uid(EEikStatusPaneUidNavi))));
        
	CAknNavigationDecorator* oldDecorator = NULL;

    if ( iNaviLabel )
        {
        oldDecorator = iNaviLabel;
        iNaviLabel = NULL;
        CleanupStack::PushL( oldDecorator );
        }

    iNaviLabel = naviContainer->CreateNavigationLabelL( aStatus );

    // Activate navi label so that it becomes visible and active
    naviContainer->PushL( *iNaviLabel );

	// The previously allocated memory is freed here.
	if ( oldDecorator )
        {
        CleanupStack::PopAndDestroy(); // oldDecorator
        }
	}


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

	void CCameraAppBaseContainer::RedrawNaviTabsL()

	Description: redraws the navi tabs, showing "Portrait" and "Standard"
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraAppBaseContainer::RedrawNaviTabsL()
	{
    //Construct Title pane from resource
    CEikStatusPane* sp = (STATIC_CAST(CAknAppUi*, 
		                  iEikonEnv->EikAppUi()))->StatusPane();

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

    TResourceReader reader;
    iCoeEnv->CreateResourceReaderLC(reader, R_CAMERA_NAVI_PANE_TAB_GROUP);

	// If it has been allocated, free it just in case we get some memory leak.
	if ( iNaviDecorator )
		delete iNaviDecorator;

    iNaviDecorator = naviPane->CreateTabGroupL(reader, this);   

    CleanupStack::PopAndDestroy();  // resource reader    

    CAknTabGroup* tabGroup = (STATIC_CAST(CAknTabGroup*, iNaviDecorator->DecoratedControl()));

    switch( iController.CameraMode() )
        {
        case ECameraLandscapeMode://Default Tab
            tabGroup->SetActiveTabById( ECameraAppView1Tab );
            break;
        case ECameraPortraitMode:
            tabGroup->SetActiveTabById( ECameraAppView2Tab );
            break;
        }
    
    // Activate tab group so that tabs become visible and active
    naviPane->PushL(*iNaviDecorator);
	}

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

	void CCameraAppBaseContainer::TabChangedL(TInt aIndex )

	Description: called by framework when tab has been changed
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraAppBaseContainer::TabChangedL(TInt /*aIndex*/ )
	{
	}

const TInt KErrorMaxWidth = 160;
const TInt KRedColor = 35;

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

	void CCameraAppBaseContainer::ShowErrorMessage(const TDesC &aMsg)

	Description: Show the error message on the screen
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraAppBaseContainer::ShowErrorMessage(const TDesC &aMsg)
	{
    const CFont* font = LatinBold16();
    iFbsBitGc->UseFont( font );
    TInt ascent = font->AscentInPixels();
    TInt height = font->HeightInPixels();
    iFbsBitGc->SetPenColor( AKN_LAF_COLOR( KRedColor ) );
	TPoint point( 0, 50 );
    iFbsBitGc->DrawText( aMsg, 
                  TRect( point, TSize( KErrorMaxWidth, height )), 
                  ascent,
                  CGraphicsContext::ERight,
                  0 );

	// Draw the offscreen bitmap now to show the message
	DrawNow();
	}

⌨️ 快捷键说明

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