#ifndef FORMCAPTURE_H
#define FORMCAPTURE_H

#include <QWidget>

#include "common.h"
#include "formcaptureimageselect.h"

#include "qvideowidget.h"

#include "sthreadwatchvideolink.h"



#include "dialogprogress.h"


#include <QTimer>
#include <QElapsedTimer>



namespace Ui {
class FormCapture;
}

class FormCapture : public QWidget
{
    Q_OBJECT

public:
    explicit FormCapture(QWidget *parent = nullptr);
    virtual ~FormCapture();

    QVideoWidget* GetVideoWidget();

    void Init();
    void ExitCapture();    

    void WriteDatabaseListCapture();

    virtual void UpdateViewer();

    virtual void wheelEvent(QWheelEvent *event);

    void UpdateObjectDisplay(vector<QRect>& listRectDisplay);

    void UpdateMakeDICOMInfo(int nCount, int nTotalCount);
    void UpdateSendInfo(int nCount, int nTotalCount);
    void UpdateSendComplete();
    void UpdateSendFailed();

    void VideoSaveEnd();

public:
    virtual void resizeEvent(QResizeEvent *event);
    virtual void keyReleaseEvent(QKeyEvent *event);

protected:
    bool m_bPrevConnectHDMI;
    SThreadWatchVideoLink* m_pThreadWatchVideoLink;
    QElapsedTimer m_TimerStartPipeLine;
    bool m_bSendBackground;
    vector<FormCaptureImageSelect*> m_ListFormVerticalImageSelect;
    vector<FormCaptureImageSelect*> m_ListFormHorizontalImageSelect;
    int m_bAutoVideoCapture;
    int m_nCurrentPos;
    int m_nIndexCurrent;
    int m_nCaptureImageCount;
    QTimer m_Timer;
    QTimer m_TimerCaptureInfo;
    QTimer m_TimerCaptureBeepSound;
    QTimer m_TimerCaptureImage;
    QTimer m_TimerCaptureVideo;
    QTimer m_TimerCaptureSingleShot;
    QElapsedTimer m_TimeCapture;
    QElapsedTimer m_TimeCaptureVideo;

    //QTime m_TimeHandSwitchOn;

    int m_nHandSwitchValue;
    int m_nPrevHandSwitchValue;


    int m_nItemPerPage;



    DialogProgress* m_pDialogSendProgress;

    bool m_bDisconnectCheck;
    bool m_bEncodingVideo;

    bool m_bExecStopRTSP;


    void CheckVideoDevice_old();

public slots:
    void FinishBeep();
    void CheckCaptureTimeInfo();
    void CheckVideoDevice();
    void SingleDown();
    void SingleUp();

    void captureImage(CAPTURE_IMAGE* pCaptureImage);
    void captureVideo(CAPTURE_IMAGE* pCaptureImage);

    void VideoStopEnable();
    void ImageCaptureEnable();

    void CaptureSingleShot();


    void CaptureHandSwitch();

    void CaptureFootSwitch();

    void SetHDMICalbeConnect(bool bCableConnect);

private slots:
    void HDMICalbeConnect(bool bCableConnect);
    void VideoButtonChange(bool bEncodingVideo);
    void CloseSelectForm();
    void ThumbnailClicked(void* pData);

    void valueChangedScrollBarVertical(int value);
    void valueChangedScrollBarHorizontal(int value);

    void on_pushButton_EXIT_clicked();


    void on_pushButton_ACQ_clicked();

    void on_pushButton_VID_clicked();

    void on_horizontalSlider_Hue_valueChanged(int value);

    void on_horizontalSlider_Saturation_valueChanged(int value);

    void on_pushButton_SEND_clicked();

    void on_pushButton_DELETE_clicked();

    void on_checkBox_Detection_toggled(bool checked);

    void OnDoubleClicked();

signals:
    void BackupNetworkShareFolder(QString strFilename);
    //void ExitCapture();

private:
    Ui::FormCapture *ui;
};

#endif // FORMCAPTURE_H
