commit 8b5f7b4f24e4ede5f6848cafb7f33769396212f6 Author: Juergen Spitzmueller <sp...@lyx.org> Date: Wed Mar 12 11:18:27 2025 +0100
Support darkmode icon subdirectories (cherry picked from commit 171cf982fbeffd66fdadc2e31fc04f4084397f62) --- 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 bb9fa9302c..494a82ab3f 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()); @@ -678,7 +679,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(); @@ -2712,8 +2714,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 c702287635..424046b9f7 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 37e5ed5ba6..d49cca4645 100644 --- a/src/frontends/qt/qt_helpers.cpp +++ b/src/frontends/qt/qt_helpers.cpp @@ -67,10 +67,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 11d7133920..59b5e188b1 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 a2eba83eef..954e68d04b 100644 --- a/src/support/filetools.cpp +++ b/src/support/filetools.cpp @@ -395,11 +395,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 ceb1da62be..c06de4b9b7 100644 --- a/src/support/filetools.h +++ b/src/support/filetools.h @@ -142,7 +142,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 lyx-cvs@lists.lyx.org https://lists.lyx.org/mailman/listinfo/lyx-cvs