#ifndef VIDEOWIDGET_H
#define VIDEOWIDGET_H

#include <QWidget>
#include "videostream.h"
#include "videoglobal.h"

extern "C" {
 #include <gst/gst.h>
}

class VIDEO_EXPORT VideoWidget : public QWidget
{
    Q_OBJECT

        Q_PROPERTY(uint         cropLeft         READ getCropLeft         WRITE setCropLeft        );
        Q_PROPERTY(uint         cropRight        READ getCropRight        WRITE setCropRight       );
        Q_PROPERTY(uint         cropTop          READ getCropTop          WRITE setCropTop         );
        Q_PROPERTY(uint         cropBottom       READ getCropBottom       WRITE setCropBottom      );
        Q_PROPERTY(bool         mirror           READ getMirror           WRITE setMirror          );
        Q_PROPERTY(bool         forceAspectRatio READ getForceAspectRatio WRITE setForceAspectRatio);
        Q_PROPERTY(E_RESOLUTION resolution       READ getResolution       WRITE setResolution      );
        Q_ENUMS(E_RESOLUTION);

    public:
        enum E_RESOLUTION {
            E_QCIF,
            E_CIF,
            E_2CIF,
            E_4CIF,
            E_CUSTOM
        };

        VideoWidget(QWidget *parent = 0);
        virtual ~VideoWidget();

        void connect(VideoStream* videoStream);
        void disconnect();
        bool connected() const;

        void         setCropLeft(int pixel);
        uint         getCropLeft() const;
        void         setCropRight(int pixel);
        uint         getCropRight() const;
        void         setCropTop(int pixel);
        uint         getCropTop() const;
        void         setCropBottom(int pixel);
        uint         getCropBottom() const;
        void         setMirror(bool mirror);
        bool         getMirror() const;
        void         setForceAspectRatio(bool force);
        bool         getForceAspectRatio() const;
        void         setResolution(E_RESOLUTION resolution);
        E_RESOLUTION getResolution() const;

    private:
        static const QSize SIZE_QCIF;
        static const QSize SIZE_CIF;
        static const QSize SIZE_2CIF;
        static const QSize SIZE_4CIF;

        static bool handleMessage (GstBus *bus, GstMessage *message, gpointer data);

        void paintEvent(QPaintEvent *event);
        void mousePressEvent(QMouseEvent *event);
        void resizeEvent(QResizeEvent * event);

        unsigned long a_winId;
        unsigned long a_sigId;
        uint          a_cropLeft;
        uint          a_cropRight;
        uint          a_cropTop;
        uint          a_cropBottom;
        bool          a_mirror;
        bool          a_forceAspectRatio;
        E_RESOLUTION  a_resolution;
        VideoStream   *a_videoStream;
        GstElement    *a_queue;
        GstElement    *a_videoCrop;
        GstElement    *a_videoFlip;
        GstElement    *a_colorSpace;
        GstElement    *a_sink;

    signals:
        void sig_clicked();

};

#endif
