mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-14 12:43:40 +02:00
gui: Alternate row background based on txid
Github-Pull: bitcoin/bitcoin #12578 Rebased-From: 264f9c4d4f7c1aeb3e89eedddcd88e47e8bba938
This commit is contained in:
parent
3edcdf8f0b
commit
1655947c15
1 changed files with 34 additions and 1 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue