From 393adf7acd8bfacaccb8b9543ce4d2b442608124 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Wed, 6 Jul 2011 21:52:23 +0200 Subject: Address book: Disable "copy to clipboard" and "Delete" buttons when nothing selected --- src/qt/addressbookdialog.cpp | 47 ++++++++++++++++++++++++++++++-------------- src/qt/addressbookdialog.h | 3 ++- 2 files changed, 34 insertions(+), 16 deletions(-) (limited to 'src/qt') diff --git a/src/qt/addressbookdialog.cpp b/src/qt/addressbookdialog.cpp index 220679c9e6..6d53ee8657 100644 --- a/src/qt/addressbookdialog.cpp +++ b/src/qt/addressbookdialog.cpp @@ -23,6 +23,8 @@ AddressBookDialog::AddressBookDialog(Mode mode, QWidget *parent) : ui->sendTableView->setFocus(); break; } + + connect(ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(selectionChanged())); } AddressBookDialog::~AddressBookDialog() @@ -64,6 +66,11 @@ void AddressBookDialog::setModel(AddressTableModel *model) ui->sendTableView->horizontalHeader()->setResizeMode( AddressTableModel::Label, QHeaderView::Stretch); + connect(ui->receiveTableView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + this, SLOT(selectionChanged())); + connect(ui->sendTableView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + this, SLOT(selectionChanged())); + if(mode == ForSending) { // Auto-select first row when in sending mode @@ -74,7 +81,7 @@ void AddressBookDialog::setModel(AddressTableModel *model) void AddressBookDialog::setTab(int tab) { ui->tabWidget->setCurrentIndex(tab); - on_tabWidget_currentChanged(tab); + selectionChanged(); } QTableView *AddressBookDialog::getCurrentTable() @@ -114,20 +121,6 @@ void AddressBookDialog::on_newAddressButton_clicked() dlg.exec(); } -void AddressBookDialog::on_tabWidget_currentChanged(int index) -{ - // Enable/disable buttons based on selected tab - switch(index) - { - case SendingTab: - ui->deleteButton->setEnabled(true); - break; - case ReceivingTab: - ui->deleteButton->setEnabled(false); - break; - } -} - void AddressBookDialog::on_deleteButton_clicked() { QTableView *table = getCurrentTable(); @@ -158,3 +151,27 @@ void AddressBookDialog::on_buttonBox_accepted() } } +void AddressBookDialog::selectionChanged() +{ + // Set button states based on selected tab and selection + QTableView *table = getCurrentTable(); + + if(table->selectionModel()->hasSelection()) + { + switch(ui->tabWidget->currentIndex()) + { + case SendingTab: + ui->deleteButton->setEnabled(true); + break; + case ReceivingTab: + ui->deleteButton->setEnabled(false); + break; + } + ui->copyToClipboard->setEnabled(true); + } + else + { + ui->deleteButton->setEnabled(false); + ui->copyToClipboard->setEnabled(false); + } +} diff --git a/src/qt/addressbookdialog.h b/src/qt/addressbookdialog.h index fe243a62ca..befa8b7659 100644 --- a/src/qt/addressbookdialog.h +++ b/src/qt/addressbookdialog.h @@ -10,6 +10,7 @@ class AddressTableModel; QT_BEGIN_NAMESPACE class QTableView; +class QItemSelection; QT_END_NAMESPACE class AddressBookDialog : public QDialog @@ -44,9 +45,9 @@ private: private slots: void on_buttonBox_accepted(); void on_deleteButton_clicked(); - void on_tabWidget_currentChanged(int index); void on_newAddressButton_clicked(); void on_copyToClipboard_clicked(); + void selectionChanged(); }; #endif // ADDRESSBOOKDIALOG_H -- cgit v1.2.3