From 72f8270742db65f796dc6fe5893b7ca9075382d2 Mon Sep 17 00:00:00 2001 From: Maarten de Vries Date: Mon, 1 May 2017 21:45:32 +0200 Subject: [PATCH] Add fullscreen option. (#1017) --- src/rviz/panel_dock_widget.cpp | 16 ++++++++++++++-- src/rviz/panel_dock_widget.h | 8 ++++++++ src/rviz/visualization_frame.cpp | 31 +++++++++++++++++++++++++++++++ src/rviz/visualization_frame.h | 13 ++++++++++++- 4 files changed, 65 insertions(+), 3 deletions(-) diff --git a/src/rviz/panel_dock_widget.cpp b/src/rviz/panel_dock_widget.cpp index 363cf07cf3..e064f65ce1 100644 --- a/src/rviz/panel_dock_widget.cpp +++ b/src/rviz/panel_dock_widget.cpp @@ -100,13 +100,13 @@ void PanelDockWidget::setCollapsed( bool collapse ) { if ( isVisible() ) { - QDockWidget::setVisible( false ); + PanelDockWidget::setVisible( false ); collapsed_ = collapse; } } else { - QDockWidget::setVisible( true ); + PanelDockWidget::setVisible( true ); collapsed_ = collapse; } } @@ -144,4 +144,16 @@ void PanelDockWidget::load( Config config ) config.mapGetBool( "collapsed", &collapsed_ ); } +void PanelDockWidget::setVisible( bool visible ) +{ + requested_visibility_ = visible; + QDockWidget::setVisible(requested_visibility_ && !forced_hidden_); +} + +void PanelDockWidget::overrideVisibility( bool hidden ) +{ + forced_hidden_ = hidden; + setVisible(requested_visibility_); +} + } // end namespace rviz diff --git a/src/rviz/panel_dock_widget.h b/src/rviz/panel_dock_widget.h index 2c7a8cabd6..5888f6d4e3 100644 --- a/src/rviz/panel_dock_widget.h +++ b/src/rviz/panel_dock_widget.h @@ -58,6 +58,9 @@ Q_OBJECT virtual void save( Config config ); virtual void load( Config config ); + /** @brief Override setVisible to respect the visibility override, */ + virtual void setVisible( bool visible ); + protected: virtual void closeEvent ( QCloseEvent * event ); @@ -66,6 +69,9 @@ public Q_SLOTS: void setWindowTitle( QString title ); + /** @ Override the visibility of the widget. **/ + virtual void overrideVisibility( bool hide ); + private Q_SLOTS: void onChildDestroyed( QObject* ); @@ -76,6 +82,8 @@ private Q_SLOTS: private: // set to true if this panel was collapsed bool collapsed_; + bool requested_visibility_; + bool forced_hidden_; QLabel *icon_label_; QLabel *title_label_; }; diff --git a/src/rviz/visualization_frame.cpp b/src/rviz/visualization_frame.cpp index 10c7e3b59c..2ac6aa794e 100644 --- a/src/rviz/visualization_frame.cpp +++ b/src/rviz/visualization_frame.cpp @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -463,6 +464,12 @@ void VisualizationFrame::initMenus() view_menu_->addAction( "Add &New Panel", this, SLOT( openNewPanelDialog() )); delete_view_menu_ = view_menu_->addMenu( "&Delete Panel" ); delete_view_menu_->setEnabled( false ); + + QAction * fullscreen_action = view_menu_->addAction("&Fullscreen", this, SLOT( setFullScreen(bool) ), Qt::Key_F11); + fullscreen_action->setCheckable(true); + this->addAction(fullscreen_action); // Also add to window, or the shortcut doest work when the menu is hidden. + connect(this, SIGNAL( fullScreenChange( bool ) ), fullscreen_action, SLOT( setChecked( bool ) ) ); + new QShortcut(Qt::Key_Escape, this, SLOT( exitFullScreen() )); view_menu_->addSeparator(); QMenu* help_menu = menuBar()->addMenu( "&Help" ); @@ -1211,6 +1218,29 @@ void VisualizationFrame::onDeletePanel() } } +void VisualizationFrame::setFullScreen( bool full_screen ) +{ + Q_EMIT( fullScreenChange( full_screen ) ); + + if (full_screen) + toolbar_visible_ = toolbar_->isVisible(); + menuBar()->setVisible(!full_screen); + toolbar_->setVisible(!full_screen && toolbar_visible_); + statusBar()->setVisible(!full_screen); + setHideButtonVisibility(!full_screen); + + if (full_screen) + setWindowState(windowState() | Qt::WindowFullScreen); + else + setWindowState(windowState() & ~Qt::WindowFullScreen); + show(); +} + +void VisualizationFrame::exitFullScreen() +{ + setFullScreen( false ); +} + QDockWidget* VisualizationFrame::addPanelByName( const QString& name, const QString& class_id, Qt::DockWidgetArea area, @@ -1251,6 +1281,7 @@ PanelDockWidget* VisualizationFrame::addPane( const QString& name, QWidget* pane // we want to know when that panel becomes visible connect( dock, SIGNAL( visibilityChanged( bool )), this, SLOT( onDockPanelVisibilityChange( bool ) )); + connect( this, SIGNAL( fullScreenChange(bool) ), dock, SLOT( overrideVisibility(bool) )); QAction* toggle_action = dock->toggleViewAction(); view_menu_->addAction( toggle_action ); diff --git a/src/rviz/visualization_frame.h b/src/rviz/visualization_frame.h index 265a3e001d..286debabdf 100644 --- a/src/rviz/visualization_frame.h +++ b/src/rviz/visualization_frame.h @@ -168,6 +168,9 @@ public Q_SLOTS: /** @brief Emitted during file-loading and initialization to indicate progress. */ void statusUpdate( const QString& message ); + /** @brief Emitted when the interface enters or leaves full screen mode. */ + void fullScreenChange( bool hidden ); + protected Q_SLOTS: void onOpen(); void onSave(); @@ -219,6 +222,12 @@ protected Q_SLOTS: * the name of the panel. */ void onDeletePanel(); + /** @brief Set full screen mode. */ + void setFullScreen( bool full_screen ); + + /** @brief Exit full screen mode. */ + void exitFullScreen(); + protected Q_SLOTS: /** @brief Set loading_ to false. */ void markLoadingDone(); @@ -299,7 +308,6 @@ protected Q_SLOTS: QMenu* view_menu_; QMenu* delete_view_menu_; QMenu* plugins_menu_; - QList view_menu_actions_; QToolBar* toolbar_; @@ -350,6 +358,9 @@ protected Q_SLOTS: ros::WallTime last_fps_calc_time_; QString error_message_; ///< Error message (if any) from most recent saveDisplayConfig() call. + + /// Indicates if the toolbar should be visible outside of fullscreen mode. + bool toolbar_visible_; }; }