# HG changeset patch # User Michael Goffioul # Date 1396400228 14400 # Node ID 9597e00ed2dd0c1aa37366a301c42ef9227b6b9e # Parent 0ede4dbb37f12189e4fd967698a10d20ec0a5855 Add support for "windowbuttonmotionfcn" and "currentpoint" * Figure.cc (Figure::Figure): Enable mouse tracking if windowbuttonmotionfcn callback is defined. (Figure::update): Enable mouse tracking on canvas and all child widgets when windowbuttonmotionfcn is defined. * Panel.cc (Panel::Panel): Propagate mouse tracking to child widgets during initialization. * Container.h (Container::childEvent): New method. * Container.cc (Container::childEvent): Likewise. Propagate mouse tracking status to child widgets. * BaseControl.cc (BaseControl::eventFilter): Handle mouse move events and call figure's appropriate callback. * Canvas.h (Canvas::updateCurrentPoint): New method. * Canvas.cc (Canvas::updateCurrentPoint): Likewise. Update figure and child axes currentpoint property. (Canvas::canvasMouseMoveEvent): Update currentpoint properties and call windowbuttonmotionfcn callback. (Canvas::canvasMousePressEvent): Call updateCurrentPoint. (Canvas::canvasMouseReleaseEvent): Likewise. diff -r 0ede4dbb37f1 -r 9597e00ed2dd libgui/graphics/BaseControl.cc --- a/libgui/graphics/BaseControl.cc Sun Mar 30 14:18:43 2014 -0700 +++ b/libgui/graphics/BaseControl.cc Tue Apr 01 20:57:08 2014 -0400 @@ -195,6 +195,20 @@ } } break; + case QEvent::MouseMove: + if (qWidget ()->hasMouseTracking ()) + { + gh_manager::auto_lock lock; + + QMouseEvent* m = dynamic_cast (event); + graphics_object go = object (); + graphics_object fig = go.get_ancestor ("figure"); + + gh_manager::post_set (fig.get_handle (), "currentpoint", + Utils::figureCurrentPoint (fig, m), false); + gh_manager::post_callback (fig.get_handle (), "windowbuttonmotionfcn"); + } + break; case QEvent::KeyPress: if (m_keyPressHandlerDefined) { diff -r 0ede4dbb37f1 -r 9597e00ed2dd libgui/graphics/Canvas.cc --- a/libgui/graphics/Canvas.cc Sun Mar 30 14:18:43 2014 -0700 +++ b/libgui/graphics/Canvas.cc Tue Apr 01 20:57:08 2014 -0400 @@ -51,6 +51,41 @@ m_redrawBlocked = block; } +void Canvas::updateCurrentPoint(const graphics_object& fig, + const graphics_object& obj, QMouseEvent* event) +{ + gh_manager::post_set (fig.get_handle (), "currentpoint", + Utils::figureCurrentPoint (fig, event), 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")) + { + 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 (event->x (), event->y (), + x_zlim(0)); + ColumnVector p2 = x_form.untransform (event->x (), event->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::canvasPaintEvent (void) { if (! m_redrawBlocked) @@ -134,6 +169,19 @@ break; } } + else if (m_mouseMode == NoMode) + { + graphics_object obj = gh_manager::get_object (m_handle); + + if (obj.valid_object ()) + { + graphics_object figObj (obj.get_ancestor ("figure")); + + updateCurrentPoint (figObj, obj, event); + gh_manager::post_callback (figObj.get_handle (), + "windowbuttonmotionfcn"); + } + } } void Canvas::canvasMousePressEvent (QMouseEvent* event) @@ -228,9 +276,7 @@ case NoMode: gh_manager::post_set (figObj.get_handle (), "selectiontype", Utils::figureSelectionType (event), false); - gh_manager::post_set (figObj.get_handle (), "currentpoint", - Utils::figureCurrentPoint (figObj, event), - false); + updateCurrentPoint (figObj, obj, event); gh_manager::post_callback (figObj.get_handle (), "windowbuttondownfcn"); gh_manager::post_callback (currentObj.get_handle (), @@ -321,9 +367,7 @@ { graphics_object figObj (obj.get_ancestor ("figure")); - gh_manager::post_set (figObj.get_handle (), "currentpoint", - Utils::figureCurrentPoint (figObj, event), - false); + updateCurrentPoint (figObj, obj, event); gh_manager::post_callback (figObj.get_handle (), "windowbuttonupfcn"); } diff -r 0ede4dbb37f1 -r 9597e00ed2dd libgui/graphics/Canvas.h --- a/libgui/graphics/Canvas.h Sun Mar 30 14:18:43 2014 -0700 +++ b/libgui/graphics/Canvas.h Tue Apr 01 20:57:08 2014 -0400 @@ -82,6 +82,9 @@ bool canvasKeyPressEvent (QKeyEvent* event); bool canvasKeyReleaseEvent (QKeyEvent* event); + void updateCurrentPoint (const graphics_object& fig, + const graphics_object& obj, QMouseEvent *event); + private: graphics_handle m_handle; bool m_redrawBlocked; diff -r 0ede4dbb37f1 -r 9597e00ed2dd libgui/graphics/Container.cc --- a/libgui/graphics/Container.cc Sun Mar 30 14:18:43 2014 -0700 +++ b/libgui/graphics/Container.cc Tue Apr 01 20:57:08 2014 -0400 @@ -24,6 +24,7 @@ #include #endif +#include #include #include "graphics.h" @@ -95,4 +96,12 @@ } } +void Container::childEvent (QChildEvent* event) +{ + if (event->child ()->isWidgetType ()) + { + qobject_cast (event->child ())->setMouseTracking (hasMouseTracking ()); + } +} + }; // namespace QtHandles diff -r 0ede4dbb37f1 -r 9597e00ed2dd libgui/graphics/Container.h --- a/libgui/graphics/Container.h Sun Mar 30 14:18:43 2014 -0700 +++ b/libgui/graphics/Container.h Tue Apr 01 20:57:08 2014 -0400 @@ -45,6 +45,7 @@ Canvas* canvas (const graphics_handle& handle, bool create = true); protected: + void childEvent (QChildEvent* event); void resizeEvent (QResizeEvent* event); private: diff -r 0ede4dbb37f1 -r 9597e00ed2dd libgui/graphics/Figure.cc --- a/libgui/graphics/Figure.cc Sun Mar 30 14:18:43 2014 -0700 +++ b/libgui/graphics/Figure.cc Tue Apr 01 20:57:08 2014 -0400 @@ -141,6 +141,12 @@ eventMask |= Canvas::KeyRelease; m_container->canvas (m_handle)->setEventMask (eventMask); + if (! fp.get_windowbuttonmotionfcn ().is_empty ()) + { + m_container->setMouseTracking (true); + m_container->canvas (m_handle)->qWidget ()->setMouseTracking (true); + } + connect (this, SIGNAL (asyncUpdate (void)), this, SLOT (updateContainer (void))); @@ -302,6 +308,15 @@ else m_container->canvas (m_handle)->addEventMask (Canvas::KeyRelease); break; + case figure::properties::ID_WINDOWBUTTONMOTIONFCN: + { + bool hasCallback = ! fp.get_windowbuttonmotionfcn ().is_empty (); + + m_container->setMouseTracking (hasCallback); + foreach (QWidget* w, m_container->findChildren ()) + { w->setMouseTracking (hasCallback); } + } + break; default: break; } diff -r 0ede4dbb37f1 -r 9597e00ed2dd libgui/graphics/Panel.cc --- a/libgui/graphics/Panel.cc Sun Mar 30 14:18:43 2014 -0700 +++ b/libgui/graphics/Panel.cc Tue Apr 01 20:57:08 2014 -0400 @@ -115,6 +115,12 @@ m_container = new Container (frame); m_container->canvas (m_handle); + if (frame->hasMouseTracking ()) + { + foreach (QWidget* w, frame->findChildren ()) + { w->setMouseTracking (true); } + } + QString title = Utils::fromStdString (pp.get_title ()); if (! title.isEmpty ()) {