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