From b4923d1c584a4dce794d91a4b090a5293569223a Mon Sep 17 00:00:00 2001 From: Kacper Donat Date: Fri, 23 Aug 2024 13:14:06 +0200 Subject: [PATCH] Gui: Use FreeCAD Theme only for FreeCAD stuff --- src/Gui/BitmapFactory.cpp | 31 +++++++++++++++++++++++++++++++ src/Gui/BitmapFactory.h | 5 +++++ src/Gui/StartupProcess.cpp | 7 +------ 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/Gui/BitmapFactory.cpp b/src/Gui/BitmapFactory.cpp index ddbb8fa2400b..c698f6231d75 100644 --- a/src/Gui/BitmapFactory.cpp +++ b/src/Gui/BitmapFactory.cpp @@ -54,6 +54,8 @@ class BitmapFactoryInstP public: QMap xpmMap; QMap xpmCache; + + bool useIconTheme; }; } @@ -93,7 +95,9 @@ void BitmapFactoryInst::destruct () BitmapFactoryInst::BitmapFactoryInst() { d = new BitmapFactoryInstP; + restoreCustomPaths(); + configureUseIconTheme(); } BitmapFactoryInst::~BitmapFactoryInst() @@ -111,6 +115,14 @@ void BitmapFactoryInst::restoreCustomPaths() } } +void Gui::BitmapFactoryInst::configureUseIconTheme() +{ + Base::Reference group = App::GetApplication().GetParameterGroupByPath + ("User parameter:BaseApp/Preferences/Bitmaps/Theme"); + + d->useIconTheme = group->GetBool("UseIconTheme", group->GetBool("ThemeSearchPaths", false)); +} + void BitmapFactoryInst::addPath(const QString& path) { QDir::addSearchPath(QString::fromLatin1("icons"), path); @@ -174,6 +186,10 @@ bool BitmapFactoryInst::findPixmapInCache(const char* name, QPixmap& px) const QIcon BitmapFactoryInst::iconFromTheme(const char* name, const QIcon& fallback) { + if (!d->useIconTheme) { + return iconFromDefaultTheme(name, fallback); + } + QString iconName = QString::fromUtf8(name); QIcon icon = QIcon::fromTheme(iconName, fallback); if (icon.isNull()) { @@ -206,6 +222,21 @@ bool BitmapFactoryInst::loadPixmap(const QString& filename, QPixmap& icon) const return !icon.isNull(); } +QIcon Gui::BitmapFactoryInst::iconFromDefaultTheme(const char* name, const QIcon& fallback) +{ + QIcon icon; + QPixmap px = pixmap(name); + + if (!px.isNull()) { + icon.addPixmap(px); + return icon; + } else { + return fallback; + } + + return icon; +} + QPixmap BitmapFactoryInst::pixmap(const char* name) const { if (!name || *name == '\0') diff --git a/src/Gui/BitmapFactory.h b/src/Gui/BitmapFactory.h index b17239484cf6..58cfc7372001 100644 --- a/src/Gui/BitmapFactory.h +++ b/src/Gui/BitmapFactory.h @@ -75,6 +75,10 @@ class GuiExport BitmapFactoryInst : public Base::Factory * If no such icon is found in the current theme fallback is returned instead. */ QIcon iconFromTheme(const char* name, const QIcon& fallback = QIcon()); + /** Returns the QIcon corresponding to name in the default (FreeCAD's) icon theme. + * If no such icon is found in the current theme fallback is returned instead. + */ + QIcon iconFromDefaultTheme(const char* name, const QIcon& fallback = QIcon()); /// Retrieves a pixmap by name QPixmap pixmap(const char* name) const; /** Retrieves a pixmap by name and size created by an @@ -150,6 +154,7 @@ class GuiExport BitmapFactoryInst : public Base::Factory private: bool loadPixmap(const QString& path, QPixmap&) const; void restoreCustomPaths(); + void configureUseIconTheme(); static BitmapFactoryInst* _pcSingleton; BitmapFactoryInst(); diff --git a/src/Gui/StartupProcess.cpp b/src/Gui/StartupProcess.cpp index 7b7e131410c5..65f46e9b07bd 100644 --- a/src/Gui/StartupProcess.cpp +++ b/src/Gui/StartupProcess.cpp @@ -178,13 +178,8 @@ void StartupProcess::setThemePaths() QIcon::setThemeSearchPaths(searchPaths); } - // KDE file dialog needs icons from the desktop theme - QIcon::setFallbackThemeName(QIcon::themeName()); - std::string name = hTheme->GetASCII("Name"); - if (name.empty()) { - QIcon::setThemeName(QLatin1String("FreeCAD-default")); - } else { + if (!name.empty()) { QIcon::setThemeName(QString::fromLatin1(name.c_str())); } }