closeProject() (#34 & #35)

This commit is contained in:
garak 2018-09-20 00:45:11 -04:00
parent d7641b4e9f
commit 20b1836ced
3 changed files with 44 additions and 17 deletions

View file

@ -54,8 +54,15 @@ MainWindow::MainWindow(QWidget *parent) :
if (settings.contains(key)) {
QString default_dir = settings.value(key).toStringList().last();
if (!default_dir.isNull()) {
qDebug() << QString("default_dir: '%1'").arg(default_dir);
openProject(default_dir);
QDir dir(default_dir);
if (dir.exists()) {
qDebug() << QString("default_dir: '%1'").arg(default_dir);
openProject(default_dir);
}
else {
qDebug() << "No project found at" << default_dir;
closeProject();
}
}
}
@ -101,6 +108,12 @@ void MainWindow::openProject(QString dir) {
setStatusBarMessage(QString("Opened project %1").arg(dir));
}
void MainWindow::closeProject() {
QSettings settings;
settings.remove("recent_projects");
//ui->setupUi(this);
}
QString MainWindow::getDefaultMap() {
if (editor && editor->project) {
QList<QStringList> names = editor->project->groupedMapNames;
@ -156,6 +169,12 @@ void MainWindow::on_action_Open_Project_triggered()
}
}
void MainWindow::on_action_Close_Project_triggered()
{
closeProject();
QApplication::quit();
}
void MainWindow::setMap(QString map_name) {
// if clicking on map group, open first map in group
if (map_name.startsWith("gMapGroup")) {
@ -677,7 +696,7 @@ void MainWindow::scaleMapView(int s) {
auto newWidth = floor((editor->scene->width() + 8) * pow(base,exp) + 2);
auto newHeight = floor((editor->scene->height() + 8) * pow(base,exp) + 2);
ui->graphicsView_Map->setFixedSize(newWidth, newHeight);
ui->graphicsView_Objects_Map->setFixedSize(newWidth, newHeight);
}

View file

@ -30,6 +30,7 @@ public slots:
private slots:
void on_action_Open_Project_triggered();
void on_action_Close_Project_triggered();
void on_mapList_activated(const QModelIndex &index);
void on_action_Save_Project_triggered();
void openWarpMap(QString map_name, QString warp_num);
@ -133,6 +134,7 @@ private:
void populateMapList();
QString getExistingDirectory(QString);
void openProject(QString dir);
void closeProject();
QString getDefaultMap();
void setRecentMap(QString map_name);
QStandardItem* createMapItem(QString mapName, int groupNum, int inGroupNum);

View file

@ -378,8 +378,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>469</width>
<height>608</height>
<width>545</width>
<height>587</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_8">
@ -687,8 +687,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>324</width>
<height>77</height>
<width>256</width>
<height>74</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_7">
@ -797,10 +797,10 @@
</property>
<property name="geometry">
<rect>
<x>0</x>
<x>8</x>
<y>0</y>
<width>307</width>
<height>387</height>
<width>222</width>
<height>353</height>
</rect>
</property>
<property name="sizePolicy">
@ -1116,8 +1116,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>381</width>
<height>657</height>
<width>371</width>
<height>643</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_7">
@ -1294,8 +1294,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>432</width>
<height>596</height>
<width>428</width>
<height>578</height>
</rect>
</property>
<property name="sizePolicy">
@ -1914,8 +1914,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>826</width>
<height>557</height>
<width>818</width>
<height>539</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_14">
@ -2087,7 +2087,7 @@
<x>0</x>
<y>0</y>
<width>1117</width>
<height>21</height>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@ -2095,6 +2095,7 @@
<string>File</string>
</property>
<addaction name="action_Open_Project"/>
<addaction name="action_Close_Project"/>
<addaction name="action_Save"/>
<addaction name="action_Save_Project"/>
<addaction name="separator"/>
@ -2268,6 +2269,11 @@
<string>P</string>
</property>
</action>
<action name="action_Close_Project">
<property name="text">
<string>Close Project</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>