Skip to content

Commit

Permalink
add option to disable keyboard focus being set on mouse move (#1174)
Browse files Browse the repository at this point in the history
* add option to disable keyboard focus being set on mouse move

currently all mouse events get forwarded to onRenderWindowMouseEvents,
there keyboard focus is requested (setFocus) unconditionally. This commit
adds a new property "focus_on_mouse_move_" that enables setting keyboard
focus on mouse move events. Setting focus on click or wheel is handled by
QObject::setFocusPolicy

Subclasses/Users of rvis::RenderPanel can disable either setting focus on
mouse move by using the boolean property and disable keyboard focus on click,
on wheel or totally via setFocusPolicy

* use scope brackets on if statement
  • Loading branch information
Simon Schmeisser authored and wjwwood committed May 10, 2018
1 parent 57325fa commit b4e4820
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/rviz/render_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ RenderPanel::RenderPanel( QWidget* parent )
: QtOgreRenderWindow( parent )
, mouse_x_( 0 )
, mouse_y_( 0 )
, focus_on_mouse_move_( true )
, context_( 0 )
, scene_manager_( 0 )
, view_controller_( 0 )
, fake_mouse_move_event_timer_( new QTimer() )
, default_camera_(0)
, context_menu_visible_(false)
{
setFocusPolicy(Qt::WheelFocus);
setFocus( Qt::OtherFocusReason );
}

Expand Down Expand Up @@ -141,7 +143,9 @@ void RenderPanel::onRenderWindowMouseEvents( QMouseEvent* event )

if (context_)
{
setFocus( Qt::MouseFocusReason );
if (focus_on_mouse_move_) {
setFocus( Qt::MouseFocusReason );
}

ViewportMouseEvent vme(this, getViewport(), event, last_x, last_y);
context_->handleMouseEvent(vme);
Expand All @@ -159,8 +163,6 @@ void RenderPanel::wheelEvent( QWheelEvent* event )

if (context_)
{
setFocus( Qt::MouseFocusReason );

ViewportMouseEvent vme(this, getViewport(), event, last_x, last_y);
context_->handleMouseEvent(vme);
event->accept();
Expand Down Expand Up @@ -234,4 +236,14 @@ void RenderPanel::sceneManagerDestroyed( Ogre::SceneManager* destroyed_scene_man
}
}

bool RenderPanel::getFocusOnMouseMove() const
{
return focus_on_mouse_move_;
}

void RenderPanel::setFocusOnMouseMove(bool enabled)
{
focus_on_mouse_move_ = enabled;
}

} // namespace rviz
7 changes: 7 additions & 0 deletions src/rviz/render_panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ Q_OBJECT

virtual void sceneManagerDestroyed( Ogre::SceneManager* source );

/** Return true if moving the mouse within this widget should set keyboard focus */
bool getFocusOnMouseMove() const;

/** Set to true if moving the mouse within this widget should set keyboard focus, default true */
void setFocusOnMouseMove( bool enabled );

protected:
// Override from QWidget
void contextMenuEvent( QContextMenuEvent* event );
Expand All @@ -124,6 +130,7 @@ Q_OBJECT
// Mouse handling
int mouse_x_; ///< X position of the last mouse event
int mouse_y_; ///< Y position of the last mouse event
bool focus_on_mouse_move_; ///< a moving the mouse catches keyboard focus

DisplayContext* context_;
Ogre::SceneManager* scene_manager_;
Expand Down

0 comments on commit b4e4820

Please sign in to comment.