#include <QRegExpValidator>
#include <QToolTip>
#include "dialogauthorization.h"
#include "ui_dialogauthorization.h"

DialogAuthorization::DialogAuthorization(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DialogAuthorization)
{
    ui->setupUi(this);

    ui->editLogin->setProperty("mandatoryField", true);
    ui->editPassword->setProperty("mandatoryField", true);

    ui->btnViewPassword->setObjectName("btnViewPassword");

    ui->editPassword->setEchoMode(QLineEdit::EchoMode::Password);

    ui->editLogin->setValidator(new QRegExpValidator(QRegExp("[A-Za-z\\d]+"), this));
}

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

QString DialogAuthorization::getLogin()
{
    return ui->editLogin->text();
}

void DialogAuthorization::setLogin(QString login)
{
    ui->editLogin->setText(login);
}

QString DialogAuthorization::getPassword()
{
    return ui->editPassword->text();
}

void DialogAuthorization::setPassword(QString password)
{
    ui->editPassword->setText(password);
}

void DialogAuthorization::on_btnLogIn_clicked()
{
    this->accept();
}

void DialogAuthorization::on_btnViewPassword_pressed()
{
    ui->editPassword->setEchoMode(QLineEdit::EchoMode::Normal);
}

void DialogAuthorization::on_btnViewPassword_released()
{
    ui->editPassword->setEchoMode(QLineEdit::EchoMode::Password);
}

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