From b8e302eb538fd7f4131452c92d22300928f19a5a Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Fri, 13 May 2011 15:58:27 +0200 Subject: [PATCH] improve address book, add less conspicious toolbar icon --- TODO | 2 + addressbookdialog.cpp | 55 +++++++++++++++++++++++++-- addressbookdialog.h | 3 ++ addressbookdialog.ui | 53 ++++++++++++++++++++++++-- addresstablemodel.cpp | 51 +++++++++++++++++++++++++ addresstablemodel.h | 14 +++++++ bitcoin.pro | 9 +++-- bitcoin.qrc | 1 + bitcoingui.cpp | 10 +++-- editaddressdialog.cpp | 14 +++++++ editaddressdialog.h | 22 +++++++++++ editaddressdialog.ui | 77 ++++++++++++++++++++++++++++++++++++++ res/icons/toolbar.png | Bin 0 -> 968 bytes transactiontablemodel.cpp | 9 ++++- transactiontablemodel.h | 8 +++- 15 files changed, 311 insertions(+), 17 deletions(-) create mode 100644 editaddressdialog.cpp create mode 100644 editaddressdialog.h create mode 100644 editaddressdialog.ui create mode 100644 res/icons/toolbar.png diff --git a/TODO b/TODO index 0cc78f119..4f81ec95f 100644 --- a/TODO +++ b/TODO @@ -60,3 +60,5 @@ AboutDialog - Address - Delete / Copy to clipboard based on tab +- Make icon blend into taskbar and maybe silver/grey + Same for the other icons? diff --git a/addressbookdialog.cpp b/addressbookdialog.cpp index e1ce1feef..72b0da35f 100644 --- a/addressbookdialog.cpp +++ b/addressbookdialog.cpp @@ -1,11 +1,20 @@ #include "addressbookdialog.h" #include "ui_addressbookdialog.h" +#include "addresstablemodel.h" +#include "editaddressdialog.h" + +#include + AddressBookDialog::AddressBookDialog(QWidget *parent) : QDialog(parent), - ui(new Ui::AddressBookDialog) + ui(new Ui::AddressBookDialog), + model(0) { ui->setupUi(this); + + model = new AddressTableModel(this); + setModel(model); } AddressBookDialog::~AddressBookDialog() @@ -13,6 +22,41 @@ AddressBookDialog::~AddressBookDialog() delete ui; } +void AddressBookDialog::setModel(AddressTableModel *model) +{ + /* Receive filter */ + QSortFilterProxyModel *receive_model = new QSortFilterProxyModel(this); + receive_model->setSourceModel(model); + receive_model->setDynamicSortFilter(true); + receive_model->setFilterRole(Qt::UserRole); + receive_model->setFilterKeyColumn(AddressTableModel::Type); + receive_model->setFilterFixedString(AddressTableModel::Receive); + ui->receiveTableView->setModel(receive_model); + + /* Send filter */ + QSortFilterProxyModel *send_model = new QSortFilterProxyModel(this); + send_model->setSourceModel(model); + send_model->setDynamicSortFilter(true); + send_model->setFilterRole(Qt::UserRole); + send_model->setFilterKeyColumn(AddressTableModel::Type); + send_model->setFilterFixedString(AddressTableModel::Send); + ui->sendTableView->setModel(send_model); + + /* Set column widths */ + ui->receiveTableView->horizontalHeader()->resizeSection( + AddressTableModel::Address, 320); + ui->receiveTableView->horizontalHeader()->setResizeMode( + AddressTableModel::Label, QHeaderView::Stretch); + ui->sendTableView->horizontalHeader()->resizeSection( + AddressTableModel::Address, 320); + ui->sendTableView->horizontalHeader()->setResizeMode( + AddressTableModel::Label, QHeaderView::Stretch); + + /* Hide "Type" column in both views as it is only used for filtering */ + ui->receiveTableView->setColumnHidden(AddressTableModel::Type, true); + ui->sendTableView->setColumnHidden(AddressTableModel::Type, true); +} + void AddressBookDialog::setTab(int tab) { ui->tabWidget->setCurrentIndex(tab); @@ -25,15 +69,18 @@ void AddressBookDialog::on_OKButton_clicked() void AddressBookDialog::on_copyToClipboard_clicked() { - + /* Copy currently selected address to clipboard */ } void AddressBookDialog::on_editButton_clicked() { - + /* Double click should trigger edit button */ + EditAddressDialog dlg; + dlg.exec(); } void AddressBookDialog::on_newAddressButton_clicked() { - + EditAddressDialog dlg; + dlg.exec(); } diff --git a/addressbookdialog.h b/addressbookdialog.h index e287019d9..d075c9ba0 100644 --- a/addressbookdialog.h +++ b/addressbookdialog.h @@ -6,6 +6,7 @@ namespace Ui { class AddressBookDialog; } +class AddressTableModel; class AddressBookDialog : public QDialog { @@ -20,9 +21,11 @@ public: ReceivingTab = 1 } Tabs; + void setModel(AddressTableModel *model); void setTab(int tab); private: Ui::AddressBookDialog *ui; + AddressTableModel *model; private slots: void on_newAddressButton_clicked(); diff --git a/addressbookdialog.ui b/addressbookdialog.ui index 8620a1cc7..0aa093e05 100644 --- a/addressbookdialog.ui +++ b/addressbookdialog.ui @@ -25,7 +25,14 @@ - + + + QAbstractItemView::SelectRows + + + false + + @@ -48,7 +55,14 @@ - + + + QAbstractItemView::SelectRows + + + false + + @@ -102,5 +116,38 @@ - + + + receiveTableView + doubleClicked(QModelIndex) + editButton + click() + + + 334 + 249 + + + 333 + 326 + + + + + sendTableView + doubleClicked(QModelIndex) + editButton + click() + + + 329 + 261 + + + 332 + 326 + + + + diff --git a/addresstablemodel.cpp b/addresstablemodel.cpp index 95ea73260..e8746c2b8 100644 --- a/addresstablemodel.cpp +++ b/addresstablemodel.cpp @@ -1,6 +1,57 @@ #include "addresstablemodel.h" +const QString AddressTableModel::Send = "S"; +const QString AddressTableModel::Receive = "R"; + AddressTableModel::AddressTableModel(QObject *parent) : QAbstractTableModel(parent) { + +} + +int AddressTableModel::rowCount(const QModelIndex &parent) const +{ + return 5; +} + +int AddressTableModel::columnCount(const QModelIndex &parent) const +{ + return 3; +} + +QVariant AddressTableModel::data(const QModelIndex &index, int role) const +{ + if(!index.isValid()) + return QVariant(); + + if(role == Qt::DisplayRole) + { + /* index.row(), index.column() */ + /* Return QString */ + if(index.column() == Address) + return "1PC9aZC4hNX2rmmrt7uHTfYAS3hRbph4UN"; + else + return "Description"; + } else if (role == Qt::UserRole) + { + switch(index.row() % 2) + { + case 0: return Send; + case 1: return Receive; + } + } + return QVariant(); +} + +QVariant AddressTableModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + return QVariant(); +} + +Qt::ItemFlags AddressTableModel::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + return Qt::ItemIsEnabled; + + return QAbstractTableModel::flags(index); } diff --git a/addresstablemodel.h b/addresstablemodel.h index 490452e11..50ed80dd3 100644 --- a/addresstablemodel.h +++ b/addresstablemodel.h @@ -9,6 +9,20 @@ class AddressTableModel : public QAbstractTableModel public: explicit AddressTableModel(QObject *parent = 0); + enum { + Label = 0, /* User specified label */ + Address = 1, /* Bitcoin address */ + Type = 2 /* Send/Receive, used for filter */ + } ColumnIndex; + + static const QString Send; /* Send addres */ + static const QString Receive; /* Receive address */ + + int rowCount(const QModelIndex &parent) const; + int columnCount(const QModelIndex &parent) const; + QVariant data(const QModelIndex &index, int role) const; + QVariant headerData(int section, Qt::Orientation orientation, int role) const; + Qt::ItemFlags flags(const QModelIndex &index) const; signals: public slots: diff --git a/bitcoin.pro b/bitcoin.pro index 7bcf3afde..d0b9512b9 100644 --- a/bitcoin.pro +++ b/bitcoin.pro @@ -15,7 +15,8 @@ HEADERS += bitcoingui.h \ mainoptionspage.h \ sendcoinsdialog.h \ addressbookdialog.h \ - aboutdialog.h + aboutdialog.h \ + editaddressdialog.h SOURCES += bitcoin.cpp bitcoingui.cpp \ transactiontablemodel.cpp \ addresstablemodel.cpp \ @@ -23,7 +24,8 @@ SOURCES += bitcoin.cpp bitcoingui.cpp \ mainoptionspage.cpp \ sendcoinsdialog.cpp \ addressbookdialog.cpp \ - aboutdialog.cpp + aboutdialog.cpp \ + editaddressdialog.cpp RESOURCES += \ bitcoin.qrc @@ -31,4 +33,5 @@ RESOURCES += \ FORMS += \ sendcoinsdialog.ui \ addressbookdialog.ui \ - aboutdialog.ui + aboutdialog.ui \ + editaddressdialog.ui diff --git a/bitcoin.qrc b/bitcoin.qrc index 0d91bbcd4..80904b341 100644 --- a/bitcoin.qrc +++ b/bitcoin.qrc @@ -4,6 +4,7 @@ res/icons/bitcoin.png res/icons/quit.png res/icons/send.png + res/icons/toolbar.png res/images/about.png diff --git a/bitcoingui.cpp b/bitcoingui.cpp index 072dc9291..4af703cf8 100644 --- a/bitcoingui.cpp +++ b/bitcoingui.cpp @@ -150,7 +150,7 @@ void BitcoinGUI::createTrayIcon() trayIcon = new QSystemTrayIcon(this); trayIcon->setContextMenu(trayIconMenu); - trayIcon->setIcon(QIcon(":/icons/bitcoin")); + trayIcon->setIcon(QIcon(":/icons/toolbar")); trayIcon->show(); } @@ -158,9 +158,9 @@ QWidget *BitcoinGUI::createTabs() { QStringList tab_filters, tab_labels; tab_filters << "^." - << "^[sr]" - << "^[s]" - << "^[r]"; + << "^["+TransactionTableModel::Sent+TransactionTableModel::Received+"]" + << "^["+TransactionTableModel::Sent+"]" + << "^["+TransactionTableModel::Received+"]"; tab_labels << tr("All transactions") << tr("Sent/Received") << tr("Sent") @@ -173,6 +173,7 @@ QWidget *BitcoinGUI::createTabs() proxy_model->setSourceModel(transaction_model); proxy_model->setDynamicSortFilter(true); proxy_model->setFilterRole(Qt::UserRole); + proxy_model->setFilterKeyColumn(TransactionTableModel::Type); proxy_model->setFilterRegExp(QRegExp(tab_filters.at(i))); QTableView *transaction_table = new QTableView(this); @@ -191,6 +192,7 @@ QWidget *BitcoinGUI::createTabs() TransactionTableModel::Debit, 79); transaction_table->horizontalHeader()->resizeSection( TransactionTableModel::Credit, 79); + transaction_table->setColumnHidden(TransactionTableModel::Type, true); tabs->addTab(transaction_table, tab_labels.at(i)); } diff --git a/editaddressdialog.cpp b/editaddressdialog.cpp new file mode 100644 index 000000000..bd5559792 --- /dev/null +++ b/editaddressdialog.cpp @@ -0,0 +1,14 @@ +#include "editaddressdialog.h" +#include "ui_editaddressdialog.h" + +EditAddressDialog::EditAddressDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::EditAddressDialog) +{ + ui->setupUi(this); +} + +EditAddressDialog::~EditAddressDialog() +{ + delete ui; +} diff --git a/editaddressdialog.h b/editaddressdialog.h new file mode 100644 index 000000000..650ed534a --- /dev/null +++ b/editaddressdialog.h @@ -0,0 +1,22 @@ +#ifndef EDITADDRESSDIALOG_H +#define EDITADDRESSDIALOG_H + +#include + +namespace Ui { + class EditAddressDialog; +} + +class EditAddressDialog : public QDialog +{ + Q_OBJECT + +public: + explicit EditAddressDialog(QWidget *parent = 0); + ~EditAddressDialog(); + +private: + Ui::EditAddressDialog *ui; +}; + +#endif // EDITADDRESSDIALOG_H diff --git a/editaddressdialog.ui b/editaddressdialog.ui new file mode 100644 index 000000000..2d8aa880f --- /dev/null +++ b/editaddressdialog.ui @@ -0,0 +1,77 @@ + + + EditAddressDialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + EditAddressDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + EditAddressDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/res/icons/toolbar.png b/res/icons/toolbar.png new file mode 100644 index 0000000000000000000000000000000000000000..f2dcb20636509921784894cc075e93f495cf3902 GIT binary patch literal 968 zcmV;(12_DMP)Px#24YJ`L;y_yO#n?P4+J>?000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2ipY= z4LB*&Ql=#U00T%#L_t(I%UzQ_Y#U_&hM)UB-<@-I96NDhJI+s&Ka@%EOvncQ}i^JmX}U3!>T z9+Y=Zp9)Cfo=J?19E)|wP!wgCxL7E1BlTxtV!CM^MHqr=m5H|6YbuEloEsoS8*wA<*8aWhYlaaFuap*oO-!esG58+-W^f$_p@lK zMkv(5&?Ao$3bx`k49b?p)8pgVO-ZBKz|3aQb)A8seQL?fz9fRd@L?$>g+d8c({UY} zd@c*X(&9Wz3-grA7XH=%l}d$ry+)&M6N|?|aKz(LJ&~O`TzrNO2&AS0ka+A#f^7l( zeuGphg{s(qhkCt<&*uZ^6OQXRuIqy9ph$^fc+u4z!RpEq>2#V*CdNXLpQve?QxfLh@pgjk|Z3{lW0`t}}gd?u^Lg)?exBicSs= z?eT>|Z3rQ7QK(u~R##U^&COCNSAOg0>YY0K;TPsE!GnD8-dmwucI||!s?XuFw{BZ4 qjplZ~TD4P}*Es*tXWw0ZnEwy#SX00_=&3CL0000 +const QString TransactionTableModel::Sent = "s"; +const QString TransactionTableModel::Received = "r"; +const QString TransactionTableModel::Generated = "g"; + /* Credit and Debit columns are right-aligned as they contain numbers */ static int column_alignments[] = { Qt::AlignLeft|Qt::AlignVCenter, Qt::AlignLeft|Qt::AlignVCenter, Qt::AlignLeft|Qt::AlignVCenter, Qt::AlignRight|Qt::AlignVCenter, - Qt::AlignRight|Qt::AlignVCenter + Qt::AlignRight|Qt::AlignVCenter, + Qt::AlignLeft|Qt::AlignVCenter }; TransactionTableModel::TransactionTableModel(QObject *parent): QAbstractTableModel(parent) { - columns << tr("Status") << tr("Date") << tr("Description") << tr("Debit") << tr("Credit"); + columns << tr("Status") << tr("Date") << tr("Description") << tr("Debit") << tr("Credit") << tr("Type"); } int TransactionTableModel::rowCount(const QModelIndex &parent) const diff --git a/transactiontablemodel.h b/transactiontablemodel.h index 8913f1d94..77ad73067 100644 --- a/transactiontablemodel.h +++ b/transactiontablemodel.h @@ -15,9 +15,15 @@ public: Date = 1, Description = 2, Debit = 3, - Credit = 4 + Credit = 4, + Type = 5 } ColumnIndex; + /* Transaction type */ + static const QString Sent; + static const QString Received; + static const QString Generated; + int rowCount(const QModelIndex &parent) const; int columnCount(const QModelIndex &parent) const; QVariant data(const QModelIndex &index, int role) const;