Gui: Use FreeCAD Theme only for FreeCAD stuff

This commit is contained in:
Kacper Donat
2024-08-23 13:14:06 +02:00
committed by wwmayer
parent f09dfa72d0
commit b4923d1c58
3 changed files with 37 additions and 6 deletions

View File

@@ -54,6 +54,8 @@ class BitmapFactoryInstP
public:
QMap<std::string, const char**> xpmMap;
QMap<std::string, QPixmap> 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<ParameterGrp> 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')