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

📄 filmreel2container.cpp

📁 series60 应用程序开发的源代码 series60 应用程序开发的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/**
*
* @brief Definition of CFilmReel2Container
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/

// INCLUDE FILES

// Class include
#include "FilmReel2Container.h"

// System includes
#include <aknnavi.h>            // CAknNavigationControlContainer
#include <aknnavide.h>            // CAknNavigationDecorator
#include <aknnavilabel.h>        // CAknNaviLabel
#include <aknnotewrappers.h>    // CAknErrorNote
#include <AknAppUi.h>            // CEikButtonGroupContainer
#include <eikapp.h>                // CEikApplication
#include <palbsettings.h>        // TPAlbSettings
#include <palbimagefactory.h>    // KWidth_VGA && KHeight_VGA
#include <StringLoader.h>        // StringLoader

// User includes
#include "CameraTimer.h"        // CCameraTimer
#include <filmreel2.rsg>

// CONSTANTS

const TInt KNumberOfPicturesInRow = 4;
const TInt KNumberOfPicturesInColumn = 4;
const TInt KTotalNumberOfPictures = KNumberOfPicturesInRow * KNumberOfPicturesInColumn;
const TInt KHorizontalDistance = KWidth_VGA / KNumberOfPicturesInRow;
const TInt KVerticalDistance = KHeight_VGA / KNumberOfPicturesInColumn;

_LIT(KDefaultFileName, "FilmReel2.jpg");

const TInt KJpgSavingQualityFactor = 55; // Quality factor for JPG saving
const TInt KFractionOfFontSizeToLowerText = 3;


// ================= MEMBER FUNCTIONS =======================

/**
* Symbian OS 2nd phase constructor.  Creates a Window for the controls, which it contains.
* Constructs a label and adds it to the window, which it then activates.
* @param aRect The rectangle for this window
*/
void CFilmReel2Container::ConstructL(const TRect& aRect)
{
    iCamera = CCamera::NewL(*this, 0);
    iCamera->Reserve();

    iBitmap = new (ELeave) CFbsBitmap();
    iCollageBitmap = new (ELeave) CFbsBitmap();
    User::LeaveIfError(iCollageBitmap->Create(TSize(KWidth_VGA, KHeight_VGA), EColor4K));

    iBitmapDevice = CFbsBitmapDevice::NewL(iCollageBitmap);
    User::LeaveIfError(iBitmapDevice->CreateContext(iBGc));

    // Init a file saver utility
    iFileSaver = CMdaImageBitmapToFileUtility::NewL(*this);
    iFormat = new (ELeave) TMdaJfifClipFormat;

    // Camera Timer
    iCameraTimer = CCameraTimer::NewL(*this);

    // Text strings
    iNotReadyText = StringLoader::LoadL(R_NOT_READY_TEXT);
    iTimeOutText = StringLoader::LoadL(R_TIMED_OUT_TEXT);

    // Fetch pointer to the default navi pane control
    CEikStatusPane* sp = ((CAknAppUi*)iEikonEnv->EikAppUi())->StatusPane();
    iNaviPane = (CAknNavigationControlContainer*)sp->ControlL(TUid::Uid(EEikStatusPaneUidNavi));
    iNaviDecoratorForLabel = iNaviPane->ResourceDecorator();

    if (iNaviDecoratorForLabel)
    {
        iNaviLabel=(CAknNaviLabel*)iNaviDecoratorForLabel->DecoratedControl();
        iNaviLabel->SetNaviLabelType(CAknNaviLabel::EAdditionalInfoLabel);
    }

    SetNaviLabelTextL(R_NOT_READY_TEXT);

    CreateWindowL();
    SetRect(aRect);
    ActivateL();
}

/**
* Symbian OS 2 phase constructor.
* Constructs the CFilmReel2Container using the NewLC method, popping
* the constructed object from the CleanupStack before returning it.
*
* @param aRect The rectangle for this window
* @return The newly constructed CFilmReel2Container
*/
CFilmReel2Container* CFilmReel2Container::NewL(const TRect& aRect)
{
    CFilmReel2Container* self = CFilmReel2Container::NewLC(aRect);
    CleanupStack::Pop(self);
    return self;
}

/**
* Symbian OS 2 phase constructor.
* Constructs the CFilmReel2Container using the constructor and ConstructL
* method, leaving the constructed object on the CleanupStack before returning it.
*
* @param aRect The rectangle for this window
* @return The newly constructed CFilmReel2Container
*/
CFilmReel2Container* CFilmReel2Container::NewLC(const TRect& aRect)
{
    CFilmReel2Container* self = new (ELeave) CFilmReel2Container;
    CleanupStack::PushL(self);
    self->ConstructL(aRect);
    return self;
}

/**
* Destructor.  Frees up memory.
*/
CFilmReel2Container::~CFilmReel2Container()
{
    if (iBitmapViewer)
    {
        iBitmapViewer->Reset();
        delete iBitmapViewer;
    }
    if (iCamera)
    {
        iCamera->PowerOff();
        iCamera->Release();
        delete iCamera;
    }
    delete iBitmap;
    delete iCollageBitmap;
    delete iBGc;
    delete iBitmapDevice;

    delete iFileSaver;
    delete iFormat;

    delete iCameraTimer;

    delete iNotReadyText;
    delete iTimeOutText;

    delete iNaviDecoratorForLabel;
}

/**
* Provides user feedback using the navigation pane for displaying messages.
* @param aTextResourceId the resource ID of the message to display
*/
void CFilmReel2Container::SetNaviLabelTextL(TInt aTextResourceId)
{
    HBufC* text = StringLoader::LoadLC(aTextResourceId);
    SetNaviLabelTextL(*text);
    CleanupStack::PopAndDestroy(text); // text
}

/**
* Provides user feedback using the navigation pane for displaying messages.
* @param aText the text message to display
*/
void CFilmReel2Container::SetNaviLabelTextL(const TDesC& aText)
{
    if (iNaviLabel)
    {
        iNaviLabel->SetTextL(aText);
        iNaviPane->DrawNow();
    }
}

/**
* Called by the framework to draw this control.  Clears the area in
* aRect. Draws preview bitmap while previewing otherwise draws the
* created collage bitmap.
* @param aRect in which to draw
*/
void CFilmReel2Container::Draw(const TRect& aRect) const
{
    CWindowGc& gc = SystemGc();
    gc.Clear(aRect);

    switch(iContainerState)
    {
        case EPreviewing:
            gc.DrawBitmap(Rect(), iBitmapViewer, iBitmapViewer->SizeInPixels());
            break;
        case ERecording:
        case EDisplayingResult:
        case ESavingImage:
            gc.DrawBitmap(Rect(), iCollageBitmap, iCollageBitmap->SizeInPixels());
            break;
        case EPoweredDown:
            DisplayMessage(*iTimeOutText, gc);
            break;
        case ENotReady:
        default:
            DisplayMessage(*iNotReadyText, gc);
            break;
    }
}

/**
* Called by the framework to draw this control.  Clears the area in
* aRect. Draws preview bitmap while previewing otherwise draws the
* created collage bitmap.
* @param aMessage string to display
* @param aGc Window graphic context
*/
void CFilmReel2Container::DisplayMessage(const TDesC& aMessage, CWindowGc& aGc) const
{
    // Draw white background
    aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
    aGc.SetBrushColor(KRgbWhite);
    aGc.DrawRect(Rect());

    // Draw black outline
    aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
    aGc.SetBrushColor(KRgbBlack);
    aGc.DrawRect(Rect());

    aGc.SetPenColor(KRgbBlack);
    const CFont* fontUsed = iEikonEnv->TitleFont();
    aGc.UseFont(fontUsed);

    // Set text position on screen
    TInt baseline = Rect().Height() - fontUsed->AscentInPixels() * KFractionOfFontSizeToLowerText;
    // Margin is zero so that the text will be centred
    TInt margin = 0;

    aGc.DrawText(aMessage, Rect(), baseline, CGraphicsContext::ECenter, margin);
}

void CFilmReel2Container::PowerOnCompleteL()
{
    SetNaviLabelTextL(R_PREVIEWING_TEXT);
    TSize size;

    // Configure the camara
    iCamera->PrepareImageCaptureL(CCamera::EFormatFbsBitmapColor4K, 1);
    iCamera->EnumerateCaptureSizes(size, 1, CCamera::EFormatFbsBitmapColor4K);

    // Start the viewfinder.
    iCamera->StartViewFinderBitmapsL(size);
}

void CFilmReel2Container::ViewFinderFrameReadyL(CFbsBitmap& aBitMap)
{
    if (iBitmapViewer)
    {
        iBitmapViewer->Reset();
        delete iBitmapViewer;
        iBitmapViewer = NULL;
    }

    // Sets the viewer bitmap image to be displayed
    iBitmapViewer = new (ELeave) CFbsBitmap();
    iBitmapViewer->Duplicate (aBitMap.Handle());
    iContainerState = EPreviewing;
    DrawNow();
}

void CFilmReel2Container::ImageReadyL(CFbsBitmap* aBitmap, HBufC8* /*aData*/)
{
    delete iBitmap;
    iBitmap = aBitmap;
    // picture has been taken, so display the bitmap
    DrawNow();

    switch (iContainerState)
    {
        case ERecording:
        {
            // copy image onto the collage bitmap
            iBGc->BitBlt(TPoint(iX * KHorizontalDistance, iY * KVerticalDistance), iBitmap);

⌨️ 快捷键说明

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