From 934abb3d52dac3789a215628044de9fcac78b403 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Mon, 4 Feb 2019 13:33:03 -0800 Subject: [PATCH] fix keyboard focus and image overlays --- interface/src/Application.cpp | 5 +-- interface/src/ui/Keyboard.cpp | 10 +++--- interface/src/ui/Keyboard.h | 4 +-- interface/src/ui/overlays/Overlays.cpp | 50 +++++++++----------------- 4 files changed, 26 insertions(+), 43 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 1cb63872e8..fea58f558c 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1884,9 +1884,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo auto pointerManager = DependencyManager::get(); auto keyboardFocusOperator = [this](const QUuid& id, const PointerEvent& event) { if (event.shouldFocus()) { + auto keyboard = DependencyManager::get(); if (getEntities()->wantsKeyboardFocus(id)) { setKeyboardFocusEntity(id); - } else { + } else if (!keyboard->getKeyIDs().contains(id)) { // FIXME: this is a hack to make the keyboard work for now, since the keys would otherwise steal focus setKeyboardFocusEntity(UNKNOWN_ENTITY_ID); } } @@ -3794,7 +3795,7 @@ static inline bool isKeyEvent(QEvent::Type type) { } bool Application::handleKeyEventForFocusedEntity(QEvent* event) { - if (!_keyboardFocusedEntity.get().isInvalidID()) { + if (_keyboardFocusedEntity.get() != UNKNOWN_ENTITY_ID) { switch (event->type()) { case QEvent::KeyPress: case QEvent::KeyRelease: diff --git a/interface/src/ui/Keyboard.cpp b/interface/src/ui/Keyboard.cpp index 32e6f9d186..8102df6dc6 100644 --- a/interface/src/ui/Keyboard.cpp +++ b/interface/src/ui/Keyboard.cpp @@ -841,7 +841,7 @@ void Keyboard::loadKeyboardFile(const QString& keyboardFile) { key.saveDimensionsAndLocalPosition(); includeItems.append(key.getID()); - _itemsToIgnore.append(key.getID()); + _itemsToIgnore.insert(key.getID()); keyboardLayerKeys.insert(id, key); } @@ -882,8 +882,8 @@ void Keyboard::loadKeyboardFile(const QString& keyboardFile) { } _ignoreItemsLock.withWriteLock([&] { - _itemsToIgnore.append(_textDisplay.entityID); - _itemsToIgnore.append(_anchor.entityID); + _itemsToIgnore.insert(_textDisplay.entityID); + _itemsToIgnore.insert(_anchor.entityID); }); _layerIndex = 0; auto pointerManager = DependencyManager::get(); @@ -905,8 +905,8 @@ bool Keyboard::shouldProcessEntity() const { return (!_keyboardLayers.empty() && isLayerSwitchTimerFinished()); } -QVector Keyboard::getKeysID() { - return _ignoreItemsLock.resultWithReadLock>([&] { +QSet Keyboard::getKeyIDs() { + return _ignoreItemsLock.resultWithReadLock>([&] { return _itemsToIgnore; }); } diff --git a/interface/src/ui/Keyboard.h b/interface/src/ui/Keyboard.h index 7056411578..958c862520 100644 --- a/interface/src/ui/Keyboard.h +++ b/interface/src/ui/Keyboard.h @@ -113,7 +113,7 @@ public: bool containsID(const QUuid& id) const; void loadKeyboardFile(const QString& keyboardFile); - QVector getKeysID(); + QSet getKeyIDs(); QUuid getAnchorID(); public slots: @@ -185,7 +185,7 @@ private: Anchor _anchor; BackPlate _backPlate; - QVector _itemsToIgnore; + QSet _itemsToIgnore; std::vector> _keyboardLayers; }; diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index a10bcc02b9..2580104d94 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -316,17 +316,6 @@ EntityItemProperties Overlays::convertOverlayToEntityProperties(QVariantMap& ove RENAME_PROP(localOrientation, localRotation); RENAME_PROP(ignoreRayIntersection, ignorePickIntersection); - // Model overlays didn't support wireframe drawing - if (type != "Model") { - RENAME_PROP(solid, isSolid); - RENAME_PROP(isFilled, isSolid); - RENAME_PROP(filled, isSolid); - OVERLAY_TO_ENTITY_PROP_CONVERT_DEFAULT(isSolid, primitiveMode, false, [](const QVariant& v) { return v.toBool() ? "solid" : "lines"; }); - - RENAME_PROP(wire, isWire); - RENAME_PROP_CONVERT(isWire, primitiveMode, [](const QVariant& v) { return v.toBool() ? "lines" : "solid"; }); - } - RENAME_PROP_CONVERT(drawInFront, renderLayer, [](const QVariant& v) { return v.toBool() ? "front" : "world"; }); RENAME_PROP_CONVERT(drawHUDLayer, renderLayer, [=](const QVariant& v) { bool f = v.toBool(); @@ -362,6 +351,16 @@ EntityItemProperties Overlays::convertOverlayToEntityProperties(QVariantMap& ove return "none"; }); + if (type == "Shape" || type == "Gizmo") { + RENAME_PROP(solid, isSolid); + RENAME_PROP(isFilled, isSolid); + RENAME_PROP(filled, isSolid); + OVERLAY_TO_ENTITY_PROP_CONVERT_DEFAULT(isSolid, primitiveMode, false, [](const QVariant& v) { return v.toBool() ? "solid" : "lines"; }); + + RENAME_PROP(wire, isWire); + RENAME_PROP_CONVERT(isWire, primitiveMode, [](const QVariant& v) { return v.toBool() ? "lines" : "solid"; }); + } + if (type == "Shape") { SET_OVERLAY_PROP_DEFAULT(shape, "Hexagon"); } else if (type == "Model") { @@ -1185,8 +1184,7 @@ PointerEvent Overlays::calculateOverlayPointerEvent(const QUuid& id, const PickR void Overlays::hoverEnterPointerEvent(const QUuid& id, const PointerEvent& event) { auto keyboard = DependencyManager::get(); // Do not send keyboard key event to scripts to prevent malignant scripts from gathering what you typed - if (!keyboard->getKeysID().contains(id)) { - // emit to scripts + if (!keyboard->getKeyIDs().contains(id)) { emit hoverEnterOverlay(id, event); } } @@ -1194,8 +1192,7 @@ void Overlays::hoverEnterPointerEvent(const QUuid& id, const PointerEvent& event void Overlays::hoverOverPointerEvent(const QUuid& id, const PointerEvent& event) { auto keyboard = DependencyManager::get(); // Do not send keyboard key event to scripts to prevent malignant scripts from gathering what you typed - if (!keyboard->getKeysID().contains(id)) { - // emit to scripts + if (!keyboard->getKeyIDs().contains(id)) { emit hoverOverOverlay(id, event); } } @@ -1203,8 +1200,7 @@ void Overlays::hoverOverPointerEvent(const QUuid& id, const PointerEvent& event) void Overlays::hoverLeavePointerEvent(const QUuid& id, const PointerEvent& event) { auto keyboard = DependencyManager::get(); // Do not send keyboard key event to scripts to prevent malignant scripts from gathering what you typed - if (!keyboard->getKeysID().contains(id)) { - // emit to scripts + if (!keyboard->getKeyIDs().contains(id)) { emit hoverLeaveOverlay(id, event); } } @@ -1228,8 +1224,7 @@ std::pair Overlays::mousePressEvent(QMouseEvent* event) { void Overlays::mousePressPointerEvent(const QUuid& id, const PointerEvent& event) { auto keyboard = DependencyManager::get(); // Do not send keyboard key event to scripts to prevent malignant scripts from gathering what you typed - if (!keyboard->getKeysID().contains(id)) { - // emit to scripts + if (!keyboard->getKeyIDs().contains(id)) { emit mousePressOnOverlay(id, event); } } @@ -1267,7 +1262,7 @@ bool Overlays::mouseReleaseEvent(QMouseEvent* event) { void Overlays::mouseReleasePointerEvent(const QUuid& id, const PointerEvent& event) { auto keyboard = DependencyManager::get(); // Do not send keyboard key event to scripts to prevent malignant scripts from gathering what you typed - if (!keyboard->getKeysID().contains(id)) { + if (!keyboard->getKeyIDs().contains(id)) { emit mouseReleaseOnOverlay(id, event); } } @@ -1311,8 +1306,7 @@ bool Overlays::mouseMoveEvent(QMouseEvent* event) { void Overlays::mouseMovePointerEvent(const QUuid& id, const PointerEvent& event) { auto keyboard = DependencyManager::get(); // Do not send keyboard key event to scripts to prevent malignant scripts from gathering what you typed - if (!keyboard->getKeysID().contains(id)) { - // emit to scripts + if (!keyboard->getKeyIDs().contains(id)) { emit mouseMoveOnOverlay(id, event); } } @@ -1649,8 +1643,6 @@ QVector Overlays::findOverlays(const glm::vec3& center, float radius) { * parentID set, otherwise the same value as position. * @property {Quat} localRotation - The orientation of the overlay relative to its parent if the overlay has a * parentID set, otherwise the same value as rotation. Synonym: localOrientation. - * @property {boolean} isSolid=false - Synonyms: solid, isFilled, and filled. - * Antonyms: isWire and wire. * @property {boolean} ignorePickIntersection=false - If true, picks ignore the overlay. ignoreRayIntersection is a synonym. * @property {boolean} drawInFront=false - If true, the overlay is rendered in front of objects in the world, but behind the HUD. * @property {boolean} drawHUDLayer=false - If true, the overlay is rendered in front of everything, including the HUD. @@ -1708,8 +1700,6 @@ QVector Overlays::findOverlays(const glm::vec3& center, float radius) { * parentID set, otherwise the same value as position. * @property {Quat} localRotation - The orientation of the overlay relative to its parent if the overlay has a * parentID set, otherwise the same value as rotation. Synonym: localOrientation. - * @property {boolean} isSolid=false - Synonyms: solid, isFilled, and filled. - * Antonyms: isWire and wire. * @property {boolean} ignorePickIntersection=false - If true, picks ignore the overlay. ignoreRayIntersection is a synonym. * @property {boolean} drawInFront=false - If true, the overlay is rendered in front of objects in the world, but behind the HUD. * @property {boolean} drawHUDLayer=false - If true, the overlay is rendered in front of everything, including the HUD. @@ -1758,8 +1748,6 @@ QVector Overlays::findOverlays(const glm::vec3& center, float radius) { * parentID set, otherwise the same value as position. * @property {Quat} localRotation - The orientation of the overlay relative to its parent if the overlay has a * parentID set, otherwise the same value as rotation. Synonym: localOrientation. - * @property {boolean} isSolid=false - Synonyms: solid, isFilled, and filled. - * Antonyms: isWire and wire. * @property {boolean} ignorePickIntersection=false - If true, picks ignore the overlay. ignoreRayIntersection is a synonym. * @property {boolean} drawInFront=false - If true, the overlay is rendered in front of objects in the world, but behind the HUD. * @property {boolean} drawHUDLayer=false - If true, the overlay is rendered in front of everything, including the HUD. @@ -1804,8 +1792,6 @@ QVector Overlays::findOverlays(const glm::vec3& center, float radius) { * parentID set, otherwise the same value as position. * @property {Quat} localRotation - The orientation of the overlay relative to its parent if the overlay has a * parentID set, otherwise the same value as rotation. Synonym: localOrientation. - * @property {boolean} isSolid=false - Synonyms: solid, isFilled, and filled. - * Antonyms: isWire and wire. * @property {boolean} ignorePickIntersection=false - If true, picks ignore the overlay. ignoreRayIntersection is a synonym. * @property {boolean} drawInFront=false - If true, the overlay is rendered in front of objects in the world, but behind the HUD. * @property {boolean} drawHUDLayer=false - If true, the overlay is rendered in front of everything, including the HUD. @@ -1838,8 +1824,6 @@ QVector Overlays::findOverlays(const glm::vec3& center, float radius) { * parentID set, otherwise the same value as position. * @property {Quat} localRotation - The orientation of the overlay relative to its parent if the overlay has a * parentID set, otherwise the same value as rotation. Synonym: localOrientation. - * @property {boolean} isSolid=false - Synonyms: solid, isFilled, and filled. - * Antonyms: isWire and wire. * @property {boolean} ignorePickIntersection=false - If true, picks ignore the overlay. ignoreRayIntersection is a synonym. * @property {boolean} drawInFront=false - If true, the overlay is rendered in front of objects in the world, but behind the HUD. * @property {boolean} drawHUDLayer=false - If true, the overlay is rendered in front of everything, including the HUD. @@ -1890,8 +1874,6 @@ QVector Overlays::findOverlays(const glm::vec3& center, float radius) { * parentID set, otherwise the same value as position. * @property {Quat} localRotation - The orientation of the overlay relative to its parent if the overlay has a * parentID set, otherwise the same value as rotation. Synonym: localOrientation. - * @property {boolean} isSolid=false - Synonyms: solid, isFilled, and filled. - * Antonyms: isWire and wire. * @property {boolean} ignorePickIntersection=false - If true, picks ignore the overlay. ignoreRayIntersection is a synonym. * @property {boolean} drawInFront=false - If true, the overlay is rendered in front of objects in the world, but behind the HUD. * @property {boolean} drawHUDLayer=false - If true, the overlay is rendered in front of everything, including the HUD.