2 // Copyright 2010 Mikko Keinänen
4 // This file is part of EmuFront.
7 // EmuFront is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2 as published by
9 // the Free Software Foundation and appearing in the file gpl.txt included in the
10 // packaging of this file.
12 // EmuFront is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with EmuFront. If not, see <http://www.gnu.org/licenses/>.
21 #include "namedialog.h"
23 NameDialog::NameDialog(QWidget *parent, EmuFrontObject *efObj)
24 : DataObjectEditDialog(parent, efObj)
26 nameLabel = new QLabel(tr("&Name: "));
27 nameEdit = new QLineEdit;
28 nameLabel->setBuddy(nameEdit);
32 setWindowTitle(tr("Set names"));
35 NameDialog::~NameDialog()
37 // should be deleted in implementing classes
40 /* no need to delete parented QT-objects in heap here
41 * because when deleting a parent widget
42 * the child widgets will be also deleted
46 void NameDialog::connectSignals()
48 DataObjectEditDialog::connectSignals();
49 connect(nameEdit, SIGNAL(textChanged(const QString &)), this, SLOT(enableSaveButton(const QString &)));
52 void NameDialog::layout()
54 QHBoxLayout *topLayout = new QHBoxLayout;
55 topLayout->addWidget(nameLabel);
56 topLayout->addWidget(nameEdit);
58 QHBoxLayout *bottomLayout = new QHBoxLayout;
59 bottomLayout->addWidget(buttonBox);
61 QVBoxLayout *mainLayout = new QVBoxLayout;
62 mainLayout->addLayout(topLayout);
63 mainLayout->addLayout(bottomLayout);
64 setLayout(mainLayout);
67 void NameDialog::acceptChanges()
69 if (nameEdit->text() == 0 || nameEdit->text().trimmed().isEmpty())
71 QMessageBox::warning(this, tr("Invalid input"), tr("Empty string is not accepted as name!"));
75 QString name = nameEdit->text().simplified();
76 qDebug() << "We have a name " << name << ".";
77 if (name != efObject->getName()) {
79 emit dataObjectUpdated();
81 qDebug() << "Signal emitted.";
82 efObject = 0; // TODO we should also set efObject to null when user clicks abort
86 void NameDialog::enableSaveButton(const QString &/*text*/)
88 //saveButton->setEnabled(!text.isEmpty());
91 void NameDialog::setDataObject(EmuFrontObject *ob)
94 // delete efObject; -> we should not delete the previously referenced data object here, it
95 // may be still used in the parent widget
96 // the parent widget will take care of destruction
97 // we'll just refresh the name dialog pointer to a new object
101 void NameDialog::clear()