diff src/gui/dialog/settings.cpp @ 68:2417121d894e

*: normalize usage of layouts before, I used them two ways, once was by setting the layout later by using setLayout(QWidget), and the other was just using the constructor. I find the constructor to be easier to read, so I chose that one.
author Paper <mrpapersonic@gmail.com>
date Mon, 02 Oct 2023 21:33:25 -0400
parents fe719c109dbc
children 27a19dd6cba1
line wrap: on
line diff
--- a/src/gui/dialog/settings.cpp	Mon Oct 02 07:06:44 2023 -0400
+++ b/src/gui/dialog/settings.cpp	Mon Oct 02 21:33:25 2023 -0400
@@ -1,14 +1,10 @@
 #include "gui/dialog/settings.h"
 #include "gui/widgets/sidebar.h"
 #include "gui/widgets/text.h"
-#include <QComboBox>
 #include <QDialogButtonBox>
-#include <QGroupBox>
-#include <QHBoxLayout>
-#include <QPlainTextDocumentLayout>
-#include <QPlainTextEdit>
 #include <QStackedWidget>
 #include <QVBoxLayout>
+#include <QHBoxLayout>
 #include <QWidget>
 
 SettingsPage::SettingsPage(QWidget* parent, QString title) : QWidget(parent) {
@@ -36,11 +32,10 @@
 	tab_widget = new QTabWidget(this);
 	tab_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
 
-	QVBoxLayout* layout = new QVBoxLayout;
+	QVBoxLayout* layout = new QVBoxLayout(this);
 	layout->setContentsMargins(0, 0, 0, 0);
 	layout->addWidget(page_title);
 	layout->addWidget(tab_widget);
-	setLayout(layout);
 }
 
 void SettingsPage::SetTitle(QString title) {
@@ -56,7 +51,7 @@
 }
 
 void SettingsDialog::OnOK() {
-	QStackedWidget* stacked = reinterpret_cast<QStackedWidget*>(layout->itemAt(1)->widget());
+	QStackedWidget* stacked = reinterpret_cast<QStackedWidget*>(layout()->itemAt(1)->widget());
 	for (int i = 0; i < stacked->count(); i++) {
 		reinterpret_cast<SettingsPage*>(stacked->widget(i))->SaveInfo();
 	}
@@ -84,25 +79,24 @@
 	font.setPointSize(9);
 	sidebar->setFont(font);
 
-	QPalette pal;
-	pal.setColor(QPalette::Window, Qt::white);
+	QPalette pal(sidebar->palette());
+	pal.setColor(QPalette::Base, pal.color(QPalette::Window));
 	sidebar->setPalette(pal);
 
 	sidebar->setFixedWidth(158);
 	sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
 
-	QStackedWidget* stacked = new QStackedWidget;
+	QStackedWidget* stacked = new QStackedWidget(this);
 	stacked->addWidget(new SettingsPageServices(stacked));
 	stacked->addWidget(new SettingsPageApplication(stacked));
 	stacked->setCurrentIndex(0);
 
 	connect(sidebar, &QListWidget::currentRowChanged, stacked, &QStackedWidget::setCurrentIndex);
 
-	layout = new QHBoxLayout;
+	QHBoxLayout* layout = new QHBoxLayout(widget);
 	layout->addWidget(sidebar);
 	layout->addWidget(stacked);
 	layout->setContentsMargins(0, 0, 0, 0);
-	widget->setLayout(layout);
 
 	QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
 	connect(button_box, &QDialogButtonBox::accepted, this, &SettingsDialog::OnOK);
@@ -111,7 +105,6 @@
 	QVBoxLayout* buttons_layout = new QVBoxLayout(this);
 	buttons_layout->addWidget(widget);
 	buttons_layout->addWidget(button_box);
-	setLayout(buttons_layout);
 }
 
 #include "gui/dialog/moc_settings.cpp"