# HG changeset patch # User Pantxo Diribarne # Date 1444472497 -7200 # Node ID 46edfbd31ad756bcf8b95e014c20f1c67207ca6a # Parent 3af34e1ef330fc572388339cc83384e111ad10f4 Fix execution of "windowbuttonmotionfcn" with uipanels (bug #46151) * Canvas.cc (Canvas::canvasMouseMoveEvent): decide here to update the currentpoint and run "windowbuttonmotionfcn" if the latter is not empty * Canvas.h: remove unused "enableCurrentPointUpdates" method and "m_updateCurrentPoint" attribute * Figure.h: declare a new private method "enableMouseTracking" * Figure.cc (Figure::Figure): use "enableMouseTracking" instead of "update" on "windowbuttonmotionfcn". * Figure.cc (Figure::update): mouse tracking is now enabled unconditionally so remove unused case "windowbuttonmotionfcn". *Figure.cc(Figure::eventNotifyAfter): enable mouse tracking on new children widgets. diff -r 3af34e1ef330 -r 46edfbd31ad7 libgui/graphics/Canvas.cc --- a/libgui/graphics/Canvas.cc Fri Oct 09 16:25:27 2015 +0200 +++ b/libgui/graphics/Canvas.cc Sat Oct 10 12:21:37 2015 +0200 @@ -507,7 +507,7 @@ break; } } - else if (m_mouseMode == NoMode && m_updateCurrentPoint) + else if (m_mouseMode == NoMode) { graphics_object obj = gh_manager::get_object (m_handle); @@ -515,9 +515,13 @@ { graphics_object figObj (obj.get_ancestor ("figure")); - updateCurrentPoint (figObj, obj, event); - gh_manager::post_callback (figObj.get_handle (), - "windowbuttonmotionfcn"); + if (figObj.valid_object () && + ! figObj.get ("windowbuttonmotionfcn").is_empty ()) + { + updateCurrentPoint (figObj, obj, event); + gh_manager::post_callback (figObj.get_handle (), + "windowbuttonmotionfcn"); + } } } diff -r 3af34e1ef330 -r 46edfbd31ad7 libgui/graphics/Canvas.h --- a/libgui/graphics/Canvas.h Fri Oct 09 16:25:27 2015 +0200 +++ b/libgui/graphics/Canvas.h Sat Oct 10 12:21:37 2015 +0200 @@ -70,7 +70,6 @@ virtual void toggleAxes (const graphics_handle& handle) = 0; virtual void toggleGrid (const graphics_handle& handle) = 0; virtual void autoAxes (const graphics_handle& handle) = 0; - void enableCurrentPointUpdates (bool on) { m_updateCurrentPoint = on; } protected: virtual void draw (const graphics_handle& handle) = 0; @@ -86,8 +85,7 @@ m_mouseMode (NoMode), m_clickMode (false), m_eventMask (0), - m_rectMode (false), - m_updateCurrentPoint (false) + m_rectMode (false) { } void canvasToggleAxes (const graphics_handle& handle); @@ -122,7 +120,6 @@ graphics_handle m_mouseAxes; int m_eventMask; bool m_rectMode; - bool m_updateCurrentPoint; }; }; // namespace QtHandles diff -r 3af34e1ef330 -r 46edfbd31ad7 libgui/graphics/Figure.cc --- a/libgui/graphics/Figure.cc Fri Oct 09 16:25:27 2015 +0200 +++ b/libgui/graphics/Figure.cc Sat Oct 10 12:21:37 2015 +0200 @@ -132,11 +132,6 @@ figure::properties& fp = properties
(); - // Enable mouse tracking - m_container->setMouseTracking (true); - foreach (QWidget* w, m_container->findChildren ()) - { w->setMouseTracking (true); } - // Status bar m_statusBar = win->statusBar (); int boffset = 0; @@ -168,6 +163,9 @@ win->setGeometry (m_innerRect.adjusted (0, -toffset, 0, boffset)); + // Enable mouse tracking unconditionally + enableMouseTracking (); + // When this constructor gets called all properties are already // set, even non default. We force "update" here to get things right. @@ -179,10 +177,6 @@ update (figure::properties::ID_KEYPRESSFCN); update (figure::properties::ID_KEYRELEASEFCN); - // Decide if the "currentpoint" is updated on mouse movements and - // if the windowbuttonmotionfcn is executed - update (figure::properties::ID_WINDOWBUTTONMOTIONFCN); - // Visibility update (figure::properties::ID_VISIBLE); @@ -485,14 +479,6 @@ m_container->canvas (m_handle)->addEventMask (Canvas::KeyRelease); break; - case figure::properties::ID_WINDOWBUTTONMOTIONFCN: - { - bool hasCallback = ! fp.get_windowbuttonmotionfcn ().is_empty (); - - m_container->canvas (m_handle)->enableCurrentPointUpdates (hasCallback); - } - break; - default: break; } @@ -733,6 +719,8 @@ { gh_manager::auto_lock lock; update (figure::properties::ID_TOOLBAR); + + enableMouseTracking (); } default: @@ -981,4 +969,14 @@ canvas->autoAxes (m_handle); } +void +Figure::enableMouseTracking (void) +{ + // Enable mouse tracking on every widgets + m_container->setMouseTracking (true); + m_container->canvas (m_handle)->qWidget ()->setMouseTracking (true); + foreach (QWidget* w, m_container->findChildren ()) + { w->setMouseTracking (true); } +} + }; // namespace QtHandles diff -r 3af34e1ef330 -r 46edfbd31ad7 libgui/graphics/Figure.h --- a/libgui/graphics/Figure.h Fri Oct 09 16:25:27 2015 +0200 +++ b/libgui/graphics/Figure.h Sat Oct 10 12:21:37 2015 +0200 @@ -113,6 +113,8 @@ void save_figure_callback (const std::string& file); void copy_figure_callback (const std::string& format); + void enableMouseTracking (void); + private slots: void setMouseMode (MouseMode mode); void fileSaveFigure (bool prompt = false);