From 110a58ef222014af7b9eeb8c1fac7f520f3c51f6 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Wed, 7 Apr 2021 09:29:57 +0300 Subject: [PATCH 1/2] qt: Make PlatformStyle aware of runtime palette change This change is a prerequisite to support changeable appearance on macOS. --- src/qt/platformstyle.cpp | 27 +++++++++++++++------------ src/qt/platformstyle.h | 7 ++----- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/qt/platformstyle.cpp b/src/qt/platformstyle.cpp index 1d0605c9030..2257c2ad4f6 100644 --- a/src/qt/platformstyle.cpp +++ b/src/qt/platformstyle.cpp @@ -71,25 +71,28 @@ PlatformStyle::PlatformStyle(const QString &_name, bool _imagesOnButtons, bool _ name(_name), imagesOnButtons(_imagesOnButtons), colorizeIcons(_colorizeIcons), - useExtraSpacing(_useExtraSpacing), - singleColor(0,0,0), - textColor(0,0,0) + useExtraSpacing(_useExtraSpacing) +{ +} + +QColor PlatformStyle::TextColor() const +{ + return QApplication::palette().color(QPalette::WindowText); +} + +QColor PlatformStyle::SingleColor() const { - // Determine icon highlighting color if (colorizeIcons) { const QColor colorHighlightBg(QApplication::palette().color(QPalette::Highlight)); const QColor colorHighlightFg(QApplication::palette().color(QPalette::HighlightedText)); const QColor colorText(QApplication::palette().color(QPalette::WindowText)); const int colorTextLightness = colorText.lightness(); - QColor colorbase; - if (abs(colorHighlightBg.lightness() - colorTextLightness) < abs(colorHighlightFg.lightness() - colorTextLightness)) - colorbase = colorHighlightBg; - else - colorbase = colorHighlightFg; - singleColor = colorbase; + if (abs(colorHighlightBg.lightness() - colorTextLightness) < abs(colorHighlightFg.lightness() - colorTextLightness)) { + return colorHighlightBg; + } + return colorHighlightFg; } - // Determine text color - textColor = QColor(QApplication::palette().color(QPalette::WindowText)); + return {0, 0, 0}; } QImage PlatformStyle::SingleColorImage(const QString& filename) const diff --git a/src/qt/platformstyle.h b/src/qt/platformstyle.h index 53632e56e2e..9df0a1f9854 100644 --- a/src/qt/platformstyle.h +++ b/src/qt/platformstyle.h @@ -21,8 +21,8 @@ class PlatformStyle bool getImagesOnButtons() const { return imagesOnButtons; } bool getUseExtraSpacing() const { return useExtraSpacing; } - QColor TextColor() const { return textColor; } - QColor SingleColor() const { return singleColor; } + QColor TextColor() const; + QColor SingleColor() const; /** Colorize an image (given filename) with the icon color */ QImage SingleColorImage(const QString& filename) const; @@ -43,9 +43,6 @@ class PlatformStyle bool imagesOnButtons; bool colorizeIcons; bool useExtraSpacing; - QColor singleColor; - QColor textColor; - /* ... more to come later */ }; #endif // BITCOIN_QT_PLATFORMSTYLE_H From 0993439ce0840a68e189add369ea8e9f92b5c2c4 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Wed, 7 Apr 2021 09:50:26 +0300 Subject: [PATCH 2/2] qt: Make BitcoinGUI aware of runtime palette change This change fixes the GUI when changing appearance on macOS. --- src/qt/bitcoingui.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 6677c9e3b59..84dd5448828 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -1138,7 +1138,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(":/icons/overview")); + sendCoinsAction->setIcon(platformStyle->SingleColorIcon(":/icons/send")); + receiveCoinsAction->setIcon(platformStyle->SingleColorIcon(":/icons/receiving_addresses")); + historyAction->setIcon(platformStyle->SingleColorIcon(":/icons/history")); + } +#endif + QMainWindow::changeEvent(e); + #ifndef Q_OS_MAC // Ignored on Mac if(e->type() == QEvent::WindowStateChange) {