Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[modules/shaper.git] / src / XGUI / XGUI_MainMenu.cpp
index bb7bbd582910f650335e9cfd4ce48615353d3ae2..96106a9111357da303ce4d14993cd204893aa057 100644 (file)
@@ -1,17 +1,21 @@
-#include "XGUI_MainMenu.h"
-#include "XGUI_Workbench.h"
-#include "XGUI_MainWindow.h"
+#include <XGUI_MainMenu.h>
+#include <XGUI_Workbench.h>
+#include <XGUI_MainWindow.h>
+#include <XGUI_Command.h>
 
 #include <QLayout>
 #include <QTabWidget>
 #include <QLabel>
 #include <QDockWidget>
+#include <QEvent>
 
 XGUI_MainMenu::XGUI_MainMenu(XGUI_MainWindow *parent)
     : QObject(parent), myDesktop(parent)
 {
   parent->setTabPosition(Qt::TopDockWidgetArea, QTabWidget::North);
-  myGeneralPage = addWorkbench(tr("GEN_MENU_TITLE"));
+  myGeneralPage = addWorkbench(tr("General"));
+  myGeneralPage->parentWidget()->setMaximumWidth(200);
+  myGeneralPage->installEventFilter(this);
 }
 
 XGUI_MainMenu::~XGUI_MainMenu(void)
@@ -51,3 +55,84 @@ XGUI_Workbench* XGUI_MainMenu::findWorkbench(const QString& theObjName)
 {
   return myDesktop->findChild<XGUI_Workbench*>(theObjName);
 }
+
+
+bool XGUI_MainMenu::eventFilter(QObject *theWatched, QEvent *theEvent)
+{
+  if (theWatched == myGeneralPage) {
+    if (theEvent->type() == QEvent::Show) {
+      myGeneralPage->parentWidget()->setMaximumWidth(16777215);
+      myGeneralPage->removeEventFilter(this);
+    }
+  }
+  return QObject::eventFilter(theWatched, theEvent);
+}
+
+XGUI_Command* XGUI_MainMenu::feature(const QString& theId) const
+{
+  QList<QDockWidget*>::const_iterator aIt;
+  for (aIt = myMenuTabs.constBegin(); aIt != myMenuTabs.constEnd(); ++aIt) {
+    XGUI_Workbench* aWbn = static_cast<XGUI_Workbench*>((*aIt)->widget());
+    XGUI_Command* aCmd = aWbn->feature(theId);
+    if (aCmd)
+      return aCmd;
+  }
+  return 0;
+}
+
+QList<XGUI_Command*> XGUI_MainMenu::features() const
+{
+  QList<XGUI_Command*> aList;
+  QList<QDockWidget*>::const_iterator aIt;
+  for (aIt = myMenuTabs.constBegin(); aIt != myMenuTabs.constEnd(); ++aIt) {
+    XGUI_Workbench* aWbn = static_cast<XGUI_Workbench*>((*aIt)->widget());
+    aList.append(aWbn->features());
+  }
+  return aList;
+}
+
+void XGUI_MainMenu::onFeatureChecked(bool isChecked)
+{
+  if (!isChecked) {
+    restoreCommandState();
+    return;
+  }
+
+  saveCommandsState();
+  QStringList aSkippedIds;
+  XGUI_Command* aToggledFeature = dynamic_cast<XGUI_Command*>(sender());
+  aSkippedIds.append(aToggledFeature->unblockableCommands());
+//  aSkippedIds.append(aToggledFeature->id());
+  XGUI_Workbench* aGeneralWB = findWorkbench(tr("General"));
+  foreach(XGUI_Command* eachFeature, aGeneralWB->features()) {
+    aSkippedIds.append(eachFeature->id());
+  }
+  QList<XGUI_Command*> allFeatures = features();
+  foreach(XGUI_Command* eachFeature, allFeatures) {
+    QString aFeatureId = eachFeature->id();
+    if (aSkippedIds.removeAll(aFeatureId) > 0) {
+      continue;
+    }
+    eachFeature->setEnabled(false);
+  }
+}
+
+void XGUI_MainMenu::saveCommandsState()
+{
+  myCommandState.clear();
+  QList<XGUI_Command*> allFeatures = features();
+  XGUI_Command* eachFeature = NULL;
+  foreach(eachFeature, allFeatures) {
+    myCommandState.insert(eachFeature, eachFeature->enabled());
+  }
+}
+
+void XGUI_MainMenu::restoreCommandState()
+{
+  QList<XGUI_Command*> allFeatures = features();
+  XGUI_Command* eachFeature = NULL;
+  foreach(eachFeature, allFeatures) {
+    eachFeature->setChecked(false);
+    eachFeature->setEnabled(myCommandState[eachFeature]);
+  }
+}