Skip to content

Commit 7f653c3

Browse files
author
MarcoFalke
committed
Merge #176: Fix TxViewDelegate layout
af58f5b qt: Stop the effect of hidden widgets on the size of QStackedWidget (Hennadii Stepanov) f0d0479 qt: Fix TxViewDelegate layout (Hennadii Stepanov) d439921 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 bitcoin/bitcoin#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 af58f5b Tree-SHA512: 6dae682490ec50fa0335d220bc2d153fa3e6ed578f07c6353a3b180f8f6cf1c2f9e52ebd7b3076f51d7004d86bf5cca14e6b5db9cdf786e85a57a81eacbb4988
2 parents 53bbbe5 + af58f5b commit 7f653c3

5 files changed

+105
-9
lines changed

src/Makefile.qt.include

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ QT_MOC_CPP = \
7878
qt/moc_transactiondesc.cpp \
7979
qt/moc_transactiondescdialog.cpp \
8080
qt/moc_transactionfilterproxy.cpp \
81+
qt/moc_transactionoverviewwidget.cpp \
8182
qt/moc_transactiontablemodel.cpp \
8283
qt/moc_transactionview.cpp \
8384
qt/moc_utilitydialog.cpp \
@@ -151,6 +152,7 @@ BITCOIN_QT_H = \
151152
qt/transactiondesc.h \
152153
qt/transactiondescdialog.h \
153154
qt/transactionfilterproxy.h \
155+
qt/transactionoverviewwidget.h \
154156
qt/transactionrecord.h \
155157
qt/transactiontablemodel.h \
156158
qt/transactionview.h \

src/qt/forms/overviewpage.ui

+14-1
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@
504504
</layout>
505505
</item>
506506
<item>
507-
<widget class="QListView" name="listTransactions">
507+
<widget class="TransactionOverviewWidget" name="listTransactions">
508508
<property name="styleSheet">
509509
<string notr="true">QListView { background: transparent; }</string>
510510
</property>
@@ -517,9 +517,15 @@
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>
526+
<property name="uniformItemSizes">
527+
<bool>true</bool>
528+
</property>
523529
</widget>
524530
</item>
525531
</layout>
@@ -544,6 +550,13 @@
544550
</item>
545551
</layout>
546552
</widget>
553+
<customwidgets>
554+
<customwidget>
555+
<class>TransactionOverviewWidget</class>
556+
<extends>QListView</extends>
557+
<header>qt/transactionoverviewwidget.h</header>
558+
</customwidget>
559+
</customwidgets>
547560
<resources/>
548561
<connections/>
549562
</ui>

src/qt/overviewpage.cpp

+32-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <qt/optionsmodel.h>
1313
#include <qt/platformstyle.h>
1414
#include <qt/transactionfilterproxy.h>
15+
#include <qt/transactionoverviewwidget.h>
1516
#include <qt/transactiontablemodel.h>
1617
#include <qt/walletmodel.h>
1718

@@ -21,6 +22,9 @@
2122
#include <QPainter>
2223
#include <QStatusTipEvent>
2324

25+
#include <algorithm>
26+
#include <map>
27+
2428
#define DECORATION_SIZE 54
2529
#define NUM_ITEMS 5
2630

@@ -34,7 +38,7 @@ class TxViewDelegate : public QAbstractItemDelegate
3438
QAbstractItemDelegate(parent), unit(BitcoinUnits::BTC),
3539
platformStyle(_platformStyle)
3640
{
37-
41+
connect(this, &TxViewDelegate::width_changed, this, &TxViewDelegate::sizeHintChanged);
3842
}
3943

4044
inline void paint(QPainter *painter, const QStyleOptionViewItem &option,
@@ -67,13 +71,15 @@ class TxViewDelegate : public QAbstractItemDelegate
6771

6872
painter->setPen(foreground);
6973
QRect boundingRect;
70-
painter->drawText(addressRect, Qt::AlignLeft|Qt::AlignVCenter, address, &boundingRect);
74+
painter->drawText(addressRect, Qt::AlignLeft | Qt::AlignVCenter, address, &boundingRect);
75+
int address_rect_min_width = boundingRect.width();
7176

7277
if (index.data(TransactionTableModel::WatchonlyRole).toBool())
7378
{
7479
QIcon iconWatchonly = qvariant_cast<QIcon>(index.data(TransactionTableModel::WatchonlyDecorationRole));
7580
QRect watchonlyRect(boundingRect.right() + 5, mainRect.top()+ypad+halfheight, 16, halfheight);
7681
iconWatchonly.paint(painter, watchonlyRect);
82+
address_rect_min_width += 5 + watchonlyRect.width();
7783
}
7884

7985
if(amount < 0)
@@ -94,23 +100,42 @@ class TxViewDelegate : public QAbstractItemDelegate
94100
{
95101
amountText = QString("[") + amountText + QString("]");
96102
}
97-
painter->drawText(amountRect, Qt::AlignRight|Qt::AlignVCenter, amountText);
103+
104+
QRect amount_bounding_rect;
105+
painter->drawText(amountRect, Qt::AlignRight | Qt::AlignVCenter, amountText, &amount_bounding_rect);
98106

99107
painter->setPen(option.palette.color(QPalette::Text));
100-
painter->drawText(amountRect, Qt::AlignLeft|Qt::AlignVCenter, GUIUtil::dateTimeStr(date));
108+
QRect date_bounding_rect;
109+
painter->drawText(amountRect, Qt::AlignLeft | Qt::AlignVCenter, GUIUtil::dateTimeStr(date), &date_bounding_rect);
110+
111+
const int minimum_width = std::max(address_rect_min_width, amount_bounding_rect.width() + date_bounding_rect.width());
112+
const auto search = m_minimum_width.find(index.row());
113+
if (search == m_minimum_width.end() || search->second != minimum_width) {
114+
m_minimum_width[index.row()] = minimum_width;
115+
Q_EMIT width_changed(index);
116+
}
101117

102118
painter->restore();
103119
}
104120

105121
inline QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
106122
{
107-
return QSize(DECORATION_SIZE, DECORATION_SIZE);
123+
const auto search = m_minimum_width.find(index.row());
124+
const int minimum_text_width = search == m_minimum_width.end() ? 0 : search->second;
125+
return {DECORATION_SIZE + 8 + minimum_text_width, DECORATION_SIZE};
108126
}
109127

110128
int unit;
111-
const PlatformStyle *platformStyle;
112129

130+
Q_SIGNALS:
131+
//! An intermediate signal for emitting from the `paint() const` member function.
132+
void width_changed(const QModelIndex& index) const;
133+
134+
private:
135+
const PlatformStyle* platformStyle;
136+
mutable std::map<int, int> m_minimum_width;
113137
};
138+
114139
#include <qt/overviewpage.moc>
115140

116141
OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent) :
@@ -136,7 +161,7 @@ OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent)
136161
ui->listTransactions->setMinimumHeight(NUM_ITEMS * (DECORATION_SIZE + 2));
137162
ui->listTransactions->setAttribute(Qt::WA_MacShowFocusRect, false);
138163

139-
connect(ui->listTransactions, &QListView::clicked, this, &OverviewPage::handleTransactionClicked);
164+
connect(ui->listTransactions, &TransactionOverviewWidget::clicked, this, &OverviewPage::handleTransactionClicked);
140165

141166
// start with displaying the "out of sync" warnings
142167
showOutOfSyncWarning(true);

src/qt/transactionoverviewwidget.h

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) 2021 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#ifndef BITCOIN_QT_TRANSACTIONOVERVIEWWIDGET_H
6+
#define BITCOIN_QT_TRANSACTIONOVERVIEWWIDGET_H
7+
8+
#include <qt/transactiontablemodel.h>
9+
10+
#include <QListView>
11+
#include <QSize>
12+
#include <QSizePolicy>
13+
14+
QT_BEGIN_NAMESPACE
15+
class QShowEvent;
16+
class QWidget;
17+
QT_END_NAMESPACE
18+
19+
class TransactionOverviewWidget : public QListView
20+
{
21+
Q_OBJECT
22+
23+
public:
24+
explicit TransactionOverviewWidget(QWidget* parent = nullptr) : QListView(parent) {}
25+
26+
QSize sizeHint() const override
27+
{
28+
return {sizeHintForColumn(TransactionTableModel::ToAddress), QListView::sizeHint().height()};
29+
}
30+
31+
protected:
32+
void showEvent(QShowEvent* event) override
33+
{
34+
Q_UNUSED(event);
35+
QSizePolicy sp = sizePolicy();
36+
sp.setHorizontalPolicy(QSizePolicy::Minimum);
37+
setSizePolicy(sp);
38+
}
39+
};
40+
41+
#endif // BITCOIN_QT_TRANSACTIONOVERVIEWWIDGET_H

src/qt/walletframe.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,24 @@ void WalletFrame::setCurrentWallet(WalletModel* wallet_model)
106106
{
107107
if (mapWalletViews.count(wallet_model) == 0) return;
108108

109+
// Stop the effect of hidden widgets on the size hint of the shown one in QStackedWidget.
110+
WalletView* view_about_to_hide = currentWalletView();
111+
if (view_about_to_hide) {
112+
QSizePolicy sp = view_about_to_hide->sizePolicy();
113+
sp.setHorizontalPolicy(QSizePolicy::Ignored);
114+
view_about_to_hide->setSizePolicy(sp);
115+
}
116+
109117
WalletView *walletView = mapWalletViews.value(wallet_model);
110-
walletStack->setCurrentWidget(walletView);
111118
assert(walletView);
119+
120+
// Set or restore the default QSizePolicy which could be set to QSizePolicy::Ignored previously.
121+
QSizePolicy sp = walletView->sizePolicy();
122+
sp.setHorizontalPolicy(QSizePolicy::Preferred);
123+
walletView->setSizePolicy(sp);
124+
walletView->updateGeometry();
125+
126+
walletStack->setCurrentWidget(walletView);
112127
walletView->updateEncryptionStatus();
113128
}
114129

0 commit comments

Comments
 (0)