changeset 26818:f7b10bd40045 stable

fix dock widget position when being dragged out of the main window (bug #55704) * octave-dock-widget.cc (octave_dock_widget): make_window now uses a bool parameter which has to be reflected in the signal connections; (make_window): previously unused bool parameter now used for indicating the case where the widget is dragged to its floating position, get last drag position before the widget is reparented and restore geometry afeterwards or set it to the last floating position; (event): emit the signal for making a window using the appropriate flag * octave-dock-widget.h: signal queue_make_window with boolean parameter, method make_window now using its boolean paramter
author Torsten <mttl@mailbox.org>
date Sun, 03 Mar 2019 12:56:12 +0100
parents 0dd5b293b18c
children 86b8f4986993 677764865056
files libgui/src/octave-dock-widget.cc libgui/src/octave-dock-widget.h
diffstat 2 files changed, 17 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/octave-dock-widget.cc	Thu Feb 28 20:40:09 2019 -0800
+++ b/libgui/src/octave-dock-widget.cc	Sun Mar 03 12:56:12 2019 +0100
@@ -204,8 +204,8 @@
         connect (m_default_float_button, SIGNAL (clicked (bool)),
                  this, SLOT (make_window (bool)));
       }
-    connect (this, SIGNAL (queue_make_window ()),
-             this, SLOT (make_window ()), Qt::QueuedConnection);
+    connect (this, SIGNAL (queue_make_window (bool)),
+             this, SLOT (make_window (bool)), Qt::QueuedConnection);
     connect (this, SIGNAL (queue_make_widget ()),
              this, SLOT (make_widget ()), Qt::QueuedConnection);
 
@@ -249,7 +249,7 @@
 
   // make the widget floating
   void
-  octave_dock_widget::make_window (bool)
+  octave_dock_widget::make_window (bool widget_was_dragged)
   {
     bool vis = isVisible ();
 
@@ -258,18 +258,25 @@
 
     set_focus_predecessor ();  // set focus previously active widget if tabbed
 
+    // Before unparenting, get current geometry for restoring if dragged
+    QRect geom = geometry ();
+
     // the widget has to be reparented (parent = 0), preferably
     // from a non-toplevel widget otherwise may not have full
     // decorations, e.g., no taskbar icon and always in front
     if (isFloating ())
       setFloating (false);
+
 // Remove after thorough testing 3/20/18    m_parent->removeDockWidget (this);
+
     setParent (0, Qt::CustomizeWindowHint | Qt::WindowTitleHint |
                Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint | Qt::Window);
 
-    // restore the last geometry when floating
-    QRect geom = m_recent_float_geom.isNull () ? QRect (50,100,480,480)
-                                               : m_recent_float_geom;
+    // restore the last geometry when floating only if we have not dragged
+    // the window outside the main window
+    if (! widget_was_dragged)
+      geom = m_recent_float_geom.isNull () ? QRect (50,100,480,480)
+                                           : m_recent_float_geom;
     setGeometry (geom);
 
     // adjust the (un)dock icon
@@ -383,14 +390,14 @@
   {
     // low-level check of whether docked-widget became a window via
     // double-click or via drag-and-drop
-    if ((event->type () == QEvent::MouseButtonDblClick && ! isFloating ())
+    if ( (event->type () == QEvent::MouseButtonDblClick && ! isFloating ())
         || (event->type () == QEvent::ActivationChange && m_waiting_for_mouse_button_release))
       {
         bool retval = QDockWidget::event (event);
         if (isFloating () && parent () != 0)
           {
             m_waiting_for_mouse_button_release = false;
-            emit queue_make_window ();
+            emit queue_make_window (event->type () != QEvent::MouseButtonDblClick);
           }
         return retval;
       }
--- a/libgui/src/octave-dock-widget.h	Thu Feb 28 20:40:09 2019 -0800
+++ b/libgui/src/octave-dock-widget.h	Sun Mar 03 12:56:12 2019 +0100
@@ -96,7 +96,7 @@
 
     void active_changed (bool active);
 
-    void queue_make_window (void);
+    void queue_make_window (bool widget_was_dragged);
 
     void queue_make_widget (void);
 
@@ -142,7 +142,7 @@
 
     void resizeEvent (QResizeEvent *event);
 
-    void make_window (bool not_used = false);
+    void make_window (bool widget_was_dragged = false);
 
     void make_widget (bool not_used = false);