gui: Alternate row background based on txid

Github-Pull: bitcoin/bitcoin #12578
Rebased-From: 264f9c4d4f7c1aeb3e89eedddcd88e47e8bba938
This commit is contained in:
João Barbosa 2018-03-06 13:53:30 +00:00 committed by Gregory Sanders
parent 3edcdf8f0b
commit 1655947c15

View file

@ -26,9 +26,11 @@
#include <QDoubleValidator>
#include <QHBoxLayout>
#include <QHeaderView>
#include <QItemDelegate>
#include <QLabel>
#include <QLineEdit>
#include <QMenu>
#include <QPainter>
#include <QPoint>
#include <QScrollBar>
#include <QSignalMapper>
@ -37,6 +39,37 @@
#include <QUrl>
#include <QVBoxLayout>
class TransactionRecordDelegate : public QItemDelegate
{
QSortFilterProxyModel* m_proxy;
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
bool alternate = false;
QVariant previous_hash;
for (int row = 0; row <= index.row(); ++row) {
QModelIndex sibling = m_proxy->mapToSource(index.sibling(row, 0));
QVariant hash = sibling.data(TransactionTableModel::TxHashRole);
if (row == 0) {
previous_hash = hash;
} else if (hash != previous_hash) {
alternate = !alternate;
previous_hash = hash;
}
}
if (alternate) {
painter->fillRect(option.rect, option.palette.alternateBase());
}
QItemDelegate::paint(painter, option, index);
}
public:
TransactionRecordDelegate(QSortFilterProxyModel* proxy) : m_proxy(proxy) {}
};
TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *parent) :
QWidget(parent), model(0), transactionProxyModel(0),
transactionView(0), abandonAction(0), bumpFeeAction(0), columnResizingFixer(0)
@ -223,7 +256,7 @@ void TransactionView::setModel(WalletModel *_model)
transactionView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
transactionView->setModel(transactionProxyModel);
transactionView->setAlternatingRowColors(true);
transactionView->setItemDelegate(new TransactionRecordDelegate(transactionProxyModel));
transactionView->setSelectionBehavior(QAbstractItemView::SelectRows);
transactionView->setSelectionMode(QAbstractItemView::ExtendedSelection);
transactionView->setSortingEnabled(true);