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 5c38080296
commit 33cd969280
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')

View File

@@ -75,6 +75,10 @@ public:
* 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 @@ public:
private:
bool loadPixmap(const QString& path, QPixmap&) const;
void restoreCustomPaths();
void configureUseIconTheme();
static BitmapFactoryInst* _pcSingleton;
BitmapFactoryInst();

View File

@@ -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()));
}
}