Skip to content

Commit

Permalink
Enable mouse tracking for RenderPanel (#1433)
Browse files Browse the repository at this point in the history
With mouseTracking enabled, a QWidget will receive mouseMoveEvents even though no mouse button is pressed. This behavior was faked in rviz with a 30Hz timer, resulting in some strange side effects.
The fake code is kept for ABI compatibility but should be removed for Noetic.
  • Loading branch information
simonschmeisser authored and rhaschke committed Sep 28, 2019
1 parent 9dcebbe commit d142f81
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/rviz/render_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,18 @@ RenderPanel::RenderPanel( QWidget* parent )
, scene_manager_( 0 )
, view_controller_( 0 )
, context_menu_visible_(false)
//TODO(simonschmeisser) remove this in noetic
, fake_mouse_move_event_timer_( new QTimer() )
, default_camera_(0)
{
setFocusPolicy(Qt::WheelFocus);
setFocus( Qt::OtherFocusReason );
setMouseTracking(true);
}

RenderPanel::~RenderPanel()
{
//TODO(simonschmeisser) remove this in noetic
delete fake_mouse_move_event_timer_;
if( scene_manager_ && default_camera_ )
{
Expand All @@ -89,11 +92,9 @@ void RenderPanel::initialize(Ogre::SceneManager* scene_manager, DisplayContext*
default_camera_->lookAt(0, 0, 0);

setCamera( default_camera_ );

connect( fake_mouse_move_event_timer_, SIGNAL( timeout() ), this, SLOT( sendMouseMoveEvent() ));
fake_mouse_move_event_timer_->start( 33 /*milliseconds*/ );
}

//TODO(simonschmeisser) remove this in noetic
void RenderPanel::sendMouseMoveEvent()
{
QPoint cursor_pos = QCursor::pos();
Expand Down Expand Up @@ -124,6 +125,7 @@ void RenderPanel::sendMouseMoveEvent()
onRenderWindowMouseEvents( &fake_event );
}
}

void RenderPanel::leaveEvent ( QEvent * event )
{
setCursor( Qt::ArrowCursor );
Expand Down
2 changes: 2 additions & 0 deletions src/rviz/render_panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,12 @@ Q_OBJECT
Display* display_;

private Q_SLOTS:
//TODO(simonschmeisser) remove this in noetic
void sendMouseMoveEvent();
void onContextMenuHide();

private:
//TODO(simonschmeisser) remove this in noetic
QTimer* fake_mouse_move_event_timer_;
Ogre::Camera* default_camera_; ///< A default camera created in initialize().
};
Expand Down

0 comments on commit d142f81

Please sign in to comment.