Showing the changes to interface/src/Application.cpp (1 of 45 files). Show all
Unified · Split
| @@ -137,6 +137,7 @@ · 136 unmodified lines | ||
| 137 | 137 | #include "ui/Snapshot.h" |
| 138 | 138 | #include "ui/StandAloneJSConsole.h" |
| 139 | 139 | #include "ui/Stats.h" |
| 140 | +#include "ui/AddressBarDialog.h" | |
| 140 | 141 | |
| 141 | 142 | // ON WIndows PC, NVidia Optimus laptop, we want to enable NVIDIA GPU |
| 142 | 143 | #if defined(Q_OS_WIN) |
| @@ -209,8 +210,12 @@ public: · 66 unmodified lines | ||
| 209 | 210 | |
| 210 | 211 | void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) { |
| 211 | 212 | QString logMessage = LogHandler::getInstance().printMessage((LogMsgType) type, context, message); |
| 212 | − | |
| 213 | + | |
| 213 | 214 | if (!logMessage.isEmpty()) { |
| 215 | +#ifdef Q_OS_WIN | |
| 216 | + OutputDebugStringA(logMessage.toLocal8Bit().constData()); | |
| 217 | + OutputDebugStringA("\n"); | |
| 218 | +#endif | |
| 214 | 219 | Application::getInstance()->getLogger()->addMessage(qPrintable(logMessage + "\n")); |
| 215 | 220 | } |
| 216 | 221 | } |
| @@ -260,6 +265,7 @@ bool setupEssentials(int& argc, char** argv) { · 43 unmodified lines | ||
| 260 | 265 | #endif |
| 261 | 266 | auto discoverabilityManager = DependencyManager::set<DiscoverabilityManager>(); |
| 262 | 267 | auto sceneScriptingInterface = DependencyManager::set<SceneScriptingInterface>(); |
| 268 | + auto offscreenUi = DependencyManager::set<OffscreenUi>(); | |
| 263 | 269 | |
| 264 | 270 | return true; |
| 265 | 271 | } |
| @@ -316,8 +322,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 50 unmodified lines | ||
| 316 | 322 | #ifdef Q_OS_WIN |
| 317 | 323 | installNativeEventFilter(&MyNativeEventFilter::getInstance()); |
| 318 | 324 | #endif |
| 325 | + | |
| 319 | 326 | |
| 320 | 327 | _logger = new FileLogger(this); // After setting organization name in order to get correct directory |
| 328 | + | |
| 321 | 329 | qInstallMessageHandler(messageHandler); |
| 322 | 330 | |
| 323 | 331 | QFontDatabase::addApplicationFont(PathUtils::resourcesPath() + "styles/Inconsolata.otf"); |
| @@ -562,8 +570,13 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 238 unmodified lines | ||
| 562 | 570 | #endif |
| 563 | 571 | |
| 564 | 572 | this->installEventFilter(this); |
| 573 | + // The offscreen UI needs to intercept the mouse and keyboard | |
| 574 | + // events coming from the onscreen window | |
| 575 | + _glWidget->installEventFilter( | |
| 576 | + DependencyManager::get<OffscreenUi>().data()); | |
| 565 | 577 | } |
| 566 | 578 | |
| 579 | + | |
| 567 | 580 | void Application::aboutToQuit() { |
| 568 | 581 | emit beforeAboutToQuit(); |
| 569 | 582 | |
| @@ -720,10 +733,35 @@ void Application::initializeGL() { · 150 unmodified lines | ||
| 720 | 733 | |
| 721 | 734 | // update before the first render |
| 722 | 735 | update(1.0f / _fps); |
| 736 | + | |
| 737 | + // The UI can't be created until the primary OpenGL | |
| 738 | + // context is created, because it needs to share | |
| 739 | + // texture resources | |
| 740 | + initializeUi(); | |
| 723 | 741 | |
| 724 | 742 | InfoView::showFirstTime(INFO_HELP_PATH); |
| 725 | 743 | } |
| 726 | 744 | |
| 745 | +void Application::initializeUi() { | |
| 746 | + AddressBarDialog::registerType(); | |
| 747 | + LoginDialog::registerType(); | |
| 748 | + | |
| 749 | + auto offscreenUi = DependencyManager::get<OffscreenUi>(); | |
| 750 | + offscreenUi->create(_glWidget->context()->contextHandle()); | |
| 751 | + offscreenUi->resize(_glWidget->size()); | |
| 752 | + offscreenUi->setProxyWindow(_window->windowHandle()); | |
| 753 | + auto rootQml = PathUtils::resourcesPath() + "qml/Root.qml"; | |
| 754 | + offscreenUi->loadQml(QUrl::fromLocalFile(rootQml)); | |
| 755 | + offscreenUi->setMouseTranslator([this](const QPointF& p){ | |
| 756 | + if (OculusManager::isConnected()) { | |
| 757 | + glm::vec2 pos = _applicationOverlay.screenToOverlay(toGlm(p)); | |
| 758 | + return QPointF(pos.x, pos.y); | |
| 759 | + } | |
| 760 | + return QPointF(p); | |
| 761 | + }); | |
| 762 | + offscreenUi->resume(); | |
| 763 | +} | |
| 764 | + | |
| 727 | 765 | void Application::paintGL() { |
| 728 | 766 | PROFILE_RANGE(__FUNCTION__); |
| 729 | 767 | PerformanceTimer perfTimer("paintGL"); |
| @@ -818,7 +856,7 @@ void Application::paintGL() { · 88 unmodified lines | ||
| 818 | 856 | |
| 819 | 857 | { |
| 820 | 858 | PerformanceTimer perfTimer("renderOverlay"); |
| 821 | − _applicationOverlay.renderOverlay(true); | |
| 859 | + _applicationOverlay.renderOverlay(); | |
| 822 | 860 | _applicationOverlay.displayOverlayTexture(); |
| 823 | 861 | } |
| 824 | 862 | } |
| @@ -863,6 +901,9 @@ void Application::resizeGL(int width, int height) { · 38 unmodified lines | ||
| 863 | 901 | updateProjectionMatrix(); |
| 864 | 902 | glLoadIdentity(); |
| 865 | 903 | |
| 904 | + auto offscreenUi = DependencyManager::get<OffscreenUi>(); | |
| 905 | + offscreenUi->resize(QSize(width, height)); | |
| 906 | + | |
| 866 | 907 | // update Stats width |
| 867 | 908 | // let's set horizontal offset to give stats some margin to mirror |
| 868 | 909 | int horizontalOffset = MIRROR_VIEW_WIDTH + MIRROR_VIEW_LEFT_PADDING * 2; |
| @@ -911,6 +952,44 @@ bool Application::importSVOFromURL(const QString& urlString) { · 42 unmodified lines | ||
| 911 | 952 | } |
| 912 | 953 | |
| 913 | 954 | bool Application::event(QEvent* event) { |
| 955 | + switch (event->type()) { | |
| 956 | + case QEvent::MouseMove: | |
| 957 | + mouseMoveEvent((QMouseEvent*)event); | |
| 958 | + return true; | |
| 959 | + case QEvent::MouseButtonPress: | |
| 960 | + mousePressEvent((QMouseEvent*)event); | |
| 961 | + return true; | |
| 962 | + case QEvent::MouseButtonRelease: | |
| 963 | + mouseReleaseEvent((QMouseEvent*)event); | |
| 964 | + return true; | |
| 965 | + case QEvent::KeyPress: | |
| 966 | + keyPressEvent((QKeyEvent*)event); | |
| 967 | + return true; | |
| 968 | + case QEvent::KeyRelease: | |
| 969 | + keyReleaseEvent((QKeyEvent*)event); | |
| 970 | + return true; | |
| 971 | + case QEvent::FocusOut: | |
| 972 | + focusOutEvent((QFocusEvent*)event); | |
| 973 | + return true; | |
| 974 | + case QEvent::TouchBegin: | |
| 975 | + touchBeginEvent(static_cast<QTouchEvent*>(event)); | |
| 976 | + event->accept(); | |
| 977 | + return true; | |
| 978 | + case QEvent::TouchEnd: | |
| 979 | + touchEndEvent(static_cast<QTouchEvent*>(event)); | |
| 980 | + return true; | |
| 981 | + case QEvent::TouchUpdate: | |
| 982 | + touchUpdateEvent(static_cast<QTouchEvent*>(event)); | |
| 983 | + return true; | |
| 984 | + case QEvent::Wheel: | |
| 985 | + wheelEvent(static_cast<QWheelEvent*>(event)); | |
| 986 | + return true; | |
| 987 | + case QEvent::Drop: | |
| 988 | + dropEvent(static_cast<QDropEvent*>(event)); | |
| 989 | + return true; | |
| 990 | + default: | |
| 991 | + break; | |
| 992 | + } | |
| 914 | 993 | |
| 915 | 994 | // handle custom URL |
| 916 | 995 | if (event->type() == QEvent::FileOpen) { |
| @@ -931,7 +1010,7 @@ bool Application::event(QEvent* event) { · 14 unmodified lines | ||
| 931 | 1010 | if (HFActionEvent::types().contains(event->type())) { |
| 932 | 1011 | _controllerScriptingInterface.handleMetaEvent(static_cast<HFMetaEvent*>(event)); |
| 933 | 1012 | } |
| 934 | − | |
| 1013 | + | |
| 935 | 1014 | return QApplication::event(event); |
| 936 | 1015 | } |
| 937 | 1016 | |
| @@ -963,14 +1042,17 @@ void Application::keyPressEvent(QKeyEvent* event) { · 25 unmodified lines | ||
| 963 | 1042 | bool isShifted = event->modifiers().testFlag(Qt::ShiftModifier); |
| 964 | 1043 | bool isMeta = event->modifiers().testFlag(Qt::ControlModifier); |
| 965 | 1044 | bool isOption = event->modifiers().testFlag(Qt::AltModifier); |
| 1045 | + bool isKeypad = event->modifiers().testFlag(Qt::KeypadModifier); | |
| 966 | 1046 | switch (event->key()) { |
| 967 | 1047 | break; |
| 968 | 1048 | case Qt::Key_L: |
| 969 | − if (isShifted) { | |
| 970 | − Menu::getInstance()->triggerOption(MenuOption::LodTools); | |
| 971 | − } else if (isMeta) { | |
| 1049 | + if (isShifted && isMeta) { | |
| 972 | 1050 | Menu::getInstance()->triggerOption(MenuOption::Log); |
| 973 | − } | |
| 1051 | + } else if (isMeta) { | |
| 1052 | + Menu::getInstance()->triggerOption(MenuOption::AddressBar); | |
| 1053 | + } else if (isShifted) { | |
| 1054 | + Menu::getInstance()->triggerOption(MenuOption::LodTools); | |
| 1055 | + } | |
| 974 | 1056 | break; |
| 975 | 1057 | |
| 976 | 1058 | case Qt::Key_E: |
| @@ -1030,11 +1112,6 @@ void Application::keyPressEvent(QKeyEvent* event) { · 53 unmodified lines | ||
| 1030 | 1112 | } |
| 1031 | 1113 | break; |
| 1032 | 1114 | |
| 1033 | − case Qt::Key_Return: | |
| 1034 | − case Qt::Key_Enter: | |
| 1035 | − Menu::getInstance()->triggerOption(MenuOption::AddressBar); | |
| 1036 | − break; | |
| 1037 | − | |
| 1038 | 1115 | case Qt::Key_Backslash: |
| 1039 | 1116 | Menu::getInstance()->triggerOption(MenuOption::Chat); |
| 1040 | 1117 | break; |
| @@ -1494,6 +1571,17 @@ void Application::dropEvent(QDropEvent *event) { · 453 unmodified lines | ||
| 1494 | 1571 | } |
| 1495 | 1572 | } |
| 1496 | 1573 | |
| 1574 | +void Application::dragEnterEvent(QDragEnterEvent* event) { | |
| 1575 | + const QMimeData* mimeData = event->mimeData(); | |
| 1576 | + foreach(QUrl url, mimeData->urls()) { | |
| 1577 | + auto urlString = url.toString(); | |
| 1578 | + if (canAcceptURL(urlString)) { | |
| 1579 | + event->acceptProposedAction(); | |
| 1580 | + break; | |
| 1581 | + } | |
| 1582 | + } | |
| 1583 | +} | |
| 1584 | + | |
| 1497 | 1585 | bool Application::acceptSnapshot(const QString& urlString) { |
| 1498 | 1586 | QUrl url(urlString); |
| 1499 | 1587 | QString snapshotPath = url.toLocalFile(); |