1 #include <XGUI_MainMenu.h>
2 #include <XGUI_Workbench.h>
3 #include <XGUI_MenuGroupPanel.h>
4 #include <XGUI_MainWindow.h>
5 #include <XGUI_Command.h>
10 #include <QDockWidget>
12 #include <QPushButton>
15 XGUI_MainMenu::XGUI_MainMenu(XGUI_MainWindow *parent)
16 : QWidget(parent), myDesktop(parent)
18 myGeneralPage = new XGUI_MenuGroupPanel(this);
19 myGeneralPage->setObjectName("Default");
20 myGeneralPage->parentWidget()->setMaximumWidth(200);
21 myGeneralPage->installEventFilter(this);
22 myGeneralPage->setFrameStyle(QFrame::StyledPanel);
24 myMenuTabs = new QTabWidget(this);
25 myMenuTabs->setStyleSheet("QTabBar::tab {height: 24px;} QTabWidget:pane {border: 0px;}");
26 QHBoxLayout* aMainLayout = new QHBoxLayout(this);
27 aMainLayout->addWidget(myGeneralPage);
28 aMainLayout->addWidget(myMenuTabs);
29 aMainLayout->setContentsMargins(0, 2, 2, 0);
30 aMainLayout->setSpacing(2);
31 setLayout(aMainLayout);
32 setFixedHeight(menuHeight());
35 XGUI_MainMenu::~XGUI_MainMenu(void)
39 XGUI_Workbench* XGUI_MainMenu::addWorkbench(const QString& theId, const QString& theTitle)
41 QString aTitle = theTitle;
42 if (aTitle.isEmpty()) {
43 aTitle = tr(theId.toLatin1().constData());
45 XGUI_Workbench* aPage = new XGUI_Workbench(myMenuTabs);
46 aPage->setObjectName(theId);
47 myMenuTabs->addTab(aPage, aTitle);
52 * Searches for already created workbench with given name.
54 XGUI_Workbench* XGUI_MainMenu::findWorkbench(const QString& theObjName) const
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 void XGUI_MainMenu::insertConsole(QWidget* theConsole)
73 int aConsoleTabId = myMenuTabs->addTab(theConsole, "Console");
75 QTabBar* aTabBar = myMenuTabs->findChild<QTabBar*>();
76 QPushButton* aCloseTabButton = new QPushButton();
77 aCloseTabButton->setFixedSize(16, 16);
78 aCloseTabButton->setIcon(QIcon(":pictures/wnd_close.png"));
79 aCloseTabButton->setFlat(true);
80 aTabBar->setTabButton(aConsoleTabId,
84 connect(aCloseTabButton, SIGNAL(clicked()),
85 myDesktop, SLOT(dockPythonConsole()));
88 void XGUI_MainMenu::removeConsole()
90 const int kLastTab = myMenuTabs->count() - 1;
91 myMenuTabs->removeTab(kLastTab);
94 XGUI_Command* XGUI_MainMenu::feature(const QString& theId) const
97 result = myGeneralPage->feature(theId);
99 for (int aTabIdx = 0; aTabIdx < myMenuTabs->count(); ++aTabIdx) {
100 XGUI_Workbench* aWbn = static_cast<XGUI_Workbench*>(myMenuTabs->widget(aTabIdx));
101 result = aWbn->feature(theId);
108 QList<XGUI_Command*> XGUI_MainMenu::features() const
110 QList<XGUI_Command*> aList = myGeneralPage->features();
111 for (int aTabIdx = 0; aTabIdx < myMenuTabs->count(); ++aTabIdx) {
112 XGUI_Workbench* aWbn = static_cast<XGUI_Workbench*>(myMenuTabs->widget(aTabIdx));
113 aList.append(aWbn->features());
118 QList<XGUI_Workbench*> XGUI_MainMenu::workbenches() const
120 QList<XGUI_Workbench*> aList;
121 for (int aTabIdx = 0; aTabIdx < myMenuTabs->count(); ++aTabIdx) {
122 XGUI_Workbench* aWb = dynamic_cast<XGUI_Workbench*>(myMenuTabs->widget(aTabIdx));
130 int XGUI_MainMenu::menuItemSize() const
132 //TODO(sbh, vsv): get this value from the preferences
133 static const ItemSize DEFAULT_ITEM_SIZE = Medium;
134 return (int) DEFAULT_ITEM_SIZE;
137 int XGUI_MainMenu::menuHeight() const
139 // Default group has no tabs above --> one extra row
140 int rows = menuItemRowsCount() + 1;
141 const int kMarginsSpacings = 4;
142 return rows * menuItemSize() + kMarginsSpacings;
145 int XGUI_MainMenu::menuItemRowsCount() const
147 //TODO(sbh, vsv): get this value from the preferences
148 static const int DEFAULT_ITEM_ROWS_COUNT = 3;
149 return DEFAULT_ITEM_ROWS_COUNT;