Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add right mouse events and tests #154

Merged
merged 2 commits into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}