-
Notifications
You must be signed in to change notification settings - Fork 0
/
renamedialog.cpp
executable file
·42 lines (32 loc) · 1.2 KB
/
renamedialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "renamedialog.h"
#include <QDialogButtonBox>
#include <QLabel>
#include <QLineEdit>
#include <QVBoxLayout>
RenameDialog::RenameDialog(QWidget *parent, Qt::WindowFlags flag)
: QDialog(parent, flag) {
setFixedHeight(120);
auto *layout = new QVBoxLayout(this);
layout->setSpacing(15);
layout->setContentsMargins(0, 0, 0, 0);
auto *label = new QLabel(tr("Name:"), this);
m_editor = new QLineEdit(this);
auto *button =
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
button->setCenterButtons(true);
connect(button, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(button, &QDialogButtonBox::rejected, this, &QDialog::reject);
layout->addWidget(label);
layout->addWidget(m_editor);
layout->addWidget(button);
setLayout(layout);
}
RenameDialog::~RenameDialog() = default;
QString RenameDialog::name() const {
return m_editor->text();
}
QString RenameDialog::getName(const QString &title, QWidget *parent, Qt::WindowFlags flag) {
RenameDialog dialog(parent, flag);
dialog.setWindowTitle(title);
return QDialog::Rejected == dialog.exec() ? QString{} : dialog.name();
}