#ifndef CCTRLGRAPHOPENGL_H
#define CCTRLGRAPHOPENGL_H
#include "base.h"
#include "cmwidget.h"
#include <QRectF>
#include <QList>
#include <QPainter>
#include <QMouseEvent>
#include <QWheelEvent>
#include <QPixmap>
#include "cshapelogic.h"

#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include "cprecisetime.h"
#include "export_ctrls_graph.h"
class CTRLS_GRAPH_EXPORT CCtrlGraphOpenGL : public QOpenGLWidget, protected QOpenGLFunctions
{
    Q_OBJECT

public:
    enum ZeroPos
    {
        CENTER_POS,
        LEFT_BOTTOM,

        LEFT_CENTER,
        LEFT_TOP,

        BOTTOM_CENTER,
        BOTTOM_RIGHT,
    };
    void initializeGL() Q_DECL_OVERRIDE;
    void resizeGL(int w, int h) Q_DECL_OVERRIDE;
    void paintGL() Q_DECL_OVERRIDE;

    explicit CCtrlGraphOpenGL(QWidget *parent = 0);
    ~CCtrlGraphOpenGL();

    virtual void MInit();
    virtual void MTimeFresh();
    virtual void MFresh();
    virtual void MApply();
//	virtual void paintEvent(QPaintEvent *pEvent);

	virtual void showEvent(QShowEvent * pEvent);
    virtual void mousePressEvent(QMouseEvent *pEvent);
    virtual void mouseReleaseEvent(QMouseEvent *pEvent);
    virtual void mouseMoveEvent(QMouseEvent *pEvent);
    virtual void wheelEvent(QWheelEvent *pEvent);
//    virtual void resizeEvent(QResizeEvent *);
	virtual QString MakeCoordText(double dPos, bool bX = true);
	virtual void refreshPixmap(bool bupdate = true);
	virtual void  init_rectWindow();
public:
	CRect_logic m_rectWindow;
    int32_t m_iMargin_Left;
    int32_t m_iMargin_Right;
    int32_t m_iMargin_Top;
    int32_t m_iMargin_Bottom;
    int32_t m_iMargin;
    int32_t m_iCoordLineLength;
	bool m_bISOTROPIC;
public:
	double m_dRangeXMin;
    double m_dRangeXMax;
	QList<double> lUnitsX;
	QString m_strUnitX;
	double m_dCurUnitX;

	double m_dRangeYMin;
    double m_dRangeYMax;
	QList<double> lUnitsY;
	QString m_strUnitY;
    double m_dCurUnitY;

    QString m_sName;
public:
	void CalcuTransfrom();
    void ZoomIn();
	void ZoomOut();
    void ZoomFit();
	void draw_Background(QPainter& painter);
	QRectF get_rectClip();
	void adjust_rectWindow(bool bresetZero);
	void SetStartXY(double dStartX, double dStartY);
protected:
    virtual void updaterubberBandRect();
public:
    int  m_iZeroPos;
    int m_iPenWidth;
	bool m_bEnableZoom;
    bool m_bEnbleDrawText;
	QPixmap m_Pixmap;
	QTransform m_trans_LP2DP;
	QTransform m_trans_DP2LP;
protected:
    bool m_bInit;
    QColor m_BKColor;
	QRect m_rubberBandRect;
	bool m_bCapture;
	bool m_bXVertical;
    CPreciseTime m_timeFPS;
    double m_dFPS;
    int m_iFrame;
private:
	double m_dStartX;
	double m_dStartY;
};

#endif // CCTRLGRAPHOPENGL_H
