From 8bb6bb7c6f260d8fc6ae3d4be22cbee28df29810 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Fri, 19 Aug 2016 10:56:52 -0700 Subject: [PATCH] generalized keyboard focus interface Removed dynamic casts to RenderableWebEntityItem, instead virtual methods were added to EntityItem to facilitate this. * bool wantsKeyboardFocus() * void setProxyWindow() * QObject* getEventHandler() --- interface/src/Application.cpp | 23 ++++++++----------- .../src/RenderableWebEntityItem.h | 6 +++-- libraries/entities/src/EntityItem.h | 5 ++++ libraries/entities/src/WebEntityItem.h | 2 -- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 070be759f3..ebae24b3b8 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2048,10 +2048,9 @@ bool Application::event(QEvent* event) { case QEvent::KeyRelease: { auto entityScriptingInterface = DependencyManager::get(); auto entity = entityScriptingInterface->getEntityTree()->findEntityByID(_keyboardFocusedItem.get()); - RenderableWebEntityItem* webEntity = dynamic_cast(entity.get()); - if (webEntity && webEntity->getEventHandler()) { + if (entity && entity->getEventHandler()) { event->setAccepted(false); - QCoreApplication::sendEvent(webEntity->getEventHandler(), event); + QCoreApplication::sendEvent(entity->getEventHandler(), event); if (event->isAccepted()) { _lastAcceptedKeyPress = usecTimestampNow(); return true; @@ -2931,10 +2930,9 @@ void Application::idle(float nsecsElapsed) { // update position of highlight overlay auto entityScriptingInterface = DependencyManager::get(); auto entity = entityScriptingInterface->getEntityTree()->findEntityByID(_keyboardFocusedItem.get()); - RenderableWebEntityItem* webEntity = dynamic_cast(entity.get()); - if (webEntity && _keyboardFocusHighlight) { - _keyboardFocusHighlight->setRotation(webEntity->getRotation()); - _keyboardFocusHighlight->setPosition(webEntity->getPosition()); + if (entity && _keyboardFocusHighlight) { + _keyboardFocusHighlight->setRotation(entity->getRotation()); + _keyboardFocusHighlight->setPosition(entity->getPosition()); } } } @@ -3540,9 +3538,8 @@ void Application::setKeyboardFocusEntity(EntityItemID entityItemID) { auto properties = entityScriptingInterface->getEntityProperties(entityItemID); if (EntityTypes::Web == properties.getType() && !properties.getLocked() && properties.getVisible()) { auto entity = entityScriptingInterface->getEntityTree()->findEntityByID(entityItemID); - RenderableWebEntityItem* webEntity = dynamic_cast(entity.get()); - if (webEntity) { - webEntity->setProxyWindow(_window->windowHandle()); + if (entity && entity->wantsKeyboardFocus()) { + entity->setProxyWindow(_window->windowHandle()); if (_keyboardMouseDevice->isActive()) { _keyboardMouseDevice->pluginFocusOutEvent(); } @@ -3560,9 +3557,9 @@ void Application::setKeyboardFocusEntity(EntityItemID entityItemID) { _keyboardFocusHighlight->setIgnoreRayIntersection(true); _keyboardFocusHighlight->setDrawInFront(false); } - _keyboardFocusHighlight->setRotation(webEntity->getRotation()); - _keyboardFocusHighlight->setPosition(webEntity->getPosition()); - _keyboardFocusHighlight->setDimensions(webEntity->getDimensions() * 1.05f); + _keyboardFocusHighlight->setRotation(entity->getRotation()); + _keyboardFocusHighlight->setPosition(entity->getPosition()); + _keyboardFocusHighlight->setDimensions(entity->getDimensions() * 1.05f); _keyboardFocusHighlight->setVisible(true); _keyboardFocusHighlightID = getOverlays().addOverlay(_keyboardFocusHighlight); } diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.h b/libraries/entities-renderer/src/RenderableWebEntityItem.h index 578bd2f3b1..ee8a484109 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.h +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.h @@ -32,8 +32,10 @@ public: virtual void render(RenderArgs* args) override; virtual void setSourceUrl(const QString& value) override; - void setProxyWindow(QWindow* proxyWindow); - QObject* getEventHandler(); + virtual bool wantsHandControllerPointerEvents() const override { return true; } + virtual bool wantsKeyboardFocus() const override { return true; } + virtual void setProxyWindow(QWindow* proxyWindow) override; + virtual QObject* getEventHandler() override; void handlePointerEvent(const PointerEvent& event); diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index e2bc9b568b..5427514573 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -17,6 +17,8 @@ #include +#include + #include // for Animation, AnimationCache, and AnimationPointer classes #include // for EncodeBitstreamParams class #include // for OctreeElement::AppendState @@ -435,6 +437,9 @@ public: virtual bool isTransparent() { return _isFading ? Interpolate::calculateFadeRatio(_fadeStartTime) < 1.0f : false; } virtual bool wantsHandControllerPointerEvents() const { return false; } + virtual bool wantsKeyboardFocus() const { return false; } + virtual void setProxyWindow(QWindow* proxyWindow) {} + virtual QObject* getEventHandler() { return nullptr; } protected: diff --git a/libraries/entities/src/WebEntityItem.h b/libraries/entities/src/WebEntityItem.h index b63edc99ea..538d0c2f45 100644 --- a/libraries/entities/src/WebEntityItem.h +++ b/libraries/entities/src/WebEntityItem.h @@ -54,8 +54,6 @@ public: virtual void setSourceUrl(const QString& value); const QString& getSourceUrl() const; - virtual bool wantsHandControllerPointerEvents() const { return true; } - protected: QString _sourceUrl; };