12
12
#include < qt/optionsmodel.h>
13
13
#include < qt/platformstyle.h>
14
14
#include < qt/transactionfilterproxy.h>
15
+ #include < qt/transactionoverviewwidget.h>
15
16
#include < qt/transactiontablemodel.h>
16
17
#include < qt/walletmodel.h>
17
18
21
22
#include < QPainter>
22
23
#include < QStatusTipEvent>
23
24
25
+ #include < algorithm>
26
+ #include < map>
27
+
24
28
#define DECORATION_SIZE 54
25
29
#define NUM_ITEMS 5
26
30
@@ -34,7 +38,7 @@ class TxViewDelegate : public QAbstractItemDelegate
34
38
QAbstractItemDelegate (parent), unit (BitcoinUnits::BTC),
35
39
platformStyle (_platformStyle)
36
40
{
37
-
41
+ connect ( this , &TxViewDelegate::width_changed, this , &TxViewDelegate::sizeHintChanged);
38
42
}
39
43
40
44
inline void paint (QPainter *painter, const QStyleOptionViewItem &option,
@@ -67,13 +71,15 @@ class TxViewDelegate : public QAbstractItemDelegate
67
71
68
72
painter->setPen (foreground);
69
73
QRect boundingRect;
70
- 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 ();
71
76
72
77
if (index .data (TransactionTableModel::WatchonlyRole).toBool ())
73
78
{
74
79
QIcon iconWatchonly = qvariant_cast<QIcon>(index .data (TransactionTableModel::WatchonlyDecorationRole));
75
80
QRect watchonlyRect (boundingRect.right () + 5 , mainRect.top ()+ypad+halfheight, 16 , halfheight);
76
81
iconWatchonly.paint (painter, watchonlyRect);
82
+ address_rect_min_width += 5 + watchonlyRect.width ();
77
83
}
78
84
79
85
if (amount < 0 )
@@ -94,23 +100,42 @@ class TxViewDelegate : public QAbstractItemDelegate
94
100
{
95
101
amountText = QString (" [" ) + amountText + QString (" ]" );
96
102
}
97
- 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);
98
106
99
107
painter->setPen (option.palette .color (QPalette::Text));
100
- 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
+ }
101
117
102
118
painter->restore ();
103
119
}
104
120
105
121
inline QSize sizeHint (const QStyleOptionViewItem &option, const QModelIndex &index ) const override
106
122
{
107
- 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};
108
126
}
109
127
110
128
int unit;
111
- const PlatformStyle *platformStyle;
112
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;
113
137
};
138
+
114
139
#include < qt/overviewpage.moc>
115
140
116
141
OverviewPage::OverviewPage (const PlatformStyle *platformStyle, QWidget *parent) :
@@ -136,7 +161,7 @@ OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent)
136
161
ui->listTransactions ->setMinimumHeight (NUM_ITEMS * (DECORATION_SIZE + 2 ));
137
162
ui->listTransactions ->setAttribute (Qt::WA_MacShowFocusRect, false );
138
163
139
- connect (ui->listTransactions , &QListView ::clicked, this , &OverviewPage::handleTransactionClicked);
164
+ connect (ui->listTransactions , &TransactionOverviewWidget ::clicked, this , &OverviewPage::handleTransactionClicked);
140
165
141
166
// start with displaying the "out of sync" warnings
142
167
showOutOfSyncWarning (true );
0 commit comments