Merge bitcoin-core/gui#176: Fix TxViewDelegate layout
af58f5b12cqt: Stop the effect of hidden widgets on the size of QStackedWidget (Hennadii Stepanov)f0d04795e2qt: Fix TxViewDelegate layout (Hennadii Stepanov)d439921406qt: Add TransactionOverviewWidget class (Hennadii Stepanov) Pull request description: This change: - prevents overlapping date and amount strings - guaranties that "eye" sign at the end of the watch-only address/label is always visible Fix https://github.com/bitcoin/bitcoin/issues/20826 Here are some screenshots with this PR with the _minimum available width_ of the transaction list widget:     ACKs for top commit: dooglus: ACKaf58f5b. jarolrod: re-ACKaf58f5b12cTree-SHA512: 6dae682490ec50fa0335d220bc2d153fa3e6ed578f07c6353a3b180f8f6cf1c2f9e52ebd7b3076f51d7004d86bf5cca14e6b5db9cdf786e85a57a81eacbb4988
This commit is contained in:
5 files changed
+105
-9
No files matched your search
@@ -78,6 +78,7 @@ QT_MOC_CPP = \
|
|||||||
qt/moc_transactiondesc.cpp \
|
qt/moc_transactiondesc.cpp \
|
||||||
qt/moc_transactiondescdialog.cpp \
|
qt/moc_transactiondescdialog.cpp \
|
||||||
qt/moc_transactionfilterproxy.cpp \
|
qt/moc_transactionfilterproxy.cpp \
|
||||||
|
qt/moc_transactionoverviewwidget.cpp \
|
||||||
qt/moc_transactiontablemodel.cpp \
|
qt/moc_transactiontablemodel.cpp \
|
||||||
qt/moc_transactionview.cpp \
|
qt/moc_transactionview.cpp \
|
||||||
qt/moc_utilitydialog.cpp \
|
qt/moc_utilitydialog.cpp \
|
||||||
@@ -151,6 +152,7 @@ BITCOIN_QT_H = \
|
|||||||
qt/transactiondesc.h \
|
qt/transactiondesc.h \
|
||||||
qt/transactiondescdialog.h \
|
qt/transactiondescdialog.h \
|
||||||
qt/transactionfilterproxy.h \
|
qt/transactionfilterproxy.h \
|
||||||
|
qt/transactionoverviewwidget.h \
|
||||||
qt/transactionrecord.h \
|
qt/transactionrecord.h \
|
||||||
qt/transactiontablemodel.h \
|
qt/transactiontablemodel.h \
|
||||||
qt/transactionview.h \
|
qt/transactionview.h \
|
||||||
|
|||||||
@@ -504,7 +504,7 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QListView" name="listTransactions">
|
<widget class="TransactionOverviewWidget" name="listTransactions">
|
||||||
<property name="styleSheet">
|
<property name="styleSheet">
|
||||||
<string notr="true">QListView { background: transparent; }</string>
|
<string notr="true">QListView { background: transparent; }</string>
|
||||||
</property>
|
</property>
|
||||||
@@ -517,9 +517,15 @@
|
|||||||
<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>
|
||||||
|
<property name="uniformItemSizes">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
@@ -544,6 +550,13 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>TransactionOverviewWidget</class>
|
||||||
|
<extends>QListView</extends>
|
||||||
|
<header>qt/transactionoverviewwidget.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
+32
-7
@@ -12,6 +12,7 @@
|
|||||||
#include <qt/optionsmodel.h>
|
#include <qt/optionsmodel.h>
|
||||||
#include <qt/platformstyle.h>
|
#include <qt/platformstyle.h>
|
||||||
#include <qt/transactionfilterproxy.h>
|
#include <qt/transactionfilterproxy.h>
|
||||||
|
#include <qt/transactionoverviewwidget.h>
|
||||||
#include <qt/transactiontablemodel.h>
|
#include <qt/transactiontablemodel.h>
|
||||||
#include <qt/walletmodel.h>
|
#include <qt/walletmodel.h>
|
||||||
|
|
||||||
@@ -21,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
|
||||||
|
|
||||||
@@ -34,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,
|
||||||
@@ -67,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)
|
||||||
@@ -94,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) :
|
||||||
@@ -136,7 +161,7 @@ OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent)
|
|||||||
ui->listTransactions->setMinimumHeight(NUM_ITEMS * (DECORATION_SIZE + 2));
|
ui->listTransactions->setMinimumHeight(NUM_ITEMS * (DECORATION_SIZE + 2));
|
||||||
ui->listTransactions->setAttribute(Qt::WA_MacShowFocusRect, false);
|
ui->listTransactions->setAttribute(Qt::WA_MacShowFocusRect, false);
|
||||||
|
|
||||||
connect(ui->listTransactions, &QListView::clicked, this, &OverviewPage::handleTransactionClicked);
|
connect(ui->listTransactions, &TransactionOverviewWidget::clicked, this, &OverviewPage::handleTransactionClicked);
|
||||||
|
|
||||||
// start with displaying the "out of sync" warnings
|
// start with displaying the "out of sync" warnings
|
||||||
showOutOfSyncWarning(true);
|
showOutOfSyncWarning(true);
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
// Copyright (c) 2021 The Bitcoin Core developers
|
||||||
|
// Distributed under the MIT software license, see the accompanying
|
||||||
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#ifndef BITCOIN_QT_TRANSACTIONOVERVIEWWIDGET_H
|
||||||
|
#define BITCOIN_QT_TRANSACTIONOVERVIEWWIDGET_H
|
||||||
|
|
||||||
|
#include <qt/transactiontablemodel.h>
|
||||||
|
|
||||||
|
#include <QListView>
|
||||||
|
#include <QSize>
|
||||||
|
#include <QSizePolicy>
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QShowEvent;
|
||||||
|
class QWidget;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
class TransactionOverviewWidget : public QListView
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit TransactionOverviewWidget(QWidget* parent = nullptr) : QListView(parent) {}
|
||||||
|
|
||||||
|
QSize sizeHint() const override
|
||||||
|
{
|
||||||
|
return {sizeHintForColumn(TransactionTableModel::ToAddress), QListView::sizeHint().height()};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void showEvent(QShowEvent* event) override
|
||||||
|
{
|
||||||
|
Q_UNUSED(event);
|
||||||
|
QSizePolicy sp = sizePolicy();
|
||||||
|
sp.setHorizontalPolicy(QSizePolicy::Minimum);
|
||||||
|
setSizePolicy(sp);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // BITCOIN_QT_TRANSACTIONOVERVIEWWIDGET_H
|
||||||
+16
-1
@@ -106,9 +106,24 @@ void WalletFrame::setCurrentWallet(WalletModel* wallet_model)
|
|||||||
{
|
{
|
||||||
if (mapWalletViews.count(wallet_model) == 0) return;
|
if (mapWalletViews.count(wallet_model) == 0) return;
|
||||||
|
|
||||||
|
// Stop the effect of hidden widgets on the size hint of the shown one in QStackedWidget.
|
||||||
|
WalletView* view_about_to_hide = currentWalletView();
|
||||||
|
if (view_about_to_hide) {
|
||||||
|
QSizePolicy sp = view_about_to_hide->sizePolicy();
|
||||||
|
sp.setHorizontalPolicy(QSizePolicy::Ignored);
|
||||||
|
view_about_to_hide->setSizePolicy(sp);
|
||||||
|
}
|
||||||
|
|
||||||
WalletView *walletView = mapWalletViews.value(wallet_model);
|
WalletView *walletView = mapWalletViews.value(wallet_model);
|
||||||
walletStack->setCurrentWidget(walletView);
|
|
||||||
assert(walletView);
|
assert(walletView);
|
||||||
|
|
||||||
|
// Set or restore the default QSizePolicy which could be set to QSizePolicy::Ignored previously.
|
||||||
|
QSizePolicy sp = walletView->sizePolicy();
|
||||||
|
sp.setHorizontalPolicy(QSizePolicy::Preferred);
|
||||||
|
walletView->setSizePolicy(sp);
|
||||||
|
walletView->updateGeometry();
|
||||||
|
|
||||||
|
walletStack->setCurrentWidget(walletView);
|
||||||
walletView->updateEncryptionStatus();
|
walletView->updateEncryptionStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user