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);
51 myWorkbenches.append(aPage);
56 * Searches for already created workbench with given name.
58 XGUI_Workbench* XGUI_MainMenu::findWorkbench(const QString& theObjName) const
60 return myDesktop->findChild<XGUI_Workbench*>(theObjName);
64 bool XGUI_MainMenu::eventFilter(QObject *theWatched, QEvent *theEvent)
66 if (theWatched == myGeneralPage) {
67 if (theEvent->type() == QEvent::Show) {
68 myGeneralPage->parentWidget()->setMaximumWidth(16777215);
69 myGeneralPage->removeEventFilter(this);
72 return QObject::eventFilter(theWatched, theEvent);
75 void XGUI_MainMenu::insertConsole(QWidget* theConsole)
77 int aConsoleTabId = myMenuTabs->addTab(theConsole, "Console");
79 QTabBar* aTabBar = myMenuTabs->findChild<QTabBar*>();
80 QPushButton* aCloseTabButton = new QPushButton();
81 aCloseTabButton->setFixedSize(16, 16);
82 aCloseTabButton->setIcon(QIcon(":pictures/wnd_close.png"));
83 aCloseTabButton->setFlat(true);
84 aTabBar->setTabButton(aConsoleTabId,
88 connect(aCloseTabButton, SIGNAL(clicked()),
89 myDesktop, SLOT(dockPythonConsole()));
92 void XGUI_MainMenu::removeConsole()
94 const int kLastTab = myMenuTabs->count() - 1;
95 myMenuTabs->removeTab(kLastTab);
98 XGUI_Command* XGUI_MainMenu::feature(const QString& theId) const
100 XGUI_Command* result;
101 result = myGeneralPage->feature(theId);
103 XGUI_Workbench* aWbn;
104 foreach (aWbn, myWorkbenches) {
105 result = aWbn->feature(theId);
112 QList<XGUI_Command*> XGUI_MainMenu::features() const
114 QList<XGUI_Command*> aList = myGeneralPage->features();
115 XGUI_Workbench* aWbn;
116 foreach (aWbn, myWorkbenches) {
117 aList.append(aWbn->features());
122 int XGUI_MainMenu::menuItemSize() const
124 const int kDefaultItemSize = 25;
125 int anItemSize = XGUI_Preferences::resourceMgr()->integerValue(
126 XGUI_Preferences::MENU_SECTION, "item_size", kDefaultItemSize);
130 int XGUI_MainMenu::menuHeight() const
132 // Default group has no tabs above --> one extra row
133 int rows = menuItemRowsCount() + 1;
134 const int kMarginsSpacings = 4;
135 return rows * menuItemSize() + kMarginsSpacings;
138 int XGUI_MainMenu::menuItemRowsCount() const
140 const int kDefaultRowsCount = 3;
141 int aRowsCount = XGUI_Preferences::resourceMgr()->integerValue(
142 XGUI_Preferences::MENU_SECTION, "rows_number", kDefaultRowsCount);
146 void XGUI_MainMenu::updateFromResources()