#include "anawidget.h"
#include "thermalwidget.h"
#include <QVBoxLayout>
extern double g_area;
extern double g_kmin;
extern double g_b_tang1;
extern double g_target_x1;
extern double g_target_y1;
extern double g_kmax;
extern double g_b_tang2;
extern double g_target_x2;
extern double g_target_y2;
extern double g_quality;
extern QuadraticFitResult g_result1;

AnaWidget::AnaWidget(QWidget *parent) : QWidget(parent)
{
    QVBoxLayout *layout = new QVBoxLayout(this);

    m_realbutton =new QPushButton(this);
    m_realbutton->setText("实时窗口");
    m_startbutton =new QPushButton(this);
    m_startbutton->setText("开始绘制");
    m_stopbutton =new QPushButton(this);
    m_stopbutton->setText("停止绘制");
    m_anabutton =new QPushButton(this);
    m_anabutton->setText("分析界面");

    m_choosebutton =new QPushButton(this);
    m_choosebutton->setText("选取曲线范围");
    m_cancelbutton =new QPushButton(this);
    m_cancelbutton->setText("取消选取范围");

    m_calcubutton =new QPushButton(this);
    m_calcubutton->setText("计算面积/切线/交点");
    m_calcubutton->setDisabled(true);
    m_label = new QLabel(this);
    m_label->setText("面积");
    m_lineEdit = new QLineEdit(this);
    m_lineEdit->setReadOnly(true);

    m_tlabel = new QLabel(this);
    m_tlabel->setText("实测热焓");
    m_tlineEdit = new QLineEdit(this);
    m_tlineEdit->setReadOnly(true);

    m_tang1_label = new QLabel(this);
    m_tang1_label->setText("左切线方程");
    m_tang1_lineEdit = new QLineEdit(this);
    m_tang1_lineEdit->setReadOnly(true);
    m_target1_label = new QLabel(this);
    m_target1_label->setText("左交点坐标");
    m_target1_lineEdit = new QLineEdit(this);
    m_target1_lineEdit->setReadOnly(true);

    m_tang2_label = new QLabel(this);
    m_tang2_label->setText("右切线方程");
    m_tang2_lineEdit = new QLineEdit(this);
    m_tang2_lineEdit->setReadOnly(true);
    m_target2_label = new QLabel(this);
    m_target2_label->setText("右交点坐标");
    m_target2_lineEdit = new QLineEdit(this);
    m_target2_lineEdit->setReadOnly(true);

    layout->addWidget(m_realbutton);
    layout->addWidget(m_startbutton);
    layout->addWidget(m_stopbutton);
    layout->addWidget(m_anabutton);
    layout->addWidget(m_choosebutton);
    layout->addWidget(m_cancelbutton);
    layout->addWidget(m_calcubutton);
    layout->addWidget(m_label);
    layout->addWidget(m_lineEdit);
    layout->addWidget(m_tlabel);
    layout->addWidget(m_tlineEdit);
    layout->addWidget(m_tang1_label);
    layout->addWidget(m_tang1_lineEdit);
    layout->addWidget(m_target1_label);
    layout->addWidget(m_target1_lineEdit);
    layout->addWidget(m_tang2_label);
    layout->addWidget(m_tang2_lineEdit);
    layout->addWidget(m_target2_label);
    layout->addWidget(m_target2_lineEdit);
    layout->setAlignment(Qt::AlignLeft|Qt::AlignTop);
    setLayout(layout);

    QPalette pal(this->palette());
    //设置背景
    pal.setColor(QPalette::Window, QColor(0, 0, 100, 100));
    this->setAutoFillBackground(true);
    this->setPalette(pal);
}
AnaWidget::~AnaWidget()
{

}

void AnaWidget::show_area_edit()
{
    m_lineEdit->setText(QString::number(g_area));
    double thermal = g_area/g_quality*(g_result1.a*g_target_x1*g_target_x1+g_result1.b*g_target_x1+g_result1.c);
    m_tlineEdit->setText(QString::number(thermal));
}

void AnaWidget::show_tang_edit()
{
    m_tang1_lineEdit->setText(QString("y=%1 * x + %2").arg(g_kmin).arg(g_b_tang1));
    m_target1_lineEdit->setText(QString("x=%1, y=%2").arg(g_target_x1).arg(g_target_y1));
    m_tang2_lineEdit->setText(QString("y=%1 * x  %2").arg(g_kmax).arg(g_b_tang2));
    m_target2_lineEdit->setText(QString("x=%1, y=%2").arg(g_target_x2).arg(g_target_y2));
}

void AnaWidget::enable_calcu_button()
{
    m_calcubutton->setDisabled(false);
}




