diff options
author | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2021-05-28 18:04:50 +0300 |
---|---|---|
committer | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2021-05-28 18:07:44 +0300 |
commit | 123b401e0acf3b26f149711bdf06d7f6eced1968 (patch) | |
tree | 332489bb57cfd42aa4254858ab786d7cf03394f1 /src/qt/guiutil.cpp | |
parent | 8115c2ad7dc87cc37662421875b728ffc29aaffd (diff) | |
parent | c231254a65d390a3350fcef456d57e4a6eca0506 (diff) |
Merge bitcoin-core/gui#275: Support runtime appearance adjustment on macOS
c231254a65d390a3350fcef456d57e4a6eca0506 qt: Make TransactionView aware of runtime palette change (Hennadii Stepanov)
2b622d4aced1848393989ee906b1f9d2436f1c1a qt: Make CoinControlDialog aware of runtime palette change (Hennadii Stepanov)
97a6b5e06a532a4ee029c8ba59c3438369f8b049 qt: Make OverviewPage aware of runtime palette change (Hennadii Stepanov)
d05f1b278d9846de5142a4ac3f53c84145330dd1 qt: Make UnitDisplayStatusBarControl aware of runtime palette change (Hennadii Stepanov)
6b2ce65392dc98250e84941370e975048b8afc54 qt: Replace base class of ClickableLabel with ThemedLabel (Hennadii Stepanov)
ff530a2093c294a1093e1b00fb66ab0a98851c04 qt: Use GUIUtil::ThemedLabel class (Hennadii Stepanov)
d99ef327a885874fed1c4e35e0f47b10290c6bd9 qt: Add GUIUtil::ThemedLabel class (Hennadii Stepanov)
c054720e08b5549913f54b9b4bc4e4002617ff23 qt: Make SignVerifyMessageDialog aware of runtime palette change (Hennadii Stepanov)
0dcc3fac433b341eb6e1d3a2fb4d2de1595e8e88 qt: Make SendCoinsEntry aware of runtime palette change (Hennadii Stepanov)
fa18d28e1242c2948814df1082ee12c2fecf5403 qt: Make RPCConsole aware of runtime palette change (Hennadii Stepanov)
f1083826e3e68803da86af6efba21c4080769b5c qt: Make BitcoinGUI aware of runtime palette change (Hennadii Stepanov)
ce17861dc419b0d1fc1d933000f484dd08bacf5b qt: Make PlatformStyle aware of runtime palette change (Hennadii Stepanov)
Pull request description:
On macOS switching appearance (Light -> Dark or Dark -> Light) when Bitcoin Core is running makes the GUI pretty unusable.
This bug is especially important when a user chose the "Auto" mode to adjust appearance automatically.
This PR fixes Bitcoin Core behavior.
This is an alternative to #268.
ACKs for top commit:
Sjors:
tACK c231254a65d390a3350fcef456d57e4a6eca0506 on macOS 11.4
goums:
ACK c231254a65d390a3350fcef456d57e4a6eca0506
promag:
Tested ACK c231254a65d390a3350fcef456d57e4a6eca0506 on macOS Big Sur arm64.
jarolrod:
tACK c231254a65d390a3350fcef456d57e4a6eca0506
Tree-SHA512: 122dda3e4c9703f68cec60613c536ca59d04c93f2c03398559f2361b8d279ae534800e8e677d94a33e10e769d00be54295a704e98afa2e986a06146b9f164854
Diffstat (limited to 'src/qt/guiutil.cpp')
-rw-r--r-- | src/qt/guiutil.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 55e57d425d..5ff40ae924 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -6,6 +6,7 @@ #include <qt/bitcoinaddressvalidator.h> #include <qt/bitcoinunits.h> +#include <qt/platformstyle.h> #include <qt/qvalidatedlineedit.h> #include <qt/sendcoinsrecipient.h> @@ -61,6 +62,7 @@ #include <QUrlQuery> #include <QtGlobal> +#include <cassert> #include <chrono> #if defined(Q_OS_MAC) @@ -791,6 +793,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()); |