Tue, 28 Jun 2022 12:18:00 +0300
Make settings editor a sub window instead of a dialog
--- a/src/main.cpp Tue Jun 28 11:51:17 2022 +0300 +++ b/src/main.cpp Tue Jun 28 12:18:00 2022 +0300 @@ -566,6 +566,7 @@ QObject::connect(data->canvas.get(), &PartRenderer::message, &messageLog, &MessageLog::addMessage); const QFileInfo fileInfo{*documents.modelPath(modelId)}; ModelSubWindow* subWindow = new ModelSubWindow{modelId, ui.mdiArea}; + subWindow->setMinimumSize({96, 96}); subWindow->setWidget(data->canvas.get()); subWindow->setWindowTitle(tabName(fileInfo)); subWindow->show(); @@ -586,12 +587,13 @@ } }); QObject::connect(ui.actionSettingsEditor, &QAction::triggered, [&]{ - SettingsEditor settingsEditor{defaultKeyboardShortcuts, &mainWindow}; - const int result = settingsEditor.exec(); - if (result == QDialog::Accepted) - { - restoreSettings(); - } + SettingsEditor* settingsEditor = new SettingsEditor{defaultKeyboardShortcuts, &mainWindow}; + QObject::connect(&settingsChanged, &Signal::triggered, settingsEditor, &SettingsEditor::loadSettings); + QObject::connect(settingsEditor, &SettingsEditor::settingsChanged, restoreSettings); + auto subwindow = new QMdiSubWindow{ui.mdiArea}; + subwindow->setAttribute(Qt::WA_DeleteOnClose); + subwindow->setWidget(settingsEditor); + subwindow->show(); }); QObject::connect(ui.actionQuit, &QAction::triggered, &mainWindow, &QMainWindow::close); #if 0 @@ -715,6 +717,9 @@ } } } + else { + checkEditingModeAction(EditingMode::SelectMode); + } updateTitle(); }); ui.messageLog->setModel(&messageLog);
--- a/src/settingseditor/settingseditor.cpp Tue Jun 28 11:51:17 2022 +0300 +++ b/src/settingseditor/settingseditor.cpp Tue Jun 28 12:18:00 2022 +0300 @@ -21,16 +21,19 @@ this->ui.viewModeButtonGroup->setId(this->ui.viewModeTabs, int{QMdiArea::TabbedView}); this->ui.viewModeButtonGroup->setId(this->ui.viewModeSubWindows, int{QMdiArea::SubWindowView}); this->loadLocales(); - this->setDefaults(); + this->loadSettings(); + this->setWindowTitle(tr("Settings")); this->librariesEditor.setModel(&libraries); QVBoxLayout* layout = new QVBoxLayout{this}; layout->addWidget(&librariesEditor); this->ui.tabLdrawLibraries->setLayout(layout); - connect( - this, - &SettingsEditor::accepted, - this, - &SettingsEditor::handleAccepted); + connect(this->ui.buttonBox, &QDialogButtonBox::clicked, + [&](QAbstractButton* button) { + const auto role = this->ui.buttonBox->buttonRole(button); + if (role == QDialogButtonBox::ApplyRole) { + this->saveSettings(); + } + }); } SettingsEditor::~SettingsEditor() @@ -38,7 +41,7 @@ delete &this->ui; } -void SettingsEditor::handleAccepted() +void SettingsEditor::saveSettings() { setSetting<Setting::Locale>(this->ui.language->currentData().toString()); setSetting<Setting::MainColor>(this->ui.mainColorButton->color()); @@ -52,6 +55,7 @@ setSetting<Setting::ViewMode>(static_cast<QMdiArea::ViewMode>(viewMode)); } this->librariesEditor.saveSettings(); + Q_EMIT this->settingsChanged(); } void SettingsEditor::loadLocales() @@ -76,7 +80,7 @@ } } -void SettingsEditor::setDefaults() +void SettingsEditor::loadSettings() { this->libraries.restoreFromSettings(); this->setCurrentLanguage(setting<Setting::Locale>());
--- a/src/settingseditor/settingseditor.h Tue Jun 28 11:51:17 2022 +0300 +++ b/src/settingseditor/settingseditor.h Tue Jun 28 12:18:00 2022 +0300 @@ -12,14 +12,15 @@ SettingsEditor(const uiutilities::KeySequenceMap& defaultKeyboardShortcuts = {}, QWidget* parent = nullptr); ~SettingsEditor(); -private Q_SLOTS: - void handleAccepted(); + Q_SLOT void saveSettings(); + Q_SLOT void loadSettings(); +Q_SIGNALS: + void settingsChanged(); private: class Ui_SettingsEditor& ui; LibrariesModel libraries; LibrariesEditor librariesEditor; const uiutilities::KeySequenceMap defaultKeyboardShortcuts; void loadLocales(); - void setDefaults(); void setCurrentLanguage(const QString& localeCode); };
--- a/src/settingseditor/settingseditor.ui Tue Jun 28 11:51:17 2022 +0300 +++ b/src/settingseditor/settingseditor.ui Tue Jun 28 12:18:00 2022 +0300 @@ -6,8 +6,8 @@ <rect> <x>0</x> <y>0</y> - <width>716</width> - <height>472</height> + <width>645</width> + <height>523</height> </rect> </property> <property name="windowTitle"> @@ -271,7 +271,7 @@ <enum>Qt::Horizontal</enum> </property> <property name="standardButtons"> - <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + <set>QDialogButtonBox::Apply</set> </property> </widget> </item>