# HG changeset patch # User Teemu Piippo # Date 1654623859 -10800 # Node ID b05af0bab735909849419c77e2c315ad96308dd3 # Parent 5d201ee4a9c36f18722384c279c704e98de42897 Replaced the tab widget with an MDI area diff -r 5d201ee4a9c3 -r b05af0bab735 src/configurationoptions.txt --- a/src/configurationoptions.txt Tue Jun 07 01:37:26 2022 +0300 +++ b/src/configurationoptions.txt Tue Jun 07 20:44:19 2022 +0300 @@ -20,6 +20,7 @@ option MainWindowGeometry = QByteArray{} option MainSplitterState = QByteArray{} option RecentFiles = QStringList{} +option ViewMode = 1 # File management options option Libraries = QVector{} 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(); diff -r 5d201ee4a9c3 -r b05af0bab735 src/mainwindow.ui --- a/src/mainwindow.ui Tue Jun 07 01:37:26 2022 +0300 +++ b/src/mainwindow.ui Tue Jun 07 20:44:19 2022 +0300 @@ -16,10 +16,19 @@ - + + + QMdiArea::TabbedView + + + true + true + + true + @@ -30,7 +39,7 @@ 0 0 800 - 27 + 22 diff -r 5d201ee4a9c3 -r b05af0bab735 src/settingseditor/settingseditor.cpp --- a/src/settingseditor/settingseditor.cpp Tue Jun 07 01:37:26 2022 +0300 +++ b/src/settingseditor/settingseditor.cpp Tue Jun 07 20:44:19 2022 +0300 @@ -1,4 +1,5 @@ #include +#include #include "gl/common.h" #include "keyboardshortcutseditor.h" #include "settingseditor.h" @@ -17,6 +18,9 @@ defaultKeyboardShortcuts{defaultKeyboardShortcuts} { this->ui.setupUi(this); + this->ui.keyboardShortcutsView->setModel(new KeyboardShortcutsEditor{parent, this}); + this->ui.viewModeButtonGroup->setId(this->ui.viewModeTabs, int{QMdiArea::TabbedView}); + this->ui.viewModeButtonGroup->setId(this->ui.viewModeSubWindows, int{QMdiArea::SubWindowView}); this->loadLocales(); this->setDefaults(); QVBoxLayout* layout = new QVBoxLayout{this}; @@ -27,7 +31,6 @@ &SettingsEditor::accepted, this, &SettingsEditor::handleAccepted); - this->ui.keyboardShortcutsView->setModel(new KeyboardShortcutsEditor{parent, this}); } SettingsEditor::~SettingsEditor() @@ -43,6 +46,10 @@ this->settings->setSelectedColor(this->ui.selectedColorButton->selectedColor()); this->settings->setLineThickness(static_cast(this->ui.lineThickness->value())); this->settings->setLineAntiAliasing(this->ui.lineAntiAliasing->isChecked()); + const int viewMode = this->ui.viewModeButtonGroup->checkedId(); + if (viewMode != -1) { + this->settings->setViewMode(viewMode); + } this->librariesEditor.saveSettings(this->settings); } @@ -76,6 +83,10 @@ this->ui.selectedColorButton->setSelectedColor(this->settings->selectedColor()); this->ui.lineThickness->setValue(static_cast(this->settings->lineThickness())); this->ui.lineAntiAliasing->setChecked(this->settings->lineAntiAliasing()); + auto* const viewModeButton = this->ui.viewModeButtonGroup->button(this->settings->viewMode()); + if (viewModeButton != nullptr) { + viewModeButton->setChecked(true); + } } void SettingsEditor::setCurrentLanguage(const QString& localeCode) diff -r 5d201ee4a9c3 -r b05af0bab735 src/settingseditor/settingseditor.ui --- a/src/settingseditor/settingseditor.ui Tue Jun 07 01:37:26 2022 +0300 +++ b/src/settingseditor/settingseditor.ui Tue Jun 07 20:44:19 2022 +0300 @@ -68,6 +68,56 @@ + + + + View mode: + + + + + + + + + Arrange opened documents using tabs + + + Tabs + + + viewModeButtonGroup + + + + + + + Arrange opened documents using resizable and movable subwindows + + + Subwindows + + + viewModeButtonGroup + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + @@ -207,6 +257,18 @@
widgets/colorbutton.h
+ + language + viewModeTabs + viewModeSubWindows + mainColorButton + selectedColorButton + backgroundColorButton + lineThickness + lineAntiAliasing + tabWidget + keyboardShortcutsView + @@ -242,4 +304,7 @@ + + +