void QueuedUsers::slotContextMenu(){ QModelIndexList indexes = treeView_USERS->selectionModel()->selectedRows(0); if (indexes.isEmpty()) return; QMenu *m = new QMenu(this); m->addAction(tr("Grant slot")); if (m->exec(QCursor::pos())){ for (const auto &i : indexes){ QueuedUserItem *item = reinterpret_cast<QueuedUserItem*>(i.internalPointer()); if (!item) continue; QString id = item->cid; if (!id.isEmpty()){ UserPtr user = ClientManager::getInstance()->findUser(CID(id.toStdString())); if (user){ try { UploadManager::getInstance()->reserveSlot(HintedUser(user, _tq(item->hub))); } catch ( ... ) {} } } } } m->deleteLater(); }
void CGI_SCADA_DLL_TreeItemNET::GetPopUpMenu() { QMenu *SwitchMenu = new QMenu(); QAction *pAddLink = new QAction(tr("新建连接"), SwitchMenu); connect(pAddLink, SIGNAL(triggered()), this, SLOT(slot_AddLink())); QAction *pDeleteChannel = new QAction(tr("删除通道"), SwitchMenu); connect(pDeleteChannel, SIGNAL(triggered()), this, SLOT(slot_DeleteChannel())); QAction *pSetEnable = new QAction(tr("使能通道"), SwitchMenu); pSetEnable->setCheckable(true); if (this->isDisabled()) { pSetEnable->setChecked(false); }else { pSetEnable->setChecked(true); } // this->isDisabled(); connect(pSetEnable, SIGNAL(triggered(bool)), this, SLOT(slot_SetEnable(bool))); SwitchMenu->addAction(pAddLink); SwitchMenu->addAction(pDeleteChannel); SwitchMenu->addAction(pSetEnable); SwitchMenu->addSeparator(); SwitchMenu->exec(QCursor::pos()); // delete SwitchMenu;//防止内存泄露 SwitchMenu->deleteLater(); qDebug()<<__func__<<__LINE__<<__FILE__<<this->childCount(); return ; }
void Scene::contextMenuEvent(QGraphicsSceneContextMenuEvent * event) { event->accept(); QMenu* menu = new QMenu(); QAction *ImageInfoAction = menu->addAction(QIcon(":/info.svg"), tr("Image info")); connect(ImageInfoAction, SIGNAL(triggered()), this, SLOT(imageInfo())); menu->addSeparator(); QAction* rotateCWAction = menu->addAction(QIcon(":/rotateCW.svg"), tr("Rotate CW")); connect(rotateCWAction, SIGNAL(triggered()), this, SLOT(rotateCW())); QAction* rotateCCWAction = menu->addAction(QIcon(":/rotateCCW.svg"), tr("Rotate CCW")); connect(rotateCCWAction, SIGNAL(triggered()), this, SLOT(rotateCCW())); QAction* rotateHalfAction = menu->addAction(QIcon(":/rotateCCW.svg"), tr("Rotate 180°")); connect(rotateHalfAction, SIGNAL(triggered()), this, SLOT(rotateHalf())); QAction* detectOrientationAction = menu->addAction(QIcon(":/orientation.svg"), tr("Detect orientation")); detectOrientationAction->setToolTip( tr("Page orientation detection (four 90 degree angles)")); connect(detectOrientationAction, SIGNAL(triggered()), this, SLOT(detectOrientation())); menu->exec(event->screenPos()); menu->deleteLater(); }
void PublicHubs::slotContextMenu(){ QItemSelectionModel *sel_model = treeView->selectionModel(); QModelIndexList indexes = sel_model->selectedRows(0); if (indexes.isEmpty()) return; if (proxy) std::transform(indexes.begin(), indexes.end(), indexes.begin(), [&](QModelIndex i) { return proxy->mapToSource(i); }); WulforUtil *WU = WulforUtil::getInstance(); QMenu *m = new QMenu(); QAction *connect = new QAction(WU->getPixmap(WulforUtil::eiCONNECT), tr("Connect"), m); QAction *add_fav = new QAction(WU->getPixmap(WulforUtil::eiBOOKMARK_ADD), tr("Add to favorites"), m); QAction *copy = new QAction(WU->getPixmap(WulforUtil::eiEDITCOPY), tr("Copy &address to clipboard"), m); m->addActions(QList<QAction*>() << connect << add_fav << copy); QAction *ret = m->exec(QCursor::pos()); m->deleteLater(); if (ret == connect){ PublicHubItem * item = NULL; MainWindow *MW = MainWindow::getInstance(); foreach (const QModelIndex &i, indexes){ item = reinterpret_cast<PublicHubItem*>(i.internalPointer()); if (item) MW->newHubFrame(item->data(COLUMN_PHUB_ADDRESS).toString(), ""); item = NULL; }
void AddressWidget::contextMenuEvent(QContextMenuEvent *event) { const QString shortcut = QKeySequence(QKeySequence::Paste).toString(QKeySequence::NativeText); QMenu *menu = createStandardContextMenu(); bool found = false; if (!shortcut.isEmpty()) { for (int i = 0; i < menu->actions().count(); ++i) { if (menu->actions().at(i)->text().endsWith(shortcut)) { menu->insertAction(menu->actions().at(i + 1), ActionsManager::getAction(PasteAndGoAction)); found = true; break; } } } if (!found) { menu->insertAction(menu->actions().at(6), ActionsManager::getAction(PasteAndGoAction)); } menu->exec(event->globalPos()); menu->deleteLater(); }
void QMailTreeView::slotCustomContextMenu(const QPoint &pos) { QMenu *menu = new QMenu; menu->addAction(tr("delete"), this, SLOT(slotDeleteMailClicked())); menu->exec(QCursor::pos()); menu->deleteLater(); }
void DataSourceView::showContextMenu(const QPoint &point) { QModelIndex i = currentIndex(); if (!i.isValid()) return; QMenu *menu = new QMenu(this); menu->addAction(style()->standardIcon(QStyle::SP_DirOpenIcon), tr("Open"), this, SLOT(indexOpenPath())); menu->addAction(QIcon(":/gfx/tab-new.png"), tr("Open in a new tab"), this, SLOT(openInANewTab())); menu->addAction(QIcon(":/gfx/gohome.png"), tr("Set as working directory"), this, SLOT(setWorkingDirectory())); menu->addAction(style()->standardIcon(QStyle::SP_FileDialogNewFolder), tr("Create directory"), this, SLOT(createDirectory())); menu->addSeparator(); menu->addAction(QIcon(":/gfx/document-edit.png"), tr("Edit"), this, SLOT(editDirectory())); menu->addAction(QIcon(":/gfx/list-remove.png"), tr("Delete"), this, SLOT(deleteDirectory())); menu->addSeparator(); m_signalMapper->setMapping(menu->addAction(QIcon(":/gfx/external_programs/ZIMA-PTC-Cleaner.png"), tr("Clean with ZIMA-PTC-Cleaner"), m_signalMapper, SLOT(map())), ZimaUtils::internalNameForUtility(ZimaUtils::ZimaPtcCleaner)); m_signalMapper->setMapping(menu->addAction(QIcon(":/gfx/external_programs/ZIMA-CAD-Sync.png"), tr("Sync with ZIMA-CAD-Sync"), m_signalMapper, SLOT(map())), ZimaUtils::internalNameForUtility(ZimaUtils::ZimaCadSync)); m_signalMapper->setMapping(menu->addAction(QIcon(":/gfx/external_programs/ZIMA-PS2PDF.png"), tr("Convert postscript to PDF with ZIMA-PS2PDF"), m_signalMapper, SLOT(map())), ZimaUtils::internalNameForUtility(ZimaUtils::ZimaPs2Pdf)); m_signalMapper->setMapping(menu->addAction(QIcon(":/gfx/external_programs/ZIMA-STEP-Edit.png"), tr("Edit step files with ZIMA-STEP-Edit"), m_signalMapper, SLOT(map())), ZimaUtils::internalNameForUtility(ZimaUtils::ZimaStepEdit)); menu->exec(mapToGlobal(point)); menu->deleteLater(); }
void ViewportView::openAddMenu(bool view_commands) { QMenu* m = new QMenu(this); if (view_commands && !angle_locked) { auto sub = new QMenu("View"); connect(sub->addAction("Top"), &QAction::triggered, [=]{ this->spinTo(0, 0); }); connect(sub->addAction("Bottom"), &QAction::triggered, [=]{ this->spinTo(0, -M_PI); }); connect(sub->addAction("Left"), &QAction::triggered, [=]{ this->spinTo(M_PI/2, -M_PI/2); }); connect(sub->addAction("Right"), &QAction::triggered, [=]{ this->spinTo(-M_PI/2, -M_PI/2); }); connect(sub->addAction("Front"), &QAction::triggered, [=]{ this->spinTo(0, -M_PI/2); }); connect(sub->addAction("Back"), &QAction::triggered, [=]{ this->spinTo(-M_PI, -M_PI/2); }); m->addMenu(sub); m->addSeparator(); } populateNodeMenu(m, view_scene->getGraph()); m->exec(QCursor::pos()); m->deleteLater(); }
void InputTextWidget::showContextMenu(const QPoint &pos) { QPoint globalPos = mapToGlobal(pos); QMenu *contextMenu = new QMenu(this); contextMenu->addAction(actionUndo); contextMenu->addAction(actionRedo); contextMenu->addSeparator(); contextMenu->addAction(actionCut); contextMenu->addAction(actionCopy); contextMenu->addAction(actionPaste); // Disable cut and copy if nothing to copy if(textCursor().selection().isEmpty()) { actionCut->setDisabled(true); actionCopy->setDisabled(true); } // Disable paste if clipboard is empty if(QApplication::clipboard()->text().isEmpty()) { actionPaste->setDisabled(true); } contextMenu->exec(globalPos); contextMenu->deleteLater(); actionCut->setEnabled(true); actionCopy->setEnabled(true); actionPaste->setEnabled(true); }
void ToolBar::slotContextMenu(const QPoint &p){ int tab = tabbar->tabAt(p); ArenaWidget *awgt = findWidgetForIndex(tab); if (!awgt){ QMenu *m = new QMenu(this); QAction *act = new QAction(tr("Show close buttons"), m); act->setCheckable(true); act->setChecked(WBGET(WB_APP_TBAR_SHOW_CL_BTNS)); m->addAction(act); if (m->exec(QCursor::pos())){ WBSET(WB_APP_TBAR_SHOW_CL_BTNS, act->isChecked()); tabbar->setTabsClosable(act->isChecked()); } m->deleteLater(); return; } QMenu *m = awgt->getMenu(); if (m) m->exec(QCursor::pos()); }
void SideBarView::slotSidebarContextMenu(){ QItemSelectionModel *s_m = selectionModel(); QModelIndexList selected = s_m->selectedRows(0); if (selected.size() < 1) return; SideBarItem *item = reinterpret_cast<SideBarItem*>(selected.at(0).internalPointer()); QMenu *menu = NULL; if (item && item->childCount() > 0){ menu = new QMenu(this); menu->addAction(WICON(WulforUtil::eiEDITDELETE), tr("Close all")); if (menu->exec(QCursor::pos())){ QList<SideBarItem*> childs = item->childItems; for (const auto &child : childs){ if (child && child->getWidget()) ArenaWidgetManager::getInstance()->rem(child->getWidget()); } } menu->deleteLater(); } else if (item && item->getWidget()){ menu = item->getWidget()->getMenu(); if (!menu && (item->getWidget()->state() & ArenaWidget::Singleton)) return; if(!menu){ menu = new QMenu(this); menu->addAction(WICON(WulforUtil::eiEDITDELETE), tr("Close")); if (menu->exec(QCursor::pos())) ArenaWidgetManager::getInstance()->rem(item->getWidget()); menu->deleteLater(); } else menu->exec(QCursor::pos()); } }
void CListViewIrcUsers::contextMenuEvent(QContextMenuEvent* event) { QModelIndex index = indexAt(event->pos()); if (index.isValid()) { QMenu* menu = menuFactory()->createUserListMenu(index.data().toString(), this); menu->exec(event->globalPos()); menu->deleteLater(); } }
void EffectSlider::contextMenuEvent(QContextMenuEvent* event) { QMenu* contextMenu = new QMenu{this}; contextMenu->addAction(m_addAutomAction); contextMenu->exec(event->globalPos()); contextMenu->deleteLater(); }
int EditorToolBar::buildMenu(QMenu* pMenu, int indx) { int index = indx; bool bSkip = true; WizEditorContextMenuItem* arrayData = contextMenuData(); WizEditorContextMenuItem& curItem = arrayData[index]; QMenu* pSubMenu = new QMenu(curItem.label, pMenu); while(1) { index++; WizEditorContextMenuItem& item = arrayData[index]; if (item.label == "+") { break; } else if (item.label == "-") { pSubMenu->addSeparator(); } else if (item.command != "+" && !item.execute.isEmpty()) { // special case if (m_editor->editorCommandQueryLink() && item.label == WIZEDITOR_ACTION_LINK_INSERT) { continue; } else if (!m_editor->editorCommandQueryLink() && item.label == WIZEDITOR_ACTION_LINK_EDIT) { continue; } if (!item.command.isEmpty()) { int value = m_editor->editorCommandQueryCommandState(item.command); if (value == -1) { continue; } } bSkip = false; QString strSlot = "1" + item.execute + "()"; m_actions[item.label] = pSubMenu->addAction(item.label, m_editor, strSlot.toUtf8()); } else if (item.command.isEmpty() && item.execute.isEmpty()) { continue; } else { Q_ASSERT(0); } } if (!bSkip) { pMenu->addMenu(pSubMenu); } else { pSubMenu->deleteLater(); } return index; }
void MarkdownEditor::contextMenuEvent( QContextMenuEvent *e ) { // copy as Html e->accept(); QMenu *menu = createStandardContextMenu(); menu->addSeparator(); QAction *spellCheckStatusAction = new QAction( tr( "Check spelling" ), menu ); spellCheckStatusAction->setCheckable( true ); spellCheckStatusAction->setChecked( !spellCheckLanguage.isEmpty() ); menu->addAction( spellCheckStatusAction ); QList<QAction *> spellCheckLanguageActions = addSpellCheckLanguageActions( menu ); menu->addSeparator(); copyAsHtmlAction->setEnabled( textCursor().hasSelection() ); menu->addAction( copyAsHtmlAction ); QList<QAction *> spellCheckActions; if ( e->reason() == QContextMenuEvent::Mouse && !textCursor().hasSelection() ) { setTextCursor( cursorForPosition( e->pos() ) ); spellCheckActions = addSpellCheckActions( menu ); } QAction *selected = menu->exec( e->globalPos() ); if ( selected ) { if ( spellCheckActions.indexOf( selected ) != -1 ) { replaceTextInCurrentCursor( selected->text() ); } else if ( selected == spellCheckStatusAction ) { if ( selected->isChecked() ) { //enable spell check spellCheckLanguage = conf->getSpellCheckLanguage(); if ( conf->getSpellCheckLanguage().isEmpty() ) { spellCheckLanguage = conf->getAllAvailableSpellCheckDictNames().first(); } enableSpellCheck(); } else {//disable spell check spellCheckLanguage.clear(); disableSpellCheck(); } } else if ( spellCheckLanguageActions.indexOf( selected ) != -1 && selected->data().canConvert( QVariant::String ) && !selected->data().toString().isEmpty() && selected->data().toString() != spellCheckLanguage ) { disableSpellCheck(); spellCheckLanguage = selected->data().toString(); enableSpellCheck(); } } menu->deleteLater(); }
void ModelNodeContextMenu::execute(const QPoint &position, bool selectionMenuBool) { QMenu* mainMenu = new QMenu(); m_selectionContext.setShowSelectionTools(selectionMenuBool); m_selectionContext.setScenePosition(m_scenePos); QSet<ActionInterface* > factories = QSet<ActionInterface* >::fromList(QmlDesignerPlugin::instance()->designerActionManager().designerActions()); populateMenu(factories, QByteArray(), mainMenu, m_selectionContext); mainMenu->exec(position); mainMenu->deleteLater(); }
void Canvas::keyPressEvent(QKeyEvent *event) { QGraphicsView::keyPressEvent(event); if (event->isAccepted()) return; if (event->key() == Qt::Key_Space) { QGraphicsItem* i = scene->itemAt( mapToScene(mapFromGlobal(QCursor::pos())), QTransform()); Control* control = dynamic_cast<Control*>(i); if (control) { control->toggleInspector(); } } else if (event->key() == Qt::Key_Alt) { hideUI(); } else if (event->key() == Qt::Key_A && (event->modifiers() & Qt::ShiftModifier)) { QMenu* m = new QMenu(this); auto window = dynamic_cast<MainWindow*>(parent()->parent()); Q_ASSERT(window); window->populateMenu(m, false); m->exec(QCursor::pos()); m->deleteLater(); } else if (event->key() == Qt::Key_S && (event->modifiers() & Qt::ShiftModifier)) { ports_visible = !ports_visible; emit(showPorts(ports_visible)); } }
void CGI_SCADA_DLL_TreeItemCOM::GetPopUpMenu() { QMenu *SwitchMenu = new QMenu(); //->添加网络节点 // AddColChannel->setIcon(QIcon(":/ico/networkc.ico")); QAction *pAddDevice = new QAction(tr("新建设备"), SwitchMenu); connect(pAddDevice, SIGNAL(triggered()), this, SLOT(slot_AddDevice())); QAction *pDeleteChannel = new QAction(tr("删除通道"), SwitchMenu); connect(pDeleteChannel, SIGNAL(triggered()), this, SLOT(slot_DeleteChannel())); QAction *pSetEnable = new QAction(tr("使能通道"), SwitchMenu); pSetEnable->setCheckable(true); if (this->isDisabled()) { pSetEnable->setChecked(false); }else { pSetEnable->setChecked(true); } // this->isDisabled(); connect(pSetEnable, SIGNAL(triggered(bool)), this, SLOT(slot_SetEnable(bool))); // QAction *pAddNET = new QAction(tr("添加NET"),SwitchMenu); // connect(pAddNET,SIGNAL(triggered()),this,SLOT(slot_AddNET())); SwitchMenu->addAction(pAddDevice); SwitchMenu->addAction(pDeleteChannel); SwitchMenu->addAction(pSetEnable); // SwitchMenu->addAction(pAddNET); SwitchMenu->addSeparator(); //-> 运行菜单 SwitchMenu->exec(QCursor::pos()); // delete SwitchMenu;//防止内存泄露 SwitchMenu->deleteLater(); qDebug()<<__func__<<__LINE__<<__FILE__<<this->childCount(); return ; }
void ServiceDiscoveryWidget::on_DiscoveryTree__customContextMenuRequested (const QPoint& point) { const auto& idx = FilterModel_->mapToSource (Ui_.DiscoveryTree_->indexAt (point)); if (!idx.isValid ()) return; const auto& actions = SDSession_->GetActionsFor (idx); if (actions.isEmpty ()) return; QMenu *menu = new QMenu (tr ("Discovery actions")); for (auto i = actions.begin (), end = actions.end (); i != end; ++i) menu->addAction (i->second)->setProperty ("Azoth/ID", i->first); QAction *result = menu->exec (Ui_.DiscoveryTree_->viewport ()->mapToGlobal (point)); menu->deleteLater (); if (!result) return; const QByteArray& id = result->property ("Azoth/ID").toByteArray (); SDSession_->ExecuteAction (idx, id); }
void BaseWindow::deleteMenuItems(QMenu *menu) { QList<QAction*> mActions = menu->actions(); for (int i = 0; i < mActions.size(); i++) { QAction *act = mActions.at(i); menu->removeAction(act); // Remove the action! QMenu *men = 0; men = act->menu(); if (men != 0) { this->deleteMenuItems(men); // Recursion men->deleteLater(); } act->deleteLater(); } // Note at this point mActions has dangling pointers... }
void ItemPhysEnv::contextMenu(QGraphicsSceneMouseEvent *mouseEvent) { m_scene->m_contextMenuIsOpened = true; //bug protector //Remove selection from non-bgo items if(!this->isSelected()) { m_scene->clearSelection(); this->setSelected(true); } this->setSelected(true); QMenu ItemMenu; /*************Layers*******************/ QMenu *LayerName = ItemMenu.addMenu(tr("Layer: ") + QString("[%1]").arg(m_data.layer).replace("&", "&&&")); QAction *setLayer; QList<QAction *> layerItems; QAction *newLayer = LayerName->addAction(tr("Add to new layer...")); LayerName->addSeparator(); for(LevelLayer &layer : m_scene->m_data->layers) { //Skip system layers if((layer.name == "Destroyed Blocks") || (layer.name == "Spawned NPCs")) continue; setLayer = LayerName->addAction(layer.name.replace("&", "&&&") + ((layer.hidden) ? "" + tr("[hidden]") : "")); setLayer->setData(layer.name); setLayer->setCheckable(true); setLayer->setEnabled(true); setLayer->setChecked(layer.name == m_data.layer); layerItems.push_back(setLayer); } ItemMenu.addSeparator(); /*************Layers*end***************/ QMenu *WaterType = ItemMenu.addMenu(tr("Environment type")); WaterType->deleteLater(); #define CONTEXT_MENU_ITEM_CHK(name, enable, visible, label, checked_condition)\ name = WaterType->addAction(label);\ name->setCheckable(true);\ name->setEnabled(enable);\ name->setVisible(visible);\ name->setChecked(checked_condition); typeID++; QAction *envTypes[16]; int typeID = 0; bool enable_new_types = !m_scene->m_data->meta.smbx64strict && (m_scene->m_configs->editor.supported_features.level_phys_ez_new_types == EditorSetup::FeaturesSupport::F_ENABLED); bool show_new_types = (m_scene->m_configs->editor.supported_features.level_phys_ez_new_types != EditorSetup::FeaturesSupport::F_HIDDEN); CONTEXT_MENU_ITEM_CHK(envTypes[typeID], true, true, tr("Water"), m_data.env_type == LevelPhysEnv::ENV_WATER); CONTEXT_MENU_ITEM_CHK(envTypes[typeID], true, true, tr("Quicksand"), m_data.env_type == LevelPhysEnv::ENV_QUICKSAND); CONTEXT_MENU_ITEM_CHK(envTypes[typeID], enable_new_types, show_new_types, tr("Custom liquid"), m_data.env_type == LevelPhysEnv::ENV_CUSTOM_LIQUID); CONTEXT_MENU_ITEM_CHK(envTypes[typeID], enable_new_types, show_new_types, tr("Gravity Field"), m_data.env_type == LevelPhysEnv::ENV_GRAVITATIONAL_FIELD); CONTEXT_MENU_ITEM_CHK(envTypes[typeID], enable_new_types, show_new_types, tr("Touch Event (Once)"), m_data.env_type == LevelPhysEnv::ENV_TOUCH_EVENT_ONCE_PLAYER); CONTEXT_MENU_ITEM_CHK(envTypes[typeID], enable_new_types, show_new_types, tr("Touch Event (Every frame)"), m_data.env_type == LevelPhysEnv::ENV_TOUCH_EVENT_PLAYER); CONTEXT_MENU_ITEM_CHK(envTypes[typeID], enable_new_types, show_new_types, tr("NPC/Player Touch Event (Once)"), m_data.env_type == LevelPhysEnv::ENV_TOUCH_EVENT_ONCE_NPC); CONTEXT_MENU_ITEM_CHK(envTypes[typeID], enable_new_types, show_new_types, tr("NPC/Player Touch Event (Every frame)"), m_data.env_type == LevelPhysEnv::ENV_TOUCH_EVENT_NPC); CONTEXT_MENU_ITEM_CHK(envTypes[typeID], enable_new_types, show_new_types, tr("Mouse click Event"), m_data.env_type == LevelPhysEnv::ENV_CLICK_EVENT); CONTEXT_MENU_ITEM_CHK(envTypes[typeID], enable_new_types, show_new_types, tr("Collision script"), m_data.env_type == LevelPhysEnv::ENV_COLLISION_SCRIPT); CONTEXT_MENU_ITEM_CHK(envTypes[typeID], enable_new_types, show_new_types, tr("Mouse click Script"), m_data.env_type == LevelPhysEnv::ENV_CLICK_SCRIPT); CONTEXT_MENU_ITEM_CHK(envTypes[typeID], enable_new_types, show_new_types, tr("Collision Event"), m_data.env_type == LevelPhysEnv::ENV_COLLISION_EVENT); CONTEXT_MENU_ITEM_CHK(envTypes[typeID], enable_new_types, show_new_types, tr("Air chamber"), m_data.env_type == LevelPhysEnv::ENV_AIR); CONTEXT_MENU_ITEM_CHK(envTypes[typeID], enable_new_types, show_new_types, tr("NPC Touch Event (Once)"), m_data.env_type == LevelPhysEnv::ENV_TOUCH_EVENT_ONCE_NPC1); CONTEXT_MENU_ITEM_CHK(envTypes[typeID], enable_new_types, show_new_types, tr("NPC Touch Event (Every frame)"), m_data.env_type == LevelPhysEnv::ENV_TOUCH_EVENT_NPC1); CONTEXT_MENU_ITEM_CHK(envTypes[typeID], enable_new_types, show_new_types, tr("NPC Hurting Field"), m_data.env_type == LevelPhysEnv::ENV_NPC_HURTING_FIELD); #undef CONTEXT_MENU_ITEM_CHK ItemMenu.addSeparator(); QMenu *copyPreferences = ItemMenu.addMenu(tr("Copy preferences")); QAction *copyPosXYWH = copyPreferences->addAction(tr("Position: X, Y, Width, Height")); QAction *copyPosLTRB = copyPreferences->addAction(tr("Position: Left, Top, Right, Bottom")); ItemMenu.addSeparator(); QAction *resize = ItemMenu.addAction(tr("Resize")); resize->deleteLater(); ItemMenu.addSeparator(); QAction *copyWater = ItemMenu.addAction(tr("Copy")); QAction *cutWater = ItemMenu.addAction(tr("Cut")); ItemMenu.addSeparator(); QAction *remove = ItemMenu.addAction(tr("Remove")); /*****************Waiting for answer************************/ QAction *selected = ItemMenu.exec(mouseEvent->screenPos()); /***********************************************************/ if(!selected) return; if(selected == cutWater) m_scene->m_mw->on_actionCut_triggered(); else if(selected == copyWater) m_scene->m_mw->on_actionCopy_triggered(); else if(selected == copyPosXYWH) { QApplication::clipboard()->setText( QString("X=%1; Y=%2; W=%3; H=%4;") .arg(m_data.x) .arg(m_data.y) .arg(m_data.w) .arg(m_data.h) ); m_scene->m_mw->showStatusMsg(tr("Preferences have been copied: %1").arg(QApplication::clipboard()->text())); } else if(selected == copyPosLTRB) { QApplication::clipboard()->setText( QString("Left=%1; Top=%2; Right=%3; Bottom=%4;") .arg(m_data.x) .arg(m_data.y) .arg(m_data.x + m_data.w) .arg(m_data.y + m_data.h) ); m_scene->m_mw->showStatusMsg(tr("Preferences have been copied: %1").arg(QApplication::clipboard()->text())); } else if(selected == resize) m_scene->setPhysEnvResizer(this, true); else if(selected == remove) m_scene->removeSelectedLvlItems(); else if(selected == newLayer) m_scene->setLayerToSelected(); else { bool found = false; //Fetch layers menu foreach(QAction *lItem, layerItems) { if(selected == lItem) { //FOUND!!! m_scene->setLayerToSelected(lItem->data().toString()); found = true; break; }//Find selected layer's item } if(!found) { for(int i = 0; i < typeID; i++) { if(selected == envTypes[i]) { LevelData modData; for(QGraphicsItem *selItem : m_scene->selectedItems()) { if(selItem->data(ITEM_TYPE).toString() == "Water") { ItemPhysEnv *pe = dynamic_cast<ItemPhysEnv*>(selItem); modData.physez.push_back(pe->m_data); pe->setType(i); m_scene->invalidate(pe->boundingRect()); } } m_scene->m_history->addChangeSettings(modData, HistorySettings::SETTING_WATERTYPE, QVariant(true)); if(!m_scene->m_opts.animationEnabled) m_scene->update(); found = true; break; } } } } }
void ItemMusic::contextMenu( QGraphicsSceneMouseEvent * mouseEvent ) { m_scene->m_contextMenuIsOpened = true; //Remove selection from non-bgo items if(!this->isSelected()) { m_scene->clearSelection(); this->setSelected(true); } this->setSelected(true); QMenu ItemMenu; if(!m_musicTitle.isEmpty()) { QAction *title = ItemMenu.addAction(QString("[%1]").arg(m_musicTitle)); title->setEnabled(false); }else if(m_data.id==0) { QAction *title = ItemMenu.addAction(QString("[%1]").arg(tr("<Silence>"))); title->setEnabled(false); } QAction *play = ItemMenu.addAction(tr("Play this")); ItemMenu.addSeparator(); QMenu * copyPreferences = ItemMenu.addMenu(tr("Copy preferences")); copyPreferences->deleteLater(); QAction *copyItemID = copyPreferences->addAction(tr("World-Music-ID: %1").arg(m_data.id)); copyItemID->deleteLater(); QAction *copyPosXY = copyPreferences->addAction(tr("Position: X, Y")); copyPosXY->deleteLater(); QAction *copyPosXYWH = copyPreferences->addAction(tr("Position: X, Y, Width, Height")); copyPosXYWH->deleteLater(); QAction *copyPosLTRB = copyPreferences->addAction(tr("Position: Left, Top, Right, Bottom")); copyPosLTRB->deleteLater(); QAction *copyTile = ItemMenu.addAction(tr("Copy")); QAction *cutTile = ItemMenu.addAction(tr("Cut")); ItemMenu.addSeparator(); QAction *transform = ItemMenu.addAction(tr("Transform into")); QAction *transform_all = ItemMenu.addAction(tr("Transform all %1 into").arg("MUSIC-%1%2") .arg(m_data.id) .arg( m_data.music_file.isEmpty()?"":" ("+m_data.music_file+")" ) ); ItemMenu.addSeparator(); QAction *remove = ItemMenu.addAction(tr("Remove")); QAction *remove_all = ItemMenu.addAction(tr("Remove all %1").arg("MUSIC-%1").arg(m_data.id)); QAction *selected = ItemMenu.exec(mouseEvent->screenPos()); if(!selected) { #ifdef _DEBUG_ WriteToLog(QtDebugMsg, "Context Menu <- NULL"); #endif return; } if(selected==play) { m_scene->m_subWindow->currentMusic = m_data.id; LvlMusPlay::setMusic(LvlMusPlay::WorldMusic, m_data.id, m_data.music_file); LvlMusPlay::updatePlayerState(true); MainWinConnect::pMainWin->setMusicButton(true); } else if(selected==copyItemID) { QApplication::clipboard()->setText(QString("%1").arg(m_data.id)); MainWinConnect::pMainWin->showStatusMsg(tr("Preferences has been copied: %1").arg(QApplication::clipboard()->text())); } else if(selected==copyPosXY) { QApplication::clipboard()->setText( QString("X=%1; Y=%2;") .arg(m_data.x) .arg(m_data.y) ); MainWinConnect::pMainWin->showStatusMsg(tr("Preferences has been copied: %1").arg(QApplication::clipboard()->text())); } else if(selected==copyPosXYWH) { QApplication::clipboard()->setText( QString("X=%1; Y=%2; W=%3; H=%4;") .arg(m_data.x) .arg(m_data.y) .arg(m_imageSize.width()) .arg(m_imageSize.height()) ); MainWinConnect::pMainWin->showStatusMsg(tr("Preferences has been copied: %1").arg(QApplication::clipboard()->text())); } else if(selected==copyPosLTRB) { QApplication::clipboard()->setText( QString("Left=%1; Top=%2; Right=%3; Bottom=%4;") .arg(m_data.x) .arg(m_data.y) .arg(m_data.x+m_imageSize.width()) .arg(m_data.y+m_imageSize.height()) ); MainWinConnect::pMainWin->showStatusMsg(tr("Preferences has been copied: %1").arg(QApplication::clipboard()->text())); } else if(selected==cutTile) { MainWinConnect::pMainWin->on_actionCut_triggered(); } else if(selected==copyTile) { MainWinConnect::pMainWin->on_actionCopy_triggered(); } else if((selected==transform)||(selected==transform_all)) { WorldData oldData; WorldData newData; int transformTO; QString transformTO_file; ItemSelectDialog * itemList = new ItemSelectDialog(m_scene->m_configs, ItemSelectDialog::TAB_MUSIC,0,0,0,0,0,0,0,0,0, m_scene->m_subWindow); itemList->removeEmptyEntry(ItemSelectDialog::TAB_MUSIC); util::DialogToCenter(itemList, true); if(itemList->exec()==QDialog::Accepted) { QList<QGraphicsItem *> our_items; bool sameID=false; transformTO = itemList->musicID; transformTO_file = itemList->musicFile; unsigned long oldID = m_data.id; if(selected==transform) our_items=m_scene->selectedItems(); else if(selected==transform_all) { our_items=m_scene->items(); sameID=true; } foreach(QGraphicsItem * SelItem, our_items ) { if(SelItem->data(ITEM_TYPE).toString()=="MUSICBOX") { if((!sameID)||(((ItemMusic *) SelItem)->m_data.id==oldID)) { oldData.music.push_back( ((ItemMusic *) SelItem)->m_data ); ((ItemMusic *) SelItem)->transformTo(transformTO, transformTO_file); newData.music.push_back( ((ItemMusic *) SelItem)->m_data ); } } } }
void CMainWindow::treeCtxMenuPrivate(const QPoint &pos, const bool fromValuesTable) { QModelIndex idx = ui->treeHives->currentIndex(); QMenu* cm; if (fromValuesTable) { cm = new QMenu(ui->tableValues); } else { if (valuesModel->getCurrentKeyName()!=treeModel->getKeyName(idx)) { showValues(idx); QApplication::processEvents(); } cm = new QMenu(ui->treeHives); } int hive = treeModel->getHiveIdx(idx); if (hive<0) return; QAction* acm; QMenu* ccm = cm->addMenu(tr("New")); { acm = ccm->addAction(tr("Key")); acm->setData(-1); connect(acm,&QAction::triggered,this,&CMainWindow::createEntry); ccm->addSeparator(); acm = ccm->addAction(tr("String value")); acm->setData(REG_SZ); connect(acm,&QAction::triggered,this,&CMainWindow::createEntry); acm = ccm->addAction(tr("Binary value")); acm->setData(REG_BINARY); connect(acm,&QAction::triggered,this,&CMainWindow::createEntry); acm = ccm->addAction(tr("DWORD value")); acm->setData(REG_DWORD); connect(acm,&QAction::triggered,this,&CMainWindow::createEntry); acm = ccm->addAction(tr("Multistring value")); acm->setData(REG_MULTI_SZ); connect(acm,&QAction::triggered,this,&CMainWindow::createEntry); acm = ccm->addAction(tr("Expandable string value")); acm->setData(REG_EXPAND_SZ); connect(acm,&QAction::triggered,this,&CMainWindow::createEntry); } if (idx.isValid()) { cm->addSeparator(); acm = cm->addAction(tr("Delete")); if (idx.parent().isValid()) { connect(acm,&QAction::triggered,[this,idx](){ treeModel->deleteKey(idx); valuesModel->keyChanged(QModelIndex(),ui->tableValues); }); } else acm->setEnabled(false); cm->addSeparator(); acm = cm->addAction(tr("Copy key name")); connect(acm,&QAction::triggered,[this,idx](){ QApplication::clipboard()->setText(treeModel->getKeyName(idx)); }); acm = cm->addAction(tr("Export...")); acm->setEnabled(cgl->reg->getHivePtr(hive)->type!=HTYPE_SAM); connect(acm,&QAction::triggered,[this,idx](){ QString fname = getSaveFileNameD(this,tr("Export registry"),QString(), tr("Registry files (*.reg)")); if (!fname.isEmpty()) { if (!treeModel->exportKey(idx,fname)) QMessageBox::critical(this,tr("Registry Editor - Error"),tr("Failed to export selected key.")); else QMessageBox::information(this,tr("Registry Editor - Export"), tr("Registry key exported successfully.")); } }); cm->addSeparator(); acm = cm->addAction(tr("Find...")); connect(acm,&QAction::triggered,[this,idx](){ bool ok; QString s = QInputDialog::getText(this,tr("Registry Editor - Search"), tr("Search text"),QLineEdit::Normal,QString(),&ok); if (ok && !s.isEmpty()) emit startSearch(idx,s); }); struct hive *h = cgl->reg->getHivePtr(hive); if (h!=nullptr && h->type==HTYPE_SOFTWARE) { cm->addSeparator(); acm = cm->addAction(tr("Show OS info...")); connect(acm,&QAction::triggered,[this,h](){ QString info = cgl->reg->getOSInfo(h); if (!info.isEmpty()) QMessageBox::information(this,tr("Registry Editor - OS info"), info); }); } } cm->addSeparator(); acm = cm->addAction(tr("Close hive")); connect(acm,&QAction::triggered,[hive](){ cgl->safeToClose(hive); }); if (fromValuesTable) cm->exec(ui->tableValues->mapToGlobal(pos)); else cm->exec(ui->treeHives->mapToGlobal(pos)); cm->deleteLater(); }
void PublicHubs::slotContextMenu(){ QItemSelectionModel *sel_model = treeView->selectionModel(); QModelIndexList indexes = sel_model->selectedRows(0); if (indexes.isEmpty()) return; if (proxy) std::transform(indexes.begin(), indexes.end(), indexes.begin(), [&](QModelIndex i) { return proxy->mapToSource(i); }); WulforUtil *WU = WulforUtil::getInstance(); QMenu *m = new QMenu(); QAction *connect = new QAction(WU->getPixmap(WulforUtil::eiCONNECT), tr("Connect"), m); QAction *add_fav = new QAction(WU->getPixmap(WulforUtil::eiBOOKMARK_ADD), tr("Add to favorites"), m); QAction *copy = new QAction(WU->getPixmap(WulforUtil::eiEDITCOPY), tr("Copy &address to clipboard"), m); m->addActions(QList<QAction*>() << connect << add_fav << copy); QAction *ret = m->exec(QCursor::pos()); m->deleteLater(); if (ret == connect){ PublicHubItem * item = NULL; MainWindow *MW = MainWindow::getInstance(); for (const auto &i : indexes){ item = reinterpret_cast<PublicHubItem*>(i.internalPointer()); if (item) MW->newHubFrame(item->data(COLUMN_PHUB_ADDRESS).toString(), ""); item = NULL; } } else if (ret == add_fav){ PublicHubItem * item = NULL; for (const auto &i : indexes){ item = reinterpret_cast<PublicHubItem*>(i.internalPointer()); if (item && item->entry){ try{ FavoriteManager::getInstance()->addFavorite(*item->entry); } catch (const std::exception&){} } item = NULL; } } else if (ret == copy){ PublicHubItem * item = NULL; QString out = ""; for (const auto &i : indexes){ item = reinterpret_cast<PublicHubItem*>(i.internalPointer()); if (item) out += item->data(COLUMN_PHUB_ADDRESS).toString() + "\n"; item = NULL; } if (!out.isEmpty()) qApp->clipboard()->setText(out, QClipboard::Clipboard); } }
View::View() : m_widg{new QWidget} { auto lay = new QFormLayout; m_widg->setLayout(lay); #if defined(HAS_VST2) m_VstPaths = new QListWidget; auto button_lay = new QHBoxLayout; auto pb = new QPushButton{"Add path"}; auto rescan = new QPushButton{"Rescan"}; button_lay->addWidget(pb); button_lay->addWidget(rescan); auto vst_lay = new QGridLayout; auto vst_ok = new QListWidget; auto vst_bad = new QListWidget; m_VstPaths->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu); connect( m_VstPaths, &QListWidget::customContextMenuRequested, this, [=](const QPoint& p) { QMenu* m = new QMenu; auto act = m->addAction("Remove"); connect(act, &QAction::triggered, this, [=] { auto idx = m_VstPaths->currentRow(); if (idx >= 0 && idx < m_curitems.size()) { m_VstPaths->takeItem(idx); m_curitems.removeAt(idx); VstPathsChanged(m_curitems); } }); m->exec(m_VstPaths->mapToGlobal(p)); m->deleteLater(); }); lay->addRow(tr("VST paths"), m_VstPaths); lay->addRow(button_lay); connect(pb, &QPushButton::clicked, this, [=] { auto path = QFileDialog::getExistingDirectory(m_widg, tr("VST Path")); if (!path.isEmpty()) { m_VstPaths->addItem(path); m_curitems.push_back(path); VstPathsChanged(m_curitems); } }); auto& app_plug = score::GUIAppContext().applicationPlugin<Media::ApplicationPlugin>(); connect(rescan, &QPushButton::clicked, this, [&] { app_plug.rescanVSTs(m_curitems); }); auto reloadVSTs = [=, &app_plug] { vst_ok->clear(); vst_bad->clear(); for (auto& plug : app_plug.vst_infos) { if (plug.isValid) { vst_ok->addItem(QString{"%1 - %2\t(%3)"} .arg(plug.prettyName) .arg(plug.displayName) .arg(plug.path)); } else { vst_bad->addItem(QString{"%1 - %2\t(%3)"} .arg(plug.prettyName) .arg(plug.displayName) .arg(plug.path)); } } }; reloadVSTs(); con(app_plug, &Media::ApplicationPlugin::vstChanged, this, reloadVSTs); lay->addRow(vst_lay); vst_lay->addWidget(new QLabel("Working plug-ins"), 0, 0, 1, 1); vst_lay->addWidget(new QLabel("Bad plug-ins"), 0, 1, 1, 1); vst_lay->addWidget(vst_ok, 1, 0, 1, 1); vst_lay->addWidget(vst_bad, 1, 1, 1, 1); #endif }
void MainWidget::on_CLTree__customContextMenuRequested (const QPoint& pos) { const QModelIndex& index = ProxyModel_->mapToSource (Ui_.CLTree_->indexAt (pos)); if (!index.isValid ()) return; const auto manager = Core::Instance ().GetActionsManager (); QMenu *menu = new QMenu (tr ("Entry context menu")); QList<QAction*> actions; switch (index.data (Core::CLREntryType).value<Core::CLEntryType> ()) { case Core::CLETContact: { auto rows = Ui_.CLTree_->selectionModel ()->selectedRows (); for (auto& row : rows) row = ProxyModel_->mapToSource (row); if (!rows.contains (index)) rows << index; if (rows.size () == 1) { QObject *obj = index.data (Core::CLREntryObject).value<QObject*> (); ICLEntry *entry = qobject_cast<ICLEntry*> (obj); const auto& allActions = manager->GetEntryActions (entry); for (auto action : allActions) { const auto& areas = manager->GetAreasForAction (action); if (action->isSeparator () || areas.contains (ActionsManager::CLEAAContactListCtxtMenu)) actions << action; } } else { QList<ICLEntry*> entries; for (const auto& row : rows) { const auto entryObj = row.data (Core::CLREntryObject).value<QObject*> (); const auto entry = qobject_cast<ICLEntry*> (entryObj); if (entry) entries << entry; } const auto& allActions = manager->CreateEntriesActions (entries, menu); for (auto action : allActions) { const auto& areas = manager->GetAreasForAction (action); if (action->isSeparator () || areas.contains (ActionsManager::CLEAAContactListCtxtMenu)) actions << action; } } break; } case Core::CLETCategory: { QAction *rename = new QAction (tr ("Rename group..."), this); const auto& objVar = index.parent ().data (Core::CLRAccountObject); rename->setProperty ("Azoth/OldGroupName", index.data ()); rename->setProperty ("Azoth/AccountObject", objVar); connect (rename, SIGNAL (triggered ()), this, SLOT (handleCatRenameTriggered ())); actions << rename; QList<QVariant> entries; for (int i = 0, cnt = index.model ()->rowCount (index); i < cnt; ++i) entries << index.child (i, 0).data (Core::CLREntryObject); QAction *sendMsg = new QAction (tr ("Send message..."), menu); sendMsg->setProperty ("Azoth/Entries", entries); connect (sendMsg, SIGNAL (triggered ()), this, SLOT (handleSendGroupMsgTriggered ())); actions << sendMsg; if (index.data (Core::CLRUnreadMsgCount).toInt ()) { auto markAll = new QAction (tr ("Mark all messages as read"), menu); markAll->setProperty ("Azoth/Entries", entries); connect (markAll, SIGNAL (triggered ()), this, SLOT (handleMarkAllTriggered ())); actions << markAll; } QAction *removeChildren = new QAction (tr ("Remove group's participants"), menu); removeChildren->setProperty ("Azoth/Entries", entries); connect (removeChildren, SIGNAL (triggered ()), this, SLOT (handleRemoveChildrenTriggered ())); actions << removeChildren; break; } case Core::CLETAccount: actions << AccountActsMgr_->GetMenuActions (menu, index.data (Core::CLRAccountObject).value<IAccount*> ()); break; default: break; } if (!actions.size ()) { delete menu; return; } menu->addActions (actions); menu->exec (Ui_.CLTree_->mapToGlobal (pos)); menu->deleteLater (); }
void QScriptEdit::extraAreaMouseEvent(QMouseEvent *e) { QTextCursor cursor = cursorForPosition(QPoint(0, e->pos().y())); cursor.setPosition(cursor.block().position()); QFontMetrics fm(font()); int markWidth = fm.lineSpacing(); if (e->type() == QEvent::MouseMove && e->buttons() == 0) { // mouse tracking bool hand = (e->pos().x() <= markWidth); int lineNumber = cursor.blockNumber() + m_baseLineNumber; hand = hand && isExecutableLine(lineNumber); #ifndef QT_NO_CURSOR if (hand != (m_extraArea->cursor().shape() == Qt::PointingHandCursor)) m_extraArea->setCursor(hand ? Qt::PointingHandCursor : Qt::ArrowCursor); #endif } if (e->type() == QEvent::MouseButtonPress) { if (e->button() == Qt::LeftButton) { int lineNumber = cursor.blockNumber() + m_baseLineNumber; bool executable = isExecutableLine(lineNumber); if ((e->pos().x() <= markWidth) && executable) m_extraAreaToggleBlockNumber = cursor.blockNumber(); else m_extraAreaToggleBlockNumber = -1; } } else if (e->type() == QEvent::MouseButtonRelease) { if (e->button() == Qt::LeftButton) { if ((m_extraAreaToggleBlockNumber != -1) && (e->pos().x() <= markWidth)) { int lineNumber = m_extraAreaToggleBlockNumber + m_baseLineNumber; bool on = !m_breakpoints.contains(lineNumber); emit breakpointToggleRequest(lineNumber, on); } } else if (e->button() == Qt::RightButton) { int lineNumber = cursor.blockNumber() + m_baseLineNumber; if (!isExecutableLine(lineNumber)) return; bool has = m_breakpoints.contains(lineNumber); QMenu *popup = new QMenu(); QAction *toggleAct = new QAction(tr("Toggle Breakpoint"), popup); popup->addAction(toggleAct); QAction *disableAct = new QAction(tr("Disable Breakpoint"), popup); QAction *enableAct = new QAction(tr("Enable Breakpoint"), popup); QWidget *conditionWidget = new QWidget(); { QHBoxLayout *hbox = new QHBoxLayout(conditionWidget); hbox->addWidget(new QLabel(tr("Breakpoint Condition:"))); hbox->addWidget(new QLineEdit()); } // QWidgetAction *conditionAct = new QWidgetAction(popup); // conditionAct->setDefaultWidget(conditionWidget); if (has) { popup->addSeparator(); popup->addAction(m_breakpoints[lineNumber].enabled ? disableAct : enableAct); // popup->addAction(conditionAct); } QAction *ret = popup->exec(e->globalPos()); if (ret) { if (ret == toggleAct) { emit breakpointToggleRequest(lineNumber, !has); } else if (ret == disableAct) { emit breakpointEnableRequest(lineNumber, false); } else if (ret == enableAct) { emit breakpointEnableRequest(lineNumber, true); }// else if (ret == conditionAct) { //} } popup->deleteLater(); } } }
void StatusBarWidget::contextMenuEvent(QContextMenuEvent *event) { QMenu *menu = ToolBarWidget::createCustomizationMenu(ToolBarsManager::StatusBar); menu->exec(event->globalPos()); menu->deleteLater(); }
void ItemScene::contextMenu( QGraphicsSceneMouseEvent * mouseEvent ) { m_scene->m_contextMenuIsOpened = true; //bug protector //Remove selection from non-bgo items if(!this->isSelected()) { m_scene->clearSelection(); this->setSelected(true); } setSelected(true);//minor, but so dumb mistake was here: "this" instead of "true" QMenu ItemMenu; QMenu * copyPreferences = ItemMenu.addMenu(tr("Copy preferences")); copyPreferences->deleteLater(); QAction *copyItemID = copyPreferences->addAction(tr("Scenery-ID: %1").arg(m_data.id)); copyItemID->deleteLater(); QAction *copyPosXY = copyPreferences->addAction(tr("Position: X, Y")); copyPosXY->deleteLater(); QAction *copyPosXYWH = copyPreferences->addAction(tr("Position: X, Y, Width, Height")); copyPosXYWH->deleteLater(); QAction *copyPosLTRB = copyPreferences->addAction(tr("Position: Left, Top, Right, Bottom")); copyPosLTRB->deleteLater(); QAction *copyTile = ItemMenu.addAction(tr("Copy")); QAction *cutTile = ItemMenu.addAction(tr("Cut")); ItemMenu.addSeparator(); QAction *transform = ItemMenu.addAction(tr("Transform into")); QAction *transform_all = ItemMenu.addAction(tr("Transform all %1 into").arg("SCENERY-%1").arg(m_data.id)); ItemMenu.addSeparator(); QAction *remove = ItemMenu.addAction(tr("Remove")); QAction *remove_all = ItemMenu.addAction(tr("Remove all %1").arg("SCENERY-%1").arg(m_data.id)); QAction *selected = ItemMenu.exec(mouseEvent->screenPos()); if(!selected) { #ifdef _DEBUG_ WriteToLog(QtDebugMsg, "Context Menu <- NULL"); #endif return; } if(selected==copyItemID) { QApplication::clipboard()->setText(QString("%1").arg(m_data.id)); MainWinConnect::pMainWin->showStatusMsg(tr("Preferences has been copied: %1").arg(QApplication::clipboard()->text())); } else if(selected==copyPosXY) { QApplication::clipboard()->setText( QString("X=%1; Y=%2;") .arg(m_data.x) .arg(m_data.y) ); MainWinConnect::pMainWin->showStatusMsg(tr("Preferences has been copied: %1").arg(QApplication::clipboard()->text())); } else if(selected==copyPosXYWH) { QApplication::clipboard()->setText( QString("X=%1; Y=%2; W=%3; H=%4;") .arg(m_data.x) .arg(m_data.y) .arg(m_imageSize.width()) .arg(m_imageSize.height()) ); MainWinConnect::pMainWin->showStatusMsg(tr("Preferences has been copied: %1").arg(QApplication::clipboard()->text())); } else if(selected==copyPosLTRB) { QApplication::clipboard()->setText( QString("Left=%1; Top=%2; Right=%3; Bottom=%4;") .arg(m_data.x) .arg(m_data.y) .arg(m_data.x+m_imageSize.width()) .arg(m_data.y+m_imageSize.height()) ); MainWinConnect::pMainWin->showStatusMsg(tr("Preferences has been copied: %1").arg(QApplication::clipboard()->text())); } else if(selected==cutTile) { MainWinConnect::pMainWin->on_actionCut_triggered(); } else if(selected==copyTile) { MainWinConnect::pMainWin->on_actionCopy_triggered(); } else if((selected==transform)||(selected==transform_all)) { WorldData oldData; WorldData newData; int transformTO; ItemSelectDialog * itemList = new ItemSelectDialog(m_scene->m_configs, ItemSelectDialog::TAB_SCENERY,0,0,0,0,0,0,0,0,0, m_scene->m_subWindow); itemList->removeEmptyEntry(ItemSelectDialog::TAB_SCENERY); util::DialogToCenter(itemList, true); if(itemList->exec()==QDialog::Accepted) { QList<QGraphicsItem *> our_items; bool sameID=false; transformTO = itemList->sceneryID; unsigned long oldID = m_data.id; if(selected==transform) our_items=m_scene->selectedItems(); else if(selected==transform_all) { our_items=m_scene->items(); sameID=true; } foreach(QGraphicsItem * SelItem, our_items ) { if(SelItem->data(ITEM_TYPE).toString()=="SCENERY") { if((!sameID)||(((ItemScene *) SelItem)->m_data.id==oldID)) { oldData.scenery.push_back( ((ItemScene *) SelItem)->m_data ); ((ItemScene *) SelItem)->transformTo(transformTO); newData.scenery.push_back( ((ItemScene *) SelItem)->m_data ); } } } }
void PlacesView::contextMenuEvent(QContextMenuEvent* event) { QModelIndex index = indexAt(event->pos()); if(index.isValid() && index.parent().isValid()) { if(index.column() != 0) // the real item is at column 0 index = index.sibling(index.row(), 0); // Do not take the ownership of the menu since // it will be deleted with deleteLater() upon hidden. // This is possibly related to #145 - https://github.com/lxde/pcmanfm-qt/issues/145 QMenu* menu = new QMenu(); QAction* action; PlacesModelItem* item = static_cast<PlacesModelItem*>(model_->itemFromIndex(index)); if(item->type() != PlacesModelItem::Mount && (item->type() != PlacesModelItem::Volume || static_cast<PlacesModelVolumeItem*>(item)->isMounted())) { action = new PlacesModel::ItemAction(item->index(), tr("Open in New Tab"), menu); connect(action, &QAction::triggered, this, &PlacesView::onOpenNewTab); menu->addAction(action); action = new PlacesModel::ItemAction(item->index(), tr("Open in New Window"), menu); connect(action, &QAction::triggered, this, &PlacesView::onOpenNewWindow); menu->addAction(action); } switch(item->type()) { case PlacesModelItem::Places: { FmPath* path = item->path(); if(path && fm_path_equal(fm_path_get_trash(), path)) { action = new PlacesModel::ItemAction(item->index(), tr("Empty Trash"), menu); connect(action, &QAction::triggered, this, &PlacesView::onEmptyTrash); menu->addAction(action); } break; } case PlacesModelItem::Bookmark: { // create context menu for bookmark item if(item->index().row() > 0) { action = new PlacesModel::ItemAction(item->index(), tr("Move Bookmark Up"), menu); connect(action, &QAction::triggered, this, &PlacesView::onMoveBookmarkUp); menu->addAction(action); } if(item->index().row() < model_->rowCount()) { action = new PlacesModel::ItemAction(item->index(), tr("Move Bookmark Down"), menu); connect(action, &QAction::triggered, this, &PlacesView::onMoveBookmarkDown); menu->addAction(action); } action = new PlacesModel::ItemAction(item->index(), tr("Rename Bookmark"), menu); connect(action, &QAction::triggered, this, &PlacesView::onRenameBookmark); menu->addAction(action); action = new PlacesModel::ItemAction(item->index(), tr("Remove Bookmark"), menu); connect(action, &QAction::triggered, this, &PlacesView::onDeleteBookmark); menu->addAction(action); break; } case PlacesModelItem::Volume: { PlacesModelVolumeItem* volumeItem = static_cast<PlacesModelVolumeItem*>(item); if(volumeItem->isMounted()) { action = new PlacesModel::ItemAction(item->index(), tr("Unmount"), menu); connect(action, &QAction::triggered, this, &PlacesView::onUnmountVolume); } else { action = new PlacesModel::ItemAction(item->index(), tr("Mount"), menu); connect(action, &QAction::triggered, this, &PlacesView::onMountVolume); } menu->addAction(action); if(volumeItem->canEject()) { action = new PlacesModel::ItemAction(item->index(), tr("Eject"), menu); connect(action, &QAction::triggered, this, &PlacesView::onEjectVolume); menu->addAction(action); } break; } case PlacesModelItem::Mount: { action = new PlacesModel::ItemAction(item->index(), tr("Unmount"), menu); connect(action, &QAction::triggered, this, &PlacesView::onUnmountMount); menu->addAction(action); break; } } if(menu->actions().size()) { menu->popup(mapToGlobal(event->pos())); connect(menu, &QMenu::aboutToHide, menu, &QMenu::deleteLater); } else { menu->deleteLater(); } } }