23
23
#include < QPainter>
24
24
#include < QStatusTipEvent>
25
25
26
+ #include < algorithm>
27
+ #include < map>
28
+
26
29
#define DECORATION_SIZE 54
27
30
#define NUM_ITEMS 5
28
31
@@ -36,7 +39,7 @@ class TxViewDelegate : public QAbstractItemDelegate
36
39
QAbstractItemDelegate (parent), unit (BitcoinUnits::BTC),
37
40
platformStyle (_platformStyle)
38
41
{
39
-
42
+ connect ( this , &TxViewDelegate::width_changed, this , &TxViewDelegate::sizeHintChanged);
40
43
}
41
44
42
45
inline void paint (QPainter *painter, const QStyleOptionViewItem &option,
@@ -69,13 +72,15 @@ class TxViewDelegate : public QAbstractItemDelegate
69
72
70
73
painter->setPen (foreground);
71
74
QRect boundingRect;
72
- painter->drawText (addressRect, Qt::AlignLeft|Qt::AlignVCenter, address, &boundingRect);
75
+ painter->drawText (addressRect, Qt::AlignLeft | Qt::AlignVCenter, address, &boundingRect);
76
+ int address_rect_min_width = boundingRect.width ();
73
77
74
78
if (index .data (TransactionTableModel::WatchonlyRole).toBool ())
75
79
{
76
80
QIcon iconWatchonly = qvariant_cast<QIcon>(index .data (TransactionTableModel::WatchonlyDecorationRole));
77
81
QRect watchonlyRect (boundingRect.right () + 5 , mainRect.top ()+ypad+halfheight, 16 , halfheight);
78
82
iconWatchonly.paint (painter, watchonlyRect);
83
+ address_rect_min_width += 5 + watchonlyRect.width ();
79
84
}
80
85
81
86
if (amount < 0 )
@@ -92,23 +97,41 @@ class TxViewDelegate : public QAbstractItemDelegate
92
97
}
93
98
painter->setPen (foreground);
94
99
QString amountText = index .sibling (index .row (), TransactionTableModel::Amount).data (Qt::DisplayRole).toString ();
95
- painter->drawText (amountRect, Qt::AlignRight|Qt::AlignVCenter, amountText);
100
+ QRect amount_bounding_rect;
101
+ painter->drawText (amountRect, Qt::AlignRight | Qt::AlignVCenter, amountText, &amount_bounding_rect);
96
102
97
103
painter->setPen (option.palette .color (QPalette::Text));
98
- painter->drawText (amountRect, Qt::AlignLeft|Qt::AlignVCenter, GUIUtil::dateTimeStr (date));
104
+ QRect date_bounding_rect;
105
+ painter->drawText (amountRect, Qt::AlignLeft | Qt::AlignVCenter, GUIUtil::dateTimeStr (date), &date_bounding_rect);
106
+
107
+ const int minimum_width = std::max (address_rect_min_width, amount_bounding_rect.width () + date_bounding_rect.width ());
108
+ const auto search = m_minimum_width.find (index .row ());
109
+ if (search == m_minimum_width.end () || search->second != minimum_width) {
110
+ m_minimum_width[index .row ()] = minimum_width;
111
+ Q_EMIT width_changed (index );
112
+ }
99
113
100
114
painter->restore ();
101
115
}
102
116
103
117
inline QSize sizeHint (const QStyleOptionViewItem &option, const QModelIndex &index ) const override
104
118
{
105
- return QSize (DECORATION_SIZE, DECORATION_SIZE);
119
+ const auto search = m_minimum_width.find (index .row ());
120
+ const int minimum_text_width = search == m_minimum_width.end () ? 0 : search->second ;
121
+ return {DECORATION_SIZE + 8 + minimum_text_width, DECORATION_SIZE};
106
122
}
107
123
108
124
int unit;
109
- const PlatformStyle *platformStyle;
110
125
126
+ Q_SIGNALS:
127
+ // ! An intermediate signal for emitting from the `paint() const` member function.
128
+ void width_changed (const QModelIndex& index ) const ;
129
+
130
+ private:
131
+ const PlatformStyle* platformStyle;
132
+ mutable std::map<int , int > m_minimum_width;
111
133
};
134
+
112
135
#include < qt/overviewpage.moc>
113
136
114
137
OverviewPage::OverviewPage (const PlatformStyle *platformStyle, QWidget *parent) :
0 commit comments