2011-07-05 22:09:39 +02:00
|
|
|
#include "overviewpage.h"
|
|
|
|
#include "ui_overviewpage.h"
|
|
|
|
|
2011-07-11 20:42:10 +02:00
|
|
|
#include "walletmodel.h"
|
2011-07-25 21:35:45 +02:00
|
|
|
#include "bitcoinunits.h"
|
2011-07-29 14:36:35 +02:00
|
|
|
#include "optionsmodel.h"
|
2011-08-03 20:52:18 +02:00
|
|
|
#include "transactiontablemodel.h"
|
|
|
|
#include "transactionfilterproxy.h"
|
|
|
|
#include "guiutil.h"
|
|
|
|
#include "guiconstants.h"
|
2011-07-29 14:36:35 +02:00
|
|
|
|
2011-08-03 21:28:11 +02:00
|
|
|
#include <QAbstractItemDelegate>
|
2011-08-03 20:52:18 +02:00
|
|
|
#include <QPainter>
|
|
|
|
|
|
|
|
#define DECORATION_SIZE 64
|
2011-08-03 21:04:15 +02:00
|
|
|
#define NUM_ITEMS 3
|
|
|
|
|
2011-08-03 21:28:11 +02:00
|
|
|
class TxViewDelegate : public QAbstractItemDelegate
|
2011-08-03 20:52:18 +02:00
|
|
|
{
|
2011-09-19 12:40:23 +02:00
|
|
|
Q_OBJECT
|
2011-08-03 20:52:18 +02:00
|
|
|
public:
|
2011-08-03 21:28:11 +02:00
|
|
|
TxViewDelegate(): QAbstractItemDelegate(), unit(BitcoinUnits::BTC)
|
2011-08-03 20:52:18 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
|
|
|
const QModelIndex &index ) const
|
|
|
|
{
|
|
|
|
painter->save();
|
|
|
|
|
|
|
|
QIcon icon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
|
|
|
|
QRect mainRect = option.rect;
|
|
|
|
QRect decorationRect(mainRect.topLeft(), QSize(DECORATION_SIZE, DECORATION_SIZE));
|
|
|
|
int xspace = DECORATION_SIZE + 8;
|
|
|
|
int ypad = 6;
|
|
|
|
int halfheight = (mainRect.height() - 2*ypad)/2;
|
|
|
|
QRect amountRect(mainRect.left() + xspace, mainRect.top()+ypad, mainRect.width() - xspace, halfheight);
|
|
|
|
QRect addressRect(mainRect.left() + xspace, mainRect.top()+ypad+halfheight, mainRect.width() - xspace, halfheight);
|
|
|
|
icon.paint(painter, decorationRect);
|
|
|
|
|
|
|
|
QDateTime date = index.data(TransactionTableModel::DateRole).toDateTime();
|
|
|
|
QString address = index.data(Qt::DisplayRole).toString();
|
|
|
|
qint64 amount = index.data(TransactionTableModel::AmountRole).toLongLong();
|
|
|
|
bool confirmed = index.data(TransactionTableModel::ConfirmedRole).toBool();
|
|
|
|
QVariant value = index.data(Qt::ForegroundRole);
|
|
|
|
QColor foreground = option.palette.color(QPalette::Text);
|
|
|
|
if(qVariantCanConvert<QColor>(value))
|
|
|
|
{
|
|
|
|
foreground = qvariant_cast<QColor>(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
painter->setPen(foreground);
|
|
|
|
painter->drawText(addressRect, Qt::AlignLeft|Qt::AlignVCenter, address);
|
|
|
|
|
|
|
|
if(amount < 0)
|
|
|
|
{
|
|
|
|
foreground = COLOR_NEGATIVE;
|
|
|
|
}
|
2011-08-03 21:04:15 +02:00
|
|
|
else if(!confirmed)
|
|
|
|
{
|
|
|
|
foreground = COLOR_UNCONFIRMED;
|
|
|
|
}
|
2011-08-03 20:52:18 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
foreground = option.palette.color(QPalette::Text);
|
|
|
|
}
|
|
|
|
painter->setPen(foreground);
|
|
|
|
QString amountText = BitcoinUnits::formatWithUnit(unit, amount, true);
|
|
|
|
if(!confirmed)
|
|
|
|
{
|
|
|
|
amountText = QString("[") + amountText + QString("]");
|
|
|
|
}
|
|
|
|
painter->drawText(amountRect, Qt::AlignRight|Qt::AlignVCenter, amountText);
|
|
|
|
|
|
|
|
painter->setPen(option.palette.color(QPalette::Text));
|
2011-08-08 17:38:17 +02:00
|
|
|
painter->drawText(amountRect, Qt::AlignLeft|Qt::AlignVCenter, GUIUtil::dateTimeStr(date));
|
2011-08-03 20:52:18 +02:00
|
|
|
|
|
|
|
painter->restore();
|
|
|
|
}
|
|
|
|
|
2011-08-03 21:28:11 +02:00
|
|
|
inline QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
return QSize(DECORATION_SIZE, DECORATION_SIZE);
|
|
|
|
}
|
|
|
|
|
2011-08-03 20:52:18 +02:00
|
|
|
int unit;
|
|
|
|
|
|
|
|
};
|
2011-09-19 12:40:23 +02:00
|
|
|
#include "overviewpage.moc"
|
2011-07-05 22:09:39 +02:00
|
|
|
|
|
|
|
OverviewPage::OverviewPage(QWidget *parent) :
|
|
|
|
QWidget(parent),
|
2011-07-29 14:36:35 +02:00
|
|
|
ui(new Ui::OverviewPage),
|
|
|
|
currentBalance(-1),
|
2011-08-03 20:52:18 +02:00
|
|
|
currentUnconfirmedBalance(-1),
|
|
|
|
txdelegate(new TxViewDelegate())
|
2011-07-05 22:09:39 +02:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2011-08-03 20:52:18 +02:00
|
|
|
// Recent transactions
|
|
|
|
ui->listTransactions->setItemDelegate(txdelegate);
|
|
|
|
ui->listTransactions->setIconSize(QSize(DECORATION_SIZE, DECORATION_SIZE));
|
2011-08-03 21:04:15 +02:00
|
|
|
ui->listTransactions->setMinimumHeight(NUM_ITEMS * (DECORATION_SIZE + 2));
|
2011-10-07 13:21:45 +02:00
|
|
|
ui->listTransactions->setAttribute(Qt::WA_MacShowFocusRect, false);
|
2011-08-04 04:41:01 +02:00
|
|
|
|
|
|
|
connect(ui->listTransactions, SIGNAL(clicked(QModelIndex)), this, SIGNAL(transactionClicked(QModelIndex)));
|
2011-07-05 22:09:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
OverviewPage::~OverviewPage()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2011-07-11 20:42:10 +02:00
|
|
|
void OverviewPage::setBalance(qint64 balance, qint64 unconfirmedBalance)
|
2011-07-05 22:09:39 +02:00
|
|
|
{
|
2011-07-29 14:36:35 +02:00
|
|
|
int unit = model->getOptionsModel()->getDisplayUnit();
|
|
|
|
currentBalance = balance;
|
|
|
|
currentUnconfirmedBalance = unconfirmedBalance;
|
|
|
|
ui->labelBalance->setText(BitcoinUnits::formatWithUnit(unit, balance));
|
|
|
|
ui->labelUnconfirmed->setText(BitcoinUnits::formatWithUnit(unit, unconfirmedBalance));
|
2011-07-05 22:09:39 +02:00
|
|
|
}
|
2011-07-07 10:59:00 +02:00
|
|
|
|
|
|
|
void OverviewPage::setNumTransactions(int count)
|
|
|
|
{
|
|
|
|
ui->labelNumTransactions->setText(QLocale::system().toString(count));
|
|
|
|
}
|
2011-07-11 20:42:10 +02:00
|
|
|
|
|
|
|
void OverviewPage::setModel(WalletModel *model)
|
|
|
|
{
|
|
|
|
this->model = model;
|
2011-11-08 21:18:36 +01:00
|
|
|
if(model)
|
|
|
|
{
|
|
|
|
// Set up transaction list
|
|
|
|
TransactionFilterProxy *filter = new TransactionFilterProxy();
|
|
|
|
filter->setSourceModel(model->getTransactionTableModel());
|
|
|
|
filter->setLimit(NUM_ITEMS);
|
|
|
|
filter->setDynamicSortFilter(true);
|
|
|
|
filter->setSortRole(Qt::EditRole);
|
|
|
|
filter->sort(TransactionTableModel::Status, Qt::DescendingOrder);
|
2011-07-11 20:42:10 +02:00
|
|
|
|
2011-11-08 21:18:36 +01:00
|
|
|
ui->listTransactions->setModel(filter);
|
|
|
|
ui->listTransactions->setModelColumn(TransactionTableModel::ToAddress);
|
2011-08-03 20:52:18 +02:00
|
|
|
|
2011-11-08 21:18:36 +01:00
|
|
|
// Keep up to date with wallet
|
|
|
|
setBalance(model->getBalance(), model->getUnconfirmedBalance());
|
|
|
|
connect(model, SIGNAL(balanceChanged(qint64, qint64)), this, SLOT(setBalance(qint64, qint64)));
|
2011-07-11 20:42:10 +02:00
|
|
|
|
2011-11-08 21:18:36 +01:00
|
|
|
setNumTransactions(model->getNumTransactions());
|
|
|
|
connect(model, SIGNAL(numTransactionsChanged(int)), this, SLOT(setNumTransactions(int)));
|
2011-07-11 20:42:10 +02:00
|
|
|
|
2011-11-08 21:18:36 +01:00
|
|
|
connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(displayUnitChanged()));
|
|
|
|
}
|
2011-07-29 14:36:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void OverviewPage::displayUnitChanged()
|
|
|
|
{
|
2011-11-08 21:18:36 +01:00
|
|
|
if(!model || !model->getOptionsModel())
|
|
|
|
return;
|
2011-07-29 14:36:35 +02:00
|
|
|
if(currentBalance != -1)
|
|
|
|
setBalance(currentBalance, currentUnconfirmedBalance);
|
2011-08-03 20:52:18 +02:00
|
|
|
|
|
|
|
txdelegate->unit = model->getOptionsModel()->getDisplayUnit();
|
|
|
|
ui->listTransactions->update();
|
2011-07-11 20:42:10 +02:00
|
|
|
}
|