/*
 * Copyright (c) 2011 Nokia Corporation.
 */

#ifndef MirrorHouse_H
#define MirrorHouse_H

#include <QtGui>


#include "cmirrorhouse.h"

// QtMobility API
#include <QSystemScreenSaver>
QTM_USE_NAMESPACE

// Unlike the other APIs in Qt Mobility,
// the Multimedia API is not in the QtMobility namespace
#include <QCamera>
#include <QCameraImageCapture>
#include <QCameraViewfinder>
#include <QAbstractVideoSurface>
#include <QVideoRendererControl>
#include <QVideoSurfaceFormat>


/* ***************************************************************************
* MyVideoSurface
*/
class VideoIF
{
public:
    virtual void updateVideo() = 0;
};
class MyVideoSurface: public QAbstractVideoSurface
{
Q_OBJECT

public:
    MyVideoSurface(QWidget* widget, VideoIF* target, QObject * parent = 0);
    ~MyVideoSurface();

    bool start(const QVideoSurfaceFormat &format);

    bool present(const QVideoFrame &frame);

    QList<QVideoFrame::PixelFormat> supportedPixelFormats(
                QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const;

    void paint(QPainter*);

private:
    QWidget*                m_targetWidget;
    VideoIF*                m_target;
    QVideoFrame             m_frame;
    QImage::Format          m_imageFormat;
    QVideoSurfaceFormat     m_videoFormat;
    int                     m_frameDelayCount;
    CMirrorHouse*           m_mirrorHouseEffect;
    QImage                  m_sourceImage;
    QImage                  m_targetImage;

};



/* ***************************************************************************
* MirrorHouse
*/
class MirrorHouse: public QMainWindow, public VideoIF
{
Q_OBJECT

public:
    MirrorHouse(QWidget *parent = 0);
    ~MirrorHouse();

    void mousePressEvent(QMouseEvent *);
    void paintEvent(QPaintEvent*);
    void updateVideo();

public slots:
    void enableCamera();
    void restartCamera();
    void error(QCamera::Error);

private:
    QWidget*                m_videoWidget;
    QCamera*                m_camera;
    MyVideoSurface*         m_myVideoSurface;
    bool                    m_showViewFinder;

    QList<QByteArray>       m_devices;
    int                     m_deviceId;

    QSystemScreenSaver*     m_systemScreenSaver;
};

#endif // MirrorHouse_H
