changeset 29147:5d7a651bf0bb stable

fix error when restoring previous main window layout (bug #59426) * default-qt-settings.in: remove default settings for dock widgets * gui-preferences-mw.h: remove default values for main window geometry and state * main-window.cc: (reset_windows): slot for resetting layout action now calling the new member function do_reset_windows; (set_window_layout): calling new member function do_reset_windows when geometry or state are not yet available from the settings file, set size to screen size if state was maximized, the settings pointer now is always valid so no further checks are required; (construct_central_widget): size for hidden central widget is fixed; (construct): window layout and adding the dock widget is moved into the new member function do_reset_windows; (resize_dock): new member function resizing a docked widget either by resizeDocks (since Qt 5.6) or by a not very reliable replacement; (do_reset_windows): new member function setting the default size of the main window, adding all widget, resize the terminal widget to the default size, showing everything if the argument is true (default) and storing size and state of main window * main-window.h (do_reset_windows, resize_dock): new member functions * octave-dock-widget.cc (make_widget): fix indentation; * acinclude.m4: add test for QMainWindow::resizeDocks ()
author Torsten Lilge <ttl-octave@mailbox.org>
date Sun, 06 Dec 2020 13:53:30 +0100
parents 1153f47f29a7
children d9ac99164c18 b3f34a22b3fe
files libgui/default-qt-settings.in libgui/src/gui-preferences-mw.h libgui/src/main-window.cc libgui/src/main-window.h libgui/src/octave-dock-widget.cc m4/acinclude.m4
diffstat 6 files changed, 165 insertions(+), 147 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/default-qt-settings.in	Fri Dec 04 22:50:37 2020 +0100
+++ b/libgui/default-qt-settings.in	Sun Dec 06 13:53:30 2020 +0100
@@ -15,32 +15,6 @@
 fontName=__default_font__
 cursorType=ibeam
 
-[DockWidgets]
-TerminalDockWidget=@ByteArray(\x1\xd9\xd0\xcb\0\x1\0\0\0\0\x1j\0\0\0 \0\0\x4\x3\0\0\x2\x9e\0\0\x1j\0\0\0 \0\0\x4\x3\0\0\x2\x9e\0\0\0\0\0\0)
-TerminalDockWidgetFloating=false
-TerminalDockWidgetVisible=true
-WorkspaceView=@ByteArray(\x1\xd9\xd0\xcb\0\x1\0\0\0\0\0\0\0\0\x1+\0\0\x1\x63\0\0\x2\0\0\0\0\0\0\0\x1+\0\0\x1\x63\0\0\x2\0\0\0\0\0\0\0)
-WorkspaceViewFloating=false
-WorkspaceViewVisible=true
-HistoryDockWidget=@ByteArray(\x1\xd9\xd0\xcb\0\x1\0\0\0\0\0\0\0\0\x2\a\0\0\x1\x63\0\0\x2\xba\0\0\0\0\0\0\x2\a\0\0\x1\x63\0\0\x2\xba\0\0\0\0\0\0)
-HistoryDockWidgetFloating=false
-HistoryDockWidgetVisible=true
-FilesDockWidget=@ByteArray(\x1\xd9\xd0\xcb\0\x1\0\0\0\0\0\0\0\0\0 \0\0\x1\x63\0\0\x1$\0\0\0\0\0\0\0 \0\0\x1\x63\0\0\x1$\0\0\0\0\0\0)
-FilesDockWidgetFloating=false
-FilesDockWidgetVisible=true
-DocumentationDockWidget=@ByteArray(\x1\xd9\xd0\xcb\0\x1\0\0\xff\xff\xfbr\xff\xff\xfb\x8d\xff\xff\xfe\v\xff\xff\xfe\v\xff\xff\xfbr\xff\xff\xfb\x8d\xff\xff\xfe\v\xff\xff\xfe\v\0\0\0\0\0\0)
-DocumentationDockWidgetFloating=false
-DocumentationDockWidgetVisible=true
-FileEditor=@ByteArray(\x1\xd9\xd0\xcb\0\x1\0\0\xff\xff\xfbr\xff\xff\xfb\x8d\xff\xff\xfe\v\xff\xff\xfe\v\xff\xff\xfbr\xff\xff\xfb\x8d\xff\xff\xfe\v\xff\xff\xfe\v\0\0\0\0\0\0)
-FileEditorFloating=false
-FileEditorVisible=true
-NewsDockWidget=@ByteArray(\x1\xd9\xd0\xcb\0\x1\0\0\0\0\x2\"\0\0\0@\0\0\x4\xb3\0\0\x1\x1a\0\0\x2\"\0\0\0@\0\0\x4\xb3\0\0\x1\x1a\0\0\0\0\0\0)
-NewsDockWidgetFloating=false
-NewsDockWidgetVisible=true
-VariableEditor=@ByteArray(\x1\xd9\xd0\xcb\0\x2\0\0\xff\xff\xfb\x65\xff\xff\xfb\xac\xff\xff\xfe\v\xff\xff\xfe\v\xff\xff\xfb\x65\xff\xff\xfb\xac\xff\xff\xfe\v\xff\xff\xfe\v\xff\xff\xff\xff\0\0\0\0\x5\0)
-VariableEditorFloating=false
-VariableEditorVisible=true
-
 [workspaceview]
 local_collapsed=false
 global_collapsed=false
--- a/libgui/src/gui-preferences-mw.h	Fri Dec 04 22:50:37 2020 +0100
+++ b/libgui/src/gui-preferences-mw.h	Sun Dec 06 13:53:30 2020 +0100
@@ -30,65 +30,13 @@
 
 // Main window preferences
 
-const unsigned char ba_geometry_data[] =
-{
-  0x01,0xd9,0xd0,0xcb,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-  0x00,0x1b,0x00,0x00,0x03,0xaf,0x00,0x00,0x02,0xb8,0x00,0x00,0x00,0x00,
-  0x00,0x00,0x00,0x39,0x00,0x00,0x03,0xaf,0x00,0x00,0x02,0xb8,0x00,0x00,
-  0x00,0x00,0x00,0x00,0x00,0x00,0x05,0x00
-};
-
-// FIXME: use the following version when Qt4 support is dropped
-// QVariant (QByteArrayLiteral ("\x1\xd9\xd0\xcb\0\x2\0\0\0\0\0\0\0\0\0\x1b\0\0\x3\xaf\0\0\x2\xb8\0\0\0\0\0\0\0\x39\0\0\x3\xaf\0\0\x2\xb8\0\0\0\0\0\0\0\0\x5\0")));
+// Geometry wihtout default since default layout is built programmatically
 const gui_pref
-mw_geometry ("MainWindow/geometry",
-             QVariant (QByteArray (reinterpret_cast<const char*> (ba_geometry_data),
-                                   sizeof (ba_geometry_data))));
+mw_geometry ("MainWindow/geometry", QVariant (QByteArray ()));
 
-const unsigned char ba_state_data[] =
-{
-  '\0','\0','\0',0xff,'\0','\0','\0','\0',0xfd,'\0','\0','\0',0x2,'\0','\0',
-  '\0','\0','\0','\0',0x1,'&','\0','\0',0x2,'+',0xfc,0x2,'\0','\0','\0',0x3,
-  0xfb,'\0','\0','\0',0x1e,'\0','F','\0','i','\0','l','\0','e','\0','s','\0',
-  'D','\0','o','\0','c','\0','k','\0','W','\0','i','\0','d','\0','g','\0','e',
-  '\0','t',0x1,'\0','\0','\0','?','\0','\0','\0',0xac,'\0','\0','\0',0x88,
-  '\0',0xff,0xff,0xff,0xfb,'\0','\0','\0',0x1a,'\0','W','\0','o','\0','r',
-  '\0','k','\0','s','\0','p','\0','a','\0','c','\0','e','\0','V','\0','i',
-  '\0','e','\0','w',0x1,'\0','\0','\0',0xf1,'\0','\0','\0',0xca,'\0','\0',
-  '\0',0x82,'\0',0xff,0xff,0xff,0xfb,'\0','\0','\0','\"','\0','H','\0','i',
-  '\0','s','\0','t','\0','o','\0','r','\0','y','\0','D','\0','o','\0','c',
-  '\0','k','\0','W','\0','i','\0','d','\0','g','\0','e','\0','t',0x1,'\0',
-  '\0',0x1,0xc1,'\0','\0','\0',0xa9,'\0','\0','\0',0x82,'\0',0xff,0xff,0xff,
-  '\0','\0','\0',0x1,'\0','\0',0x2,0x84,'\0','\0',0x2,'+',0xfc,0x2,'\0','\0',
-  '\0',0x1,0xfc,'\0','\0','\0','?','\0','\0',0x2,'+','\0','\0','\0',0xeb,0x1,
-  '\0','\0',0x1b,0xfa,'\0','\0','\0','\0',0x2,'\0','\0','\0',0x4,0xfb,'\0',
-  '\0','\0','$','\0','T','\0','e','\0','r','\0','m','\0','i','\0','n','\0',
-  'a','\0','l','\0','D','\0','o','\0','c','\0','k','\0','W','\0','i','\0',
-  'd','\0','g','\0','e','\0','t',0x1,'\0','\0','\0','\0',0xff,0xff,0xff,0xff,
-  '\0','\0','\0',0x46,'\0',0xff,0xff,0xff,0xfb,'\0','\0','\0','.','\0','D','\0',
-  'o','\0','c','\0','u','\0','m','\0','e','\0','n','\0','t','\0','a','\0','t',
-  '\0','i','\0','o','\0','n','\0','D','\0','o','\0','c','\0','k','\0','W',
-  '\0','i','\0','d','\0','g','\0','e','\0','t',0x1,'\0','\0','\0','\0',0xff,
-  0xff,0xff,0xff,'\0','\0','\0',0xcf,'\0',0xff,0xff,0xff,0xfb,'\0','\0','\0',
-  0x14,'\0','F','\0','i','\0','l','\0','e','\0','E','\0','d','\0','i','\0',
-  't','\0','o','\0','r',0x1,'\0','\0','\0','\0',0xff,0xff,0xff,0xff,'\0',
-  '\0','\0',0x62,'\0',0xff,0xff,0xff,0xfb,'\0','\0','\0',0x1c,'\0','V','\0',
-  'a','\0','r','\0','i','\0','a','\0','b','\0','l','\0','e','\0','E','\0',
-  'D','\0','i','\0','t','\0','o','\0','r',0x1,'\0','\0','\0','\0',0xff,0xff,
-  0xff,0xff,'\0','\0','\0',';','\0',0xff,0xff,0xff,'\0','\0','\0','\0','\0',
-  '\0',0x2,'+','\0','\0','\0',0x4,'\0','\0','\0',0x4,'\0','\0','\0','\b',
-  '\0','\0','\0','\b',0xfc,'\0','\0','\0',0x1,'\0','\0','\0',0x2,'\0','\0',
-  '\0',0x1,'\0','\0','\0',0x16,'\0','M','\0','a','\0','i','\0','n','\0','T',
-  '\0','o','\0','o','\0','l','\0','b','\0','a','\0','r',0x1,'\0','\0','\0',
-  '\0',0xff,0xff,0xff,0xff,'\0','\0','\0','\0','\0','\0','\0','\0'
-};
-
-// FIXME: use the following version when Qt4 support is dropped
-// QVariant (QByteArrayLiteral ("\0\0\0\xff\0\0\0\0\xfd\0\0\0\x2\0\0\0\0\0\0\x1&\0\0\x2+\xfc\x2\0\0\0\x3\xfb\0\0\0\x1e\0\x46\0i\0l\0\x65\0s\0\x44\0o\0\x63\0k\0W\0i\0\x64\0g\0\x65\0t\x1\0\0\0?\0\0\0\xac\0\0\0\x88\0\xff\xff\xff\xfb\0\0\0\x1a\0W\0o\0r\0k\0s\0p\0\x61\0\x63\0\x65\0V\0i\0\x65\0w\x1\0\0\0\xf1\0\0\0\xca\0\0\0\x82\0\xff\xff\xff\xfb\0\0\0\"\0H\0i\0s\0t\0o\0r\0y\0\x44\0o\0\x63\0k\0W\0i\0\x64\0g\0\x65\0t\x1\0\0\x1\xc1\0\0\0\xa9\0\0\0\x82\0\xff\xff\xff\0\0\0\x1\0\0\x2\x84\0\0\x2+\xfc\x2\0\0\0\x1\xfc\0\0\0?\0\0\x2+\0\0\0\xeb\x1\0\0\x1b\xfa\0\0\0\0\x2\0\0\0\x4\xfb\0\0\0$\0T\0\x65\0r\0m\0i\0n\0\x61\0l\0\x44\0o\0\x63\0k\0W\0i\0\x64\0g\0\x65\0t\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\x46\0\xff\xff\xff\xfb\0\0\0.\0\x44\0o\0\x63\0u\0m\0\x65\0n\0t\0\x61\0t\0i\0o\0n\0\x44\0o\0\x63\0k\0W\0i\0\x64\0g\0\x65\0t\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\xcf\0\xff\xff\xff\xfb\0\0\0\x14\0\x46\0i\0l\0\x65\0\x45\0\x64\0i\0t\0o\0r\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\x62\0\xff\xff\xff\xfb\0\0\0\x1c\0V\0\x61\0r\0i\0\x61\0\x62\0l\0\x65\0\x45\0\x64\0i\0t\0o\0r\x1\0\0\0\0\xff\xff\xff\xff\0\0\0;\0\xff\xff\xff\0\0\0\0\0\0\x2+\0\0\0\x4\0\0\0\x4\0\0\0\b\0\0\0\b\xfc\0\0\0\x1\0\0\0\x2\0\0\0\x1\0\0\0\x16\0M\0\x61\0i\0n\0T\0o\0o\0l\0\x42\0\x61\0r\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0")));
+// State wihtout default since default layout is built programmatically
 const gui_pref
-mw_state ("MainWindow/windowState",
-          QVariant (QByteArray (reinterpret_cast<const char*> (ba_state_data),
-                                sizeof (ba_state_data))));
+mw_state ("MainWindow/windowState", QVariant (QByteArray ()));
 
 const gui_pref
 mw_dir_list ("MainWindow/current_directory_list", QVariant (QStringList ()));
--- a/libgui/src/main-window.cc	Fri Dec 04 22:50:37 2020 +0100
+++ b/libgui/src/main-window.cc	Sun Dec 06 13:53:30 2020 +0100
@@ -956,14 +956,6 @@
     m_previous_dock->activate ();
   }
 
-  void main_window::reset_windows (void)
-  {
-    hide ();
-    set_window_layout (nullptr);  // do not use the settings file
-    showNormal ();  // make sure main window is not minimized
-    focus_command_window ();
-  }
-
   void main_window::update_octave_directory (const QString& dir)
   {
     // Remove existing entry, if any, then add new directory at top and
@@ -1474,14 +1466,22 @@
   void main_window::set_window_layout (gui_settings *settings)
   {
     // Restore main window state and geometry from settings file or, in case
-    // of an error, from the default layout.
-    if (settings)
+    // of an error (no pref values yet), from the default layout.
+    if (! restoreGeometry (settings->value (mw_geometry).toByteArray ()))
       {
-        if (! restoreState (settings->value (mw_state).toByteArray ()))
-          restoreState (mw_state.def.toByteArray ());
-
-        if (! restoreGeometry (settings->value (mw_geometry).toByteArray ()))
-          restoreGeometry (mw_geometry.def.toByteArray ());
+        do_reset_windows (true);
+        return;
+      }
+
+    if (isMaximized())
+      {
+        setGeometry( QApplication::desktop ()->availableGeometry (this));
+      }
+
+    if (! restoreState (settings->value (mw_state).toByteArray ()))
+      {
+        do_reset_windows (true);
+        return;
       }
 
     // Restore the geometry of all dock-widgets
@@ -1493,13 +1493,11 @@
           {
             bool floating = false;
             bool visible = true;
-            if (settings)
-              {
-                floating = settings->value
-                  (dw_is_floating.key.arg (name), dw_is_floating.def).toBool ();
-                visible = settings->value
-                  (dw_is_visible.key.arg (name), dw_is_visible.def).toBool ();
-              }
+
+            floating = settings->value
+                (dw_is_floating.key.arg (name), dw_is_floating.def).toBool ();
+            visible = settings->value
+                (dw_is_visible.key.arg (name), dw_is_visible.def).toBool ();
 
             // If floating, make window from widget.
             if (floating)
@@ -1508,9 +1506,8 @@
 
                 if (visible)
                   {
-                    if (settings
-                        && settings->value (dw_is_minimized.key.arg (name),
-                                            dw_is_minimized.def).toBool ())
+                    if (settings->value (dw_is_minimized.key.arg (name),
+                                         dw_is_minimized.def).toBool ())
                       widget->showMinimized ();
                     else
                       widget->setVisible (true);
@@ -1527,14 +1524,6 @@
           }
       }
 
-    if (! settings)
-      {
-        restoreGeometry (mw_geometry.def.toByteArray ());
-        restoreState (mw_state.def.toByteArray ());
-
-        set_default_geometry ();
-      }
-
     show ();
   }
 
@@ -1945,7 +1934,7 @@
     QWidget *dummyWidget = new QWidget ();
     dummyWidget->setObjectName ("CentralDummyWidget");
     dummyWidget->resize (10, 10);
-    dummyWidget->setSizePolicy (QSizePolicy::Minimum, QSizePolicy::Minimum);
+    dummyWidget->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
     dummyWidget->hide ();
     setCentralWidget (dummyWidget);
   }
@@ -2054,36 +2043,8 @@
     connect (this, SIGNAL (warning_function_not_found_signal (const QString&)),
              this, SLOT (warning_function_not_found (const QString&)));
 
-    // Build the window with widgets
-
     setWindowTitle ("Octave");
 
-    // See Octave bug #53409 and https://bugreports.qt.io/browse/QTBUG-55357
-#if (QT_VERSION < 0x050601) || (QT_VERSION >= 0x050701)
-    setDockOptions (QMainWindow::AnimatedDocks
-                    | QMainWindow::AllowNestedDocks
-                    | QMainWindow::AllowTabbedDocks);
-#else
-    setDockNestingEnabled (true);
-#endif
-
-    addDockWidget (Qt::RightDockWidgetArea, m_command_window);
-    addDockWidget (Qt::RightDockWidgetArea, m_doc_browser_window);
-    tabifyDockWidget (m_command_window, m_doc_browser_window);
-
-#if defined (HAVE_QSCINTILLA)
-    addDockWidget (Qt::RightDockWidgetArea, m_editor_window);
-    tabifyDockWidget (m_command_window, m_editor_window);
-#endif
-    addDockWidget (Qt::RightDockWidgetArea, m_variable_editor_window);
-    tabifyDockWidget (m_command_window, m_variable_editor_window);
-
-    addDockWidget (Qt::LeftDockWidgetArea, m_file_browser_window);
-    addDockWidget (Qt::LeftDockWidgetArea, m_workspace_window);
-    addDockWidget (Qt::LeftDockWidgetArea, m_history_window);
-
-    set_default_geometry ();
-
     setStatusBar (m_status_bar);
 
 #if defined (HAVE_QSCINTILLA)
@@ -2820,6 +2781,7 @@
        });
   }
 
+  // Get size of screen where the main window is located
   void main_window::get_screen_geometry (int *width, int *height)
   {
     QRect screen_geometry
@@ -2829,6 +2791,28 @@
     *height = screen_geometry.height ();
   }
 
+  void main_window::resize_dock (QDockWidget *dw, int width, int height)
+  {
+#if defined (HAVE_QMAINWINDOW_RESIZEDOCKS)
+    // resizeDockWidget was added to Qt in Qt 5.6
+    if (width >= 0)
+      resizeDocks ({dw},{width},Qt::Horizontal);
+    if (height >= 0)
+      resizeDocks ({dw},{height},Qt::Vertical);
+#else
+    // This replacement of resizeDockWidget is not very reliable.
+    // But even if Qt4 is not yet
+    QSize s = dw->widget ()->size ();
+    if (width >= 0)
+      s.setWidth (width);
+    if (height >= 0)
+      s.setHeight (height);
+    dw->widget ()->resize (s);
+    dw->adjustSize ();
+#endif
+  }
+
+  // The default main window size relative to the desktop size
   void main_window::set_default_geometry ()
   {
     int win_x, win_y;
@@ -2838,4 +2822,78 @@
     resize (2*win_x/3, 7*win_y/8);
   }
 
+  void main_window::reset_windows (void)
+  {
+    // Slot for resetting the window layout to the default one
+    hide ();
+    showNormal ();              // Unmaximize
+    do_reset_windows (false);   // Add all widgets
+    // Re-add after giving time: This seems to be a reliable way to
+    // reset the main window's layout
+    QTimer::singleShot (250, this, SLOT (do_reset_windows (void)));
+  }
+
+  // Create the default layout of the main window. Do not use
+  // restoreState () and restoreGeometry () with default values since
+  // this might lead to problems when the Qt version changes
+  void main_window::do_reset_windows (bool show_it)
+  {
+    // Set main window default geometry and store its width for
+    // later resizing the command window
+    set_default_geometry ();
+    int win_x = geometry ().width ();
+
+    // Resize command window, the important one in the default layout
+    resize_dock (m_command_window, 7*win_x/8, -1);
+
+    // See Octave bug #53409 and https://bugreports.qt.io/browse/QTBUG-55357
+#if (QT_VERSION < 0x050601) || (QT_VERSION >= 0x050701)
+    setDockOptions (QMainWindow::AnimatedDocks
+                    | QMainWindow::AllowNestedDocks
+                    | QMainWindow::AllowTabbedDocks);
+#else
+    setDockNestingEnabled (true);
+#endif
+
+    // Add the dock widgets and show them
+    addDockWidget (Qt::LeftDockWidgetArea, m_file_browser_window);
+    addDockWidget (Qt::LeftDockWidgetArea, m_workspace_window);
+    addDockWidget (Qt::LeftDockWidgetArea, m_history_window);
+
+    addDockWidget (Qt::RightDockWidgetArea, m_command_window);
+
+    addDockWidget (Qt::RightDockWidgetArea, m_doc_browser_window);
+    tabifyDockWidget (m_command_window, m_doc_browser_window);
+
+    addDockWidget (Qt::RightDockWidgetArea, m_variable_editor_window);
+    tabifyDockWidget (m_command_window, m_variable_editor_window);
+
+#if defined (HAVE_QSCINTILLA)
+    addDockWidget (Qt::RightDockWidgetArea, m_editor_window);
+    tabifyDockWidget (m_command_window, m_editor_window);
+#endif
+
+    // Resize command window, the important one in the default layout
+    resize_dock (m_command_window, 2*win_x/3, -1);
+
+    // Show main wibdow, save state and geometry of main window and
+    // all dock widgets
+    if (show_it)
+      {
+        // Show all dock widgets
+        for (auto *widget : dock_widget_list ())
+          widget->show ();
+
+        // Show main window and store size and state
+        showNormal ();
+
+        resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
+        gui_settings *settings = rmgr.get_settings ();
+
+        settings->setValue (mw_geometry.key, saveGeometry ());
+        settings->setValue (mw_state.key, saveState ());
+
+        focus_command_window ();
+      }
+  }
 }
--- a/libgui/src/main-window.h	Fri Dec 04 22:50:37 2020 +0100
+++ b/libgui/src/main-window.h	Sun Dec 06 13:53:30 2020 +0100
@@ -162,6 +162,7 @@
     void prepare_to_exit (void);
     void go_to_previous_widget (void);
     void reset_windows (void);
+    void do_reset_windows (bool show_it = true);
 
     void update_octave_directory (const QString& dir);
     void browse_for_directory (void);
@@ -298,6 +299,7 @@
 
     void get_screen_geometry (int *width, int *height);
     void set_default_geometry (void);
+    void resize_dock (QDockWidget *dw, int width, int height);
 
     base_qobject& m_octave_qobj;
 
--- a/libgui/src/octave-dock-widget.cc	Fri Dec 04 22:50:37 2020 +0100
+++ b/libgui/src/octave-dock-widget.cc	Sun Dec 06 13:53:30 2020 +0100
@@ -109,6 +109,7 @@
              this, SLOT (pasteClipboard ()));
     connect (p, SIGNAL (selectAll_signal ()),
              this, SLOT (selectAll ()));
+
     // undo handling
     connect (p, SIGNAL (undo_signal ()), this, SLOT (do_undo ()));
   }
@@ -355,9 +356,9 @@
     // recover old window states, hide and re-show new added widget
     m_parent->restoreState (settings->value (mw_state.key).toByteArray ());
     setFloating (false);
-     // restore size using setGeometry instead of restoreGeometry following
-     // this post:
-     // https://forum.qt.io/topic/79326/qdockwidget-restoregeometry-not-working-correctly-when-qmainwindow-is-maximized/5
+    // restore size using setGeometry instead of restoreGeometry following
+    // this post:
+    // https://forum.qt.io/topic/79326/qdockwidget-restoregeometry-not-working-correctly-when-qmainwindow-is-maximized/5
     setGeometry (m_recent_dock_geom);
 
     // adjust the (un)dock icon
--- a/m4/acinclude.m4	Fri Dec 04 22:50:37 2020 +0100
+++ b/m4/acinclude.m4	Sun Dec 06 13:53:30 2020 +0100
@@ -763,6 +763,40 @@
   fi
 ])
 dnl
+dnl Check whether the Qt class QMainWindow has the resizeDocks member function.
+dnl This member function was introduced in Qt 5.6.
+dnl
+dnl FIXME: remove this test when we drop support for Qt older than 5.6
+dnl
+AC_DEFUN([OCTAVE_CHECK_FUNC_QMAINWINDOW_RESIZEDOCKS], [
+  AC_CACHE_CHECK([for QMainWindow::resizeDocks in <QMainWindow>],
+    [octave_cv_func_mainwindow_resizedocks],
+    [AC_LANG_PUSH(C++)
+    ac_octave_save_CPPFLAGS="$CPPFLAGS"
+    ac_octave_save_CXXFLAGS="$CXXFLAGS"
+    CPPFLAGS="$QT_CPPFLAGS $CXXPICFLAG $CPPFLAGS"
+    CXXFLAGS="$CXXPICFLAG $CXXFLAGS"
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+        #include <QMainWindow>
+        #include <QDockWidget>
+        ]], [[
+        QMainWindow *mw = new QMainWindow ();
+        QDockWidget *dw = new QDockWidget (mw);
+        mw->addDockWidget (Qt::LeftDockWidgetArea, dw);
+        mw->resizeDocks ({dw},{20},Qt::Horizontal);
+        ]])],
+      octave_cv_func_mainwindow_resizedocks=yes,
+      octave_cv_func_mainwindow_resizedocks=no)
+    CPPFLAGS="$ac_octave_save_CPPFLAGS"
+    CXXFLAGS="$ac_octave_save_CXXFLAGS"
+    AC_LANG_POP(C++)
+  ])
+  if test $octave_cv_func_mainwindow_resizedocks = yes; then
+    AC_DEFINE(HAVE_QMAINWINDOW_RESIZEDOCKS, 1,
+      [Define to 1 if you have the 'QMainWindow::resizeDocks' member function.])
+  fi
+])
+dnl
 dnl Check whether the Qt class QScreen has the devicePixelRatio member function.
 dnl This member function was introduced in Qt 5.5.
 dnl
@@ -2496,6 +2530,7 @@
     OCTAVE_CHECK_FUNC_QLIST_ITERATOR_CONSTRUCTOR
     OCTAVE_CHECK_FUNC_QMOUSEEVENT_LOCALPOS
     OCTAVE_CHECK_FUNC_QOBJECT_FINDCHILDREN_ACCEPTS_FINDCHILDOPTIONS
+    OCTAVE_CHECK_FUNC_QMAINWINDOW_RESIZEDOCKS
     OCTAVE_CHECK_FUNC_QSCREEN_DEVICEPIXELRATIO
     OCTAVE_CHECK_FUNC_QTABWIDGET_SETMOVABLE
     OCTAVE_CHECK_FUNC_QTMESSAGEHANDLER_ACCEPTS_QMESSAGELOGCONTEXT