Skip to content

Commit

Permalink
Gui: Use FreeCAD Theme only for FreeCAD stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
kadet1090 authored and wwmayer committed Sep 14, 2024
1 parent f09dfa7 commit b4923d1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
31 changes: 31 additions & 0 deletions src/Gui/BitmapFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class BitmapFactoryInstP
public:
QMap<std::string, const char**> xpmMap;
QMap<std::string, QPixmap> xpmCache;

bool useIconTheme;
};
}

Expand Down Expand Up @@ -93,7 +95,9 @@ void BitmapFactoryInst::destruct ()
BitmapFactoryInst::BitmapFactoryInst()
{
d = new BitmapFactoryInstP;

restoreCustomPaths();
configureUseIconTheme();
}

BitmapFactoryInst::~BitmapFactoryInst()
Expand All @@ -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);
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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')
Expand Down
5 changes: 5 additions & 0 deletions src/Gui/BitmapFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
7 changes: 1 addition & 6 deletions src/Gui/StartupProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}
Expand Down

0 comments on commit b4923d1

Please sign in to comment.