mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-28 00:31:28 +02:00
qt: Make PlatformStyle aware of runtime palette change
This change is a prerequisite to support changeable appearance on macOS.
This commit is contained in:
@@ -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
|
||||
|
@@ -21,8 +21,8 @@ public:
|
||||
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 @@ private:
|
||||
bool imagesOnButtons;
|
||||
bool colorizeIcons;
|
||||
bool useExtraSpacing;
|
||||
QColor singleColor;
|
||||
QColor textColor;
|
||||
/* ... more to come later */
|
||||
};
|
||||
|
||||
#endif // BITCOIN_QT_PLATFORMSTYLE_H
|
||||
|
Reference in New Issue
Block a user