Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PoC] [do not merge]: Support runtime appearance adjustment on macOS #274

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
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