#ifndef QT_INPUT_GEOMETRY_CURVES_HPP
#define QT_INPUT_GEOMETRY_CURVES_HPP

#include <iostream>
#include <fstream>
#include <QWidget>
#include <QMouseEvent>
#include <QPainter>

#include "math/point.hpp"
#include "math/spline.hpp"

using namespace std;

static const size_t np = 10;

class QtInputGeometryCurves:public QWidget{
private:
  int margin;
  int radius;
  float min_d;
  size_t selected;
  Point point[2*np];
  Spline hsoil;
  Spline hbot;
  
  size_t findPoint(int x,int y);
  int get_x(float x,int w);
  int get_y(float y,int h);
  void moveSelected(float x,float y);
  void drawSpline(Spline& S,QPainter& painter);
public:
  QtInputGeometryCurves();
  ~QtInputGeometryCurves();
  void save(fstream& file);
  void load(fstream& file);
  Spline& getSsoil();
  Spline& getSbot();
protected:
  void initPoints();
  void paintEvent(QPaintEvent* event);
  void mousePressEvent(QMouseEvent* event) override;
  void mouseMoveEvent(QMouseEvent* event) override;
  void mouseReleaseEvent(QMouseEvent* event) override;
};

inline
QtInputGeometryCurves::~QtInputGeometryCurves(){
}

inline Spline&
QtInputGeometryCurves::getSsoil(){
  return hsoil;
}

inline Spline&
QtInputGeometryCurves::getSbot(){
  return hbot;
}

#endif
