History

Switching to a wrapper mechanism for VR menus

Brad Davis committed 11 years ago

Commit a96f69a1 parent ee3058830 files · +1335 −1045Browse files

Showing the changes to interface/src/Application.cpp (1 of 30 files). Show all

Unified · Split

interface/src/Application.cpp+69−27
@@ -52,8 +52,6 @@ · 51 unmodified lines
5252 #include <QMimeData>
5353 #include <QMessageBox>
5454 #include <QJsonDocument>
55−#include <QQmlNetworkAccessManagerFactory>
56−#include <QThreadStorage>
5755
5856 #include <AddressManager.h>
5957 #include <AccountManager.h>
@@ -65,6 +63,7 @@ · 5 unmodified lines
6563 #include <GlowEffect.h>
6664 #include <HFActionEvent.h>
6765 #include <HFBackEvent.h>
66+#include <HifiMenu.h>
6867 #include <LogHandler.h>
6968 #include <MainWindow.h>
7069 #include <ModelEntityItem.h>
@@ -135,7 +134,6 @@ · 64 unmodified lines
135134 #include "ui/DialogsManager.h"
136135 #include "ui/InfoView.h"
137136 #include "ui/LoginDialog.h"
138−#include "ui/MarketplaceDialog.h"
139137 #include "ui/Snapshot.h"
140138 #include "ui/StandAloneJSConsole.h"
141139 #include "ui/Stats.h"
@@ -510,6 +508,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 368 unmodified lines
510508 // enable mouse tracking; otherwise, we only get drag events
511509 _glWidget->setMouseTracking(true);
512510
511+ _fullscreenMenuWidget->setParent(_glWidget);
512+ _menuBarHeight = Menu::getInstance()->height();
513513 if (Menu::getInstance()->isOptionChecked(MenuOption::Fullscreen)) {
514514 setFullscreen(true); // Initialize menu bar show/hide
515515 }
@@ -730,6 +730,10 @@ void Application::initializeGL() { · 214 unmodified lines
730730 qCDebug(interfaceapp, "Initialized Offscreen UI.");
731731 _glWidget->makeCurrent();
732732
733+ // call Menu getInstance static method to set up the menu
734+ // Needs to happen AFTER the QML UI initialization
735+ _window->setMenuBar(Menu::getInstance());
736+
733737 init();
734738 qCDebug(interfaceapp, "init() complete.");
735739
@@ -764,9 +768,7 @@ void Application::initializeGL() { · 28 unmodified lines
764768 void Application::initializeUi() {
765769 AddressBarDialog::registerType();
766770 LoginDialog::registerType();
767− MarketplaceDialog::registerType();
768771 MessageDialog::registerType();
769− Menu::registerType();
770772
771773 auto offscreenUi = DependencyManager::get<OffscreenUi>();
772774 offscreenUi->create(_glWidget->context()->contextHandle());
@@ -902,7 +904,9 @@ void Application::runTests() { · 129 unmodified lines
902904 }
903905
904906 void Application::audioMuteToggled() {
905− Menu::getInstance()->setIsOptionChecked(MenuOption::MuteAudio, DependencyManager::get<AudioClient>()->isMuted());
907+ QAction* muteAction = Menu::getInstance()->getActionForOption(MenuOption::MuteAudio);
908+ Q_CHECK_PTR(muteAction);
909+ muteAction->setChecked(DependencyManager::get<AudioClient>()->isMuted());
906910 }
907911
908912 void Application::aboutApp() {
@@ -1067,12 +1071,10 @@ bool Application::eventFilter(QObject* object, QEvent* event) { · 158 unmodified lines
10671071 return false;
10681072 }
10691073
1070−static bool altPressed;
1071−static bool ctrlPressed;
1074+static bool _altPressed{ false };
10721075
10731076 void Application::keyPressEvent(QKeyEvent* event) {
1074− altPressed = event->key() == Qt::Key_Alt;
1075− ctrlPressed = event->key() == Qt::Key_Control;
1077+ _altPressed = event->key() == Qt::Key_Alt;
10761078 _keysPressed.insert(event->key());
10771079
10781080 _controllerScriptingInterface.emitKeyPressEvent(event); // send events to any registered scripts
@@ -1162,9 +1164,7 @@ void Application::keyPressEvent(QKeyEvent* event) { · 83 unmodified lines
11621164 break;
11631165
11641166 case Qt::Key_Backslash:
1165− MarketplaceDialog::show();
1166−
1167− //Menu::getInstance()->triggerOption(MenuOption::Chat);
1167+ Menu::getInstance()->triggerOption(MenuOption::Chat);
11681168 break;
11691169
11701170 case Qt::Key_Up:
@@ -1329,13 +1329,15 @@ void Application::keyPressEvent(QKeyEvent* event) { · 158 unmodified lines
13291329 }
13301330
13311331 void Application::keyReleaseEvent(QKeyEvent* event) {
1332− if (event->key() == Qt::Key_Alt && altPressed && _window->isActiveWindow()) {
1333− Menu::toggle();
1334− }
1335− if (event->key() == Qt::Key_Control && ctrlPressed && _window->isActiveWindow()) {
1336− Menu::toggle();
1332+ if (event->key() == Qt::Key_Alt && _altPressed && _window->isActiveWindow()) {
1333+#ifndef DEBUG
1334+ if (OculusManager::isConnected()) {
1335+#endif
1336+ VrMenu::toggle();
1337+#ifndef DEBUG
1338+ }
1339+#endif
13371340 }
1338− ctrlPressed = altPressed = false;
13391341
13401342 _keysPressed.remove(event->key());
13411343
@@ -1346,6 +1348,7 @@ void Application::keyReleaseEvent(QKeyEvent* event) { · 4 unmodified lines
13461348 return;
13471349 }
13481350
1351+
13491352 switch (event->key()) {
13501353 case Qt::Key_E:
13511354 case Qt::Key_PageUp:
@@ -1442,6 +1445,18 @@ void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { · 90 unmodified lines
14421445 return;
14431446 }
14441447
1448+ if (Menu::getInstance()->isOptionChecked(MenuOption::Fullscreen)
1449+ && !Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode)) {
1450+ // Show/hide menu bar in fullscreen
1451+ if (event->globalY() > _menuBarHeight) {
1452+ _fullscreenMenuWidget->setFixedHeight(0);
1453+ Menu::getInstance()->setFixedHeight(0);
1454+ } else {
1455+ _fullscreenMenuWidget->setFixedHeight(_menuBarHeight);
1456+ Menu::getInstance()->setFixedHeight(_menuBarHeight);
1457+ }
1458+ }
1459+
14451460 _entities.mouseMoveEvent(event, deviceID);
14461461
14471462 _controllerScriptingInterface.emitMouseMoveEvent(event, deviceID); // send events to any registered scripts
@@ -1449,6 +1464,7 @@ void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { · 1 unmodified line
14491464 if (_controllerScriptingInterface.isMouseCaptured()) {
14501465 return;
14511466 }
1467+
14521468 }
14531469
14541470 void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) {
@@ -1735,6 +1751,34 @@ void Application::setFullscreen(bool fullscreen) { · 280 unmodified lines
17351751 Menu::getInstance()->getActionForOption(MenuOption::Fullscreen)->setChecked(fullscreen);
17361752 }
17371753
1754+// The following code block is useful on platforms that can have a visible
1755+// app menu in a fullscreen window. However the OSX mechanism hides the
1756+// application menu for fullscreen apps, so the check is not required.
1757+#ifndef Q_OS_MAC
1758+ if (Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode)) {
1759+ if (fullscreen) {
1760+ // Menu hide() disables menu commands, and show() after hide() doesn't work with Rift VR display.
1761+ // So set height instead.
1762+ _window->menuBar()->setMaximumHeight(0);
1763+ } else {
1764+ _window->menuBar()->setMaximumHeight(QWIDGETSIZE_MAX);
1765+ }
1766+ } else {
1767+ if (fullscreen) {
1768+ // Move menu to a QWidget floating above _glWidget so that show/hide doesn't adjust viewport.
1769+ _menuBarHeight = Menu::getInstance()->height();
1770+ Menu::getInstance()->setParent(_fullscreenMenuWidget);
1771+ Menu::getInstance()->setFixedWidth(_window->windowHandle()->screen()->size().width());
1772+ _fullscreenMenuWidget->show();
1773+ } else {
1774+ // Restore menu to being part of MainWindow.
1775+ _fullscreenMenuWidget->hide();
1776+ _window->setMenuBar(Menu::getInstance());
1777+ _window->menuBar()->setMaximumHeight(QWIDGETSIZE_MAX);
1778+ }
1779+ }
1780+#endif
1781+
17381782 // Work around Qt bug that prevents floating menus being shown when in fullscreen mode.
17391783 // https://bugreports.qt.io/browse/QTBUG-41883
17401784 // Known issue: Top-level menu items don't highlight when cursor hovers. This is probably a side-effect of the work-around.
@@ -1987,18 +2031,16 @@ void Application::init() { · 246 unmodified lines
19872031
19882032 OculusManager::connect();
19892033 if (OculusManager::isConnected()) {
1990− // perform as a post-event so that the code is run after init is complete
1991− qApp->postLambdaEvent([] {
1992− Menu::getInstance()->triggerOption(MenuOption::Fullscreen);
1993− });
2034+ QMetaObject::invokeMethod(Menu::getInstance()->getActionForOption(MenuOption::Fullscreen),
2035+ "trigger",
2036+ Qt::QueuedConnection);
19942037 }
19952038
19962039 TV3DManager::connect();
19972040 if (TV3DManager::isConnected()) {
1998− // perform as a post-event so that the code is run after init is complete
1999− qApp->postLambdaEvent([] {
2000− Menu::getInstance()->triggerOption(MenuOption::Fullscreen);
2001− });
2041+ QMetaObject::invokeMethod(Menu::getInstance()->getActionForOption(MenuOption::Fullscreen),
2042+ "trigger",
2043+ Qt::QueuedConnection);
20022044 }
20032045
20042046 _timerStart.start();

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t