Mercurial > octave-nkf
comparison 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 |
comparison
equal
deleted
inserted
replaced
20302:ce8fda51d236 | 20305:062422f2e399 |
---|---|
393 octave_scalar_map zm = ov_zm.scalar_map_value (); | 393 octave_scalar_map zm = ov_zm.scalar_map_value (); |
394 | 394 |
395 return zm.contents ("Direction").string_value (); | 395 return zm.contents ("Direction").string_value (); |
396 } | 396 } |
397 | 397 |
398 void | |
399 Canvas::select_object (graphics_object obj, QMouseEvent* event, | |
400 graphics_object ¤tObj, graphics_object &axesObj) | |
401 { | |
402 QList<graphics_object> axesList; | |
403 Matrix children = obj.get_properties ().get_all_children (); | |
404 octave_idx_type num_children = children.numel (); | |
405 | |
406 for (int i = 0; i < num_children; i++) | |
407 { | |
408 graphics_object childObj (gh_manager::get_object (children(i))); | |
409 | |
410 if (childObj.isa ("axes")) | |
411 axesList.append (childObj); | |
412 else if (childObj.isa ("uicontrol") || childObj.isa ("uipanel")) | |
413 { | |
414 Matrix bb = childObj.get_properties ().get_boundingbox (false); | |
415 QRectF r (bb(0), bb(1), bb(2), bb(3)); | |
416 | |
417 r.adjust (-5, -5, 5, 5); | |
418 if (r.contains (event->posF ())) | |
419 { | |
420 currentObj = childObj; | |
421 break; | |
422 } | |
423 } | |
424 } | |
425 | |
426 if (! currentObj) | |
427 { | |
428 for (QList<graphics_object>::ConstIterator it = axesList.begin (); | |
429 it != axesList.end (); ++it) | |
430 { | |
431 graphics_object go = selectFromAxes (*it, event->pos ()); | |
432 | |
433 if (go) | |
434 { | |
435 currentObj = go; | |
436 axesObj = *it; | |
437 } | |
438 // FIXME: is this really necessary? the axes object should | |
439 // have been selected through selectFromAxes anyway | |
440 else if (it->get_properties ().is_hittest ()) | |
441 { | |
442 Matrix bb = it->get_properties ().get_boundingbox (true); | |
443 QRectF r (bb(0), bb(1), bb(2), bb(3)); | |
444 | |
445 if (r.contains (event->posF ())) | |
446 axesObj = *it; | |
447 } | |
448 | |
449 if (axesObj && currentObj) | |
450 break; | |
451 } | |
452 } | |
453 } | |
454 | |
398 void | 455 void |
399 Canvas::canvasMouseMoveEvent (QMouseEvent* event) | 456 Canvas::canvasMouseMoveEvent (QMouseEvent* event) |
400 { | 457 { |
401 gh_manager::auto_lock lock; | 458 gh_manager::auto_lock lock; |
402 graphics_object ax = gh_manager::get_object (m_mouseAxes); | 459 graphics_object ax = gh_manager::get_object (m_mouseAxes); |
450 | 507 |
451 default: | 508 default: |
452 break; | 509 break; |
453 } | 510 } |
454 } | 511 } |
455 else if (m_mouseMode == NoMode) | 512 else if (m_mouseMode == NoMode && m_updateCurrentPoint) |
456 { | 513 { |
457 graphics_object obj = gh_manager::get_object (m_handle); | 514 graphics_object obj = gh_manager::get_object (m_handle); |
458 | 515 |
459 if (obj.valid_object ()) | 516 if (obj.valid_object ()) |
460 { | 517 { |
463 updateCurrentPoint (figObj, obj, event); | 520 updateCurrentPoint (figObj, obj, event); |
464 gh_manager::post_callback (figObj.get_handle (), | 521 gh_manager::post_callback (figObj.get_handle (), |
465 "windowbuttonmotionfcn"); | 522 "windowbuttonmotionfcn"); |
466 } | 523 } |
467 } | 524 } |
525 | |
526 // Update mouse coordinates in the figure window status bar | |
527 graphics_object obj = gh_manager::get_object (m_handle); | |
528 | |
529 if (obj.valid_object ()) | |
530 { | |
531 graphics_object currentObj, axesObj; | |
532 select_object (obj, event, currentObj, axesObj); | |
533 | |
534 if (axesObj.valid_object ()) | |
535 { | |
536 Figure* fig = | |
537 dynamic_cast<Figure*> (Backend::toolkitObject (obj)); | |
538 axes::properties& ap = Utils::properties<axes> (axesObj); | |
539 fig->updateStatusBar (ap.pixel2coord (event->x (), event->y ())); | |
540 } | |
541 } | |
468 } | 542 } |
469 | 543 |
470 void | 544 void |
471 Canvas::canvasMouseDoubleClickEvent (QMouseEvent* event) | 545 Canvas::canvasMouseDoubleClickEvent (QMouseEvent* event) |
472 { | 546 { |
510 | 584 |
511 if (obj.valid_object ()) | 585 if (obj.valid_object ()) |
512 { | 586 { |
513 graphics_object figObj (obj.get_ancestor ("figure")); | 587 graphics_object figObj (obj.get_ancestor ("figure")); |
514 graphics_object currentObj, axesObj; | 588 graphics_object currentObj, axesObj; |
515 QList<graphics_object> axesList; | 589 |
516 | 590 select_object (obj, event, currentObj, axesObj); |
517 Matrix children = obj.get_properties ().get_all_children (); | 591 |
518 octave_idx_type num_children = children.numel (); | 592 if (axesObj) |
519 | 593 { |
520 for (int i = 0; i < num_children; i++) | 594 if (axesObj.get_properties ().handlevisibility_is ("on")) |
521 { | 595 Utils::properties<figure> (figObj) |
522 graphics_object childObj (gh_manager::get_object (children(i))); | 596 .set_currentaxes (axesObj.get_handle ().as_octave_value ()); |
523 | 597 if (! currentObj) |
524 if (childObj.isa ("axes")) | 598 currentObj = axesObj; |
525 axesList.append (childObj); | |
526 else if (childObj.isa ("uicontrol") || childObj.isa ("uipanel")) | |
527 { | |
528 Matrix bb = childObj.get_properties ().get_boundingbox (false); | |
529 QRectF r (bb(0), bb(1), bb(2), bb(3)); | |
530 | |
531 r.adjust (-5, -5, 5, 5); | |
532 if (r.contains (event->posF ())) | |
533 { | |
534 currentObj = childObj; | |
535 break; | |
536 } | |
537 } | |
538 } | |
539 | |
540 if (! currentObj) | |
541 { | |
542 for (QList<graphics_object>::ConstIterator it = axesList.begin (); | |
543 it != axesList.end (); ++it) | |
544 { | |
545 graphics_object go = selectFromAxes (*it, event->pos ()); | |
546 | |
547 if (go) | |
548 { | |
549 currentObj = go; | |
550 axesObj = *it; | |
551 } | |
552 // FIXME: is this really necessary? the axes object should | |
553 // have been selected through selectFromAxes anyway | |
554 else if (it->get_properties ().is_hittest ()) | |
555 { | |
556 Matrix bb = it->get_properties ().get_boundingbox (true); | |
557 QRectF r (bb(0), bb(1), bb(2), bb(3)); | |
558 | |
559 if (r.contains (event->posF ())) | |
560 axesObj = *it; | |
561 } | |
562 | |
563 if (axesObj && currentObj) | |
564 break; | |
565 } | |
566 | |
567 if (axesObj) | |
568 { | |
569 if (axesObj.get_properties ().handlevisibility_is ("on")) | |
570 Utils::properties<figure> (figObj) | |
571 .set_currentaxes (axesObj.get_handle ().as_octave_value ()); | |
572 if (! currentObj) | |
573 currentObj = axesObj; | |
574 } | |
575 } | 599 } |
576 | 600 |
577 if (! currentObj) | 601 if (! currentObj) |
578 currentObj = obj; | 602 currentObj = obj; |
579 | 603 |