Showing the changes to interface/src/Application.cpp (1 of 30 files). Show all
Unified · Split
| @@ -52,8 +52,6 @@ · 51 unmodified lines | ||
| 52 | 52 | #include <QMimeData> |
| 53 | 53 | #include <QMessageBox> |
| 54 | 54 | #include <QJsonDocument> |
| 55 | −#include <QQmlNetworkAccessManagerFactory> | |
| 56 | −#include <QThreadStorage> | |
| 57 | 55 | |
| 58 | 56 | #include <AddressManager.h> |
| 59 | 57 | #include <AccountManager.h> |
| @@ -65,6 +63,7 @@ · 5 unmodified lines | ||
| 65 | 63 | #include <GlowEffect.h> |
| 66 | 64 | #include <HFActionEvent.h> |
| 67 | 65 | #include <HFBackEvent.h> |
| 66 | +#include <HifiMenu.h> | |
| 68 | 67 | #include <LogHandler.h> |
| 69 | 68 | #include <MainWindow.h> |
| 70 | 69 | #include <ModelEntityItem.h> |
| @@ -135,7 +134,6 @@ · 64 unmodified lines | ||
| 135 | 134 | #include "ui/DialogsManager.h" |
| 136 | 135 | #include "ui/InfoView.h" |
| 137 | 136 | #include "ui/LoginDialog.h" |
| 138 | −#include "ui/MarketplaceDialog.h" | |
| 139 | 137 | #include "ui/Snapshot.h" |
| 140 | 138 | #include "ui/StandAloneJSConsole.h" |
| 141 | 139 | #include "ui/Stats.h" |
| @@ -510,6 +508,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 368 unmodified lines | ||
| 510 | 508 | // enable mouse tracking; otherwise, we only get drag events |
| 511 | 509 | _glWidget->setMouseTracking(true); |
| 512 | 510 | |
| 511 | + _fullscreenMenuWidget->setParent(_glWidget); | |
| 512 | + _menuBarHeight = Menu::getInstance()->height(); | |
| 513 | 513 | if (Menu::getInstance()->isOptionChecked(MenuOption::Fullscreen)) { |
| 514 | 514 | setFullscreen(true); // Initialize menu bar show/hide |
| 515 | 515 | } |
| @@ -730,6 +730,10 @@ void Application::initializeGL() { · 214 unmodified lines | ||
| 730 | 730 | qCDebug(interfaceapp, "Initialized Offscreen UI."); |
| 731 | 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 | 737 | init(); |
| 734 | 738 | qCDebug(interfaceapp, "init() complete."); |
| 735 | 739 | |
| @@ -764,9 +768,7 @@ void Application::initializeGL() { · 28 unmodified lines | ||
| 764 | 768 | void Application::initializeUi() { |
| 765 | 769 | AddressBarDialog::registerType(); |
| 766 | 770 | LoginDialog::registerType(); |
| 767 | − MarketplaceDialog::registerType(); | |
| 768 | 771 | MessageDialog::registerType(); |
| 769 | − Menu::registerType(); | |
| 770 | 772 | |
| 771 | 773 | auto offscreenUi = DependencyManager::get<OffscreenUi>(); |
| 772 | 774 | offscreenUi->create(_glWidget->context()->contextHandle()); |
| @@ -902,7 +904,9 @@ void Application::runTests() { · 129 unmodified lines | ||
| 902 | 904 | } |
| 903 | 905 | |
| 904 | 906 | 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()); | |
| 906 | 910 | } |
| 907 | 911 | |
| 908 | 912 | void Application::aboutApp() { |
| @@ -1067,12 +1071,10 @@ bool Application::eventFilter(QObject* object, QEvent* event) { · 158 unmodified lines | ||
| 1067 | 1071 | return false; |
| 1068 | 1072 | } |
| 1069 | 1073 | |
| 1070 | −static bool altPressed; | |
| 1071 | −static bool ctrlPressed; | |
| 1074 | +static bool _altPressed{ false }; | |
| 1072 | 1075 | |
| 1073 | 1076 | 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; | |
| 1076 | 1078 | _keysPressed.insert(event->key()); |
| 1077 | 1079 | |
| 1078 | 1080 | _controllerScriptingInterface.emitKeyPressEvent(event); // send events to any registered scripts |
| @@ -1162,9 +1164,7 @@ void Application::keyPressEvent(QKeyEvent* event) { · 83 unmodified lines | ||
| 1162 | 1164 | break; |
| 1163 | 1165 | |
| 1164 | 1166 | case Qt::Key_Backslash: |
| 1165 | − MarketplaceDialog::show(); | |
| 1166 | − | |
| 1167 | − //Menu::getInstance()->triggerOption(MenuOption::Chat); | |
| 1167 | + Menu::getInstance()->triggerOption(MenuOption::Chat); | |
| 1168 | 1168 | break; |
| 1169 | 1169 | |
| 1170 | 1170 | case Qt::Key_Up: |
| @@ -1329,13 +1329,15 @@ void Application::keyPressEvent(QKeyEvent* event) { · 158 unmodified lines | ||
| 1329 | 1329 | } |
| 1330 | 1330 | |
| 1331 | 1331 | 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 | |
| 1337 | 1340 | } |
| 1338 | − ctrlPressed = altPressed = false; | |
| 1339 | 1341 | |
| 1340 | 1342 | _keysPressed.remove(event->key()); |
| 1341 | 1343 | |
| @@ -1346,6 +1348,7 @@ void Application::keyReleaseEvent(QKeyEvent* event) { · 4 unmodified lines | ||
| 1346 | 1348 | return; |
| 1347 | 1349 | } |
| 1348 | 1350 | |
| 1351 | + | |
| 1349 | 1352 | switch (event->key()) { |
| 1350 | 1353 | case Qt::Key_E: |
| 1351 | 1354 | case Qt::Key_PageUp: |
| @@ -1442,6 +1445,18 @@ void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { · 90 unmodified lines | ||
| 1442 | 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 | 1460 | _entities.mouseMoveEvent(event, deviceID); |
| 1446 | 1461 | |
| 1447 | 1462 | _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 | 1464 | if (_controllerScriptingInterface.isMouseCaptured()) { |
| 1450 | 1465 | return; |
| 1451 | 1466 | } |
| 1467 | + | |
| 1452 | 1468 | } |
| 1453 | 1469 | |
| 1454 | 1470 | void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { |
| @@ -1735,6 +1751,34 @@ void Application::setFullscreen(bool fullscreen) { · 280 unmodified lines | ||
| 1735 | 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 | 1782 | // Work around Qt bug that prevents floating menus being shown when in fullscreen mode. |
| 1739 | 1783 | // https://bugreports.qt.io/browse/QTBUG-41883 |
| 1740 | 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 | 2032 | OculusManager::connect(); |
| 1989 | 2033 | 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); | |
| 1994 | 2037 | } |
| 1995 | 2038 | |
| 1996 | 2039 | TV3DManager::connect(); |
| 1997 | 2040 | 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); | |
| 2002 | 2044 | } |
| 2003 | 2045 | |
| 2004 | 2046 | _timerStart.start(); |