Mercurial > octave-nkf
diff libgui/graphics/Canvas.cc @ 20305:062422f2e399
Show axes coordinates in Qt figures (bug #44959)
* Canvas.h: new private bool member m_updtaCurrentPoint, to decide wether update the figure "currentpoint" property
* Canvas.h (Canvas::enableCurrentPointUpdates): new method to set m_updtaCurrentPoint
* Canvas.cc (Canvas::canvasMousePressEvent): move the code for axes/object selection in a dedicated method and call this method (select_object) instead.
* Canvas.cc (Canvas::select_object): new method for axes/object selection.
* Canvas.cc (Canvas::canvasMouseMoveEvent): update the parent figure status bar with the hovered axes coordinates
* Figure.h: declare new method updateStatusBar
* Figure.h: declare new private QStatusBar member m_statusBar. Include QStatusBar.h
* Figure.cc (Figure::Figure): unconditionally enable mouse traching
* Figure.cc (Figure::Figure): add status below of the canvas
* Figure.cc (Figure::update): take status bar into account when updating the figure position
* Figure.cc (Figure::update): remove some of the leftover debug comments
* Figure.cc: define new method updateStatusBar
author | Pantxo Diribarne <pantxo.diribarne@gmail.com> |
---|---|
date | Sat, 13 Jun 2015 13:27:01 +0200 |
parents | a5f9bf4df254 |
children | 64f6d0543626 |
line wrap: on
line diff
--- a/libgui/graphics/Canvas.cc Sat Jun 20 16:00:50 2015 -0700 +++ b/libgui/graphics/Canvas.cc Sat Jun 13 13:27:01 2015 +0200 @@ -395,6 +395,63 @@ return zm.contents ("Direction").string_value (); } +void +Canvas::select_object (graphics_object obj, QMouseEvent* event, + graphics_object ¤tObj, graphics_object &axesObj) +{ + QList<graphics_object> axesList; + Matrix children = obj.get_properties ().get_all_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")) + axesList.append (childObj); + else if (childObj.isa ("uicontrol") || childObj.isa ("uipanel")) + { + Matrix bb = childObj.get_properties ().get_boundingbox (false); + QRectF r (bb(0), bb(1), bb(2), bb(3)); + + r.adjust (-5, -5, 5, 5); + if (r.contains (event->posF ())) + { + currentObj = childObj; + break; + } + } + } + + if (! currentObj) + { + for (QList<graphics_object>::ConstIterator it = axesList.begin (); + it != axesList.end (); ++it) + { + graphics_object go = selectFromAxes (*it, event->pos ()); + + if (go) + { + currentObj = go; + axesObj = *it; + } + // FIXME: is this really necessary? the axes object should + // have been selected through selectFromAxes anyway + else if (it->get_properties ().is_hittest ()) + { + Matrix bb = it->get_properties ().get_boundingbox (true); + QRectF r (bb(0), bb(1), bb(2), bb(3)); + + if (r.contains (event->posF ())) + axesObj = *it; + } + + if (axesObj && currentObj) + break; + } + } +} + void Canvas::canvasMouseMoveEvent (QMouseEvent* event) { @@ -452,7 +509,7 @@ break; } } - else if (m_mouseMode == NoMode) + else if (m_mouseMode == NoMode && m_updateCurrentPoint) { graphics_object obj = gh_manager::get_object (m_handle); @@ -465,6 +522,23 @@ "windowbuttonmotionfcn"); } } + + // Update mouse coordinates in the figure window status bar + graphics_object obj = gh_manager::get_object (m_handle); + + if (obj.valid_object ()) + { + graphics_object currentObj, axesObj; + select_object (obj, event, currentObj, axesObj); + + if (axesObj.valid_object ()) + { + Figure* fig = + dynamic_cast<Figure*> (Backend::toolkitObject (obj)); + axes::properties& ap = Utils::properties<axes> (axesObj); + fig->updateStatusBar (ap.pixel2coord (event->x (), event->y ())); + } + } } void @@ -512,66 +586,16 @@ { graphics_object figObj (obj.get_ancestor ("figure")); graphics_object currentObj, axesObj; - QList<graphics_object> axesList; - - Matrix children = obj.get_properties ().get_all_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))); + + select_object (obj, event, currentObj, axesObj); - if (childObj.isa ("axes")) - axesList.append (childObj); - else if (childObj.isa ("uicontrol") || childObj.isa ("uipanel")) - { - Matrix bb = childObj.get_properties ().get_boundingbox (false); - QRectF r (bb(0), bb(1), bb(2), bb(3)); - - r.adjust (-5, -5, 5, 5); - if (r.contains (event->posF ())) - { - currentObj = childObj; - break; - } - } - } - - if (! currentObj) + if (axesObj) { - for (QList<graphics_object>::ConstIterator it = axesList.begin (); - it != axesList.end (); ++it) - { - graphics_object go = selectFromAxes (*it, event->pos ()); - - if (go) - { - currentObj = go; - axesObj = *it; - } - // FIXME: is this really necessary? the axes object should - // have been selected through selectFromAxes anyway - else if (it->get_properties ().is_hittest ()) - { - Matrix bb = it->get_properties ().get_boundingbox (true); - QRectF r (bb(0), bb(1), bb(2), bb(3)); - - if (r.contains (event->posF ())) - axesObj = *it; - } - - if (axesObj && currentObj) - break; - } - - if (axesObj) - { - if (axesObj.get_properties ().handlevisibility_is ("on")) - Utils::properties<figure> (figObj) - .set_currentaxes (axesObj.get_handle ().as_octave_value ()); - if (! currentObj) - currentObj = axesObj; - } + if (axesObj.get_properties ().handlevisibility_is ("on")) + Utils::properties<figure> (figObj) + .set_currentaxes (axesObj.get_handle ().as_octave_value ()); + if (! currentObj) + currentObj = axesObj; } if (! currentObj)