2 #include "namedialog.h"
4 NameDialog::NameDialog(QWidget *parent, EmuFrontObject *efObj)
5 : EmuFrontDialog(parent), efObject(efObj)
7 // actually we need to create here a (deep) copy of the original object
8 // if the user clicks cancel the original remains unchanged
9 // if the user clicks or we set the pointer to modified object OR we update the original object:
10 // - the copy object could be a stack object
11 nameLabel = new QLabel(tr("&Name: "));
12 nameEdit = new QLineEdit;
13 nameLabel->setBuddy(nameEdit);
14 buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Abort, Qt::Horizontal);
15 /*saveButton = new QPushButton(tr("&Save"));
16 saveButton->setDefault(true);
17 saveButton->setEnabled(false);
18 closeButton = new QPushButton(tr("Close"));*/
21 setWindowTitle(tr("Set names"));
24 NameDialog::~NameDialog()
28 /* deleting objects in heap is not needed here
29 * because when deleting a parent widget
30 * the child widgets will be also deleted:
38 void NameDialog::connectSignals()
40 connect(nameEdit, SIGNAL(textChanged(const QString &)), this, SLOT(enableSaveButton(const QString &)));
41 connect(buttonBox, SIGNAL(accepted()), this, SLOT(acceptChanges()));
42 connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));
44 /*connect(saveButton, SIGNAL(clicked()), this, SLOT(saveButtonClicked()));
45 connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));*/
48 void NameDialog::layout()
50 QHBoxLayout *topLayout = new QHBoxLayout;
51 topLayout->addWidget(nameLabel);
52 topLayout->addWidget(nameEdit);
54 QHBoxLayout *bottomLayout = new QHBoxLayout;
55 bottomLayout->addWidget(buttonBox);
56 /*bottomLayout->addStretch();
57 bottomLayout->addWidget(saveButton);
58 bottomLayout->addWidget(closeButton);*/
60 QVBoxLayout *mainLayout = new QVBoxLayout;
61 mainLayout->addLayout(topLayout);
62 mainLayout->addLayout(bottomLayout);
63 setLayout(mainLayout);
66 void NameDialog::saveButtonClicked()
68 if (nameEdit->text() == 0 || nameEdit->text().trimmed().isEmpty())
71 QString name = nameEdit->text().simplified();
76 efObject->setName(name);
77 efObject->setFilename("");
82 void NameDialog::enableSaveButton(const QString &text)
84 //saveButton->setEnabled(!text.isEmpty());
87 void NameDialog::close(bool save)
91 // restore original instance