Cleaned up
[emufront] / src / dialogs / namedialog.cpp
1 #include <QtGui>
2 #include "namedialog.h"
3
4 NameDialog::NameDialog(QWidget *parent, EmuFrontObject *efObj)
5         : EmuFrontDialog(parent), efObject(efObj)
6 {
7         nameLabel = new QLabel(tr("&Name: "));  
8         nameEdit = new QLineEdit;
9         nameLabel->setBuddy(nameEdit);
10     buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Abort, Qt::Horizontal);
11     connectSignals();
12         layout();
13         setWindowTitle(tr("Set names"));
14 }
15
16 NameDialog::~NameDialog()
17 {
18     delete efObject;
19
20     /* deleting parenteed QT-objects in heap is not needed here
21          * because when deleting a parent widget
22      * the child widgets will be also deleted
23          */
24 }
25
26 void NameDialog::connectSignals()
27 {
28     connect(nameEdit, SIGNAL(textChanged(const QString &)), this, SLOT(enableSaveButton(const QString &)));
29     connect(buttonBox, SIGNAL(accepted()), this, SLOT(acceptChanges()));
30     connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));
31 }
32
33 void NameDialog::layout()
34 {
35         QHBoxLayout *topLayout = new QHBoxLayout;
36         topLayout->addWidget(nameLabel);
37         topLayout->addWidget(nameEdit);
38
39         QHBoxLayout *bottomLayout = new QHBoxLayout;
40     bottomLayout->addWidget(buttonBox);
41
42         QVBoxLayout *mainLayout = new QVBoxLayout;
43         mainLayout->addLayout(topLayout);
44         mainLayout->addLayout(bottomLayout);
45         setLayout(mainLayout);
46 }
47
48 void NameDialog::acceptChanges()
49 {
50     if (nameEdit->text() == 0 || nameEdit->text().trimmed().isEmpty())
51     {
52         QMessageBox::warning(this, tr("Invalid input"), tr("Empty string is not accepted as name!"));
53                 return;
54     }
55
56         QString name = nameEdit->text().simplified();
57     setDataObject(name);
58     emit dataObjectUpdated();
59     close();
60 }
61
62 void NameDialog::enableSaveButton(const QString &text)
63 {
64     //saveButton->setEnabled(!text.isEmpty());
65 }
66
67