Mangiare Senza Glutine disponibile su App Store

Per altre informazioni scrivi a fabriziocaldarelli@negusweb.it

Progetto completo per usare la camera su Symbian Qt 4.6 (senza Qt Mobility)

Da Programmazione Software.

(goto English version)

Di seguito i sorgenti ed il progetto completo per usare la camera su Symbian Qt 4.6 (senza usare le Qt Mobility).

Il progetto è molto semplice, si compone di 2 schermate che per rendere ancora più semplificata la lettura sono state create programmaticamente.

Il primo schermo visualizza solo un pulsante per accedere al secondo dove viene visualizzata il viewfinder della camera.

Il progetto lo potete scaricare da: Progetto completo


TestCamera.pro

#-------------------------------------------------
#
# Project created by QtCreator 2011-01-12T10:48:09
#
#-------------------------------------------------
 
QT       += core gui
 
TARGET = TestCamera
TEMPLATE = app
 
 
SOURCES += main.cpp\
        mainwindow.cpp
 
HEADERS  += mainwindow.h
 
FORMS    +=
 
CONFIG += mobility
MOBILITY = 
 
symbian {
    TARGET.UID3 = 0xe96e71cb
    TARGET.CAPABILITY += UserEnvironment
    TARGET.EPOCSTACKSIZE = 0x14000
    TARGET.EPOCHEAPSIZE = 0x020000 0x800000
 
    LIBS += -lecam -lfbscli                 # use camera
 
}

main.cpp

#include <QtGui/QApplication>
#include "mainwindow.h"
 
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
#if defined(Q_WS_S60)
    w.showMaximized();
#else
    w.show();
#endif
 
    return a.exec();
}

MainWindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
 
#include <QMainWindow>
#include <QLabel>
 
#ifdef Q_WS_S60
#include <ecam.h>
#include <fbs.h>
#endif
 
 
class MainWindow : public QMainWindow
#ifdef Q_WS_S60
, public MCameraObserver2
#endif
{
    Q_OBJECT
 
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
 
public:
    void CreateFirstScreen();
    void CreateSecondScreen();
    void StartCamera();
    void StopCamera();
 
private slots:
    void OnBtnGoToSecondScreenClicked();
    void OnBtnGoToFirstScreenClicked();
 
private:
    QWidget *firstScreen;
    QWidget *secondScreen;
    QLabel *secondScreenImgPreview;
 
/* CODE TO USE CAMERA */
#ifdef Q_WS_S60
private:
    void HandleEvent(const TECAMEvent& aEvent);
    void ViewFinderReady(MCameraBuffer& aCameraBuffer,TInt aError);
    void ImageBufferReady(MCameraBuffer& aCameraBuffer,TInt aError);
    void VideoBufferReady(MCameraBuffer& aCameraBuffer,TInt aError);
 
 
private:
    CCamera         *iCamera;
#endif
 
};
 
#endif // MAINWINDOW_H

MainWindow.cpp

#include "mainwindow.h"
#include <QGridLayout>
#include <QPushButton>
#include <QDebug>
#include <QVBoxLayout>
 
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
{
    this->firstScreen = NULL;
    this->secondScreen = NULL;
    this->secondScreenImgPreview = NULL;
 
#ifdef Q_WS_S60
    this->iCamera = NULL;
#endif
 
    CreateFirstScreen();
    this->setCentralWidget(this->firstScreen);
}
 
 
MainWindow::~MainWindow()
{
}
 
void MainWindow::CreateFirstScreen()
{
    this->firstScreen = new QWidget(this);
 
    QVBoxLayout *layout = new QVBoxLayout(this->firstScreen);
    QPushButton *btnGoToSecondScreen = new QPushButton(this->firstScreen);
    connect(btnGoToSecondScreen, SIGNAL(clicked()), this, SLOT(OnBtnGoToSecondScreenClicked()));
    btnGoToSecondScreen->setText("Go to second screen");
    layout->addWidget(btnGoToSecondScreen);
    this->firstScreen->setLayout(layout);
 
}
 
void MainWindow::OnBtnGoToSecondScreenClicked()
{
    CreateSecondScreen();
    this->setCentralWidget(this->secondScreen);
    this->firstScreen = NULL;
}
 
void MainWindow::OnBtnGoToFirstScreenClicked()
{
    StopCamera();
 
    CreateFirstScreen();
    this->setCentralWidget(this->firstScreen);
    this->secondScreen = NULL;
}
 
void MainWindow::CreateSecondScreen()
{
    this->secondScreen = new QWidget(this);
 
    QVBoxLayout *layout = new QVBoxLayout(this->secondScreen);
 
    this->secondScreenImgPreview = new QLabel(this->secondScreen);
    layout->addWidget(this->secondScreenImgPreview);
 
    QPushButton *btnGoToFirstScreen = new QPushButton(this->secondScreen);
    connect(btnGoToFirstScreen, SIGNAL(clicked()), this, SLOT(OnBtnGoToFirstScreenClicked()));
    btnGoToFirstScreen->setText("Go to first screen");
    layout->addWidget(btnGoToFirstScreen);
    this->secondScreen->setLayout(layout);
 
    StartCamera();
 
}
 
void MainWindow::StartCamera()
{
#ifdef Q_WS_S60
    iCamera = CCamera::New2L(*this, 0, 0);
    iCamera->Reserve();
#endif
}
 
void MainWindow::StopCamera()
{
#ifdef Q_WS_S60
    iCamera->StopViewFinder();
    iCamera->PowerOff();
    delete iCamera;
    iCamera = NULL;
#endif
}
 
#ifdef Q_WS_S60
void MainWindow::HandleEvent(const TECAMEvent& aEvent)
{
    qDebug()<< "HandleEvent";
 
    qDebug() << "Error code: " << aEvent.iErrorCode;
 
    if (aEvent.iEventType == KUidECamEventReserveComplete)
    {
        //Reserve Complete
        qDebug()<<"Reserve Complete";
        iCamera->PowerOn();
    }
 
    if (aEvent.iEventType == KUidECamEventPowerOnComplete)
    {
        //PowerOn Complete
        qDebug()<<"PowerOn complete";
 
        TSize sz(240,180);
        iCamera->StartViewFinderBitmapsL(sz);
    }
}
 
void MainWindow::ViewFinderReady(MCameraBuffer& aCameraBuffer,TInt aError)
{
    qDebug() << "ViewFinderReady";
    CFbsBitmap bmp;
    bmp.Duplicate(aCameraBuffer.BitmapL(0).Handle());
    QPixmap pxm = QPixmap::fromSymbianCFbsBitmap(&bmp);
 
    this->secondScreenImgPreview->setPixmap(pxm);
 
    aCameraBuffer.Release();
}
 
void MainWindow::ImageBufferReady(MCameraBuffer& aCameraBuffer,TInt aError)
{
    qDebug() << "ImageBufferReady";
    aCameraBuffer.Release();
}
 
void MainWindow::VideoBufferReady(MCameraBuffer& aCameraBuffer,TInt aError)
{
    qDebug() << "VideoBufferReady";
    aCameraBuffer.Release();
}
#endif