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>
6 #include <XGUI_Preferences.h>
8 #include <SUIT_ResourceMgr.h>
13 #include <QDockWidget>
15 #include <QPushButton>
18 XGUI_MainMenu::XGUI_MainMenu(XGUI_MainWindow *parent)
19 : QWidget(parent), myDesktop(parent)
21 myGeneralPage = new XGUI_MenuGroupPanel(this);
22 myGeneralPage->setObjectName("Default");
23 myGeneralPage->parentWidget()->setMaximumWidth(200);
24 myGeneralPage->installEventFilter(this);
25 myGeneralPage->setFrameStyle(QFrame::StyledPanel);
27 myMenuTabs = new QTabWidget(this);
28 myMenuTabs->setStyleSheet("QTabBar::tab {height: 24px;} QTabWidget:pane {border: 0px;}");
29 QHBoxLayout* aMainLayout = new QHBoxLayout(this);
30 aMainLayout->addWidget(myGeneralPage);
31 aMainLayout->addWidget(myMenuTabs);
32 aMainLayout->setContentsMargins(0, 2, 2, 0);
33 aMainLayout->setSpacing(2);
34 setLayout(aMainLayout);
35 setFixedHeight(menuHeight());
38 XGUI_MainMenu::~XGUI_MainMenu(void)
42 XGUI_Workbench* XGUI_MainMenu::addWorkbench(const QString& theId, const QString& theTitle)
44 QString aTitle = theTitle;
45 if (aTitle.isEmpty()) {
46 aTitle = tr(theId.toLatin1().constData());
48 XGUI_Workbench* aPage = new XGUI_Workbench(myMenuTabs);
49 aPage->setObjectName(theId);
50 myMenuTabs->addTab(aPage, aTitle);
55 * Searches for already created workbench with given name.
57 XGUI_Workbench* XGUI_MainMenu::findWorkbench(const QString& theObjName) const
59 return myDesktop->findChild<XGUI_Workbench*>(theObjName);
63 bool XGUI_MainMenu::eventFilter(QObject *theWatched, QEvent *theEvent)
65 if (theWatched == myGeneralPage) {
66 if (theEvent->type() == QEvent::Show) {
67 myGeneralPage->parentWidget()->setMaximumWidth(16777215);
68 myGeneralPage->removeEventFilter(this);
71 return QObject::eventFilter(theWatched, theEvent);
74 void XGUI_MainMenu::insertConsole(QWidget* theConsole)
76 int aConsoleTabId = myMenuTabs->addTab(theConsole, "Console");
78 QTabBar* aTabBar = myMenuTabs->findChild<QTabBar*>();
79 QPushButton* aCloseTabButton = new QPushButton();
80 aCloseTabButton->setFixedSize(16, 16);
81 aCloseTabButton->setIcon(QIcon(":pictures/wnd_close.png"));
82 aCloseTabButton->setFlat(true);
83 aTabBar->setTabButton(aConsoleTabId,
87 connect(aCloseTabButton, SIGNAL(clicked()),
88 myDesktop, SLOT(dockPythonConsole()));
91 void XGUI_MainMenu::removeConsole()
93 const int kLastTab = myMenuTabs->count() - 1;
94 myMenuTabs->removeTab(kLastTab);
97 XGUI_Command* XGUI_MainMenu::feature(const QString& theId) const
100 result = myGeneralPage->feature(theId);
102 for (int aTabIdx = 0; aTabIdx < myMenuTabs->count(); ++aTabIdx) {
103 XGUI_Workbench* aWbn = static_cast<XGUI_Workbench*>(myMenuTabs->widget(aTabIdx));
104 result = aWbn->feature(theId);
111 QList<XGUI_Command*> XGUI_MainMenu::features() const
113 QList<XGUI_Command*> aList = myGeneralPage->features();
114 for (int aTabIdx = 0; aTabIdx < myMenuTabs->count(); ++aTabIdx) {
115 XGUI_Workbench* aWbn = static_cast<XGUI_Workbench*>(myMenuTabs->widget(aTabIdx));
116 aList.append(aWbn->features());
121 int XGUI_MainMenu::menuItemSize() const
123 int DEFAULT_ITEM_SIZE = XGUI_Preferences::resourceMgr()->integerValue(
124 XGUI_Preferences::MENU_SECTION, "item_size", 25);
125 return DEFAULT_ITEM_SIZE;
128 int XGUI_MainMenu::menuHeight() const
130 // Default group has no tabs above --> one extra row
131 int rows = menuItemRowsCount() + 1;
132 const int kMarginsSpacings = 4;
133 return rows * menuItemSize() + kMarginsSpacings;
136 int XGUI_MainMenu::menuItemRowsCount() const
138 int DEFAULT_ITEM_ROWS_COUNT = XGUI_Preferences::resourceMgr()->integerValue(
139 XGUI_Preferences::MENU_SECTION, "rows_number", 3);
140 return DEFAULT_ITEM_ROWS_COUNT;
143 void XGUI_MainMenu::updateFromResources()