comparison libgui/graphics/Canvas.cc @ 18614:1f8ce7be9c00 gui-release

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 fb96b7f55242
children fe0e34be5576
comparison
equal deleted inserted replaced
18611:086093fbdc1a 18614:1f8ce7be9c00
47 } 47 }
48 48
49 void Canvas::blockRedraw (bool block) 49 void Canvas::blockRedraw (bool block)
50 { 50 {
51 m_redrawBlocked = block; 51 m_redrawBlocked = block;
52 }
53
54 void Canvas::updateCurrentPoint(const graphics_object& fig,
55 const graphics_object& obj, QMouseEvent* event)
56 {
57 gh_manager::post_set (fig.get_handle (), "currentpoint",
58 Utils::figureCurrentPoint (fig, event), false);
59
60 Matrix children = obj.get_properties ().get_children ();
61 octave_idx_type num_children = children.numel ();
62
63 for (int i = 0; i < num_children; i++)
64 {
65 graphics_object childObj (gh_manager::get_object (children(i)));
66
67 if (childObj.isa ("axes"))
68 {
69 axes::properties& ap = Utils::properties<axes> (childObj);
70 Matrix x_zlim = ap.get_transform_zlim ();
71 graphics_xform x_form = ap.get_transform ();
72
73 ColumnVector p1 = x_form.untransform (event->x (), event->y (),
74 x_zlim(0));
75 ColumnVector p2 = x_form.untransform (event->x (), event->y (),
76 x_zlim(1));
77
78 Matrix cp (2, 3, 0.0);
79
80 cp(0,0) = p1(0); cp(0,1) = p1(1); cp(0,2) = p1(2);
81 cp(1,0) = p2(0); cp(1,1) = p2(1); cp(1,2) = p2(2);
82
83 gh_manager::post_set (childObj.get_handle (), "currentpoint", cp,
84 false);
85 }
86 }
52 } 87 }
53 88
54 void Canvas::canvasPaintEvent (void) 89 void Canvas::canvasPaintEvent (void)
55 { 90 {
56 if (! m_redrawBlocked) 91 if (! m_redrawBlocked)
132 break; 167 break;
133 default: 168 default:
134 break; 169 break;
135 } 170 }
136 } 171 }
172 else if (m_mouseMode == NoMode)
173 {
174 graphics_object obj = gh_manager::get_object (m_handle);
175
176 if (obj.valid_object ())
177 {
178 graphics_object figObj (obj.get_ancestor ("figure"));
179
180 updateCurrentPoint (figObj, obj, event);
181 gh_manager::post_callback (figObj.get_handle (),
182 "windowbuttonmotionfcn");
183 }
184 }
137 } 185 }
138 186
139 void Canvas::canvasMousePressEvent (QMouseEvent* event) 187 void Canvas::canvasMousePressEvent (QMouseEvent* event)
140 { 188 {
141 gh_manager::auto_lock lock; 189 gh_manager::auto_lock lock;
226 switch (newMouseMode) 274 switch (newMouseMode)
227 { 275 {
228 case NoMode: 276 case NoMode:
229 gh_manager::post_set (figObj.get_handle (), "selectiontype", 277 gh_manager::post_set (figObj.get_handle (), "selectiontype",
230 Utils::figureSelectionType (event), false); 278 Utils::figureSelectionType (event), false);
231 gh_manager::post_set (figObj.get_handle (), "currentpoint", 279 updateCurrentPoint (figObj, obj, event);
232 Utils::figureCurrentPoint (figObj, event),
233 false);
234 gh_manager::post_callback (figObj.get_handle (), 280 gh_manager::post_callback (figObj.get_handle (),
235 "windowbuttondownfcn"); 281 "windowbuttondownfcn");
236 gh_manager::post_callback (currentObj.get_handle (), 282 gh_manager::post_callback (currentObj.get_handle (),
237 "buttondownfcn"); 283 "buttondownfcn");
238 if (event->button () == Qt::RightButton) 284 if (event->button () == Qt::RightButton)
319 365
320 if (obj.valid_object ()) 366 if (obj.valid_object ())
321 { 367 {
322 graphics_object figObj (obj.get_ancestor ("figure")); 368 graphics_object figObj (obj.get_ancestor ("figure"));
323 369
324 gh_manager::post_set (figObj.get_handle (), "currentpoint", 370 updateCurrentPoint (figObj, obj, event);
325 Utils::figureCurrentPoint (figObj, event),
326 false);
327 gh_manager::post_callback (figObj.get_handle (), 371 gh_manager::post_callback (figObj.get_handle (),
328 "windowbuttonupfcn"); 372 "windowbuttonupfcn");
329 } 373 }
330 } 374 }
331 375