diff --git a/interface/resources/qml/desktop/Desktop.qml b/interface/resources/qml/desktop/Desktop.qml index 847111b8a0..e7c68b2a47 100644 --- a/interface/resources/qml/desktop/Desktop.qml +++ b/interface/resources/qml/desktop/Desktop.qml @@ -51,19 +51,23 @@ FocusScope { // The VR version of the primary menu property var rootMenu: Menu { + id: rootMenuId objectName: "rootMenu" - // for some reasons it is not possible to use just '({})' here as it gets empty when passed to TableRoot/DesktopRoot - property var exclusionGroupsByMenuItem : ListModel {} + property var exclusionGroups: ({}); + property Component exclusiveGroupMaker: Component { + ExclusiveGroup { + } + } - function addExclusionGroup(menuItem, exclusionGroup) - { - exclusionGroupsByMenuItem.append( - { - 'menuItem' : menuItem.toString(), - 'exclusionGroup' : exclusionGroup.toString() - } - ); + function addExclusionGroup(qmlAction, exclusionGroup) { + + var exclusionGroupId = exclusionGroup.toString(); + if(!exclusionGroups[exclusionGroupId]) { + exclusionGroups[exclusionGroupId] = exclusiveGroupMaker.createObject(rootMenuId); + } + + qmlAction.exclusiveGroup = exclusionGroups[exclusionGroupId] } } diff --git a/interface/resources/qml/hifi/tablet/TabletMenuItem.qml b/interface/resources/qml/hifi/tablet/TabletMenuItem.qml index 11d3cab35e..520841b33f 100644 --- a/interface/resources/qml/hifi/tablet/TabletMenuItem.qml +++ b/interface/resources/qml/hifi/tablet/TabletMenuItem.qml @@ -40,37 +40,29 @@ Item { CheckBox { id: checkbox - // FIXME: Should use radio buttons if source.exclusiveGroup. + width: 20 visible: source !== null ? source.visible && source.type === 1 && source.checkable && !source.exclusiveGroup : false - checked: setChecked() - function setChecked() { - if (!source || source.type !== 1 || !source.checkable) { - return false; - } - // FIXME this works for native QML menus but I don't think it will - // for proxied QML menus - return source.checked; + + Binding on checked { + value: source.checked; + when: source && source.type === 1 && source.checkable && !source.exclusiveGroup; } } RadioButton { id: radiobutton - // FIXME: Should use radio buttons if source.exclusiveGroup. + width: 20 visible: source !== null ? source.visible && source.type === 1 && source.checkable && source.exclusiveGroup : false - checked: setChecked() - function setChecked() { - if (!source || source.type !== 1 || !source.checkable) { - return false; - } - // FIXME this works for native QML menus but I don't think it will - // for proxied QML menus - return source.checked; + + Binding on checked { + value: source.checked; + when: source && source.type === 1 && source.checkable && source.exclusiveGroup; } } } diff --git a/interface/resources/qml/hifi/tablet/TabletMenuStack.qml b/interface/resources/qml/hifi/tablet/TabletMenuStack.qml index ce4fac3bd5..8cd696a41b 100644 --- a/interface/resources/qml/hifi/tablet/TabletMenuStack.qml +++ b/interface/resources/qml/hifi/tablet/TabletMenuStack.qml @@ -66,7 +66,6 @@ Item { function toModel(items, newMenu) { var result = modelMaker.createObject(tabletMenu); - var exclusionGroups = {}; for (var i = 0; i < items.length; ++i) { var item = items[i]; @@ -78,28 +77,6 @@ Item { if (item.text !== "Users Online") { result.append({"name": item.text, "item": item}) } - - for(var j = 0; j < tabletMenu.rootMenu.exclusionGroupsByMenuItem.count; ++j) - { - var entry = tabletMenu.rootMenu.exclusionGroupsByMenuItem.get(j); - if(entry.menuItem == item.toString()) - { - var exclusionGroupId = entry.exclusionGroup; - console.debug('item exclusionGroupId: ', exclusionGroupId) - - if(!exclusionGroups[exclusionGroupId]) - { - exclusionGroups[exclusionGroupId] = exclusiveGroupMaker.createObject(newMenu); - console.debug('new exclusion group created: ', exclusionGroups[exclusionGroupId]) - } - - var exclusionGroup = exclusionGroups[exclusionGroupId]; - - item.exclusiveGroup = exclusionGroup - console.debug('item.exclusiveGroup: ', item.exclusiveGroup) - } - } - break; case MenuItemType.Separator: result.append({"name": "", "item": item}) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 585cf5e856..dcece932e5 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -7089,6 +7089,7 @@ DisplayPluginPointer Application::getActiveDisplayPlugin() const { return _displayPlugin; } +static const char* EXCLUSION_GROUP_KEY = "exclusionGroup"; static void addDisplayPluginToMenu(DisplayPluginPointer displayPlugin, bool active = false) { auto menu = Menu::getInstance(); @@ -7124,6 +7125,8 @@ static void addDisplayPluginToMenu(DisplayPluginPointer displayPlugin, bool acti action->setCheckable(true); action->setChecked(active); displayPluginGroup->addAction(action); + + action->setProperty(EXCLUSION_GROUP_KEY, QVariant::fromValue(displayPluginGroup)); Q_ASSERT(menu->menuItemExists(MenuOption::OutputMenu, name)); } diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 9df22ab08e..9ec5cc6034 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -56,7 +56,7 @@ Menu* Menu::getInstance() { return dynamic_cast