Name dialog accepts now input.
[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     /*saveButton = new QPushButton(tr("&Save"));
12         saveButton->setDefault(true);
13         saveButton->setEnabled(false);
14     closeButton = new QPushButton(tr("Close"));*/
15     connectSignals();
16         layout();
17         setWindowTitle(tr("Set names"));
18 }
19
20 NameDialog::~NameDialog()
21 {
22     delete efObject;
23
24         /* deleting objects in heap is not needed here
25          * because when deleting a parent widget
26          * the child widgets will be also deleted:
27          * delete nameLabel;
28          * delete nameEdit;
29          * delete saveButton;
30          * delete closeButton;
31          */
32 }
33
34 void NameDialog::connectSignals()
35 {
36     connect(nameEdit, SIGNAL(textChanged(const QString &)), this, SLOT(enableSaveButton(const QString &)));
37     connect(buttonBox, SIGNAL(accepted()), this, SLOT(acceptChanges()));
38     connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));
39
40     /*connect(saveButton, SIGNAL(clicked()), this, SLOT(saveButtonClicked()));
41     connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));*/
42 }
43
44 void NameDialog::layout()
45 {
46         QHBoxLayout *topLayout = new QHBoxLayout;
47         topLayout->addWidget(nameLabel);
48         topLayout->addWidget(nameEdit);
49
50         QHBoxLayout *bottomLayout = new QHBoxLayout;
51     bottomLayout->addWidget(buttonBox);
52     /*bottomLayout->addStretch();
53         bottomLayout->addWidget(saveButton);
54     bottomLayout->addWidget(closeButton);*/
55
56         QVBoxLayout *mainLayout = new QVBoxLayout;
57         mainLayout->addLayout(topLayout);
58         mainLayout->addLayout(bottomLayout);
59         setLayout(mainLayout);
60 }
61
62 void NameDialog::acceptChanges()
63 {
64     if (nameEdit->text() == 0 || nameEdit->text().trimmed().isEmpty())
65     {
66         QMessageBox::warning(this, tr("Invalid input"), tr("Empty string is not accepted as name!"));
67                 return;
68     }
69
70         QString name = nameEdit->text().simplified();
71     setDataObject(name);
72     emit dataObjectUpdated();
73     close();
74 }
75
76 void NameDialog::enableSaveButton(const QString &text)
77 {
78     //saveButton->setEnabled(!text.isEmpty());
79 }
80
81