#ifndef CENTRALWIDGET_H
#define CENTRALWIDGET_H

#include <QWidget>
#include <QMenu>

#include "qcustomplot.h"
#include "protocol.h"
#include "global.h"
#include "draglinehandler.h"
#include "filemanager.h"

class CentralWidget:public QWidget
{
    Q_OBJECT
public:
    enum AnalysisMode{
        None,
        NumericalLabel,
        StartPoint,
        StopPoint,
        PeakSynthesisAnalysis
    };
    CentralWidget(QWidget *parent = nullptr);
    ~CentralWidget();

    void setAnalysisMode(const AnalysisMode);
    void clearAllData();
signals:
    void sigContextMenuShow(const QPoint);
    void sigSendLineXCoord(const int,const double);
    void sigRightDockWidgetHide();
public slots:
    void slotModeModify(const Global::Mode);
    void slotRecvCommonData(const CommonData&);
    void slotRecvAnalysisFileName(const QString&);
    //analysis setting
    void slotAnalysisSettingLineXPoint(const int index,const double);

    void slotAnalysisSettingApply();
    void slotAnalysisSettingConfirm();
    void slotAnalysisSettingUndo();
    void slotAnalysisSettingCancel();
protected:
    void timerEvent(QTimerEvent* event);
    void contextMenuEvent(QContextMenuEvent *event);
private:
    void setEventHandlerEnable(const bool);
    void drawText(const QPointF,const QString);
    void fillGraph(const double x1,const double x2);
    enum ClearDataMode{
        All,
        Undo
    };
    void clearData(const ClearDataMode);
private:
    AnalysisMode _nanlysisMode;
    QCustomPlot *_customPlot;
    QCPGraph* _graph;
    DragLineHandler* _eventHandler;
    QCPItemStraightLine *_line1,*_line2;
    QVector<FileManager::ExperimentData> _dataVtr;
};

#endif // CENTRALWIDGET_H
