exporting patch:
# HG changeset patch
# User Daniel J Sebald <daniel.sebald@ieee.org>
# Date 1520309493 21600
#      Mon Mar 05 22:11:33 2018 -0600
# Node ID 31f6b6a116c65cc2067561b96a79c4bdcb6bbb85
# Parent  c644c53c8d3737fb7052b04634bb37a5af6e2017
Improve fullscreen action for variable editor panes (bug #53275)

* octave-dock-widget.cc (label_dock_widget::label_dock_widget): Make
  m_title_widget the parent of all items placed in the h_layout QHBoxLayout.

* variable-editor.cc (variable_dock_widget::variable_dock_widget): Replace
  member variable m_initial_float with variables m_fullscreen_action,
  m_full_screen, m_prev_floating.  All is pre-processor-conditioned on
  HAVE_QGUIAPPLICATION.
  (variable_dock_widget::change_floating): Set the full-screen action tooltip
  to "Fullscreen" if undocking.  If docking, change full-screen action tooltip
  to "Fullscreen undock" and if in full screen mode restore the non-full-screen
  size and QAction icon.  All is pre-processor-conditioned on
  HAVE_QGUIAPPLICATION.
  (variable_dock_widget::toplevel_change): Remove the code that made the
  initial floating size full screen.
  (variable_dock_widget::change_fullscreen): New slot/method to undock a panel
  if it is docked and then set the panel size to fullscreen as well as change
  the QAction icon to view-restore and if the panel was not undocked set
  the QAction tooltip to "Restore geometry".  If in fullscreen mode, change
  back to the state, icon and tooltips prior to fullscreen mode.  The inside
  of the function is pre-processor-conditioned on HAVE_QGUIAPPLICATION.

* variable-editor.h (variable_dock_widget): Declare new slot
  change_fullscreen().  Replace member variable m_initial_float with
  m_fullscreen_action, m_full_screen, m_prev_floating and m_prev_geom.  Place
  just the variables and not the slot within pre-processor-condition of
  HAVE_QGUIAPPLICATION.

diff --git a/libgui/src/octave-dock-widget.cc b/libgui/src/octave-dock-widget.cc
--- a/libgui/src/octave-dock-widget.cc
+++ b/libgui/src/octave-dock-widget.cc
@@ -45,10 +45,12 @@ namespace octave
     m_icon_size = 0.75*st->pixelMetric (QStyle::PM_SmallIconSize);
 
     // the custom (extra) title bar of the widget
+    m_title_widget = new QWidget ();
+
     m_dock_action = new QAction
       (QIcon (":/actions/icons/widget-undock.png"), "", this);
     m_dock_action->setToolTip (tr ("Undock widget"));
-    m_dock_button = new QToolButton (this);
+    m_dock_button = new QToolButton (m_title_widget);
     m_dock_button->setDefaultAction (m_dock_action);
     m_dock_button->setFocusPolicy (Qt::NoFocus);
     m_dock_button->setIconSize (QSize (m_icon_size,m_icon_size));
@@ -56,7 +58,7 @@ namespace octave
     m_close_action = new QAction
       (QIcon (":/actions/icons/widget-close.png"), "", this);
     m_close_action->setToolTip (tr ("Close widget"));
-    m_close_button = new QToolButton (this);
+    m_close_button = new QToolButton (m_title_widget);
     m_close_button->setDefaultAction (m_close_action);
     m_close_button->setFocusPolicy (Qt::NoFocus);
     m_close_button->setIconSize (QSize (m_icon_size,m_icon_size));
@@ -72,7 +74,6 @@ namespace octave
     h_layout->setSpacing (0);
     h_layout->setContentsMargins (5,2,2,2);
 
-    m_title_widget = new QWidget ();
     m_title_widget->setLayout (h_layout);
     setTitleBarWidget (m_title_widget);
 
@@ -93,7 +94,7 @@ namespace octave
   {
     QHBoxLayout *h_layout
       = static_cast<QHBoxLayout *> (titleBarWidget ()->layout ());
-    QLabel *label = new QLabel (title);
+    QLabel *label = new QLabel (title, titleBarWidget ());
     label->setStyleSheet ("background: transparent;");
     h_layout->insertWidget (0,label);
     setWindowTitle (title);
diff --git a/libgui/src/variable-editor.cc b/libgui/src/variable-editor.cc
--- a/libgui/src/variable-editor.cc
+++ b/libgui/src/variable-editor.cc
@@ -85,7 +85,7 @@ namespace octave
   // Variable dock widget
 
   variable_dock_widget::variable_dock_widget (QWidget *p)
-    : label_dock_widget (p), m_initial_float (true)
+    : label_dock_widget (p)
   {
     setFocusPolicy (Qt::StrongFocus);
     // This controls whether the variable_dock_widgets are deleted
@@ -105,12 +105,59 @@ namespace octave
              this, SLOT (toplevel_change (bool)));
     connect (p, SIGNAL (visibilityChanged (bool)),
              this, SLOT (setVisible (bool)));
+
+#if defined (HAVE_QGUIAPPLICATION)
+    // Add a fullscreen button
+
+    m_fullscreen_action = nullptr;
+    m_full_screen = false;
+    m_prev_floating = false;
+    m_prev_geom = QRect (0, 0, 0, 0);
+
+    QHBoxLayout *h_layout = findChild<QHBoxLayout *> ();
+    if (h_layout != nullptr && titleBarWidget () != nullptr)
+      {
+        m_fullscreen_action = new QAction
+          (QIcon::fromTheme ("view-fullscreen"), "", this);
+        m_fullscreen_action->setToolTip (tr ("Fullscreen undock"));
+        QToolButton *fullscreen_button = new QToolButton (titleBarWidget ());
+        fullscreen_button->setDefaultAction (m_fullscreen_action);
+        fullscreen_button->setFocusPolicy (Qt::NoFocus);
+        fullscreen_button->setIconSize (QSize (m_icon_size,m_icon_size));
+        QString css_button = QString ("QToolButton {background: transparent; border: 0px;}");
+        fullscreen_button->setStyleSheet (css_button);
+
+        connect (m_fullscreen_action, SIGNAL (triggered ()),
+                 this, SLOT (change_fullscreen ()));
+
+        int index = -1;
+        QToolButton *first = titleBarWidget ()->findChild<QToolButton *> ();
+        if (first != nullptr)
+          index = h_layout->indexOf (first);
+        h_layout->insertWidget (index, fullscreen_button);
+      }
+#endif
   }
 
   // slot for (un)dock action
   void
   variable_dock_widget::change_floating (bool)
   {
+#if defined (HAVE_QGUIAPPLICATION)
+    if (isFloating ())
+      {
+        if (m_full_screen)
+          {
+            setGeometry (m_prev_geom);
+            m_fullscreen_action->setIcon (QIcon::fromTheme ("view-fullscreen"));
+            m_full_screen = false;
+          }
+        m_fullscreen_action->setToolTip (tr ("Fullscreen undock"));
+      }
+    else
+      m_fullscreen_action->setToolTip (tr ("Fullscreen"));
+#endif
+
     setFloating (! isFloating ());
   }
 
@@ -129,24 +176,6 @@ namespace octave
         m_dock_action->setIcon (QIcon (":/actions/icons/widget-dock.png"));
         m_dock_action->setToolTip (tr ("Dock widget"));
 
-        // Make initial size expanded very large for "magnified" viewing
-        if (m_initial_float)
-          {
-            // This will be resolved based on user feedback and preference
-            // and will eventually work without QGuiApplication.  Perhaps
-            // a maximize button added to the label_dock_widget windows
-            // along with the dock/undock and close buttons is best.
-#if defined (HAVE_QGUIAPPLICATION)
-            QScreen *pscreen = QGuiApplication::primaryScreen ();
-            QRect rect (0, 0, 0, 0);
-            rect = pscreen->availableGeometry ();
-            rect = QRect (rect.x () + 5, rect.y () + 5,
-                          rect.width () - 10, rect.height () - 10);
-            setGeometry (rect);
-            m_initial_float = false;
-#endif
-          }
-
         setFocus (Qt::OtherFocusReason);
         activateWindow();
       }
@@ -160,6 +189,43 @@ namespace octave
   }
 
   void
+  variable_dock_widget::change_fullscreen (void)
+  {
+#if defined (HAVE_QGUIAPPLICATION)
+    if (! m_full_screen)
+      {
+        m_prev_floating = isFloating ();
+        m_prev_geom = geometry ();
+
+        m_fullscreen_action->setIcon (QIcon::fromTheme ("view-restore"));
+        if (m_prev_floating)
+          m_fullscreen_action->setToolTip (tr ("Restore geometry"));
+        else
+          setFloating (true);
+
+        // showFullscreen() and setWindowState() only work for QWindow objects.
+        QScreen *pscreen = QGuiApplication::primaryScreen ();
+        QRect rect (0, 0, 0, 0);
+        rect = pscreen->availableGeometry ();
+        setGeometry (rect);
+
+        m_full_screen = true;
+      }
+    else
+      {
+        m_fullscreen_action->setIcon (QIcon::fromTheme ("view-fullscreen"));
+        setGeometry (m_prev_geom);
+        if (m_prev_floating)
+            m_fullscreen_action->setToolTip (tr ("Fullscreen"));
+        else
+          setFloating (false);
+
+        m_full_screen = false;
+      }
+#endif
+  }
+
+  void
   variable_dock_widget::closeEvent (QCloseEvent *e)
   {
     QDockWidget::closeEvent (e);
diff --git a/libgui/src/variable-editor.h b/libgui/src/variable-editor.h
--- a/libgui/src/variable-editor.h
+++ b/libgui/src/variable-editor.h
@@ -74,9 +74,16 @@ namespace octave
 
     void toplevel_change (bool);
 
+    void change_fullscreen (void);
+
+#if defined (HAVE_QGUIAPPLICATION)
   protected:
 
-    bool m_initial_float;
+    QAction *m_fullscreen_action;
+    bool m_full_screen;
+    bool m_prev_floating;
+    QRect m_prev_geom;
+#endif
   };
 
   class variable_editor_stack : public QStackedWidget
