]> AND Private Git Repository - blast.git/blobdiff - MainWindow.cpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
added patterns and started OP computation
[blast.git] / MainWindow.cpp
index e9f841475ce352d735c9b879b8b83a81571bbeb4..4be284b68cb1d8d4b738f81f47bf92f1683ffe3b 100644 (file)
@@ -271,11 +271,12 @@ void MainWindow::slotLoadProject(){
     if (topGroup != NULL) {
       addTopGroup(topGroup);
       library->updateComboScene();
+      params->isCurrentProject = true;
+      enableProjectActions(true, PROJECT_CLOSE | PROJECT_SAVE | PROJECT_SAVEAS | PROJECT_LIB, OP_RAZ);
     }
     else {
       QMessageBox msgBox;
-      msgBox.setText("Cannot open the project.");
-      msgBox.setInformativeText("Do you want to save your changes?");
+      msgBox.setText("Cannot open the project.");      
       msgBox.setStandardButtons(QMessageBox::Cancel);
       msgBox.setDefaultButton(QMessageBox::Cancel);
 
@@ -291,24 +292,53 @@ void MainWindow::slotNewProject(){
   GroupWidget* topGroup = dispatcher->createTopScene();
   addTopGroup(topGroup);
   library->updateComboScene();
+  library->show();
   params->isCurrentProject = true;
 }
 
-void MainWindow::slotCloseProject(){
+bool MainWindow::slotCloseProject(){
 
-  // removing the GroupWidget from stack
-  QWidget *widget = stackedWidget->widget(1);
-  stackedWidget->removeWidget(widget);
-  stackedWidget->setCurrentIndex(0);
+  bool doClose = false;
 
-  dispatcher->closeCurrentProject();
+  if(params->isCurrentProject) {
+    if (params->unsaveModif) {
+      QMessageBox msgBox;
+      msgBox.setText("The project has been modified.");
+      msgBox.setInformativeText("Do you want to save your changes?");
+      msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
+      msgBox.setDefaultButton(QMessageBox::Save);
 
+      int ret = msgBox.exec();
 
-  params->isCurrentProject = false;
-  params->unsaveModif = false;
-  absoluteFilename = QString();
+      switch(ret) {
+      case QMessageBox::Save :
+        slotSaveProject();
+        doClose = true;
+        break;
+      case QMessageBox::Discard :
+        doClose = true;
+        break;
+      }
+    }
+    else {
+      doClose = true;
+    }
+    if (doClose) {
+      // removing the GroupWidget from stack
+      QWidget *widget = stackedWidget->widget(1);
+      stackedWidget->removeWidget(widget);
+      stackedWidget->setCurrentIndex(0);
 
-  initialize();
+      dispatcher->closeCurrentProject();
+
+      params->isCurrentProject = false;
+      params->unsaveModif = false;
+      absoluteFilename = QString();
+
+      initialize();
+    }
+  }
+  return doClose;
 }
 
 
@@ -358,29 +388,16 @@ void MainWindow::removeTopGroup() {
   stackedWidget->setCurrentIndex(0);
 }
 
-void MainWindow::closeEvent(QCloseEvent *event){
-  if(params->isCurrentProject){
-    QMessageBox msgBox;
-    msgBox.setText("The project has been modified.");
-    msgBox.setInformativeText("Do you want to save your changes?");
-    msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
-    msgBox.setDefaultButton(QMessageBox::Save);
-
-    int ret = msgBox.exec();
-
-    switch(ret) {
-    case QMessageBox::Save :
-      slotSaveProject();
-      slotCloseProject();
-      break;
-    case QMessageBox::Discard :
-      slotCloseProject();
-      break;
-    }
+void MainWindow::closeEvent(QCloseEvent *event) {
+
+  if (params->isCurrentProject) {
+    slotCloseProject();
     event->ignore();
-  } else {
-    exit(0);
   }
+  else {
+    library->deleteLater();
+  }
+
 }
 
 void MainWindow::mousePressEvent(QMouseEvent *e) {