b41d1be128
- Remove onion address label from overview page (was cutting into transaction list area) - Add it to the left side of the main window status bar instead, opposite the sync/connection icons - Add "Show .onion address in status bar" checkbox under Options > Display (enabled by default) - Polls every 5 seconds; hidden until the address is available Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
225 lines
7.5 KiB
C++
225 lines
7.5 KiB
C++
#include "overviewpage.h"
|
|
#include "ui_overviewpage.h"
|
|
|
|
#include "walletmodel.h"
|
|
#include "trianglesunits.h"
|
|
#include "optionsmodel.h"
|
|
#include "transactiontablemodel.h"
|
|
#include "transactionfilterproxy.h"
|
|
#include "guiutil.h"
|
|
#include "guiconstants.h"
|
|
|
|
#include <QAbstractItemDelegate>
|
|
#include <QPainter>
|
|
#include <QTimer>
|
|
|
|
#define DECORATION_SIZE 64
|
|
#define NUM_ITEMS 5
|
|
|
|
class TxViewDelegate : public QAbstractItemDelegate
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
TxViewDelegate(): QAbstractItemDelegate(), unit(TrianglesUnits::TRI)
|
|
{
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
painter->setPen(foreground);
|
|
painter->drawText(addressRect, Qt::AlignLeft|Qt::AlignVCenter, address);
|
|
|
|
if(amount < 0)
|
|
{
|
|
foreground = COLOR_NEGATIVE;
|
|
}
|
|
else if(!confirmed)
|
|
{
|
|
foreground = COLOR_UNCONFIRMED;
|
|
}
|
|
else
|
|
{
|
|
foreground = option.palette.color(QPalette::Text);
|
|
}
|
|
painter->setPen(foreground);
|
|
QString amountText = TrianglesUnits::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));
|
|
painter->drawText(amountRect, Qt::AlignLeft|Qt::AlignVCenter, GUIUtil::dateTimeStr(date));
|
|
|
|
painter->restore();
|
|
}
|
|
|
|
inline QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
|
{
|
|
return QSize(DECORATION_SIZE, DECORATION_SIZE);
|
|
}
|
|
|
|
int unit;
|
|
|
|
};
|
|
#include "overviewpage.moc"
|
|
|
|
OverviewPage::OverviewPage(QWidget *parent) :
|
|
QWidget(parent),
|
|
ui(new Ui::OverviewPage),
|
|
clientModel(0),
|
|
currentBalance(-1),
|
|
currentStake(0),
|
|
currentUnconfirmedBalance(-1),
|
|
currentImmatureBalance(-1),
|
|
walletTransactionSyncing(false),
|
|
txdelegate(new TxViewDelegate()),
|
|
filter(0)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
// Recent transactions
|
|
ui->listTransactions->setItemDelegate(txdelegate);
|
|
ui->listTransactions->setIconSize(QSize(DECORATION_SIZE, DECORATION_SIZE));
|
|
ui->listTransactions->setMinimumHeight(NUM_ITEMS * (DECORATION_SIZE + 2));
|
|
ui->listTransactions->setAttribute(Qt::WA_MacShowFocusRect, false);
|
|
|
|
connect(ui->listTransactions, SIGNAL(clicked(QModelIndex)), this, SLOT(handleTransactionClicked(QModelIndex)));
|
|
|
|
// init "out of sync" warning labels
|
|
ui->labelWalletStatus->setText("(" + tr("out of sync") + ")");
|
|
ui->labelTransactionsStatus->setText("(" + tr("out of sync") + ")");
|
|
|
|
// start with displaying the "out of sync" warnings
|
|
showOutOfSyncWarning(true);
|
|
|
|
}
|
|
|
|
void OverviewPage::handleTransactionClicked(const QModelIndex &index)
|
|
{
|
|
if(filter)
|
|
emit transactionClicked(filter->mapToSource(index));
|
|
}
|
|
|
|
OverviewPage::~OverviewPage()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void OverviewPage::setClientModel(ClientModel *clientModel)
|
|
{
|
|
this->clientModel = clientModel;
|
|
}
|
|
|
|
void OverviewPage::setBalance(qint64 balance, qint64 stake, qint64 unconfirmedBalance, qint64 immatureBalance)
|
|
{
|
|
if (!model || !model->getOptionsModel())
|
|
return;
|
|
int unit = model->getOptionsModel()->getDisplayUnit();
|
|
currentBalance = balance;
|
|
currentStake = stake;
|
|
currentUnconfirmedBalance = unconfirmedBalance;
|
|
currentImmatureBalance = immatureBalance;
|
|
ui->labelBalance->setText(TrianglesUnits::formatWithUnit(unit, balance));
|
|
ui->labelStake->setText(TrianglesUnits::formatWithUnit(unit, stake));
|
|
ui->labelUnconfirmed->setText(TrianglesUnits::formatWithUnit(unit, unconfirmedBalance));
|
|
ui->labelImmature->setText(TrianglesUnits::formatWithUnit(unit, immatureBalance));
|
|
ui->labelTotal->setText(TrianglesUnits::formatWithUnit(unit, balance + stake + unconfirmedBalance + immatureBalance));
|
|
|
|
// only show immature (newly mined) balance if it's non-zero, so as not to complicate things
|
|
// for the non-mining users
|
|
bool showImmature = immatureBalance != 0;
|
|
ui->labelImmature->setVisible(showImmature);
|
|
ui->labelImmatureText->setVisible(showImmature);
|
|
}
|
|
|
|
void OverviewPage::setModel(WalletModel *model)
|
|
{
|
|
this->model = model;
|
|
if(model && model->getOptionsModel())
|
|
{
|
|
// Set up transaction list
|
|
filter = new TransactionFilterProxy();
|
|
filter->setSourceModel(model->getTransactionTableModel());
|
|
filter->setLimit(NUM_ITEMS);
|
|
filter->setDynamicSortFilter(true);
|
|
filter->setSortRole(Qt::EditRole);
|
|
filter->setShowInactive(false);
|
|
filter->sort(TransactionTableModel::Status, Qt::DescendingOrder);
|
|
|
|
ui->listTransactions->setModel(filter);
|
|
ui->listTransactions->setModelColumn(TransactionTableModel::ToAddress);
|
|
|
|
// Keep up to date with wallet
|
|
setBalance(model->getBalance(), model->getStake(), model->getUnconfirmedBalance(), model->getImmatureBalance());
|
|
connect(model, SIGNAL(balanceChanged(qint64, qint64, qint64, qint64)), this, SLOT(setBalance(qint64, qint64, qint64, qint64)));
|
|
connect(model, SIGNAL(transactionSyncStateChanged(bool)), this, SLOT(setTransactionSyncState(bool)));
|
|
|
|
connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
|
|
setTransactionSyncState(model->isTransactionSyncing());
|
|
}
|
|
|
|
// update the display unit, to not use the default ("TRI")
|
|
updateDisplayUnit();
|
|
}
|
|
|
|
void OverviewPage::updateDisplayUnit()
|
|
{
|
|
if(model && model->getOptionsModel())
|
|
{
|
|
if(currentBalance != -1)
|
|
setBalance(currentBalance, model->getStake(), currentUnconfirmedBalance, currentImmatureBalance);
|
|
|
|
// Update txdelegate->unit with the current unit
|
|
txdelegate->unit = model->getOptionsModel()->getDisplayUnit();
|
|
|
|
ui->listTransactions->update();
|
|
}
|
|
}
|
|
|
|
void OverviewPage::setTransactionSyncState(bool syncing)
|
|
{
|
|
walletTransactionSyncing = syncing;
|
|
if (!filter)
|
|
return;
|
|
|
|
filter->setDynamicSortFilter(!syncing);
|
|
ui->listTransactions->setUpdatesEnabled(!syncing);
|
|
|
|
if (!syncing)
|
|
{
|
|
filter->invalidate();
|
|
filter->sort(TransactionTableModel::Status, Qt::DescendingOrder);
|
|
ui->listTransactions->viewport()->update();
|
|
}
|
|
}
|
|
|
|
void OverviewPage::showOutOfSyncWarning(bool fShow)
|
|
{
|
|
ui->labelWalletStatus->setVisible(fShow);
|
|
ui->labelTransactionsStatus->setVisible(fShow);
|
|
}
|
|
|