Mercurial > octave-nkf
comparison libgui/graphics/Figure.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 | 4c2d39de1e96 |
children | b6ae0ef9327e |
comparison
equal
deleted
inserted
replaced
20302:ce8fda51d236 | 20305:062422f2e399 |
---|---|
127 : Object (go, win), m_blockUpdates (false), m_figureToolBar (0), | 127 : Object (go, win), m_blockUpdates (false), m_figureToolBar (0), |
128 m_menuBar (0), m_innerRect (), m_outerRect (), m_mouseModeGroup (0) | 128 m_menuBar (0), m_innerRect (), m_outerRect (), m_mouseModeGroup (0) |
129 { | 129 { |
130 m_container = new Container (win); | 130 m_container = new Container (win); |
131 win->setCentralWidget (m_container); | 131 win->setCentralWidget (m_container); |
132 | 132 |
133 figure::properties& fp = properties<figure> (); | 133 figure::properties& fp = properties<figure> (); |
134 | 134 |
135 // Enable mouse tracking | |
136 m_container->setMouseTracking (true); | |
137 foreach (QWidget* w, m_container->findChildren<QWidget*> ()) | |
138 { w->setMouseTracking (true); } | |
139 | |
140 // Status bar | |
141 m_statusBar = win->statusBar (); | |
142 m_statusBar->setVisible (true); | |
143 int boffset = m_statusBar->sizeHint ().height (); | |
144 | |
145 | |
146 // Toolbar and menubar | |
135 createFigureToolBarAndMenuBar (); | 147 createFigureToolBarAndMenuBar (); |
136 | 148 int toffset = 0; |
137 int offset = 0; | 149 |
138 if (fp.toolbar_is ("figure") || | 150 if (fp.toolbar_is ("figure") || |
139 (fp.toolbar_is ("auto") && fp.menubar_is ("figure") && | 151 (fp.toolbar_is ("auto") && fp.menubar_is ("figure") && |
140 ! hasUiControlChildren (fp))) | 152 ! hasUiControlChildren (fp))) |
141 offset += m_figureToolBar->sizeHint ().height (); | 153 toffset += m_figureToolBar->sizeHint ().height (); |
142 else | 154 else |
143 m_figureToolBar->hide (); | 155 m_figureToolBar->hide (); |
144 if (fp.menubar_is ("figure") || hasUiMenuChildren (fp)) | 156 if (fp.menubar_is ("figure") || hasUiMenuChildren (fp)) |
145 offset += m_menuBar->sizeHint ().height () + 1; | 157 toffset += m_menuBar->sizeHint ().height () + 1; |
146 else | 158 else |
147 m_menuBar->hide (); | 159 m_menuBar->hide (); |
148 | 160 |
149 m_innerRect = boundingBoxToRect (fp.get_boundingbox (true)); | 161 m_innerRect = boundingBoxToRect (fp.get_boundingbox (true)); |
150 m_outerRect = boundingBoxToRect (fp.get_boundingbox (false)); | 162 m_outerRect = boundingBoxToRect (fp.get_boundingbox (false)); |
151 | 163 |
152 //qDebug () << "Figure::Figure:" << m_innerRect; | 164 //qDebug () << "Figure::Figure:" << m_innerRect; |
153 win->setGeometry (m_innerRect.adjusted (0, -offset, 0, 0)); | 165 win->setGeometry (m_innerRect.adjusted (0, -toffset, 0, boffset)); |
154 //qDebug () << "Figure::Figure(adjusted)" << m_innerRect.adjusted (0, -offset, 0, 0); | 166 //qDebug () << "Figure::Figure(adjusted)" << m_innerRect.adjusted (0, -offset, 0, 0); |
155 win->setWindowTitle (Utils::fromStdString (fp.get_title ())); | 167 win->setWindowTitle (Utils::fromStdString (fp.get_title ())); |
156 | 168 |
157 int eventMask = 0; | 169 int eventMask = 0; |
158 if (! fp.get_keypressfcn ().is_empty ()) | 170 if (! fp.get_keypressfcn ().is_empty ()) |
409 switch (pId) | 421 switch (pId) |
410 { | 422 { |
411 case figure::properties::ID_POSITION: | 423 case figure::properties::ID_POSITION: |
412 { | 424 { |
413 m_innerRect = boundingBoxToRect (fp.get_boundingbox (true)); | 425 m_innerRect = boundingBoxToRect (fp.get_boundingbox (true)); |
414 //qDebug () << "Figure::update(position):" << m_innerRect; | 426 int toffset = 0; |
415 int offset = 0; | 427 int boffset = 0; |
416 | 428 |
417 foreach (QToolBar* tb, win->findChildren<QToolBar*> ()) | 429 foreach (QToolBar* tb, win->findChildren<QToolBar*> ()) |
418 if (! tb->isHidden ()) | 430 if (! tb->isHidden ()) |
419 offset += tb->sizeHint ().height (); | 431 toffset += tb->sizeHint ().height (); |
432 | |
420 if (! m_menuBar->isHidden ()) | 433 if (! m_menuBar->isHidden ()) |
421 offset += m_menuBar->sizeHint ().height () + 1; | 434 toffset += m_menuBar->sizeHint ().height () + 1; |
422 //qDebug () << "Figure::update(position)(adjusted):" << m_innerRect.adjusted (0, -offset, 0, 0); | 435 |
423 win->setGeometry (m_innerRect.adjusted (0, -offset, 0, 0)); | 436 if (! m_statusBar->isHidden ()) |
424 //qDebug () << "Figure::update(position): done"; | 437 boffset += m_statusBar->sizeHint ().height () + 1; |
438 | |
439 win->setGeometry (m_innerRect.adjusted (0, -toffset, 0, boffset)); | |
425 } | 440 } |
426 break; | 441 break; |
427 | 442 |
428 case figure::properties::ID_NAME: | 443 case figure::properties::ID_NAME: |
429 case figure::properties::ID_NUMBERTITLE: | 444 case figure::properties::ID_NUMBERTITLE: |
469 | 484 |
470 case figure::properties::ID_WINDOWBUTTONMOTIONFCN: | 485 case figure::properties::ID_WINDOWBUTTONMOTIONFCN: |
471 { | 486 { |
472 bool hasCallback = ! fp.get_windowbuttonmotionfcn ().is_empty (); | 487 bool hasCallback = ! fp.get_windowbuttonmotionfcn ().is_empty (); |
473 | 488 |
474 m_container->setMouseTracking (hasCallback); | 489 m_container->canvas (m_handle)->enableCurrentPointUpdates (hasCallback); |
475 foreach (QWidget* w, m_container->findChildren<QWidget*> ()) | |
476 { w->setMouseTracking (hasCallback); } | |
477 } | 490 } |
478 break; | 491 break; |
479 | 492 |
480 default: | 493 default: |
481 break; | 494 break; |
547 gh_manager::auto_lock lock; | 560 gh_manager::auto_lock lock; |
548 graphics_object go = object (); | 561 graphics_object go = object (); |
549 | 562 |
550 if (go.valid_object ()) | 563 if (go.valid_object ()) |
551 showMenuBar (Utils::properties<figure> (go).menubar_is ("figure")); | 564 showMenuBar (Utils::properties<figure> (go).menubar_is ("figure")); |
565 } | |
566 | |
567 void | |
568 Figure::updateStatusBar (ColumnVector pt) | |
569 { | |
570 if (! m_statusBar->isHidden ()) | |
571 m_statusBar->showMessage (QString ("(%1, %2)") | |
572 .arg (pt(0), 0, 'g', 5) | |
573 .arg (pt(1), 0, 'g', 5)); | |
552 } | 574 } |
553 | 575 |
554 QWidget* | 576 QWidget* |
555 Figure::menu (void) | 577 Figure::menu (void) |
556 { | 578 { |