#include <QFormLayout>
#include <QVBoxLayout>
#include <QHBoxLayout>

#include "analysissettingform.h"

AnalysisSettingForm::AnalysisSettingForm(QWidget *parent) :
    QWidget(parent)
  ,_leftBorderSpinBox(new QDoubleSpinBox(this))
  ,_rightBorderSpinBox(new QDoubleSpinBox(this))
  ,_thresholdLineEdit(new QLineEdit(this))
  ,_applyButton(new QPushButton("应用",this))
  ,_undoButton(new QPushButton("撤销",this))
  ,_confirmButton(new QPushButton("确定",this))
  ,_cancelButton(new QPushButton("取消",this))
{
    QVBoxLayout *layout = new QVBoxLayout(this);
    // 设置间距和边距
    //        layout->setSpacing(0); // 设置子布局之间的间距
    //        layout->setContentsMargins(0, 0, 0, 0); // 设置布局的边距

    QFormLayout *editLayout = new QFormLayout();
    editLayout->addRow("左边界:",_leftBorderSpinBox);
    editLayout->addRow("右边界:",_rightBorderSpinBox);
    editLayout->addRow("阈值:",_thresholdLineEdit);

    QGridLayout *buttonLayout = new QGridLayout();

    buttonLayout->addWidget(_applyButton, 0, 0); // 第一行第一列
    buttonLayout->addWidget(_undoButton, 0, 1); // 第一行第二列
    buttonLayout->addWidget(_confirmButton, 1, 0); // 第二行第一列
    buttonLayout->addWidget(_cancelButton, 1, 1); // 第二行第二列
    //    buttonLayout->setSpacing(0);

    // 创建一个空白行
    QSpacerItem *spacer =
            new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding);

    // 将 editLayout 和 buttonLayout 添加到主布局，并在它们之间添加空白行
    layout->addLayout(editLayout);
    layout->addSpacerItem(spacer);
    layout->addLayout(buttonLayout);
//    layout->addLayout(editLayout);
    //    layout->setSpacing(1);
//    layout->addLayout(buttonLayout);
    layout->addStretch(1);
    //
#if 0
    connect(_applyButton,&QPushButton::clicked,
            this,&AnalysisSettingForm::slotApply);
    connect(_confirmButton,&QPushButton::clicked,
            this,&AnalysisSettingForm::slotConfirm);
    connect(_undoButton,&QPushButton::clicked,
            this,&AnalysisSettingForm::slotUndo);
    connect(_cancelButton,&QPushButton::clicked,
            this,&AnalysisSettingForm::slotCancel);
#endif
    connect(_applyButton,&QPushButton::clicked,
            this,&AnalysisSettingForm::sigApply);
    connect(_confirmButton,&QPushButton::clicked,
            this,&AnalysisSettingForm::sigConfirm);
    connect(_undoButton,&QPushButton::clicked,
            this,&AnalysisSettingForm::sigUndo);
    connect(_cancelButton,&QPushButton::clicked,
            this,&AnalysisSettingForm::sigCancel);
    //
    _leftBorderSpinBox->setRange(0.0, 10000.0); // 设置范围
    _rightBorderSpinBox->setRange(0.0, 10000.0); // 设置范围
}

AnalysisSettingForm::~AnalysisSettingForm()
{

}

void AnalysisSettingForm::slotRecvLineXCoord(const int index, const double point)
{
    if(1 == index){
        _leftBorderSpinBox->setValue(point);
    }else{
        _rightBorderSpinBox->setValue(point);
    }
}

#if 0
void AnalysisSettingForm::slotApply()
{
    emit sigApply();
}

void AnalysisSettingForm::slotConfirm()
{
    emit sigConfirm();
    hide();
}

void AnalysisSettingForm::slotUndo()
{
    emit sigUndo();
}

void AnalysisSettingForm::slotCancel()
{
    emit sigCancel();
    hide();
}
#endif
