Skip to content

Commit

Permalink
Add maximize button to Image and Camera display (ros-visualization#1803)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhaschke authored Apr 17, 2024
1 parent 02ea03e commit 6ca7e79
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/rviz/default_plugin/camera_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include <rviz/properties/float_property.h>
#include <rviz/properties/int_property.h>
#include <rviz/properties/ros_topic_property.h>
#include <rviz/panel_dock_widget.h>
#include <rviz/render_panel.h>
#include <rviz/uniform_string_stream.h>
#include <rviz/validate_floats.h>
Expand Down Expand Up @@ -192,6 +193,7 @@ void CameraDisplay::onInitialize()
render_panel_->initialize(context_->getSceneManager(), context_);

setAssociatedWidget(render_panel_);
getAssociatedWidgetPanel()->addMaximizeButton();

render_panel_->setAutoRender(false);
render_panel_->setOverlaysEnabled(false);
Expand Down
2 changes: 2 additions & 0 deletions src/rviz/default_plugin/image_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

#include <rviz/display_context.h>
#include <rviz/frame_manager.h>
#include <rviz/panel_dock_widget.h>
#include <rviz/ogre_helpers/compatibility.h>
#include <rviz/render_panel.h>
#include <rviz/validate_floats.h>
Expand Down Expand Up @@ -130,6 +131,7 @@ void ImageDisplay::onInitialize()
render_panel_->initialize(img_scene_manager_, context_);

setAssociatedWidget(render_panel_);
getAssociatedWidgetPanel()->addMaximizeButton();

render_panel_->setAutoRender(false);
render_panel_->setOverlaysEnabled(false);
Expand Down
24 changes: 24 additions & 0 deletions src/rviz/panel_dock_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,30 @@ void PanelDockWidget::setContentWidget(QWidget* child)
}
}

void PanelDockWidget::addMaximizeButton()
{
QToolButton* button = new QToolButton();
button->setIcon(QIcon::fromTheme("view-fullscreen"));
button->setIconSize(QSize(10, 10));
button->setToolTip("Toggle maximize");
connect(button, &QToolButton::clicked, this, &PanelDockWidget::toggleMaximized);
dynamic_cast<QHBoxLayout*>(titleBarWidget()->layout())->insertWidget(2, button);
}

void PanelDockWidget::toggleMaximized()
{
if (windowState() & Qt::WindowMaximized)
{
setFloating(false);
showNormal();
}
else
{
setFloating(true);
showMaximized();
}
}

void PanelDockWidget::closeEvent(QCloseEvent* /*event*/)
{
Q_EMIT closed();
Expand Down
2 changes: 2 additions & 0 deletions src/rviz/panel_dock_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class RVIZ_EXPORT PanelDockWidget : public QDockWidget
void setCollapsed(bool collapsed);

void setIcon(const QIcon& icon);
void addMaximizeButton();

virtual void save(Config config);
virtual void load(const Config& config);
Expand All @@ -67,6 +68,7 @@ class RVIZ_EXPORT PanelDockWidget : public QDockWidget
public Q_SLOTS:

void setWindowTitle(const QString& title);
void toggleMaximized();

/** @ Override the visibility of the widget. **/
virtual void overrideVisibility(bool hide);
Expand Down

0 comments on commit 6ca7e79

Please sign in to comment.