Skip to content

Commit 29ca167

Browse files
committed
Implement decoration scaling for overview page
based on logical DPI.
1 parent c5b6d82 commit 29ca167

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

src/qt/forms/overviewpage.ui

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
<item row="1" column="0">
141141
<widget class="QLabel" name="stakeTextLabel">
142142
<property name="text">
143-
<string>Stake</string>
143+
<string>Stake:</string>
144144
</property>
145145
</widget>
146146
</item>
@@ -163,7 +163,7 @@
163163
<item row="2" column="0">
164164
<widget class="QLabel" name="unconfirmedTextLabel">
165165
<property name="text">
166-
<string>Unconfirmed</string>
166+
<string>Unconfirmed:</string>
167167
</property>
168168
</widget>
169169
</item>

src/qt/overviewpage.cpp

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020
#include <QAbstractItemDelegate>
2121
#include <QPainter>
2222

23-
#define DECORATION_SIZE 64
23+
#define DECORATION_SIZE 48
2424

2525
class TxViewDelegate : public QAbstractItemDelegate
2626
{
2727
Q_OBJECT
2828
public:
29-
TxViewDelegate(QObject *parent=nullptr): QAbstractItemDelegate(parent), unit(BitcoinUnits::BTC)
29+
TxViewDelegate(QObject *parent=nullptr, int scaledDecorationSize = DECORATION_SIZE):
30+
QAbstractItemDelegate(parent), unit(BitcoinUnits::BTC), scaledDecorationSize(scaledDecorationSize)
3031
{
3132

3233
}
@@ -38,8 +39,8 @@ class TxViewDelegate : public QAbstractItemDelegate
3839

3940
QIcon icon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
4041
QRect mainRect = option.rect;
41-
QRect decorationRect(mainRect.topLeft(), QSize(DECORATION_SIZE, DECORATION_SIZE));
42-
int xspace = DECORATION_SIZE + 8;
42+
QRect decorationRect(mainRect.topLeft(), QSize(scaledDecorationSize, scaledDecorationSize));
43+
int xspace = scaledDecorationSize + 8;
4344
int ypad = 6;
4445
int halfheight = (mainRect.height() - 2*ypad)/2;
4546
QRect amountRect(mainRect.left() + xspace, mainRect.top()+ypad, mainRect.width() - xspace, halfheight);
@@ -89,11 +90,15 @@ class TxViewDelegate : public QAbstractItemDelegate
8990

9091
inline QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
9192
{
92-
return QSize(DECORATION_SIZE, DECORATION_SIZE);
93+
return QSize(scaledDecorationSize, scaledDecorationSize);
9394
}
9495

9596
int unit;
9697

98+
private:
99+
100+
int scaledDecorationSize;
101+
97102
};
98103
#include "overviewpage.moc"
99104

@@ -105,14 +110,29 @@ OverviewPage::OverviewPage(QWidget *parent) :
105110
currentBalance(-1),
106111
currentStake(0),
107112
currentUnconfirmedBalance(-1),
108-
currentImmatureBalance(-1),
109-
txdelegate(new TxViewDelegate(this))
113+
currentImmatureBalance(-1)
110114
{
115+
scaledDecorationSize = DECORATION_SIZE * this->logicalDpiX() / 96;
116+
117+
txdelegate = new TxViewDelegate(this, scaledDecorationSize);
118+
111119
ui->setupUi(this);
112120

121+
// Override .ui default spacing to deal with various dpi displays.
122+
int verticalSpacing = 7 * this->logicalDpiY() / 96;
123+
ui->verticalLayout_10->setMargin(verticalSpacing);
124+
ui->formLayout->setVerticalSpacing(verticalSpacing);
125+
ui->formLayout_2->setVerticalSpacing(verticalSpacing);
126+
ui->researcherFormLayout->setVerticalSpacing(verticalSpacing);
127+
128+
QRect verticalSpacerSpacing(0, 0, 20, 20 * this->logicalDpiY() / 96);
129+
ui->verticalSpacer->setGeometry(verticalSpacerSpacing);
130+
ui->researcherSectionVerticalSpacer->setGeometry(verticalSpacerSpacing);
131+
ui->verticalSpacer_2->setGeometry(verticalSpacerSpacing);
132+
113133
// Recent transactions
114134
ui->listTransactions->setItemDelegate(txdelegate);
115-
ui->listTransactions->setIconSize(QSize(DECORATION_SIZE, DECORATION_SIZE));
135+
ui->listTransactions->setIconSize(QSize(scaledDecorationSize, scaledDecorationSize));
116136
ui->listTransactions->setAttribute(Qt::WA_MacShowFocusRect, false);
117137
updateTransactions();
118138

@@ -158,7 +178,7 @@ int OverviewPage::getNumTransactionsForView()
158178
{
159179
// Compute the maximum number of transactions the transaction list widget
160180
// can hold without overflowing.
161-
const size_t itemHeight = DECORATION_SIZE + ui->listTransactions->spacing();
181+
const size_t itemHeight = scaledDecorationSize + ui->listTransactions->spacing();
162182
const size_t contentsHeight = ui->listTransactions->height();
163183
const int numItems = contentsHeight / itemHeight;
164184

src/qt/overviewpage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public slots:
5656
qint64 currentStake;
5757
qint64 currentUnconfirmedBalance;
5858
qint64 currentImmatureBalance;
59+
int scaledDecorationSize;
5960

6061
TxViewDelegate *txdelegate;
6162
std::unique_ptr<TransactionFilterProxy> filter;

0 commit comments

Comments
 (0)