From 9c824bbe5b2be03760df2d6ec7047cc9c5bfdd83 Mon Sep 17 00:00:00 2001
From: Andreas Schenk <andreas_schenk@hms.harvard.edu>
Date: Tue, 9 Jul 2013 11:28:12 -0400
Subject: [PATCH] Author: Jeff Lovelace

- Fix for data viewer to use main ost menubar: Data viewer menu (labeled Panels) for the active data viewer window will show in the main menu bar.
- Added foxus proxy for the data viewer and its QMdiSubwindow to ensure that the data viewer panel gets the keyboard focus from the beginning.
---
 modules/gui/src/data_viewer/data_viewer.cc | 52 ++++++++++++++++++++--
 modules/gui/src/data_viewer/data_viewer.hh |  5 ++-
 modules/gui/src/gosty_app.cc               |  1 +
 modules/gui/src/main_window.cc             |  2 +-
 4 files changed, 55 insertions(+), 5 deletions(-)

diff --git a/modules/gui/src/data_viewer/data_viewer.cc b/modules/gui/src/data_viewer/data_viewer.cc
index a13a6d7ab..fec36c81a 100644
--- a/modules/gui/src/data_viewer/data_viewer.cc
+++ b/modules/gui/src/data_viewer/data_viewer.cc
@@ -20,7 +20,7 @@
 
 
 /*
-  Authors: Ansgar Philippsen, Andreas Schenk
+  Authors: Ansgar Philippsen, Andreas Schenk, Jeff Lovelace
 */
 
 #include <cassert>
@@ -35,6 +35,9 @@
 #include <ost/img/alg/norm.hh>   
 #include <ost/gui/dock_widget.hh>
 
+#include <ost/gui/gosty_app.hh>
+#include <ost/gui/perspective.hh>
+
 #include "data_viewer.hh"
 #include "data_viewer_panel.hh"
 #include "overlay_base.hh"
@@ -74,10 +77,13 @@ DataViewer::DataViewer(QWidget* p, const ImageHandle& data, const QString& name)
   connect(ov_manager_gui_,SIGNAL(SettingsChanged()),this,SLOT(UpdateView()));
   setWindowTitle("OpenStructure Data Viewer");
   build(data);
+  setFocusProxy(panel_);
 }
 
 DataViewer::~DataViewer()
 {
+  QMenuBar* mainMenu = ost::gui::GostyApp::Instance()->GetPerspective()->GetMenuBar();
+  mainMenu->removeAction(WindowMenu()->menuAction());
 }
 
 void DataViewer::SetData(const ImageHandle& d)
@@ -304,8 +310,35 @@ void DataViewer::build(const ImageHandle& data)
 
 void DataViewer::build_menu()
 {
-  menuBar()->addMenu(WindowMenu());
-}
+QMenuBar* mainMenu = ost::gui::GostyApp::Instance()->GetPerspective()->GetMenuBar();
+mainMenu->addMenu(WindowMenu());
+}
+
+ void DataViewer::show_current_window_menu(void)
+   {
+   // If the Panel menu for this window is already visible do nothing
+   if (!WindowMenu()->isVisible())
+     {
+     // We need to hide all instances of panels
+     // Get the Main Menu Bar pointer from OST
+     QMenuBar* mainMenu = ost::gui::GostyApp::Instance()->GetPerspective()->GetMenuBar();
+     // Get a list of all the main level menus
+     QList<QAction*> ActionList=mainMenu->actions();
+     // Any menus named panels are hidden
+     for (int i=0;i<ActionList.count();i++)
+       {
+       if (ActionList[i]->text()=="Panels")
+         {
+         if (ActionList[i]->isVisible())
+           {
+           ActionList[i]->setVisible(false);
+           }
+         }
+       }
+     // Show the panel menu for this object
+     WindowMenu()->menuAction()->setVisible(true);
+     }
+   }
 
 bool DataViewer::eventFilter(QObject * object, QEvent *event)
 {
@@ -320,6 +353,19 @@ bool DataViewer::eventFilter(QObject * object, QEvent *event)
         }
       }
       break;
+    case QEvent::FocusIn:
+      {
+        // Show panels menu when data viewer gets focus
+        show_current_window_menu();
+        return true;
+      }
+      break;
+    case QEvent::Show:
+      {
+        // Show panels menu when data viewer gets focus
+        show_current_window_menu();
+        return true;
+      }
     case QEvent::MouseButtonDblClick:
     case QEvent::MouseButtonPress:
     case QEvent::MouseButtonRelease:
diff --git a/modules/gui/src/data_viewer/data_viewer.hh b/modules/gui/src/data_viewer/data_viewer.hh
index 6b056de38..902466a68 100644
--- a/modules/gui/src/data_viewer/data_viewer.hh
+++ b/modules/gui/src/data_viewer/data_viewer.hh
@@ -19,7 +19,7 @@
 //------------------------------------------------------------------------------
 
 /*
-  Authors: Ansgar Philippsen, Andreas Schenk
+  Authors: Ansgar Philippsen, Andreas Schenk, Jeff Lovelace
 */
 
 #ifndef IMG_GUI_DATA_VIEWER_H
@@ -178,6 +178,9 @@ public slots:
 
   void build(const ImageHandle& data);
 
+  void show_current_window_menu(void);
+
+
   void build_menu();
 };
 
diff --git a/modules/gui/src/gosty_app.cc b/modules/gui/src/gosty_app.cc
index 2c1b644ec..66c612e94 100644
--- a/modules/gui/src/gosty_app.cc
+++ b/modules/gui/src/gosty_app.cc
@@ -115,6 +115,7 @@ ost::img::gui::DataViewer* GostyApp::CreateDataViewer(const ost::img::ImageHandl
   QMdiSubWindow* mdi=new QMdiSubWindow(this->GetPerspective()->GetMainArea());
   mdi->setWindowTitle(name);
   mdi->setWidget(viewer);
+  mdi->setFocusProxy(viewer);
   viewer->setAttribute(Qt::WA_DeleteOnClose);
   mdi->setAttribute(Qt::WA_DeleteOnClose);
   viewer->setParent(mdi);
diff --git a/modules/gui/src/main_window.cc b/modules/gui/src/main_window.cc
index 098e7cfab..2ddeea9f7 100644
--- a/modules/gui/src/main_window.cc
+++ b/modules/gui/src/main_window.cc
@@ -31,7 +31,7 @@ namespace ost { namespace gui {
 
 MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags flags):
   QMainWindow(parent,flags),
-  window_menu_(new QMenu("Windows")),
+  window_menu_(new QMenu("Panels")),
   dock_widget_map_()
 {
   connect(window_menu_,SIGNAL(triggered(QAction*)),this,SLOT(OnDockMenu(QAction*)));
-- 
GitLab