mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-10-10 19:43:13 +02:00
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.
This commit is contained in:
@@ -517,6 +517,9 @@
|
|||||||
<property name="horizontalScrollBarPolicy">
|
<property name="horizontalScrollBarPolicy">
|
||||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="sizeAdjustPolicy">
|
||||||
|
<enum>QAbstractScrollArea::AdjustToContents</enum>
|
||||||
|
</property>
|
||||||
<property name="selectionMode">
|
<property name="selectionMode">
|
||||||
<enum>QAbstractItemView::NoSelection</enum>
|
<enum>QAbstractItemView::NoSelection</enum>
|
||||||
</property>
|
</property>
|
||||||
|
@@ -22,6 +22,9 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QStatusTipEvent>
|
#include <QStatusTipEvent>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
#define DECORATION_SIZE 54
|
#define DECORATION_SIZE 54
|
||||||
#define NUM_ITEMS 5
|
#define NUM_ITEMS 5
|
||||||
|
|
||||||
@@ -35,7 +38,7 @@ public:
|
|||||||
QAbstractItemDelegate(parent), unit(BitcoinUnits::BTC),
|
QAbstractItemDelegate(parent), unit(BitcoinUnits::BTC),
|
||||||
platformStyle(_platformStyle)
|
platformStyle(_platformStyle)
|
||||||
{
|
{
|
||||||
|
connect(this, &TxViewDelegate::width_changed, this, &TxViewDelegate::sizeHintChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
inline void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||||
@@ -68,13 +71,15 @@ public:
|
|||||||
|
|
||||||
painter->setPen(foreground);
|
painter->setPen(foreground);
|
||||||
QRect boundingRect;
|
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())
|
if (index.data(TransactionTableModel::WatchonlyRole).toBool())
|
||||||
{
|
{
|
||||||
QIcon iconWatchonly = qvariant_cast<QIcon>(index.data(TransactionTableModel::WatchonlyDecorationRole));
|
QIcon iconWatchonly = qvariant_cast<QIcon>(index.data(TransactionTableModel::WatchonlyDecorationRole));
|
||||||
QRect watchonlyRect(boundingRect.right() + 5, mainRect.top()+ypad+halfheight, 16, halfheight);
|
QRect watchonlyRect(boundingRect.right() + 5, mainRect.top()+ypad+halfheight, 16, halfheight);
|
||||||
iconWatchonly.paint(painter, watchonlyRect);
|
iconWatchonly.paint(painter, watchonlyRect);
|
||||||
|
address_rect_min_width += 5 + watchonlyRect.width();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(amount < 0)
|
if(amount < 0)
|
||||||
@@ -95,23 +100,42 @@ public:
|
|||||||
{
|
{
|
||||||
amountText = QString("[") + amountText + QString("]");
|
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->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();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
|
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;
|
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>
|
#include <qt/overviewpage.moc>
|
||||||
|
|
||||||
OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent) :
|
OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent) :
|
||||||
|
Reference in New Issue
Block a user