#include "dialogform.h"
#include "ui_dialogform.h"

DialogForm::DialogForm(QWidget *parent) :
    Scene(parent),
    ui(new Ui::DialogForm)
{
    ok = false;
    setWindowModality(Qt::ApplicationModal);
    ui->setupUi(this);
    raise();
}

void DialogForm::exec()
{
    raise();
    QEventLoop loop;
    connect(ui->ok_button, &QPushButton::clicked, &loop, &QEventLoop::quit);
    connect(ui->cancel_button, &QPushButton::clicked, &loop, &QEventLoop::quit);
    loop.exec();
}

bool DialogForm::isOk()
{
    return ok;
}

void DialogForm::setTitle(QString title)
{
    ui->title->setText(title);
}

void DialogForm::setText(QString text)
{
    ui->text->setText(text);
}

void DialogForm::setShowCancel(bool show)
{
    show ? ui->cancel_button->show() : ui->cancel_button->hide();
}

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

void DialogForm::on_cancel_button_clicked()
{
    ok = false;
}

void DialogForm::on_ok_button_clicked()
{
    ok = true;
}
