changeset 17686:65544374c1cf

restore (un)docking of widgets without reparenting on non-windows systems * octave-dock-widget.cc(constructor): dock widgets features depending on system; (destructor): update comment; (set_title): set title in user defined title bar widget only on windows; (make_window): just set the windows flag when floating on non-windows systems; (make_widget): just set the widget flag when docked on non-windows systems; (change_floating): detect actual state from related flag on non-windows sys.; * main-window.cc(set_window_layout): use correct setting categorie for geometry
author Torsten <ttl@justmail.de>
date Fri, 18 Oct 2013 20:01:03 +0200
parents 3d862202c4f6
children cf43cc342bfa
files libgui/src/main-window.cc libgui/src/octave-dock-widget.cc
diffstat 2 files changed, 51 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/main-window.cc	Fri Oct 18 18:48:08 2013 +0200
+++ b/libgui/src/main-window.cc	Fri Oct 18 20:01:03 2013 +0200
@@ -633,7 +633,7 @@
             widget->make_widget (false); // no docking, just reparent
 
           // restore geometry
-          QVariant val = settings->value (name);
+          QVariant val = settings->value ("DockWidgets/" + name);
           widget->restoreGeometry (val.toByteArray ());
 
           // make widget visible if desired
--- a/libgui/src/octave-dock-widget.cc	Fri Oct 18 18:48:08 2013 +0200
+++ b/libgui/src/octave-dock-widget.cc	Fri Oct 18 20:01:03 2013 +0200
@@ -38,7 +38,6 @@
 {
 
   _parent = static_cast<QMainWindow *> (p);     // store main window
-  setFeatures (QDockWidget::DockWidgetMovable); // not floatable or cloasable
 
   connect (this, SIGNAL (visibilityChanged (bool)),
            this, SLOT (handle_visibility_changed (bool)));
@@ -46,6 +45,11 @@
   connect (p, SIGNAL (settings_changed (const QSettings*)),
            this, SLOT (notice_settings (const QSettings*)));
 
+#if defined (Q_OS_WIN32)
+  // windows: add an extra title bar that persists when floating
+
+  setFeatures (QDockWidget::DockWidgetMovable); // not floatable or closeable
+
   // the custom (extra) title bar of the widget
   _dock_action = new QAction
                    (QIcon (":/actions/icons/widget-undock.png"), "", this);
@@ -78,6 +82,18 @@
   title_widget->setLayout (h_layout);
   setTitleBarWidget (title_widget);
 
+#else
+
+  // non windows: qt takes control of floating widgets
+  setFeatures (QDockWidget::DockWidgetMovable |
+               QDockWidget::DockWidgetClosable |
+               QDockWidget::DockWidgetFloatable); // floatable and closeable
+
+  connect (this, SIGNAL (topLevelChanged (bool)),
+           this, SLOT (change_floating (bool)));
+
+#endif
+
   // copy & paste handling
   connect (p, SIGNAL (copyClipboard_signal ()), this, SLOT (copyClipboard ()));
   connect (p, SIGNAL (pasteClipboard_signal()), this, SLOT (pasteClipboard ()));
@@ -94,7 +110,7 @@
   settings->beginGroup ("DockWidgets");
 
   if (!parent ())
-    { // widget is floating, save actual floating geometry
+    { // widget is floating (windows), save actual floating geometry
       floating = true;
       settings->setValue (name+"_floating_geometry", saveGeometry ());
     }
@@ -123,10 +139,12 @@
 void
 octave_dock_widget::set_title (const QString& title)
 {
+#if defined (Q_OS_WIN32)
   QHBoxLayout* h_layout =
       static_cast<QHBoxLayout *> (titleBarWidget ()->layout ());
   QLabel *label = new QLabel (title);
   h_layout->insertWidget (0,label);
+#endif
   setWindowTitle (title);
 }
 
@@ -134,6 +152,10 @@
 void
 octave_dock_widget::make_window ()
 {
+#if defined (Q_OS_WIN32)
+
+  // windows: the widget has to be reparented (parent = 0)
+
   QSettings *settings = resource_manager::get_settings ();
 
   // save the docking area for later redocking
@@ -150,12 +172,24 @@
   // restore the last geometry when floating
   restoreGeometry (settings->value
           ("DockWidgets/" + objectName ()+"_floating_geometry").toByteArray ());
+
+#else
+
+  // non windows: Just set the appripriate window flag
+  setWindowFlags (Qt::Window);
+
+#endif
+
 }
 
 // dock the widget
 void
 octave_dock_widget::make_widget (bool dock)
 {
+#if defined (Q_OS_WIN32)
+
+  // windows: Since floating widget has no parent, we have to readd it
+
   QSettings *settings = resource_manager::get_settings ();
 
   // save last floating geometry
@@ -179,13 +213,24 @@
   // adjust the (un)dock icon
   _dock_action->setIcon (QIcon (":/actions/icons/widget-undock.png"));
   _dock_action->setToolTip (tr ("Undock widget"));
+
+#else
+
+  // non windows: just say we are a docked widget again
+  setWindowFlags (Qt::Widget);
+
+#endif
 }
 
 // slot for (un)dock action
 void
-octave_dock_widget::change_floating (bool)
-{
-  if (parent())
+octave_dock_widget::change_floating (bool floating)
+ {
+#if defined (Q_OS_WIN32)
+   if (parent())
+#else
+  if (floating)
+#endif
     {
       make_window ();
       focus ();