mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 17:14:59 +02:00
Merge pull request #9035 from druiz17/vrmenu
Fixed unable to remove menus from VrMenu context
This commit is contained in:
commit
4ae6cbad7b
2 changed files with 28 additions and 14 deletions
|
@ -12,6 +12,7 @@
|
|||
|
||||
#include <QtQml>
|
||||
#include <QMenuBar>
|
||||
#include <QDebug>
|
||||
|
||||
#include "OffscreenUi.h"
|
||||
|
||||
|
@ -58,6 +59,18 @@ public:
|
|||
_qml->setProperty("visible", _action->isVisible());
|
||||
}
|
||||
|
||||
void clear() {
|
||||
_qml->setProperty("checkable", 0);
|
||||
_qml->setProperty("enabled", 0);
|
||||
_qml->setProperty("text", 0);
|
||||
_qml->setProperty("shortcut", 0);
|
||||
_qml->setProperty("checked", 0);
|
||||
_qml->setProperty("visible", 0);
|
||||
|
||||
_action->setUserData(USER_DATA_ID, nullptr);
|
||||
_qml->setUserData(USER_DATA_ID, nullptr);
|
||||
}
|
||||
|
||||
|
||||
const QUuid uuid{ QUuid::createUuid() };
|
||||
|
||||
|
@ -217,6 +230,7 @@ void VrMenu::insertAction(QAction* before, QAction* action) {
|
|||
}
|
||||
|
||||
class QQuickMenuBase;
|
||||
class QQuickMenu1;
|
||||
|
||||
void VrMenu::removeAction(QAction* action) {
|
||||
if (!action) {
|
||||
|
@ -228,10 +242,7 @@ void VrMenu::removeAction(QAction* action) {
|
|||
qWarning("Attempted to remove menu action with no found QML object");
|
||||
return;
|
||||
}
|
||||
|
||||
QObject* item = findMenuObject(userData->uuid.toString());
|
||||
QObject* menu = item->parent();
|
||||
// Proxy QuickItem requests through the QML layer
|
||||
QQuickMenuBase* qmlItem = reinterpret_cast<QQuickMenuBase*>(item);
|
||||
QMetaObject::invokeMethod(menu, "removeItem", Qt::DirectConnection, Q_ARG(QQuickMenuBase*, qmlItem));
|
||||
|
||||
userData->clear();
|
||||
delete userData;
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ void Menu::scanMenu(QMenu& menu, settingsAction modifySetting, Settings& setting
|
|||
groups.pop_back();
|
||||
}
|
||||
|
||||
void Menu::addDisabledActionAndSeparator(MenuWrapper* destinationMenu, const QString& actionName,
|
||||
void Menu::addDisabledActionAndSeparator(MenuWrapper* destinationMenu, const QString& actionName,
|
||||
int menuItemLocation, const QString& grouping) {
|
||||
QAction* actionBefore = NULL;
|
||||
QAction* separator;
|
||||
|
@ -123,7 +123,7 @@ QAction* Menu::addActionToQMenuAndActionHash(MenuWrapper* destinationMenu,
|
|||
const QObject* receiver,
|
||||
const char* member,
|
||||
QAction::MenuRole role,
|
||||
int menuItemLocation,
|
||||
int menuItemLocation,
|
||||
const QString& grouping) {
|
||||
QAction* action = NULL;
|
||||
QAction* actionBefore = NULL;
|
||||
|
@ -165,7 +165,7 @@ QAction* Menu::addActionToQMenuAndActionHash(MenuWrapper* destinationMenu,
|
|||
const QString& actionName,
|
||||
const QKeySequence& shortcut,
|
||||
QAction::MenuRole role,
|
||||
int menuItemLocation,
|
||||
int menuItemLocation,
|
||||
const QString& grouping) {
|
||||
QAction* actionBefore = NULL;
|
||||
|
||||
|
@ -207,7 +207,7 @@ QAction* Menu::addCheckableActionToQMenuAndActionHash(MenuWrapper* destinationMe
|
|||
const bool checked,
|
||||
const QObject* receiver,
|
||||
const char* member,
|
||||
int menuItemLocation,
|
||||
int menuItemLocation,
|
||||
const QString& grouping) {
|
||||
|
||||
QAction* action = addActionToQMenuAndActionHash(destinationMenu, actionName, shortcut, receiver, member,
|
||||
|
@ -408,6 +408,10 @@ void Menu::removeMenu(const QString& menuName) {
|
|||
parent->removeAction(action);
|
||||
} else {
|
||||
QMenuBar::removeAction(action);
|
||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||
offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) {
|
||||
vrMenu->removeAction(action);
|
||||
});
|
||||
}
|
||||
|
||||
QMenuBar::repaint();
|
||||
|
@ -496,15 +500,15 @@ void Menu::setGroupingIsVisible(const QString& grouping, bool isVisible) {
|
|||
|
||||
void Menu::addActionGroup(const QString& groupName, const QStringList& actionList, const QString& selected, QObject* receiver, const char* slot) {
|
||||
auto menu = addMenu(groupName);
|
||||
|
||||
|
||||
QActionGroup* actionGroup = new QActionGroup(menu);
|
||||
actionGroup->setExclusive(true);
|
||||
|
||||
|
||||
for (auto action : actionList) {
|
||||
auto item = addCheckableActionToQMenuAndActionHash(menu, action, 0, action == selected, receiver, slot);
|
||||
actionGroup->addAction(item);
|
||||
}
|
||||
|
||||
|
||||
QMenuBar::repaint();
|
||||
}
|
||||
|
||||
|
@ -582,4 +586,3 @@ void MenuWrapper::insertAction(QAction* before, QAction* action) {
|
|||
vrMenu->insertAction(before, action);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue