From 458384ab93dc2dc95943bf70c77bf8748e92b662 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Thu, 21 Jan 2021 18:53:49 +0100 Subject: [PATCH] Merge bitcoin-core/gui#176: Fix TxViewDelegate layout af58f5b12cea91467692dd4ae71d8cc916a608ed qt: Stop the effect of hidden widgets on the size of QStackedWidget (Hennadii Stepanov) f0d04795e23606399414d074d78efe5aa0da7259 qt: Fix TxViewDelegate layout (Hennadii Stepanov) d43992140679fb9a5ebc7850923679033f9837f3 qt: 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: ![Screenshot from 2021-01-03 20-23-56](https://user-images.githubusercontent.com/32963518/103486411-6408ca00-4e06-11eb-9c21-627a65e532c1.png) ![Screenshot from 2021-01-03 20-24-47](https://user-images.githubusercontent.com/32963518/103486413-6834e780-4e06-11eb-8221-478d98bbdf69.png) ![Screenshot from 2021-01-03 20-25-27](https://user-images.githubusercontent.com/32963518/103486418-6d923200-4e06-11eb-8625-a4ed3089b6ab.png) ![Screenshot from 2021-01-03 20-33-20](https://user-images.githubusercontent.com/32963518/103486420-708d2280-4e06-11eb-90c2-f2463fb3c4b3.png) ACKs for top commit: dooglus: ACK af58f5b. jarolrod: re-ACK af58f5b12cea91467692dd4ae71d8cc916a608ed Tree-SHA512: 6dae682490ec50fa0335d220bc2d153fa3e6ed578f07c6353a3b180f8f6cf1c2f9e52ebd7b3076f51d7004d86bf5cca14e6b5db9cdf786e85a57a81eacbb4988 --- src/Makefile.qt.include | 2 ++ src/qt/forms/overviewpage.ui | 15 ++++++++++- src/qt/overviewpage.cpp | 28 +++++++++++++++++--- src/qt/transactionoverviewwidget.h | 41 ++++++++++++++++++++++++++++++ src/qt/walletframe.cpp | 17 ++++++++++++- 5 files changed, 97 insertions(+), 6 deletions(-) create mode 100644 src/qt/transactionoverviewwidget.h diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 8ca112d131..885a0e5334 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -87,6 +87,7 @@ QT_MOC_CPP = \ qt/moc_transactiondesc.cpp \ qt/moc_transactiondescdialog.cpp \ qt/moc_transactionfilterproxy.cpp \ + qt/moc_transactionoverviewwidget.cpp \ qt/moc_transactiontablemodel.cpp \ qt/moc_transactionview.cpp \ qt/moc_utilitydialog.cpp \ @@ -164,6 +165,7 @@ BITCOIN_QT_H = \ qt/transactiondesc.h \ qt/transactiondescdialog.h \ qt/transactionfilterproxy.h \ + qt/transactionoverviewwidget.h \ qt/transactionrecord.h \ qt/transactiontablemodel.h \ qt/transactionview.h \ diff --git a/src/qt/forms/overviewpage.ui b/src/qt/forms/overviewpage.ui index 947edb70a2..062be8e6b5 100644 --- a/src/qt/forms/overviewpage.ui +++ b/src/qt/forms/overviewpage.ui @@ -638,7 +638,7 @@ - + QFrame::NoFrame @@ -648,9 +648,15 @@ Qt::ScrollBarAlwaysOff + + QAbstractScrollArea::AdjustToContents + QAbstractItemView::NoSelection + + true + @@ -678,6 +684,13 @@ + + + TransactionOverviewWidget + QListView +
qt/transactionoverviewwidget.h
+
+
diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index c530787b32..16c2a5dfae 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -18,6 +19,8 @@ #include #include +#include +#include #include #include @@ -42,7 +45,7 @@ public: explicit TxViewDelegate(QObject* parent = nullptr) : QAbstractItemDelegate(), unit(BitcoinUnits::DASH) { - + connect(this, &TxViewDelegate::width_changed, this, &TxViewDelegate::sizeHintChanged); } inline void paint(QPainter *painter, const QStyleOptionViewItem &option, @@ -83,7 +86,8 @@ public: qint64 nAmount = index.data(TransactionTableModel::AmountRole).toLongLong(); QString strAmount = BitcoinUnits::floorWithUnit(unit, nAmount, true, BitcoinUnits::SeparatorStyle::ALWAYS); painter->setPen(colorForeground); - painter->drawText(rectTopHalf, Qt::AlignRight | Qt::AlignVCenter, strAmount); + QRect amount_bounding_rect; + painter->drawText(rectTopHalf, Qt::AlignRight | Qt::AlignVCenter, strAmount, &amount_bounding_rect); // Draw second line (with the initial font) // Content: Address/label, Optional Watchonly indicator @@ -93,6 +97,7 @@ public: QString address = indexAddress.data(Qt::DisplayRole).toString(); painter->setPen(colorForeground); painter->drawText(rectBottomHalf, Qt::AlignLeft | Qt::AlignVCenter, address, &rectBounding); + int address_rect_min_width = rectBounding.width(); // Optional Watchonly indicator if (index.data(TransactionTableModel::WatchonlyRole).toBool()) { @@ -101,17 +106,32 @@ public: iconWatchonly.paint(painter, rectWatchonly); } + 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(ITEM_HEIGHT, ITEM_HEIGHT); + const auto search = m_minimum_width.find(index.row()); + const int minimum_text_width = search == m_minimum_width.end() ? 0 : search->second; + return {ITEM_HEIGHT + 8 + minimum_text_width, ITEM_HEIGHT}; } int unit; +Q_SIGNALS: + //! An intermediate signal for emitting from the `paint() const` member function. + void width_changed(const QModelIndex& index) const; + +private: + mutable std::map m_minimum_width; }; + #include OverviewPage::OverviewPage(QWidget* parent) : @@ -151,7 +171,7 @@ OverviewPage::OverviewPage(QWidget* parent) : // Note: minimum height of listTransactions will be set later in updateAdvancedCJUI() to reflect actual settings ui->listTransactions->setAttribute(Qt::WA_MacShowFocusRect, false); - connect(ui->listTransactions, &QListView::clicked, this, &OverviewPage::handleTransactionClicked); + connect(ui->listTransactions, &TransactionOverviewWidget::clicked, this, &OverviewPage::handleTransactionClicked); // init "out of sync" warning labels ui->labelWalletStatus->setText("(" + tr("out of sync") + ")"); diff --git a/src/qt/transactionoverviewwidget.h b/src/qt/transactionoverviewwidget.h new file mode 100644 index 0000000000..2bdead7bc4 --- /dev/null +++ b/src/qt/transactionoverviewwidget.h @@ -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 + +#include +#include +#include + +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 diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index 36eeebaf82..13d5102b92 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -117,9 +117,24 @@ void WalletFrame::setCurrentWallet(WalletModel* wallet_model) { 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); - walletStack->setCurrentWidget(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(); }