diff --git a/src/rviz/default_plugin/camera_display.cpp b/src/rviz/default_plugin/camera_display.cpp index 28b434ec5..e092e196a 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 bd00107d3..5ad297919 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 8e3d60180..88492c191 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 0f82678a0..d6d7e8b90 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 6282d9f93..f6f27c13a 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);