[LyX/master] GuiDelimiter: use highlight text color if icon is selected

Juergen Spitzmueller spitz at lyx.org
Sat Feb 6 15:23:41 UTC 2021


commit 5c1a6468ac087bfe8b6b145601138887c5c21980
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Sat Feb 6 16:25:55 2021 +0100

    GuiDelimiter: use highlight text color if icon is selected
---
 src/frontends/qt/GuiDelimiter.cpp |   27 ++++++++++++++++++++++++++-
 1 files changed, 26 insertions(+), 1 deletions(-)

diff --git a/src/frontends/qt/GuiDelimiter.cpp b/src/frontends/qt/GuiDelimiter.cpp
index cc980bc..9043974 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 <QBitmap>
+#include <QPainter>
 #include <QPixmap>
 #include <QCheckBox>
 #include <QListWidgetItem>
@@ -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<std::string, MathSymbol> 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));


More information about the lyx-cvs mailing list