/*
____________________________________________________
|                                                  |
|          author => Martin Robinson               |
|                                                  |
|          you are authorised to use               |
|          this code in the way you                |
|          like, commercial, personal,             |
|          opensource or anything else             |
|          you could imagine. But you              |
|          are not authorised to own               |
|          copyright on this work                  |
|__________________________________________________|
____________________________________________________
|                                                  |
|           graphical interface                    |
|           language C++                           |
|           Library Qt4.4                          |
|           turtle graphic like                    |
|__________________________________________________|
*/
#include "gui.hpp"
#include "Lturtle.hpp"

  gui::gui(QWidget *parent) : QWidget(parent)
  {
    startTimer(1000);
    setMouseTracking(true);
    
    slider = new QSlider(Qt::Horizontal , this);
    slider->setGeometry(400, 50, 130, 30);
    label = new QLabel("0", this);
    label->setGeometry(400, 25, 20, 30);
    connect(slider, SIGNAL(valueChanged(int)), label, SLOT(setNum(int)));
    
    Ledit = new QLineEdit(this);
    Ledit->setGeometry(400,75,130,30);
    
    cb = new QCheckBox("wind", this);
    cb->setCheckState(Qt::Unchecked);
    cb->move(400, 100);
    
    apply = new QPushButton("apply", this);
    apply->setGeometry(400, 125, 75, 30);
    connect(apply, SIGNAL(clicked()), qApp, SLOT(applying()));
    
  }

  void gui::timerEvent(QTimerEvent *event)
  {
    QTime qtime = QTime::currentTime();
    QString stime = qtime.toString(Qt::LocalDate);
    //setWindowTitle(stime);
  }

  void gui::paintEvent(QPaintEvent *event)
  {

    QPen pen(Qt::black, 2, Qt::SolidLine);

    QPainter painter(this);
    painter.setPen(pen);
    //the real thing
    if (Lsystem != 0)
    {
 
      DrawLTurtle(&Lsystem,&queueline);
      while (!queueline.isEmpty())
      {
        painter.drawLine(queueline.dequeue());
      }
    }
    else
    {
      painter.drawLine(1,1,398,398);
      painter.drawLine(1,398,398,1);
    }
  } 

  void gui::mouseMoveEvent ( QMouseEvent * event )
  {
    int x = event->x();
    int y = event->y();

    QString text = QString::number(x) + "," + QString::number(y);

    setWindowTitle(text);
  }
  
  void gui::mousePressEvent ( QMouseEvent * event )
  {
    int x = event->pos().x();
    int y = event->pos().y();

    QString text = QString::number(x) + "," + QString::number(y) + "button";

    setWindowTitle(text);
  }
  
  void gui::applying()
  {
    setWindowTitle(QString("applied"));
  }
 