History

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()

Anthony J. Thibault committed 10 years ago

Commit 8bb6bb71 parent 4db16874 files · +19 −17Browse files

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

Unified · Split

interface/src/Application.cpp+10−13
@@ -2048,10 +2048,9 @@ bool Application::event(QEvent* event) { · 2047 unmodified lines
20482048 case QEvent::KeyRelease: {
20492049 auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
20502050 auto entity = entityScriptingInterface->getEntityTree()->findEntityByID(_keyboardFocusedItem.get());
2051− RenderableWebEntityItem* webEntity = dynamic_cast<RenderableWebEntityItem*>(entity.get());
2052− if (webEntity && webEntity->getEventHandler()) {
2051+ if (entity && entity->getEventHandler()) {
20532052 event->setAccepted(false);
2054− QCoreApplication::sendEvent(webEntity->getEventHandler(), event);
2053+ QCoreApplication::sendEvent(entity->getEventHandler(), event);
20552054 if (event->isAccepted()) {
20562055 _lastAcceptedKeyPress = usecTimestampNow();
20572056 return true;
@@ -2931,10 +2930,9 @@ void Application::idle(float nsecsElapsed) { · 873 unmodified lines
29312930 // update position of highlight overlay
29322931 auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
29332932 auto entity = entityScriptingInterface->getEntityTree()->findEntityByID(_keyboardFocusedItem.get());
2934− RenderableWebEntityItem* webEntity = dynamic_cast<RenderableWebEntityItem*>(entity.get());
2935− if (webEntity && _keyboardFocusHighlight) {
2936− _keyboardFocusHighlight->setRotation(webEntity->getRotation());
2937− _keyboardFocusHighlight->setPosition(webEntity->getPosition());
2933+ if (entity && _keyboardFocusHighlight) {
2934+ _keyboardFocusHighlight->setRotation(entity->getRotation());
2935+ _keyboardFocusHighlight->setPosition(entity->getPosition());
29382936 }
29392937 }
29402938 }
@@ -3540,9 +3538,8 @@ void Application::setKeyboardFocusEntity(EntityItemID entityItemID) { · 599 unmodified lines
35403538 auto properties = entityScriptingInterface->getEntityProperties(entityItemID);
35413539 if (EntityTypes::Web == properties.getType() && !properties.getLocked() && properties.getVisible()) {
35423540 auto entity = entityScriptingInterface->getEntityTree()->findEntityByID(entityItemID);
3543− RenderableWebEntityItem* webEntity = dynamic_cast<RenderableWebEntityItem*>(entity.get());
3544− if (webEntity) {
3545− webEntity->setProxyWindow(_window->windowHandle());
3541+ if (entity && entity->wantsKeyboardFocus()) {
3542+ entity->setProxyWindow(_window->windowHandle());
35463543 if (_keyboardMouseDevice->isActive()) {
35473544 _keyboardMouseDevice->pluginFocusOutEvent();
35483545 }
@@ -3560,9 +3557,9 @@ void Application::setKeyboardFocusEntity(EntityItemID entityItemID) { · 11 unmodified lines
35603557 _keyboardFocusHighlight->setIgnoreRayIntersection(true);
35613558 _keyboardFocusHighlight->setDrawInFront(false);
35623559 }
3563− _keyboardFocusHighlight->setRotation(webEntity->getRotation());
3564− _keyboardFocusHighlight->setPosition(webEntity->getPosition());
3565− _keyboardFocusHighlight->setDimensions(webEntity->getDimensions() * 1.05f);
3560+ _keyboardFocusHighlight->setRotation(entity->getRotation());
3561+ _keyboardFocusHighlight->setPosition(entity->getPosition());
3562+ _keyboardFocusHighlight->setDimensions(entity->getDimensions() * 1.05f);
35663563 _keyboardFocusHighlight->setVisible(true);
35673564 _keyboardFocusHighlightID = getOverlays().addOverlay(_keyboardFocusHighlight);
35683565 }