Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[modules/shaper.git] / src / XGUI / XGUI_MainMenu.cpp
index bb7bbd582910f650335e9cfd4ce48615353d3ae2..273e248dfccfc7c9e36e3f5dabdc3b06a89dea5c 100644 (file)
@@ -1,17 +1,38 @@
-#include "XGUI_MainMenu.h"
-#include "XGUI_Workbench.h"
-#include "XGUI_MainWindow.h"
+#include <XGUI_MainMenu.h>
+#include <XGUI_Workbench.h>
+#include <XGUI_MenuGroupPanel.h>
+#include <XGUI_MainWindow.h>
+#include <XGUI_Command.h>
+#include <XGUI_Preferences.h>
+
+#include <SUIT_ResourceMgr.h>
 
 #include <QLayout>
 #include <QTabWidget>
 #include <QLabel>
 #include <QDockWidget>
+#include <QEvent>
+#include <QPushButton>
+#include <QTabBar>
 
 XGUI_MainMenu::XGUI_MainMenu(XGUI_MainWindow *parent)
-    : QObject(parent), myDesktop(parent)
+    : QWidget(parent), myDesktop(parent)
 {
-  parent->setTabPosition(Qt::TopDockWidgetArea, QTabWidget::North);
-  myGeneralPage = addWorkbench(tr("GEN_MENU_TITLE"));
+  myGeneralPage = new XGUI_MenuGroupPanel(this);
+  myGeneralPage->setObjectName("Default");
+  myGeneralPage->parentWidget()->setMaximumWidth(200);
+  myGeneralPage->installEventFilter(this);
+  myGeneralPage->setFrameStyle(QFrame::StyledPanel);
+
+  myMenuTabs = new QTabWidget(this);
+  myMenuTabs->setStyleSheet("QTabBar::tab {height: 24px;} QTabWidget:pane {border: 0px;}");
+  QHBoxLayout* aMainLayout = new QHBoxLayout(this);
+  aMainLayout->addWidget(myGeneralPage);
+  aMainLayout->addWidget(myMenuTabs);
+  aMainLayout->setContentsMargins(0, 2, 2, 0);
+  aMainLayout->setSpacing(2);
+  setLayout(aMainLayout);
+  setFixedHeight(menuHeight());
 }
 
 XGUI_MainMenu::~XGUI_MainMenu(void)
@@ -20,34 +41,105 @@ XGUI_MainMenu::~XGUI_MainMenu(void)
 
 XGUI_Workbench* XGUI_MainMenu::addWorkbench(const QString& theId, const QString& theTitle)
 {
-  QDockWidget* aDock = new QDockWidget(myDesktop);
-  aDock->setFeatures(QDockWidget::DockWidgetVerticalTitleBar);
-  aDock->setAllowedAreas(Qt::TopDockWidgetArea);
   QString aTitle = theTitle;
   if (aTitle.isEmpty()) {
     aTitle = tr(theId.toLatin1().constData());
   }
-  aDock->setWindowTitle(aTitle);
-  aDock->setMinimumHeight(30);
-  aDock->setContentsMargins(0, 0, 0, 0);
-
-  XGUI_Workbench* aPage = new XGUI_Workbench(aDock);
+  XGUI_Workbench* aPage = new XGUI_Workbench(myMenuTabs);
   aPage->setObjectName(theId);
-  aDock->setWidget(aPage);
-
-  myDesktop->addDockWidget(Qt::TopDockWidgetArea, aDock);
-  if (myMenuTabs.length() > 1) {
-    myDesktop->tabifyDockWidget(myMenuTabs.last(), aDock);
-  }
-
-  myMenuTabs.append(aDock);
+  myMenuTabs->addTab(aPage, aTitle);
   return aPage;
 }
 
 /*
  * Searches for already created workbench with given name.
  */
-XGUI_Workbench* XGUI_MainMenu::findWorkbench(const QString& theObjName)
+XGUI_Workbench* XGUI_MainMenu::findWorkbench(const QString& theObjName) const
 {
   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);
+}
+
+void XGUI_MainMenu::insertConsole(QWidget* theConsole)
+{
+  int aConsoleTabId = myMenuTabs->addTab(theConsole, "Console");
+
+  QTabBar* aTabBar = myMenuTabs->findChild<QTabBar*>();
+  QPushButton* aCloseTabButton = new QPushButton();
+  aCloseTabButton->setFixedSize(16, 16);
+  aCloseTabButton->setIcon(QIcon(":pictures/wnd_close.png"));
+  aCloseTabButton->setFlat(true);
+  aTabBar->setTabButton(aConsoleTabId,
+                        QTabBar::RightSide,
+                        aCloseTabButton);
+
+  connect(aCloseTabButton, SIGNAL(clicked()),
+          myDesktop, SLOT(dockPythonConsole()));
+}
+
+void XGUI_MainMenu::removeConsole()
+{
+  const int kLastTab = myMenuTabs->count() - 1;
+  myMenuTabs->removeTab(kLastTab);
+}
+
+XGUI_Command* XGUI_MainMenu::feature(const QString& theId) const
+{
+  XGUI_Command* result;
+  result = myGeneralPage->feature(theId);
+  if (!result) {
+    for (int aTabIdx = 0; aTabIdx < myMenuTabs->count(); ++aTabIdx) {
+      XGUI_Workbench* aWbn = static_cast<XGUI_Workbench*>(myMenuTabs->widget(aTabIdx));
+      result = aWbn->feature(theId);
+      if (result) break;
+    }
+  }
+  return result;
+}
+
+QList<XGUI_Command*> XGUI_MainMenu::features() const
+{
+  QList<XGUI_Command*> aList = myGeneralPage->features();
+  for (int aTabIdx = 0; aTabIdx < myMenuTabs->count(); ++aTabIdx) {
+    XGUI_Workbench* aWbn = static_cast<XGUI_Workbench*>(myMenuTabs->widget(aTabIdx));
+    aList.append(aWbn->features());
+  }
+  return aList;
+}
+
+int XGUI_MainMenu::menuItemSize() const
+{
+  int DEFAULT_ITEM_SIZE = XGUI_Preferences::resourceMgr()->integerValue(
+    XGUI_Preferences::MENU_SECTION, "item_size");
+  return DEFAULT_ITEM_SIZE;
+}
+
+int XGUI_MainMenu::menuHeight() const
+{
+  // Default group has no tabs above --> one extra row
+  int rows = menuItemRowsCount() + 1;
+  const int kMarginsSpacings = 4;
+  return rows * menuItemSize() + kMarginsSpacings;
+}
+
+int XGUI_MainMenu::menuItemRowsCount() const
+{
+  int DEFAULT_ITEM_ROWS_COUNT = XGUI_Preferences::resourceMgr()->integerValue(
+    XGUI_Preferences::MENU_SECTION, "rows_number");
+  return DEFAULT_ITEM_ROWS_COUNT;
+}
+
+void XGUI_MainMenu::updateFromResources()
+{
+}