From 6b2ce65392dc98250e84941370e975048b8afc54 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Thu, 8 Apr 2021 16:14:12 +0300 Subject: [PATCH] qt: Replace base class of ClickableLabel with ThemedLabel This change fixes the GUI when changing appearance on macOS. --- src/qt/bitcoingui.cpp | 18 +++++++++--------- src/qt/guiutil.cpp | 5 +++++ src/qt/guiutil.h | 5 ++++- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 5c3f16aab09..ff5d38fb0aa 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -152,9 +152,9 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformSty unitDisplayControl = new UnitDisplayStatusBarControl(platformStyle); labelWalletEncryptionIcon = new GUIUtil::ThemedLabel(platformStyle); labelWalletHDStatusIcon = new GUIUtil::ThemedLabel(platformStyle); - labelProxyIcon = new GUIUtil::ClickableLabel(); - connectionsControl = new GUIUtil::ClickableLabel(); - labelBlocksIcon = new GUIUtil::ClickableLabel(); + labelProxyIcon = new GUIUtil::ClickableLabel(platformStyle); + connectionsControl = new GUIUtil::ClickableLabel(platformStyle); + labelBlocksIcon = new GUIUtil::ClickableLabel(platformStyle); if(enableWallet) { frameBlocksLayout->addStretch(); @@ -925,7 +925,7 @@ void BitcoinGUI::updateNetworkState() tooltip = QString("") + tooltip + QString(""); 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) @@ -1021,7 +1021,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(".
") + 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) @@ -1047,9 +1047,9 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer tooltip = tr("Catching up...") + QString("
") + 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; @@ -1325,7 +1325,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 enabled: %1").arg(ip_port_q)); } else { labelProxyIcon->show(); diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 3c4f3df89d0..b738d13840c 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -817,6 +817,11 @@ 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()); diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index 31e7aa73355..d3d0ba64cad 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -241,10 +241,13 @@ namespace GUIUtil void updateThemedPixmap(); }; - class ClickableLabel : public QLabel + 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.