Skip to content

Commit ce17861

Browse files
committed
qt: Make PlatformStyle aware of runtime palette change
This change is a prerequisite to support changeable appearance on macOS.
1 parent d22e7ee commit ce17861

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/qt/platformstyle.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,28 @@ PlatformStyle::PlatformStyle(const QString &_name, bool _imagesOnButtons, bool _
7171
name(_name),
7272
imagesOnButtons(_imagesOnButtons),
7373
colorizeIcons(_colorizeIcons),
74-
useExtraSpacing(_useExtraSpacing),
75-
singleColor(0,0,0),
76-
textColor(0,0,0)
74+
useExtraSpacing(_useExtraSpacing)
75+
{
76+
}
77+
78+
QColor PlatformStyle::TextColor() const
79+
{
80+
return QApplication::palette().color(QPalette::WindowText);
81+
}
82+
83+
QColor PlatformStyle::SingleColor() const
7784
{
78-
// Determine icon highlighting color
7985
if (colorizeIcons) {
8086
const QColor colorHighlightBg(QApplication::palette().color(QPalette::Highlight));
8187
const QColor colorHighlightFg(QApplication::palette().color(QPalette::HighlightedText));
8288
const QColor colorText(QApplication::palette().color(QPalette::WindowText));
8389
const int colorTextLightness = colorText.lightness();
84-
QColor colorbase;
85-
if (abs(colorHighlightBg.lightness() - colorTextLightness) < abs(colorHighlightFg.lightness() - colorTextLightness))
86-
colorbase = colorHighlightBg;
87-
else
88-
colorbase = colorHighlightFg;
89-
singleColor = colorbase;
90+
if (abs(colorHighlightBg.lightness() - colorTextLightness) < abs(colorHighlightFg.lightness() - colorTextLightness)) {
91+
return colorHighlightBg;
92+
}
93+
return colorHighlightFg;
9094
}
91-
// Determine text color
92-
textColor = QColor(QApplication::palette().color(QPalette::WindowText));
95+
return {0, 0, 0};
9396
}
9497

9598
QImage PlatformStyle::SingleColorImage(const QString& filename) const

src/qt/platformstyle.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class PlatformStyle
2121
bool getImagesOnButtons() const { return imagesOnButtons; }
2222
bool getUseExtraSpacing() const { return useExtraSpacing; }
2323

24-
QColor TextColor() const { return textColor; }
25-
QColor SingleColor() const { return singleColor; }
24+
QColor TextColor() const;
25+
QColor SingleColor() const;
2626

2727
/** Colorize an image (given filename) with the icon color */
2828
QImage SingleColorImage(const QString& filename) const;
@@ -43,9 +43,6 @@ class PlatformStyle
4343
bool imagesOnButtons;
4444
bool colorizeIcons;
4545
bool useExtraSpacing;
46-
QColor singleColor;
47-
QColor textColor;
48-
/* ... more to come later */
4946
};
5047

5148
#endif // BITCOIN_QT_PLATFORMSTYLE_H

0 commit comments

Comments
 (0)