diff -r 5d201ee4a9c3 -r b05af0bab735 src/main.cpp --- a/src/main.cpp Tue Jun 07 01:37:26 2022 +0300 +++ b/src/main.cpp Tue Jun 07 20:44:19 2022 +0300 @@ -1,6 +1,7 @@ #include #include #include +#include #include "mainwindow.h" #include "ui_mainwindow.h" #include "version.h" @@ -126,7 +127,13 @@ static EditorTabWidget* currentTabWidget(Ui_MainWindow* ui) { - return qobject_cast(ui->tabs->currentWidget()); + QMdiSubWindow* activeSubWindow = ui->mdiArea->activeSubWindow(); + if (activeSubWindow == nullptr) { + return nullptr; + } + else { + return qobject_cast(activeSubWindow->widget()); + } }; @@ -141,12 +148,14 @@ static void handleTabCloseButton(Ui_MainWindow* ui, DocumentManager* documents, int tabIndex) { + /* if (tabIndex >= 0 and tabIndex < ui->tabs->count()) { EditorTabWidget* tab = qobject_cast(ui->tabs->widget(tabIndex)); if (tab != nullptr) { closeDocument(documents, tab); } } + */ } static std::optional findCurrentModelId(Ui_MainWindow* ui, DocumentManager* documents) @@ -201,8 +210,8 @@ Ui_MainWindow* ui, const gl::RenderPreferences* renderPreferences) { - for (int i = 0; i < ui->tabs->count(); i += 1) { - EditorTabWidget* tab = qobject_cast(ui->tabs->widget(i)); + for (QMdiSubWindow* subWindow : ui->mdiArea->subWindowList()) { + EditorTabWidget* tab = qobject_cast(subWindow->widget()); if (tab != nullptr) { tab->canvas->setRenderPreferences(*renderPreferences); } @@ -275,6 +284,7 @@ updateRecentlyOpenedDocumentsMenu(); colorTable = loadColors(&libraries); updateRenderPreferences(&ui, &renderPreferences); + ui.mdiArea->setViewMode(static_cast(settings.viewMode())); ui.retranslateUi(&mainWindow); }; const auto addRecentlyOpenedFile = [&](const QString& path){ @@ -302,15 +312,13 @@ mainWindow.statusBar()->showMessage(newStatusText); }); const QFileInfo fileInfo{*documents.modelPath(modelId)}; - ui.tabs->addTab(document, tabName(fileInfo)); - ui.tabs->setCurrentWidget(document); + QMdiSubWindow* subWindow = ui.mdiArea->addSubWindow(document); + subWindow->setWindowTitle(tabName(fileInfo)); + subWindow->show(); document->restoreSplitterState(documentSplitterState); }; - const auto newModel = [&openModelForEditing](DocumentManager* documents){ - openModelForEditing(documents->newModel()); - }; - QObject::connect(ui.actionNew, &QAction::triggered, [&newModel, &documents]{ - newModel(&documents); + QObject::connect(ui.actionNew, &QAction::triggered, [&]{ + openModelForEditing(documents.newModel()); }); QObject::connect(ui.actionOpen, &QAction::triggered, [&]{ const QString path = getOpenModelPath(&mainWindow); @@ -378,7 +386,10 @@ QString error; QTextStream errorStream{&error}; documents.setModelPath(*modelId, newPath, libraries, errorStream); - ui.tabs->setTabText(ui.tabs->currentIndex(), QFileInfo{newPath}.fileName()); + QMdiSubWindow* const subWindow = ui.mdiArea->currentSubWindow(); + if (subWindow != nullptr) { + subWindow->setWindowTitle(tabName(QFileInfo{newPath})); + } save(*modelId); } } @@ -398,9 +409,11 @@ } } }); - QObject::connect(ui.tabs, &QTabWidget::tabCloseRequested, [&](int index){ + /* + QObject::connect(ui.mdiArea, &QTabWidget::tabCloseRequested, [&](int index){ handleTabCloseButton(&ui, &documents, index); }); + */ QObject::connect(ui.actionDrawAxes, &QAction::triggered, [&](bool drawAxes){ renderPreferences.drawAxes = drawAxes; saveSettings(); @@ -418,7 +431,6 @@ mainWindow.restoreGeometry(settings.mainWindowGeometry()); restoreSettings(); updateRenderPreferences(&ui, &renderPreferences); - newModel(&documents); mainWindow.show(); const int result = app.exec(); saveSettings();