From 6f1dca719ea7453108ba9328eec8b96f586771dd Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Thu, 10 Dec 2020 13:21:27 -0800 Subject: [PATCH 1/2] Change deprecated Qt::MidButton (#153) Signed-off-by: Louise Poubel --- src/Conversions.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Conversions.cc b/src/Conversions.cc index c5641fba4..77b1eee68 100644 --- a/src/Conversions.cc +++ b/src/Conversions.cc @@ -73,7 +73,7 @@ ignition::common::MouseEvent ignition::gui::convert(const QMouseEvent &_e) event.SetButton(common::MouseEvent::LEFT); else if (_e.button() == Qt::RightButton) event.SetButton(common::MouseEvent::RIGHT); - else if (_e.button() == Qt::MidButton) + else if (_e.button() == Qt::MiddleButton) event.SetButton(common::MouseEvent::MIDDLE); // Buttons @@ -83,7 +83,7 @@ ignition::common::MouseEvent ignition::gui::convert(const QMouseEvent &_e) if (_e.buttons() & Qt::RightButton) event.SetButtons(event.Buttons() | common::MouseEvent::RIGHT); - if (_e.buttons() & Qt::MidButton) + if (_e.buttons() & Qt::MiddleButton) event.SetButtons(event.Buttons() | common::MouseEvent::MIDDLE); // Type From 94a3fce483f1f6b68e08a976ff3e6c613d9b0074 Mon Sep 17 00:00:00 2001 From: John Shepherd Date: Thu, 10 Dec 2020 13:22:09 -0800 Subject: [PATCH 2/2] Add right mouse events and tests (#154) Signed-off-by: John Shepherd --- include/ignition/gui/GuiEvents.hh | 54 +++++++++++++++++++++++++++++++ src/GuiEvents_TEST.cc | 23 +++++++++++++ 2 files changed, 77 insertions(+) diff --git a/include/ignition/gui/GuiEvents.hh b/include/ignition/gui/GuiEvents.hh index 08d776a54..8ef8ea819 100644 --- a/include/ignition/gui/GuiEvents.hh +++ b/include/ignition/gui/GuiEvents.hh @@ -201,6 +201,60 @@ namespace ignition /// \brief The 3D point that the user clicked within the scene. private: math::Vector3d point; }; + + /// \brief Event which is called to broadcast the 3D coordinates of a + /// user's right click within the scene. + class RightClickToScene : public QEvent + { + /// \brief Constructor + /// \param[in] _point The point which the user has right clicked + /// within the scene + public: explicit RightClickToScene(const math::Vector3d &_point) + : QEvent(kType), point(_point) + { + } + + /// \brief Unique type for this event. + static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 6); + + /// \brief Get the point within the scene that the user clicked. + /// \return The 3D point. + public: math::Vector3d Point() const + { + return this->point; + } + + /// \brief The 3D point that the user clicked within the scene. + private: math::Vector3d point; + }; + + /// \brief Event which is called to enable or disable the dropdown menu. + /// This is primarily used by plugins which also use the right click + /// mouse event to cancel any actions currently in progress. + class DropdownMenuEnabled : public QEvent + { + /// \brief Constructor + /// \param[in] _menuEnabled The boolean indicating whether the dropdown + /// menu should be enabled or disabled. + public: explicit DropdownMenuEnabled(bool _menuEnabled) + : QEvent(kType), menuEnabled(_menuEnabled) + { + } + + /// \brief Unique type for this event. + static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 7); + + /// \brief Gets whether the menu is enabled or not for this event. + /// \return True if enabling the menu, false if disabling the menu + public: bool MenuEnabled() const + { + return this->menuEnabled; + } + + /// \brief The boolean indicating whether the menu is disabled or not + /// for this event. + private: bool menuEnabled; + }; } } } diff --git a/src/GuiEvents_TEST.cc b/src/GuiEvents_TEST.cc index 0bdb24d74..72c4ee740 100644 --- a/src/GuiEvents_TEST.cc +++ b/src/GuiEvents_TEST.cc @@ -78,3 +78,26 @@ TEST(GuiEventsTest, LeftClickToScene) EXPECT_EQ(math::Vector3d(1, 2, 3), event.Point()); } +///////////////////////////////////////////////// +TEST(GuiEventsTest, RightClickToScene) +{ + events::RightClickToScene event({1, 2, 3}); + + EXPECT_LT(QEvent::User, event.type()); + EXPECT_EQ(math::Vector3d(1, 2, 3), event.Point()); +} + +///////////////////////////////////////////////// +TEST(GuiEventsTest, DropdownMenuEnabled) +{ + events::DropdownMenuEnabled event(true); + + EXPECT_LT(QEvent::User, event.type()); + EXPECT_EQ(true, event.MenuEnabled()); + + events::DropdownMenuEnabled event2(false); + + EXPECT_LT(QEvent::User, event2.type()); + EXPECT_EQ(false, event2.MenuEnabled()); +} +