From 6ca7e79215e60ca8d27f2a707a721a9b1ae40b6f Mon Sep 17 00:00:00 2001 From: Robert Haschke Date: Wed, 17 Apr 2024 13:36:55 +0200 Subject: [PATCH] Add maximize button to Image and Camera display (#1803) --- src/rviz/default_plugin/camera_display.cpp | 2 ++ src/rviz/default_plugin/image_display.cpp | 2 ++ src/rviz/panel_dock_widget.cpp | 24 ++++++++++++++++++++++ src/rviz/panel_dock_widget.h | 2 ++ 4 files changed, 30 insertions(+) diff --git a/src/rviz/default_plugin/camera_display.cpp b/src/rviz/default_plugin/camera_display.cpp index 28b434ec51..e092e196aa 100644 --- a/src/rviz/default_plugin/camera_display.cpp +++ b/src/rviz/default_plugin/camera_display.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include @@ -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); diff --git a/src/rviz/default_plugin/image_display.cpp b/src/rviz/default_plugin/image_display.cpp index 8efe0e1719..8cf5b1fe0a 100644 --- a/src/rviz/default_plugin/image_display.cpp +++ b/src/rviz/default_plugin/image_display.cpp @@ -44,6 +44,7 @@ #include #include +#include #include #include #include @@ -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); diff --git a/src/rviz/panel_dock_widget.cpp b/src/rviz/panel_dock_widget.cpp index 82fb8352d0..f166262fea 100644 --- a/src/rviz/panel_dock_widget.cpp +++ b/src/rviz/panel_dock_widget.cpp @@ -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(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(); diff --git a/src/rviz/panel_dock_widget.h b/src/rviz/panel_dock_widget.h index 6282d9f93f..f6f27c13a9 100644 --- a/src/rviz/panel_dock_widget.h +++ b/src/rviz/panel_dock_widget.h @@ -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); @@ -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);