From 527b503d5f044deebebee38d8145109c9df05e14 Mon Sep 17 00:00:00 2001 From: John Shepherd Date: Thu, 10 Dec 2020 12:54:31 -0800 Subject: [PATCH 1/2] add right mouse events and tests 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..1db9eb5cc 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 right click + /// dropdown menu. This is primarily used by plugins which also use + /// the right click to cancel any actions currently in progress. + class RightClickDropdownMenu : public QEvent + { + /// \brief Constructor + /// \param[in] _menuEnabled The boolean indicating whether the dropdown + /// menu should be enabled or disabled. + public: explicit RightClickDropdownMenu(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..7ce314a3b 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, RightClickDropdownMenu) +{ + events::RightClickDropdownMenu event(true); + + EXPECT_LT(QEvent::User, event.type()); + EXPECT_EQ(true, event.MenuEnabled()); + + events::RightClickDropdownMenu event2(false); + + EXPECT_LT(QEvent::User, event2.type()); + EXPECT_EQ(false, event2.MenuEnabled()); +} + From 1b8204e841affe2b0ca602e4e215ad557df2a020 Mon Sep 17 00:00:00 2001 From: John Shepherd Date: Thu, 10 Dec 2020 13:10:46 -0800 Subject: [PATCH 2/2] rename right click dropdown event Signed-off-by: John Shepherd --- include/ignition/gui/GuiEvents.hh | 10 +++++----- src/GuiEvents_TEST.cc | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/ignition/gui/GuiEvents.hh b/include/ignition/gui/GuiEvents.hh index 1db9eb5cc..8ef8ea819 100644 --- a/include/ignition/gui/GuiEvents.hh +++ b/include/ignition/gui/GuiEvents.hh @@ -228,15 +228,15 @@ namespace ignition private: math::Vector3d point; }; - /// \brief Event which is called to enable or disable the right click - /// dropdown menu. This is primarily used by plugins which also use - /// the right click to cancel any actions currently in progress. - class RightClickDropdownMenu : public QEvent + /// \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 RightClickDropdownMenu(bool _menuEnabled) + public: explicit DropdownMenuEnabled(bool _menuEnabled) : QEvent(kType), menuEnabled(_menuEnabled) { } diff --git a/src/GuiEvents_TEST.cc b/src/GuiEvents_TEST.cc index 7ce314a3b..72c4ee740 100644 --- a/src/GuiEvents_TEST.cc +++ b/src/GuiEvents_TEST.cc @@ -88,14 +88,14 @@ TEST(GuiEventsTest, RightClickToScene) } ///////////////////////////////////////////////// -TEST(GuiEventsTest, RightClickDropdownMenu) +TEST(GuiEventsTest, DropdownMenuEnabled) { - events::RightClickDropdownMenu event(true); + events::DropdownMenuEnabled event(true); EXPECT_LT(QEvent::User, event.type()); EXPECT_EQ(true, event.MenuEnabled()); - events::RightClickDropdownMenu event2(false); + events::DropdownMenuEnabled event2(false); EXPECT_LT(QEvent::User, event2.type()); EXPECT_EQ(false, event2.MenuEnabled());