Don't create more than one settings editor

Tue, 28 Jun 2022 13:03:21 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Tue, 28 Jun 2022 13:03:21 +0300
changeset 285
99af8bf63d10
parent 284
9266239cf72b
child 286
04478da357d0

Don't create more than one settings editor

src/main.cpp file | annotate | diff | comparison | revisions
src/settingseditor/settingseditor.cpp file | annotate | diff | comparison | revisions
src/settingseditor/settingseditor.h file | annotate | diff | comparison | revisions
src/settingseditor/settingseditor.ui file | annotate | diff | comparison | revisions
--- a/src/main.cpp	Tue Jun 28 12:47:46 2022 +0300
+++ b/src/main.cpp	Tue Jun 28 13:03:21 2022 +0300
@@ -588,13 +588,13 @@
 		}
 	});
 	QObject::connect(ui.actionSettingsEditor, &QAction::triggered, [&]{
-		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();
+		if (ui.mdiArea->findChildren<SettingsEditor*>().isEmpty()) {
+			SettingsEditor* settingsEditor = new SettingsEditor{defaultKeyboardShortcuts, ui.mdiArea};
+			QObject::connect(&settingsChanged, &Signal::triggered, settingsEditor, &SettingsEditor::loadSettings);
+			QObject::connect(settingsEditor, &SettingsEditor::settingsChanged, restoreSettings);
+			settingsEditor->setAttribute(Qt::WA_DeleteOnClose);
+			settingsEditor->show();
+		}
 	});
 	QObject::connect(ui.actionQuit, &QAction::triggered, &mainWindow, &QMainWindow::close);
 #if 0
--- a/src/settingseditor/settingseditor.cpp	Tue Jun 28 12:47:46 2022 +0300
+++ b/src/settingseditor/settingseditor.cpp	Tue Jun 28 13:03:21 2022 +0300
@@ -10,19 +10,22 @@
 	const uiutilities::KeySequenceMap& defaultKeyboardShortcuts,
 	QWidget* parent
 ) :
-	QDialog{parent},
+	QMdiSubWindow{parent},
 	ui{*new Ui_SettingsEditor},
 	libraries{this},
 	librariesEditor{this},
 	defaultKeyboardShortcuts{defaultKeyboardShortcuts}
 {
-	this->ui.setupUi(this);
+	QWidget* widget = new QWidget{this};
+	this->ui.setupUi(widget);
+	this->setWidget(widget);
 	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->loadSettings();
 	this->setWindowTitle(tr("Settings"));
+	this->setWindowIcon(QIcon{":/icons/settings-outline.png"});
 	this->librariesEditor.setModel(&libraries);
 	QVBoxLayout* layout = new QVBoxLayout{this};
 	layout->addWidget(&librariesEditor);
--- a/src/settingseditor/settingseditor.h	Tue Jun 28 12:47:46 2022 +0300
+++ b/src/settingseditor/settingseditor.h	Tue Jun 28 13:03:21 2022 +0300
@@ -1,11 +1,11 @@
 #pragma once
-#include <QDialog>
+#include <QMdiSubWindow>
 #include "src/basics.h"
 #include "src/libraries.h"
 #include "src/uiutilities.h"
 #include "src/settingseditor/librarieseditor.h"
 
-class SettingsEditor : public QDialog
+class SettingsEditor : public QMdiSubWindow
 {
 	Q_OBJECT
 public:
--- a/src/settingseditor/settingseditor.ui	Tue Jun 28 12:47:46 2022 +0300
+++ b/src/settingseditor/settingseditor.ui	Tue Jun 28 13:03:21 2022 +0300
@@ -1,21 +1,27 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <ui version="4.0">
  <class>SettingsEditor</class>
- <widget class="QDialog" name="SettingsEditor">
+ <widget class="QWidget" name="SettingsEditor">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>621</width>
-    <height>572</height>
+    <width>718</width>
+    <height>629</height>
    </rect>
   </property>
   <property name="windowTitle">
-   <string>Dialog</string>
+   <string>Settings</string>
   </property>
   <layout class="QVBoxLayout" name="verticalLayout_4">
    <item>
     <widget class="QScrollArea" name="scrollArea">
+     <property name="minimumSize">
+      <size>
+       <width>96</width>
+       <height>96</height>
+      </size>
+     </property>
      <property name="widgetResizable">
       <bool>true</bool>
      </property>
@@ -24,8 +30,8 @@
        <rect>
         <x>0</x>
         <y>0</y>
-        <width>597</width>
-        <height>504</height>
+        <width>694</width>
+        <height>561</height>
        </rect>
       </property>
       <layout class="QVBoxLayout" name="verticalLayout">
@@ -277,53 +283,8 @@
    <header>widgets/colorbutton.h</header>
   </customwidget>
  </customwidgets>
- <tabstops>
-  <tabstop>language</tabstop>
-  <tabstop>viewModeTabs</tabstop>
-  <tabstop>viewModeSubWindows</tabstop>
-  <tabstop>mainColorButton</tabstop>
-  <tabstop>selectedColorButton</tabstop>
-  <tabstop>backgroundColorButton</tabstop>
-  <tabstop>lineThickness</tabstop>
-  <tabstop>lineAntiAliasing</tabstop>
-  <tabstop>tabWidget</tabstop>
-  <tabstop>keyboardShortcutsView</tabstop>
- </tabstops>
  <resources/>
- <connections>
-  <connection>
-   <sender>buttonBox</sender>
-   <signal>accepted()</signal>
-   <receiver>SettingsEditor</receiver>
-   <slot>accept()</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>227</x>
-     <y>394</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>157</x>
-     <y>274</y>
-    </hint>
-   </hints>
-  </connection>
-  <connection>
-   <sender>buttonBox</sender>
-   <signal>rejected()</signal>
-   <receiver>SettingsEditor</receiver>
-   <slot>reject()</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>295</x>
-     <y>400</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>286</x>
-     <y>274</y>
-    </hint>
-   </hints>
-  </connection>
- </connections>
+ <connections/>
  <buttongroups>
   <buttongroup name="viewModeButtonGroup"/>
  </buttongroups>

mercurial