changeset 30777:439eb9bd4c04

icon fallback concept without QIcon::fallbackSearchPaths (bug #62106) * FigureWindow.cc (FigureWindow): do not use fromTheme * ToolBarButton.cc: include QString and gui-preferences-global.h; (get_icon): do not use fromTheme * gui-preferences-global.h: define QStringList with exisiting icon fallback paths togehter with an enumeration for the list inidices * octave-dock-widget.cc (label_dock_widget): use ressource_manager::icon instead of fromTheme, use constants from gui-preferences for icon paths instead of literal strings in style sheets (make_window): dito (make_widget): dito * resource-manager.cc (resource_manager): initialize m_icon_fallbacks; (config_icon_theme): collect fallback paths in a string list depending on selected icon theme; (icon): test existance of icon in current theme, if not, test the fallback locations; * resource-manager.h: new string list m_icon_fallbacks
author Torsten Lilge <ttl-octave@mailbox.org>
date Thu, 24 Feb 2022 22:16:35 +0100
parents bc390b9d14f9
children 73404743f3de
files libgui/graphics/FigureWindow.cc libgui/graphics/ToolBarButton.cc libgui/src/gui-preferences-global.h libgui/src/octave-dock-widget.cc libgui/src/resource-manager.cc libgui/src/resource-manager.h
diffstat 6 files changed, 60 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/graphics/FigureWindow.cc	Thu Feb 24 17:33:44 2022 +0100
+++ b/libgui/graphics/FigureWindow.cc	Thu Feb 24 22:16:35 2022 +0100
@@ -30,6 +30,7 @@
 #include <QMenu>
 
 #include "FigureWindow.h"
+#include "gui-preferences-global.h"
 
 namespace octave
 {
@@ -38,7 +39,7 @@
     : FigureWindowBase (xparent)
   {
     // set icon from application resources
-    setWindowIcon (QIcon::fromTheme ("graphic_logo_Figure"));
+    setWindowIcon (QIcon (global_icon_fallback_paths.at (ICON_THEME_OCTAVE)));
   }
 
   FigureWindow::~FigureWindow (void)
--- a/libgui/graphics/ToolBarButton.cc	Thu Feb 24 17:33:44 2022 +0100
+++ b/libgui/graphics/ToolBarButton.cc	Thu Feb 24 22:16:35 2022 +0100
@@ -29,11 +29,13 @@
 
 #include <QAction>
 #include <QIcon>
+#include <QString>
 #include <QWidget>
 
 #include "ToolBarButton.h"
 #include "QtHandlesUtils.h"
 #include "octave-qobject.h"
+#include "gui-preferences-global.h"
 
 namespace octave
 {
@@ -155,7 +157,7 @@
   template <typename T>
   QIcon ToolBarButton<T>::get_icon (const std::string& name)
   {
-    return QIcon::fromTheme (QString::fromStdString (name));
+    return QIcon (global_icon_fallback_paths.at (ICON_THEME_OCTAVE) + QString::fromStdString (name) + ".png");
   }
 
 }
--- a/libgui/src/gui-preferences-global.h	Thu Feb 24 17:33:44 2022 +0100
+++ b/libgui/src/gui-preferences-global.h	Thu Feb 24 22:16:35 2022 +0100
@@ -84,6 +84,22 @@
 const gui_pref
 global_icon_theme ("use_system_icon_theme", QVariant (true));
 
+enum
+{
+  ICON_THEME_SYSTEM,
+  ICON_THEME_OCTAVE,
+  ICON_THEME_TANGO,
+  ICON_THEME_CURSORS
+};
+
+const QStringList
+global_icon_fallback_paths (QStringList ()
+                        << ""
+                        << ":/icons/octave/128x128/"
+                        << ":/icons/tango/128x128/"
+                        << ":/cursors/"
+                       );
+
 // Other
 
 const gui_pref
--- a/libgui/src/octave-dock-widget.cc	Thu Feb 24 17:33:44 2022 +0100
+++ b/libgui/src/octave-dock-widget.cc	Thu Feb 24 22:16:35 2022 +0100
@@ -73,11 +73,13 @@
           }
       }
 
+    resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
+
     // the custom (extra) title bar of the widget
     m_title_widget = new QWidget ();
 
     m_dock_action = new QAction
-      (QIcon::fromTheme ("widget-undock"), "", this);
+      (rmgr.icon ("widget-undock"), "", this);
     m_dock_action->setToolTip (tr ("Undock widget"));
     m_dock_button = new QToolButton (m_title_widget);
     m_dock_button->setDefaultAction (m_dock_action);
@@ -85,7 +87,7 @@
     m_dock_button->setIconSize (QSize (m_icon_size, m_icon_size));
 
     m_close_action = new QAction
-      (QIcon::fromTheme ("widget-close"), "", this);
+      (rmgr.icon ("widget-close"), "", this);
     m_close_action->setToolTip (tr ("Close widget"));
     m_close_button = new QToolButton (m_title_widget);
     m_close_button->setDefaultAction (m_close_action);
@@ -233,13 +235,15 @@
 
     m_close_action->setToolTip (tr ("Hide widget"));
 
-    setStyleSheet (qdockwidget_css (QString (":/icons/octave/widget-close.png"),
-                                    QString ("Close widget"),
-                                    QString (":/icons/octave/widget-undock.png"),
-                                    QString ("Undock widget"),
-                                    m_icon_size,
-                                    QString (""),
-                                    QString ("")));
+    setStyleSheet (qdockwidget_css (
+      global_icon_fallback_paths.at (ICON_THEME_OCTAVE) + "widget-close.png",
+      QString ("Close widget"),
+      global_icon_fallback_paths.at (ICON_THEME_OCTAVE) + "widget-undock.png",
+      QString ("Undock widget"),
+      m_icon_size,
+      QString (""),
+      QString ("")));
+
     if (widget ())
       widget ()->setToolTip (QString (""));
 
@@ -311,7 +315,8 @@
     // adjust the (un)dock icon
     if (titleBarWidget ())
       {
-        m_dock_action->setIcon (QIcon::fromTheme ("widget-dock" + m_icon_color));
+        resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
+        m_dock_action->setIcon (rmgr.icon ("widget-dock" + m_icon_color));
         m_dock_action->setToolTip (tr ("Dock widget"));
       }
     else
@@ -369,7 +374,7 @@
              this, &octave_dock_widget::make_window);
     if (titleBarWidget ())
       {
-        m_dock_action->setIcon (QIcon::fromTheme ("widget-undock" + m_icon_color));
+        m_dock_action->setIcon (rmgr.icon ("widget-undock" + m_icon_color));
         m_dock_action->setToolTip (tr ("Undock widget"));
       }
     else
@@ -800,18 +805,19 @@
     QString full_close_icon = "widget-close" + icon_col;
     if (titleBarWidget ())
       {
+        resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
         titleBarWidget ()->setStyleSheet (css_foreground + css_background);
         css_button = QString ("QToolButton {background: transparent; border: 0px;}");
         m_dock_button->setStyleSheet (css_button);
         m_close_button->setStyleSheet (css_button);
-        m_dock_action->setIcon (QIcon::fromTheme (full_dock_icon));
-        m_close_action->setIcon (QIcon::fromTheme (full_close_icon));
+        m_dock_action->setIcon (rmgr.icon (full_dock_icon));
+        m_close_action->setIcon (rmgr.icon (full_close_icon));
       }
     else
       {
-        setStyleSheet (qdockwidget_css (":/icons/octave/" + full_close_icon + ".png",
+        setStyleSheet (qdockwidget_css (global_icon_fallback_paths.at (ICON_THEME_OCTAVE) + full_close_icon + ".png",
                                         close_tooltip,
-                                        ":/icons/octave/" + full_dock_icon + ".png",
+                                        global_icon_fallback_paths.at (ICON_THEME_OCTAVE) + full_dock_icon + ".png",
                                         dock_tooltip,
                                         m_icon_size,
                                         css_foreground,
--- a/libgui/src/resource-manager.cc	Thu Feb 24 17:33:44 2022 +0100
+++ b/libgui/src/resource-manager.cc	Thu Feb 24 22:16:35 2022 +0100
@@ -67,7 +67,7 @@
 {
   resource_manager::resource_manager (void)
     : m_settings_directory (), m_settings_file (), m_settings (nullptr),
-      m_default_settings (nullptr), m_temporary_files ()
+      m_default_settings (nullptr), m_temporary_files (), m_icon_fallbacks ()
   {
     // Let gui_settings decide where to put the ini file with gui preferences
     m_default_settings
@@ -187,34 +187,23 @@
 
   void resource_manager::config_icon_theme (void)
   {
-#if (QT_VERSION >= 0x051100)
-    QStringList fallbacks (QIcon::fallbackSearchPaths ());
-#else
-    QStringList fallbacks;
-#endif
-
+     m_icon_fallbacks.clear ();
 // FIXME: update fallbacks depending on selection (tango, octave or system)
 // Can cursor be moce to :/cursor and added as search path
 // By this, we can generate the list of themes from the :/icons dir?
 
-
-
     if (m_settings && (! m_settings->value (global_icon_theme).toBool ()))
       {
         QIcon::setThemeName ("tango");
-        fallbacks << ":/icons/octave/128x128";
+        m_icon_fallbacks << global_icon_fallback_paths.at (ICON_THEME_OCTAVE);
       }
     else
       {
         QIcon::setThemeName ("");
-        fallbacks << ":/icons/octave/128x128";
+        m_icon_fallbacks << global_icon_fallback_paths.at (ICON_THEME_OCTAVE);
       }
 
-    fallbacks << ":/cursors";
-
-#if (QT_VERSION >= 0x051100)
-    QIcon::setFallbackSearchPaths (fallbacks);
-#endif
+    m_icon_fallbacks << global_icon_fallback_paths.at (ICON_THEME_CURSORS);
   }
 
   gui_settings * resource_manager::get_settings (void) const
@@ -615,7 +604,17 @@
 
   QIcon resource_manager::icon (const QString& icon_name, bool)
   {
-      return QIcon::fromTheme (icon_name);
+    if (QIcon::hasThemeIcon (icon_name))
+      return QIcon (QIcon::fromTheme (icon_name));
+
+    for (int i = 0; i < m_icon_fallbacks.length (); i++ )
+      {
+        QString icon_file (m_icon_fallbacks.at (i) + icon_name + ".png");
+        if (QFile (icon_file).exists ())
+          return QIcon (icon_file);
+      }
+
+      return QIcon ();
   }
 
   // get a list of all available encodings
--- a/libgui/src/resource-manager.h	Thu Feb 24 17:33:44 2022 +0100
+++ b/libgui/src/resource-manager.h	Thu Feb 24 22:16:35 2022 +0100
@@ -123,6 +123,8 @@
     gui_settings *m_default_settings;
 
     QList<QTemporaryFile *> m_temporary_files;
+
+    QStringList m_icon_fallbacks;
   };
 }