Skip to content

Commit

Permalink
qt: Make PlatformStyle aware of runtime palette change
Browse files Browse the repository at this point in the history
This change is a prerequisite to support changeable appearance on macOS.
  • Loading branch information
hebasto committed Apr 9, 2021
1 parent 4ad83a9 commit 3696ebc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
27 changes: 15 additions & 12 deletions src/qt/platformstyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions src/qt/platformstyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit 3696ebc

Please sign in to comment.