exporting patch:
# HG changeset patch
# User Daniel J Sebald <daniel.sebald@ieee.org>
# Date 1520498126 21600
#      Thu Mar 08 02:35:26 2018 -0600
# Node ID fb2711e74c9a6d9827c5e351396a5cf9f565eb8c
# Parent  578ebece3dc70f3725e159de8e3a7988c256027e
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 title bar h_layout
  QHBoxLayout.
  (label_dock_widget::set_title): Ditto.
  (octave_dock_widget::make_window): Remove obsolete FIXME comment.  Place
  pre-processor conditional around three peculiar lines relevant to KDE.  Add
  maximize control to the window-manager title bar inherently enabling feature.

* variable-editor.cc (variable_dock_widget::variable_dock_widget): Replace
  member variable m_initial_float with variables m_frame, m_fullscreen_action,
  m_full_screen, m_prev_floating, m_prev_geom.  Pre-processor-condition the
  addition of a fullscreen button on the title bar before the undock/dock
  button, based on HAVE_QGUIAPPLICATION.  Create new QFrame assigned to m_frame
  parented by the variable editor but otherwise not associated with a layout.
  Give it attribute sunken appearance and invisible to mouse cursor.
  (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" otherwise to "Redock".  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_dock_widget::resizeEvent): Re-implement virtual base function by
  setting the size of the m_frame QFrame to that of the variable_dock_widget.

* variable-editor.h (variable_dock_widget): Declare reimplemented resizeEvent()
  and new slot change_fullscreen().  Replace member variable m_initial_float
  with m_frame, m_fullscreen_action, m_full_screen, m_prev_floating and
  m_prev_geom.  Place the last four variables within a pre-processor-condition
  based on 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);
@@ -153,19 +154,21 @@ namespace octave
     QSettings *settings = resource_manager::get_settings ();
 
     // save the docking area and geometry for later redocking
-    // FIXME: dockWidgetArea always returns 2
     settings->setValue ("DockWidgets/" + objectName () + "_dock_area",
                         m_parent->dockWidgetArea (this));
     settings->setValue ("DockWidgets/" + objectName (), saveGeometry ());
     settings->sync ();
 
     // remove parent and adjust the (un)dock icon
+#if 1
+    // Needed for some GUIs, e.g., KDE Oxygen
     setTitleBarWidget (0);
     setParent (0, Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint |
-               Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint);
+               Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
     setTitleBarWidget (m_title_widget);
+#endif
     setParent (0, Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint |
-               Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint);
+               Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
 
 #if defined (Q_OS_UNIX)
     m_title_widget->setToolTip (
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,64 @@ 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
+          (resource_manager::icon ("view-fullscreen", false), "", 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
+
+    // Custom title bars cause loss of decorations, add a frame
+    m_frame = new QFrame (this);
+    m_frame->setFrameStyle (QFrame::Box | QFrame::Sunken);
+    m_frame->setAttribute (Qt::WA_TransparentForMouseEvents);
   }
 
   // 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 (resource_manager::icon ("view-fullscreen", false));
+            m_full_screen = false;
+          }
+        m_fullscreen_action->setToolTip (tr ("Fullscreen undock"));
+      }
+    else
+      m_fullscreen_action->setToolTip (tr ("Fullscreen"));
+#endif
+
     setFloating (! isFloating ());
   }
 
@@ -129,24 +181,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 +194,45 @@ 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 (resource_manager::icon ("view-restore", false));
+        if (m_prev_floating)
+          m_fullscreen_action->setToolTip (tr ("Restore geometry"));
+        else
+          {
+            m_fullscreen_action->setToolTip (tr ("Redock"));
+            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 (resource_manager::icon ("view-fullscreen", false));
+        setGeometry (m_prev_geom);
+        if (! m_prev_floating)
+          setFloating (false);
+        m_fullscreen_action->setToolTip (tr ("Fullscreen"));
+
+        m_full_screen = false;
+      }
+#endif
+  }
+
+  void
   variable_dock_widget::closeEvent (QCloseEvent *e)
   {
     QDockWidget::closeEvent (e);
@@ -190,6 +263,12 @@ namespace octave
       }
   }
 
+  void variable_dock_widget::resizeEvent (QResizeEvent *)
+  {
+    if (m_frame)
+      m_frame->resize (size ());
+  }
+
 
   // Variable editor stack
 
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
@@ -62,6 +62,8 @@ namespace octave
 
     virtual void closeEvent (QCloseEvent *e);
 
+    void resizeEvent (QResizeEvent *event);
+
   public slots:
 
     void handle_focus_change (QWidget *old, QWidget *now);
@@ -74,9 +76,23 @@ namespace octave
 
     void toplevel_change (bool);
 
+    void change_fullscreen (void);
+
   protected:
 
-    bool m_initial_float;
+    QFrame *m_frame;
+
+#if defined (HAVE_QGUIAPPLICATION)
+
+    QAction *m_fullscreen_action;
+
+    bool m_full_screen;
+
+    bool m_prev_floating;
+
+    QRect m_prev_geom;
+
+#endif
   };
 
   class variable_editor_stack : public QStackedWidget
