From 5c1a6468ac087bfe8b6b145601138887c5c21980 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Sat, 6 Feb 2021 16:25:55 +0100 Subject: [PATCH] GuiDelimiter: use highlight text color if icon is selected --- src/frontends/qt/GuiDelimiter.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/frontends/qt/GuiDelimiter.cpp b/src/frontends/qt/GuiDelimiter.cpp index cc980bc79c..9043974785 100644 --- a/src/frontends/qt/GuiDelimiter.cpp +++ b/src/frontends/qt/GuiDelimiter.cpp @@ -26,6 +26,8 @@ #include "support/gettext.h" #include "support/lstrings.h" +#include +#include #include #include #include @@ -87,6 +89,27 @@ struct MathSymbol { string icon; }; + +QPixmap getSelectedPixmap(QPixmap pixmap) +{ + QPalette palette = QPalette(); + QColor text_color = (guiApp->isInDarkMode()) + ? palette.color(QPalette::Active, QPalette::WindowText) + : Qt::black; + QColor highlight_color = palette.color(QPalette::Active, QPalette::HighlightedText); + + // create a layer with black text turned to QPalette::HighlightedText + QPixmap hl_overlay(pixmap.size()); + hl_overlay.fill(highlight_color); + hl_overlay.setMask(pixmap.createMaskFromColor(text_color, Qt::MaskOutColor)); + + // put layers on top of existing pixmap + QPainter painter(&pixmap); + painter.drawPixmap(pixmap.rect(), hl_overlay); + + return pixmap; +} + /// TeX-name / Math-symbol map. static map math_symbols_; /// Math-symbol / TeX-name map. @@ -216,7 +239,9 @@ GuiDelimiter::GuiDelimiter(GuiView & lv) MathSymbol const & ms = mathSymbol(delim); // get pixmap with bullets QPixmap pixmap = getPixmap("images/math/", toqstr(ms.icon), "svgz,png"); - QListWidgetItem * lwi = new QListWidgetItem(QIcon(pixmap), QString()); + QIcon icon(pixmap); + icon.addPixmap(getSelectedPixmap(pixmap), QIcon::Selected); + QListWidgetItem * lwi = new QListWidgetItem(icon, QString()); setDelimiterName(lwi, delim); left_list_items_[ms.unicode] = lwi; lwi->setToolTip(toqstr(delim));