Showing the changes to interface/src/Menu.cpp (1 of 8 files). Show all
Unified · Split
| @@ -690,13 +690,28 @@ QAction* Menu::addActionToQMenuAndActionHash(QMenu* destinationMenu, · 689 unmodified lines | ||
| 690 | 690 | const char* member, |
| 691 | 691 | QAction::MenuRole role, |
| 692 | 692 | int menuItemLocation) { |
| 693 | − QAction* action; | |
| 693 | + QAction* action = NULL; | |
| 694 | + QAction* actionBefore = NULL; | |
| 695 | + | |
| 696 | + if (menuItemLocation >= 0 && destinationMenu->actions().size() > menuItemLocation) { | |
| 697 | + actionBefore = destinationMenu->actions()[menuItemLocation]; | |
| 698 | + } | |
| 694 | 699 | |
| 695 | − if (receiver && member) { | |
| 696 | − action = destinationMenu->addAction(actionName, receiver, member, shortcut); | |
| 700 | + if (!actionBefore) { | |
| 701 | + if (receiver && member) { | |
| 702 | + action = destinationMenu->addAction(actionName, receiver, member, shortcut); | |
| 703 | + } else { | |
| 704 | + action = destinationMenu->addAction(actionName); | |
| 705 | + action->setShortcut(shortcut); | |
| 706 | + } | |
| 697 | 707 | } else { |
| 698 | − action = destinationMenu->addAction(actionName); | |
| 708 | + action = new QAction(actionName, destinationMenu); | |
| 699 | 709 | action->setShortcut(shortcut); |
| 710 | + destinationMenu->insertAction(actionBefore, action); | |
| 711 | + | |
| 712 | + if (receiver && member) { | |
| 713 | + connect(action, SIGNAL(triggered()), receiver, member); | |
| 714 | + } | |
| 700 | 715 | } |
| 701 | 716 | action->setMenuRole(role); |
| 702 | 717 | |
| @@ -1366,6 +1381,17 @@ QAction* Menu::getMenuAction(const QString& menuName) { · 663 unmodified lines | ||
| 1366 | 1381 | return action; |
| 1367 | 1382 | } |
| 1368 | 1383 | |
| 1384 | +int Menu::findPositionOfMenuItem(QMenu* menu, const QString& searchMenuItem) { | |
| 1385 | + int position = 0; | |
| 1386 | + foreach(QAction* action, menu->actions()) { | |
| 1387 | + if (action->text() == searchMenuItem) { | |
| 1388 | + return position; | |
| 1389 | + } | |
| 1390 | + position++; | |
| 1391 | + } | |
| 1392 | + return UNSPECIFIED_POSITION; // not found | |
| 1393 | +} | |
| 1394 | + | |
| 1369 | 1395 | QMenu* Menu::addMenu(const QString& menuName) { |
| 1370 | 1396 | QStringList menuTree = menuName.split(">"); |
| 1371 | 1397 | QMenu* addTo = NULL; |
| @@ -1416,24 +1442,30 @@ void Menu::addMenuItem(const MenuItemProperties& properties) { · 44 unmodified lines | ||
| 1416 | 1442 | if (menuObj) { |
| 1417 | 1443 | QShortcut* shortcut = NULL; |
| 1418 | 1444 | if (!properties.shortcutKeySequence.isEmpty()) { |
| 1419 | − shortcut = new QShortcut(properties.shortcutKey, this); | |
| 1445 | + shortcut = new QShortcut(properties.shortcutKeySequence, this); | |
| 1420 | 1446 | } |
| 1421 | 1447 | |
| 1422 | − /** | |
| 1423 | − // test insert in middle of menu... | |
| 1424 | − QAction* physics = getMenuAction("Edit>Physics"); | |
| 1425 | − QAction* testHack = new QAction("test", editMenu); | |
| 1426 | − editMenu->insertAction(gravity, testHack); | |
| 1427 | − **/ | |
| 1448 | + // check for positioning requests | |
| 1449 | + int requestedPosition = properties.position; | |
| 1450 | + if (requestedPosition == UNSPECIFIED_POSITION && !properties.beforeItem.isEmpty()) { | |
| 1451 | + requestedPosition = findPositionOfMenuItem(menuObj, properties.beforeItem); | |
| 1452 | + } | |
| 1453 | + if (requestedPosition == UNSPECIFIED_POSITION && !properties.afterItem.isEmpty()) { | |
| 1454 | + int afterPosition = findPositionOfMenuItem(menuObj, properties.afterItem); | |
| 1455 | + if (afterPosition != UNSPECIFIED_POSITION) { | |
| 1456 | + requestedPosition = afterPosition + 1; | |
| 1457 | + } | |
| 1458 | + } | |
| 1428 | 1459 | |
| 1429 | 1460 | QAction* menuItemAction; |
| 1430 | 1461 | if (properties.isCheckable) { |
| 1431 | 1462 | menuItemAction = addCheckableActionToQMenuAndActionHash(menuObj, properties.menuItemName, |
| 1432 | 1463 | properties.shortcutKeySequence, properties.isChecked, |
| 1433 | − MenuScriptingInterface::getInstance(), SLOT(menuItemTriggered())); | |
| 1464 | + MenuScriptingInterface::getInstance(), SLOT(menuItemTriggered()), requestedPosition); | |
| 1434 | 1465 | } else { |
| 1435 | 1466 | menuItemAction = addActionToQMenuAndActionHash(menuObj, properties.menuItemName, properties.shortcutKeySequence, |
| 1436 | − MenuScriptingInterface::getInstance(), SLOT(menuItemTriggered())); | |
| 1467 | + MenuScriptingInterface::getInstance(), SLOT(menuItemTriggered()), | |
| 1468 | + QAction::NoRole, requestedPosition); | |
| 1437 | 1469 | } |
| 1438 | 1470 | if (shortcut) { |
| 1439 | 1471 | connect(shortcut, SIGNAL(activated()), menuItemAction, SLOT(trigger())); |