#include "axissettingform.h"
#include "ui_axissettingform.h"
#include "global.h"

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

AxisSettingForm::~AxisSettingForm()
{
    delete ui;
}

void AxisSettingForm::slotGetAxisInfoWithData(const QVector<CentralWidget::AxisInfo> vtr)
{
    ui->lineEditXMin->setText(Global::converDoubleToStr(vtr.first().lower));
    ui->lineEditXMax->setText(Global::converDoubleToStr(vtr.first().upper));

    ui->lineEditYLeftMin->setText(Global::converDoubleToStr(vtr.at(1).lower));
    ui->lineEditYLeftMax->setText(Global::converDoubleToStr(vtr.at(1).upper));

    //Axis Y right.
    ui->lineEditYRightMin->setEnabled(vtr.last().visiable);
    ui->lineEditYRightMax->setEnabled(vtr.last().visiable);

    if(vtr.last().visiable){
        ui->lineEditYRightMin->setText(Global::converDoubleToStr(vtr.last().lower));
        ui->lineEditYRightMax->setText(Global::converDoubleToStr(vtr.last().upper));
    }else{
        ui->lineEditYRightMin->setText(0);
        ui->lineEditYRightMax->setText(0);
    }
}

void AxisSettingForm::showEvent(QShowEvent *event)
{
    emit sigGetAxisInfo();
    QWidget::showEvent(event);
}

void AxisSettingForm::on_pushButtonConfirm_clicked()
{
    QVector<double> vtr;

#if 0
    double xMin = ui->lineEditXMin->text().toDouble();
    double xMax = ui->lineEditXMin->text().toDouble();
    double yLeftMin = ui->lineEditYLeftMin->text().toDouble();
    double yLeftMax = ui->lineEditYLeftMax->text().toDouble();

    double yRightMin = ui->lineEditYRightMin->text().toDouble();
    double yRightMax = ui->lineEditYRightMax->text().toDouble();
#endif

    vtr.push_back(ui->lineEditXMin->text().toDouble());
    vtr.push_back(ui->lineEditXMax->text().toDouble());

    vtr.push_back(ui->lineEditYLeftMin->text().toDouble());
    vtr.push_back(ui->lineEditYLeftMax->text().toDouble());

    vtr.push_back(ui->lineEditYRightMin->text().toDouble());
    vtr.push_back(ui->lineEditYRightMax->text().toDouble());

    emit sigSetAxisSettings(vtr);
}

void AxisSettingForm::on_pushButtonCancel_clicked()
{
    hide();
}
