changeset 27125:d2d2f66e1cdc

Implement figure "windowscrollwheelfcn" property for Qt toolkit (bug #56028). * NEWS: Announce implementation. * QtHandlesUtils.[h,cc] (makeScrollEventStruct): New method to prepare a ScrollWheel event structure. * Canvas.cc (Canvas::canvasWheelEvent): Post "windowscrollwheelfcn" whenever a WheelEvent happens. * genpropdoc.m: Document "windowscrollwheelfcn" property.
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Tue, 28 May 2019 16:43:48 +0200
parents da349bc21f8d
children 3d9e72cac668
files NEWS doc/interpreter/genpropdoc.m libgui/graphics/Canvas.cc libgui/graphics/QtHandlesUtils.cc libgui/graphics/QtHandlesUtils.h
diffstat 5 files changed, 48 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Tue May 28 19:18:50 2019 +0000
+++ b/NEWS	Tue May 28 16:43:48 2019 +0200
@@ -21,7 +21,11 @@
   rendering of characters.  The default is "on" which produces smooth,
   more visually appealing text.
 
-- The graphics properties `"pointer"`, `"pointershapecdata"`, and
+- The figure property `"windowscrollwheelfcn"`is now implemented.
+  This makes it possible to provide a callback function to be executed when
+  users manipulate the mouse wheel on a given figure.
+
+- The figure properties `"pointer"`, `"pointershapecdata"`, and
   `"pointershapehotspot"` are now implemented.  This makes it possible
   to change the shape of the cursor (pointer in Matlab-speak) displayed
   in a plot window.
--- a/doc/interpreter/genpropdoc.m	Tue May 28 19:18:50 2019 +0000
+++ b/doc/interpreter/genpropdoc.m	Tue May 28 16:43:48 2019 +0200
@@ -594,7 +594,21 @@
         s.valid = valid_fcn;
 
       case "windowscrollwheelfcn"
-        s.doc = doc_unused;
+        s.doc = "Function that is executed when a user manipulates \
+the mouse wheel over this figure.  \
+The function is called with two input arguments.  The first \
+argument holds the handle of the calling figure.  The second argument holds \
+an event structure which has the following members:\n\
+@table @code\n\
+@item VerticalScrollCount:\n\
+The number of wheel steps, typically 1 when scrolling down and -1 when \
+scrolling up.\n\
+@item VerticalScrollAmount:\n\
+The number of lines a wheel step should scroll.  This value is always 3.\n\
+@item EventName:\n\
+The event name which is \"WindowScrollWheel\".\
+@end table\
+\n\n__fcnmsg__";
         s.valid = valid_fcn;
 
       case "windowstyle"
--- a/libgui/graphics/Canvas.cc	Tue May 28 19:18:50 2019 +0000
+++ b/libgui/graphics/Canvas.cc	Tue May 28 16:43:48 2019 +0200
@@ -906,6 +906,8 @@
       {
         std::string mode;
 
+        graphics_object figObj (obj.get_ancestor ("figure"));
+
         graphics_object axesObj;
 
         Matrix children = obj.get_properties ().get_children ();
@@ -931,8 +933,6 @@
           {
             MouseMode newMouseMode = NoMode;
 
-            graphics_object figObj (obj.get_ancestor ("figure"));
-
             Figure *fig = dynamic_cast<Figure *> (Backend::toolkitObject (figObj));
 
             if (fig)
@@ -1006,6 +1006,13 @@
             if (redrawFigure)
               redraw (false);
           }
+        
+        if (! figObj.get ("windowscrollwheelfcn").isempty ())
+          {
+            octave_scalar_map eventData = Utils::makeScrollEventStruct (event);
+            gh_manager::post_callback (m_handle, "windowscrollwheelfcn",
+                                       eventData);
+          }
       }
   }
 
--- a/libgui/graphics/QtHandlesUtils.cc	Tue May 28 19:18:50 2019 +0000
+++ b/libgui/graphics/QtHandlesUtils.cc	Tue May 28 16:43:48 2019 +0200
@@ -388,6 +388,23 @@
       return retval;
     }
 
+    octave_scalar_map
+    makeScrollEventStruct (QWheelEvent *event)
+    {
+      octave_scalar_map retval;
+
+      // We assume a standard mouse with 15 degree steps and Qt returns
+      // 1/8 of a degree.
+      retval.setfield ("VerticalScrollCount",
+                       octave_value (- event->angleDelta().y () / 120));
+      // FIXME: Is there any way to access the number of lines a scroll step
+      // should correspond to?
+      retval.setfield ("VerticalScrollAmount", octave_value (3));
+      retval.setfield ("EventName", octave_value ("WindowScrollWheel"));
+
+      return retval;
+    }
+
   }
 
 }
--- a/libgui/graphics/QtHandlesUtils.h	Tue May 28 19:18:50 2019 +0000
+++ b/libgui/graphics/QtHandlesUtils.h	Tue May 28 16:43:48 2019 +0200
@@ -35,6 +35,7 @@
 
 class QKeyEvent;
 class QMouseEvent;
+class QWheelEvent;
 
 namespace QtHandles
 {
@@ -78,6 +79,7 @@
                                int height = -1);
 
     octave_scalar_map makeKeyEventStruct (QKeyEvent *event);
+    octave_scalar_map makeScrollEventStruct (QWheelEvent *event);
   }
 
 }