# HG changeset patch # User Rik # Date 1429588014 25200 # Node ID 248f2f2e7d4872466ee478b51debc63d56c8353d # Parent de1377a638d7df0e6116febb1a149470d58ca6ca 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. diff -r de1377a638d7 -r 248f2f2e7d48 libgui/graphics/Canvas.cc --- a/libgui/graphics/Canvas.cc Tue Apr 21 00:24:35 2015 +0200 +++ b/libgui/graphics/Canvas.cc Mon Apr 20 20:46:54 2015 -0700 @@ -114,6 +114,11 @@ } } +/* + Two updateCurrentPoint() 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. +*/ void Canvas::updateCurrentPoint(const graphics_object& fig, const graphics_object& obj, QMouseEvent* event) @@ -153,6 +158,46 @@ } void +Canvas::updateCurrentPoint(const graphics_object& fig, + const graphics_object& obj) +{ + gh_manager::auto_lock lock; + + gh_manager::post_set (fig.get_handle (), "currentpoint", + Utils::figureCurrentPoint (fig), false); + + Matrix children = obj.get_properties ().get_children (); + octave_idx_type num_children = children.numel (); + + for (int i = 0; i < num_children; i++) + { + graphics_object childObj (gh_manager::get_object (children(i))); + + if (childObj.isa ("axes")) + { + // FIXME: QCursor::pos() may give inaccurate results with asynchronous + // window systems like X11 over ssh. + QWidget *w = qWidget (); + QPoint p = w->mapFromGlobal (QCursor::pos ()); + axes::properties& ap = Utils::properties (childObj); + Matrix x_zlim = ap.get_transform_zlim (); + graphics_xform x_form = ap.get_transform (); + + ColumnVector p1 = x_form.untransform (p.x (), p.y (), x_zlim(0)); + ColumnVector p2 = x_form.untransform (p.x (), p.y (), x_zlim(1)); + + Matrix cp (2, 3, 0.0); + + cp(0,0) = p1(0); cp(0,1) = p1(1); cp(0,2) = p1(2); + cp(1,0) = p2(0); cp(1,1) = p2(1); cp(1,2) = p2(2); + + gh_manager::post_set (childObj.get_handle (), "currentpoint", cp, + false); + } + } +} + +void Canvas::annotation_callback (const octave_value_list& args) { Ffeval (ovl ("annotation").append (args)); @@ -886,6 +931,16 @@ { if (m_eventMask & KeyPress) { + gh_manager::auto_lock lock; + graphics_object obj = gh_manager::get_object (m_handle); + + if (obj.valid_object ()) + { + graphics_object figObj (obj.get_ancestor ("figure")); + + updateCurrentPoint (figObj, obj); + } + octave_scalar_map eventData = Utils::makeKeyEventStruct (event); gh_manager::post_set (m_handle, "currentcharacter", diff -r de1377a638d7 -r 248f2f2e7d48 libgui/graphics/Canvas.h --- a/libgui/graphics/Canvas.h Tue Apr 21 00:24:35 2015 +0200 +++ b/libgui/graphics/Canvas.h Mon Apr 20 20:46:54 2015 -0700 @@ -102,6 +102,8 @@ void updateCurrentPoint (const graphics_object& fig, const graphics_object& obj, QMouseEvent *event); + void updateCurrentPoint (const graphics_object& fig, + const graphics_object& obj); void annotation_callback (const octave_value_list& args); diff -r de1377a638d7 -r 248f2f2e7d48 libgui/graphics/QtHandlesUtils.cc --- 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
().map_from_boundingbox (qp.x (), - qp.y ()); + return tkFig->properties
().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
().map_from_boundingbox (qp.x (), + qp.y ()); } } diff -r de1377a638d7 -r 248f2f2e7d48 libgui/graphics/QtHandlesUtils.h --- a/libgui/graphics/QtHandlesUtils.h Tue Apr 21 00:24:35 2015 +0200 +++ b/libgui/graphics/QtHandlesUtils.h Mon Apr 20 20:46:54 2015 -0700 @@ -62,6 +62,7 @@ bool isDoubleClick = false); Matrix figureCurrentPoint (const graphics_object& fig, QMouseEvent* event); + Matrix figureCurrentPoint (const graphics_object& fig); template inline typename T::properties&