#include <XGUI_MainMenu.h>
#include <XGUI_Workbench.h>
+#include <XGUI_MenuGroupPanel.h>
#include <XGUI_MainWindow.h>
#include <XGUI_Command.h>
+#include <XGUI_Preferences.h>
+
+#include <SUIT_ResourceMgr.h>
#include <QLayout>
#include <QTabWidget>
#include <QLabel>
#include <QDockWidget>
#include <QEvent>
+#include <QPushButton>
+#include <QTabBar>
XGUI_MainMenu::XGUI_MainMenu(XGUI_MainWindow *parent)
- : QObject(parent), myDesktop(parent)
+ : QWidget(parent),
+ myDesktop(parent)
{
- parent->setTabPosition(Qt::TopDockWidgetArea, QTabWidget::North);
- myGeneralPage = addWorkbench(tr("General"));
+ 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)
XGUI_Workbench* XGUI_MainMenu::addWorkbench(const QString& theId, const QString& theTitle)
{
- QDockWidget* aDock = new QDockWidget(myDesktop);
- aDock->setFeatures(QDockWidget::DockWidgetVerticalTitleBar);
- aDock->setAllowedAreas(Qt::TopDockWidgetArea);
QString aTitle = theTitle;
if (aTitle.isEmpty()) {
aTitle = tr(theId.toLatin1().constData());
}
- aDock->setWindowTitle(aTitle);
- aDock->setMinimumHeight(30);
- aDock->setContentsMargins(0, 0, 0, 0);
-
- XGUI_Workbench* aPage = new XGUI_Workbench(aDock);
+ XGUI_Workbench* aPage = new XGUI_Workbench(myMenuTabs);
aPage->setObjectName(theId);
- aDock->setWidget(aPage);
-
- myDesktop->addDockWidget(Qt::TopDockWidgetArea, aDock);
- if (myMenuTabs.length() > 1) {
- myDesktop->tabifyDockWidget(myMenuTabs.last(), aDock);
- }
-
- myMenuTabs.append(aDock);
+ myMenuTabs->addTab(aPage, aTitle);
+ myWorkbenches.append(aPage);
return aPage;
}
/*
* Searches for already created workbench with given name.
*/
-XGUI_Workbench* XGUI_MainMenu::findWorkbench(const QString& theObjName)
+XGUI_Workbench* XGUI_MainMenu::findWorkbench(const QString& theObjName) const
{
return myDesktop->findChild<XGUI_Workbench*>(theObjName);
}
-
bool XGUI_MainMenu::eventFilter(QObject *theWatched, QEvent *theEvent)
{
if (theWatched == myGeneralPage) {
return QObject::eventFilter(theWatched, theEvent);
}
+void XGUI_MainMenu::insertConsole(QWidget* theConsole)
+{
+ int aConsoleTabId = myMenuTabs->addTab(theConsole, "Console");
+
+ QTabBar* aTabBar = myMenuTabs->findChild<QTabBar*>();
+ QPushButton* aCloseTabButton = new QPushButton();
+ aCloseTabButton->setFixedSize(16, 16);
+ aCloseTabButton->setIcon(QIcon(":pictures/wnd_close.png"));
+ aCloseTabButton->setFlat(true);
+ aTabBar->setTabButton(aConsoleTabId, QTabBar::RightSide, aCloseTabButton);
+
+ connect(aCloseTabButton, SIGNAL(clicked()), myDesktop, SLOT(dockPythonConsole()));
+}
+
+void XGUI_MainMenu::removeConsole()
+{
+ const int kLastTab = myMenuTabs->count() - 1;
+ myMenuTabs->removeTab(kLastTab);
+}
+
XGUI_Command* XGUI_MainMenu::feature(const QString& theId) const
{
- QList<QDockWidget*>::const_iterator aIt;
- for (aIt = myMenuTabs.constBegin(); aIt != myMenuTabs.constEnd(); ++aIt) {
- XGUI_Workbench* aWbn = static_cast<XGUI_Workbench*>((*aIt)->widget());
- XGUI_Command* aCmd = aWbn->feature(theId);
- if (aCmd)
- return aCmd;
+ XGUI_Command* result;
+ result = myGeneralPage->feature(theId);
+ if (!result) {
+ XGUI_Workbench* aWbn;
+ foreach (aWbn, myWorkbenches)
+ {
+ result = aWbn->feature(theId);
+ if (result)
+ break;
+ }
}
- return 0;
+ return result;
}
QList<XGUI_Command*> XGUI_MainMenu::features() const
{
- QList<XGUI_Command*> aList;
- QList<QDockWidget*>::const_iterator aIt;
- for (aIt = myMenuTabs.constBegin(); aIt != myMenuTabs.constEnd(); ++aIt) {
- XGUI_Workbench* aWbn = static_cast<XGUI_Workbench*>((*aIt)->widget());
+ QList<XGUI_Command*> aList = myGeneralPage->features();
+ XGUI_Workbench* aWbn;
+ foreach (aWbn, myWorkbenches)
+ {
aList.append(aWbn->features());
}
return aList;
}
-void XGUI_MainMenu::onFeatureChecked(bool isChecked)
+int XGUI_MainMenu::menuItemSize() const
{
- if (!isChecked) {
- restoreCommandState();
- return;
- }
+ const int kDefaultItemSize = 25;
+ return kDefaultItemSize;
+}
- saveCommandsState();
- QStringList aSkippedIds;
- XGUI_Command* aToggledFeature = dynamic_cast<XGUI_Command*>(sender());
- aSkippedIds.append(aToggledFeature->unblockableCommands());
-// aSkippedIds.append(aToggledFeature->id());
- XGUI_Workbench* aGeneralWB = findWorkbench(tr("General"));
- foreach(XGUI_Command* eachFeature, aGeneralWB->features()) {
- aSkippedIds.append(eachFeature->id());
- }
- QList<XGUI_Command*> allFeatures = features();
- foreach(XGUI_Command* eachFeature, allFeatures) {
- QString aFeatureId = eachFeature->id();
- if (aSkippedIds.removeAll(aFeatureId) > 0) {
- continue;
- }
- eachFeature->setEnabled(false);
- }
+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;
}
-void XGUI_MainMenu::saveCommandsState()
+int XGUI_MainMenu::menuItemRowsCount() const
{
- myCommandState.clear();
- QList<XGUI_Command*> allFeatures = features();
- XGUI_Command* eachFeature = NULL;
- foreach(eachFeature, allFeatures) {
- myCommandState.insert(eachFeature, eachFeature->enabled());
- }
+ static const int kDefaultRowsCount = 3;
+ int aRowsCount = XGUI_Preferences::resourceMgr()->integerValue(XGUI_Preferences::MENU_SECTION,
+ "rows_number", kDefaultRowsCount);
+ return aRowsCount;
}
-void XGUI_MainMenu::restoreCommandState()
+void XGUI_MainMenu::updateFromResources()
{
- QList<XGUI_Command*> allFeatures = features();
- XGUI_Command* eachFeature = NULL;
- foreach(eachFeature, allFeatures) {
- eachFeature->setChecked(false);
- eachFeature->setEnabled(myCommandState[eachFeature]);
- }
+ setFixedHeight(menuHeight());
+ repaint();
}