#include "dialognewversion.h"
#include "ui_dialognewversion.h"

DialogNewVersion::DialogNewVersion(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DialogNewVersion),
    versionSelectWidget(nullptr),
    validator(nullptr)
{
    ui->setupUi(this);

    validator = new QRegExpValidator(QRegExp("^[A-Za-z0-9]{20}$"));
    ui->lineEdit->setValidator(validator);

    setMinimumSize(200, 100);
    setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
    setWindowTitle(tr("New version"));
}

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

void DialogNewVersion::initialize(VersionSelectWidget *versionSelectWidget, QString prevName)
{
    this->versionSelectWidget = versionSelectWidget;
    ui->prevVerValue->setText(prevName);    
}

void DialogNewVersion::on_createButton_clicked()
{
    if(ui->lineEdit->text() != "")
    {
        versionSelectWidget->sendCopyEmit(ui->lineEdit->text());
        close();
    }
}

void DialogNewVersion::on_cancelButton_clicked()
{
    close();
}

void DialogNewVersion::on_lineEdit_inputRejected()
{
    QToolTip::showText(QCursor::pos(),tr("Only Latin letters and numbers"));
}
