void MainWindow::updateBookmarks(int folder) { if (m_ui->menuBookmarks->actions().count() == 3) { return; } for (int i = (m_ui->menuBookmarks->actions().count() - 1); i > 2; --i) { QAction *action = m_ui->menuBookmarks->actions().at(i); if (folder == 0) { action->deleteLater(); m_ui->menuBookmarks->removeAction(action); } else if (m_ui->menuBookmarks->actions().at(i)->menu()) { action->menu()->deleteLater(); action->setMenu(new QMenu()); connect(action->menu(), SIGNAL(aboutToShow()), this, SLOT(menuBookmarksAboutToShow())); } } }
void WindowMenu::onAboutToShow() { QWidget* win = QApplication::activeWindow(); pMinimize_->setEnabled(win); pZoom_->setEnabled(win && win->maximumSize() != win->minimumSize()); pBringAllToFront_->setEnabled(win); for (int i = windows_.size() - 1; i >= 0; i--) { QAction* pAction = windows_[i]; removeAction(pAction); windows_.removeAt(i); pAction->deleteLater(); } QWidgetList topLevels = QApplication::topLevelWidgets(); for (int i = 0; i < topLevels.size(); i++) { QWidget* pWindow = topLevels.at(i); if (!pWindow->isVisible()) continue; QAction* pAction = new QAction(pWindow->windowTitle(), pWindow); pAction->setData(QVariant::fromValue(pWindow)); pAction->setCheckable(true); if (pWindow->isActiveWindow()) pAction->setChecked(true); insertAction(pWindowPlaceholder_, pAction); connect(pAction, SIGNAL(triggered()), this, SLOT(showWindow())); windows_.append(pAction); } }
void Favorites::updateMenu() { // Remove all except the first 2 items while (_menu->actions().count() > FIRST_MENU_ENTRY) { QAction * a = _menu->actions()[FIRST_MENU_ENTRY]; _menu->removeAction( a ); a->deleteLater(); } populateMenu(); markCurrent(); }
void Core::handleUnclose () { QAction *action = qobject_cast<QAction*> (sender ()); UncloseData ud = action->data ().value<UncloseData> (); BrowserWidget *bw = NewURL (ud.URL_); QDataStream str (ud.History_); str >> *bw->GetView ()->page ()->history (); bw->SetOnLoadScrollPoint (ud.SPoint_); Unclosers_.removeAll (action); action->deleteLater (); }
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 BOpenSaveEditorModulePrivate::resetFileHistory(const QStringList &list) { if (mnuFileHistory.isNull()) return; QList<QAction *> acts = mnuFileHistory->actions(); while (acts.size() > list.size()) { QAction *act = acts.takeLast(); mnuFileHistory->removeAction(act); act->deleteLater(); } while (acts.size() < list.size()) { QAction *act = new QAction(mnuFileHistory); acts << act; mnuFileHistory->addAction(act); } for (int i = 0; i < list.size(); ++i) { QAction *act = acts.at(i); act->setProperty("beqt/file_name", list.at(i)); act->setText(QFileInfo( list.at(i) ).fileName()); connect(act, SIGNAL(triggered()), this, SLOT(fileTriggered()), Qt::UniqueConnection); connect(act, SIGNAL(hovered()), this, SLOT(resetFileHistoryMenuToolTip())); } mnuFileHistory->setEnabled(!mnuFileHistory->isEmpty()); }
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 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; } } } } }
QAction* QtWebKitWebWidget::getAction(WindowAction action) { const QWebPage::WebAction webAction = mapAction(action); if (webAction != QWebPage::NoWebAction) { return m_webView->page()->action(webAction); } if (action == NoAction) { return NULL; } if (m_actions.contains(action)) { return m_actions[action]; } QAction *actionObject = new QAction(this); actionObject->setData(action); connect(actionObject, SIGNAL(triggered()), this, SLOT(triggerAction())); switch (action) { case OpenLinkInNewTabAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("OpenLinkInNewTab"), true); break; case OpenLinkInNewTabBackgroundAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("OpenLinkInNewTabBackground"), true); break; case OpenLinkInNewWindowAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("OpenLinkInNewWindow"), true); break; case OpenLinkInNewWindowBackgroundAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("OpenLinkInNewWindowBackground"), true); break; case OpenFrameInThisTabAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("OpenFrameInThisTab"), true); break; case OpenFrameInNewTabBackgroundAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("OpenFrameInNewTabBackground"), true); break; case CopyFrameLinkToClipboardAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("CopyFrameLinkToClipboard"), true); break; case ViewSourceFrameAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("ViewSourceFrame"), true); actionObject->setEnabled(false); break; case ReloadFrameAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("ReloadFrame"), true); break; case SaveLinkToDownloadsAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("SaveLinkToDownloads")); break; case RewindBackAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("RewindBack"), true); actionObject->setEnabled(getAction(GoBackAction)->isEnabled()); break; case RewindForwardAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("RewindForward"), true); actionObject->setEnabled(getAction(GoForwardAction)->isEnabled()); break; case ReloadTimeAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("ReloadTime"), true); actionObject->setMenu(new QMenu(this)); actionObject->setEnabled(false); break; case PrintAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("Print"), true); break; case BookmarkAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("AddBookmark"), true); break; case BookmarkLinkAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("BookmarkLink"), true); break; case CopyAddressAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("CopyAddress"), true); break; case ViewSourceAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("ViewSource"), true); actionObject->setEnabled(false); break; case ValidateAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("Validate"), true); actionObject->setMenu(new QMenu(this)); actionObject->setEnabled(false); break; case ContentBlockingAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("ContentBlocking"), true); actionObject->setEnabled(false); break; case WebsitePreferencesAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("WebsitePreferences"), true); actionObject->setEnabled(false); break; case FullScreenAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("FullScreen"), true); actionObject->setEnabled(false); break; case ZoomInAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("ZoomIn")); break; case ZoomOutAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("ZoomOut"), true); break; case ZoomOriginalAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("ZoomOriginal"), true); break; case SearchAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("Search"), true); break; case SearchMenuAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("SearchMenu"), true); actionObject->setMenu(new QMenu(this)); connect(actionObject->menu(), SIGNAL(aboutToShow()), this, SLOT(searchMenuAboutToShow())); connect(actionObject->menu(), SIGNAL(triggered(QAction*)), this, SLOT(search(QAction*))); break; case OpenSelectionAsLinkAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("OpenSelectionAsLink"), true); break; case ClearAllAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("ClearAll"), true); break; case SpellCheckAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("SpellCheck"), true); actionObject->setEnabled(false); break; case ImagePropertiesAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("ImageProperties"), true); break; case CreateSearchAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("CreateSearch"), true); break; case ReloadOrStopAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("Reload")); actionObject->setEnabled(true); actionObject->setShortcut(QKeySequence()); break; case InspectPageAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("InspectPage")); actionObject->setEnabled(true); actionObject->setShortcut(QKeySequence()); break; case FindAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("Find"), true); actionObject->setEnabled(true); break; case FindNextAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("FindNext"), true); actionObject->setEnabled(true); break; case FindPreviousAction: ActionsManager::setupLocalAction(actionObject, QLatin1String("FindPrevious"), true); actionObject->setEnabled(true); break; default: actionObject->deleteLater(); actionObject = NULL; break; } if (actionObject) { m_actions[action] = actionObject; } return actionObject; }
void ItemDoor::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(1); QMenu ItemMenu; QAction *openLvl = ItemMenu.addAction(tr("Open target level: %1").arg(m_data.lname).replace("&", "&&&")); openLvl->setVisible((!m_data.lname.isEmpty()) && (QFile(m_scene->m_data->meta.path + "/" + m_data.lname).exists())); openLvl->deleteLater(); /*************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()->deleteLater();; 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***************/ QAction *jumpTo = NULL; if(this->data(ITEM_TYPE).toString() == "Door_enter") { jumpTo = ItemMenu.addAction(tr("Jump to exit")); jumpTo->setVisible((m_data.isSetIn) && (m_data.isSetOut)); } else if(this->data(ITEM_TYPE).toString() == "Door_exit") { jumpTo = ItemMenu.addAction(tr("Jump to entrance")); jumpTo->setVisible((m_data.isSetIn) && (m_data.isSetOut)); } ItemMenu.addSeparator(); QAction *NoTransport = ItemMenu.addAction(tr("No Vehicles")); NoTransport->setCheckable(true); NoTransport->setChecked(m_data.novehicles); QAction *AllowNPC = ItemMenu.addAction(tr("Allow NPC")); AllowNPC->setCheckable(true); AllowNPC->setChecked(m_data.allownpc); QAction *Locked = ItemMenu.addAction(tr("Locked")); Locked->setCheckable(true); Locked->setChecked(m_data.locked); QAction *BombNeed = ItemMenu.addAction(tr("Need a bomb")); BombNeed->setCheckable(true); BombNeed->setChecked(m_data.need_a_bomb); QAction *SpecialStReq = ItemMenu.addAction(tr("Required special state")); SpecialStReq->setCheckable(true); SpecialStReq->setChecked(m_data.special_state_required); /*************Copy Preferences*******************/ ItemMenu.addSeparator(); QMenu *copyPreferences = ItemMenu.addMenu(tr("Copy preferences")); QAction *copyPosXY = copyPreferences->addAction(tr("Position: X, Y")); QAction *copyPosXYWH = copyPreferences->addAction(tr("Position: X, Y, Width, Height")); QAction *copyPosLTRB = copyPreferences->addAction(tr("Position: Left, Top, Right, Bottom")); /*************Copy Preferences*end***************/ ItemMenu.addSeparator(); QAction *remove = ItemMenu.addAction(tr("Remove")); ItemMenu.addSeparator(); QAction *props = ItemMenu.addAction(tr("Properties...")); /*****************Waiting for answer************************/ QAction *selected = ItemMenu.exec(mouseEvent->screenPos()); /***********************************************************/ if(!selected) return; if(selected == openLvl) m_scene->m_mw->OpenFile(m_scene->m_data->meta.path + "/" + m_data.lname); else if(selected == jumpTo) { //scene->doCopy = true ; if(this->data(ITEM_TYPE).toString() == "Door_enter") { if(m_data.isSetOut) m_scene->m_mw->activeLvlEditWin()->goTo(m_data.ox, m_data.oy, true, QPoint(0, 0), true); } else if(this->data(ITEM_TYPE).toString() == "Door_exit") { if(m_data.isSetIn) m_scene->m_mw->activeLvlEditWin()->goTo(m_data.ix, m_data.iy, true, QPoint(0, 0), true); } } else if(selected == NoTransport) { LevelData modDoors; for(QGraphicsItem *SelItem : m_scene->selectedItems()) { if((SelItem->data(ITEM_TYPE).toString() == "Door_exit") || (SelItem->data(ITEM_TYPE).toString() == "Door_enter")) { if(SelItem->data(ITEM_TYPE).toString() == "Door_exit") { LevelDoor door = ((ItemDoor *) SelItem)->m_data; door.isSetOut = true; door.isSetIn = false; modDoors.doors.push_back(door); } else if(SelItem->data(ITEM_TYPE).toString() == "Door_enter") { LevelDoor door = ((ItemDoor *) SelItem)->m_data; door.isSetOut = false; door.isSetIn = true; modDoors.doors.push_back(door); } ((ItemDoor *) SelItem)->m_data.novehicles = NoTransport->isChecked(); ((ItemDoor *) SelItem)->arrayApply(); } } m_scene->m_history->addChangeSettings(modDoors, HistorySettings::SETTING_NOVEHICLE, QVariant(NoTransport->isChecked())); m_scene->m_mw->dock_LvlWarpProps->setDoorData(-2); } else if(selected == AllowNPC) { LevelData modDoors; for(QGraphicsItem *SelItem : m_scene->selectedItems()) { if((SelItem->data(ITEM_TYPE).toString() == "Door_exit") || (SelItem->data(ITEM_TYPE).toString() == "Door_enter")) { if(SelItem->data(ITEM_TYPE).toString() == "Door_exit") { LevelDoor door = ((ItemDoor *) SelItem)->m_data; door.isSetOut = true; door.isSetIn = false; modDoors.doors.push_back(door); } else if(SelItem->data(ITEM_TYPE).toString() == "Door_enter") { LevelDoor door = ((ItemDoor *) SelItem)->m_data; door.isSetOut = false; door.isSetIn = true; modDoors.doors.push_back(door); } ((ItemDoor *) SelItem)->m_data.allownpc = AllowNPC->isChecked(); ((ItemDoor *) SelItem)->arrayApply(); } } m_scene->m_history->addChangeSettings(modDoors, HistorySettings::SETTING_ALLOWNPC, QVariant(AllowNPC->isChecked())); m_scene->m_mw->dock_LvlWarpProps->setDoorData(-2); } else if(selected == Locked) { LevelData modDoors; for(QGraphicsItem *SelItem : m_scene->selectedItems()) { if((SelItem->data(ITEM_TYPE).toString() == "Door_exit") || (SelItem->data(ITEM_TYPE).toString() == "Door_enter")) { if(SelItem->data(ITEM_TYPE).toString() == "Door_exit") { LevelDoor door = ((ItemDoor *) SelItem)->m_data; door.isSetOut = true; door.isSetIn = false; modDoors.doors.push_back(door); } else if(SelItem->data(ITEM_TYPE).toString() == "Door_enter") { LevelDoor door = ((ItemDoor *) SelItem)->m_data; door.isSetOut = false; door.isSetIn = true; modDoors.doors.push_back(door); } ((ItemDoor *) SelItem)->m_data.locked = Locked->isChecked(); ((ItemDoor *) SelItem)->arrayApply(); } } m_scene->m_history->addChangeSettings(modDoors, HistorySettings::SETTING_LOCKED, QVariant(Locked->isChecked())); m_scene->m_mw->dock_LvlWarpProps->setDoorData(-2); } else if(selected == BombNeed) { LevelData modDoors; for(QGraphicsItem *SelItem : m_scene->selectedItems()) { if((SelItem->data(ITEM_TYPE).toString() == "Door_exit") || (SelItem->data(ITEM_TYPE).toString() == "Door_enter")) { if(SelItem->data(ITEM_TYPE).toString() == "Door_exit") { LevelDoor door = ((ItemDoor *) SelItem)->m_data; door.isSetOut = true; door.isSetIn = false; modDoors.doors.push_back(door); } else if(SelItem->data(ITEM_TYPE).toString() == "Door_enter") { LevelDoor door = ((ItemDoor *) SelItem)->m_data; door.isSetOut = false; door.isSetIn = true; modDoors.doors.push_back(door); } ((ItemDoor *) SelItem)->m_data.need_a_bomb = BombNeed->isChecked(); ((ItemDoor *) SelItem)->arrayApply(); } } m_scene->m_history->addChangeSettings(modDoors, HistorySettings::SETTING_NEED_A_BOMB, QVariant(BombNeed->isChecked())); m_scene->m_mw->dock_LvlWarpProps->setDoorData(-2); } else if(selected == SpecialStReq) { LevelData modDoors; for(QGraphicsItem *SelItem : m_scene->selectedItems()) { if((SelItem->data(ITEM_TYPE).toString() == "Door_exit") || (SelItem->data(ITEM_TYPE).toString() == "Door_enter")) { if(SelItem->data(ITEM_TYPE).toString() == "Door_exit") { LevelDoor door = ((ItemDoor *) SelItem)->m_data; door.isSetOut = true; door.isSetIn = false; modDoors.doors.push_back(door); } else if(SelItem->data(ITEM_TYPE).toString() == "Door_enter") { LevelDoor door = ((ItemDoor *) SelItem)->m_data; door.isSetOut = false; door.isSetIn = true; modDoors.doors.push_back(door); } ((ItemDoor *) SelItem)->m_data.special_state_required = SpecialStReq->isChecked(); ((ItemDoor *) SelItem)->arrayApply(); } } m_scene->m_history->addChangeSettings(modDoors, HistorySettings::SETTING_W_SPECIAL_STATE_REQUIRED, QVariant(SpecialStReq->isChecked())); m_scene->m_mw->dock_LvlWarpProps->setDoorData(-2); } else if(selected == copyPosXY) { QApplication::clipboard()->setText( QString("X=%1; Y=%2;") .arg(m_pointSide == D_Entrance ? m_data.ix : m_data.ox) .arg(m_pointSide == D_Entrance ? m_data.iy : m_data.oy) ); m_scene->m_mw->showStatusMsg(tr("Preferences have 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_pointSide == D_Entrance ? m_data.ix : m_data.ox) .arg(m_pointSide == D_Entrance ? m_data.iy : m_data.oy) .arg(m_itemSize.width()) .arg(m_itemSize.height()) ); 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_pointSide == D_Entrance ? m_data.ix : m_data.ox) .arg(m_pointSide == D_Entrance ? m_data.iy : m_data.oy) .arg((m_pointSide == D_Entrance ? m_data.ix : m_data.ox) + m_itemSize.width()) .arg((m_pointSide == D_Entrance ? m_data.iy : m_data.oy) + m_itemSize.height()) ); m_scene->m_mw->showStatusMsg(tr("Preferences have been copied: %1").arg(QApplication::clipboard()->text())); } else if(selected == remove) m_scene->removeSelectedLvlItems(); else if(selected == props) m_scene->m_mw->dock_LvlWarpProps->SwitchToDoor(m_data.meta.array_id); else if(selected == newLayer) { m_scene->setLayerToSelected(); m_scene->applyLayersVisible(); } else { //Fetch layers menu foreach(QAction *lItem, layerItems) { if(selected == lItem) { //FOUND!!! m_scene->setLayerToSelected(lItem->data().toString()); m_scene->applyLayersVisible(); m_scene->m_mw->dock_LvlWarpProps->setDoorData(-2); break; }//Find selected layer's item } } }
void ItemTile::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) { int multimouse=0; bool callContext=false; if(((mouseMid)||(mouseRight))&&( mouseLeft^(mouseEvent->buttons() & Qt::LeftButton) )) multimouse++; if( (((mouseLeft)||(mouseRight)))&&( mouseMid^(mouseEvent->buttons() & Qt::MiddleButton) )) multimouse++; if((((mouseLeft)||(mouseMid)))&&( mouseRight^(mouseEvent->buttons() & Qt::RightButton) )) multimouse++; if(multimouse>0) { mouseEvent->accept(); return; } if( mouseLeft^(mouseEvent->buttons() & Qt::LeftButton) ) mouseLeft=false; if( mouseMid^(mouseEvent->buttons() & Qt::MiddleButton) ) mouseMid=false; if( mouseRight^(mouseEvent->buttons() & Qt::RightButton) ) { if(!scene->IsMoved) callContext=true; mouseRight=false; } QGraphicsItem::mouseReleaseEvent(mouseEvent); /////////////////////////CONTEXT MENU://///////////////////////////// if((callContext)&&(!scene->contextMenuOpened)) { if((!scene->lock_tile)&&(!scene->DrawMode)&&(!isLocked)) { scene->contextMenuOpened = true; //bug protector //Remove selection from non-bgo items if(!this->isSelected()) { scene->clearSelection(); this->setSelected(true); } this->setSelected(1); ItemMenu->clear(); QAction *copyTile = ItemMenu->addAction(tr("Copy")); copyTile->deleteLater(); QAction *cutTile = ItemMenu->addAction(tr("Cut")); cutTile->deleteLater(); ItemMenu->addSeparator()->deleteLater(); QAction *remove = ItemMenu->addAction(tr("Remove")); remove->deleteLater(); QAction *selected = ItemMenu->exec(mouseEvent->screenPos()); if(!selected) { #ifdef _DEBUG_ WriteToLog(QtDebugMsg, "Context Menu <- NULL"); #endif return; } if(selected==cutTile) { MainWinConnect::pMainWin->on_actionCut_triggered(); } else if(selected==copyTile) { MainWinConnect::pMainWin->on_actionCopy_triggered(); } else if(selected==remove) { scene->removeSelectedWldItems(); } } } }
void TabBarWidget::contextMenuEvent(QContextMenuEvent *event) { m_clickedTab = tabAt(event->pos()); hidePreview(); QMenu menu(this); menu.addAction(ActionsManager::getAction(ActionsManager::NewTabAction, this)); menu.addAction(ActionsManager::getAction(ActionsManager::NewTabPrivateAction, this)); if (m_clickedTab >= 0) { const bool isPinned = getTabProperty(m_clickedTab, QLatin1String("isPinned"), false).toBool(); Action *cloneTabAction = new Action(ActionsManager::CloneTabAction, &menu); cloneTabAction->setEnabled(getTabProperty(m_clickedTab, QLatin1String("canClone"), false).toBool()); Action *pinTabAction = new Action(ActionsManager::PinTabAction, &menu); pinTabAction->setOverrideText(isPinned ? QT_TRANSLATE_NOOP("actions", "Unpin Tab") : QT_TRANSLATE_NOOP("actions", "Pin Tab")); Action *detachTabAction = new Action(ActionsManager::DetachTabAction, &menu); detachTabAction->setEnabled(count() > 1); menu.addAction(cloneTabAction); menu.addAction(pinTabAction); menu.addSeparator(); menu.addAction(detachTabAction); menu.addSeparator(); if (isPinned) { Action *closeTabAction = new Action(ActionsManager::CloseTabAction, &menu); closeTabAction->setEnabled(false); menu.addAction(closeTabAction); } else { menu.addAction(ActionsManager::getAction(ActionsManager::CloseTabAction, this)); } const int amount = (count() - getPinnedTabsAmount()); Action *closeOtherTabsAction = new Action(ActionsManager::CloseOtherTabsAction, &menu); closeOtherTabsAction->setEnabled(amount > 0 && !(amount == 1 && !isPinned)); menu.addAction(closeOtherTabsAction); menu.addAction(ActionsManager::getAction(ActionsManager::ClosePrivateTabsAction, this)); connect(cloneTabAction, SIGNAL(triggered()), this, SLOT(cloneTab())); connect(pinTabAction, SIGNAL(triggered()), this, SLOT(pinTab())); connect(detachTabAction, SIGNAL(triggered()), this, SLOT(detachTab())); connect(closeOtherTabsAction, SIGNAL(triggered()), this, SLOT(closeOtherTabs())); } menu.addSeparator(); QMenu *arrangeMenu = menu.addMenu(tr("Arrange")); arrangeMenu->addAction(ActionsManager::getAction(ActionsManager::RestoreTabAction, this)); arrangeMenu->addSeparator(); arrangeMenu->addAction(ActionsManager::getAction(ActionsManager::RestoreAllAction, this)); arrangeMenu->addAction(ActionsManager::getAction(ActionsManager::MaximizeAllAction, this)); arrangeMenu->addAction(ActionsManager::getAction(ActionsManager::MinimizeAllAction, this)); arrangeMenu->addSeparator(); arrangeMenu->addAction(ActionsManager::getAction(ActionsManager::CascadeAllAction, this)); arrangeMenu->addAction(ActionsManager::getAction(ActionsManager::TileAllAction, this)); QAction *cycleAction = new QAction(tr("Switch tabs using the mouse wheel"), this); cycleAction->setCheckable(true); cycleAction->setChecked(!SettingsManager::getValue(QLatin1String("TabBar/RequireModifierToSwitchTabOnScroll")).toBool()); connect(cycleAction, SIGNAL(toggled(bool)), this, SLOT(setCycle(bool))); ToolBarWidget *toolBar = qobject_cast<ToolBarWidget*>(parentWidget()); if (toolBar) { QList<QAction*> actions; actions.append(cycleAction); menu.addMenu(ToolBarWidget::createCustomizationMenu(ToolBarsManager::TabBar, actions, &menu)); } else { QMenu *customizationMenu = menu.addMenu(tr("Customize")); customizationMenu->addAction(cycleAction); customizationMenu->addSeparator(); customizationMenu->addAction(ActionsManager::getAction(ActionsManager::LockToolBarsAction, this)); } menu.exec(event->globalPos()); cycleAction->deleteLater(); m_clickedTab = -1; if (underMouse()) { m_previewTimer = startTimer(250); } }
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 ); } } } }