X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_MainMenu.cpp;h=d874cc974d48745772d71c12124baf12a7cdd1b4;hb=f57633e7e47026f501b94c38989e39450a946ce4;hp=0a4903bcea28b92a50b13f46b89b46bbf9bd604c;hpb=dcfbdb77dfd1e8f4f5a9f636ff5534d74af3592e;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_MainMenu.cpp b/src/XGUI/XGUI_MainMenu.cpp index 0a4903bce..d874cc974 100644 --- a/src/XGUI/XGUI_MainMenu.cpp +++ b/src/XGUI/XGUI_MainMenu.cpp @@ -1,49 +1,148 @@ -#include "XGUI_MainMenu.h" -#include "XGUI_Workbench.h" -#include "XGUI_MainWindow.h" +#include +#include +#include +#include +#include +#include + +#include #include #include #include #include +#include +#include +#include -XGUI_MainMenu::XGUI_MainMenu(XGUI_MainWindow *parent) : - QObject(parent), myDesktop(parent) +XGUI_MainMenu::XGUI_MainMenu(XGUI_MainWindow *parent) + : QWidget(parent), + myDesktop(parent) { - parent->setTabPosition(Qt::TopDockWidgetArea, QTabWidget::North); -} + myGeneralPage = new XGUI_MenuGroupPanel(this); + myGeneralPage->setObjectName("Default"); + myGeneralPage->parentWidget()->setMaximumWidth(200); + myGeneralPage->installEventFilter(this); + myGeneralPage->setFrameStyle(QFrame::StyledPanel); + myMenuTabs = new QTabWidget(this); + myMenuTabs->setStyleSheet("QTabBar::tab {height: 24px;} QTabWidget:pane {border: 0px;}"); + QHBoxLayout* aMainLayout = new QHBoxLayout(this); + aMainLayout->addWidget(myGeneralPage); + aMainLayout->addWidget(myMenuTabs); + aMainLayout->setContentsMargins(0, 2, 2, 0); + aMainLayout->setSpacing(2); + setLayout(aMainLayout); + updateFromResources(); +} XGUI_MainMenu::~XGUI_MainMenu(void) { } -IWorkbench* XGUI_MainMenu::addWorkbench(QString theTitle) +XGUI_Workbench* XGUI_MainMenu::addWorkbench(const QString& theId, const QString& theTitle) { - QDockWidget* aDoc = new QDockWidget(myDesktop); - aDoc->setFeatures(QDockWidget::DockWidgetVerticalTitleBar); - aDoc->setAllowedAreas(Qt::TopDockWidgetArea); - aDoc->setWindowTitle(theTitle); - aDoc->setMinimumHeight(30); - aDoc->setContentsMargins(0, 0, 0, 0); + QString aTitle = theTitle; + if (aTitle.isEmpty()) { + aTitle = tr(theId.toLatin1().constData()); + } + XGUI_Workbench* aPage = new XGUI_Workbench(myMenuTabs); + aPage->setObjectName(theId); + myMenuTabs->addTab(aPage, aTitle); + myWorkbenches.append(aPage); + return aPage; +} - XGUI_Workbench* aPage = new XGUI_Workbench(aDoc); - aDoc->setWidget(aPage); +/* + * Searches for already created workbench with given name. + */ +XGUI_Workbench* XGUI_MainMenu::findWorkbench(const QString& theObjName) const +{ + return myDesktop->findChild(theObjName); +} - myDesktop->addDockWidget(Qt::TopDockWidgetArea, aDoc); - if (myMenuTabs.length() > 1) { - myDesktop->tabifyDockWidget(myMenuTabs.last(), aDoc); +bool XGUI_MainMenu::eventFilter(QObject *theWatched, QEvent *theEvent) +{ + if (theWatched == myGeneralPage) { + if (theEvent->type() == QEvent::Show) { + myGeneralPage->parentWidget()->setMaximumWidth(16777215); + myGeneralPage->removeEventFilter(this); } + } + return QObject::eventFilter(theWatched, theEvent); +} + +void XGUI_MainMenu::insertConsole(QWidget* theConsole) +{ + int aConsoleTabId = myMenuTabs->addTab(theConsole, "Console"); + QTabBar* aTabBar = myMenuTabs->findChild(); + QPushButton* aCloseTabButton = new QPushButton(); + aCloseTabButton->setFixedSize(16, 16); + aCloseTabButton->setIcon(QIcon(":pictures/wnd_close.png")); + aCloseTabButton->setFlat(true); + aTabBar->setTabButton(aConsoleTabId, QTabBar::RightSide, aCloseTabButton); - myMenuTabs.append(aDoc); - return aPage; + connect(aCloseTabButton, SIGNAL(clicked()), myDesktop, SLOT(dockPythonConsole())); } +void XGUI_MainMenu::removeConsole() +{ + const int kLastTab = myMenuTabs->count() - 1; + myMenuTabs->removeTab(kLastTab); +} -IMenuGroup* XGUI_MainMenu::addGroup(int thePageId) +XGUI_Command* XGUI_MainMenu::feature(const QString& theId) const { - XGUI_Workbench* aPage = dynamic_cast(myMenuTabs[thePageId]->widget()); - return aPage->addGroup(); + XGUI_Command* result; + result = myGeneralPage->feature(theId); + if (!result) { + XGUI_Workbench* aWbn; + foreach (aWbn, myWorkbenches) + { + result = aWbn->feature(theId); + if (result) + break; + } + } + return result; } +QList XGUI_MainMenu::features() const +{ + QList aList = myGeneralPage->features(); + XGUI_Workbench* aWbn; + foreach (aWbn, myWorkbenches) + { + aList.append(aWbn->features()); + } + return aList; +} + +int XGUI_MainMenu::menuItemSize() const +{ + const int kDefaultItemSize = 25; + return kDefaultItemSize; +} + +int XGUI_MainMenu::menuHeight() const +{ + // Default group has no tabs above --> one extra row + int rows = menuItemRowsCount() + 1; + const int kMarginsSpacings = 5; + return rows * menuItemSize() + kMarginsSpacings; +} + +int XGUI_MainMenu::menuItemRowsCount() const +{ + static const int kDefaultRowsCount = 3; + int aRowsCount = XGUI_Preferences::resourceMgr()->integerValue(XGUI_Preferences::MENU_SECTION, + "rows_number", kDefaultRowsCount); + return aRowsCount; +} + +void XGUI_MainMenu::updateFromResources() +{ + setFixedHeight(menuHeight()); + repaint(); +}