diff libgui/graphics/QtHandlesUtils.cc @ 20110:248f2f2e7d48

Return correct x,y coordinates for keystroke with ginput in Qt (bug #44834). * Canvas.h (updateCurrentPoint (fig, obj)): New prototype for 2-argument form of updateCurrentPoint used with QKeyEvents. * Canvas.cc (updateCurrentPoint (fig, obj)): New version of function that uses QCursor::pos() to get CurrentPoint rather than using data embedded in QMouseEvent. * QtHandlesUtils.h (figureCurrentPoint (fig)): New prototype for 1-argument form of figureCurrentPoint used with QKeyEvents. * QtHandlesUtils.cc (figureCurrentPoint (fig)): New version of function that uses QCursor::pos() to get CurrentPoint rather than using data embedded in QMouseEvent.
author Rik <rik@octave.org>
date Mon, 20 Apr 2015 20:46:54 -0700
parents 76c72314d905
children 6446649e42c1
line wrap: on
line diff
--- a/libgui/graphics/QtHandlesUtils.cc	Tue Apr 21 00:24:35 2015 +0200
+++ b/libgui/graphics/QtHandlesUtils.cc	Mon Apr 20 20:46:54 2015 -0700
@@ -193,6 +193,11 @@
   return std::string ("normal");
 }
 
+/*
+   Two figureCurrentPoint() routines are required:
+   1) Used for QMouseEvents where cursor position data is in callback from Qt.
+   2) Used for QKeyEvents where cursor position must be determined.
+*/
 Matrix
 figureCurrentPoint (const graphics_object& fig, QMouseEvent* event)
 {
@@ -206,9 +211,31 @@
         {
           QPoint qp = c->mapFromGlobal (event->globalPos ());
 
-          return
-            tkFig->properties<figure> ().map_from_boundingbox (qp.x (),
-                                                               qp.y ());
+          return tkFig->properties<figure> ().map_from_boundingbox (qp.x (),
+                                                                    qp.y ());
+        }
+    }
+
+  return Matrix (1, 2, 0.0);
+}
+
+Matrix
+figureCurrentPoint (const graphics_object& fig)
+{
+  Object* tkFig = Backend::toolkitObject (fig);
+
+  if (tkFig)
+    {
+      Container* c = tkFig->innerContainer ();
+
+      if (c)
+        {
+          // FIXME: QCursor::pos() may give inaccurate results with asynchronous
+          //        window systems like X11 over ssh.
+          QPoint qp = c->mapFromGlobal (QCursor::pos ());
+
+          return tkFig->properties<figure> ().map_from_boundingbox (qp.x (),
+                                                                    qp.y ());
         }
     }