From 065d904fa6e258d8559f946409336af36d46f0c7 Mon Sep 17 00:00:00 2001 From: Robert Haschke Date: Wed, 17 Apr 2024 13:13:11 +0200 Subject: [PATCH] Move core functionality into PanelDockWidget --- src/rviz/default_plugin/camera_display.cpp | 2 ++ src/rviz/default_plugin/image_display.cpp | 28 +--------------------- src/rviz/default_plugin/image_display.h | 1 - src/rviz/panel_dock_widget.cpp | 24 +++++++++++++++++++ src/rviz/panel_dock_widget.h | 2 ++ 5 files changed, 29 insertions(+), 28 deletions(-) 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 bd00107d3d..5ad2979198 100644 --- a/src/rviz/default_plugin/image_display.cpp +++ b/src/rviz/default_plugin/image_display.cpp @@ -42,9 +42,6 @@ #include #include -#include -#include - #include #include #include @@ -129,15 +126,7 @@ void ImageDisplay::onInitialize() render_panel_->initialize(img_scene_manager_, context_); setAssociatedWidget(render_panel_); - - // fullscreen button - QToolButton* fullscreen_button = new QToolButton(); - fullscreen_button->setIcon(QIcon::fromTheme("view-fullscreen")); - fullscreen_button->setIconSize(QSize(10, 10)); - fullscreen_button->setToolTip("Toggle fullscreen"); - connect(fullscreen_button, &QToolButton::clicked, this, &ImageDisplay::toggleFullScreen); - dynamic_cast(getAssociatedWidgetPanel()->titleBarWidget()->layout()) - ->insertWidget(2, fullscreen_button); + getAssociatedWidgetPanel()->addMaximizeButton(); render_panel_->setAutoRender(false); render_panel_->setOverlaysEnabled(false); @@ -169,21 +158,6 @@ void ImageDisplay::onDisable() reset(); } -void ImageDisplay::toggleFullScreen() -{ - auto* panel = getAssociatedWidgetPanel(); - if (panel->windowState() & Qt::WindowMaximized) - { - panel->setFloating(false); - panel->showNormal(); - } - else - { - panel->setFloating(true); - panel->showMaximized(); - } -} - void ImageDisplay::updateNormalizeOptions() { if (got_float_image_) diff --git a/src/rviz/default_plugin/image_display.h b/src/rviz/default_plugin/image_display.h index 8e3d601809..88492c191e 100644 --- a/src/rviz/default_plugin/image_display.h +++ b/src/rviz/default_plugin/image_display.h @@ -73,7 +73,6 @@ class ImageDisplay : public ImageDisplayBase public Q_SLOTS: virtual void updateNormalizeOptions(); - virtual void toggleFullScreen(); protected: // overrides from Display diff --git a/src/rviz/panel_dock_widget.cpp b/src/rviz/panel_dock_widget.cpp index 0f82678a03..d6d7e8b90b 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);