Doc - More on Part 5

RevBy:    TrustMe
parent a8b496c9
......@@ -41,6 +41,11 @@ AddressBook::AddressBook(QWidget *parent)
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,
......@@ -55,6 +60,8 @@ AddressBook::AddressBook(QWidget *parent)
SLOT(editContact()));
connect(removeButton, SIGNAL(clicked()), this,
SLOT(removeContact()));
connect(findButton, SIGNAL(clicked()), this,
SLOT(findContact()));
setWindowTitle(tr("Simple Address Book"));
}
......@@ -235,3 +242,23 @@ void AddressBook::updateInterface(Mode mode)
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);
}
......@@ -6,6 +6,7 @@
#include <QtGui/QLineEdit>
#include <QtGui/QTextEdit>
#include <QtGui/QMessageBox>
#include "finddialog.h"
namespace Ui
......@@ -30,6 +31,7 @@ public slots:
void removeContact();
void next();
void previous();
void findContact();
private:
Ui::AddressBook *ui;
......@@ -42,6 +44,7 @@ private:
QPushButton *removeButton;
QPushButton *nextButton;
QPushButton *previousButton;
QPushButton *findButton;
QLineEdit *nameLine;
QTextEdit *addressText;
......@@ -49,6 +52,7 @@ private:
QString oldName;
QString oldAddress;
Mode currentMode;
FindDialog *dialog;
};
#endif // ADDRESSBOOK_H
......@@ -6,6 +6,17 @@ FindDialog::FindDialog(QWidget *parent) :
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()
......@@ -15,8 +26,20 @@ 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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment