#include "dialog.h"

SaveDialog::SaveDialog(QWidget* p_parent): QDialog(p_parent)
{
    f_tblWidget = new QTableWidget(this);
    QGridLayout* grid_lay = new QGridLayout(this);

    QLabel* warningLbl = new QLabel("Сохранить измененный файл?");
    grid_lay->addWidget(warningLbl, 0, 0, 1, 2);

    grid_lay->addWidget(f_tblWidget, 1, 0, 1, 2);

    QPushButton* okBtn = new QPushButton("Сохранить все");
    connect( okBtn, SIGNAL(clicked()), SLOT(accept()));
    grid_lay->addWidget(okBtn, 2, 0);

    QPushButton* cancelBtn = new QPushButton("Не сохранять");
    connect( cancelBtn, SIGNAL(clicked()), SLOT(reject()));
    grid_lay->addWidget(cancelBtn, 2, 1);

    this->setLayout(grid_lay);

    resize(700, 300);

    f_tblWidget->setEditTriggers(QTableWidget::NoEditTriggers);

}

void SaveDialog::sltSetSizes(int p_rCt, int p_cCt) const
{
    f_tblWidget->setRowCount(p_rCt);
    f_tblWidget->setColumnCount(p_cCt);
    f_tblWidget->verticalHeader()->hide();
    f_tblWidget->setHorizontalHeaderLabels(
                QStringList(
                    {"File Name",
                     "File Directory"}
                    )
                );
    f_tblWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
}

void SaveDialog::sltSetContents(int p_row, int p_column, QTableWidgetItem *p_item)
{
    f_tblWidget->setItem(p_row, p_column, p_item);
}

void SaveDialog::closeEvent(QCloseEvent *event)
{
    done(-88);
    event->accept();
}
