Skip to content

Commit

Permalink
Add right mouse events and tests (#154)
Browse files Browse the repository at this point in the history
Signed-off-by: John Shepherd <[email protected]>
  • Loading branch information
John Shepherd authored Dec 10, 2020
1 parent 6f1dca7 commit 94a3fce
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
54 changes: 54 additions & 0 deletions include/ignition/gui/GuiEvents.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions src/GuiEvents_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

0 comments on commit 94a3fce

Please sign in to comment.