// // Created by bbr on 18. 04. 2022.. // #include #include "name_dialog.h" display::NameDialog::NameDialog(std::string currentName, std::set &names): currentName(currentName) { usedNames.erase(currentName); auto *layout = new QVBoxLayout(this); layout->addWidget(new QLabel("Izmjeni ime", this)); edit = new QLineEdit(this); edit->insert(currentName.c_str()); connect(edit, &QLineEdit::textChanged, this, &NameDialog::onNameUpdate); layout->addWidget(edit); setWindowTitle("Izmjeni ime"); setLayout(layout); auto buttonLayout = new QHBoxLayout(this); auto okButton = new QPushButton("Ažuriraj"); auto cancelButton = new QPushButton("Odustani", this); connect(okButton, &QPushButton::clicked, this, &NameDialog::onNameChange); connect(cancelButton, &QPushButton::clicked, [this]() { reject(); }); buttonLayout->addWidget(okButton); buttonLayout->addWidget(cancelButton); layout->addLayout(buttonLayout); } void display::NameDialog::onNameUpdate(const QString &text) { if(usedNames.find(text.toStdString()) == usedNames.end()) { button->setDisabled(false); } else { button->setDisabled(true); } } void display::NameDialog::onNameChange() { currentName = edit->text().toStdString(); close(); } std::string display::NameDialog::getName() { return currentName; }