From 4bd38b22f39d0eb07a66b05cdd7bab625aee355d Mon Sep 17 00:00:00 2001 From: John Shepherd Date: Sat, 25 Apr 2020 15:04:33 -0700 Subject: [PATCH 1/5] Add force focus when mouse enters render window Signed-off-by: John Shepherd --- src/gui/plugins/scene3d/GzScene3D.qml | 3 +++ src/gui/plugins/scene3d/Scene3D.cc | 7 +++++++ src/gui/plugins/scene3d/Scene3D.hh | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/src/gui/plugins/scene3d/GzScene3D.qml b/src/gui/plugins/scene3d/GzScene3D.qml index 661c0fb57a..d1b774bb72 100644 --- a/src/gui/plugins/scene3d/GzScene3D.qml +++ b/src/gui/plugins/scene3d/GzScene3D.qml @@ -43,6 +43,9 @@ Rectangle { id: renderWindow objectName: "renderWindow" anchors.fill: parent + onEntered: { + GzScene3D.OnFocusWindow() + } /** * Message to be displayed over the render window diff --git a/src/gui/plugins/scene3d/Scene3D.cc b/src/gui/plugins/scene3d/Scene3D.cc index ca23556f01..5b66af2838 100644 --- a/src/gui/plugins/scene3d/Scene3D.cc +++ b/src/gui/plugins/scene3d/Scene3D.cc @@ -2047,6 +2047,13 @@ void Scene3D::OnDropped(const QString &_drop, int _mouseX, int _mouseY) req, cb); } +///////////////////////////////////////////////// +void Scene3D::OnFocusWindow() +{ + auto renderWindow = this->PluginItem()->findChild(); + renderWindow->forceActiveFocus(); +} + ///////////////////////////////////////////////// void RenderWindowItem::SetXYZSnap(const math::Vector3d &_xyz) { diff --git a/src/gui/plugins/scene3d/Scene3D.hh b/src/gui/plugins/scene3d/Scene3D.hh index 8a3d234ff0..f6f47335c2 100644 --- a/src/gui/plugins/scene3d/Scene3D.hh +++ b/src/gui/plugins/scene3d/Scene3D.hh @@ -96,6 +96,10 @@ inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { public slots: void OnDropped(const QString &_drop, int _mouseX, int _mouseY); + /// \brief Callback when the mouse enters the render window to + /// focus the window for mouse/key events + public slots: void OnFocusWindow(); + // Documentation inherited protected: bool eventFilter(QObject *_obj, QEvent *_event) override; From 7ecc5e11fea05ff5b40fff0743c501a0c5f2707e Mon Sep 17 00:00:00 2001 From: John Shepherd Date: Sat, 25 Apr 2020 15:24:31 -0700 Subject: [PATCH 2/5] Move on entered to mouse area Signed-off-by: John Shepherd --- src/gui/plugins/scene3d/GzScene3D.qml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gui/plugins/scene3d/GzScene3D.qml b/src/gui/plugins/scene3d/GzScene3D.qml index d1b774bb72..aeec5ce7fc 100644 --- a/src/gui/plugins/scene3d/GzScene3D.qml +++ b/src/gui/plugins/scene3d/GzScene3D.qml @@ -37,15 +37,15 @@ Rectangle { anchors.fill: parent hoverEnabled: true acceptedButtons: Qt.NoButton + onEntered: { + GzScene3D.OnFocusWindow() + } } RenderWindow { id: renderWindow objectName: "renderWindow" anchors.fill: parent - onEntered: { - GzScene3D.OnFocusWindow() - } /** * Message to be displayed over the render window From 870a0135906562d1fd9cf6a315cedc0849929a7c Mon Sep 17 00:00:00 2001 From: John Shepherd Date: Sat, 25 Apr 2020 16:34:24 -0700 Subject: [PATCH 3/5] Remove unnecessary force focuses Signed-off-by: John Shepherd --- src/gui/plugins/scene3d/Scene3D.cc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/gui/plugins/scene3d/Scene3D.cc b/src/gui/plugins/scene3d/Scene3D.cc index 5b66af2838..80773cb516 100644 --- a/src/gui/plugins/scene3d/Scene3D.cc +++ b/src/gui/plugins/scene3d/Scene3D.cc @@ -2227,8 +2227,6 @@ void RenderWindowItem::SetWorldName(const std::string &_name) ///////////////////////////////////////////////// void RenderWindowItem::mousePressEvent(QMouseEvent *_e) { - this->forceActiveFocus(); - auto event = ignition::gui::convert(*_e); event.SetPressPos(event.Pos()); this->dataPtr->mouseEvent = event; @@ -2277,8 +2275,6 @@ void RenderWindowItem::mouseMoveEvent(QMouseEvent *_e) //////////////////////////////////////////////// void RenderWindowItem::wheelEvent(QWheelEvent *_e) { - this->forceActiveFocus(); - this->dataPtr->mouseEvent.SetType(common::MouseEvent::SCROLL); this->dataPtr->mouseEvent.SetPos(_e->x(), _e->y()); double scroll = (_e->angleDelta().y() > 0) ? -1.0 : 1.0; From a5104f89e9309d4dad47f49daca3c89008d97a3b Mon Sep 17 00:00:00 2001 From: John Shepherd Date: Tue, 28 Apr 2020 11:27:56 -0700 Subject: [PATCH 4/5] update changelog Signed-off-by: John Shepherd --- Changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Changelog.md b/Changelog.md index 18391b7465..8bbed41543 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,6 +5,9 @@ 1. Add ability to save worlds to SDFormat * [BitBucket pull request 545](https://osrf-migration.github.io/ignition-gh-pages/#!/ignitionrobotics/ign-gazebo/pull-requests/545) +1. Add window focus upon mouse entering the render window + * [Github pull request 95](https://github.com/ignitionrobotics/ign-gazebo/pull/95) + ### Ignition Gazebo 2.16.0 (2020-03-24) 1. Add support for computing model bounding box in physics system From d0316c39abe89df47a04b4cdae4baa7e6bcc400a Mon Sep 17 00:00:00 2001 From: John Shepherd Date: Tue, 28 Apr 2020 14:33:19 -0700 Subject: [PATCH 5/5] Add back force focus for mouse and scroll Signed-off-by: John Shepherd --- src/gui/plugins/scene3d/Scene3D.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gui/plugins/scene3d/Scene3D.cc b/src/gui/plugins/scene3d/Scene3D.cc index 80773cb516..5b66af2838 100644 --- a/src/gui/plugins/scene3d/Scene3D.cc +++ b/src/gui/plugins/scene3d/Scene3D.cc @@ -2227,6 +2227,8 @@ void RenderWindowItem::SetWorldName(const std::string &_name) ///////////////////////////////////////////////// void RenderWindowItem::mousePressEvent(QMouseEvent *_e) { + this->forceActiveFocus(); + auto event = ignition::gui::convert(*_e); event.SetPressPos(event.Pos()); this->dataPtr->mouseEvent = event; @@ -2275,6 +2277,8 @@ void RenderWindowItem::mouseMoveEvent(QMouseEvent *_e) //////////////////////////////////////////////// void RenderWindowItem::wheelEvent(QWheelEvent *_e) { + this->forceActiveFocus(); + this->dataPtr->mouseEvent.SetType(common::MouseEvent::SCROLL); this->dataPtr->mouseEvent.SetPos(_e->x(), _e->y()); double scroll = (_e->angleDelta().y() > 0) ? -1.0 : 1.0;