X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_MainWindow.cpp;h=7fc26f0bfb5f8fb38556a89734e28a7b2f32cdec;hb=c58d52e4c1562a78b91e222190b2fd6e5bba0ef0;hp=fdaaf16f0e00e6524f6c4c581b35cda2f2d6666e;hpb=ff8ca280553ca5b69794492d5c1c4b60b180959e;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_MainWindow.cpp b/src/XGUI/XGUI_MainWindow.cpp index fdaaf16f0..7fc26f0bf 100644 --- a/src/XGUI/XGUI_MainWindow.cpp +++ b/src/XGUI/XGUI_MainWindow.cpp @@ -9,38 +9,49 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include +#include +#include +#include +#include + XGUI_MainWindow::XGUI_MainWindow(QWidget* parent) - : QMainWindow(parent), - myObjectBrowser(0), - myPythonConsole(0), - myPropertyPanelDock(0) + : QMainWindow(parent), + myPythonConsole(0), myIsModified(false) { - setWindowTitle(tr("New Geom")); - myMenuBar = new XGUI_MainMenu(this); - + myTitle = tr("New Geom"); + updateTitle(); + createMainMenu(); QMdiArea* aMdiArea = new QMdiArea(this); + aMdiArea->setContextMenuPolicy(Qt::ActionsContextMenu); setCentralWidget(aMdiArea); + connect(aMdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)), this, + SLOT(onViewActivated(QMdiSubWindow*))); - myViewer = new XGUI_Viewer(this); + // Create actions of MDI area + QAction* aAction = new QAction(QIcon(":pictures/new_view.png"), tr("Create Window"), aMdiArea); + aMdiArea->addAction(aAction); + connect(aAction, SIGNAL(triggered(bool)), this, SLOT(createSubWindow())); + + aAction = new QAction(QIcon(":pictures/tile_views.png"), tr("Tile"), aMdiArea); + aMdiArea->addAction(aAction); + connect(aAction, SIGNAL(triggered(bool)), aMdiArea, SLOT(tileSubWindows())); - //createDockWidgets(); + aAction = new QAction(QIcon(":pictures/cascade_views.png"), tr("Cascade"), aMdiArea); + aMdiArea->addAction(aAction); + connect(aAction, SIGNAL(triggered(bool)), this, SLOT(cascadeWindows())); + + aAction = new QAction(aMdiArea); + aAction->setSeparator(true); + aMdiArea->addAction(aAction); + + myViewer = new XGUI_Viewer(this); + connect(myViewer, SIGNAL(viewCreated(XGUI_ViewWindow*)), this, + SLOT(onViewCreated(XGUI_ViewWindow*))); + connect(myViewer, SIGNAL(deleteView(XGUI_ViewWindow*)), this, + SLOT(onDeleteView(XGUI_ViewWindow*))); } XGUI_MainWindow::~XGUI_MainWindow(void) @@ -54,128 +65,232 @@ QMdiArea* XGUI_MainWindow::mdiArea() const } //****************************************************** -void XGUI_MainWindow::showObjectBrowser() +void XGUI_MainWindow::showPythonConsole() { - myObjectBrowser->parentWidget()->show(); + // TODO: Check why PyConsole can not be created + if (!myPythonConsole) { + myPythonConsole = new PyConsole_EnhConsole(this, new PyConsole_EnhInterp()); + myPythonConsole->setObjectName("PythonConsole"); + undockPythonConsole(); + } + myPythonConsole->parentWidget()->show(); } //****************************************************** -void XGUI_MainWindow::hideObjectBrowser() +void XGUI_MainWindow::hidePythonConsole() { - myObjectBrowser->parentWidget()->hide(); + if (myPythonConsole) + myPythonConsole->parentWidget()->hide(); } //****************************************************** -void XGUI_MainWindow::showPythonConsole() +void XGUI_MainWindow::dockPythonConsole() { - if (!myPythonConsole) { + if (!myPythonConsole) + return; + myMenuBar->removeConsole(); + QDockWidget* aDock = new QDockWidget(this); + aDock->setFeatures(QDockWidget::AllDockWidgetFeatures | QDockWidget::DockWidgetVerticalTitleBar); + aDock->setAllowedAreas( + Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea); + aDock->setMinimumHeight(0); + aDock->setWindowTitle("Console"); + aDock->setWidget(myPythonConsole); + addDockWidget(Qt::BottomDockWidgetArea, aDock); + // Undock python console if widget is closed... + CloseEventWatcher* aWatcher = new CloseEventWatcher(aDock); + connect(aWatcher, SIGNAL(widgetClosed()), this, SLOT(undockPythonConsole())); + aDock->installEventFilter(aWatcher); +} - QDockWidget* aDoc = new QDockWidget(this); - aDoc->setFeatures(QDockWidget::AllDockWidgetFeatures | QDockWidget::DockWidgetVerticalTitleBar); - aDoc->setMinimumHeight(0); - aDoc->setWindowTitle("Console"); - myPythonConsole = new PyConsole_EnhConsole( aDoc, new PyConsole_EnhInterp()); - aDoc->setWidget(myPythonConsole); - addDockWidget(Qt::TopDockWidgetArea, aDoc); - tabifyDockWidget(myMenuBar->getLastDockWindow(), aDoc); +void XGUI_MainWindow::undockPythonConsole() +{ + if (!myPythonConsole) + return; + QDockWidget* aDock = qobject_cast(myPythonConsole->parentWidget()); + //When the application starts console will be displayed as + //a wokbench tab, so there is no dock yet + if (aDock) { + aDock->hide(); + aDock->setWidget(NULL); + aDock->deleteLater(); } - myPythonConsole->parentWidget()->show(); + myMenuBar->insertConsole(myPythonConsole); } //****************************************************** -void XGUI_MainWindow::hidePythonConsole() +void XGUI_MainWindow::createSubWindow() { - if (myPythonConsole) - myPythonConsole->parentWidget()->hide(); + viewer()->createView(); +} + +//****************************************************** +void XGUI_MainWindow::cascadeWindows() +{ + QMdiArea* aMdiArea = static_cast(centralWidget()); + QList aWindows = aMdiArea->subWindowList(); + + QSize aSize = aMdiArea->size(); + QRect aRect = aMdiArea->geometry(); + const int aOffset = 30; + int i = 0, j = 0; + int x, y; + int w = aSize.width() / 2; + int h = aSize.height() / 2; + QMdiSubWindow* aLastWnd; + foreach(QMdiSubWindow* aWnd, aWindows) + { + aWnd->showNormal(); + aWnd->raise(); + x = aOffset * i; + if ((x + w) > aSize.width()) { + x = 0; + i = 0; + } + y = aOffset * j; + if ((y + h) > aSize.height()) { + y = 0; + j = 0; + } + aWnd->setGeometry(QStyle::visualRect(aWnd->layoutDirection(), aRect, QRect(x, y, w, h))); + i++; + j++; + viewer()->onWindowActivated(aWnd); + aLastWnd = aWnd; + QApplication::processEvents(); + } + aLastWnd->setFocus(); } -void XGUI_MainWindow::showPropertyPanel() +void XGUI_MainWindow::onViewCreated(XGUI_ViewWindow* theWindow) { - QAction* aViewAct = myPropertyPanelDock->toggleViewAction(); - //setEnabled(true); - myPropertyPanelDock->show(); - myPropertyPanelDock->raise(); + QWidget* aSubWindow = theWindow->parentWidget(); + QWidget* aMDIWidget = centralWidget(); + + QAction* aAction = new QAction(aSubWindow->windowTitle(), aMDIWidget); + aAction->setCheckable(true); + connect(aAction, SIGNAL(triggered(bool)), this, SLOT(activateView())); + aMDIWidget->addAction(aAction); + + QList aActions = aMDIWidget->actions(); + foreach(QAction* aAct, aActions) + { + if (aAct->isCheckable()) + aAct->setChecked(false); + } + aAction->setChecked(true); } -void XGUI_MainWindow::hidePropertyPanel() +void XGUI_MainWindow::onDeleteView(XGUI_ViewWindow* theWindow) { - QAction* aViewAct = myPropertyPanelDock->toggleViewAction(); - //setEnabled(false); - myPropertyPanelDock->hide(); + QWidget* aSubWindow = theWindow->parentWidget(); + QString aTitle = aSubWindow->windowTitle(); + QWidget* aMDIWidget = centralWidget(); + QList aActions = aMDIWidget->actions(); + + QAction* aDelAct = 0; + foreach(QAction* aAct, aActions) + { + if (aAct->text() == aTitle) { + aDelAct = aAct; + break; + } + } + aMDIWidget->removeAction(aDelAct); } -/* - * Creates dock widgets, places them in corresponding area - * and tabifies if necessary. - */ -void XGUI_MainWindow::createDockWidgets() +void XGUI_MainWindow::activateView() { - QDockWidget* aObjDock = createObjectBrowser(); - addDockWidget(Qt::LeftDockWidgetArea, aObjDock); - myPropertyPanelDock = createPropertyPanel(); - addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanelDock); - hidePropertyPanel(); //(sender()); + QString aWndTitle = aAction->text(); + QMdiArea* aMdiArea = static_cast(centralWidget()); + + QList aWndList = aMdiArea->subWindowList(); + QMdiSubWindow* aTargetView = 0; + foreach(QMdiSubWindow* aWnd, aWndList) + { + if (aWnd->windowTitle() == aWndTitle) { + aWnd->raise(); + aWnd->activateWindow(); + aTargetView = aWnd; + break; + } + } + QApplication::processEvents(); + if (aTargetView) + QTimer::singleShot(20, aTargetView, SLOT(setFocus())); } -void XGUI_MainWindow::setPropertyPannelTitle(const QString& theTitle) +void XGUI_MainWindow::onViewActivated(QMdiSubWindow* theSubWnd) { - myPropertyPanelDock->setWindowTitle(theTitle); + if (!theSubWnd) + return; + QMdiArea* aMdiArea = static_cast(centralWidget()); + QString aWndTitle = theSubWnd->windowTitle(); + QList aActionList = aMdiArea->actions(); + foreach(QAction* aAct, aActionList) + { + if (aAct->isCheckable()) + aAct->setChecked(aAct->text() == aWndTitle); + } } +void XGUI_MainWindow::closeEvent(QCloseEvent * event) +{ + emit exitKeySequence(); + event->ignore(); +} -QDockWidget* XGUI_MainWindow::createPropertyPanel() +void XGUI_MainWindow::createMainMenu() { - QDockWidget* aPropPanel = new QDockWidget(this); - aPropPanel->setWindowTitle(tr("Property Panel")); - QAction* aViewAct = aPropPanel->toggleViewAction(); - aPropPanel->setObjectName(XGUI::PROP_PANEL); + myMenuBar = new XGUI_MainMenu(this); + QDockWidget* aMenuDock = new QDockWidget(this); + aMenuDock->setWidget(myMenuBar); + aMenuDock->setAllowedAreas(Qt::TopDockWidgetArea); + aMenuDock->setFeatures(QDockWidget::DockWidgetVerticalTitleBar); + aMenuDock->setWindowTitle(tr("General")); + addDockWidget(Qt::TopDockWidgetArea, aMenuDock); +} - QWidget* aContent = new QWidget(aPropPanel); - QVBoxLayout* aMainLay = new QVBoxLayout(aContent); - aMainLay->setContentsMargins(3, 3, 3, 3); - aPropPanel->setWidget(aContent); - QWidget* aCustomWidget = new QWidget(aContent); - aCustomWidget->setObjectName(XGUI::PROP_PANEL_WDG); - aMainLay->addWidget(aCustomWidget); - aMainLay->addStretch(1); +void XGUI_MainWindow::updateTitle() +{ + QString aTitle = myTitle; + if (!myCurrentDir.isNull()) + aTitle += " - " + myCurrentDir; + if (myIsModified) + aTitle += "*"; + setWindowTitle(aTitle); +} - QFrame* aFrm = new QFrame(aContent); - aFrm->setFrameStyle(QFrame::Sunken); - aFrm->setFrameShape(QFrame::Panel); - QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm); - aBtnLay->setContentsMargins(0, 0, 0, 0); - aMainLay->addWidget(aFrm); +void XGUI_MainWindow::setCurrentDir(const QString& theDir, bool toUpdate) +{ + myCurrentDir = theDir; + if (toUpdate) + updateTitle(); +} - QPushButton* aBtn = new QPushButton(QIcon(":pictures/button_help.png"), "", aFrm); - aBtn->setFlat(true); - //connect(aBtn, SIGNAL(clicked()), this, SIGNAL(propertyHelpPressed())); - aBtnLay->addWidget(aBtn); - aBtnLay->addStretch(1); - aBtn = new QPushButton(QIcon(":pictures/button_ok.png"), "", aFrm); - aBtn->setObjectName(XGUI::PROP_PANEL_OK); - aBtn->setFlat(true); - //connect(aBtn, SIGNAL(clicked()), this, SIGNAL(propertyOkPressed())); - aBtnLay->addWidget(aBtn); - aBtn = new QPushButton(QIcon(":pictures/button_cancel.png"), "", aFrm); - aBtn->setObjectName(XGUI::PROP_PANEL_CANCEL); - aBtn->setFlat(true); - //connect(aBtn, SIGNAL(clicked()), this, SIGNAL(propertyClosePressed())); - aBtnLay->addWidget(aBtn); +void XGUI_MainWindow::setModifiedState(bool isModified, bool toUpdate) +{ + myIsModified = isModified; + if (toUpdate) + updateTitle(); +} - return aPropPanel; +CloseEventWatcher::CloseEventWatcher(QObject* theParent) + : QObject(theParent) +{ } -QDockWidget* XGUI_MainWindow::createObjectBrowser() +bool CloseEventWatcher::eventFilter(QObject *obj, QEvent *event) { - QDockWidget* aObjDock = new QDockWidget(this); - aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - aObjDock->setWindowTitle(tr("Object browser")); - myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock); - aObjDock->setWidget(myObjectBrowser); - return aObjDock; + if (event->type() == QEvent::Close) { + emit widgetClosed(); + event->ignore(); + return true; + } else { + // standard event processing + return QObject::eventFilter(obj, event); + } } +