Commits

Ian Chen committed ff38b1f Merge

Merged in issue_506 (pull request #298)

Fix native menu bar when switching in and out of building editor

Comments (0)

Files changed (2)

gazebo/gui/MainWindow.cc

     this->renderWidget->ShowEditor(true);
     this->tabWidget->hide();
     this->buildingEditorTabWidget->show();
-    this->menuBar->hide();
-    this->buildingEditorMenuBar->show();
+    this->AttachEditorMenuBar();
   }
   else
   {
     this->renderWidget->ShowEditor(false);
     this->tabWidget->show();
     this->buildingEditorTabWidget->hide();
-    this->buildingEditorMenuBar->hide();
-    this->menuBar->show();
+    this->AttachMainMenuBar();
     this->Play();
   }
 }
 }
 
 /////////////////////////////////////////////////
-void MainWindow::CreateMenus()
+void MainWindow::AttachEditorMenuBar()
 {
-  this->menuLayout = new QHBoxLayout;
+  if (this->menuBar)
+  {
+    delete menuBar;
+  }
 
-  QFrame *frame = new QFrame;
+  this->menuBar = new QMenuBar;
+  this->menuBar->setSizePolicy(QSizePolicy::Fixed,
+      QSizePolicy::Fixed);
+  QMenu *buildingEditorFileMenu = this->menuBar->addMenu(
+      tr("&File"));
+  buildingEditorFileMenu->addAction(g_buildingEditorSaveAct);
+  buildingEditorFileMenu->addAction(g_buildingEditorDiscardAct);
+  buildingEditorFileMenu->addAction(g_buildingEditorDoneAct);
+  buildingEditorFileMenu->addAction(g_buildingEditorExitAct);
+
+  this->menuLayout->addWidget(this->menuBar);
+}
+
+/////////////////////////////////////////////////
+void MainWindow::AttachMainMenuBar()
+{
+  if (this->menuBar)
+  {
+    delete menuBar;
+  }
+
   this->menuBar =  new QMenuBar;
   this->menuBar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
 
-  this->menuLayout->addWidget(this->menuBar);
-  this->menuLayout->addStretch(5);
-  this->menuLayout->setContentsMargins(0, 0, 0, 0);
-
-  frame->setLayout(this->menuLayout);
-  frame->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
-
-  this->setMenuWidget(frame);
-
   QMenu *fileMenu = this->menuBar->addMenu(tr("&File"));
   // fileMenu->addAction(g_openAct);
   // fileMenu->addAction(g_importAct);
   QMenu *helpMenu = this->menuBar->addMenu(tr("&Help"));
   helpMenu->addAction(g_aboutAct);
 
-  this->buildingEditorMenuBar = new QMenuBar;
-  this->buildingEditorMenuBar->setSizePolicy(QSizePolicy::Fixed,
-      QSizePolicy::Fixed);
-  this->menuLayout->insertWidget(0, this->buildingEditorMenuBar);
-  this->buildingEditorMenuBar->hide();
+  this->menuLayout->addWidget(this->menuBar);
+}
 
-  QMenu *buildingEditorFileMenu = this->buildingEditorMenuBar->addMenu(
-      tr("&File"));
-  buildingEditorFileMenu->addAction(g_buildingEditorSaveAct);
-  buildingEditorFileMenu->addAction(g_buildingEditorDiscardAct);
-  buildingEditorFileMenu->addAction(g_buildingEditorDoneAct);
-  buildingEditorFileMenu->addAction(g_buildingEditorExitAct);
+/////////////////////////////////////////////////
+void MainWindow::CreateMenus()
+{
+  this->menuLayout = new QHBoxLayout;
+
+  QFrame *frame = new QFrame;
+
+  this->AttachMainMenuBar();
+
+  this->menuLayout->addStretch(5);
+  this->menuLayout->setContentsMargins(0, 0, 0, 0);
+
+  frame->setLayout(this->menuLayout);
+  frame->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
+
+  this->setMenuWidget(frame);
 }
 
 /////////////////////////////////////////////////

gazebo/gui/MainWindow.hh

       private: void CreateMenus();
       private: void CreateToolbars();
 
+      /// \brief Attach Gazebo's main menu bar
+      private: void AttachMainMenuBar();
+
+      /// \brief Attach building editor's menu bar
+      private: void AttachEditorMenuBar();
+
       private: void OnModel(ConstModelPtr &_msg);
       private: void OnResponse(ConstResponsePtr &_msg);
       private: void OnWorldModify(ConstWorldModifyPtr &_msg);
       /// \brief Tab widget that holds the building editor palette
       private: QTabWidget *buildingEditorTabWidget;
 
-      /// \brief Building editor's own separate menu bar of actions, e.g. save.
-      private: QMenuBar *buildingEditorMenuBar;
-
       private: QTabWidget *tabWidget;
       private: QMenuBar *menuBar;