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

feat: Configurable tool button style melodic #1309

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
56 changes: 50 additions & 6 deletions src/rviz/visualization_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,11 +507,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 @@ -522,6 +524,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 @@ -809,6 +832,7 @@ void VisualizationFrame::save( Config config )
savePanels( config.mapMakeChild( "Panels" ));
saveWindowGeometry( config.mapMakeChild( "Window Geometry" ));
savePreferences( config.mapMakeChild( "Preferences" ));
saveToolbars( config.mapMakeChild( "Toolbars" ));
}

void VisualizationFrame::load( const Config& config )
Expand All @@ -817,6 +841,7 @@ void VisualizationFrame::load( const Config& config )
loadPanels( config.mapGetChild( "Panels" ));
loadWindowGeometry( config.mapGetChild( "Window Geometry" ));
loadPreferences( config.mapGetChild( "Preferences" ));
configureToolbars( config.mapGetChild( "Toolbars" ));
}

void VisualizationFrame::loadWindowGeometry( const Config& config )
Expand Down Expand Up @@ -863,6 +888,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 @@ -1114,7 +1153,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 @@ -1145,6 +1184,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 @@ -191,6 +191,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 @@ -259,6 +262,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 @@ -280,6 +284,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 @@ -352,6 +362,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