aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2011-07-06 21:52:23 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2011-07-06 21:52:23 +0200
commit393adf7acd8bfacaccb8b9543ce4d2b442608124 (patch)
treef65556e38a367a09002cc164a8c5d8d069346d87
parent8bca4099c712b816ec859b39571b7c555b33be49 (diff)
Address book: Disable "copy to clipboard" and "Delete" buttons when nothing selected
-rw-r--r--src/qt/addressbookdialog.cpp47
-rw-r--r--src/qt/addressbookdialog.h3
2 files changed, 34 insertions, 16 deletions
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