void MacMenu::popup(qlonglong key, int idx, int x, int y) { QMenuBar *menu = menuBar(key); if (!menu) return; QMenu *pop; for (int i = 0; i < menu->actions().count(); ++i) { if (!(pop = menu->actions().at(i)->menu())) continue; if (i == idx) { if (!pop->isVisible()) { connect (pop, SIGNAL(aboutToHide()), this, SLOT(menuClosed())); XBAR_SEND( MSG("setOpenPopup") << idx ); pop->popup(QPoint(x,y)); } else { XBAR_SEND( MSG("setOpenPopup") << -1000 ); pop->hide(); } } else pop->hide(); } }
void MacMenu::popDown(qlonglong key) { QMenuBar *menu = menuBar(key); if (!menu) return; QWidget *pop; for (int i = 0; i < menu->actions().count(); ++i) { if (!(pop = menu->actions().at(i)->menu())) continue; disconnect (pop, SIGNAL(aboutToHide()), this, SLOT(menuClosed())); pop->hide(); // menu->activateWindow(); break; } }
void MenuManager::retranslate() const { QMenuBar* menuBar = getMainWindow()->menuBar(); QList<QAction*> actions = menuBar->actions(); for (QList<QAction*>::Iterator it = actions.begin(); it != actions.end(); ++it) { if ((*it)->menu()) retranslate((*it)->menu()); } }
void MenuManager::setup(MenuItem* menuItems) const { if (!menuItems) return; // empty menu bar QMenuBar* menuBar = getMainWindow()->menuBar(); //menuBar->setUpdatesEnabled(false); QList<MenuItem*> items = menuItems->getItems(); QList<QAction*> actions = menuBar->actions(); for (QList<MenuItem*>::ConstIterator it = items.begin(); it != items.end(); ++it) { // search for the menu action QAction* action = findAction(actions, QString::fromAscii((*it)->command().c_str())); if (!action) { // There must be not more than one separator in the menu bar, so // we can safely remove it if available and append it at the end if ((*it)->command() == "Separator") { action = menuBar->addSeparator(); action->setObjectName(QLatin1String("Separator")); } else { // create a new menu std::string menuName = (*it)->command(); QMenu* menu = menuBar->addMenu( QApplication::translate("Workbench", menuName.c_str(), 0, QApplication::UnicodeUTF8)); action = menu->menuAction(); menu->setObjectName(QString::fromAscii(menuName.c_str())); action->setObjectName(QString::fromAscii(menuName.c_str())); } // set the menu user data action->setData(QString::fromAscii((*it)->command().c_str())); } else { // put the menu at the end menuBar->removeAction(action); menuBar->addAction(action); action->setVisible(true); int index = actions.indexOf(action); actions.removeAt(index); } // flll up the menu if (!action->isSeparator()) setup(*it, action->menu()); } // hide all menus which we don't need for the moment for (QList<QAction*>::Iterator it = actions.begin(); it != actions.end(); ++it) { (*it)->setVisible(false); } // enable update again //menuBar->setUpdatesEnabled(true); }
void QgsRasterTerrainAnalysisPlugin::initGui() { //create Action if ( mIface ) { //find raster menu QString rasterText = QCoreApplication::translate( "QgisApp", "&Raster" ); QMainWindow* mainWindow = qobject_cast<QMainWindow*>( mIface->mainWindow() ); if ( !mainWindow ) { return; } QMenuBar* menuBar = mainWindow->menuBar(); if ( !menuBar ) { return; } QMenu* rasterMenu = 0; QList<QAction *> menuBarActions = menuBar->actions(); QList<QAction *>::iterator menuActionIt = menuBarActions.begin(); for ( ; menuActionIt != menuBarActions.end(); ++menuActionIt ) { if (( *menuActionIt )->menu() && ( *menuActionIt )->menu()->title() == rasterText ) { rasterMenu = ( *menuActionIt )->menu(); rasterMenu->addSeparator(); break; } } if ( !rasterMenu ) { return; } mTerrainAnalysisMenu = new QMenu( tr( "Terrain analysis" ), rasterMenu ); mTerrainAnalysisMenu->setObjectName( "mTerrainAnalysisMenu" ); mTerrainAnalysisMenu->setIcon( QIcon( ":/raster/dem.png" ) ); QAction *slopeAction = mTerrainAnalysisMenu->addAction( tr( "Slope" ), this, SLOT( slope() ) ); slopeAction->setObjectName( "slopeAction" ); QAction *aspectAction = mTerrainAnalysisMenu->addAction( tr( "Aspect" ), this, SLOT( aspect() ) ); aspectAction->setObjectName( "aspectAction" ); QAction *hilshadeAction = mTerrainAnalysisMenu->addAction( tr( "Hillshade" ), this, SLOT( hillshade() ) ); hilshadeAction->setObjectName( "hilshadeAction" ); QAction *reliefAction = mTerrainAnalysisMenu->addAction( tr( "Relief" ), this, SLOT( relief() ) ); reliefAction->setObjectName( "reliefAction" ); QAction *ruggednesIndex = mTerrainAnalysisMenu->addAction( tr( "Ruggedness index" ), this, SLOT( ruggedness() ) ); ruggednesIndex->setObjectName( "ruggednesIndex" ); rasterMenu->addMenu( mTerrainAnalysisMenu ); } }
//@Override /*public*/ void AudioTableAction::setMenuBar(BeanTableFrame* f) { QMenuBar* menuBar = f->menuBar(); // ResourceBundle rbapps = ResourceBundle.getBundle("apps.AppsBundle"); QList<QAction*> subElements = menuBar->actions(); QMenu* fileMenu = nullptr; for (int i = 0; i < menuBar->actions().count(); i++) { //if (menuBar->actionAt(i) instanceof JMenu) if(qobject_cast<QMenu*>(menuBar->actions().at(i)) != nullptr) { if( ((QMenu*) menuBar->actions().at(i))->title()==(tr("File"))) { fileMenu = (QMenu*) menuBar->actions().at(i); } } } if (fileMenu == nullptr) { return; } subElements = fileMenu->actions(); for (int i = 0; i < subElements.length(); i++) { QList<QAction*> popsubElements = ((QMenu*)subElements.at(i))->actions(); for (int x = 0; x < popsubElements.length(); x++) { // if (popsubElements[x] instanceof JMenuItem) if(qobject_cast<QMenu*>(popsubElements.at(x))!= nullptr) { if (((QMenu*) popsubElements[x])->title()==(tr("Print Table")))\ { QMenu* printMenu = ((QMenu*) popsubElements[x]); fileMenu->removeAction((QAction*)printMenu); break; } } } } fileMenu->addAction(atp->getPrintItem()); }
void MacMenu::hover(qlonglong key, int idx, int x, int y) { QMenuBar *menu = menuBar(key); if (!menu) return; QWidget *pop; for (int i = 0; i < menu->actions().count(); ++i) { if ((i == idx) || !(pop = menu->actions().at(i)->menu())) continue; if (pop->isVisible()) { inHover = true; popup(key, idx, x, y); // TODO: this means a useless second pass above... inHover = false; break; } } }
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())); } } }
bool UIKeyboardHandlerNormal::eventFilter(QObject *pWatchedObject, QEvent *pEvent) { /* Check if pWatchedObject object is view: */ if (UIMachineView *pWatchedView = isItListenedView(pWatchedObject)) { /* Get corresponding screen index: */ ulong uScreenId = m_views.key(pWatchedView); NOREF(uScreenId); /* Handle view events: */ switch (pEvent->type()) { /* We don't want this on the Mac, cause there the menu-bar isn't within the * window and popping up a menu there looks really ugly. */ case QEvent::KeyPress: { /* Get key-event: */ QKeyEvent *pKeyEvent = static_cast<QKeyEvent*>(pEvent); /* Process Host+Home as menu-bar activator: */ if (isHostKeyPressed() && QKeySequence(pKeyEvent->key()) == gShortcutPool->shortcut(GUI_Input_MachineShortcuts, QString("PopupMenu")).sequence()) { /* Trying to get menu-bar: */ QMenuBar *pMenuBar = qobject_cast<QMainWindow*>(m_windows[uScreenId])->menuBar(); /* If menu-bar is present and have actions: */ if (pMenuBar && !pMenuBar->actions().isEmpty()) { /* Is menu-bar visible? */ if (pMenuBar->isVisible()) { /* If 'active' action is NOT chosen: */ if (!pMenuBar->activeAction()) /* Set first menu-bar action as 'active': */ pMenuBar->setActiveAction(pMenuBar->actions()[0]); /* If 'active' action is chosen: */ if (pMenuBar->activeAction()) { /* Activate 'active' menu-bar action: */ pMenuBar->activeAction()->activate(QAction::Trigger); #ifdef VBOX_WS_WIN /* Windows host needs separate 'focus set' * to let menubar operate while popped up: */ pMenuBar->setFocus(); #endif /* VBOX_WS_WIN */ } } else { /* Post request to show popup-menu: */ QTimer::singleShot(0, m_pMachineLogic, SLOT(sltInvokePopupMenu())); } /* Filter-out this event: */ return true; } } break; } default: break; } } /* Else just propagate to base-class: */ return UIKeyboardHandler::eventFilter(pWatchedObject, pEvent); }
void AcceleratorManagerPrivate::calculateAccelerators(Item *item, QString &used) { if (!item->m_children) return; // collect the contents AccelStringList contents; for (Item *it: *item->m_children) { contents << it->m_content; } // find the right accelerators AccelManagerAlgorithm::findAccelerators(contents, used); // write them back into the widgets int cnt = -1; for (Item *it: *item->m_children) { cnt++; QDockWidget *dock = qobject_cast<QDockWidget*>(it->m_widget); if (dock) { if (checkChange(contents[cnt])) dock->setWindowTitle(contents[cnt].accelerated()); continue; } QTabBar *tabBar = qobject_cast<QTabBar*>(it->m_widget); if (tabBar) { if (checkChange(contents[cnt])) tabBar->setTabText(it->m_index, contents[cnt].accelerated()); continue; } QMenuBar *menuBar = qobject_cast<QMenuBar*>(it->m_widget); if (menuBar) { if (it->m_index >= 0) { QAction *maction = menuBar->actions()[it->m_index]; if (maction) { checkChange(contents[cnt]); maction->setText(contents[cnt].accelerated()); } continue; } } // we possibly reserved an accel, but we won't set it as it looks silly QGroupBox *groupBox = qobject_cast<QGroupBox*>(it->m_widget); if (groupBox && !groupBox->isCheckable()) continue; int tprop = it->m_widget->metaObject()->indexOfProperty("text"); if (tprop != -1) { if (checkChange(contents[cnt])) it->m_widget->setProperty("text", contents[cnt].accelerated()); } else { tprop = it->m_widget->metaObject()->indexOfProperty("title"); if (tprop != -1 && checkChange(contents[cnt])) it->m_widget->setProperty("title", contents[cnt].accelerated()); } } // calculate the accelerators for the children for (Item *it: *item->m_children) { if (it->m_widget && it->m_widget->isVisibleTo( item->m_widget ) ) calculateAccelerators(it, used); } }
QList<QAction*> actions() const { return menu ? menu->actions() : menuBar->actions(); }