2 #include "namedialog.h"
4 NameDialog::NameDialog(QWidget *parent, EmuFrontObject *efObj)
5 : EmuFrontDialog(parent), efObject(efObj)
7 nameLabel = new QLabel(tr("&Name: "));
8 nameEdit = new QLineEdit;
9 nameLabel->setBuddy(nameEdit);
10 saveButton = new QPushButton(tr("&Save"));
11 saveButton->setDefault(true);
12 saveButton->setEnabled(false);
13 closeButton = new QPushButton(tr("Close"));
16 setWindowTitle(tr("Set names"));
19 NameDialog::~NameDialog()
23 /* deleting objects in heap is not needed here
24 * because when deleting a parent widget
25 * the child widgets will be also deleted:
33 void NameDialog::connectSignals()
35 connect(nameEdit, SIGNAL(textChanged(const QString &)),
36 this, SLOT(enableSaveButton(const QString &)));
37 connect(saveButton, SIGNAL(clicked()), this, SLOT(saveButtonClicked()));
38 connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
41 void NameDialog::layout()
43 QHBoxLayout *topLayout = new QHBoxLayout;
44 topLayout->addWidget(nameLabel);
45 topLayout->addWidget(nameEdit);
47 QHBoxLayout *bottomLayout = new QHBoxLayout;
48 bottomLayout->addStretch();
49 bottomLayout->addWidget(saveButton);
50 bottomLayout->addWidget(closeButton);
52 QVBoxLayout *mainLayout = new QVBoxLayout;
53 mainLayout->addLayout(topLayout);
54 mainLayout->addLayout(bottomLayout);
55 setLayout(mainLayout);
58 void NameDialog::saveButtonClicked()
60 if (nameEdit->text() == 0 || nameEdit->text().trimmed().isEmpty())
63 QString name = nameEdit->text().simplified();
64 if (save(name)) emit dbUpdated();
65 else errorMessage->showMessage("Database update failed!");
66 /*if (edit) updateDb(name);
67 else insertDb(name);*/
70 void NameDialog::enableSaveButton(const QString &text)
72 saveButton->setEnabled(!text.isEmpty());