void qt_tm_widget_rep::install_main_menu () { main_menu_widget = waiting_main_menu_widget; QMenu* src = main_menu_widget->get_qmenu(); if (!src) return; // REMARK: We do not want the menubar shared across windows as suggested // in http://doc.qt.nokia.com/4.7/qmainwindow.html#menuBar // e.g. : // // QMenuBar *dest = new QMenuBar(0); // mainwindow()->setMenuBar(dest); // // as the default behavior on MacOS. The main reason is that in TeXmacs // different windows can have different main menus so that it is indeed // appropriate to change the main menu as the window focus changes. // So we kindly ask to each window to give us its own menu and we install // there our actions. // So we do: QMenuBar* dest = mainwindow()->menuBar(); // and everything is fine. // Also please note that we have to do the replacement and not simply // install the menu returned by get_qmenu() since the main menu there // could contain some default items appropriate for the given OS (like the // service menu on MacOS) which are not present in our menu widget. // UPDATE: But replaceActions() *does remove* all actions (!?) // It looks more like the reason is that we have to "flatten out" the first // level of the QMenu returned... ? replaceActions (dest, src); QList<QAction*> list = dest->actions(); for (int i = 0; i < list.count(); i++) { QAction* a = list[i]; if (a->menu()) { QObject::connect (a->menu(), SIGNAL (aboutToShow()), the_gui->gui_helper, SLOT (aboutToShowMainMenu())); QObject::connect (a->menu(), SIGNAL (aboutToHide()), the_gui->gui_helper, SLOT (aboutToHideMainMenu())); } } }
void qt_tm_widget_rep::install_main_menu () { if (main_menu_widget == waiting_main_menu_widget) return; main_menu_widget = waiting_main_menu_widget; QList<QAction*>* src = main_menu_widget->get_qactionlist(); if (!src) return; QMenuBar* dest = mainwindow()->menuBar(); dest->clear(); for (int i = 0; i < src->count(); i++) { QAction* a = (*src)[i]; if (a->menu()) { //TRICK: Mac native QMenuBar accepts only menus which are already populated // this will cause a problem for us, since menus are lazy and populated only after triggering // this is the reason we add a dummy action before inserting the menu a->menu()->addAction("native menubar trick"); dest->addAction(a->menu()->menuAction()); QObject::connect (a->menu(), SIGNAL (aboutToShow()), the_gui->gui_helper, SLOT (aboutToShowMainMenu())); QObject::connect (a->menu(), SIGNAL (aboutToHide()), the_gui->gui_helper, SLOT (aboutToHideMainMenu())); } } }