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

📄 cameraappbasecontainer.cpp

📁 Symbian智能手机操作系统源代码值的参考_摄像头
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CCameraAppBaseContainer from CameraAppBaseContainer.cpp
*  Part of  : CameraApp
*  Created  : 05/06/2006 by Forum Nokia
*  Version  : 2.0
*  Copyright: Nokia Corporation, 2006
* ============================================================================
*/

#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"

// Constants
const TInt KErrorMsgXPos = 0;
const TInt KErrorMsgYPos = 50;
const TInt KErrorMaxWidth = 160;
const TInt KRedColor = 35;

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

	void CCameraAppBaseContainer::ConstructL(const TRect& aRect)

	Description: second phase constructor
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraAppBaseContainer::ConstructL(const TRect& aRect)
    {
    iNaviLabel = 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()
    {
    if (iOffScreenBitmap)
        delete iOffScreenBitmap;
    if (iFbsBitGc)
        delete iFbsBitGc;
    if (iBmpDevice)    
        delete iBmpDevice;
    
    iBitmap = NULL;

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

    }

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

	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(CAknNavigationDecorator* aNaviDecorator)
    {
    //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))));

    CAknTabGroup* tabGroup = (STATIC_CAST(CAknTabGroup*, aNaviDecorator->
        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(*aNaviDecorator);
    }

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

	void CCameraAppBaseContainer::TabChangedL(TInt aIndex )

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

    Return values: N/A

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

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

	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( KErrorMsgXPos, KErrorMsgYPos );
    iFbsBitGc->DrawText( aMsg, 
                  TRect( point, TSize( KErrorMaxWidth, height )), 
                  ascent,
                  CGraphicsContext::ERight,
                  0 );

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

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

    void CCameraAppBaseContainer::SizeChanged()

    Description: From CCoeControl, called when this control's rect changes
    Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/    
void CCameraAppBaseContainer::SizeChanged()
    {
        TRect rect = Rect();
        TRAPD(ignore, iController.ClientRectChangedL(rect));
    }    

⌨️ 快捷键说明

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