Skip to content

Commit

Permalink
Implement decoration scaling for overview page
Browse files Browse the repository at this point in the history
based on logical DPI.
  • Loading branch information
jamescowens committed Nov 27, 2020
1 parent c5b6d82 commit 4caa7f7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/qt/forms/overviewpage.ui
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
<item row="1" column="0">
<widget class="QLabel" name="stakeTextLabel">
<property name="text">
<string>Stake</string>
<string>Stake:</string>
</property>
</widget>
</item>
Expand All @@ -163,7 +163,7 @@
<item row="2" column="0">
<widget class="QLabel" name="unconfirmedTextLabel">
<property name="text">
<string>Unconfirmed</string>
<string>Unconfirmed:</string>
</property>
</widget>
</item>
Expand Down
32 changes: 23 additions & 9 deletions src/qt/overviewpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
#include <QAbstractItemDelegate>
#include <QPainter>

#define DECORATION_SIZE 64
#define DECORATION_SIZE 48

class TxViewDelegate : public QAbstractItemDelegate
{
Q_OBJECT
public:
TxViewDelegate(QObject *parent=nullptr): QAbstractItemDelegate(parent), unit(BitcoinUnits::BTC)
TxViewDelegate(QObject *parent=nullptr, int scaledDecorationSize = DECORATION_SIZE):
QAbstractItemDelegate(parent), unit(BitcoinUnits::BTC), scaledDecorationSize(scaledDecorationSize)
{

}
Expand All @@ -38,8 +39,8 @@ class TxViewDelegate : public QAbstractItemDelegate

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

inline QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
return QSize(DECORATION_SIZE, DECORATION_SIZE);
return QSize(scaledDecorationSize, scaledDecorationSize);
}

int unit;

private:

int scaledDecorationSize;

};
#include "overviewpage.moc"

Expand All @@ -105,14 +110,23 @@ OverviewPage::OverviewPage(QWidget *parent) :
currentBalance(-1),
currentStake(0),
currentUnconfirmedBalance(-1),
currentImmatureBalance(-1),
txdelegate(new TxViewDelegate(this))
currentImmatureBalance(-1)
{
scaledDecorationSize = DECORATION_SIZE * this->logicalDpiX() / 96;

txdelegate = new TxViewDelegate(this, scaledDecorationSize);

ui->setupUi(this);

// Override .ui default spacing to deal with various dpi displays.
int verticalSpacing = 7 * this->logicalDpiX() / 96;
ui->formLayout->setVerticalSpacing(verticalSpacing);
ui->formLayout_2->setVerticalSpacing(verticalSpacing);
ui->researcherFormLayout->setVerticalSpacing(verticalSpacing);

// Recent transactions
ui->listTransactions->setItemDelegate(txdelegate);
ui->listTransactions->setIconSize(QSize(DECORATION_SIZE, DECORATION_SIZE));
ui->listTransactions->setIconSize(QSize(scaledDecorationSize, scaledDecorationSize));
ui->listTransactions->setAttribute(Qt::WA_MacShowFocusRect, false);
updateTransactions();

Expand Down Expand Up @@ -158,7 +172,7 @@ int OverviewPage::getNumTransactionsForView()
{
// Compute the maximum number of transactions the transaction list widget
// can hold without overflowing.
const size_t itemHeight = DECORATION_SIZE + ui->listTransactions->spacing();
const size_t itemHeight = scaledDecorationSize + ui->listTransactions->spacing();
const size_t contentsHeight = ui->listTransactions->height();
const int numItems = contentsHeight / itemHeight;

Expand Down
1 change: 1 addition & 0 deletions src/qt/overviewpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public slots:
qint64 currentStake;
qint64 currentUnconfirmedBalance;
qint64 currentImmatureBalance;
int scaledDecorationSize;

TxViewDelegate *txdelegate;
std::unique_ptr<TransactionFilterProxy> filter;
Expand Down

0 comments on commit 4caa7f7

Please sign in to comment.