//
// Created by Krad on 2021/11/10.
//

#include "GUIFormBaseDialog.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPushButton>
GUIFormBaseDialog::GUIFormBaseDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f) {
	this->setObjectName("formDialog");
	this->setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
	//    this->setFixedSize(500,600);
	this->setFixedWidth(500);
	this->formWidget = new QWidget(this);
	this->formWidget->setObjectName("formWidget");

	QVBoxLayout* vLayout = new QVBoxLayout(this);
	//    vLayout->setContentsMargins(680,100,680,100);
	vLayout->addWidget(formWidget);

	QWidget* btnWidget = new QWidget(this);
	vLayout->addWidget(btnWidget);
	QHBoxLayout* hLayout = new QHBoxLayout(btnWidget);
	btnOk = new QPushButton(btnWidget);
	btnOk->setText(tr("OK"));
	btnCancel = new QPushButton(btnWidget);
	btnCancel->setText(tr("Cancel"));
	hLayout->addWidget(btnOk);
	hLayout->addWidget(btnCancel);
	btnOk->setObjectName("btnOK");
	connect(btnOk, &QPushButton::clicked, [t = this]() {
		if (t->updateReferenceData())
			t->accept();
		});
	connect(btnCancel, &QPushButton::clicked, [t = this]() {
		t->reject();
		});
}

GUIFormBaseDialog::~GUIFormBaseDialog() {

}

void GUIFormBaseDialog::setButtonMode(DialogButtonMode mode) {
	switch (mode) {
	case OkOnly:
	{
		btnOk->setVisible(true);
		btnCancel->setVisible(false);
		return;
	}
	case OkAndCancel:
	{
		btnOk->setVisible(true);
		btnCancel->setVisible(true);
		return;
	}
	case None:
	default:
	{
		btnOk->setVisible(false);
		btnCancel->setVisible(false);
	}
	}
}
