History

Working on new-UI implementations of address bar and login

Brad Davis committed 11 years ago

Commit d14d5f31 parent fe482b345 files · +1842 −726Browse files

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

Unified · Split

interface/src/Application.cpp+100−12
@@ -137,6 +137,7 @@ · 136 unmodified lines
137137 #include "ui/Snapshot.h"
138138 #include "ui/StandAloneJSConsole.h"
139139 #include "ui/Stats.h"
140+#include "ui/AddressBarDialog.h"
140141
141142 // ON WIndows PC, NVidia Optimus laptop, we want to enable NVIDIA GPU
142143 #if defined(Q_OS_WIN)
@@ -209,8 +210,12 @@ public: · 66 unmodified lines
209210
210211 void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) {
211212 QString logMessage = LogHandler::getInstance().printMessage((LogMsgType) type, context, message);
212−
213+
213214 if (!logMessage.isEmpty()) {
215+#ifdef Q_OS_WIN
216+ OutputDebugStringA(logMessage.toLocal8Bit().constData());
217+ OutputDebugStringA("\n");
218+#endif
214219 Application::getInstance()->getLogger()->addMessage(qPrintable(logMessage + "\n"));
215220 }
216221 }
@@ -260,6 +265,7 @@ bool setupEssentials(int& argc, char** argv) { · 43 unmodified lines
260265 #endif
261266 auto discoverabilityManager = DependencyManager::set<DiscoverabilityManager>();
262267 auto sceneScriptingInterface = DependencyManager::set<SceneScriptingInterface>();
268+ auto offscreenUi = DependencyManager::set<OffscreenUi>();
263269
264270 return true;
265271 }
@@ -316,8 +322,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 50 unmodified lines
316322 #ifdef Q_OS_WIN
317323 installNativeEventFilter(&MyNativeEventFilter::getInstance());
318324 #endif
325+
319326
320327 _logger = new FileLogger(this); // After setting organization name in order to get correct directory
328+
321329 qInstallMessageHandler(messageHandler);
322330
323331 QFontDatabase::addApplicationFont(PathUtils::resourcesPath() + "styles/Inconsolata.otf");
@@ -562,8 +570,13 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 238 unmodified lines
562570 #endif
563571
564572 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());
565577 }
566578
579+
567580 void Application::aboutToQuit() {
568581 emit beforeAboutToQuit();
569582
@@ -720,10 +733,35 @@ void Application::initializeGL() { · 150 unmodified lines
720733
721734 // update before the first render
722735 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();
723741
724742 InfoView::showFirstTime(INFO_HELP_PATH);
725743 }
726744
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+
727765 void Application::paintGL() {
728766 PROFILE_RANGE(__FUNCTION__);
729767 PerformanceTimer perfTimer("paintGL");
@@ -818,7 +856,7 @@ void Application::paintGL() { · 88 unmodified lines
818856
819857 {
820858 PerformanceTimer perfTimer("renderOverlay");
821− _applicationOverlay.renderOverlay(true);
859+ _applicationOverlay.renderOverlay();
822860 _applicationOverlay.displayOverlayTexture();
823861 }
824862 }
@@ -863,6 +901,9 @@ void Application::resizeGL(int width, int height) { · 38 unmodified lines
863901 updateProjectionMatrix();
864902 glLoadIdentity();
865903
904+ auto offscreenUi = DependencyManager::get<OffscreenUi>();
905+ offscreenUi->resize(QSize(width, height));
906+
866907 // update Stats width
867908 // let's set horizontal offset to give stats some margin to mirror
868909 int horizontalOffset = MIRROR_VIEW_WIDTH + MIRROR_VIEW_LEFT_PADDING * 2;
@@ -911,6 +952,44 @@ bool Application::importSVOFromURL(const QString& urlString) { · 42 unmodified lines
911952 }
912953
913954 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+ }
914993
915994 // handle custom URL
916995 if (event->type() == QEvent::FileOpen) {
@@ -931,7 +1010,7 @@ bool Application::event(QEvent* event) { · 14 unmodified lines
9311010 if (HFActionEvent::types().contains(event->type())) {
9321011 _controllerScriptingInterface.handleMetaEvent(static_cast<HFMetaEvent*>(event));
9331012 }
934−
1013+
9351014 return QApplication::event(event);
9361015 }
9371016
@@ -963,14 +1042,17 @@ void Application::keyPressEvent(QKeyEvent* event) { · 25 unmodified lines
9631042 bool isShifted = event->modifiers().testFlag(Qt::ShiftModifier);
9641043 bool isMeta = event->modifiers().testFlag(Qt::ControlModifier);
9651044 bool isOption = event->modifiers().testFlag(Qt::AltModifier);
1045+ bool isKeypad = event->modifiers().testFlag(Qt::KeypadModifier);
9661046 switch (event->key()) {
9671047 break;
9681048 case Qt::Key_L:
969− if (isShifted) {
970− Menu::getInstance()->triggerOption(MenuOption::LodTools);
971− } else if (isMeta) {
1049+ if (isShifted && isMeta) {
9721050 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+ }
9741056 break;
9751057
9761058 case Qt::Key_E:
@@ -1030,11 +1112,6 @@ void Application::keyPressEvent(QKeyEvent* event) { · 53 unmodified lines
10301112 }
10311113 break;
10321114
1033− case Qt::Key_Return:
1034− case Qt::Key_Enter:
1035− Menu::getInstance()->triggerOption(MenuOption::AddressBar);
1036− break;
1037−
10381115 case Qt::Key_Backslash:
10391116 Menu::getInstance()->triggerOption(MenuOption::Chat);
10401117 break;
@@ -1494,6 +1571,17 @@ void Application::dropEvent(QDropEvent *event) { · 453 unmodified lines
14941571 }
14951572 }
14961573
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+
14971585 bool Application::acceptSnapshot(const QString& urlString) {
14981586 QUrl url(urlString);
14991587 QString snapshotPath = url.toLocalFile();