# HG changeset patch
# User Pantxo Diribarne
# Date 1525037240 -7200
# Sun Apr 29 23:27:20 2018 +0200
# Node ID e0227b7e1de9557d0b26a6ea336469a6c6031c38
# Parent 70e24005cc3f6d26ffa89114f5c3117e179963b9
Use uimenu objects for default menus in Qt toolkit
* Menu.cc (Menu::Menu): use QAction name to tag wether a menu is a builtin
or a custom menu based on the uimenu "tag" property.
* Figure.cc (hasUiMenuChildren): Remove
(Figure::editCopy,Figure::fileCloseFigure,Figure::fileSaveFigureAs,
Figure::copy_figure_callback, Figure::save_figure_callback): Remove
(Figure::createFigureToolBarAndMenuBar): Don't create menus not backed by
uimenu objects
(Figure::showMenuBar): Make use of the QAction name for menu triage. Use the
difference between previous and current menubar height to adjust the figure
position.
* __add_default_menu__.m: Create default menus for Qt aswell. Change actions
in the "Edit" menu to "Tools" menu. Add a few actions in "Edit" menu. Rename
uimenu handles to hui as is conventional in Octave code.
* clf.m: With "reset" option, don't unnecessarily delete/recreate default menus.
diff -r 70e24005cc3f -r e0227b7e1de9 libgui/graphics/Figure.cc
--- a/libgui/graphics/Figure.cc Thu Apr 26 18:59:12 2018 +0200
+++ b/libgui/graphics/Figure.cc Sun Apr 29 23:27:20 2018 +0200
@@ -82,25 +82,6 @@
return false;
}
- static bool
- hasUiMenuChildren (const figure::properties& fp)
- {
- gh_manager::auto_lock lock;
-
- Matrix kids = fp.get_all_children ();
-
- for (int i = 0; i < kids.numel (); i++)
- {
- graphics_object go (gh_manager::get_object (kids(i)));
-
- if (go && go.isa ("uimenu") &&
- go.get ("visible").string_value () == "on")
- return true;
- }
-
- return false;
- }
-
static QRect
boundingBoxToRect (const Matrix& bb)
{
@@ -154,9 +135,7 @@
m_statusBar->hide ();
}
- if (fp.menubar_is ("figure") || hasUiMenuChildren (fp))
- toffset += m_menuBar->sizeHint ().height ();
- else
+ if (! fp.menubar_is ("figure"))
m_menuBar->hide ();
m_innerRect = boundingBoxToRect (fp.get_boundingbox (true));
@@ -319,27 +298,6 @@
m_menuBar = new MenuBar (win);
win->setMenuBar (m_menuBar);
-
- QMenu *fileMenu = m_menuBar->addMenu (tr ("&File"));
- fileMenu->menuAction ()->setObjectName ("builtinMenu");
- fileMenu->addAction (tr ("&Save"), this, SLOT (fileSaveFigure (bool)));
- fileMenu->addAction (tr ("Save &As"), this, SLOT (fileSaveFigureAs (void)));
- fileMenu->addSeparator ();
- fileMenu->addAction (tr ("&Close Figure"), this,
- SLOT (fileCloseFigure (void)), Qt::CTRL | Qt::Key_W);
-
- QMenu *editMenu = m_menuBar->addMenu (tr ("&Edit"));
- editMenu->menuAction ()->setObjectName ("builtinMenu");
- editMenu->addAction (tr ("Cop&y"), this, SLOT (editCopy (bool)),
- Qt::CTRL | Qt::Key_C);
- editMenu->addSeparator ();
- editMenu->addActions (m_mouseModeGroup->actions ());
-
- QMenu *helpMenu = m_menuBar->addMenu (tr ("&Help"));
- helpMenu->menuAction ()->setObjectName ("builtinMenu");
- helpMenu->addAction (tr ("About Octave"), this,
- SLOT (helpAboutOctave (void)));
-
m_menuBar->addReceiver (this);
}
@@ -568,35 +526,36 @@
Figure::showMenuBar (bool visible, int h1)
{
// Get the height before and after toggling the visibility of builtin menus
- if (h1 <= 0)
+ if (h1 < 0)
h1 = m_menuBar->sizeHint ().height ();
+ // Keep the menubar visible if it contains custom menus
+ bool keep_visible = visible;
foreach (QAction *a, m_menuBar->actions ())
if (a->objectName () == "builtinMenu")
a->setVisible (visible);
+ else if ((a->objectName () == "customMenu") && a->isVisible ())
+ keep_visible = true;
+
+ visible = keep_visible;
int h2 = m_menuBar->sizeHint ().height ();
-
- // Keep the menubar visible if it contains custom menus
- if (! visible)
- visible = hasUiMenuChildren (properties