MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / paint

Function paint

src/qt/overviewpage.cpp:33–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 8

dateTimeStrFunction · 0.85
heightMethod · 0.80
SingleColorIconMethod · 0.80
findMethod · 0.80
dataMethod · 0.45
toStringMethod · 0.45
endMethod · 0.45
restoreMethod · 0.45

Tested by

no test coverage detected