Skip to content

Commit 7bc4498

Browse files
hebastoMarcoFalke
authored and
MarcoFalke
committed
qt: Fix TxViewDelegate layout
This change (1) prevents overlapping date and amount strings, and (2) guaranties that "eye" sign at the end of the watch-only address/label is always visible. Github-Pull: bitcoin-core/gui#176 Rebased-From: f0d0479
1 parent b7086e6 commit 7bc4498

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

src/qt/forms/overviewpage.ui

+3
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,9 @@
517517
<property name="horizontalScrollBarPolicy">
518518
<enum>Qt::ScrollBarAlwaysOff</enum>
519519
</property>
520+
<property name="sizeAdjustPolicy">
521+
<enum>QAbstractScrollArea::AdjustToContents</enum>
522+
</property>
520523
<property name="selectionMode">
521524
<enum>QAbstractItemView::NoSelection</enum>
522525
</property>

src/qt/overviewpage.cpp

+30-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
#include <QPainter>
2222
#include <QStatusTipEvent>
2323

24+
#include <algorithm>
25+
#include <map>
26+
2427
#define DECORATION_SIZE 54
2528
#define NUM_ITEMS 5
2629

@@ -34,7 +37,7 @@ class TxViewDelegate : public QAbstractItemDelegate
3437
QAbstractItemDelegate(parent), unit(BitcoinUnits::BTC),
3538
platformStyle(_platformStyle)
3639
{
37-
40+
connect(this, &TxViewDelegate::width_changed, this, &TxViewDelegate::sizeHintChanged);
3841
}
3942

4043
inline void paint(QPainter *painter, const QStyleOptionViewItem &option,
@@ -67,13 +70,15 @@ class TxViewDelegate : public QAbstractItemDelegate
6770

6871
painter->setPen(foreground);
6972
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();
7175

7276
if (index.data(TransactionTableModel::WatchonlyRole).toBool())
7377
{
7478
QIcon iconWatchonly = qvariant_cast<QIcon>(index.data(TransactionTableModel::WatchonlyDecorationRole));
7579
QRect watchonlyRect(boundingRect.right() + 5, mainRect.top()+ypad+halfheight, 16, halfheight);
7680
iconWatchonly.paint(painter, watchonlyRect);
81+
address_rect_min_width += 5 + watchonlyRect.width();
7782
}
7883

7984
if(amount < 0)
@@ -94,23 +99,42 @@ class TxViewDelegate : public QAbstractItemDelegate
9499
{
95100
amountText = QString("[") + amountText + QString("]");
96101
}
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);
98105

99106
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+
}
101116

102117
painter->restore();
103118
}
104119

105120
inline QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
106121
{
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};
108125
}
109126

110127
int unit;
111-
const PlatformStyle *platformStyle;
112128

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;
113136
};
137+
114138
#include <qt/overviewpage.moc>
115139

116140
OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent) :

0 commit comments

Comments
 (0)