Adjust selection color of delimiter icons

This commit is contained in:
Juergen Spitzmueller 2021-02-07 12:32:11 +01:00
parent f330682a0c
commit fa56a5eb98

View File

@ -90,21 +90,27 @@ struct MathSymbol {
}; };
QPixmap getSelectedPixmap(QPixmap pixmap) QPixmap getSelectedPixmap(QPixmap pixmap, QSize const icon_size)
{ {
QPalette palette = QPalette(); QPalette palette = QPalette();
QColor text_color = (guiApp->isInDarkMode()) QColor text_color = (guiApp->isInDarkMode())
? palette.color(QPalette::Active, QPalette::WindowText) ? palette.color(QPalette::Active, QPalette::WindowText)
: Qt::black; : Qt::black;
QColor highlight_color = palette.color(QPalette::Active, QPalette::HighlightedText); QColor highlight_color = palette.color(QPalette::Active, QPalette::HighlightedText);
QColor highlight_bg = palette.color(QPalette::Active, QPalette::Highlight);
// create a layer with black text turned to QPalette::HighlightedText // create a layer with black text turned to QPalette::HighlightedText
QPixmap hl_overlay(pixmap.size()); QPixmap hl_overlay(pixmap.size());
hl_overlay.fill(highlight_color); hl_overlay.fill(highlight_color);
hl_overlay.setMask(pixmap.createMaskFromColor(text_color, Qt::MaskOutColor)); hl_overlay.setMask(pixmap.createMaskFromColor(text_color, Qt::MaskOutColor));
// Create highlighted background
QPixmap hl_background(icon_size);
hl_background.fill(highlight_bg);
// put layers on top of existing pixmap // put layers on top of existing pixmap
QPainter painter(&pixmap); QPainter painter(&pixmap);
painter.drawPixmap(pixmap.rect(), hl_background);
painter.drawPixmap(pixmap.rect(), hl_overlay); painter.drawPixmap(pixmap.rect(), hl_overlay);
return pixmap; return pixmap;
@ -240,7 +246,7 @@ GuiDelimiter::GuiDelimiter(GuiView & lv)
// get pixmap with bullets // get pixmap with bullets
QPixmap pixmap = getPixmap("images/math/", toqstr(ms.icon), "svgz,png"); QPixmap pixmap = getPixmap("images/math/", toqstr(ms.icon), "svgz,png");
QIcon icon(pixmap); QIcon icon(pixmap);
icon.addPixmap(getSelectedPixmap(pixmap), QIcon::Selected); icon.addPixmap(getSelectedPixmap(pixmap, icon_size), QIcon::Selected);
QListWidgetItem * lwi = new QListWidgetItem(icon, QString()); QListWidgetItem * lwi = new QListWidgetItem(icon, QString());
setDelimiterName(lwi, delim); setDelimiterName(lwi, delim);
left_list_items_[ms.unicode] = lwi; left_list_items_[ms.unicode] = lwi;