diff libgui/src/main-window.cc @ 15552:bbbb89cc338f

make a floating widget behave like a normal window (bug #37190) * main-window.cc: save and recover the floating- and visible-state of each dock-widget in write_settings() and read_settings(); change window-flag to window if widget is floating at start-up * documentation-dockwidget.cc/.h, files-dockwidget.cc/.h, history-dockwodget.cc/.h, file-editor.cc/.h, terminal-dockwidget.cc/.h, workspace-view.cc/.h: implement slot for signal topLevelChanged where window-flag is changed from widget into window when widget is floating; change icon of all widgets to octave logo
author Torsten <ttl@justmail.de>
date Sat, 20 Oct 2012 17:43:35 +0200
parents ded4ce76ee7a
children 204cafff778c
line wrap: on
line diff
--- a/libgui/src/main-window.cc	Fri Oct 19 17:11:55 2012 -0400
+++ b/libgui/src/main-window.cc	Sat Oct 20 17:43:35 2012 +0200
@@ -397,15 +397,20 @@
 
   restoreState (settings->value ("MainWindow/windowState").toByteArray ());
   settings->beginGroup ("DockWidgets");
-  // restoring the geometry of all widgets
+  // restoring the geometry of all dock-widgets
   foreach (QObject *obj, children ())
     {
       QString name = obj->objectName ();
-      if (obj->isWidgetType () && ! name.isEmpty ())
+      if (obj->inherits("QDockWidget") && ! name.isEmpty ())
         {
-          QWidget *widget = qobject_cast<QWidget *> (obj);
+          QDockWidget *widget = qobject_cast<QDockWidget *> (obj);
           QVariant val = settings->value (name);
           widget->restoreGeometry (val.toByteArray ());
+          bool floating = settings->value (name+"Floating",false).toBool ();
+          bool visible = settings->value (name+"Visible",true).toBool ();
+          if (floating)
+            widget->setWindowFlags (Qt::Window); // if floating, make window from widget
+          widget->setVisible (visible);          // make widget visible if desired (setWindowFlags hides widget)
         }
     }
   settings->endGroup();
@@ -427,20 +432,25 @@
   // FIXME -- what should happen if settings is 0?
 
   settings->setValue ("MainWindow/geometry", saveGeometry ());
-  settings->setValue ("MainWindow/windowState", saveState ());
   settings->beginGroup ("DockWidgets");
   // saving the geometry of all widgets
   foreach (QObject *obj, children())
     {
       QString name = obj->objectName ();
-      if (obj->isWidgetType () && ! name.isEmpty ())
+      if (obj->inherits ("QDockWidget") && ! name.isEmpty ())
         {
-          QWidget *widget = qobject_cast<QWidget *>(obj);
+          QDockWidget *widget = qobject_cast<QDockWidget *> (obj);
           settings->setValue (name, widget->saveGeometry ());
-        }
+          bool floating = widget->isFloating ();
+          bool visible = widget->isVisible ();
+          settings->setValue (name+"Floating",floating);  // store floating state
+          settings->setValue (name+"Visible",visible);    // store visibility
+          if (floating)
+            widget->setWindowFlags(Qt::Widget); // if floating, recover the widget state such that the widget's
+        }                                       // state is correctly saved by the saveSate () below
     }
-
   settings->endGroup();
+  settings->setValue ("MainWindow/windowState", saveState ());
   // write the list of recent used directories
   QStringList curr_dirs;
   for (int i=0; i<_current_directory_combo_box->count (); i++)