Mercurial > minori
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 6:1d82f6e04d7d | 7:07a9095eaeed |
|---|---|
| 4 #include <QPlainTextEdit> | 4 #include <QPlainTextEdit> |
| 5 #include <QPlainTextDocumentLayout> | 5 #include <QPlainTextDocumentLayout> |
| 6 #include <QComboBox> | 6 #include <QComboBox> |
| 7 #include <QGroupBox> | 7 #include <QGroupBox> |
| 8 #include <QWidget> | 8 #include <QWidget> |
| 9 #include <QTextDocument> | 9 #include <QStackedWidget> |
| 10 #include "settings.h" | 10 #include "settings.h" |
| 11 #include "sidebar.h" | 11 #include "sidebar.h" |
| 12 #include "ui_utils.h" | 12 #include "ui_utils.h" |
| 13 | 13 |
| 14 SettingsPage::SettingsPage(QWidget* parent, QString title) | 14 SettingsPage::SettingsPage(QWidget* parent, QString title) |
| 42 | 42 |
| 43 void SettingsPage::SaveInfo() { | 43 void SettingsPage::SaveInfo() { |
| 44 // no-op... child classes will implement this | 44 // no-op... child classes will implement this |
| 45 } | 45 } |
| 46 | 46 |
| 47 void SettingsDialog::OnSidebar(QListWidgetItem* item) { | |
| 48 layout->itemAt(1)->widget()->setVisible(false); // old widget | |
| 49 layout->replaceWidget(layout->itemAt(1)->widget(), pages[item->listWidget()->row(item)], Qt::FindDirectChildrenOnly); | |
| 50 pages[item->listWidget()->row(item)]->setVisible(true); // new widget | |
| 51 } | |
| 52 | |
| 53 void SettingsDialog::OnOK() { | 47 void SettingsDialog::OnOK() { |
| 54 for (const auto& page : pages) { | 48 QStackedWidget* stacked = (QStackedWidget*)layout->itemAt(1)->widget(); |
| 55 page->SaveInfo(); | 49 for (int i = 0; i < stacked->count(); i++) { |
| 50 ((SettingsPage*)stacked->widget(i))->SaveInfo(); | |
| 56 } | 51 } |
| 57 QDialog::accept(); | 52 QDialog::accept(); |
| 58 } | 53 } |
| 59 | 54 |
| 60 SettingsDialog::SettingsDialog(QWidget* parent) | 55 SettingsDialog::SettingsDialog(QWidget* parent) |
| 75 sidebar->setIconSize(QSize(24, 24)); | 70 sidebar->setIconSize(QSize(24, 24)); |
| 76 sidebar->setFrameShape(QFrame::Box); | 71 sidebar->setFrameShape(QFrame::Box); |
| 77 sidebar->setStyleSheet("QListWidget { background-color: white; font-size: 12px; }"); | 72 sidebar->setStyleSheet("QListWidget { background-color: white; font-size: 12px; }"); |
| 78 sidebar->setFixedWidth(158); | 73 sidebar->setFixedWidth(158); |
| 79 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); | 74 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); |
| 80 connect(sidebar, &QListWidget::itemActivated, this, &SettingsDialog::OnSidebar); | |
| 81 | 75 |
| 82 SettingsPageServices* services_page = new SettingsPageServices(this); | 76 QStackedWidget* stacked = new QStackedWidget; |
| 83 pages.push_back(services_page); | 77 stacked->addWidget(new SettingsPageServices(stacked)); |
| 84 SettingsPageApplication* application_page = new SettingsPageApplication(this); | 78 stacked->addWidget(new SettingsPageApplication(stacked)); |
| 85 application_page->setVisible(false); | 79 stacked->setCurrentIndex(0); |
| 86 pages.push_back(application_page); | 80 |
| 81 connect(sidebar, &QListWidget::currentRowChanged, stacked, &QStackedWidget::setCurrentIndex); | |
| 87 | 82 |
| 88 layout = new QHBoxLayout; | 83 layout = new QHBoxLayout; |
| 89 layout->addWidget(sidebar); | 84 layout->addWidget(sidebar); |
| 90 layout->addWidget(services_page); | 85 layout->addWidget(stacked); |
| 91 layout->setMargin(0); | 86 layout->setMargin(0); |
| 92 widget->setLayout(layout); | 87 widget->setLayout(layout); |
| 93 | 88 |
| 94 QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); | 89 QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); |
| 95 connect(button_box, &QDialogButtonBox::accepted, this, &SettingsDialog::OnOK); | 90 connect(button_box, &QDialogButtonBox::accepted, this, &SettingsDialog::OnOK); |
