removeButton = ui->removeButton;
removeButton->setEnabled(false);
+ findButton = new QPushButton;
+ findButton = ui->findButton;
+
+ dialog = new FindDialog;
+
connect(addButton, SIGNAL(clicked()), this,
SLOT(addContact()));
connect(submitButton, SIGNAL(clicked()), this,
SLOT(editContact()));
connect(removeButton, SIGNAL(clicked()), this,
SLOT(removeContact()));
+ connect(findButton, SIGNAL(clicked()), this,
+ SLOT(findContact()));
setWindowTitle(tr("Simple Address Book"));
}
break;
}
}
+
+void AddressBook::findContact()
+{
+ dialog->show();
+
+ if (dialog->exec() == QDialog::Accepted) {
+ QString contactName = dialog->getFindText();
+
+ if (contacts.contains(contactName)) {
+ nameLine->setText(contactName);
+ addressText->setText(contacts.value(contactName));
+ } else {
+ QMessageBox::information(this, tr("Contact Not Found"),
+ tr("Sorry, \"%1\" is not in your address book.").arg(contactName));
+ return;
+ }
+ }
+
+ updateInterface(NavigationMode);
+}
#include <QtGui/QLineEdit>
#include <QtGui/QTextEdit>
#include <QtGui/QMessageBox>
+#include "finddialog.h"
namespace Ui
void removeContact();
void next();
void previous();
+ void findContact();
private:
Ui::AddressBook *ui;
QPushButton *removeButton;
QPushButton *nextButton;
QPushButton *previousButton;
+ QPushButton *findButton;
QLineEdit *nameLine;
QTextEdit *addressText;
QString oldName;
QString oldAddress;
Mode currentMode;
+ FindDialog *dialog;
};
#endif // ADDRESSBOOK_H
m_ui(new Ui::FindDialog)
{
m_ui->setupUi(this);
+ lineEdit = new QLineEdit;
+ lineEdit = m_ui->lineEdit;
+
+ findButton = new QPushButton;
+ findButton = m_ui->findButton;
+
+ findText = "";
+
+ connect(findButton, SIGNAL(clicked()), this, SLOT(findClicked()));
+
+ setWindowTItle(tr("Find a Contact"));
}
FindDialog::~FindDialog()
void FindDialog::findClicked()
{
+ QString text = lineEdit->text();
+
+ if (text.isEmpty()) {
+ QMessageBox::information(this, tr("Empty Field"),
+ tr("Please enter a name."));
+ return;
+ } else {
+ findText = text;
+ lineEdit->clear();
+ hide();
+ }
}
QString FindDialog::getFindText()
{
+ return findText;
}