diff libgui/src/octave-dock-widget.cc @ 17899:14c427b5c5c1

Restore geometry of floating widgets after restart in windows (bug #40485) * main-window.cc(set_window_layout): non-window systems: restore geometry of all non-floating widgets, make widgets floating after restoring main window * octave_dock_widget.h: new class variable for floating state * octave_dock_widget.cc(constructor): initialize floating to false; (destructor): use this new state variable for saving settings; (make_window): store last docked geometry, set last floating geometry with setGeometry instead of restoreGeometry, set floating state true; (make_widget): save last geometry with geometry only, restore last docked geometry, set floating state false; (change_floating): determine necessary action from floating state;
author Torsten <ttl@justmail.de>
date Mon, 11 Nov 2013 07:32:19 +0100
parents 86c6ae5f969e
children b602014eeb54
line wrap: on
line diff
--- a/libgui/src/octave-dock-widget.cc	Mon Nov 11 01:49:57 2013 -0500
+++ b/libgui/src/octave-dock-widget.cc	Mon Nov 11 07:32:19 2013 +0100
@@ -38,6 +38,7 @@
 {
 
   _parent = static_cast<QMainWindow *> (p);     // store main window
+  _floating = false;
 
   connect (this, SIGNAL (visibilityChanged (bool)),
            this, SLOT (handle_visibility_changed (bool)));
@@ -104,25 +105,20 @@
 octave_dock_widget::~octave_dock_widget ()
 {
   // save state of this dock-widget
-  bool floating = false;
-  bool visible;
   QString name = objectName ();
   QSettings *settings = resource_manager::get_settings ();
 
   settings->beginGroup ("DockWidgets");
 
-  if (!parent ())
-    {
-      // widget is floating (windows), save actual floating geometry
-      floating = true;
-      settings->setValue (name+"_floating_geometry", saveGeometry ());
-    }
-  else  // not floating save docked (normal) geometry
+#if defined (Q_OS_WIN32)
+  if (_floating) // widget is floating (windows), save actual floating geometry
+    settings->setValue (name+"_floating_geometry", geometry ());
+  else           // not floating save docked (normal) geometry
+#endif
     settings->setValue (name, saveGeometry ());
 
-  visible = isVisible ();
-  settings->setValue (name+"Floating", floating);  // store floating state
-  settings->setValue (name+"Visible", visible);    // store visibility
+  settings->setValue (name+"Visible", isVisible ()); // store visibility
+  settings->setValue (name+"Floating", _floating);    // store visibility
 
   settings->endGroup ();
   settings->sync ();
@@ -161,10 +157,11 @@
 
   QSettings *settings = resource_manager::get_settings ();
 
-  // save the docking area for later redocking
+  // save the docking area and geometry for later redocking
   // FIXME: dockWidgetArea always returns 2
   settings->setValue ("DockWidgets/" + objectName () + "_dock_area",
                       _parent->dockWidgetArea (this));
+  settings->setValue ("DockWidgets/" + objectName (), saveGeometry ());
   settings->sync ();
 
   // remove parent and adjust the (un)dock icon
@@ -172,9 +169,9 @@
   _dock_action->setIcon (QIcon (":/actions/icons/widget-dock.png"));
   _dock_action->setToolTip (tr ("Dock widget"));
 
-  // restore the last geometry when floating
-  restoreGeometry (settings->value ("DockWidgets/" + objectName ()
-                                    + "_floating_geometry").toByteArray ());
+  // restore the last geometry( when floating
+  setGeometry (settings->value ("DockWidgets/" + objectName ()
+                       + "_floating_geometry",QRect(50,100,480,480)).toRect ());
 
 #else
 
@@ -183,6 +180,7 @@
 
 #endif
 
+  _floating = true;
 }
 
 // dock the widget
@@ -195,9 +193,10 @@
 
   QSettings *settings = resource_manager::get_settings ();
 
-  // save last floating geometry
-  settings->setValue ("DockWidgets/" + objectName () + "_floating_geometry",
-                      saveGeometry ());
+  // save last floating geometry if widget really was floating
+  if (_floating)
+    settings->setValue ("DockWidgets/" + objectName () + "_floating_geometry",
+                        geometry ());
   settings->sync ();
 
   if (dock)
@@ -209,8 +208,8 @@
 
       // FIXME: restoreGeometry is ignored for docked widgets
       //        and its child widget
-      // restoreGeometry (settings->value
-      //        ("DockWidgets/" + objectName ()).toByteArray ());
+      restoreGeometry (settings->value
+             ("DockWidgets/" + objectName ()).toByteArray ());
     }
   else  // only reparent, no docking
     setParent (_parent);
@@ -225,23 +224,21 @@
   setWindowFlags (Qt::Widget);
 
 #endif
+
+  _floating = false;
 }
 
 // slot for (un)dock action
 void
-octave_dock_widget::change_floating (bool floating)
+octave_dock_widget::change_floating (bool)
 {
-#if defined (Q_OS_WIN32)
-  if (parent ())
-#else
-  if (floating)
-#endif
+  if (_floating)
+    make_widget ();
+  else
     {
       make_window ();
       focus ();
     }
-  else
-    make_widget ();
 }
 
 // slot for hiding the widget