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: f0d04795e23606399414d074d78efe5aa0da7259
This commit is contained in:
parent
b7086e69ff
commit
7bc4498234
|
@ -517,6 +517,9 @@
|
|||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QAbstractScrollArea::AdjustToContents</enum>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::NoSelection</enum>
|
||||
</property>
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
#include <QPainter>
|
||||
#include <QStatusTipEvent>
|
||||
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
|
||||
#define DECORATION_SIZE 54
|
||||
#define NUM_ITEMS 5
|
||||
|
||||
|
@ -34,7 +37,7 @@ public:
|
|||
QAbstractItemDelegate(parent), unit(BitcoinUnits::BTC),
|
||||
platformStyle(_platformStyle)
|
||||
{
|
||||
|
||||
connect(this, &TxViewDelegate::width_changed, this, &TxViewDelegate::sizeHintChanged);
|
||||
}
|
||||
|
||||
inline void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
|
@ -67,13 +70,15 @@ public:
|
|||
|
||||
painter->setPen(foreground);
|
||||
QRect boundingRect;
|
||||
painter->drawText(addressRect, Qt::AlignLeft|Qt::AlignVCenter, address, &boundingRect);
|
||||
painter->drawText(addressRect, Qt::AlignLeft | Qt::AlignVCenter, address, &boundingRect);
|
||||
int address_rect_min_width = boundingRect.width();
|
||||
|
||||
if (index.data(TransactionTableModel::WatchonlyRole).toBool())
|
||||
{
|
||||
QIcon iconWatchonly = qvariant_cast<QIcon>(index.data(TransactionTableModel::WatchonlyDecorationRole));
|
||||
QRect watchonlyRect(boundingRect.right() + 5, mainRect.top()+ypad+halfheight, 16, halfheight);
|
||||
iconWatchonly.paint(painter, watchonlyRect);
|
||||
address_rect_min_width += 5 + watchonlyRect.width();
|
||||
}
|
||||
|
||||
if(amount < 0)
|
||||
|
@ -94,23 +99,42 @@ public:
|
|||
{
|
||||
amountText = QString("[") + amountText + QString("]");
|
||||
}
|
||||
painter->drawText(amountRect, Qt::AlignRight|Qt::AlignVCenter, amountText);
|
||||
|
||||
QRect amount_bounding_rect;
|
||||
painter->drawText(amountRect, Qt::AlignRight | Qt::AlignVCenter, amountText, &amount_bounding_rect);
|
||||
|
||||
painter->setPen(option.palette.color(QPalette::Text));
|
||||
painter->drawText(amountRect, Qt::AlignLeft|Qt::AlignVCenter, GUIUtil::dateTimeStr(date));
|
||||
QRect date_bounding_rect;
|
||||
painter->drawText(amountRect, Qt::AlignLeft | Qt::AlignVCenter, GUIUtil::dateTimeStr(date), &date_bounding_rect);
|
||||
|
||||
const int minimum_width = std::max(address_rect_min_width, amount_bounding_rect.width() + date_bounding_rect.width());
|
||||
const auto search = m_minimum_width.find(index.row());
|
||||
if (search == m_minimum_width.end() || search->second != minimum_width) {
|
||||
m_minimum_width[index.row()] = minimum_width;
|
||||
Q_EMIT width_changed(index);
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
inline QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
|
||||
{
|
||||
return QSize(DECORATION_SIZE, DECORATION_SIZE);
|
||||
const auto search = m_minimum_width.find(index.row());
|
||||
const int minimum_text_width = search == m_minimum_width.end() ? 0 : search->second;
|
||||
return {DECORATION_SIZE + 8 + minimum_text_width, DECORATION_SIZE};
|
||||
}
|
||||
|
||||
int unit;
|
||||
const PlatformStyle *platformStyle;
|
||||
|
||||
Q_SIGNALS:
|
||||
//! An intermediate signal for emitting from the `paint() const` member function.
|
||||
void width_changed(const QModelIndex& index) const;
|
||||
|
||||
private:
|
||||
const PlatformStyle* platformStyle;
|
||||
mutable std::map<int, int> m_minimum_width;
|
||||
};
|
||||
|
||||
#include <qt/overviewpage.moc>
|
||||
|
||||
OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent) :
|
||||
|
|
Loading…
Reference in a new issue