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)
22 myGeneralPage = new XGUI_MenuGroupPanel(this);
23 myGeneralPage->setObjectName("Default");
24 myGeneralPage->parentWidget()->setMaximumWidth(200);
25 myGeneralPage->installEventFilter(this);
26 myGeneralPage->setFrameStyle(QFrame::StyledPanel);
28 myMenuTabs = new QTabWidget(this);
29 myMenuTabs->setStyleSheet("QTabBar::tab {height: 24px;} QTabWidget:pane {border: 0px;}");
30 QHBoxLayout* aMainLayout = new QHBoxLayout(this);
31 aMainLayout->addWidget(myGeneralPage);
32 aMainLayout->addWidget(myMenuTabs);
33 aMainLayout->setContentsMargins(0, 2, 2, 0);
34 aMainLayout->setSpacing(2);
35 setLayout(aMainLayout);
36 updateFromResources();
39 XGUI_MainMenu::~XGUI_MainMenu(void)
43 XGUI_Workbench* XGUI_MainMenu::addWorkbench(const QString& theId, const QString& theTitle)
45 QString aTitle = theTitle;
46 if (aTitle.isEmpty()) {
47 aTitle = tr(theId.toLatin1().constData());
49 XGUI_Workbench* aPage = new XGUI_Workbench(myMenuTabs);
50 aPage->setObjectName(theId);
51 myMenuTabs->addTab(aPage, aTitle);
52 myWorkbenches.append(aPage);
57 * Searches for already created workbench with given name.
59 XGUI_Workbench* XGUI_MainMenu::findWorkbench(const QString& theObjName) const
61 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, QTabBar::RightSide, aCloseTabButton);
86 connect(aCloseTabButton, SIGNAL(clicked()), myDesktop, SLOT(dockPythonConsole()));
89 void XGUI_MainMenu::removeConsole()
91 const int kLastTab = myMenuTabs->count() - 1;
92 myMenuTabs->removeTab(kLastTab);
95 XGUI_Command* XGUI_MainMenu::feature(const QString& theId) const
98 result = myGeneralPage->feature(theId);
100 XGUI_Workbench* aWbn;
101 foreach (aWbn, myWorkbenches)
103 result = aWbn->feature(theId);
111 QList<XGUI_Command*> XGUI_MainMenu::features() const
113 QList<XGUI_Command*> aList = myGeneralPage->features();
114 XGUI_Workbench* aWbn;
115 foreach (aWbn, myWorkbenches)
117 aList.append(aWbn->features());
122 int XGUI_MainMenu::menuItemSize() const
124 const int kDefaultItemSize = 25;
125 return kDefaultItemSize;
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 = 5;
133 return rows * menuItemSize() + kMarginsSpacings;
136 int XGUI_MainMenu::menuItemRowsCount() const
138 static const int kDefaultRowsCount = 3;
139 int aRowsCount = XGUI_Preferences::resourceMgr()->integerValue(XGUI_Preferences::MENU_SECTION,
140 "rows_number", kDefaultRowsCount);
144 void XGUI_MainMenu::updateFromResources()
146 setFixedHeight(menuHeight());