Changeset 84635 in vbox
- Timestamp:
- Jun 2, 2020 11:56:56 AM (4 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.cpp
r84625 r84635 63 63 , m_pMouseHandler(0) 64 64 , m_pKeyboardHandler(0) 65 , m_pContextMenuGlobal(0)66 , m_pContextMenuGroup(0)67 , m_pContextMenuMachine(0)68 65 , m_iCurrentSearchResultIndex(-1) 69 66 , m_iScrollingTokenSize(30) … … 1235 1232 { 1236 1233 /* Context menu for global(s): */ 1237 m_ pContextMenuGlobal= new QMenu;1238 if ( m_pContextMenuGlobal)1234 m_menus[UIChooserNodeType_Global] = new QMenu; 1235 if (QMenu *pMenuGlobal = m_menus.value(UIChooserNodeType_Global)) 1239 1236 { 1240 1237 /* Check if Ext Pack is ready, some of actions my depend on it: */ … … 1243 1240 1244 1241 #ifdef VBOX_WS_MAC 1245 m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndex_M_Application_S_About));1246 m_pContextMenuGlobal->addSeparator();1247 m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndex_M_Application_S_Preferences));1248 m_pContextMenuGlobal->addSeparator();1249 m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ImportAppliance));1250 m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ExportAppliance));1251 m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_NewCloudVM));1242 pMenuGlobal->addAction(actionPool()->action(UIActionIndex_M_Application_S_About)); 1243 pMenuGlobal->addSeparator(); 1244 pMenuGlobal->addAction(actionPool()->action(UIActionIndex_M_Application_S_Preferences)); 1245 pMenuGlobal->addSeparator(); 1246 pMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ImportAppliance)); 1247 pMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ExportAppliance)); 1248 pMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_NewCloudVM)); 1252 1249 # ifdef VBOX_GUI_WITH_EXTRADATA_MANAGER_UI 1253 m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowExtraDataManager));1250 pMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowExtraDataManager)); 1254 1251 # endif 1255 m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowVirtualMediumManager));1256 m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowHostNetworkManager));1252 pMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowVirtualMediumManager)); 1253 pMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowHostNetworkManager)); 1257 1254 if (fExtPackAccessible) 1258 m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowCloudProfileManager));1255 pMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowCloudProfileManager)); 1259 1256 1260 1257 #else /* !VBOX_WS_MAC */ 1261 1258 1262 m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndex_M_Application_S_Preferences));1263 m_pContextMenuGlobal->addSeparator();1264 m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ImportAppliance));1265 m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ExportAppliance));1266 m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_NewCloudVM));1267 m_pContextMenuGlobal->addSeparator();1259 pMenuGlobal->addAction(actionPool()->action(UIActionIndex_M_Application_S_Preferences)); 1260 pMenuGlobal->addSeparator(); 1261 pMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ImportAppliance)); 1262 pMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ExportAppliance)); 1263 pMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_NewCloudVM)); 1264 pMenuGlobal->addSeparator(); 1268 1265 # ifdef VBOX_GUI_WITH_EXTRADATA_MANAGER_UI 1269 m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowExtraDataManager));1266 pMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowExtraDataManager)); 1270 1267 # endif 1271 m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowVirtualMediumManager));1272 m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowHostNetworkManager));1268 pMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowVirtualMediumManager)); 1269 pMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowHostNetworkManager)); 1273 1270 if (fExtPackAccessible) 1274 m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowCloudProfileManager));1271 pMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowCloudProfileManager)); 1275 1272 # ifdef VBOX_GUI_WITH_NETWORK_MANAGER 1276 m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndex_M_Application_S_NetworkAccessManager));1273 pMenuGlobal->addAction(actionPool()->action(UIActionIndex_M_Application_S_NetworkAccessManager)); 1277 1274 if (gEDataManager->applicationUpdateEnabled()) 1278 m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndex_M_Application_S_CheckForUpdates));1275 pMenuGlobal->addAction(actionPool()->action(UIActionIndex_M_Application_S_CheckForUpdates)); 1279 1276 # endif 1280 1277 #endif /* !VBOX_WS_MAC */ … … 1282 1279 1283 1280 /* Context menu for group(s): */ 1284 m_ pContextMenuGroup= new QMenu;1285 if ( m_pContextMenuGroup)1286 { 1287 m_pContextMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_New));1288 m_pContextMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_Add));1289 m_pContextMenuGroup->addSeparator();1290 m_pContextMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_Rename));1291 m_pContextMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_Remove));1292 m_pContextMenuGroup->addMenu(actionPool()->action(UIActionIndexST_M_Group_M_MoveToGroup)->menu());1293 m_pContextMenuGroup->addSeparator();1294 m_pContextMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_M_StartOrShow));1295 m_pContextMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_T_Pause));1296 m_pContextMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_Reset));1297 m_pContextMenuGroup->addMenu(actionPool()->action(UIActionIndexST_M_Group_M_Close)->menu());1298 m_pContextMenuGroup->addSeparator();1299 m_pContextMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_Discard));1300 m_pContextMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_ShowLogDialog));1301 m_pContextMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_Refresh));1302 m_pContextMenuGroup->addSeparator();1303 m_pContextMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_ShowInFileManager));1304 m_pContextMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_CreateShortcut));1305 m_pContextMenuGroup->addSeparator();1306 m_pContextMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_Sort));1281 m_menus[UIChooserNodeType_Group] = new QMenu; 1282 if (QMenu *pMenuGroup = m_menus.value(UIChooserNodeType_Group)) 1283 { 1284 pMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_New)); 1285 pMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_Add)); 1286 pMenuGroup->addSeparator(); 1287 pMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_Rename)); 1288 pMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_Remove)); 1289 pMenuGroup->addMenu(actionPool()->action(UIActionIndexST_M_Group_M_MoveToGroup)->menu()); 1290 pMenuGroup->addSeparator(); 1291 pMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_M_StartOrShow)); 1292 pMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_T_Pause)); 1293 pMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_Reset)); 1294 pMenuGroup->addMenu(actionPool()->action(UIActionIndexST_M_Group_M_Close)->menu()); 1295 pMenuGroup->addSeparator(); 1296 pMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_Discard)); 1297 pMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_ShowLogDialog)); 1298 pMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_Refresh)); 1299 pMenuGroup->addSeparator(); 1300 pMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_ShowInFileManager)); 1301 pMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_CreateShortcut)); 1302 pMenuGroup->addSeparator(); 1303 pMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_Sort)); 1307 1304 } 1308 1305 1309 1306 /* Context menu for machine(s): */ 1310 m_ pContextMenuMachine= new QMenu;1311 if ( m_pContextMenuMachine)1312 { 1313 m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_Settings));1314 m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_Clone));1315 m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_Move));1316 m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_ExportToOCI));1317 m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_Remove));1318 m_pContextMenuMachine->addMenu(actionPool()->action(UIActionIndexST_M_Machine_M_MoveToGroup)->menu());1319 m_pContextMenuMachine->addSeparator();1320 m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_M_StartOrShow));1321 m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_T_Pause));1322 m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_Reset));1323 m_pContextMenuMachine->addMenu(actionPool()->action(UIActionIndexST_M_Machine_M_Close)->menu());1324 m_pContextMenuMachine->addSeparator();1325 m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_Discard));1326 m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_ShowLogDialog));1327 m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_Refresh));1328 m_pContextMenuMachine->addSeparator();1329 m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_ShowInFileManager));1330 m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_CreateShortcut));1331 m_pContextMenuMachine->addSeparator();1332 m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_SortParent));1333 m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_T_Search));1307 m_menus[UIChooserNodeType_Machine] = new QMenu; 1308 if (QMenu *pMenuMachine = m_menus.value(UIChooserNodeType_Machine)) 1309 { 1310 pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_Settings)); 1311 pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_Clone)); 1312 pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_Move)); 1313 pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_ExportToOCI)); 1314 pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_Remove)); 1315 pMenuMachine->addMenu(actionPool()->action(UIActionIndexST_M_Machine_M_MoveToGroup)->menu()); 1316 pMenuMachine->addSeparator(); 1317 pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_M_StartOrShow)); 1318 pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_T_Pause)); 1319 pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_Reset)); 1320 pMenuMachine->addMenu(actionPool()->action(UIActionIndexST_M_Machine_M_Close)->menu()); 1321 pMenuMachine->addSeparator(); 1322 pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_Discard)); 1323 pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_ShowLogDialog)); 1324 pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_Refresh)); 1325 pMenuMachine->addSeparator(); 1326 pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_ShowInFileManager)); 1327 pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_CreateShortcut)); 1328 pMenuMachine->addSeparator(); 1329 pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_SortParent)); 1330 pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_T_Search)); 1334 1331 } 1335 1332 } … … 1381 1378 void UIChooserModel::cleanupContextMenu() 1382 1379 { 1383 delete m_pContextMenuGlobal; 1384 m_pContextMenuGlobal = 0; 1385 delete m_pContextMenuGroup; 1386 m_pContextMenuGroup = 0; 1387 delete m_pContextMenuMachine; 1388 m_pContextMenuMachine = 0; 1380 qDeleteAll(m_menus); 1381 m_menus.clear(); 1389 1382 } 1390 1383 … … 1409 1402 case QGraphicsSceneContextMenuEvent::Mouse: 1410 1403 { 1411 /* First of all we should look for an item under cursor: */1404 /* Look for an item under cursor: */ 1412 1405 if (QGraphicsItem *pItem = itemAt(pEvent->scenePos())) 1413 1406 { 1414 /* If this item of known type? */1415 1407 switch (pItem->type()) 1416 1408 { 1417 1409 case UIChooserNodeType_Global: 1418 1410 { 1419 /* Global context menu for global item cases: */1420 popupContextMenu(UIGraphicsSelectorContextMenuType_Global,pEvent->screenPos());1421 return true;1411 /* Global context menu for all global item cases: */ 1412 m_menus.value(UIChooserNodeType_Global)->exec(pEvent->screenPos()); 1413 break; 1422 1414 } 1423 1415 case UIChooserNodeType_Group: … … 1425 1417 /* Get group-item: */ 1426 1418 UIChooserItem *pGroupItem = qgraphicsitem_cast<UIChooserItemGroup*>(pItem); 1427 /* Make sure thats not root: */1419 /* Don't show context menu for root-item: */ 1428 1420 if (pGroupItem->isRoot()) 1429 return false;1430 /* Is this group-item only the one selected?*/1421 break; 1422 /* Make sure we have group-item selected exclusively: */ 1431 1423 if (selectedItems().contains(pGroupItem) && selectedItems().size() == 1) 1432 1424 { 1433 1425 /* Group context menu in that case: */ 1434 popupContextMenu(UIGraphicsSelectorContextMenuType_Group,pEvent->screenPos());1435 return true;1426 m_menus.value(UIChooserNodeType_Group)->exec(pEvent->screenPos()); 1427 break; 1436 1428 } 1437 1429 } … … 1440 1432 { 1441 1433 /* Machine context menu for other Group/Machine cases: */ 1442 popupContextMenu(UIGraphicsSelectorContextMenuType_Machine,pEvent->screenPos());1443 return true;1434 m_menus.value(UIChooserNodeType_Machine)->exec(pEvent->screenPos()); 1435 break; 1444 1436 } 1445 1437 default: … … 1447 1439 } 1448 1440 } 1441 /* Filter out by default: */ 1449 1442 return true; 1450 1443 } … … 1454 1447 if (UIChooserItem *pItem = firstSelectedItem()) 1455 1448 { 1456 /* If this item of known type? */1457 1449 switch (pItem->type()) 1458 1450 { 1459 1451 case UIChooserNodeType_Global: 1460 1452 { 1461 /* Global context menu for global item cases: */1462 popupContextMenu(UIGraphicsSelectorContextMenuType_Machine,pEvent->screenPos());1463 return true;1453 /* Global context menu for all global item cases: */ 1454 m_menus.value(UIChooserNodeType_Global)->exec(pEvent->screenPos()); 1455 break; 1464 1456 } 1465 1457 case UIChooserNodeType_Group: 1466 1458 { 1467 /* Is this group-item only the one selected?*/1459 /* Make sure we have group-item selected exclusively: */ 1468 1460 if (selectedItems().size() == 1) 1469 1461 { 1470 1462 /* Group context menu in that case: */ 1471 popupContextMenu(UIGraphicsSelectorContextMenuType_Group,pEvent->screenPos());1472 return true;1463 m_menus.value(UIChooserNodeType_Group)->exec(pEvent->screenPos()); 1464 break; 1473 1465 } 1474 1466 } … … 1477 1469 { 1478 1470 /* Machine context menu for other Group/Machine cases: */ 1479 popupContextMenu(UIGraphicsSelectorContextMenuType_Machine,pEvent->screenPos());1480 return true;1471 m_menus.value(UIChooserNodeType_Machine)->exec(pEvent->screenPos()); 1472 break; 1481 1473 } 1482 1474 default: … … 1484 1476 } 1485 1477 } 1478 /* Filter out by default: */ 1486 1479 return true; 1487 1480 } … … 1491 1484 /* Pass others context menu events: */ 1492 1485 return false; 1493 }1494 1495 void UIChooserModel::popupContextMenu(UIGraphicsSelectorContextMenuType enmType, QPoint point)1496 {1497 /* Which type of context-menu requested? */1498 switch (enmType)1499 {1500 /* For global item? */1501 case UIGraphicsSelectorContextMenuType_Global:1502 {1503 m_pContextMenuGlobal->exec(point);1504 break;1505 }1506 /* For group? */1507 case UIGraphicsSelectorContextMenuType_Group:1508 {1509 m_pContextMenuGroup->exec(point);1510 break;1511 }1512 /* For machine(s)? */1513 case UIGraphicsSelectorContextMenuType_Machine:1514 {1515 m_pContextMenuMachine->exec(point);1516 break;1517 }1518 }1519 1486 } 1520 1487 -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.h
r84625 r84635 45 45 class UIChooserView; 46 46 class UIVirtualMachineItem; 47 48 49 /** Context-menu types. */50 enum UIGraphicsSelectorContextMenuType51 {52 UIGraphicsSelectorContextMenuType_Global,53 UIGraphicsSelectorContextMenuType_Group,54 UIGraphicsSelectorContextMenuType_Machine55 };56 57 47 58 48 /** UIChooserAbstractModel extension used as VM Chooser-pane model. … … 340 330 /** Handles context-menu @a pEvent. */ 341 331 bool processContextMenuEvent(QGraphicsSceneContextMenuEvent *pEvent); 342 /** Popups context-menu of certain @a enmType in specified @a point. */343 void popupContextMenu(UIGraphicsSelectorContextMenuType enmType, QPoint point);344 332 /** @} */ 345 333 … … 389 377 UIChooserHandlerKeyboard *m_pKeyboardHandler; 390 378 391 /** Holds the global item context menu instance. */ 392 QMenu *m_pContextMenuGlobal; 393 /** Holds the group item context menu instance. */ 394 QMenu *m_pContextMenuGroup; 395 /** Holds the machine item context menu instance. */ 396 QMenu *m_pContextMenuMachine; 379 /** Holds the map of context-menu instances. */ 380 QMap<UIChooserNodeType, QMenu*> m_menus; 397 381 /** @} */ 398 382 … … 428 412 }; 429 413 430 431 414 #endif /* !FEQT_INCLUDED_SRC_manager_chooser_UIChooserModel_h */
Note:
See TracChangeset
for help on using the changeset viewer.