2022-06-13 22:53:46 +00:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include "generic_dialog.h"
|
|
|
|
|
2022-06-19 18:10:44 +00:00
|
|
|
#include "message_source.h"
|
|
|
|
|
|
|
|
display::GenericDialog::GenericDialog(std::string title, std::optional<std::string> action, std::string cancel) {
|
2022-06-13 22:53:46 +00:00
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
2022-06-19 18:10:44 +00:00
|
|
|
setWindowTitle(QMESSAGE(title));
|
2022-06-13 22:53:46 +00:00
|
|
|
|
|
|
|
setLayout(new QVBoxLayout());
|
|
|
|
content = new QWidget(this);
|
|
|
|
layout()->addWidget(content);
|
|
|
|
|
|
|
|
auto actionWidget = new QWidget(this);
|
|
|
|
auto actionBar = new QHBoxLayout(actionWidget);
|
|
|
|
layout()->addWidget(actionWidget);
|
|
|
|
|
|
|
|
// if action isn't defined only close button is offered
|
2022-06-19 18:10:44 +00:00
|
|
|
if(action.has_value()) {
|
|
|
|
okButton = new QPushButton(QMESSAGE(*action), this);
|
|
|
|
connect(okButton, &QPushButton::clicked, this, [this](){
|
|
|
|
if(this->onUpdate()) {
|
|
|
|
this->accept();
|
|
|
|
}
|
|
|
|
});
|
2022-06-13 22:53:46 +00:00
|
|
|
actionBar->addWidget(okButton);
|
|
|
|
}
|
2022-06-19 18:10:44 +00:00
|
|
|
cancelButton = new QPushButton(QMESSAGE(cancel), this);
|
2022-06-13 22:53:46 +00:00
|
|
|
connect(cancelButton, &QPushButton::clicked, [this]() { reject(); });
|
|
|
|
actionBar->addWidget(cancelButton);
|
|
|
|
}
|
|
|
|
|
|
|
|
void display::GenericDialog::setOkButtonDisabled(bool disabled) {
|
|
|
|
okButton->setDisabled(disabled);
|
|
|
|
}
|