1 #include <XGUI_MainMenu.h>
2 #include <XGUI_Workbench.h>
3 #include <XGUI_MainWindow.h>
4 #include <XGUI_Command.h>
12 XGUI_MainMenu::XGUI_MainMenu(XGUI_MainWindow *parent)
13 : QObject(parent), myDesktop(parent)
15 parent->setTabPosition(Qt::TopDockWidgetArea, QTabWidget::North);
16 myGeneralPage = addWorkbench(tr("General"));
17 myGeneralPage->parentWidget()->setMaximumWidth(200);
18 myGeneralPage->installEventFilter(this);
21 XGUI_MainMenu::~XGUI_MainMenu(void)
25 XGUI_Workbench* XGUI_MainMenu::addWorkbench(const QString& theId, const QString& theTitle)
27 QDockWidget* aDock = new QDockWidget(myDesktop);
28 aDock->setFeatures(QDockWidget::DockWidgetVerticalTitleBar);
29 aDock->setAllowedAreas(Qt::TopDockWidgetArea);
30 QString aTitle = theTitle;
31 if (aTitle.isEmpty()) {
32 aTitle = tr(theId.toLatin1().constData());
34 aDock->setWindowTitle(aTitle);
35 aDock->setMinimumHeight(30);
36 aDock->setContentsMargins(0, 0, 0, 0);
38 XGUI_Workbench* aPage = new XGUI_Workbench(aDock);
39 aPage->setObjectName(theId);
40 aDock->setWidget(aPage);
42 myDesktop->addDockWidget(Qt::TopDockWidgetArea, aDock);
43 if (myMenuTabs.length() > 1) {
44 myDesktop->tabifyDockWidget(myMenuTabs.last(), aDock);
47 myMenuTabs.append(aDock);
52 * Searches for already created workbench with given name.
54 XGUI_Workbench* XGUI_MainMenu::findWorkbench(const QString& theObjName)
56 return myDesktop->findChild<XGUI_Workbench*>(theObjName);
60 bool XGUI_MainMenu::eventFilter(QObject *theWatched, QEvent *theEvent)
62 if (theWatched == myGeneralPage) {
63 if (theEvent->type() == QEvent::Show) {
64 myGeneralPage->parentWidget()->setMaximumWidth(16777215);
65 myGeneralPage->removeEventFilter(this);
68 return QObject::eventFilter(theWatched, theEvent);
71 XGUI_Command* XGUI_MainMenu::feature(const QString& theId) const
73 QList<QDockWidget*>::const_iterator aIt;
74 for (aIt = myMenuTabs.constBegin(); aIt != myMenuTabs.constEnd(); ++aIt) {
75 XGUI_Workbench* aWbn = static_cast<XGUI_Workbench*>((*aIt)->widget());
76 XGUI_Command* aCmd = aWbn->feature(theId);
83 QList<XGUI_Command*> XGUI_MainMenu::features() const
85 QList<XGUI_Command*> aList;
86 QList<QDockWidget*>::const_iterator aIt;
87 for (aIt = myMenuTabs.constBegin(); aIt != myMenuTabs.constEnd(); ++aIt) {
88 XGUI_Workbench* aWbn = static_cast<XGUI_Workbench*>((*aIt)->widget());
89 aList.append(aWbn->features());