MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // serialport
    m_serial = new QSerialPort(this);

    connect(ui->eStop, SIGNAL(clicked()), this, SLOT(eStop_clicked()));//
    connect(ui->eStepPwr, SIGNAL(clicked()), this, SLOT(eStepPwr_clicked()));//
  //  connect(ui->spinBoxExtTarget, SIGNAL(valueChanged (int)), this, SLOT(extSpinbox_changed()));
    connect(ui->ExtUpX10, SIGNAL(clicked()), this, SLOT(extTarget_Up_10()));//
    connect(ui->ExtUpX1, SIGNAL(clicked()), this, SLOT(extTarget_Up_1()));//
    connect(ui->ExtDnX1, SIGNAL(clicked()), this, SLOT(extTarget_Dn_1()));//
    connect(ui->ExtDnX10, SIGNAL(clicked()), this, SLOT(extTarget_Dn_10()));//

    connect(ui->extEnable, SIGNAL(clicked()), this, SLOT(extEnable_clicked()));
//    connect(ui->spinBoxBedTarget, SIGNAL(valueChanged (int)), this, SLOT(bedSpinbox_changed()));
    connect(ui->BedUpX10, SIGNAL(clicked()), this, SLOT(bedTarget_Up_10()));//
    connect(ui->BedUpX1, SIGNAL(clicked()), this, SLOT(bedTarget_Up_1()));//
    connect(ui->BedDnX1, SIGNAL(clicked()), this, SLOT(bedTarget_Dn_1()));//
    connect(ui->BedDnX10, SIGNAL(clicked()), this, SLOT(bedTarget_Dn_10()));//

    connect(ui->bedEnable, SIGNAL(clicked()), this, SLOT(bedEnable_clicked()));
    connect(ui->getCode, SIGNAL(clicked()), this, SLOT(getCode_clicked()));
    connect(ui->exitButton, SIGNAL(clicked()), this, SLOT(exitButton_clicked()));
    connect(ui->searchButton, SIGNAL(clicked()), this, SLOT(searchButton_clicked()));
    connect(ui->comboBoxDevices, SIGNAL(activated(int)), this, SLOT(comboBoxDevices_clicked()));
    connect(ui->connectButton, SIGNAL(clicked()), this, SLOT(connectButton_clicked()));//
    connect(ui->comboBoxFiles, SIGNAL(activated(int)), this, SLOT(comboBoxFiles_clicked()));
    connect(ui->waittempsButton, SIGNAL(clicked()), this, SLOT(waittempsButton_clicked()));

    m_chartScene.setSceneRect(0, 0, 600, 280);
    m_chartScene.setBackgroundBrush(Qt::white);

    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(periodic_update()));

    ui->comboBoxDevices->addItem("Select a Device to connect to","");
    ui->comboBoxFiles->addItem("No \"g\" code file selected","");
    ui->eStop->setStyleSheet("background-color: #00C000; border-radius: 5px; color : #ffffff;");

    timer->start(1000);
}
void MainWindow::prepareGUI()
{

    this->ui->mapLayout->addWidget(&this->map, 0, 0);
    this->map.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    this->textEditLog.append("Application log\nApplication started\n");
    this->textEditLog.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);

    this->ui->controlsLayout->addWidget(&this->browser, 0, 0);
    this->ui->controlsLayout->addWidget(&this->list, 1, 0);
    this->ui->controlsLayout->addWidget(&this->textEditLog, 2, 0);

    this->map.setMapThemeId("earth/openstreetmap/openstreetmap.dgml");
    connect(&this->map, SIGNAL(placeSelected(double,double,QString)), this, SLOT(placeSelected(double,double,QString)));
    connect(&this->browser, SIGNAL(search_button_clicked(QString)), this, SLOT(searchButton_clicked(QString)));
    connect(&this->browser, SIGNAL(add_button_clicked()), this, SLOT(addPlace()));
    connect(&this->browser, SIGNAL(suggestion_clicked(QListWidgetItem*)), this, SLOT(suggestion_clicked(QListWidgetItem*)));
    connect(&this->list, SIGNAL(btn_delete_click(QListWidgetItem*)), this, SLOT(deletePlace(QListWidgetItem*)));
    connect(&this->list, SIGNAL(btn_calculate_click(int)), this, SLOT(calculate(int)));
    connect(&this->list, SIGNAL(item_clicked(QListWidgetItem*)), this, SLOT(place_clicked(QListWidgetItem*)));
}