From 86ab58e06b8d56f4dfde7fb90c16057e353a1227 Mon Sep 17 00:00:00 2001
From: Victor Poughon <victor.poughon@cnes.fr>
Date: Mon, 25 Mar 2019 17:09:59 +0100
Subject: [PATCH] REFAC: add otbQtWrapperMainWindow

---
 .../include/otbWrapperQtWidgetMainWindow.h    | 59 +++++++++++++++++++
 .../QtWidget/include/otbWrapperQtWidgetView.h |  2 -
 Modules/Wrappers/QtWidget/src/CMakeLists.txt  |  2 +
 .../QtWidget/src/otbApplicationLauncherQt.cxx | 53 +++++++----------
 .../src/otbWrapperQtWidgetMainWindow.cxx      | 58 ++++++++++++++++++
 .../QtWidget/src/otbWrapperQtWidgetView.cxx   |  6 +-
 6 files changed, 140 insertions(+), 40 deletions(-)
 create mode 100644 Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetMainWindow.h
 create mode 100644 Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetMainWindow.cxx

diff --git a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetMainWindow.h b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetMainWindow.h
new file mode 100644
index 0000000000..3cfd84e1f9
--- /dev/null
+++ b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetMainWindow.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
+ *
+ * This file is part of Orfeo Toolbox
+ *
+ *     https://www.orfeo-toolbox.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef otbWrapperQtWidgetMainWindow_h
+#define otbWrapperQtWidgetMainWindow_h
+
+#include <QMainWindow>
+#include "OTBQtWidgetExport.h"
+
+#include "otbWrapperApplication.h"
+
+class QAction;
+class QMenu;
+
+namespace otb
+{
+namespace Wrapper
+{
+
+class QtWidgetView;
+
+class OTBQtWidget_EXPORT QtMainWindow : public QMainWindow
+{
+  Q_OBJECT
+
+public:
+  QtMainWindow(Application::Pointer);
+
+public slots:
+  void UnhandledException(QString message);
+
+private:
+  QMenu*   helpMenu;
+  QAction* helpAction;
+
+  QtWidgetView* gui;
+};
+
+} // namespace Wrapper
+} // namespace otb
+
+#endif
diff --git a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetView.h b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetView.h
index 352bc07c24..441684e40d 100644
--- a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetView.h
+++ b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetView.h
@@ -68,8 +68,6 @@ public:
 
   bool IsClosable() const;
 
-public slots:
-
   void UnhandledException(QString message);
 
 signals:
diff --git a/Modules/Wrappers/QtWidget/src/CMakeLists.txt b/Modules/Wrappers/QtWidget/src/CMakeLists.txt
index 961f34dffc..727f90cdf5 100644
--- a/Modules/Wrappers/QtWidget/src/CMakeLists.txt
+++ b/Modules/Wrappers/QtWidget/src/CMakeLists.txt
@@ -23,6 +23,7 @@ set(OTBQtWidget_SRC
   otbWrapperQtWidgetModel.cxx
   otbWrapperQtWidgetParameterLabel.cxx
   otbWrapperQtWidgetView.cxx
+  otbWrapperQtWidgetMainWindow.cxx
   otbWrapperQtWidgetInputProcessXMLParameter.cxx
   otbWrapperQtWidgetIntParameter.cxx
   otbWrapperQtWidgetInputVectorDataListParameter.cxx
@@ -81,6 +82,7 @@ set(OTBQtWidget_MOC_HDR
   ../include/otbWrapperQtWidgetParameterBase.h
   ../include/otbWrapperQtWidgetModel.h
   ../include/otbWrapperQtWidgetView.h
+  ../include/otbWrapperQtWidgetMainWindow.h
   ../include/otbWrapperQtWidgetProgressReport.h
   ../include/otbWrapperQtWidgetListViewParameter.h
   ../include/otbQtFileSelectionWidget.h
diff --git a/Modules/Wrappers/QtWidget/src/otbApplicationLauncherQt.cxx b/Modules/Wrappers/QtWidget/src/otbApplicationLauncherQt.cxx
index f28b9e32a4..12601d0923 100644
--- a/Modules/Wrappers/QtWidget/src/otbApplicationLauncherQt.cxx
+++ b/Modules/Wrappers/QtWidget/src/otbApplicationLauncherQt.cxx
@@ -19,19 +19,22 @@
  */
 
 #include <QtWidgets>
+#include <QTranslator>
+#include <QDesktopServices>
+
 #include "otbConfigurationManager.h"
 #include "otbWrapperApplicationRegistry.h"
-#include "otbWrapperQtWidgetView.h"
 #include "otbWrapperQtWidgetSimpleProgressReport.h"
 #include "otbQtApplication.h"
+#include "otbWrapperQtWidgetMainWindow.h"
 #include "itksys/SystemTools.hxx"
 
 using otb::Wrapper::Application;
 using otb::Wrapper::ApplicationRegistry;
-using otb::Wrapper::QtWidgetView;
-//using otb::Wrapper::QtWidgetProgressReport;
-using otb::Wrapper::QtWidgetSimpleProgressReport;
 using otb::Wrapper::QtApplication;
+using otb::Wrapper::QtMainWindow;
+using otb::Wrapper::QtWidgetSimpleProgressReport;
+using otb::Wrapper::QtWidgetView;
 
 int main(int argc, char* argv[])
 {
@@ -47,33 +50,33 @@ int main(int argc, char* argv[])
   otb::ConfigurationManager::InitOpenMPThreads();
 
   if (argc < 2)
-    {
+  {
     std::cerr << "Usage : " << argv[0] << " module_name [module_path]" << std::endl;
     return EXIT_FAILURE;
-    }
+  }
 
   std::string moduleName = argv[1];
 
   // Get the module path list
   std::list<std::string> modulePathList;
   if (argc > 2)
-    {
+  {
     std::copy(argv + 2, argv + argc, std::back_inserter(modulePathList));
 
     // Load the path in the environment
     std::list<std::string>::const_iterator it = modulePathList.begin();
-    while( it != modulePathList.end() )
-      {
-      ApplicationRegistry::AddApplicationPath( *(it) );
+    while (it != modulePathList.end())
+    {
+      ApplicationRegistry::AddApplicationPath(*(it));
       ++it;
-      }
     }
+  }
 
   // Create module
   Application::Pointer app = ApplicationRegistry::CreateApplication(moduleName);
   if (app.IsNull())
 
-    {
+  {
     std::cerr << "Could not find application " << moduleName << std::endl;
     std::string modulePath = ApplicationRegistry::GetApplicationPath();
     std::cout << "Module search path : " << modulePath << std::endl;
@@ -81,31 +84,15 @@ int main(int argc, char* argv[])
 
     std::cout << "Available applications : " << (list.empty() ? "None" : "") << std::endl;
     for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it)
-      {
+    {
       std::cout << "  " << *it << std::endl;
-      }
-    return EXIT_FAILURE;
     }
+    return EXIT_FAILURE;
+  }
 
-  // MainWidget : that contains the view and any other widget
-  // (progress, logs...)
-  QMainWindow* mainWindow =  new QMainWindow();
-  mainWindow->setWindowIcon(QIcon( ":/otb_small.png" ));
-  mainWindow->setWindowTitle(QString(app->GetDocName()).append(" - ").append(OTB_VERSION_STRING));
-
-  // Create GUI based on module
-  QtWidgetView* gui = new QtWidgetView(app, mainWindow);
-  gui->CreateGui();
-
-  // Connect the View "Quit" signal, to the mainWindow close slot
-  QObject::connect(gui, &QtWidgetView::QuitSignal, mainWindow, &QMainWindow::close);
-
-  QObject::connect(&qtApp, &QtApplication::UnhandledException, gui, &QtWidgetView::UnhandledException);
-
+  QtMainWindow* mainWindow = new otb::Wrapper::QtMainWindow(app);
 
-  // build the main window, central widget is the plugin view, other
-  // are docked widget (progress, logs...)
-  mainWindow->setCentralWidget(gui);
+  QObject::connect(&qtApp, &QtApplication::UnhandledException, mainWindow, &QtMainWindow::UnhandledException);
 
   // Show the main window
   mainWindow->show();
diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetMainWindow.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetMainWindow.cxx
new file mode 100644
index 0000000000..172b67e224
--- /dev/null
+++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetMainWindow.cxx
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
+ *
+ * This file is part of Orfeo Toolbox
+ *
+ *     https://www.orfeo-toolbox.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "otbWrapperQtWidgetMainWindow.h"
+
+#include <QtWidgets>
+#include "otbWrapperQtWidgetView.h"
+
+namespace otb
+{
+namespace Wrapper
+{
+
+QtMainWindow::QtMainWindow(Application::Pointer app)
+{
+  this->setWindowIcon(QIcon(":/otb_small.png"));
+  this->setWindowTitle(QString(app->GetDocName()).append(" - ").append(OTB_VERSION_STRING));
+
+  // Create main application widget
+  gui = new QtWidgetView(app, this);
+  gui->CreateGui();
+  this->setCentralWidget(gui);
+
+  // Connect the View "Quit" signal, to the mainWindow close slot
+  connect(gui, &QtWidgetView::QuitSignal, this, &QMainWindow::close);
+
+  // Setup the help menu
+  QMenu* helpMenu = this->menuBar()->addMenu(tr("&Help"));
+  helpAction      = new QAction(tr("&Documentation"), this);
+  helpAction->setShortcuts(QKeySequence::HelpContents);
+  helpMenu->addAction(helpAction);
+  QObject::connect(helpAction, &QAction::triggered, this, [] { QDesktopServices::openUrl(QUrl("https://www.orfeo-toolbox.org/CookBook/")); });
+}
+
+void QtMainWindow::UnhandledException(QString message)
+{
+  gui->UnhandledException(message);
+}
+
+} // namespace Wrapper
+} // namespace otb
diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetView.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetView.cxx
index 22a49c3be4..6b84fa510c 100644
--- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetView.cxx
+++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetView.cxx
@@ -113,7 +113,7 @@ void QtWidgetView::CreateGui()
   progressReport->SetApplication(m_Model->GetApplication());
 
   QWidget* footer = CreateFooter();
-   
+
   QHBoxLayout *footLayout = new QHBoxLayout;
   footLayout->addWidget(progressReport);
   footLayout->addWidget(footer);
@@ -179,10 +179,6 @@ QWidget* QtWidgetView::CreateFooter()
   // an HLayout with two buttons : Execute and Quit
   QGroupBox *footerGroup = new QGroupBox(this);
   QHBoxLayout *footerLayout = new QHBoxLayout;
- 
-  footerGroup->setFixedHeight(40);
-  footerGroup->setContentsMargins(0, 0, 0, 0);
-  footerLayout->setContentsMargins(5, 5, 5, 5);
 
   m_ExecButton = new QPushButton(footerGroup);
   m_ExecButton->setDefault(true);
-- 
GitLab