Skip to content

Commit

Permalink
feat: Configurable tool button style kinetic (#1307)
Browse files Browse the repository at this point in the history
* feat: Configurable tool button style

* Clear separation between toolbar actions and static buttons.

Also introduced separator between the toolbar actions and the static
buttons. Clarifies the separation and this way we can keep the button
ordening.

* Added rename todo for separator to maintain the ABI
  • Loading branch information
reinzor authored and chapulina committed Nov 2, 2018
1 parent 87742e4 commit 9114606
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 6 deletions.
56 changes: 50 additions & 6 deletions src/rviz/visualization_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,11 +503,13 @@ void VisualizationFrame::initToolbars()
connect( toolbar_actions_, SIGNAL( triggered( QAction* )), this, SLOT( onToolbarActionTriggered( QAction* )));
view_menu_->addAction( toolbar_->toggleViewAction() );

add_tool_action_ = new QAction( "", toolbar_actions_ );
add_tool_action_->setToolTip( "Add a new tool" );
add_tool_action_->setIcon( loadPixmap( "package://rviz/icons/plus.png" ) );
toolbar_->addAction( add_tool_action_ );
connect( add_tool_action_, SIGNAL( triggered() ), this, SLOT( openNewToolDialog() ));
add_tool_action_ = toolbar_->addSeparator();

QToolButton* add_tool_button = new QToolButton();
add_tool_button->setToolTip( "Add a new tool" );
add_tool_button->setIcon( loadPixmap( "package://rviz/icons/plus.png" ) );
toolbar_->addWidget( add_tool_button );
connect(add_tool_button, SIGNAL(clicked()), this, SLOT(openNewToolDialog()));

remove_tool_menu_ = new QMenu();
QToolButton* remove_tool_button = new QToolButton();
Expand All @@ -518,6 +520,27 @@ void VisualizationFrame::initToolbars()
toolbar_->addWidget( remove_tool_button );
connect( remove_tool_menu_, SIGNAL( triggered( QAction* )), this, SLOT( onToolbarRemoveTool( QAction* )));

QMenu* button_style_menu = new QMenu();
QAction* action_tool_button_icon_only = new QAction( "Icon only", toolbar_actions_ );
action_tool_button_icon_only->setData(Qt::ToolButtonIconOnly);
button_style_menu->addAction(action_tool_button_icon_only);
QAction* action_tool_button_text_only = new QAction( "Text only", toolbar_actions_ );
action_tool_button_text_only->setData(Qt::ToolButtonTextOnly);
button_style_menu->addAction(action_tool_button_text_only);
QAction* action_tool_button_text_beside_icon = new QAction( "Text beside icon", toolbar_actions_ );
action_tool_button_text_beside_icon->setData(Qt::ToolButtonTextBesideIcon);
button_style_menu->addAction(action_tool_button_text_beside_icon);
QAction* action_tool_button_text_under_icon = new QAction( "Text under icon", toolbar_actions_ );
action_tool_button_text_under_icon->setData(Qt::ToolButtonTextUnderIcon);
button_style_menu->addAction(action_tool_button_text_under_icon);

QToolButton* button_style_button = new QToolButton();
button_style_button->setMenu( button_style_menu );
button_style_button->setPopupMode( QToolButton::InstantPopup );
button_style_button->setToolTip( "Set toolbar style" );
button_style_button->setIcon( loadPixmap( "package://rviz/icons/visibility.svg" ) );
toolbar_->addWidget( button_style_button );
connect( button_style_menu, SIGNAL( triggered( QAction* )), this, SLOT( onButtonStyleTool( QAction* )));
}

void VisualizationFrame::hideDockImpl( Qt::DockWidgetArea area, bool hide )
Expand Down Expand Up @@ -790,13 +813,15 @@ void VisualizationFrame::save( Config config )
manager_->save( config.mapMakeChild( "Visualization Manager" ));
savePanels( config.mapMakeChild( "Panels" ));
saveWindowGeometry( config.mapMakeChild( "Window Geometry" ));
saveToolbars( config.mapMakeChild( "Toolbars" ));
}

void VisualizationFrame::load( const Config& config )
{
manager_->load( config.mapGetChild( "Visualization Manager" ));
loadPanels( config.mapGetChild( "Panels" ));
loadWindowGeometry( config.mapGetChild( "Window Geometry" ));
configureToolbars( config.mapGetChild( "Toolbars" ));
}

void VisualizationFrame::loadWindowGeometry( const Config& config )
Expand Down Expand Up @@ -843,6 +868,20 @@ void VisualizationFrame::loadWindowGeometry( const Config& config )
hide_right_dock_button_->setChecked( b );
}

void VisualizationFrame::configureToolbars( const Config& config )
{
int tool_button_style;
if ( config.mapGetInt( "toolButtonStyle", &tool_button_style) )
{
toolbar_->setToolButtonStyle(static_cast<Qt::ToolButtonStyle>(tool_button_style));
}
}

void VisualizationFrame::saveToolbars( Config config )
{
config.mapSetValue( "toolButtonStyle", static_cast<int>(toolbar_->toolButtonStyle()) );
}

void VisualizationFrame::saveWindowGeometry( Config config )
{
config.mapSetValue( "X", x() );
Expand Down Expand Up @@ -1084,7 +1123,7 @@ void VisualizationFrame::addTool( Tool* tool )
action->setIcon( tool->getIcon() );
action->setIconText( tool->getName() );
action->setCheckable( true );
toolbar_->insertAction( add_tool_action_, action );
toolbar_->insertAction(add_tool_action_, action);
action_to_tool_map_[ action ] = tool;
tool_to_action_map_[ tool ] = action;

Expand Down Expand Up @@ -1115,6 +1154,11 @@ void VisualizationFrame::onToolbarRemoveTool( QAction* remove_tool_menu_action )
}
}

void VisualizationFrame::onButtonStyleTool( QAction* button_style_tool_menu_action )
{
toolbar_->setToolButtonStyle(static_cast<Qt::ToolButtonStyle>(button_style_tool_menu_action->data().toInt()));
}

void VisualizationFrame::removeTool( Tool* tool )
{
QAction* action = tool_to_action_map_[ tool ];
Expand Down
11 changes: 11 additions & 0 deletions src/rviz/visualization_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ protected Q_SLOTS:
/** @brief Remove a the tool whose name is given by remove_tool_menu_action->text(). */
void onToolbarRemoveTool( QAction* remove_tool_menu_action );

/** @brief Change the button style of the toolbar */
void onButtonStyleTool( QAction* button_style_tool_menu_action );

/** @brief Looks up the Tool for this action and calls
* VisualizationManager::setCurrentTool(). */
void onToolbarActionTriggered( QAction* action );
Expand Down Expand Up @@ -255,6 +258,7 @@ protected Q_SLOTS:

void initMenus();

/** @brief Sets up the top toolbar with QToolbuttions for adding/deleting tools and modifiying the tool view **/
void initToolbars();

/** @brief Check for unsaved changes, prompt to save config, etc.
Expand All @@ -276,6 +280,12 @@ protected Q_SLOTS:
/** @brief Loads custom panels from the given config node. */
void loadPanels( const Config& config );

/** @brief Applies the user defined toolbar configuration from the given config node **/
void configureToolbars( const Config& config );

/** @brief Saves the user configuration of the toolbar to the config node **/
void saveToolbars( Config config );

/** @brief Saves custom panels to the given config node. */
void savePanels( Config config );

Expand Down Expand Up @@ -343,6 +353,7 @@ protected Q_SLOTS:
};
QList<PanelRecord> custom_panels_;

//! @todo Rename to toolbar_button_separator_ in Noetic
QAction* add_tool_action_;
QMenu* remove_tool_menu_;

Expand Down

0 comments on commit 9114606

Please sign in to comment.