| 33 | Q_DECLARE_METATYPE(interfaces::WalletBalances) |
| 34 | |
| 35 | class TxViewDelegate : public QAbstractItemDelegate |
| 36 | { |
| 37 | Q_OBJECT |
| 38 | public: |
| 39 | explicit TxViewDelegate(const PlatformStyle *_platformStyle, QObject *parent=nullptr): |
| 40 | QAbstractItemDelegate(parent), unit(BitcoinUnits::BTC), |
| 41 | platformStyle(_platformStyle) |
| 42 | { |
| 43 | connect(this, &TxViewDelegate::width_changed, this, &TxViewDelegate::sizeHintChanged); |
| 44 | } |
| 45 | |
| 46 | inline void paint(QPainter *painter, const QStyleOptionViewItem &option, |
| 47 | const QModelIndex &index ) const override |
| 48 | { |
| 49 | painter->save(); |
| 50 | |
| 51 | QIcon icon = qvariant_cast<QIcon>(index.data(TransactionTableModel::RawDecorationRole)); |
| 52 | QRect mainRect = option.rect; |
| 53 | QRect decorationRect(mainRect.topLeft(), QSize(DECORATION_SIZE, DECORATION_SIZE)); |
| 54 | int xspace = DECORATION_SIZE + 8; |
| 55 | int ypad = 6; |
| 56 | int halfheight = (mainRect.height() - 2*ypad)/2; |
| 57 | QRect amountRect(mainRect.left() + xspace, mainRect.top()+ypad, mainRect.width() - xspace, halfheight); |
| 58 | QRect addressRect(mainRect.left() + xspace, mainRect.top()+ypad+halfheight, mainRect.width() - xspace, halfheight); |
| 59 | icon = platformStyle->SingleColorIcon(icon); |
| 60 | icon.paint(painter, decorationRect); |
| 61 | |
| 62 | QDateTime date = index.data(TransactionTableModel::DateRole).toDateTime(); |
| 63 | QString address = index.data(Qt::DisplayRole).toString(); |
| 64 | qint64 amount = index.data(TransactionTableModel::AmountRole).toLongLong(); |
| 65 | bool confirmed = index.data(TransactionTableModel::ConfirmedRole).toBool(); |
| 66 | QVariant value = index.data(Qt::ForegroundRole); |
| 67 | QColor foreground = option.palette.color(QPalette::Text); |
| 68 | if(value.canConvert<QBrush>()) |
| 69 | { |
| 70 | QBrush brush = qvariant_cast<QBrush>(value); |
| 71 | foreground = brush.color(); |
| 72 | } |
| 73 | |
| 74 | if (index.data(TransactionTableModel::WatchonlyRole).toBool()) { |
| 75 | QIcon iconWatchonly = qvariant_cast<QIcon>(index.data(TransactionTableModel::WatchonlyDecorationRole)); |
| 76 | QRect watchonlyRect(addressRect.left(), addressRect.top(), 16, addressRect.height()); |
| 77 | iconWatchonly = platformStyle->TextColorIcon(iconWatchonly); |
| 78 | iconWatchonly.paint(painter, watchonlyRect); |
| 79 | addressRect.setLeft(addressRect.left() + watchonlyRect.width() + 5); |
| 80 | } |
| 81 | |
| 82 | painter->setPen(foreground); |
| 83 | QRect boundingRect; |
| 84 | painter->drawText(addressRect, Qt::AlignLeft | Qt::AlignVCenter, address, &boundingRect); |
| 85 | |
| 86 | if(amount < 0) |
| 87 | { |
| 88 | foreground = COLOR_NEGATIVE; |
| 89 | } |
| 90 | else if(!confirmed) |
| 91 | { |
| 92 | foreground = COLOR_UNCONFIRMED; |
nothing calls this directly
no test coverage detected