ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/s10k/Vago/mainwindow.cpp
(Generate patch)

Comparing Vago/trunk/Vago/mainwindow.cpp (file contents):
Revision 1052 by s10k, Sat Sep 17 13:32:34 2016 UTC vs.
Revision 1054 by s10k, Wed Oct 12 21:35:13 2016 UTC

# Line 71 | Line 71 | MainWindow::MainWindow(QWidget *parent)
71          this->vagoSettings->setValue("SeparateInWorkspace",true);
72          iniChanged=true;
73      }
74 <    if(!this->vagoSettings->contains("ConfirmExit")){
75 <        this->vagoSettings->setValue("ConfirmExit", false);
74 >    if(!this->vagoSettings->contains("AskSaveProject")){
75 >        this->vagoSettings->setValue("AskSaveProject", true);
76 >        iniChanged=true;
77 >    }
78 >    if(!this->vagoSettings->contains("AskToOpenLastProject")){
79 >        this->vagoSettings->setValue("AskToOpenLastProject", false);
80          iniChanged=true;
81      }
82      if(!this->vagoSettings->contains("LastProjectPath")){
# Line 179 | Line 183 | MainWindow::~MainWindow()
183  
184   void MainWindow::showEvent(QShowEvent *e)
185   {
186 <    #ifdef Q_OS_WIN
186 >    // If we don't have a converter yet, application wasn't started.
187 >    if(!this->applicationIsFullyLoaded)
188 >    {
189 >        // Apparently Qt doesn't contains a slot to when the application was fully load (mainwindow). So we do our own implementation instead.
190 >        connect(this, SIGNAL(signalAppIsLoaded()), this, SLOT(applicationWasLoaded()), Qt::ConnectionType::QueuedConnection);
191 >        emit signalAppIsLoaded();
192 >    }
193 >
194 >    e->accept();
195 > }
196 >
197 > // Called only when the MainWindow was fully loaded and painted on the screen. This slot is only called once.
198 > void MainWindow::applicationWasLoaded(){
199 > #ifdef Q_OS_WIN
200      // QProgressBar only works after the windows was shown
201      // http://stackoverflow.com/questions/24840941/qwintaskbarprogress-wont-show (Kervala answer)
202  
# Line 191 | Line 208 | void MainWindow::showEvent(QShowEvent *e
208  
209      //Create a thread for do the conversion in background
210      this->myConverter = new Converter(UtilVago::getAppPath(), this->myLogger, this->listToProccess, this->win7TaskBarProgress);
211 <    #else
211 > #else
212      this->myConverter = new Converter(UtilVago::getAppPath(), this->myLogger, this->listToProccess);
213 <    #endif
213 > #endif
214  
215      connectSlots();
216  
217      this->myLogger->writeString("Application started.");
218  
219 <    e->accept();
219 >    this->applicationIsFullyLoaded = true;
220 >
221 >    QString lastSavedProject = this->vagoSettings->value("RecentProject1").toString();
222 >
223 >    if(!lastSavedProject.isEmpty() && this->vagoSettings->value("AskToOpenLastProject").toBool()){
224 >        if(Util::showQuestionPopUp(this,"Do you want to load latest project?\n\nLatest project was '" + Util::cutNameWithoutBackSlash(lastSavedProject) + "'.")){
225 >            loadProjectState(lastSavedProject);
226 >        }
227 >    }
228   }
229  
230  
# Line 227 | Line 252 | void MainWindow::on_actionSound_Wizard_t
252      myWizard.exec();
253   }
254  
255 + void MainWindow::on_actionBackground_Image_Wizard_triggered()
256 + {
257 +    BGImageWizard myWizard (UtilVago::getAppPath(), this->workspaceWizardsLocation, this->vagoSettings, this->myLogger);
258 +    myWizard.exec();
259 + }
260 +
261   void MainWindow::on_tbOni_clicked()
262   {
263      QStringList arguments;
# Line 433 | Line 464 | void MainWindow::addFilesSource(DropTabl
464          addRowTable(myTable,lastFileName,fromTo,command);
465      }
466      updateItemsLoaded(myTable);
467 +    rowsWereChangedInDropTableWidget();
468   }
469  
470   QString MainWindow::fileParsingXML(QString tabTitle, QString myOutputFolder, QString from, QString to , QString file){
# Line 735 | Line 767 | void MainWindow::TresultConversion(QStri
767      if(numErrors!=0){
768          QString sNumErrors=QString::number(numErrors);
769          if(numErrors>1){
770 <            UtilVago::showErrorPopUpLogButton(result+"\n This is the last of "+sNumErrors+" Errors.");
771 <            showErrStatusMessage("Something gone wrong. Check log file ("+sNumErrors+" Errors).");
770 >            UtilVago::showErrorPopUpLogButton(result+"\n This is the last of "+sNumErrors+" errors.");
771 >            showErrStatusMessage("Something gone wrong. Check log file ("+sNumErrors+" errors).");
772          }
773          else{
774              UtilVago::showErrorPopUpLogButton(result);
775              showErrStatusMessage("Something gone wrong. Check log file.");
776          }
745
777      }
778      else{
779          showSuccessStatusMessage("Everything went well!");
# Line 1107 | Line 1138 | void MainWindow::removeTableContents(Dro
1138              myTable->removeRow(myTable->selectionModel()->selectedRows().at(size-i-1).row());
1139          }
1140          updateItemsLoaded(myTable);
1141 +        rowsWereChangedInDropTableWidget();
1142      }
1143   }
1144  
# Line 1130 | Line 1162 | void MainWindow::clearTableContents(Drop
1162  
1163      if(Util::showQuestionPopUp(this,"Are you sure you want to clear the content?",defaultButton)){
1164          clearTableNoPrompt(myTable);
1165 +        updateItemsLoaded(myTable);
1166 +        rowsWereChangedInDropTableWidget();
1167      }
1168 <    updateItemsLoaded(myTable);
1168 >
1169   }
1170  
1171   void MainWindow::clearTableNoPrompt(DropTableWidget *myTable){
# Line 1148 | Line 1182 | void MainWindow::on_actionPreferences_tr
1182  
1183  
1184   void MainWindow::closeEvent(QCloseEvent *event){
1185 <    if(this->vagoSettings->value("ConfirmExit").toBool()){
1186 <        if(!Util::showQuestionPopUp(this,"Exit Vago?")){
1185 >    if(this->vagoSettings->value("AskSaveProject").toBool() && this->unsavedChangesExist){
1186 >        QMessageBox::StandardButton result = askToSaveCurrentProject();
1187 >        if(result == QMessageBox::StandardButton::Cancel){
1188              event->ignore();
1189          }
1190      }
1191   }
1192  
1193 + QMessageBox::StandardButton MainWindow::askToSaveCurrentProject(){
1194 +    QMessageBox::StandardButton result =
1195 +            Util::showQuestionPopUpWithCancel(this,"There are unsaved changes. Do you want to save the current project?", QMessageBox::StandardButton::Yes);
1196 +
1197 +    if(result == QMessageBox::StandardButton::Yes){
1198 +        on_actionSave_triggered();
1199 +    }
1200 +
1201 +    return result;
1202 + }
1203 +
1204   void MainWindow::on_cbToLevels_currentIndexChanged(const QString &arg1)
1205   {
1206  
# Line 1249 | Line 1295 | void MainWindow::updateItemsLoaded(DropT
1295      this->itemsLoaded->setText(QString().setNum(numItems)+ (numItems==1?" item ":" items ") +"loaded");
1296   }
1297  
1298 + void MainWindow::rowsWereChangedInDropTableWidget(){
1299 +    // We have changed rows, we have now unsaved changes.
1300 +    if(!this->unsavedChangesExist){
1301 +        this->unsavedChangesExist = true;
1302 +        setVagoWindowTitle();
1303 +    }
1304 + }
1305 +
1306   void MainWindow::on_tbCommand_clicked()
1307   {
1308      //Show preferences
# Line 1313 | Line 1367 | void MainWindow::on_actionSave_Project_t
1367  
1368   }
1369  
1370 + // New Project
1371 + void MainWindow::on_actionNew_Project_triggered()
1372 + {
1373 +    if(this->vagoSettings->value("AskSaveProject").toBool() && this->unsavedChangesExist){
1374 +        QMessageBox::StandardButton result = askToSaveCurrentProject();
1375 +        if(result == QMessageBox::StandardButton::Cancel){
1376 +            return;
1377 +        }
1378 +    }
1379 +
1380 +    QList<DropTableWidget*> myTables = getAllTableWidgets();
1381 +
1382 +    for(DropTableWidget* const currTable : myTables){
1383 +        clearTableNoPrompt(currTable);
1384 +    }
1385 +
1386 +    this->lastProjectFilePath=""; // clear last project file path
1387 +    this->unsavedChangesExist = false;
1388 +
1389 +    setVagoWindowTitle(); // update vago title
1390 + }
1391 +
1392   void MainWindow::on_actionSave_triggered()
1393   {
1394      if(this->lastProjectFilePath.isEmpty()){
# Line 1477 | Line 1553 | void MainWindow::dtContextMenu(DropTable
1553      else if(selectedOption==moveUp.get()){
1554          qSort(selectedRows); //let's order the selections by the row number, so we know exactly how to swap it
1555          myTable->swapPositions(selectedRows,-1);
1556 +        rowsWereChangedInDropTableWidget();
1557      }
1558      else if(selectedOption==moveDown.get()){
1559          qSort(selectedRows);
1560          myTable->swapPositions(selectedRows,+1);
1561 +        rowsWereChangedInDropTableWidget();
1562      }
1563      else if(selectedOption==changeOptions.get()){
1564          changeToCurrentSettings(selectedRows,myTable);
# Line 1539 | Line 1617 | void MainWindow::dtContextMenu(DropTable
1617              result+=QString::number(disabledCount) + (disabledCount==1?" item ":" items ") + "Disabled";
1618          }
1619  
1620 +        rowsWereChangedInDropTableWidget();
1621          showSuccessStatusMessage(result);
1622      }
1623   }
# Line 1564 | Line 1643 | void MainWindow::changeToCurrentSettings
1643          myTable->updateTableToolTips(row);
1644      }
1645  
1646 +    rowsWereChangedInDropTableWidget();
1647      showSuccessStatusMessage(QString::number(rows.size()) + (rows.size()==1?" item ":" items ")+ "changed to the current settings");
1648   }
1649  
# Line 1587 | Line 1667 | void MainWindow::changeItemsOutput(DropT
1667          myTable->updateTableToolTips(row);
1668      }
1669  
1670 +    rowsWereChangedInDropTableWidget();
1671      showSuccessStatusMessage(QString::number(rows.size()) + (rows.size()==1?" item ":" items ")+ "changed the output to "+(newOutput!=this->workspaceLocation?Util::cutName(newOutput):"Vago workspace"));
1672   }
1673  
# Line 1677 | Line 1758 | void MainWindow::saveProjectState(const
1758      pugi::xml_document doc;
1759  
1760      pugi::xml_node rootNode = doc.append_child("VagoProject");
1761 <    rootNode.append_attribute("vagoVersion").set_value(GlobalVars::AppVersion.toUtf8().constData());
1761 >    rootNode.append_attribute("vagoVersion").set_value(GlobalVars::LastCompatibleVersion.toUtf8().constData());
1762  
1763      foreach(DropTableWidget* const &myTable, tableWidgets){
1764          saveProjectWidget(rootNode, myTable);
# Line 1691 | Line 1772 | void MainWindow::saveProjectState(const
1772      this->vagoSettings->setValue("LastProjectPath",QFileInfo(filePath).absoluteDir().path());
1773  
1774      this->lastProjectFilePath = filePath;
1775 +    this->unsavedChangesExist = false;
1776  
1777      addNewRecentProject(filePath);
1778  
# Line 1843 | Line 1925 | void MainWindow::setVagoWindowTitle(){
1925          vagoTitle += Util::cutNameWithoutBackSlash(this->lastProjectFilePath);
1926      }
1927  
1928 +    if(this->unsavedChangesExist){
1929 +        vagoTitle += "*";
1930 +    }
1931 +
1932      setWindowTitle(vagoTitle);
1933   }
1934  
# Line 1915 | Line 2001 | QList<DropTableWidget*> MainWindow::getA
2001   void MainWindow::loadProjectState(const QString &filePath)
2002   {
2003  
2004 +    if(this->vagoSettings->value("AskSaveProject").toBool() && this->unsavedChangesExist){
2005 +        QMessageBox::StandardButton result = askToSaveCurrentProject();
2006 +        if(result == QMessageBox::StandardButton::Cancel){
2007 +            return;
2008 +        }
2009 +    }
2010 +
2011      QString statusError = "Couldn't load project.";
2012  
2013      pugi::xml_document doc;
# Line 1970 | Line 2063 | void MainWindow::loadProjectState(const
2063      this->vagoSettings->setValue("LastProjectPath",QFileInfo(filePath).absoluteDir().path());
2064  
2065      this->lastProjectFilePath = filePath;
2066 +    this->unsavedChangesExist = false;
2067  
2068      addNewRecentProject(filePath);
2069  

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)