Mercurial > hg > octave-nkf
changeset 18760:9597e00ed2dd
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.
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Tue, 01 Apr 2014 20:57:08 -0400 |
parents | 0ede4dbb37f1 |
children | 1b6f5917ae4b |
files | libgui/graphics/BaseControl.cc libgui/graphics/Canvas.cc libgui/graphics/Canvas.h libgui/graphics/Container.cc libgui/graphics/Container.h libgui/graphics/Figure.cc libgui/graphics/Panel.cc |
diffstat | 7 files changed, 98 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/graphics/BaseControl.cc +++ b/libgui/graphics/BaseControl.cc @@ -195,6 +195,20 @@ } } break; + case QEvent::MouseMove: + if (qWidget<QWidget> ()->hasMouseTracking ()) + { + gh_manager::auto_lock lock; + + QMouseEvent* m = dynamic_cast<QMouseEvent*> (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) {
--- a/libgui/graphics/Canvas.cc +++ b/libgui/graphics/Canvas.cc @@ -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<axes> (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"); }
--- a/libgui/graphics/Canvas.h +++ b/libgui/graphics/Canvas.h @@ -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;
--- a/libgui/graphics/Container.cc +++ b/libgui/graphics/Container.cc @@ -24,6 +24,7 @@ #include <config.h> #endif +#include <QChildEvent> #include <QVBoxLayout> #include "graphics.h" @@ -95,4 +96,12 @@ } } +void Container::childEvent (QChildEvent* event) +{ + if (event->child ()->isWidgetType ()) + { + qobject_cast<QWidget*> (event->child ())->setMouseTracking (hasMouseTracking ()); + } +} + }; // namespace QtHandles
--- a/libgui/graphics/Container.h +++ b/libgui/graphics/Container.h @@ -45,6 +45,7 @@ Canvas* canvas (const graphics_handle& handle, bool create = true); protected: + void childEvent (QChildEvent* event); void resizeEvent (QResizeEvent* event); private:
--- a/libgui/graphics/Figure.cc +++ b/libgui/graphics/Figure.cc @@ -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<QWidget*> ()) + { w->setMouseTracking (hasCallback); } + } + break; default: break; }
--- a/libgui/graphics/Panel.cc +++ b/libgui/graphics/Panel.cc @@ -115,6 +115,12 @@ m_container = new Container (frame); m_container->canvas (m_handle); + if (frame->hasMouseTracking ()) + { + foreach (QWidget* w, frame->findChildren<QWidget*> ()) + { w->setMouseTracking (true); } + } + QString title = Utils::fromStdString (pp.get_title ()); if (! title.isEmpty ()) {