# HG changeset patch
# User Pantxo Diribarne <pantxo.diribarne@gmail.com>
# Date 1575920299 -3600
#      Mon Dec 09 20:38:19 2019 +0100
# Node ID 7e1ba20386fe04e42f761c717018335a846a1bff
# Parent  18de386596066b5c6723414d426253453e07fbe6
More reactive Pan, Rotate and Zoom mode for Qt figures (bug #57385)

* Canvas.cc (Canvas::mousePressEvent): Out of SelectMode and NoMode,
  call select_oject for axes only, which is much faster. Reorganise code
  for readability.

diff -r 18de38659606 -r 7e1ba20386fe libgui/graphics/Canvas.cc
--- a/libgui/graphics/Canvas.cc	Tue Dec 03 17:50:59 2019 +0100
+++ b/libgui/graphics/Canvas.cc	Mon Dec 09 20:38:19 2019 +0100
@@ -585,9 +585,22 @@
 
     if (obj.valid_object ())
       {
+        MouseMode newMouseMode = NoMode;
+        
         graphics_object figObj (obj.get_ancestor ("figure"));
+        Figure *fig =
+          dynamic_cast<Figure *> (qt_graphics_toolkit::toolkitObject (figObj));
 
-        // Any click in a figure canvas makes it current
+        if (fig)
+          newMouseMode = fig->mouseMode ();
+
+        // Retrieve selected objects.
+        graphics_object currentObj, axesObj;
+        select_object (obj, event, currentObj, axesObj,
+                       (newMouseMode != NoMode
+                        && newMouseMode != SelectMode));
+        
+        // Make selected figure current
         if (figObj)
           {
             graphics_object root = gh_mgr.get_object (0);
@@ -595,32 +608,6 @@
               .set_currentfigure (figObj.get_handle ().as_octave_value ());
           }
 
-        graphics_object currentObj, axesObj;
-
-        // Retrieve selected object.
-        select_object (obj, event, currentObj, axesObj);
-
-        // currentObj may be invalid if, e.g., all objects under the mouse
-        // click had "hittest" -> "off" or "pickableparts" -> "none".  In that
-        // case, replace with underlying figObj which always accepts mouse
-        // clicks.
-        if (! currentObj.valid_object ())
-          currentObj = figObj;
-        else if (! currentObj.get_properties ().is_hittest ())
-          {
-            // Objects with "hittest"->"off" pass the mouse event to their
-            // parent and so on.
-            graphics_object tmpgo;
-            tmpgo = gh_mgr.get_object (currentObj.get_parent ());
-            while (tmpgo && ! tmpgo.get_properties ().is_hittest ())
-              tmpgo = gh_mgr.get_object (tmpgo.get_parent ());
-
-            if (tmpgo && tmpgo.get_handle () != 0.0)
-              currentObj = tmpgo;
-            else
-              currentObj = graphics_object ();
-          }
-
         // Make selected axes current
         bool valid_axes = axesObj.valid_object ()
           && axesObj.get_properties ().handlevisibility_is ("on")
@@ -631,17 +618,31 @@
           Utils::properties<figure> (figObj)
             .set_currentaxes (axesObj.get_handle ().as_octave_value ());
 
-        Figure *fig = dynamic_cast<Figure *> (qt_graphics_toolkit::toolkitObject (figObj));
-
-        MouseMode newMouseMode = NoMode;
-
-        if (fig)
-          newMouseMode = fig->mouseMode ();
-
         switch (newMouseMode)
           {
           case NoMode:
             {
+              // currentObj may be invalid if, e.g., all objects under the
+              // mouse click had "hittest"->"off" or "pickableparts"->"none".
+              // In that case, replace with underlying figObj which always
+              // accepts mouse clicks.
+              if (! currentObj.valid_object ())
+                currentObj = figObj;
+              else if (! currentObj.get_properties ().is_hittest ())
+                {
+                  // Objects with "hittest"->"off" pass the mouse event to their
+                  // parent and so on.
+                  graphics_object tmpgo;
+                  tmpgo = gh_mgr.get_object (currentObj.get_parent ());
+                  while (tmpgo && ! tmpgo.get_properties ().is_hittest ())
+                    tmpgo = gh_mgr.get_object (tmpgo.get_parent ());
+
+                  if (tmpgo && tmpgo.get_handle () != 0.0)
+                    currentObj = tmpgo;
+                  else
+                    currentObj = graphics_object ();
+                }
+              
               // Update the figure "currentobject"
               auto& fprop = Utils::properties<figure> (figObj);
 
