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

SettingsDialog: tweak color aware icons #813

Merged
merged 2 commits into from
Nov 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 22 additions & 7 deletions src/gui/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,17 +358,32 @@ void SettingsDialog::customizeStyle()
}
}

static bool isDarkColor(const QColor &color)
{
// account for different sensitivity of the human eye to certain colors
double treshold = 1.0 - (0.299 * color.red() + 0.587 * color.green() + 0.114 * color.blue()) / 255.0;
return treshold > 0.5;
}

QIcon SettingsDialog::createColorAwareIcon(const QString &name)
{
QColor bg(palette().base().color());
QPalette pal = palette();
QImage img(name);
// account for different sensitivity of the human eye to certain colors
double treshold = 1.0 - (0.299 * bg.red() + 0.587 * bg.green() + 0.114 * bg.blue()) / 255.0;
if (treshold > 0.5) {
img.invertPixels(QImage::InvertRgb);
}
QImage inverted(img);
inverted.invertPixels(QImage::InvertRgb);

return QIcon(QPixmap::fromImage(img));
QIcon icon;
if (isDarkColor(pal.color(QPalette::Base))) {
icon.addPixmap(QPixmap::fromImage(inverted));
} else {
icon.addPixmap(QPixmap::fromImage(img));
}
if (isDarkColor(pal.color(QPalette::HighlightedText))) {
icon.addPixmap(QPixmap::fromImage(img), QIcon::Normal, QIcon::On);
} else {
icon.addPixmap(QPixmap::fromImage(inverted), QIcon::Normal, QIcon::On);
}
return icon;
}

class ToolButtonAction : public QWidgetAction
Expand Down