From d55d467d3f19e70492e8de3c0886591429744ca4 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Mon, 27 Apr 2015 11:35:57 -0700 Subject: [PATCH] Tweaking VR menu for PR --- interface/resources/qml/VrMenu.qml | 22 +++++++++++++++++-- interface/src/Application.cpp | 9 +++++--- interface/src/Menu.cpp | 2 +- libraries/ui/src/{HifiMenu.cpp => VrMenu.cpp} | 14 +++++++----- libraries/ui/src/{HifiMenu.h => VrMenu.h} | 10 ++++----- tests/ui/src/main.cpp | 2 +- 6 files changed, 42 insertions(+), 17 deletions(-) rename libraries/ui/src/{HifiMenu.cpp => VrMenu.cpp} (93%) rename libraries/ui/src/{HifiMenu.h => VrMenu.h} (83%) diff --git a/interface/resources/qml/VrMenu.qml b/interface/resources/qml/VrMenu.qml index 7de66de23c..01714e9ebe 100644 --- a/interface/resources/qml/VrMenu.qml +++ b/interface/resources/qml/VrMenu.qml @@ -94,6 +94,9 @@ Hifi.VrMenu { var newWidth = minWidth; for (var i = 0; i < children.length; ++i) { var item = children[i]; + if (!item.visible) { + continue + } newHeight += item.height } parent.height = newHeight + outerMargin * 2; @@ -152,8 +155,23 @@ Hifi.VrMenu { height: implicitHeight width: implicitWidth color: source.enabled ? hifi.colors.text : hifi.colors.disabledText - enabled: source.enabled - + enabled: source.enabled && source.visible + // FIXME uncommenting this line results in menus that have blank spots + // rather than having the correct size + // visible: source.visible + + onListViewChanged: { + if (listView) { + listView.minWidth = Math.max(listView.minWidth, implicitWidth + 64); + listView.recalculateSize(); + } + } + + onVisibleChanged: { + if (listView) { + listView.recalculateSize(); + } + } onImplicitWidthChanged: { if (listView) { diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 5fd3cc48ab..2550651a34 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -63,7 +63,7 @@ #include #include #include -#include +#include #include #include #include @@ -1327,13 +1327,16 @@ void Application::keyPressEvent(QKeyEvent* event) { } } + +//#define VR_MENU_ONLY_IN_HMD + void Application::keyReleaseEvent(QKeyEvent* event) { if (event->key() == Qt::Key_Alt && _altPressed && _window->isActiveWindow()) { -#ifndef DEBUG +#ifdef VR_MENU_ONLY_IN_HMD if (OculusManager::isConnected()) { #endif VrMenu::toggle(); -#ifndef DEBUG +#ifdef VR_MENU_ONLY_IN_HMD } #endif } diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 67fae46b33..42670c2979 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include "Application.h" #include "AccountManager.h" diff --git a/libraries/ui/src/HifiMenu.cpp b/libraries/ui/src/VrMenu.cpp similarity index 93% rename from libraries/ui/src/HifiMenu.cpp rename to libraries/ui/src/VrMenu.cpp index 854f0d6eb2..e0fa296857 100644 --- a/libraries/ui/src/HifiMenu.cpp +++ b/libraries/ui/src/VrMenu.cpp @@ -1,5 +1,5 @@ // -// HifiMenu.cpp +// VrMenu.cpp // // Created by Bradley Austin Davis on 2015/04/21 // Copyright 2015 High Fidelity, Inc. @@ -8,11 +8,15 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "HifiMenu.h" +#include "VrMenu.h" #include #include // Binds together a Qt Action or Menu with the QML Menu or MenuItem +// +// TODO On reflection, it may be pointless to use the UUID. Perhaps +// simply creating the bidirectional link pointing to both the widget +// and qml object and inject the pointer into both objects class MenuUserData : public QObjectUserData { static const int USER_DATA_ID; @@ -69,7 +73,7 @@ VrMenu::VrMenu(QQuickItem* parent) : QQuickItem(parent) { } // QML helper functions -QObject* addMenu(QObject* parent, const QString & text) { +QObject* addMenu(QObject* parent, const QString& text) { // FIXME add more checking here to ensure no name conflicts QVariant returnedValue; QMetaObject::invokeMethod(parent, "addMenu", Qt::DirectConnection, @@ -94,7 +98,7 @@ QObject* addItem(QObject* parent, const QString& text) { return result; } -const QObject* VrMenu::findMenuObject(const QString & menuOption) const { +const QObject* VrMenu::findMenuObject(const QString& menuOption) const { if (menuOption.isEmpty()) { return _rootMenu; } @@ -102,7 +106,7 @@ const QObject* VrMenu::findMenuObject(const QString & menuOption) const { return result; } -QObject* VrMenu::findMenuObject(const QString & menuOption) { +QObject* VrMenu::findMenuObject(const QString& menuOption) { if (menuOption.isEmpty()) { return _rootMenu; } diff --git a/libraries/ui/src/HifiMenu.h b/libraries/ui/src/VrMenu.h similarity index 83% rename from libraries/ui/src/HifiMenu.h rename to libraries/ui/src/VrMenu.h index 43af05a426..7fe0d33cc4 100644 --- a/libraries/ui/src/HifiMenu.h +++ b/libraries/ui/src/VrMenu.h @@ -1,5 +1,5 @@ // -// HifiMenu.h +// VrMenu.h // // Created by Bradley Austin Davis on 2015/04/21 // Copyright 2015 High Fidelity, Inc. @@ -9,8 +9,8 @@ // #pragma once -#ifndef hifi_HifiMenu_h -#define hifi_HifiMenu_h +#ifndef hifi_VrMenu_h +#define hifi_VrMenu_h #include #include @@ -20,7 +20,7 @@ #include #include "OffscreenUi.h" -// FIXME rename the compilation files to VrMenu.h and VrMenu.cpp after upstream pull requests are merged. +// FIXME break up the rendering code (VrMenu) and the code for mirroring a Widget based menu in QML class VrMenu : public QQuickItem { Q_OBJECT HIFI_QML_DECL_LAMBDA @@ -45,4 +45,4 @@ protected: friend class MenuUserData; }; -#endif // hifi_HifiMenu_h +#endif // hifi_VrMenu_h diff --git a/tests/ui/src/main.cpp b/tests/ui/src/main.cpp index 192bfd928b..ae8375717e 100644 --- a/tests/ui/src/main.cpp +++ b/tests/ui/src/main.cpp @@ -35,7 +35,7 @@ #include #include "MessageDialog.h" -#include "HifiMenu.h" +#include "VrMenu.h" class RateCounter { std::vector times;