Skip to content

Commit

Permalink
Merge 123b401 into merged_master (Bitcoin PR bitcoin-core/gui#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
apoelstra committed Jul 18, 2021
2 parents 95bd11d + 123b401 commit 2645f81
Show file tree
Hide file tree
Showing 18 changed files with 228 additions and 41 deletions.
59 changes: 41 additions & 18 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformSty
frameBlocksLayout->setContentsMargins(3,0,3,0);
frameBlocksLayout->setSpacing(3);
unitDisplayControl = new UnitDisplayStatusBarControl(platformStyle);
labelWalletEncryptionIcon = new QLabel();
labelWalletHDStatusIcon = new QLabel();
labelProxyIcon = new GUIUtil::ClickableLabel();
connectionsControl = new GUIUtil::ClickableLabel();
labelBlocksIcon = new GUIUtil::ClickableLabel();
labelWalletEncryptionIcon = new GUIUtil::ThemedLabel(platformStyle);
labelWalletHDStatusIcon = new GUIUtil::ThemedLabel(platformStyle);
labelProxyIcon = new GUIUtil::ClickableLabel(platformStyle);
connectionsControl = new GUIUtil::ClickableLabel(platformStyle);
labelBlocksIcon = new GUIUtil::ClickableLabel(platformStyle);
if(enableWallet)
{
frameBlocksLayout->addStretch();
Expand Down Expand Up @@ -910,7 +910,7 @@ void BitcoinGUI::updateNetworkState()
tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
connectionsControl->setToolTip(tooltip);

connectionsControl->setPixmap(platformStyle->SingleColorIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
connectionsControl->setThemedPixmap(icon, STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE);
}

void BitcoinGUI::setNumConnections(int count)
Expand Down Expand Up @@ -1006,7 +1006,7 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer
// Set icon state: spinning if catching up, tick otherwise
if (secs < MAX_BLOCK_TIME_GAP) {
tooltip = tr("Up to date") + QString(".<br>") + tooltip;
labelBlocksIcon->setPixmap(platformStyle->SingleColorIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
labelBlocksIcon->setThemedPixmap(QStringLiteral(":/icons/synced"), STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE);

#ifdef ENABLE_WALLET
if(walletFrame)
Expand All @@ -1032,9 +1032,9 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer
tooltip = tr("Catching up…") + QString("<br>") + tooltip;
if(count != prevBlocks)
{
labelBlocksIcon->setPixmap(platformStyle->SingleColorIcon(QString(
":/animation/spinner-%1").arg(spinnerFrame, 3, 10, QChar('0')))
.pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
labelBlocksIcon->setThemedPixmap(
QString(":/animation/spinner-%1").arg(spinnerFrame, 3, 10, QChar('0')),
STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE);
spinnerFrame = (spinnerFrame + 1) % SPINNER_FRAMES;
}
prevBlocks = count;
Expand Down Expand Up @@ -1123,7 +1123,17 @@ void BitcoinGUI::message(const QString& title, QString message, unsigned int sty

void BitcoinGUI::changeEvent(QEvent *e)
{
#ifdef Q_OS_MACOS
if (e->type() == QEvent::PaletteChange) {
overviewAction->setIcon(platformStyle->SingleColorIcon(QStringLiteral(":/icons/overview")));
sendCoinsAction->setIcon(platformStyle->SingleColorIcon(QStringLiteral(":/icons/send")));
receiveCoinsAction->setIcon(platformStyle->SingleColorIcon(QStringLiteral(":/icons/receiving_addresses")));
historyAction->setIcon(platformStyle->SingleColorIcon(QStringLiteral(":/icons/history")));
}
#endif

QMainWindow::changeEvent(e);

#ifndef Q_OS_MAC // Ignored on Mac
if(e->type() == QEvent::WindowStateChange)
{
Expand Down Expand Up @@ -1229,7 +1239,7 @@ bool BitcoinGUI::handlePaymentRequest(const SendCoinsRecipient& recipient)

void BitcoinGUI::setHDStatus(bool privkeyDisabled, int hdEnabled)
{
labelWalletHDStatusIcon->setPixmap(platformStyle->SingleColorIcon(privkeyDisabled ? ":/icons/eye" : hdEnabled ? ":/icons/hd_enabled" : ":/icons/hd_disabled").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
labelWalletHDStatusIcon->setThemedPixmap(privkeyDisabled ? QStringLiteral(":/icons/eye") : hdEnabled ? QStringLiteral(":/icons/hd_enabled") : QStringLiteral(":/icons/hd_disabled"), STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE);
labelWalletHDStatusIcon->setToolTip(privkeyDisabled ? tr("Private key <b>disabled</b>") : hdEnabled ? tr("HD key generation is <b>enabled</b>") : tr("HD key generation is <b>disabled</b>"));
labelWalletHDStatusIcon->show();
// eventually disable the QLabel to set its opacity to 50%
Expand All @@ -1248,15 +1258,15 @@ void BitcoinGUI::setEncryptionStatus(int status)
break;
case WalletModel::Unlocked:
labelWalletEncryptionIcon->show();
labelWalletEncryptionIcon->setPixmap(platformStyle->SingleColorIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
labelWalletEncryptionIcon->setThemedPixmap(QStringLiteral(":/icons/lock_open"), STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE);
labelWalletEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
encryptWalletAction->setChecked(true);
changePassphraseAction->setEnabled(true);
encryptWalletAction->setEnabled(false);
break;
case WalletModel::Locked:
labelWalletEncryptionIcon->show();
labelWalletEncryptionIcon->setPixmap(platformStyle->SingleColorIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
labelWalletEncryptionIcon->setThemedPixmap(QStringLiteral(":/icons/lock_closed"), STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE);
labelWalletEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
encryptWalletAction->setChecked(true);
changePassphraseAction->setEnabled(true);
Expand Down Expand Up @@ -1288,7 +1298,7 @@ void BitcoinGUI::updateProxyIcon()
if (proxy_enabled) {
if (!GUIUtil::HasPixmap(labelProxyIcon)) {
QString ip_port_q = QString::fromStdString(ip_port);
labelProxyIcon->setPixmap(platformStyle->SingleColorIcon(":/icons/proxy").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
labelProxyIcon->setThemedPixmap((":/icons/proxy"), STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE);
labelProxyIcon->setToolTip(tr("Proxy is <b>enabled</b>: %1").arg(ip_port_q));
} else {
labelProxyIcon->show();
Expand Down Expand Up @@ -1413,9 +1423,10 @@ bool BitcoinGUI::isPrivacyModeActivated() const
return m_mask_values_action->isChecked();
}

UnitDisplayStatusBarControl::UnitDisplayStatusBarControl(const PlatformStyle *platformStyle) :
optionsModel(nullptr),
menu(nullptr)
UnitDisplayStatusBarControl::UnitDisplayStatusBarControl(const PlatformStyle *platformStyle)
: optionsModel(nullptr),
menu(nullptr),
m_platform_style{platformStyle}
{
createContextMenu();
setToolTip(tr("Unit to show amounts in. Click to select another unit."));
Expand All @@ -1428,7 +1439,7 @@ UnitDisplayStatusBarControl::UnitDisplayStatusBarControl(const PlatformStyle *pl
}
setMinimumSize(max_width, 0);
setAlignment(Qt::AlignRight | Qt::AlignVCenter);
setStyleSheet(QString("QLabel { color : %1 }").arg(platformStyle->SingleColor().name()));
setStyleSheet(QString("QLabel { color : %1 }").arg(m_platform_style->SingleColor().name()));
}

/** So that it responds to button clicks */
Expand All @@ -1437,6 +1448,18 @@ void UnitDisplayStatusBarControl::mousePressEvent(QMouseEvent *event)
onDisplayUnitsClicked(event->pos());
}

void UnitDisplayStatusBarControl::changeEvent(QEvent* e)
{
#ifdef Q_OS_MACOS
if (e->type() == QEvent::PaletteChange) {
QString style = QString("QLabel { color : %1 }").arg(m_platform_style->SingleColor().name());
if (style != styleSheet()) {
setStyleSheet(style);
}
}
#endif
}

/** Creates context menu, its actions, and wires up all the relevant signals for mouse events. */
void UnitDisplayStatusBarControl::createContextMenu()
{
Expand Down
7 changes: 5 additions & 2 deletions src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <config/bitcoin-config.h>
#endif

#include <qt/guiutil.h>
#include <qt/optionsdialog.h>

#include <amount.h>
Expand Down Expand Up @@ -120,8 +121,8 @@ class BitcoinGUI : public QMainWindow
WalletFrame* walletFrame = nullptr;

UnitDisplayStatusBarControl* unitDisplayControl = nullptr;
QLabel* labelWalletEncryptionIcon = nullptr;
QLabel* labelWalletHDStatusIcon = nullptr;
GUIUtil::ThemedLabel* labelWalletEncryptionIcon = nullptr;
GUIUtil::ThemedLabel* labelWalletHDStatusIcon = nullptr;
GUIUtil::ClickableLabel* labelProxyIcon = nullptr;
GUIUtil::ClickableLabel* connectionsControl = nullptr;
GUIUtil::ClickableLabel* labelBlocksIcon = nullptr;
Expand Down Expand Up @@ -328,10 +329,12 @@ class UnitDisplayStatusBarControl : public QLabel
protected:
/** So that it responds to left-button clicks */
void mousePressEvent(QMouseEvent *event) override;
void changeEvent(QEvent* e) override;

private:
OptionsModel *optionsModel;
QMenu* menu;
const PlatformStyle* m_platform_style;

/** Shows context menu with Display Unit options by the mouse coordinates */
void onDisplayUnitsClicked(const QPoint& point);
Expand Down
9 changes: 9 additions & 0 deletions src/qt/coincontroldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,15 @@ void CoinControlDialog::updateLabels(CCoinControl& m_coin_control, WalletModel *
label->setVisible(nChange < 0);
}

void CoinControlDialog::changeEvent(QEvent* e)
{
#ifdef Q_OS_MACOS
if (e->type() == QEvent::PaletteChange) {
updateView();
}
#endif
}

void CoinControlDialog::updateView()
{
if (!model || !model->getOptionsModel() || !model->getAddressTableModel())
Expand Down
3 changes: 3 additions & 0 deletions src/qt/coincontroldialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class CoinControlDialog : public QDialog
static QList<CAmount> payAmounts;
static bool fSubtractFeeFromAmount;

protected:
void changeEvent(QEvent* e) override;

private:
Ui::CoinControlDialog *ui;
CCoinControl& m_coin_control;
Expand Down
36 changes: 36 additions & 0 deletions src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <qt/bitcoinaddressvalidator.h>
#include <qt/bitcoinunits.h>
#include <qt/platformstyle.h>
#include <qt/qvalidatedlineedit.h>
#include <qt/sendcoinsrecipient.h>

Expand Down Expand Up @@ -63,6 +64,7 @@
#include <QUrlQuery>
#include <QtGlobal>

#include <cassert>
#include <chrono>

#if defined(Q_OS_MAC)
Expand Down Expand Up @@ -859,6 +861,40 @@ qreal calculateIdealFontSize(int width, const QString& text, QFont font, qreal m
return font_size;
}

ThemedLabel::ThemedLabel(const PlatformStyle* platform_style, QWidget* parent)
: QLabel{parent}, m_platform_style{platform_style}
{
assert(m_platform_style);
}

void ThemedLabel::setThemedPixmap(const QString& image_filename, int width, int height)
{
m_image_filename = image_filename;
m_pixmap_width = width;
m_pixmap_height = height;
updateThemedPixmap();
}

void ThemedLabel::changeEvent(QEvent* e)
{
#ifdef Q_OS_MACOS
if (e->type() == QEvent::PaletteChange) {
updateThemedPixmap();
}
#endif
QLabel::changeEvent(e);
}

void ThemedLabel::updateThemedPixmap()
{
setPixmap(m_platform_style->SingleColorIcon(m_image_filename).pixmap(m_pixmap_width, m_pixmap_height));
}

ClickableLabel::ClickableLabel(const PlatformStyle* platform_style, QWidget* parent)
: ThemedLabel{platform_style, parent}
{
}

void ClickableLabel::mouseReleaseEvent(QMouseEvent *event)
{
Q_EMIT clicked(event->pos());
Expand Down
25 changes: 24 additions & 1 deletion src/qt/guiutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <chrono>
#include <utility>

class PlatformStyle;
class QValidatedLineEdit;
class SendCoinsRecipient;

Expand Down Expand Up @@ -242,10 +243,32 @@ namespace GUIUtil

qreal calculateIdealFontSize(int width, const QString& text, QFont font, qreal minPointSize = 4, qreal startPointSize = 14);

class ClickableLabel : public QLabel
class ThemedLabel : public QLabel
{
Q_OBJECT

public:
explicit ThemedLabel(const PlatformStyle* platform_style, QWidget* parent = nullptr);
void setThemedPixmap(const QString& image_filename, int width, int height);

protected:
void changeEvent(QEvent* e) override;

private:
const PlatformStyle* m_platform_style;
QString m_image_filename;
int m_pixmap_width;
int m_pixmap_height;
void updateThemedPixmap();
};

class ClickableLabel : public ThemedLabel
{
Q_OBJECT

public:
explicit ClickableLabel(const PlatformStyle* platform_style, QWidget* parent = nullptr);

Q_SIGNALS:
/** Emitted when the label is clicked. The relative mouse coordinates of the click are
* passed to the signal.
Expand Down
15 changes: 14 additions & 1 deletion src/qt/overviewpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class TxViewDelegate : public QAbstractItemDelegate
{
QIcon iconWatchonly = qvariant_cast<QIcon>(index.data(TransactionTableModel::WatchonlyDecorationRole));
QRect watchonlyRect(boundingRect.right() + 5, mainRect.top()+ypad+halfheight, 16, halfheight);
iconWatchonly = platformStyle->TextColorIcon(iconWatchonly);
iconWatchonly.paint(painter, watchonlyRect);
address_rect_min_width += 5 + watchonlyRect.width();
}
Expand Down Expand Up @@ -141,14 +142,15 @@ OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent)
ui(new Ui::OverviewPage),
clientModel(nullptr),
walletModel(nullptr),
m_platform_style{platformStyle},
txdelegate(new TxViewDelegate(platformStyle, this))
{
ui->setupUi(this);

m_balances.balance[::policyAsset] = -1;

// use a SingleColorIcon for the "out of sync warning" icon
QIcon icon = platformStyle->SingleColorIcon(":/icons/warning");
QIcon icon = m_platform_style->SingleColorIcon(QStringLiteral(":/icons/warning"));
ui->labelTransactionsStatus->setIcon(icon);
ui->labelWalletStatus->setIcon(icon);

Expand Down Expand Up @@ -301,6 +303,17 @@ void OverviewPage::setWalletModel(WalletModel *model)
updateDisplayUnit();
}

void OverviewPage::changeEvent(QEvent* e)
{
#ifdef Q_OS_MACOS
if (e->type() == QEvent::PaletteChange) {
QIcon icon = m_platform_style->SingleColorIcon(QStringLiteral(":/icons/warning"));
ui->labelTransactionsStatus->setIcon(icon);
ui->labelWalletStatus->setIcon(icon);
}
#endif
}

void OverviewPage::updateDisplayUnit()
{
if(walletModel && walletModel->getOptionsModel())
Expand Down
5 changes: 5 additions & 0 deletions src/qt/overviewpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,18 @@ public Q_SLOTS:
void transactionClicked(const QModelIndex &index);
void outOfSyncWarningClicked();

protected:
void changeEvent(QEvent* e) override;

private:
Ui::OverviewPage *ui;
ClientModel *clientModel;
WalletModel *walletModel;
interfaces::WalletBalances m_balances;
bool m_privacy{false};

const PlatformStyle* m_platform_style;

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

Expand Down
Loading

0 comments on commit 2645f81

Please sign in to comment.