From 208e41efd19d12eff4c2d25f83561315c8f445b9 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Thu, 13 Aug 2015 16:22:26 -0700 Subject: [PATCH 1/3] WebEntity keyboard input with mouse hover --- interface/src/Application.cpp | 51 ++++++++++++++++++- interface/src/Application.h | 2 + .../src/RenderableWebEntityItem.cpp | 8 +++ .../src/RenderableWebEntityItem.h | 5 ++ .../render-utils/src/OffscreenQmlSurface.cpp | 4 ++ .../render-utils/src/OffscreenQmlSurface.h | 1 + 6 files changed, 69 insertions(+), 2 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 598498e2d0..e7783c779e 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -98,6 +98,8 @@ #include #include +#include + #include "AudioClient.h" #include "DiscoverabilityManager.h" #include "GLCanvas.h" @@ -146,9 +148,8 @@ #include "ui/AddressBarDialog.h" #include "ui/UpdateDialog.h" -//#include - // ON WIndows PC, NVidia Optimus laptop, we want to enable NVIDIA GPU +// FIXME seems to be broken. #if defined(Q_OS_WIN) extern "C" { _declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; @@ -671,6 +672,28 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : auto& packetReceiver = nodeList->getPacketReceiver(); packetReceiver.registerListener(PacketType::DomainConnectionDenied, this, "handleDomainConnectionDeniedPacket"); + + auto entityScriptingInterface = DependencyManager::get(); + connect(entityScriptingInterface.data(), &EntityScriptingInterface::hoverEnterEntity, [this, entityScriptingInterface](const EntityItemID& entityItemID, const MouseEvent& event) { + if (_keyboardFocusedItem != entityItemID) { + _keyboardFocusedItem = UNKNOWN_ENTITY_ID; + auto properties = entityScriptingInterface->getEntityProperties(entityItemID); + if (EntityTypes::Web == properties.getType() && !properties.getLocked()) { + auto entity = entityScriptingInterface->getEntityTree()->findEntityByID(entityItemID); + RenderableWebEntityItem* webEntity = dynamic_cast(entity.get()); + if (webEntity) { + webEntity->setProxyWindow(_window->windowHandle()); + _keyboardFocusedItem = entityItemID; + } + } + } + }); + + connect(entityScriptingInterface.data(), &EntityScriptingInterface::hoverLeaveEntity, [=](const EntityItemID& entityItemID, const MouseEvent& event) { + if (_keyboardFocusedItem == entityItemID) { + _keyboardFocusedItem = UNKNOWN_ENTITY_ID; + } + }); } void Application::aboutToQuit() { @@ -854,6 +877,10 @@ void Application::initializeGL() { InfoView::show(INFO_HELP_PATH, true); } +QWindow* getProxyWindow() { + return qApp->getWindow()->windowHandle(); +} + void Application::initializeUi() { AddressBarDialog::registerType(); ErrorDialog::registerType(); @@ -1232,6 +1259,26 @@ bool Application::event(QEvent* event) { return true; } + if (!_keyboardFocusedItem.isInvalidID()) { + switch (event->type()) { + case QEvent::KeyPress: + case QEvent::KeyRelease: + { + auto entityScriptingInterface = DependencyManager::get(); + auto entity = entityScriptingInterface->getEntityTree()->findEntityByID(_keyboardFocusedItem); + RenderableWebEntityItem* webEntity = dynamic_cast(entity.get()); + if (webEntity && webEntity->getEventHandler()) { + event->setAccepted(false); + QCoreApplication::sendEvent(webEntity->getEventHandler(), event); + if (event->isAccepted()) { + return true; + } + } + } + break; + } + } + switch (event->type()) { case QEvent::MouseMove: mouseMoveEvent((QMouseEvent*)event); diff --git a/interface/src/Application.h b/interface/src/Application.h index 239b440822..cec1325baf 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -678,6 +678,8 @@ private: bool _overlayEnabled = true; QRect _savedGeometry; DialogsManagerScriptingInterface* _dialogsManagerScriptingInterface = new DialogsManagerScriptingInterface(); + + EntityItemID _keyboardFocusedItem; }; #endif // hifi_Application_h diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp index ce5b389333..73aa6f2718 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp @@ -195,3 +195,11 @@ void RenderableWebEntityItem::setSourceUrl(const QString& value) { } } } + +void RenderableWebEntityItem::setProxyWindow(QWindow* proxyWindow) { + _webSurface->setProxyWindow(proxyWindow); +} + +QObject* RenderableWebEntityItem::getEventHandler() { + return _webSurface->getEventHandler(); +} diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.h b/libraries/entities-renderer/src/RenderableWebEntityItem.h index ee9c2531f1..63418a890f 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.h +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.h @@ -16,6 +16,8 @@ #include "RenderableEntityItem.h" class OffscreenQmlSurface; +class QWindow; +class QObject; class RenderableWebEntityItem : public WebEntityItem { public: @@ -26,6 +28,9 @@ public: virtual void render(RenderArgs* args); virtual void setSourceUrl(const QString& value); + + void setProxyWindow(QWindow* proxyWindow); + QObject* getEventHandler(); SIMPLE_RENDERABLE(); diff --git a/libraries/render-utils/src/OffscreenQmlSurface.cpp b/libraries/render-utils/src/OffscreenQmlSurface.cpp index 78edb8e899..0dfd95a725 100644 --- a/libraries/render-utils/src/OffscreenQmlSurface.cpp +++ b/libraries/render-utils/src/OffscreenQmlSurface.cpp @@ -599,6 +599,10 @@ void OffscreenQmlSurface::setProxyWindow(QWindow* window) { _renderer->_renderControl->_renderWindow = window; } +QObject* OffscreenQmlSurface::getEventHandler() { + return getWindow(); +} + QQuickWindow* OffscreenQmlSurface::getWindow() { return _renderer->_quickWindow; } diff --git a/libraries/render-utils/src/OffscreenQmlSurface.h b/libraries/render-utils/src/OffscreenQmlSurface.h index 1a1827b63f..13e467bccd 100644 --- a/libraries/render-utils/src/OffscreenQmlSurface.h +++ b/libraries/render-utils/src/OffscreenQmlSurface.h @@ -59,6 +59,7 @@ public: void setBaseUrl(const QUrl& baseUrl); QQuickItem* getRootItem(); QQuickWindow* getWindow(); + QObject* getEventHandler(); virtual bool eventFilter(QObject* originalDestination, QEvent* event); From db95657455363a97db19c86da52bf783e14ba8bd Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Fri, 14 Aug 2015 16:40:53 -0700 Subject: [PATCH 2/3] PR comments --- interface/src/Application.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index e7783c779e..ca7ee8d98c 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1262,8 +1262,7 @@ bool Application::event(QEvent* event) { if (!_keyboardFocusedItem.isInvalidID()) { switch (event->type()) { case QEvent::KeyPress: - case QEvent::KeyRelease: - { + case QEvent::KeyRelease: { auto entityScriptingInterface = DependencyManager::get(); auto entity = entityScriptingInterface->getEntityTree()->findEntityByID(_keyboardFocusedItem); RenderableWebEntityItem* webEntity = dynamic_cast(entity.get()); @@ -1274,7 +1273,10 @@ bool Application::event(QEvent* event) { return true; } } + break; } + + default: break; } } From dc2ddd0303a1f9ab8c6ada32bd86a0a3a9eae7d4 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Fri, 14 Aug 2015 17:12:00 -0700 Subject: [PATCH 3/3] switch statement spacing --- interface/src/Application.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index ca7ee8d98c..b8c9b78cc5 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1263,18 +1263,18 @@ bool Application::event(QEvent* event) { switch (event->type()) { case QEvent::KeyPress: case QEvent::KeyRelease: { - auto entityScriptingInterface = DependencyManager::get(); - auto entity = entityScriptingInterface->getEntityTree()->findEntityByID(_keyboardFocusedItem); - RenderableWebEntityItem* webEntity = dynamic_cast(entity.get()); - if (webEntity && webEntity->getEventHandler()) { - event->setAccepted(false); - QCoreApplication::sendEvent(webEntity->getEventHandler(), event); - if (event->isAccepted()) { - return true; - } + auto entityScriptingInterface = DependencyManager::get(); + auto entity = entityScriptingInterface->getEntityTree()->findEntityByID(_keyboardFocusedItem); + RenderableWebEntityItem* webEntity = dynamic_cast(entity.get()); + if (webEntity && webEntity->getEventHandler()) { + event->setAccepted(false); + QCoreApplication::sendEvent(webEntity->getEventHandler(), event); + if (event->isAccepted()) { + return true; } - break; } + break; + } default: break;