# HG changeset patch
# User Pantxo Diribarne <pantxo.diribarne@gmail.com>
# Date 1538938927 -7200
#      Sun Oct 07 21:02:07 2018 +0200
# Node ID 7f54428c02263c89686f4d3cc5f16e8911caf309
# Parent  bb9fcc4525804cca244b03ad628ace2048186b7a
Implement "resize" property for Qt figures (bug #)

* Figure.h/cc (Figure::m_resizable): New data member.
  (get_geometry): New private method that allows resizing a figure even when
  its size has been fixed.
  (Figure::update): Handle the "resize" property. Call QWidget::setSizePolicy
  and QWidget::setFixedSize to (dis)allow figure resizing and set m_resizable.
  (Figure::Figure, Figure::update, Figure::showFigureToolBar,
  Figure::updateFigureHeight, Figure::addCustomToolBar,
  Figure::showCustomToolBar): Make use of Figure::set_geometry rather that
  directly calling QMainWindow::setGeometry.

* genpropdoc.m: Document the "resize" figure property.

diff -r bb9fcc452580 -r 7f54428c0226 doc/interpreter/genpropdoc.m
--- a/doc/interpreter/genpropdoc.m	Sat Oct 06 11:10:36 2018 +0200
+++ b/doc/interpreter/genpropdoc.m	Sun Oct 07 21:02:07 2018 +0200
@@ -522,7 +522,10 @@
         s.doc = doc_unused;
 
       case "resize"
-        s.doc = doc_unused;
+        s.doc = "Control whether the figure can be resized by dragging the \
+window borders and corners using a mouse.  When __prop__ is @qcode{\"off\"} \
+mouse interactions are disabled but the figure can still be resized by \
+changing its @qcode{\"position\"} property.";
 
       case "resizefcn"
         s.doc = "__prop__ is deprecated.  Use @code{sizechangedfcn} instead.";
diff -r bb9fcc452580 -r 7f54428c0226 libgui/graphics/Figure.cc
--- a/libgui/graphics/Figure.cc	Sat Oct 06 11:10:36 2018 +0200
+++ b/libgui/graphics/Figure.cc	Sun Oct 07 21:02:07 2018 +0200
@@ -111,7 +111,7 @@
   Figure::Figure (const graphics_object& go, FigureWindow *win)
     : Object (go, win), m_blockUpdates (false), m_figureToolBar (nullptr),
       m_menuBar (nullptr), m_innerRect (), m_outerRect (),
-      m_mouseModeGroup (nullptr)
+      m_mouseModeGroup (nullptr), m_previousHeight (0), m_resizable (true)
   {
     m_container = new Container (win);
     win->setCentralWidget (m_container);
@@ -147,7 +147,7 @@
     m_innerRect = boundingBoxToRect (fp.get_boundingbox (true));
     m_outerRect = boundingBoxToRect (fp.get_boundingbox (false));
 
-    win->setGeometry (m_innerRect.adjusted (0, -toffset, 0, boffset));
+    set_geometry (m_innerRect.adjusted (0, -toffset, 0, boffset));
 
     // Enable mouse tracking unconditionally
     enableMouseTracking ();
@@ -166,6 +166,9 @@
     // modal style
     update (figure::properties::ID_WINDOWSTYLE);
 
+    // Handle resizing constraints
+    update (figure::properties::ID_RESIZE);
+
     // Visibility
     update (figure::properties::ID_VISIBLE);
 
@@ -317,6 +320,26 @@
         m_blockUpdates = false;
       }
   }
+  
+  void
+  Figure::set_geometry (QRect r)
+  {
+    QMainWindow *win = qWidget<QMainWindow> ();
+    
+    if (! m_resizable)
+      {
+        win->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Preferred);
+        win->setFixedSize (QSize( QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
+      }
+
+    win->setGeometry (r);
+    
+    if (! m_resizable)
+      {
+        win->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
+        win->setFixedSize(win->size ());
+      }
+  }
 
   Container*
   Figure::innerContainer (void)
@@ -435,7 +458,7 @@
           if (! m_statusBar->isHidden ())
             boffset += m_statusBar->sizeHint ().height ();
 
-          win->setGeometry (m_innerRect.adjusted (0, -toffset, 0, boffset));
+          set_geometry (m_innerRect.adjusted (0, -toffset, 0, boffset));
         }
         break;
 
@@ -458,6 +481,21 @@
           win->hide ();
         break;
 
+      case figure::properties::ID_RESIZE:
+        if (fp.is_resize ())
+          {
+            win->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Preferred);
+            win->setFixedSize (QSize( QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
+            m_resizable = true;
+          }
+        else
+          {
+            win->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
+            win->setFixedSize(win->size ());
+            m_resizable = false;
+          }
+        break;
+
       case figure::properties::ID_TOOLBAR:
         if (fp.toolbar_is ("none"))
           showFigureToolBar (false);
@@ -531,7 +569,7 @@
           r.adjust (0, -dy1, 0, dy2);
 
         m_blockUpdates = true;
-        qWidget<QWidget> ()->setGeometry (r);
+        set_geometry (r);
         m_figureToolBar->setVisible (visible);
         m_statusBar->setVisible (visible);
         m_blockUpdates = false;
@@ -553,7 +591,7 @@
         r.adjust (0, dh, 0, 0);
 
         m_blockUpdates = true;
-        qWidget<QWidget> ()->setGeometry (r);
+        set_geometry (r);
         m_blockUpdates = false;
 
         updateBoundingBox (false);
@@ -831,7 +869,7 @@
         r.adjust (0, -sz.height (), 0, 0);
 
         m_blockUpdates = true;
-        win->setGeometry (r);
+        set_geometry (r);
         win->addToolBarBreak ();
         win->addToolBar (bar);
         m_blockUpdates = false;
@@ -857,7 +895,7 @@
           r.adjust (0, sz.height (), 0, 0);
 
         m_blockUpdates = true;
-        win->setGeometry (r);
+        set_geometry (r);
         bar->setVisible (visible);
         m_blockUpdates = false;
 
diff -r bb9fcc452580 -r 7f54428c0226 libgui/graphics/Figure.h
--- a/libgui/graphics/Figure.h	Sat Oct 06 11:10:36 2018 +0200
+++ b/libgui/graphics/Figure.h	Sun Oct 07 21:02:07 2018 +0200
@@ -106,8 +106,8 @@
     void showFigureToolBar (bool visible);
     void addCustomToolBar (QToolBar *bar, bool visible);
     void showCustomToolBar (QToolBar *bar, bool visible);
-
     void updateFigureToolBarAndMenuBar (void);
+    void set_geometry (QRect r);
 
     static void updateBoundingBoxHelper (void*);
 
@@ -141,6 +141,7 @@
     QRect m_outerRect;
     MouseModeActionGroup *m_mouseModeGroup;
     int m_previousHeight;
+    bool m_resizable;
   };
 
 }
