void MainWindowMenuManager::AddMenus (const QMap<QString, QList<QAction*>>& menus) { for (const auto& menuName : menus.keys ()) { QMenu *toInsert = nullptr; if (menuName == "view") toInsert = MenuView_; else if (menuName == "tools") toInsert = MenuTools_; else for (auto action : Menu_->actions ()) if (action->menu () && action->text () == menuName) { toInsert = action->menu (); break; } const auto& actions = menus [menuName]; if (toInsert) toInsert->insertActions (toInsert->actions ().value (0, 0), actions); else { auto menu = new QMenu { menuName, Menu_.get () }; menu->addActions (actions); Menu_->insertMenu (MenuTools_->menuAction (), menu); } IconThemeEngine::Instance ().UpdateIconset (actions); } }
void ActionLineEdit::contextMenuEvent(QContextMenuEvent *e) { QMenu *menu = createStandardContextMenu(); if (actions().count() > 0) { QAction *before = NULL; if (menu->actions().count() > 0) { before = menu->actions().first(); } menu->insertActions(before, actions()); menu->insertSeparator(before); } menu->exec(e->globalPos()); delete menu; }
void ProjectManager::createActions() { newProjectAct = new QAction(tr("New Project"),this); newProjectAct->setToolTip(tr("Create New Project")); connect(newProjectAct,SIGNAL(triggered()),this,SLOT(newProject())); openProjectAct = new QAction(tr("Open Project"),this); openProjectAct->setToolTip(tr("Open Project")); connect(openProjectAct,SIGNAL(triggered()),this,SLOT(openProject())); closeProjectAct = new QAction(tr("Close Project"),this); closeProjectAct->setToolTip(tr("Close Project")); connect(closeProjectAct,SIGNAL(triggered()),this,SLOT(closeProject())); QMenu *fileMenu = liteApp->mainWindow()->fileMenu(); QAction *seperator = fileMenu->insertSeparator(fileMenu->actions()[0]); fileMenu->insertActions(seperator,QList<QAction*>() << newProjectAct << openProjectAct << closeProjectAct); }
void QMenuProto::insertActions(QAction *before, QList<QAction *>actions) { QMenu *item = qscriptvalue_cast<QMenu*>(thisObject()); if (item) item->insertActions(before, actions); }