diff libgui/src/main-window.cc @ 15914:85f9aca30c76

gui: reorganized handling of different icons for dock widgets * main-window.cc(notice-settings): icon set is stored with its short name instead of a number; if no valid value is read from the settings, no special icons are set for the widgets * settings-dialog.cc(settings_dialog): changes for short names of icons; set radio buttom of no special icon per default (if settings value is not value) if value from settings file is invalid; * settings-dialog.cc(write_changes settings): changes for short names of icons * resource-manager.h: remove enum declaration for icon sets
author Torsten <ttl@justmail.de>
date Tue, 08 Jan 2013 21:35:12 +0100
parents 80e99730e5d4
children 6c0fce0632a4
line wrap: on
line diff
--- a/libgui/src/main-window.cc	Sun Jan 06 21:52:29 2013 -0800
+++ b/libgui/src/main-window.cc	Tue Jan 08 21:35:12 2013 +0100
@@ -200,24 +200,15 @@
   delete settingsDialog;
 }
 
+
 void
 main_window::notice_settings ()
 {
-  // FIXME -- was this supposed to be configurable in some way?  If so,
-  // maybe it should be moved back to resource-manager.{h,cc}, but not
-  // as a static variable.
-  static const char *WIDGET_ICON_SET_PREFIX[] =
-    {
-      ":/actions/icons/logo.png",
-      ":/actions/icons/graphic_logo_",
-      ":/actions/icons/letter_logo_"
-    };
-
-  // Set terminal font:
   QSettings *settings = resource_manager::get_settings ();
 
   // FIXME -- what should happen if settings is 0?
 
+  // Set terminal font:
   QFont term_font = QFont();
   term_font.setFamily(settings->value("terminal/fontName").toString());
   term_font.setPointSize(settings->value("terminal/fontSize").toInt ());
@@ -234,8 +225,32 @@
                              cursorBlinking);
 
   // the widget's icons (when floating)
-  int icon_set = settings->value ("DockWidgets/widget_icon_set",0).toInt ();
-  QString icon_prefix = QString (WIDGET_ICON_SET_PREFIX[icon_set]);
+  QString icon_set = settings->value ("DockWidgets/widget_icon_set","NONE").
+                                      toString ();
+  static struct
+    {
+      QString name;
+      QString path;
+    }
+  widget_icon_data[] =
+    { // array of possible icon sets (name, path (complete for NONE))
+      // the first entry here is the default!
+      {"NONE",    ":/actions/icons/logo.png"},
+      {"GRAPHIC", ":/actions/icons/graphic_logo_"},
+      {"LETTER",  ":/actions/icons/letter_logo_"},
+      {"", ""} // end marker has empty name
+    };
+  int count = 0;
+  int icon_set_found = 0; // default
+  while (!widget_icon_data[count].name.isEmpty ())
+    { // while not end of data
+      if (widget_icon_data[count].name == icon_set)
+        { // data of desired icon set found
+          icon_set_found = count;
+          break;
+        }
+      count++;
+    }
   QString icon;
   foreach (QObject *obj, children ())
     {
@@ -243,9 +258,9 @@
       if (obj->inherits("QDockWidget") && ! name.isEmpty ())
         { // if children is a dockwidget with a name
           QDockWidget *widget = qobject_cast<QDockWidget *> (obj);
-          icon = icon_prefix;  // prefix or octave-logo
-          if (icon_set)        // > 0 : each widget has individual icon
-            icon = icon + name + QString(".png");
+          icon = widget_icon_data[icon_set_found].path; // prefix or octave-logo
+          if (widget_icon_data[icon_set_found].name != "NONE")
+            icon = icon + name + ".png"; // add widget name and ext.
           widget->setWindowIcon (QIcon (icon));
         }
     }
@@ -253,6 +268,7 @@
   resource_manager::update_network_settings ();
 }
 
+
 void
 main_window::prepare_for_quit ()
 {