From 882139ebcff481bb4edf1e21f72590a218ca521d Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Thu, 14 Jul 2016 12:10:46 -0700 Subject: [PATCH] Allow scripts to override the navigation focus state set by QML dialogs --- interface/src/Application.cpp | 1 + libraries/ui/src/OffscreenUi.cpp | 19 ++++++++++++++++++- libraries/ui/src/OffscreenUi.h | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 0e0f56438e..fb48472b14 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4705,6 +4705,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri qScriptRegisterMetaType(scriptEngine, RayToOverlayIntersectionResultToScriptValue, RayToOverlayIntersectionResultFromScriptValue); + scriptEngine->registerGlobalObject("OffscreenFlags", DependencyManager::get()->getFlags()); scriptEngine->registerGlobalObject("Desktop", DependencyManager::get().data()); scriptEngine->registerGlobalObject("Toolbars", DependencyManager::get().data()); diff --git a/libraries/ui/src/OffscreenUi.cpp b/libraries/ui/src/OffscreenUi.cpp index 1a7d4b2328..28aba4a365 100644 --- a/libraries/ui/src/OffscreenUi.cpp +++ b/libraries/ui/src/OffscreenUi.cpp @@ -29,6 +29,9 @@ class OffscreenFlags : public QObject { Q_OBJECT Q_PROPERTY(bool navigationFocused READ isNavigationFocused WRITE setNavigationFocused NOTIFY navigationFocusedChanged) + // Allow scripts that are doing their own navigation support to disable navigation focus (i.e. handControllerPointer.js) + Q_PROPERTY(bool navigationFocusDisabled READ isNavigationFocusDisabled WRITE setNavigationFocusDisabled NOTIFY navigationFocusDisabledChanged) + public: OffscreenFlags(QObject* parent = nullptr) : QObject(parent) {} @@ -40,11 +43,21 @@ public: } } + bool isNavigationFocusDisabled() const { return _navigationFocusDisabled; } + void setNavigationFocusDisabled(bool disabled) { + if (_navigationFocusDisabled != disabled) { + _navigationFocusDisabled = disabled; + emit navigationFocusDisabledChanged(); + } + } + signals: void navigationFocusedChanged(); + void navigationFocusDisabledChanged(); private: bool _navigationFocused { false }; + bool _navigationFocusDisabled{ false }; }; QString fixupHifiUrl(const QString& urlString) { @@ -103,6 +116,10 @@ bool OffscreenUi::shouldSwallowShortcut(QEvent* event) { OffscreenUi::OffscreenUi() { } +QObject* OffscreenUi::getFlags() { + return offscreenFlags; +} + void OffscreenUi::create(QOpenGLContext* context) { OffscreenQmlSurface::create(context); auto rootContext = getRootContext(); @@ -392,7 +409,7 @@ QVariant OffscreenUi::waitForInputDialogResult(QQuickItem* inputDialog) { } bool OffscreenUi::navigationFocused() { - return offscreenFlags->isNavigationFocused(); + return !offscreenFlags->isNavigationFocusDisabled() && offscreenFlags->isNavigationFocused(); } void OffscreenUi::setNavigationFocused(bool focused) { diff --git a/libraries/ui/src/OffscreenUi.h b/libraries/ui/src/OffscreenUi.h index e1d552c978..2bd00bf612 100644 --- a/libraries/ui/src/OffscreenUi.h +++ b/libraries/ui/src/OffscreenUi.h @@ -55,7 +55,7 @@ public: bool eventFilter(QObject* originalDestination, QEvent* event) override; void addMenuInitializer(std::function f); - + QObject* getFlags(); QQuickItem* getDesktop(); QQuickItem* getToolWindow();