//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      GUI/View/Plotter/ScientificPlot.h
//! @brief     Declares class ScientificPlot.
//!
//! @homepage  http://www.bornagainproject.org
//! @license   GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
//  ************************************************************************************************

#ifndef BORNAGAIN_GUI_VIEW_PLOTTER_SCIENTIFICPLOT_H
#define BORNAGAIN_GUI_VIEW_PLOTTER_SCIENTIFICPLOT_H

#include <QWidget>

class PlotEventHelper;
class QCustomPlot;

//! Common interface for plot-descriptor interaction

class ScientificPlot : public QWidget {
    Q_OBJECT
public:
    enum class PLOT_TYPE { Plot1D, Plot2D };

    explicit ScientificPlot(PLOT_TYPE plot_type);
    ~ScientificPlot() override;

    QCustomPlot* customPlot() { return m_qcp; }
    const QCustomPlot* customPlot() const { return m_qcp; }

    PlotEventHelper* eventHelper() { return m_event_helper; }

    //! Tracks move events (used when showing profile histograms and printing status string)
    void setMouseTrackingEnabled(bool enable);

    //! Returns true if axes rectangle contains given in axes coordinates.
    bool axesRangeContains(double xpos, double ypos) const;

    //! Returns the type of current plot
    PLOT_TYPE plotType() const { return m_plot_type; }

    QRectF viewportRectangle() const;

    virtual QString infoString(const QPointF& pos) const = 0;

    qreal toSceneX(qreal v) const;
    qreal toSceneY(qreal v) const;
    qreal fromSceneX(qreal p) const;
    qreal fromSceneY(qreal p) const;

signals:
    void repaint_request();
    void statusString(const QString& text);

protected:
    void replot();

    QCustomPlot* m_qcp;

private:
    bool event(QEvent* event) override;

    void onTimeToReplot();

    PLOT_TYPE m_plot_type;
    PlotEventHelper* m_event_helper;
};

#endif // BORNAGAIN_GUI_VIEW_PLOTTER_SCIENTIFICPLOT_H
