1 #include "XGUI_MainMenu.h"
2 #include "XGUI_Workbench.h"
3 #include "XGUI_MainWindow.h"
11 XGUI_MainMenu::XGUI_MainMenu(XGUI_MainWindow *parent)
12 : QObject(parent), myDesktop(parent)
14 parent->setTabPosition(Qt::TopDockWidgetArea, QTabWidget::North);
15 myGeneralPage = addWorkbench(tr("General"));
16 myGeneralPage->parentWidget()->setMaximumWidth(200);
17 myGeneralPage->installEventFilter(this);
20 XGUI_MainMenu::~XGUI_MainMenu(void)
24 XGUI_Workbench* XGUI_MainMenu::addWorkbench(const QString& theId, const QString& theTitle)
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());
33 aDock->setWindowTitle(aTitle);
34 aDock->setMinimumHeight(30);
35 aDock->setContentsMargins(0, 0, 0, 0);
37 XGUI_Workbench* aPage = new XGUI_Workbench(aDock);
38 aPage->setObjectName(theId);
39 aDock->setWidget(aPage);
41 myDesktop->addDockWidget(Qt::TopDockWidgetArea, aDock);
42 if (myMenuTabs.length() > 1) {
43 myDesktop->tabifyDockWidget(myMenuTabs.last(), aDock);
46 myMenuTabs.append(aDock);
51 * Searches for already created workbench with given name.
53 XGUI_Workbench* XGUI_MainMenu::findWorkbench(const QString& theObjName)
55 return myDesktop->findChild<XGUI_Workbench*>(theObjName);
59 bool XGUI_MainMenu::eventFilter(QObject *theWatched, QEvent *theEvent)
61 if (theWatched == myGeneralPage) {
62 if (theEvent->type() == QEvent::Show) {
63 myGeneralPage->parentWidget()->setMaximumWidth(16777215);
64 myGeneralPage->removeEventFilter(this);
67 return QObject::eventFilter(theWatched, theEvent);
70 XGUI_Command* XGUI_MainMenu::feature(const QString& theId) const
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);
82 QList<XGUI_Command*> XGUI_MainMenu::features() const
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());