Salome HOME
Release version on WIndows
[modules/shaper.git] / src / XGUI / XGUI_MainMenu.cpp
1 #include "XGUI_MainMenu.h"
2 #include "XGUI_Workbench.h"
3 #include "XGUI_MainWindow.h"
4
5 #include <QLayout>
6 #include <QTabWidget>
7 #include <QLabel>
8 #include <QDockWidget>
9 #include <QEvent>
10
11 XGUI_MainMenu::XGUI_MainMenu(XGUI_MainWindow *parent)
12     : QObject(parent), myDesktop(parent)
13 {
14   parent->setTabPosition(Qt::TopDockWidgetArea, QTabWidget::North);
15   myGeneralPage = addWorkbench(tr("General"));
16   myGeneralPage->parentWidget()->setMaximumWidth(200);
17   myGeneralPage->installEventFilter(this);
18 }
19
20 XGUI_MainMenu::~XGUI_MainMenu(void)
21 {
22 }
23
24 XGUI_Workbench* XGUI_MainMenu::addWorkbench(const QString& theId, const QString& theTitle)
25 {
26   QDockWidget* aDock = new QDockWidget(myDesktop);
27   aDock->setFeatures(QDockWidget::DockWidgetVerticalTitleBar);
28   aDock->setAllowedAreas(Qt::TopDockWidgetArea);
29   QString aTitle = theTitle;
30   if (aTitle.isEmpty()) {
31     aTitle = tr(theId.toLatin1().constData());
32   }
33   aDock->setWindowTitle(aTitle);
34   aDock->setMinimumHeight(30);
35   aDock->setContentsMargins(0, 0, 0, 0);
36
37   XGUI_Workbench* aPage = new XGUI_Workbench(aDock);
38   aPage->setObjectName(theId);
39   aDock->setWidget(aPage);
40
41   myDesktop->addDockWidget(Qt::TopDockWidgetArea, aDock);
42   if (myMenuTabs.length() > 1) {
43     myDesktop->tabifyDockWidget(myMenuTabs.last(), aDock);
44   }
45
46   myMenuTabs.append(aDock);
47   return aPage;
48 }
49
50 /*
51  * Searches for already created workbench with given name.
52  */
53 XGUI_Workbench* XGUI_MainMenu::findWorkbench(const QString& theObjName)
54 {
55   return myDesktop->findChild<XGUI_Workbench*>(theObjName);
56 }
57
58
59 bool XGUI_MainMenu::eventFilter(QObject *theWatched, QEvent *theEvent)
60 {
61   if (theWatched == myGeneralPage) {
62     if (theEvent->type() == QEvent::Show) {
63       myGeneralPage->parentWidget()->setMaximumWidth(16777215);
64       myGeneralPage->removeEventFilter(this);
65     }
66   }
67   return QObject::eventFilter(theWatched, theEvent);
68 }
69
70 XGUI_Command* XGUI_MainMenu::feature(const QString& theId) const
71 {
72   QList<QDockWidget*>::const_iterator aIt;
73   for (aIt = myMenuTabs.constBegin(); aIt != myMenuTabs.constEnd(); ++aIt) {
74     XGUI_Workbench* aWbn = static_cast<XGUI_Workbench*>((*aIt)->widget());
75     XGUI_Command* aCmd = aWbn->feature(theId);
76     if (aCmd)
77       return aCmd;
78   }
79   return 0;
80 }
81
82 QList<XGUI_Command*> XGUI_MainMenu::features() const
83 {
84   QList<XGUI_Command*> aList;
85   QList<QDockWidget*>::const_iterator aIt;
86   for (aIt = myMenuTabs.constBegin(); aIt != myMenuTabs.constEnd(); ++aIt) {
87     XGUI_Workbench* aWbn = static_cast<XGUI_Workbench*>((*aIt)->widget());
88     aList.append(aWbn->features());
89   }
90   return aList;
91 }