]> git.lyx.org Git - lyx.git/commitdiff
Get rid of Qt resources
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sat, 6 Jun 2020 22:57:40 +0000 (00:57 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sat, 6 Jun 2020 23:15:28 +0000 (01:15 +0200)
It turns out that the resources were mostly not used anyway. Removing
them shrinks LyX binary by ~6MB.

Only autotools have been adapted. cmake will require the same
simplification.

src/frontends/qt/.gitignore
src/frontends/qt/BulletsModule.cpp
src/frontends/qt/GuiApplication.cpp
src/frontends/qt/GuiCompleter.cpp
src/frontends/qt/Makefile.am
src/insets/InsetInfo.cpp
src/mathed/InsetMathNest.cpp

index f487992aaaa05b6aadfec272aefe257b320c35f0..388b16574c8344f433514e541a586912e0d5dd8e 100644 (file)
@@ -1,5 +1,3 @@
-Resources.cpp
-Resources.qrc
 liblyxqt.a
 ui_*.h
 moc_*.cpp
index ba96453eb6a075d5c1a69e5609cf45b144496524..2dca758d127f5e99a06c652516ac08a1fc82d953 100644 (file)
@@ -11,6 +11,7 @@
 #include <config.h>
 
 #include "BulletsModule.h"
+#include "GuiApplication.h"
 #include "qt_helpers.h"
 
 #include <QPixmap>
@@ -64,7 +65,7 @@ void BulletsModule::setupPanel(QListWidget * lw, QString const & panelname,
        bulletpaneCO->addItem(panelname);
 
        // get pixmap with bullets
-       QPixmap pixmap(":/images/" + toqstr(fname) + ".png");
+       QPixmap pixmap = getPixmap("images", toqstr(fname), ".png");
 
        int const w = pixmap.width() / 6;
        int const h = pixmap.height() / 6;
index e9244e1a78303a084805ba4cea670b9a849fd393..d2ff132bc10c68455a8da41f6dfdc602e879597d 100644 (file)
@@ -157,16 +157,6 @@ using namespace std;
 using namespace lyx::support;
 
 
-static void initializeResources()
-{
-       static bool initialized = false;
-       if (!initialized) {
-               Q_INIT_RESOURCE(Resources);
-               initialized = true;
-       }
-}
-
-
 namespace lyx {
 
 frontend::Application * createApplication(int & argc, char * argv[])
@@ -490,7 +480,6 @@ QString themeIconName(QString const & action)
 // the returned bool is true if the icon needs to be flipped
 pair<QString,bool> iconName(FuncRequest const & f, bool unknown, bool rtl)
 {
-       initializeResources();
        QStringList names;
        QString lfunname = toqstr(lyxaction.getActionName(f.action()));
 
@@ -538,36 +527,25 @@ pair<QString,bool> iconName(FuncRequest const & f, bool unknown, bool rtl)
                names << "unknown";
 
        search_mode const mode = theGuiApp()->imageSearchMode();
+       // The folders where icons are searched for
        QStringList imagedirs;
        imagedirs << "images/" << "images/ipa/";
+       // This is used to search for rtl version of icons which have the +rrtl suffix.
        QStringList suffixes;
        if (rtl)
                suffixes << "+rtl";
        suffixes << QString();
+
        for (QString const & imagedir : imagedirs)
                for (QString const & name : names)
                        for (QString const & suffix : suffixes) {
                                QString id = imagedir;
                                FileName fname = imageLibFileSearch(id, name + suffix, "svgz,png", mode);
                                if (fname.exists())
-                                       return make_pair(toqstr(fname.absFileName()), rtl && suffix.isEmpty());
+                                       return make_pair(toqstr(fname.absFileName()),
+                                                        rtl && suffix.isEmpty());
                        }
 
-       QString const resdir(":/images/");
-       QDir res(resdir);
-       if (!res.exists()) {
-               LYXERR0("Directory :/images/ not found in resource!");
-               return make_pair(QString(), false);
-       }
-
-       for (QString const & name : names)
-               for (QString const & suffix : suffixes) {
-                       if (res.exists(name + suffix + ".svgz"))
-                               return make_pair(resdir + name + ".svgz", rtl && suffix.isEmpty());
-                       if (res.exists(name + suffix + ".png"))
-                               return make_pair(resdir + name + ".png", rtl && suffix.isEmpty());
-               }
-
        LYXERR(Debug::GUI, "Cannot find icon for command \""
                           << lyxaction.getActionName(f.action())
                           << '(' << to_utf8(f.argument()) << ")\"");
@@ -583,22 +561,13 @@ QPixmap getPixmap(QString const & path, QString const & name, QString const & ex
        QString fpath = toqstr(fname.absFileName());
        QPixmap pixmap = QPixmap();
 
-       if (pixmap.load(fpath)) {
+       if (pixmap.load(fpath))
                return pixmap;
-       }
-
-       QStringList exts = ext.split(",");
-       fpath = ":/" + path + name + ".";
-       for (int i = 0; i < exts.size(); ++i) {
-               if (pixmap.load(fpath + exts.at(i))) {
-                       return pixmap;
-               }
-       }
 
        bool const list = ext.contains(",");
-       LYXERR0("Cannot load pixmap \""
-               << path << name << "." << (list ? "{" : "") << ext
-               << (list ? "}" : "") << "\", please verify resource system!");
+       LYXERR(Debug::GUI, "Cannot load pixmap \""
+                       << path << "/" << name << "." << (list ? "{" : "") << ext
+               << (list ? "}" : "") << "\".");
 
        return QPixmap();
 }
@@ -630,7 +599,7 @@ QIcon getIcon(FuncRequest const & f, bool unknown, bool rtl)
        //LYXERR(Debug::GUI, "Found icon: " << icon);
        QPixmap pixmap = QPixmap();
        if (!pixmap.load(icon)) {
-               LYXERR0("Cannot load icon " << icon << " please verify resource system!");
+               LYXERR0("Cannot load icon " << icon << ".");
                return QIcon();
        }
 
index 74fe357971da0f4fba805a928738a93576088a01..064049c60bbd614c29e11c9f4b3515aa5fe224b4 100644 (file)
 
 #include "GuiCompleter.h"
 
+#include "GuiApplication.h"
+#include "GuiWorkArea.h"
+#include "GuiView.h"
+#include "qt_helpers.h"
+
 #include "Buffer.h"
 #include "BufferView.h"
 #include "CompletionList.h"
 #include "Cursor.h"
 #include "Dimension.h"
-#include "GuiWorkArea.h"
-#include "GuiView.h"
 #include "LyX.h"
 #include "LyXRC.h"
 #include "Paragraph.h"
-#include "qt_helpers.h"
 #include "version.h"
 
+#include "support/debug.h"
 #include "support/lassert.h"
 #include "support/lstrings.h"
-#include "support/debug.h"
+#include "support/qstring_helpers.h"
 
-#include <QApplication>
 #include <QHeaderView>
 #include <QKeyEvent>
 #include <QPainter>
@@ -137,18 +139,18 @@ public:
 
                // get icon from cache
                QPixmap scaled;
-               QString const name = ":" + toqstr(list_->icon(index.row()));
-               if (name == ":")
+               QString const name = toqstr(list_->icon(index.row()));
+               if (name.isEmpty())
                        return scaled;
-               if (!QPixmapCache::find("completion" + name, &scaled)) {
+               if (!QPixmapCache::find("completion:" + name, &scaled)) {
                        // load icon from disk
-                       QPixmap p = QPixmap(name);
+                       QPixmap p = getPixmap("images", name, "svgz,png");
                        if (!p.isNull()) {
                                // scale it to 16x16 or smaller
                                scaled = p.scaled(min(16, p.width()), min(16, p.height()),
                                        Qt::KeepAspectRatio, Qt::SmoothTransformation);
                        }
-                       QPixmapCache::insert("completion" + name, scaled);
+                       QPixmapCache::insert("completion:" + name, scaled);
                }
                return scaled;
        }
index eb933c71738562b88bcf716e003122e0abbd1c35..e01f8ddba8b2d9a9dbcf7c4fec88e4a578b80983 100644 (file)
@@ -2,7 +2,6 @@ include $(top_srcdir)/config/common.am
 
 BUILT_SOURCES = $(UIFILES:%.ui=ui_%.h)
 BUILT_SOURCES += $(MOCEDFILES)
-BUILT_SOURCES += Resources.cpp Resources.qrc
 
 CLEANFILES = $(BUILT_SOURCES)
 
@@ -23,17 +22,6 @@ QT_VERSION = $(shell IFS=.; set -- `echo $(QTLIB_VERSION)`; \
 moc_%.cpp: %.h
        $(AM_V_GEN)$(QT_MOC) -DQT_VERSION=$(QT_VERSION) -o $@ $<
 
-Resources.qrc: Makefile
-       $(AM_V_GEN)echo "<!DOCTYPE RCC><RCC version='1.0'><qresource>" > $@ ; \
-       find $(top_srcdir)/lib/images -name '*.svgz' -o -name '*.png' -o -name '*.gif' \
-               | LC_ALL=C sort \
-               | sed -e 's:$(top_srcdir)/lib/\(.*\):<file alias="\1">&</file>:' \
-               >> $@ ;\
-       echo "</qresource></RCC>" >> $@
-
-Resources.cpp: Resources.qrc
-       $(AM_V_GEN)$(QT_RCC) $< -name Resources -o $@
-
 
 #########################  LIBRARIES  #############################
 
@@ -367,8 +355,6 @@ UIFILES = \
        WorkAreaUi.ui \
        WrapUi.ui
 
-nodist_liblyxqt_a_SOURCES = Resources.cpp
-
 liblyxqt_a_SOURCES = \
        $(SOURCEFILES) \
        $(MOCHEADER) \
index db64a2d366a7366a207aff1e12d7bd3e59c6b549..b6fc541793d8c1704a1f360299da94329acce483 100644 (file)
@@ -1037,14 +1037,6 @@ void InsetInfo::updateBuffer(ParIterator const & it, UpdateType utype, bool cons
                initialized_ = true;
                FuncRequest func = lyxaction.lookupFunc(params_.name);
                docstring icon_name = frontend::Application::iconName(func, true);
-               // FIXME: We should use the icon directly instead of
-               // going through FileName. The code below won't work
-               // if the icon is embedded in the executable through
-               // the Qt resource system.
-               // This is only a negligible performance problem:
-               // If the installed icon differs from the resource icon the
-               // installed one is preferred anyway, and all icons that are
-               // embedded in the resources are installed as well.
                FileName file(to_utf8(icon_name));
                if (file.onlyFileNameWithoutExt() == "unknown") {
                        string dir = "images";
index 907d7d460807ce3de3e1365ca998e4dfde5ab175..44091f03200496a812da37f2bb694698aa8fca27 100644 (file)
@@ -2180,11 +2180,11 @@ std::string MathCompletionList::icon(size_t idx) const
        else
                cmd = locals[idx];
 
-       // get the icon resource name by stripping the backslash
+       // get the icon name by stripping the backslash
        docstring icon_name = frontend::Application::mathIcon(cmd.substr(1));
        if (icon_name.empty())
                return std::string();
-       return "images/math/" + to_utf8(icon_name);
+       return "math/" + to_utf8(icon_name);
 }
 
 std::vector<docstring> MathCompletionList::globals;