mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-29 22:22:54 +02:00
6788: You can deselect your current view mode
This commit is contained in:
parent
bb49bcdcfd
commit
cbbe03cee7
4 changed files with 120 additions and 15 deletions
|
@ -50,7 +50,24 @@ FocusScope {
|
||||||
property bool desktopRoot: true
|
property bool desktopRoot: true
|
||||||
|
|
||||||
// The VR version of the primary menu
|
// The VR version of the primary menu
|
||||||
property var rootMenu: Menu { objectName: "rootMenu" }
|
property var rootMenu: Menu {
|
||||||
|
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 {}
|
||||||
|
|
||||||
|
function addExclusionGroup(menuItem, exclusionGroup)
|
||||||
|
{
|
||||||
|
console.debug('entering Desktop::addExclusionGroup: menuItem = ', menuItem, 'exclusionGroup = ', exclusionGroup);
|
||||||
|
exclusionGroupsByMenuItem.append(
|
||||||
|
{
|
||||||
|
'menuItem' : menuItem.toString(),
|
||||||
|
'exclusionGroup' : exclusionGroup.toString()
|
||||||
|
}
|
||||||
|
);
|
||||||
|
console.debug('Desktop::addExclusionGroup: ', exclusionGroup, 'rootMenu: ', this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME: Alpha gradients display as fuschia under QtQuick 2.5 on OSX/AMD
|
// FIXME: Alpha gradients display as fuschia under QtQuick 2.5 on OSX/AMD
|
||||||
// because shaders are 4.2, and do not include #version declarations.
|
// because shaders are 4.2, and do not include #version declarations.
|
||||||
|
|
|
@ -64,8 +64,10 @@ Item {
|
||||||
d.pop();
|
d.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
function toModel(items) {
|
function toModel(items, newMenu) {
|
||||||
var result = modelMaker.createObject(tabletMenu);
|
var result = modelMaker.createObject(tabletMenu);
|
||||||
|
var exclusionGroups = {};
|
||||||
|
|
||||||
for (var i = 0; i < items.length; ++i) {
|
for (var i = 0; i < items.length; ++i) {
|
||||||
var item = items[i];
|
var item = items[i];
|
||||||
if (!item.visible) continue;
|
if (!item.visible) continue;
|
||||||
|
@ -77,6 +79,28 @@ Item {
|
||||||
if (item.text !== "Users Online") {
|
if (item.text !== "Users Online") {
|
||||||
result.append({"name": item.text, "item": item})
|
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;
|
break;
|
||||||
case MenuItemType.Separator:
|
case MenuItemType.Separator:
|
||||||
result.append({"name": "", "item": item})
|
result.append({"name": "", "item": item})
|
||||||
|
@ -133,10 +157,24 @@ Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
property Component exclusiveGroupMaker: Component {
|
||||||
|
ExclusiveGroup {
|
||||||
|
Component.onDestruction: {
|
||||||
|
console.debug('ExclusionGroup destroyed: ', this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function buildMenu(items) {
|
function buildMenu(items) {
|
||||||
var model = toModel(items);
|
|
||||||
// Menus must be childed to desktop for Z-ordering
|
// Menus must be childed to desktop for Z-ordering
|
||||||
var newMenu = menuViewMaker.createObject(tabletMenu, { model: model, isSubMenu: topMenu !== null });
|
var newMenu = menuViewMaker.createObject(tabletMenu);
|
||||||
|
console.debug('newMenu created: ', newMenu)
|
||||||
|
|
||||||
|
var model = toModel(items, newMenu);
|
||||||
|
|
||||||
|
newMenu.model = model;
|
||||||
|
newMenu.isSubMenu = topMenu !== null;
|
||||||
|
|
||||||
pushMenu(newMenu);
|
pushMenu(newMenu);
|
||||||
return newMenu;
|
return newMenu;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,8 @@ Menu* Menu::getInstance() {
|
||||||
return dynamic_cast<Menu*>(qApp->getWindow()->menuBar());
|
return dynamic_cast<Menu*>(qApp->getWindow()->menuBar());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* exclusionGroupKey = "exclusionGroup";
|
||||||
|
|
||||||
Menu::Menu() {
|
Menu::Menu() {
|
||||||
auto dialogsManager = DependencyManager::get<DialogsManager>();
|
auto dialogsManager = DependencyManager::get<DialogsManager>();
|
||||||
auto accountManager = DependencyManager::get<AccountManager>();
|
auto accountManager = DependencyManager::get<AccountManager>();
|
||||||
|
@ -222,32 +224,42 @@ Menu::Menu() {
|
||||||
cameraModeGroup->setExclusive(true);
|
cameraModeGroup->setExclusive(true);
|
||||||
|
|
||||||
// View > First Person
|
// View > First Person
|
||||||
cameraModeGroup->addAction(addCheckableActionToQMenuAndActionHash(
|
auto firstPersonAction = cameraModeGroup->addAction(addCheckableActionToQMenuAndActionHash(
|
||||||
viewMenu, MenuOption::FirstPerson, Qt::CTRL | Qt::Key_F,
|
viewMenu, MenuOption::FirstPerson, Qt::CTRL | Qt::Key_F,
|
||||||
true, qApp, SLOT(cameraMenuChanged())));
|
true, qApp, SLOT(cameraMenuChanged())));
|
||||||
|
|
||||||
|
firstPersonAction->setProperty(exclusionGroupKey, QVariant::fromValue(cameraModeGroup));
|
||||||
|
|
||||||
// View > Third Person
|
// View > Third Person
|
||||||
cameraModeGroup->addAction(addCheckableActionToQMenuAndActionHash(
|
auto thirdPersonAction = cameraModeGroup->addAction(addCheckableActionToQMenuAndActionHash(
|
||||||
viewMenu, MenuOption::ThirdPerson, Qt::CTRL | Qt::Key_G,
|
viewMenu, MenuOption::ThirdPerson, Qt::CTRL | Qt::Key_G,
|
||||||
false, qApp, SLOT(cameraMenuChanged())));
|
false, qApp, SLOT(cameraMenuChanged())));
|
||||||
|
|
||||||
|
thirdPersonAction->setProperty(exclusionGroupKey, QVariant::fromValue(cameraModeGroup));
|
||||||
|
|
||||||
// View > Mirror
|
// View > Mirror
|
||||||
cameraModeGroup->addAction(addCheckableActionToQMenuAndActionHash(
|
auto viewMirrorAction = cameraModeGroup->addAction(addCheckableActionToQMenuAndActionHash(
|
||||||
viewMenu, MenuOption::FullscreenMirror, Qt::CTRL | Qt::Key_H,
|
viewMenu, MenuOption::FullscreenMirror, Qt::CTRL | Qt::Key_H,
|
||||||
false, qApp, SLOT(cameraMenuChanged())));
|
false, qApp, SLOT(cameraMenuChanged())));
|
||||||
|
|
||||||
|
viewMirrorAction->setProperty(exclusionGroupKey, QVariant::fromValue(cameraModeGroup));
|
||||||
|
|
||||||
// View > Independent [advanced]
|
// View > Independent [advanced]
|
||||||
cameraModeGroup->addAction(addCheckableActionToQMenuAndActionHash(viewMenu,
|
auto viewIndependentAction = cameraModeGroup->addAction(addCheckableActionToQMenuAndActionHash(viewMenu,
|
||||||
MenuOption::IndependentMode, 0,
|
MenuOption::IndependentMode, 0,
|
||||||
false, qApp, SLOT(cameraMenuChanged()),
|
false, qApp, SLOT(cameraMenuChanged()),
|
||||||
UNSPECIFIED_POSITION, "Advanced"));
|
UNSPECIFIED_POSITION, "Advanced"));
|
||||||
|
|
||||||
|
viewIndependentAction->setProperty(exclusionGroupKey, QVariant::fromValue(cameraModeGroup));
|
||||||
|
|
||||||
// View > Entity Camera [advanced]
|
// View > Entity Camera [advanced]
|
||||||
cameraModeGroup->addAction(addCheckableActionToQMenuAndActionHash(viewMenu,
|
auto viewEntityCameraAction = cameraModeGroup->addAction(addCheckableActionToQMenuAndActionHash(viewMenu,
|
||||||
MenuOption::CameraEntityMode, 0,
|
MenuOption::CameraEntityMode, 0,
|
||||||
false, qApp, SLOT(cameraMenuChanged()),
|
false, qApp, SLOT(cameraMenuChanged()),
|
||||||
UNSPECIFIED_POSITION, "Advanced"));
|
UNSPECIFIED_POSITION, "Advanced"));
|
||||||
|
|
||||||
|
viewEntityCameraAction->setProperty(exclusionGroupKey, QVariant::fromValue(cameraModeGroup));
|
||||||
|
|
||||||
viewMenu->addSeparator();
|
viewMenu->addSeparator();
|
||||||
|
|
||||||
// View > Center Player In View
|
// View > Center Player In View
|
||||||
|
|
|
@ -26,12 +26,14 @@ static unsigned int USER_DATA_ID = 0;
|
||||||
// and qml object and inject the pointer into both objects
|
// and qml object and inject the pointer into both objects
|
||||||
class MenuUserData : public QObjectUserData {
|
class MenuUserData : public QObjectUserData {
|
||||||
public:
|
public:
|
||||||
MenuUserData(QAction* action, QObject* qmlObject) {
|
MenuUserData(QAction* action, QObject* qmlObject, QObject* qmlParent) {
|
||||||
if (!USER_DATA_ID) {
|
if (!USER_DATA_ID) {
|
||||||
USER_DATA_ID = DependencyManager::get<OffscreenUi>()->getMenuUserDataId();
|
USER_DATA_ID = DependencyManager::get<OffscreenUi>()->getMenuUserDataId();
|
||||||
}
|
}
|
||||||
_action = action;
|
_action = action;
|
||||||
_qml = qmlObject;
|
_qml = qmlObject;
|
||||||
|
_qmlParent = qmlParent;
|
||||||
|
|
||||||
action->setUserData(USER_DATA_ID, this);
|
action->setUserData(USER_DATA_ID, this);
|
||||||
qmlObject->setUserData(USER_DATA_ID, this);
|
qmlObject->setUserData(USER_DATA_ID, this);
|
||||||
qmlObject->setObjectName(uuid.toString());
|
qmlObject->setObjectName(uuid.toString());
|
||||||
|
@ -43,6 +45,41 @@ public:
|
||||||
_shutdownConnection = QObject::connect(qApp, &QCoreApplication::aboutToQuit, [=] {
|
_shutdownConnection = QObject::connect(qApp, &QCoreApplication::aboutToQuit, [=] {
|
||||||
QObject::disconnect(_changedConnection);
|
QObject::disconnect(_changedConnection);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
class ExclusionGroupSetter : public QObject {
|
||||||
|
public:
|
||||||
|
ExclusionGroupSetter(QObject* from, QObject* to, QObject* qmlParent) : QObject(from), _from(from), _to(to), _qmlParent(qmlParent) {
|
||||||
|
_from->installEventFilter(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
~ExclusionGroupSetter() {
|
||||||
|
_from->removeEventFilter(this);
|
||||||
|
}
|
||||||
|
protected:
|
||||||
|
bool eventFilter(QObject* o, QEvent* e) {
|
||||||
|
if (e->type() == QEvent::DynamicPropertyChange) {
|
||||||
|
QDynamicPropertyChangeEvent* dpc = static_cast<QDynamicPropertyChangeEvent*>(e);
|
||||||
|
if (dpc->propertyName() == "exclusionGroup")
|
||||||
|
{
|
||||||
|
// unfortunately Qt doesn't support passing dynamic properties between C++ / QML, so we have to use this ugly helper function
|
||||||
|
QMetaObject::invokeMethod(_qmlParent,
|
||||||
|
"addExclusionGroup",
|
||||||
|
Qt::DirectConnection,
|
||||||
|
Q_ARG(QVariant, QVariant::fromValue(_to)),
|
||||||
|
Q_ARG(QVariant, _from->property(dpc->propertyName())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return QObject::eventFilter(o, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QObject* _from;
|
||||||
|
QObject* _to;
|
||||||
|
QObject* _qmlParent;
|
||||||
|
};
|
||||||
|
|
||||||
|
new ExclusionGroupSetter(action, qmlObject, qmlParent);
|
||||||
}
|
}
|
||||||
|
|
||||||
~MenuUserData() {
|
~MenuUserData() {
|
||||||
|
@ -110,6 +147,7 @@ private:
|
||||||
QMetaObject::Connection _changedConnection;
|
QMetaObject::Connection _changedConnection;
|
||||||
QAction* _action { nullptr };
|
QAction* _action { nullptr };
|
||||||
QObject* _qml { nullptr };
|
QObject* _qml { nullptr };
|
||||||
|
QObject* _qmlParent{ nullptr };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -157,16 +195,16 @@ void VrMenu::addMenu(QMenu* menu) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bind the QML and Widget together
|
// Bind the QML and Widget together
|
||||||
new MenuUserData(menu->menuAction(), result);
|
new MenuUserData(menu->menuAction(), result, qmlParent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void bindActionToQmlAction(QObject* qmlAction, QAction* action) {
|
void bindActionToQmlAction(QObject* qmlAction, QAction* action, QObject* qmlParent) {
|
||||||
auto text = action->text();
|
auto text = action->text();
|
||||||
if (text == "Login") {
|
if (text == "Login") {
|
||||||
qDebug(uiLogging) << "Login action " << action;
|
qDebug(uiLogging) << "Login action " << action;
|
||||||
}
|
}
|
||||||
|
|
||||||
new MenuUserData(action, qmlAction);
|
new MenuUserData(action, qmlAction, qmlParent);
|
||||||
QObject::connect(action, &QAction::toggled, [=](bool checked) {
|
QObject::connect(action, &QAction::toggled, [=](bool checked) {
|
||||||
qmlAction->setProperty("checked", checked);
|
qmlAction->setProperty("checked", checked);
|
||||||
});
|
});
|
||||||
|
@ -195,7 +233,7 @@ void VrMenu::addAction(QMenu* menu, QAction* action) {
|
||||||
QObject* result = reinterpret_cast<QObject*>(returnedValue); // returnedValue.value<QObject*>();
|
QObject* result = reinterpret_cast<QObject*>(returnedValue); // returnedValue.value<QObject*>();
|
||||||
Q_ASSERT(result);
|
Q_ASSERT(result);
|
||||||
// Bind the QML and Widget together
|
// Bind the QML and Widget together
|
||||||
bindActionToQmlAction(result, action);
|
bindActionToQmlAction(result, action, _rootMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VrMenu::addSeparator(QMenu* menu) {
|
void VrMenu::addSeparator(QMenu* menu) {
|
||||||
|
@ -231,7 +269,7 @@ void VrMenu::insertAction(QAction* before, QAction* action) {
|
||||||
Q_ASSERT(invokeResult);
|
Q_ASSERT(invokeResult);
|
||||||
QObject* result = reinterpret_cast<QObject*>(returnedValue); // returnedValue.value<QObject*>();
|
QObject* result = reinterpret_cast<QObject*>(returnedValue); // returnedValue.value<QObject*>();
|
||||||
Q_ASSERT(result);
|
Q_ASSERT(result);
|
||||||
bindActionToQmlAction(result, action);
|
bindActionToQmlAction(result, action, _rootMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
class QQuickMenuBase;
|
class QQuickMenuBase;
|
||||||
|
|
Loading…
Reference in a new issue