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
52#include <QMimeData>52#include <QMimeData>
53#include <QMessageBox>53#include <QMessageBox>
54#include <QJsonDocument>54#include <QJsonDocument>
55#include <QQmlNetworkAccessManagerFactory>
56#include <QThreadStorage>
57 55
58#include <AddressManager.h>56#include <AddressManager.h>
59#include <AccountManager.h>57#include <AccountManager.h>
@@ -65,6 +63,7 @@ · 5 unmodified lines
65#include <GlowEffect.h>63#include <GlowEffect.h>
66#include <HFActionEvent.h>64#include <HFActionEvent.h>
67#include <HFBackEvent.h>65#include <HFBackEvent.h>
66#include <HifiMenu.h>
68#include <LogHandler.h>67#include <LogHandler.h>
69#include <MainWindow.h>68#include <MainWindow.h>
70#include <ModelEntityItem.h>69#include <ModelEntityItem.h>
@@ -135,7 +134,6 @@ · 64 unmodified lines
135#include "ui/DialogsManager.h"134#include "ui/DialogsManager.h"
136#include "ui/InfoView.h"135#include "ui/InfoView.h"
137#include "ui/LoginDialog.h"136#include "ui/LoginDialog.h"
138#include "ui/MarketplaceDialog.h"
139#include "ui/Snapshot.h"137#include "ui/Snapshot.h"
140#include "ui/StandAloneJSConsole.h"138#include "ui/StandAloneJSConsole.h"
141#include "ui/Stats.h"139#include "ui/Stats.h"
@@ -510,6 +508,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 368 unmodified lines
510 // enable mouse tracking; otherwise, we only get drag events508 // enable mouse tracking; otherwise, we only get drag events
511 _glWidget->setMouseTracking(true);509 _glWidget->setMouseTracking(true);
512 510
511 _fullscreenMenuWidget->setParent(_glWidget);
512 _menuBarHeight = Menu::getInstance()->height();
513 if (Menu::getInstance()->isOptionChecked(MenuOption::Fullscreen)) {513 if (Menu::getInstance()->isOptionChecked(MenuOption::Fullscreen)) {
514 setFullscreen(true); // Initialize menu bar show/hide514 setFullscreen(true); // Initialize menu bar show/hide
515 }515 }
@@ -730,6 +730,10 @@ void Application::initializeGL() { · 214 unmodified lines
730 qCDebug(interfaceapp, "Initialized Offscreen UI.");730 qCDebug(interfaceapp, "Initialized Offscreen UI.");
731 _glWidget->makeCurrent();731 _glWidget->makeCurrent();
732 732
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
733 init();737 init();
734 qCDebug(interfaceapp, "init() complete.");738 qCDebug(interfaceapp, "init() complete.");
735 739
@@ -764,9 +768,7 @@ void Application::initializeGL() { · 28 unmodified lines
764void Application::initializeUi() {768void Application::initializeUi() {
765 AddressBarDialog::registerType();769 AddressBarDialog::registerType();
766 LoginDialog::registerType();770 LoginDialog::registerType();
767 MarketplaceDialog::registerType();
768 MessageDialog::registerType();771 MessageDialog::registerType();
769 Menu::registerType();
770 772
771 auto offscreenUi = DependencyManager::get<OffscreenUi>();773 auto offscreenUi = DependencyManager::get<OffscreenUi>();
772 offscreenUi->create(_glWidget->context()->contextHandle());774 offscreenUi->create(_glWidget->context()->contextHandle());
@@ -902,7 +904,9 @@ void Application::runTests() { · 129 unmodified lines
902}904}
903 905
904void Application::audioMuteToggled() {906void 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());
906}910}
907 911
908void Application::aboutApp() {912void Application::aboutApp() {
@@ -1067,12 +1071,10 @@ bool Application::eventFilter(QObject* object, QEvent* event) { · 158 unmodified lines
1067 return false;1071 return false;
1068}1072}
1069 1073
1070static bool altPressed;1074static bool _altPressed{ false };
1071static bool ctrlPressed;
1072 1075
1073void Application::keyPressEvent(QKeyEvent* event) {1076void Application::keyPressEvent(QKeyEvent* event) {
1074 altPressed = event->key() == Qt::Key_Alt;1077 _altPressed = event->key() == Qt::Key_Alt;
1075 ctrlPressed = event->key() == Qt::Key_Control;
1076 _keysPressed.insert(event->key());1078 _keysPressed.insert(event->key());
1077 1079
1078 _controllerScriptingInterface.emitKeyPressEvent(event); // send events to any registered scripts1080 _controllerScriptingInterface.emitKeyPressEvent(event); // send events to any registered scripts
@@ -1162,9 +1164,7 @@ void Application::keyPressEvent(QKeyEvent* event) { · 83 unmodified lines
1162 break;1164 break;
1163 1165
1164 case Qt::Key_Backslash:1166 case Qt::Key_Backslash:
1165 MarketplaceDialog::show();1167 Menu::getInstance()->triggerOption(MenuOption::Chat);
1166
1167 //Menu::getInstance()->triggerOption(MenuOption::Chat);
1168 break;1168 break;
1169 1169
1170 case Qt::Key_Up:1170 case Qt::Key_Up:
@@ -1329,13 +1329,15 @@ void Application::keyPressEvent(QKeyEvent* event) { · 158 unmodified lines
1329}1329}
1330 1330
1331void Application::keyReleaseEvent(QKeyEvent* event) {1331void Application::keyReleaseEvent(QKeyEvent* event) {
1332 if (event->key() == Qt::Key_Alt && altPressed && _window->isActiveWindow()) {1332 if (event->key() == Qt::Key_Alt && _altPressed && _window->isActiveWindow()) {
1333 Menu::toggle();1333#ifndef DEBUG
1334 }1334 if (OculusManager::isConnected()) {
1335 if (event->key() == Qt::Key_Control && ctrlPressed && _window->isActiveWindow()) {1335#endif
1336 Menu::toggle();1336 VrMenu::toggle();
1337#ifndef DEBUG
1338 }
1339#endif
1337 }1340 }
1338 ctrlPressed = altPressed = false;
1339 1341
1340 _keysPressed.remove(event->key());1342 _keysPressed.remove(event->key());
1341 1343
@@ -1346,6 +1348,7 @@ void Application::keyReleaseEvent(QKeyEvent* event) { · 4 unmodified lines
1346 return;1348 return;
1347 }1349 }
1348 1350
1351
1349 switch (event->key()) {1352 switch (event->key()) {
1350 case Qt::Key_E:1353 case Qt::Key_E:
1351 case Qt::Key_PageUp:1354 case Qt::Key_PageUp:
@@ -1442,6 +1445,18 @@ void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { · 90 unmodified lines
1442 return;1445 return;
1443 }1446 }
1444 1447
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
1445 _entities.mouseMoveEvent(event, deviceID);1460 _entities.mouseMoveEvent(event, deviceID);
1446 1461
1447 _controllerScriptingInterface.emitMouseMoveEvent(event, deviceID); // send events to any registered scripts1462 _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
1449 if (_controllerScriptingInterface.isMouseCaptured()) {1464 if (_controllerScriptingInterface.isMouseCaptured()) {
1450 return;1465 return;
1451 }1466 }
1467
1452}1468}
1453 1469
1454void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) {1470void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) {
@@ -1735,6 +1751,34 @@ void Application::setFullscreen(bool fullscreen) { · 280 unmodified lines
1735 Menu::getInstance()->getActionForOption(MenuOption::Fullscreen)->setChecked(fullscreen);1751 Menu::getInstance()->getActionForOption(MenuOption::Fullscreen)->setChecked(fullscreen);
1736 }1752 }
1737 1753
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
1738 // Work around Qt bug that prevents floating menus being shown when in fullscreen mode.1782 // Work around Qt bug that prevents floating menus being shown when in fullscreen mode.
1739 // https://bugreports.qt.io/browse/QTBUG-418831783 // https://bugreports.qt.io/browse/QTBUG-41883
1740 // Known issue: Top-level menu items don't highlight when cursor hovers. This is probably a side-effect of the work-around.1784 // 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
1987 2031
1988 OculusManager::connect();2032 OculusManager::connect();
1989 if (OculusManager::isConnected()) {2033 if (OculusManager::isConnected()) {
1990 // perform as a post-event so that the code is run after init is complete2034 QMetaObject::invokeMethod(Menu::getInstance()->getActionForOption(MenuOption::Fullscreen),
1991 qApp->postLambdaEvent([] {2035 "trigger",
1992 Menu::getInstance()->triggerOption(MenuOption::Fullscreen);2036 Qt::QueuedConnection);
1993 });
1994 }2037 }
1995 2038
1996 TV3DManager::connect();2039 TV3DManager::connect();
1997 if (TV3DManager::isConnected()) {2040 if (TV3DManager::isConnected()) {
1998 // perform as a post-event so that the code is run after init is complete2041 QMetaObject::invokeMethod(Menu::getInstance()->getActionForOption(MenuOption::Fullscreen),
1999 qApp->postLambdaEvent([] {2042 "trigger",
2000 Menu::getInstance()->triggerOption(MenuOption::Fullscreen);2043 Qt::QueuedConnection);
2001 });
2002 }2044 }
2003 2045
2004 _timerStart.start();2046 _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