commit 171cf982fbeffd66fdadc2e31fc04f4084397f62
Author: Juergen Spitzmueller <[email protected]>
Date: Wed Mar 12 11:18:27 2025 +0100
Support darkmode icon subdirectories
---
src/frontends/qt/GuiApplication.cpp | 9 ++++++---
src/frontends/qt/GuiSearch.cpp | 20 +++++++++++++++-----
src/frontends/qt/GuiToolbar.cpp | 4 ++--
src/frontends/qt/qt_helpers.cpp | 6 ++++--
src/frontends/qt/qt_helpers.h | 3 ++-
src/support/filetools.cpp | 9 +++++++--
src/support/filetools.h | 3 ++-
7 files changed, 38 insertions(+), 16 deletions(-)
diff --git a/src/frontends/qt/GuiApplication.cpp
b/src/frontends/qt/GuiApplication.cpp
index 0cf0419536..367da8b652 100644
--- a/src/frontends/qt/GuiApplication.cpp
+++ b/src/frontends/qt/GuiApplication.cpp
@@ -604,6 +604,7 @@ IconInfo iconInfo(FuncRequest const & f, bool unknown, bool
rtl)
names << "unknown";
search_mode const mode = theGuiApp() ? theGuiApp()->imageSearchMode() :
support::must_exist;
+ bool const dark_mode = theGuiApp() ? theGuiApp()->isInDarkMode() :
false;
// The folders where icons are searched for
QStringList imagedirs;
imagedirs << "images/ipa/" << "images/";
@@ -617,7 +618,7 @@ IconInfo iconInfo(FuncRequest const & f, bool unknown, bool
rtl)
for (QString const & name : names)
for (QString const & suffix : suffixes) {
QString id = imagedir;
- FileName fname = imageLibFileSearch(id, name +
suffix, "svgz,png", mode);
+ FileName fname = imageLibFileSearch(id, name +
suffix, "svgz,png", mode, dark_mode);
if (fname.exists()) {
docstring const fpath =
fname.absoluteFilePath();
res.filepath =
toqstr(fname.absFileName());
@@ -680,7 +681,8 @@ QPixmap prepareForDarkMode(QPixmap pixmap)
QPixmap getPixmap(QString const & path, QString const & name, QString const &
ext)
{
QString imagedir = path;
- FileName fname = imageLibFileSearch(imagedir, name, ext,
theGuiApp()->imageSearchMode());
+ FileName fname = imageLibFileSearch(imagedir, name, ext,
theGuiApp()->imageSearchMode(),
+ theGuiApp()->isInDarkMode());
QString fpath = toqstr(fname.absFileName());
QPixmap pixmap = QPixmap();
@@ -2679,8 +2681,9 @@ QPixmap GuiApplication::getScaledPixmap(QString imagedir,
QString name) const
dpr = currentView()->pixelRatio();
// We render SVG directly for HiDPI scalability
QPixmap pm = getPixmap(imagedir, name, "svgz,png");
- FileName fname = imageLibFileSearch(imagedir, name, "svgz,png");
+ search_mode const mode = theGuiApp() ? theGuiApp()->imageSearchMode() :
support::must_exist;
bool const dark_mode = theGuiApp() ? theGuiApp()->isInDarkMode() :
false;
+ FileName fname = imageLibFileSearch(imagedir, name, "svgz,png", mode,
dark_mode);
QString fpath = toqstr(fname.absFileName());
if (!fpath.isEmpty() && !fpath.endsWith(".png")) {
QSvgRenderer svgRenderer(fpath);
diff --git a/src/frontends/qt/GuiSearch.cpp b/src/frontends/qt/GuiSearch.cpp
index 92297d07e4..975083a167 100644
--- a/src/frontends/qt/GuiSearch.cpp
+++ b/src/frontends/qt/GuiSearch.cpp
@@ -266,7 +266,9 @@ void GuiSearchWidget::handleIndicators()
tip += "<li>" + qt_("Case sensitive search");
QPixmap spixmap = getPixmap("images/",
"search-case-sensitive", "svgz,png");
// We render SVG directly for HiDPI scalability
- FileName fname = imageLibFileSearch(imagedir,
"search-case-sensitive", "svgz,png");
+ FileName fname = imageLibFileSearch(imagedir,
"search-case-sensitive", "svgz,png",
+
theGuiApp()->imageSearchMode(),
+
theGuiApp()->isInDarkMode());
QString fpath = toqstr(fname.absFileName());
if (!fpath.isEmpty()) {
QSvgRenderer svgRenderer(fpath);
@@ -292,7 +294,9 @@ void GuiSearchWidget::handleIndicators()
if (selectionCB->isChecked()) {
tip += "<li>" + qt_("Search only in selection");
QPixmap spixmap = getPixmap("images/",
"search-selection", "svgz,png");
- FileName fname = imageLibFileSearch(imagedir,
"search-selection", "svgz,png");
+ FileName fname = imageLibFileSearch(imagedir,
"search-selection", "svgz,png",
+
theGuiApp()->imageSearchMode(),
+
theGuiApp()->isInDarkMode());
QString fpath = toqstr(fname.absFileName());
if (!fpath.isEmpty()) {
QSvgRenderer svgRenderer(fpath);
@@ -305,7 +309,9 @@ void GuiSearchWidget::handleIndicators()
if (instantSearchCB->isChecked()) {
tip += "<li>" + qt_("Search as you type");
QPixmap spixmap = getPixmap("images/",
"search-instant", "svgz,png");
- FileName fname = imageLibFileSearch(imagedir,
"search-instant", "svgz,png");
+ FileName fname = imageLibFileSearch(imagedir,
"search-instant", "svgz,png",
+
theGuiApp()->imageSearchMode(),
+
theGuiApp()->isInDarkMode());
QString fpath = toqstr(fname.absFileName());
if (!fpath.isEmpty()) {
QSvgRenderer svgRenderer(fpath);
@@ -318,7 +324,9 @@ void GuiSearchWidget::handleIndicators()
if (wrapCB->isChecked()) {
tip += "<li>" + qt_("Wrap search");
QPixmap spixmap = getPixmap("images/",
"search-wrap", "svgz,png");
- FileName fname = imageLibFileSearch(imagedir,
"search-wrap", "svgz,png");
+ FileName fname = imageLibFileSearch(imagedir,
"search-wrap", "svgz,png",
+
theGuiApp()->imageSearchMode(),
+
theGuiApp()->isInDarkMode());
QString fpath = toqstr(fname.absFileName());
if (!fpath.isEmpty()) {
QSvgRenderer svgRenderer(fpath);
@@ -334,7 +342,9 @@ void GuiSearchWidget::handleIndicators()
} else {
tip = qt_("Click here to change search options");
// We render SVG directly for HiDPI scalability
- FileName fname = imageLibFileSearch(imagedir,
"search-options", "svgz,png");
+ FileName fname = imageLibFileSearch(imagedir,
"search-options", "svgz,png",
+
theGuiApp()->imageSearchMode(),
+
theGuiApp()->isInDarkMode());
QString fpath = toqstr(fname.absFileName());
if (!fpath.isEmpty()) {
QSvgRenderer svgRenderer(fpath);
diff --git a/src/frontends/qt/GuiToolbar.cpp b/src/frontends/qt/GuiToolbar.cpp
index ba12442414..76b6853d4a 100644
--- a/src/frontends/qt/GuiToolbar.cpp
+++ b/src/frontends/qt/GuiToolbar.cpp
@@ -248,9 +248,9 @@ MenuButtonBase::MenuButtonBase(GuiToolbar * bar,
ToolbarItem const & item)
for (int i = 0; i < imagedirs.size(); ++i) {
QString imagedir = imagedirs.at(i);
FileName const fname = imageLibFileSearch(imagedir, name,
"svgz,png",
- theGuiApp()->imageSearchMode());
+ theGuiApp()->imageSearchMode(),
theGuiApp()->isInDarkMode());
if (fname.exists()) {
- setIcon(QIcon(getPixmap(imagedir, name, "svgz,png")));
+ setIcon(QIcon(toqstr(fname.absFileName())));
break;
}
}
diff --git a/src/frontends/qt/qt_helpers.cpp b/src/frontends/qt/qt_helpers.cpp
index e03da21fea..f21f93bd3d 100644
--- a/src/frontends/qt/qt_helpers.cpp
+++ b/src/frontends/qt/qt_helpers.cpp
@@ -70,10 +70,12 @@ FileName libFileSearch(QString const & dir, QString const &
name,
FileName imageLibFileSearch(QString & dir, QString const & name,
- QString const & ext, search_mode mode)
+ QString const & ext, search_mode mode,
+ bool const dark_mode)
{
string tmp = fromqstr(dir);
- FileName fn = support::imageLibFileSearch(tmp, fromqstr(name),
fromqstr(ext), mode);
+ FileName fn = support::imageLibFileSearch(tmp, fromqstr(name),
fromqstr(ext),
+ mode, dark_mode);
dir = toqstr(tmp);
return fn;
}
diff --git a/src/frontends/qt/qt_helpers.h b/src/frontends/qt/qt_helpers.h
index b8eb11c7e5..ea606f8a96 100644
--- a/src/frontends/qt/qt_helpers.h
+++ b/src/frontends/qt/qt_helpers.h
@@ -118,7 +118,8 @@ support::FileName libFileSearch(QString const & dir,
QString const & name,
///
support::FileName imageLibFileSearch(QString & dir, QString const & name,
QString const & ext = QString(),
- support::search_mode mode =
support::must_exist);
+ support::search_mode mode = support::must_exist,
+ bool dark_mode = false);
/** Build filelists of all available bst/cls/sty-files. Done through
* kpsewhich and an external script, saved in *Files.lst.
diff --git a/src/support/filetools.cpp b/src/support/filetools.cpp
index 3bdeb8e1e1..f8eab61f7c 100644
--- a/src/support/filetools.cpp
+++ b/src/support/filetools.cpp
@@ -394,11 +394,16 @@ FileName const i18nLibFileSearch(string const & dir,
string const & name,
FileName const imageLibFileSearch(string & dir, string const & name,
- string const & ext, search_mode mode)
+ string const & ext, search_mode mode, bool const dark_mode)
{
if (!lyx::lyxrc.icon_set.empty()) {
string const imagedir = addPath(dir, lyx::lyxrc.icon_set);
- FileName const fn = libFileSearch(imagedir, name, ext, mode);
+ // In dark mode, try "darkmode" subdirectory first
+ string const darkimagedir = addPath(imagedir, "darkmode");
+ FileName fn = dark_mode ? libFileSearch(darkimagedir, name,
ext, mode)
+ : libFileSearch(imagedir, name, ext,
mode);
+ if (!fn.exists() && dark_mode)
+ fn = libFileSearch(imagedir, name, ext, mode);
if (fn.exists()) {
dir = imagedir;
return fn;
diff --git a/src/support/filetools.h b/src/support/filetools.h
index 14aea9c216..4e6e9e3dae 100644
--- a/src/support/filetools.h
+++ b/src/support/filetools.h
@@ -141,7 +141,8 @@ i18nLibFileSearch(std::string const & dir,
FileName const
imageLibFileSearch(std::string & dir, std::string const & name,
std::string const & ext = std::string(),
- search_mode mode = must_exist);
+ search_mode mode = must_exist,
+ bool dark_mode = false);
/// How to quote a filename
enum quote_style {
--
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs