#ifndef DRAGlINEHANDLER_H
#define DRAGlINEHANDLER_H

#include <QApplication>
#include <QMouseEvent>
#include <QDebug>
#include <QPixmap>
#include <QLabel>
#include <QCursor>

#include "qcustomplot.h"

class DragLineHandler : public QObject
{
    Q_OBJECT
public:
    DragLineHandler(QCustomPlot *plot, QCPItemStraightLine *line1, QCPItemStraightLine *line2,
                    QCPGraph*graph,QObject *parent);

    ~DragLineHandler();

    void setEnable(const bool flag){_enableFlag = flag;}
signals:
    void sigSendLineXCoord(const int,const double);
protected:
    bool eventFilter(QObject *obj, QEvent *event) override;
private:
    int findClosestIndex(const QVector<double> &data, double target);
    void updateSelectedRegion();
    bool isNearLine(QCPItemStraightLine *line, const QPoint &pos);
private:
    bool _enableFlag;
    QCustomPlot *_plot;
    QCPItemStraightLine *_line1,*_line2;
    QCPItemStraightLine *_draggingLine = nullptr;
    QCPGraph *_graph;
};

#endif
