Skip to content

Commit

Permalink
Update key event handling (#466)
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 15, 2020
1 parent db45e15 commit 6d1582f
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 24 deletions.
27 changes: 24 additions & 3 deletions src/gui/plugins/scene3d/Scene3D.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2346,6 +2346,8 @@ void Scene3D::LoadConfig(const tinyxml2::XMLElement *_pluginElem)
ignmsg << "Camera pose topic advertised on ["
<< this->dataPtr->cameraPoseTopic << "]" << std::endl;

ignition::gui::App()->findChild<
ignition::gui::MainWindow *>()->QuickWindow()->installEventFilter(this);
ignition::gui::App()->findChild<
ignition::gui::MainWindow *>()->installEventFilter(this);
}
Expand Down Expand Up @@ -2547,7 +2549,26 @@ void RenderWindowItem::SetScaleSnap(const math::Vector3d &_scale)
/////////////////////////////////////////////////
bool Scene3D::eventFilter(QObject *_obj, QEvent *_event)
{
if (_event->type() == ignition::gazebo::gui::events::EntitiesSelected::kType)
if (_event->type() == QEvent::KeyPress)
{
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(_event);
if (keyEvent)
{
auto renderWindow = this->PluginItem()->findChild<RenderWindowItem *>();
renderWindow->HandleKeyPress(keyEvent);
}
}
else if (_event->type() == QEvent::KeyRelease)
{
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(_event);
if (keyEvent)
{
auto renderWindow = this->PluginItem()->findChild<RenderWindowItem *>();
renderWindow->HandleKeyRelease(keyEvent);
}
}
else if (_event->type() ==
ignition::gazebo::gui::events::EntitiesSelected::kType)
{
auto selectedEvent =
reinterpret_cast<gui::events::EntitiesSelected *>(_event);
Expand Down Expand Up @@ -2817,13 +2838,13 @@ void RenderWindowItem::wheelEvent(QWheelEvent *_e)
}

////////////////////////////////////////////////
void RenderWindowItem::keyPressEvent(QKeyEvent *_e)
void RenderWindowItem::HandleKeyPress(QKeyEvent *_e)
{
this->dataPtr->renderThread->ignRenderer.HandleKeyPress(_e);
}

////////////////////////////////////////////////
void RenderWindowItem::keyReleaseEvent(QKeyEvent *_e)
void RenderWindowItem::HandleKeyRelease(QKeyEvent *_e)
{
this->dataPtr->renderThread->ignRenderer.HandleKeyRelease(_e);

Expand Down
14 changes: 8 additions & 6 deletions src/gui/plugins/scene3d/Scene3D.hh
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,14 @@ inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
/// \brief Slot called when thread is ready to be started
public Q_SLOTS: void Ready();

/// \brief Handle key press event for snapping
/// \param[in] _e The key event to process.
public: void HandleKeyPress(QKeyEvent *_e);

/// \brief Handle key release event for snapping
/// \param[in] _e The key event to process.
public: void HandleKeyRelease(QKeyEvent *_e);

// Documentation inherited
protected: void mousePressEvent(QMouseEvent *_e) override;

Expand All @@ -611,12 +619,6 @@ inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
// Documentation inherited
protected: void wheelEvent(QWheelEvent *_e) override;

// Documentation inherited
protected: void keyPressEvent(QKeyEvent *_e) override;

// Documentation inherited
protected: void keyReleaseEvent(QKeyEvent *_e) override;

/// \brief Overrides the paint event to render the render engine
/// camera view
/// \param[in] _oldNode The node passed in previous updatePaintNode
Expand Down
23 changes: 23 additions & 0 deletions src/gui/plugins/transform_control/TransformControl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ void TransformControl::LoadConfig(const tinyxml2::XMLElement *)

ignition::gui::App()->findChild<ignition::gui::MainWindow *>
()->installEventFilter(this);
ignition::gui::App()->findChild<ignition::gui::MainWindow *>
()->QuickWindow()->installEventFilter(this);
}

/////////////////////////////////////////////////
Expand Down Expand Up @@ -232,6 +234,27 @@ bool TransformControl::eventFilter(QObject *_obj, QEvent *_event)
this->dataPtr->snapToGrid = false;
}
}
else if (_event->type() == QEvent::KeyPress)
{
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(_event);
if (keyEvent->key() == Qt::Key_T)
{
this->activateTranslate();
}
else if (keyEvent->key() == Qt::Key_R)
{
this->activateRotate();
}
}
else if (_event->type() == QEvent::KeyRelease)
{
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(_event);
if (keyEvent->key() == Qt::Key_Escape)
{
this->activateSelect();
}
}

return QObject::eventFilter(_obj, _event);
}

Expand Down
9 changes: 9 additions & 0 deletions src/gui/plugins/transform_control/TransformControl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ namespace gazebo
/// \brief Notify that new snapping values have been set.
signals: void newSnapValues();

/// \brief Notify that selection has been activated
signals: void activateSelect();

/// \brief Notify that translation has been activated
signals: void activateTranslate();

/// \brief Notify that rotation has been activated
signals: void activateRotate();

/// \internal
/// \brief Pointer to private data.
private: std::unique_ptr<TransformControlPrivate> dataPtr;
Expand Down
24 changes: 9 additions & 15 deletions src/gui/plugins/transform_control/TransformControl.qml
Original file line number Diff line number Diff line change
Expand Up @@ -91,25 +91,19 @@ ToolBar {
onNewSnapValues: updateSnapValues();
}

// TODO(anyone) enable scale button when support is added in ign-physics
// Shortcut {
// sequence: "S"
// onActivated: activateScale()
// }

Shortcut {
sequence: "T"
onActivated: activateTranslate()
Connections {
target: TransformControl
onActivateSelect: activateSelect();
}

Shortcut {
sequence: "R"
onActivated: activateRotate()
Connections {
target: TransformControl
onActivateTranslate: activateTranslate();
}

Shortcut {
sequence: "Esc"
onActivated: activateSelect()
Connections {
target: TransformControl
onActivateRotate: activateRotate();
}

RowLayout {
Expand Down

0 comments on commit 6d1582f

Please sign in to comment.