Skip to content

Commit

Permalink
Move core functionality into PanelDockWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
rhaschke committed Apr 17, 2024
1 parent 6d4b8e7 commit 065d904
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 28 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
28 changes: 1 addition & 27 deletions src/rviz/default_plugin/image_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@
#include <OgreTechnique.h>
#include <OgreCamera.h>

#include <QToolButton>
#include <QHBoxLayout>

#include <rviz/display_context.h>
#include <rviz/frame_manager.h>
#include <rviz/panel_dock_widget.h>
Expand Down Expand Up @@ -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<QHBoxLayout*>(getAssociatedWidgetPanel()->titleBarWidget()->layout())
->insertWidget(2, fullscreen_button);
getAssociatedWidgetPanel()->addMaximizeButton();

render_panel_->setAutoRender(false);
render_panel_->setOverlaysEnabled(false);
Expand Down Expand Up @@ -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_)
Expand Down
1 change: 0 additions & 1 deletion src/rviz/default_plugin/image_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class ImageDisplay : public ImageDisplayBase

public Q_SLOTS:
virtual void updateNormalizeOptions();
virtual void toggleFullScreen();

protected:
// overrides from Display
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 065d904

Please sign in to comment.