Salome HOME
Make property panel as a GUI of an operation
[modules/shaper.git] / src / XGUI / XGUI_MainWindow.cpp
index 3aa696045b5be600507280c70bcc2dd80a1ca208..7fc26f0bfb5f8fb38556a89734e28a7b2f32cdec 100644 (file)
 #include <QTimer>
 #include <QCloseEvent>
 
+
 XGUI_MainWindow::XGUI_MainWindow(QWidget* parent)
-    : QMainWindow(parent), 
-    myPythonConsole(0)
+    : QMainWindow(parent),
+      myPythonConsole(0), myIsModified(false)
 {
-  setWindowTitle(tr("New Geom"));
+  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*)));
+  connect(aMdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)), this,
+          SLOT(onViewActivated(QMdiSubWindow*)));
 
   // 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()));
-  
+
   aAction = new QAction(QIcon(":pictures/cascade_views.png"), tr("Cascade"), aMdiArea);
   aMdiArea->addAction(aAction);
   connect(aAction, SIGNAL(triggered(bool)), this, SLOT(cascadeWindows()));
@@ -46,10 +48,10 @@ XGUI_MainWindow::XGUI_MainWindow(QWidget* parent)
   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*)));
+  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)
@@ -66,11 +68,12 @@ QMdiArea* XGUI_MainWindow::mdiArea() const
 void XGUI_MainWindow::showPythonConsole()
 {
   // TODO: Check why PyConsole can not be created
-  //if (!myPythonConsole) {
-  //  myPythonConsole = new PyConsole_EnhConsole(this, new PyConsole_EnhInterp());
-  //  undockPythonConsole();
-  //}
-  //myPythonConsole->parentWidget()->show();
+  if (!myPythonConsole) {
+    myPythonConsole = new PyConsole_EnhConsole(this, new PyConsole_EnhInterp());
+    myPythonConsole->setObjectName("PythonConsole");
+    undockPythonConsole();
+  }
+  myPythonConsole->parentWidget()->show();
 }
 
 //******************************************************
@@ -87,19 +90,16 @@ void XGUI_MainWindow::dockPythonConsole()
     return;
   myMenuBar->removeConsole();
   QDockWidget* aDock = new QDockWidget(this);
-  aDock->setFeatures(QDockWidget::AllDockWidgetFeatures |
-                     QDockWidget::DockWidgetVerticalTitleBar);
-  aDock->setAllowedAreas(Qt::LeftDockWidgetArea  |
-                         Qt::RightDockWidgetArea |
-                         Qt::BottomDockWidgetArea);
+  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()));
+  CloseEventWatcher* aWatcher = new CloseEventWatcher(aDock);
+  connect(aWatcher, SIGNAL(widgetClosed()), this, SLOT(undockPythonConsole()));
   aDock->installEventFilter(aWatcher);
 }
 
@@ -110,7 +110,7 @@ void XGUI_MainWindow::undockPythonConsole()
   QDockWidget* aDock = qobject_cast<QDockWidget*>(myPythonConsole->parentWidget());
   //When the application starts console will be displayed as
   //a wokbench tab, so there is no dock yet
-  if(aDock) {
+  if (aDock) {
     aDock->hide();
     aDock->setWidget(NULL);
     aDock->deleteLater();
@@ -129,7 +129,7 @@ void XGUI_MainWindow::cascadeWindows()
 {
   QMdiArea* aMdiArea = static_cast<QMdiArea*>(centralWidget());
   QList<QMdiSubWindow*> aWindows = aMdiArea->subWindowList();
-  
+
   QSize aSize = aMdiArea->size();
   QRect aRect = aMdiArea->geometry();
   const int aOffset = 30;
@@ -138,7 +138,8 @@ void XGUI_MainWindow::cascadeWindows()
   int w = aSize.width() / 2;
   int h = aSize.height() / 2;
   QMdiSubWindow* aLastWnd;
-  foreach(QMdiSubWindow* aWnd, aWindows) {
+  foreach(QMdiSubWindow* aWnd, aWindows)
+  {
     aWnd->showNormal();
     aWnd->raise();
     x = aOffset * i;
@@ -151,8 +152,7 @@ void XGUI_MainWindow::cascadeWindows()
       y = 0;
       j = 0;
     }
-    aWnd->setGeometry(QStyle::visualRect(aWnd->layoutDirection(), aRect, 
-      QRect(x, y, w, h)));
+    aWnd->setGeometry(QStyle::visualRect(aWnd->layoutDirection(), aRect, QRect(x, y, w, h)));
     i++;
     j++;
     viewer()->onWindowActivated(aWnd);
@@ -173,7 +173,8 @@ void XGUI_MainWindow::onViewCreated(XGUI_ViewWindow* theWindow)
   aMDIWidget->addAction(aAction);
 
   QList<QAction*> aActions = aMDIWidget->actions();
-  foreach(QAction* aAct, aActions) {
+  foreach(QAction* aAct, aActions)
+  {
     if (aAct->isCheckable())
       aAct->setChecked(false);
   }
@@ -188,7 +189,8 @@ void XGUI_MainWindow::onDeleteView(XGUI_ViewWindow* theWindow)
   QList<QAction*> aActions = aMDIWidget->actions();
 
   QAction* aDelAct = 0;
-  foreach(QAction* aAct, aActions) {
+  foreach(QAction* aAct, aActions)
+  {
     if (aAct->text() == aTitle) {
       aDelAct = aAct;
       break;
@@ -205,7 +207,8 @@ void XGUI_MainWindow::activateView()
 
   QList<QMdiSubWindow*> aWndList = aMdiArea->subWindowList();
   QMdiSubWindow* aTargetView = 0;
-  foreach(QMdiSubWindow* aWnd, aWndList) {
+  foreach(QMdiSubWindow* aWnd, aWndList)
+  {
     if (aWnd->windowTitle() == aWndTitle) {
       aWnd->raise();
       aWnd->activateWindow();
@@ -225,7 +228,8 @@ void XGUI_MainWindow::onViewActivated(QMdiSubWindow* theSubWnd)
   QMdiArea* aMdiArea = static_cast<QMdiArea*>(centralWidget());
   QString aWndTitle = theSubWnd->windowTitle();
   QList<QAction*> aActionList = aMdiArea->actions();
-  foreach(QAction* aAct, aActionList) {
+  foreach(QAction* aAct, aActionList)
+  {
     if (aAct->isCheckable())
       aAct->setChecked(aAct->text() == aWndTitle);
   }
@@ -248,11 +252,38 @@ void XGUI_MainWindow::createMainMenu()
   addDockWidget(Qt::TopDockWidgetArea, aMenuDock);
 }
 
+
+void XGUI_MainWindow::updateTitle()
+{
+  QString aTitle = myTitle;
+  if (!myCurrentDir.isNull())
+    aTitle += " - " + myCurrentDir;
+  if (myIsModified)
+    aTitle += "*";
+  setWindowTitle(aTitle);
+}
+
+void XGUI_MainWindow::setCurrentDir(const QString& theDir, bool toUpdate)
+{
+  myCurrentDir = theDir;
+  if (toUpdate)
+    updateTitle();
+}
+
+void XGUI_MainWindow::setModifiedState(bool isModified, bool toUpdate)
+{
+  myIsModified = isModified;
+  if (toUpdate)
+    updateTitle();
+}
+
 CloseEventWatcher::CloseEventWatcher(QObject* theParent)
     : QObject(theParent)
-{}
+{
+}
 
-bool CloseEventWatcher::eventFilter(QObject *obj, QEvent *event) {
+bool CloseEventWatcher::eventFilter(QObject *obj, QEvent *event)
+{
   if (event->type() == QEvent::Close) {
     emit widgetClosed();
     event->ignore();