Mercurial > minori
diff src/dialog/settings.cpp @ 7:07a9095eaeed
Update
Refactored some code, moved some around
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Thu, 24 Aug 2023 23:11:38 -0400 |
parents | 1d82f6e04d7d |
children |
line wrap: on
line diff
--- a/src/dialog/settings.cpp Wed Aug 16 00:49:17 2023 -0400 +++ b/src/dialog/settings.cpp Thu Aug 24 23:11:38 2023 -0400 @@ -6,7 +6,7 @@ #include <QComboBox> #include <QGroupBox> #include <QWidget> -#include <QTextDocument> +#include <QStackedWidget> #include "settings.h" #include "sidebar.h" #include "ui_utils.h" @@ -44,15 +44,10 @@ // no-op... child classes will implement this } -void SettingsDialog::OnSidebar(QListWidgetItem* item) { - layout->itemAt(1)->widget()->setVisible(false); // old widget - layout->replaceWidget(layout->itemAt(1)->widget(), pages[item->listWidget()->row(item)], Qt::FindDirectChildrenOnly); - pages[item->listWidget()->row(item)]->setVisible(true); // new widget -} - void SettingsDialog::OnOK() { - for (const auto& page : pages) { - page->SaveInfo(); + QStackedWidget* stacked = (QStackedWidget*)layout->itemAt(1)->widget(); + for (int i = 0; i < stacked->count(); i++) { + ((SettingsPage*)stacked->widget(i))->SaveInfo(); } QDialog::accept(); } @@ -77,17 +72,17 @@ sidebar->setStyleSheet("QListWidget { background-color: white; font-size: 12px; }"); sidebar->setFixedWidth(158); sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); - connect(sidebar, &QListWidget::itemActivated, this, &SettingsDialog::OnSidebar); - SettingsPageServices* services_page = new SettingsPageServices(this); - pages.push_back(services_page); - SettingsPageApplication* application_page = new SettingsPageApplication(this); - application_page->setVisible(false); - pages.push_back(application_page); + QStackedWidget* stacked = new QStackedWidget; + stacked->addWidget(new SettingsPageServices(stacked)); + stacked->addWidget(new SettingsPageApplication(stacked)); + stacked->setCurrentIndex(0); + + connect(sidebar, &QListWidget::currentRowChanged, stacked, &QStackedWidget::setCurrentIndex); layout = new QHBoxLayout; layout->addWidget(sidebar); - layout->addWidget(services_page); + layout->addWidget(stacked); layout->setMargin(0); widget->setLayout(layout);