From 4530400268bf9a8749513e69a7bfb574fca20f09 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Thu, 3 Aug 2017 14:03:29 -0400 Subject: Cleanup some fallback routines for loading icons from the Qt theme methods. --- src-qt5/core/libLumina/LIconCache.cpp | 13 +++++++++---- src-qt5/core/libLumina/LuminaXDG.cpp | 9 ++++++--- .../lthemeengineplatformtheme.cpp | 21 +++++++++++++++++---- .../lthemeengineplatformtheme.h | 2 +- 4 files changed, 33 insertions(+), 12 deletions(-) (limited to 'src-qt5') diff --git a/src-qt5/core/libLumina/LIconCache.cpp b/src-qt5/core/libLumina/LIconCache.cpp index 9d122df7..bb81bc47 100644 --- a/src-qt5/core/libLumina/LIconCache.cpp +++ b/src-qt5/core/libLumina/LIconCache.cpp @@ -55,9 +55,9 @@ QString LIconCache::findFile(QString icon){ if(icon.isEmpty()){ return ""; } //Get the currently-set theme QString cTheme = QIcon::themeName(); - if(cTheme.isEmpty()){ - QIcon::setThemeName("material-design-light"); - cTheme = "material-design-light"; + if(cTheme.isEmpty()){ + QIcon::setThemeName("material-design-light"); + cTheme = "material-design-light"; } //Make sure the current search paths correspond to this theme if( QDir::searchPaths("icontheme").filter("/"+cTheme+"/").isEmpty() ){ @@ -309,7 +309,12 @@ bool LIconCache::isThemeIcon(QString id){ } QIcon LIconCache::iconFromTheme(QString id){ - return QIcon::fromTheme(id); + QIcon ico = QIcon::fromTheme(id); + if(ico.isNull()){ + //icon missing in theme? run the old icon-finder system + ico = QIcon(findFile(id)); + } + return ico; } // === PRIVATE SLOTS === diff --git a/src-qt5/core/libLumina/LuminaXDG.cpp b/src-qt5/core/libLumina/LuminaXDG.cpp index fed998a2..01b3305e 100644 --- a/src-qt5/core/libLumina/LuminaXDG.cpp +++ b/src-qt5/core/libLumina/LuminaXDG.cpp @@ -747,9 +747,12 @@ void LXDG::setEnvironmentVars(){ QIcon LXDG::findIcon(QString iconName, QString fallback){ //With the addition of the Lumina theme engine (8/3/17), switch back to using the Qt icon from theme method for apps - QIcon tmp = QIcon::fromTheme(iconName); - if(tmp.isNull()){ tmp = QIcon::fromTheme(fallback); } - return tmp; + QIcon tmp; + if(!iconName.contains("libreoffice")){ //libreoffice is stupid - their svg icons are un-renderable with Qt + tmp = QIcon::fromTheme(iconName); + if(tmp.isNull()){ tmp = QIcon::fromTheme(fallback); } + } + if(!tmp.isNull()){ return tmp; } //found one in the theme //NOTE: This was re-written on 11/10/15 to avoid using the QIcon::fromTheme() framework diff --git a/src-qt5/core/lumina-theme-engine/src/lthemeengine-qtplugin/lthemeengineplatformtheme.cpp b/src-qt5/core/lumina-theme-engine/src/lthemeengine-qtplugin/lthemeengineplatformtheme.cpp index 9d6c9bea..453bde1d 100644 --- a/src-qt5/core/lumina-theme-engine/src/lthemeengine-qtplugin/lthemeengineplatformtheme.cpp +++ b/src-qt5/core/lumina-theme-engine/src/lthemeengine-qtplugin/lthemeengineplatformtheme.cpp @@ -70,7 +70,7 @@ QPlatformSystemTrayIcon *lthemeenginePlatformTheme::createPlatformSystemTrayIcon QDBusMenuConnection conn; m_dbusTrayAvailable = conn.isStatusNotifierHostRegistered(); m_checkDBusTray = false; - qCDebug(llthemeengine) << "D-Bus system tray:" << (m_dbusTrayAvailable ? "yes" : "no"); + //qCDebug(llthemeengine) << "D-Bus system tray:" << (m_dbusTrayAvailable ? "yes" : "no"); } return (m_dbusTrayAvailable ? new QDBusTrayIcon() : nullptr); } @@ -177,10 +177,10 @@ void lthemeenginePlatformTheme::readSettings(){ settings.beginGroup("Appearance"); m_style = settings.value("style", "Fusion").toString(); if(settings.value("custom_palette", false).toBool()){ - QString schemePath = settings.value("color_scheme_path").toString(); + QString schemePath = settings.value("color_scheme_path","airy").toString(); m_customPalette = new QPalette(loadColorScheme(schemePath)); } - m_iconTheme = settings.value("icon_theme").toString(); + m_iconTheme = settings.value("icon_theme", "material-design-light").toString(); settings.endGroup(); settings.beginGroup("Fonts"); m_generalFont = settings.value("general", QPlatformTheme::font(QPlatformTheme::SystemFont)).value(); @@ -237,7 +237,20 @@ QString lthemeenginePlatformTheme::loadStyleSheets(const QStringList &paths){ return content; } -QPalette lthemeenginePlatformTheme::loadColorScheme(const QString &filePath){ +QPalette lthemeenginePlatformTheme::loadColorScheme(QString filePath){ + if(!filePath.contains("/") && !filePath.endsWith(".conf") && !filePath.isEmpty()){ + //relative theme name, auto-complete it + QStringList dirs; + dirs << getenv("XDG_CONFIG_HOME"); + dirs << QString(getenv("XDG_CONFIG_DIRS")).split(":"); + dirs << QString(getenv("XDG_DATA_DIRS")).split(":"); + QString relpath = "/lthemeengine/colors/%1.conf"; + relpath = relpath.arg(filePath); + for(int i=0; i