Browse Source

improve address book, add less conspicious toolbar icon

pull/1/head
Wladimir J. van der Laan 12 years ago
parent
commit
b8e302eb53
  1. 2
      TODO
  2. 55
      addressbookdialog.cpp
  3. 3
      addressbookdialog.h
  4. 53
      addressbookdialog.ui
  5. 51
      addresstablemodel.cpp
  6. 14
      addresstablemodel.h
  7. 9
      bitcoin.pro
  8. 1
      bitcoin.qrc
  9. 10
      bitcoingui.cpp
  10. 14
      editaddressdialog.cpp
  11. 22
      editaddressdialog.h
  12. 77
      editaddressdialog.ui
  13. BIN
      res/icons/toolbar.png
  14. 9
      transactiontablemodel.cpp
  15. 8
      transactiontablemodel.h

2
TODO

@ -60,3 +60,5 @@ AboutDialog @@ -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?

55
addressbookdialog.cpp

@ -1,11 +1,20 @@ @@ -1,11 +1,20 @@
#include "addressbookdialog.h"
#include "ui_addressbookdialog.h"
#include "addresstablemodel.h"
#include "editaddressdialog.h"
#include <QSortFilterProxyModel>
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() @@ -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() @@ -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();
}

3
addressbookdialog.h

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
namespace Ui {
class AddressBookDialog;
}
class AddressTableModel;
class AddressBookDialog : public QDialog
{
@ -20,9 +21,11 @@ public: @@ -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();

53
addressbookdialog.ui

@ -25,7 +25,14 @@ @@ -25,7 +25,14 @@
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QTableView" name="sendTableView"/>
<widget class="QTableView" name="sendTableView">
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
</layout>
</widget>
@ -48,7 +55,14 @@ @@ -48,7 +55,14 @@
</widget>
</item>
<item>
<widget class="QTableView" name="receiveTableView"/>
<widget class="QTableView" name="receiveTableView">
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
</layout>
</widget>
@ -102,5 +116,38 @@ @@ -102,5 +116,38 @@
</layout>
</widget>
<resources/>
<connections/>
<connections>
<connection>
<sender>receiveTableView</sender>
<signal>doubleClicked(QModelIndex)</signal>
<receiver>editButton</receiver>
<slot>click()</slot>
<hints>
<hint type="sourcelabel">
<x>334</x>
<y>249</y>
</hint>
<hint type="destinationlabel">
<x>333</x>
<y>326</y>
</hint>
</hints>
</connection>
<connection>
<sender>sendTableView</sender>
<signal>doubleClicked(QModelIndex)</signal>
<receiver>editButton</receiver>
<slot>click()</slot>
<hints>
<hint type="sourcelabel">
<x>329</x>
<y>261</y>
</hint>
<hint type="destinationlabel">
<x>332</x>
<y>326</y>
</hint>
</hints>
</connection>
</connections>
</ui>

51
addresstablemodel.cpp

@ -1,6 +1,57 @@ @@ -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);
}

14
addresstablemodel.h

@ -9,6 +9,20 @@ class AddressTableModel : public QAbstractTableModel @@ -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:

9
bitcoin.pro

@ -15,7 +15,8 @@ HEADERS += bitcoingui.h \ @@ -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 \ @@ -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 += \ @@ -31,4 +33,5 @@ RESOURCES += \
FORMS += \
sendcoinsdialog.ui \
addressbookdialog.ui \
aboutdialog.ui
aboutdialog.ui \
editaddressdialog.ui

1
bitcoin.qrc

@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
<file alias="bitcoin">res/icons/bitcoin.png</file>
<file alias="quit">res/icons/quit.png</file>
<file alias="send">res/icons/send.png</file>
<file alias="toolbar">res/icons/toolbar.png</file>
</qresource>
<qresource prefix="/images">
<file alias="about">res/images/about.png</file>

10
bitcoingui.cpp

@ -150,7 +150,7 @@ void BitcoinGUI::createTrayIcon() @@ -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() @@ -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() @@ -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() @@ -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));
}

14
editaddressdialog.cpp

@ -0,0 +1,14 @@ @@ -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;
}

22
editaddressdialog.h

@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@
#ifndef EDITADDRESSDIALOG_H
#define EDITADDRESSDIALOG_H
#include <QDialog>
namespace Ui {
class EditAddressDialog;
}
class EditAddressDialog : public QDialog
{
Q_OBJECT
public:
explicit EditAddressDialog(QWidget *parent = 0);
~EditAddressDialog();
private:
Ui::EditAddressDialog *ui;
};
#endif // EDITADDRESSDIALOG_H

77
editaddressdialog.ui

@ -0,0 +1,77 @@ @@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>EditAddressDialog</class>
<widget class="QDialog" name="EditAddressDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>EditAddressDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>EditAddressDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

BIN
res/icons/toolbar.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 968 B

9
transactiontablemodel.cpp

@ -2,19 +2,24 @@ @@ -2,19 +2,24 @@
#include <QLocale>
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

8
transactiontablemodel.h

@ -15,9 +15,15 @@ public: @@ -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;

Loading…
Cancel
Save