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