
#include <iostream>
#include <vector>
#include <CGAL/Cartesian.h>
#include <CGAL/Point_2.h>
#include <CGAL/Delaunay_triangulation_2.h>
#include <CGAL/IO/Qt_widget_Delaunay_triangulation_2.h>
#include <CGAL/IO/Qt_widget.h>
#include <CGAL/IO/Qt_widget_layer.h>
#include <qapplication.h>


typedef CGAL::Cartesian<double>		    K;
typedef CGAL::Point_2<K> 		    Point;


typedef CGAL::Delaunay_triangulation_2<K>            Delaunay;




class My_layer : public CGAL::Qt_widget_layer{
  void draw(){
    ;
  }
};

class My_window : public CGAL::Qt_widget {
public:
  My_window(int x, int y)
  {
    resize(x,y);
    attach(&layer);
  };
private:
  //this method is called when the user presses the mouse
  void mousePressEvent(QMouseEvent *e)
  {
    Qt_widget::mousePressEvent(e);

    /////////////////////////////////////////////////////////////
    //  C'EST ICI QUE CA SE PASSE QUAND ON CLIQUE !
    //
      exit(1);
    /////////////////////////////////////////////////////////////

    redraw();
  }
  My_layer layer;
};

int main( int argc, char **argv )
{
    QApplication app( argc, argv );
    My_window *W = new My_window(400,400);
    app.setMainWidget(W);
    W->show();
    W->set_window(-1, 1, -1, 1);

    int Nb_points;

    std::cout<<" Nombre de points ? "<<std::endl;
    std::cin>>Nb_points;

    std::vector<Point> points(Nb_points);
    
    for( int i = 0 ; i<Nb_points;++i) {
      double x= (Nb_points-i) / (double)Nb_points;
      points[i] = Point(x,x*x);
    }

    Delaunay dt1;
    for( int i = 0 ; i<Nb_points;++i) {
      dt1.insert( points[i] );
    }
    *W << CGAL::GREEN<<dt1;
    std::cout<<Nb_points<<" points "<<std::endl;


    return app.exec();
}
