Mercurial > minori
comparison 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 |
comparison
equal
deleted
inserted
replaced
67:442065432549 | 68:2417121d894e |
---|---|
1 #include "gui/dialog/settings.h" | 1 #include "gui/dialog/settings.h" |
2 #include "gui/widgets/sidebar.h" | 2 #include "gui/widgets/sidebar.h" |
3 #include "gui/widgets/text.h" | 3 #include "gui/widgets/text.h" |
4 #include <QComboBox> | |
5 #include <QDialogButtonBox> | 4 #include <QDialogButtonBox> |
6 #include <QGroupBox> | |
7 #include <QHBoxLayout> | |
8 #include <QPlainTextDocumentLayout> | |
9 #include <QPlainTextEdit> | |
10 #include <QStackedWidget> | 5 #include <QStackedWidget> |
11 #include <QVBoxLayout> | 6 #include <QVBoxLayout> |
7 #include <QHBoxLayout> | |
12 #include <QWidget> | 8 #include <QWidget> |
13 | 9 |
14 SettingsPage::SettingsPage(QWidget* parent, QString title) : QWidget(parent) { | 10 SettingsPage::SettingsPage(QWidget* parent, QString title) : QWidget(parent) { |
15 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); | 11 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); |
16 page_title = new QLabel(title, this); | 12 page_title = new QLabel(title, this); |
34 page_title->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); | 30 page_title->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); |
35 | 31 |
36 tab_widget = new QTabWidget(this); | 32 tab_widget = new QTabWidget(this); |
37 tab_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); | 33 tab_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); |
38 | 34 |
39 QVBoxLayout* layout = new QVBoxLayout; | 35 QVBoxLayout* layout = new QVBoxLayout(this); |
40 layout->setContentsMargins(0, 0, 0, 0); | 36 layout->setContentsMargins(0, 0, 0, 0); |
41 layout->addWidget(page_title); | 37 layout->addWidget(page_title); |
42 layout->addWidget(tab_widget); | 38 layout->addWidget(tab_widget); |
43 setLayout(layout); | |
44 } | 39 } |
45 | 40 |
46 void SettingsPage::SetTitle(QString title) { | 41 void SettingsPage::SetTitle(QString title) { |
47 page_title->setText(title); | 42 page_title->setText(title); |
48 } | 43 } |
54 void SettingsPage::SaveInfo() { | 49 void SettingsPage::SaveInfo() { |
55 // no-op... child classes will implement this | 50 // no-op... child classes will implement this |
56 } | 51 } |
57 | 52 |
58 void SettingsDialog::OnOK() { | 53 void SettingsDialog::OnOK() { |
59 QStackedWidget* stacked = reinterpret_cast<QStackedWidget*>(layout->itemAt(1)->widget()); | 54 QStackedWidget* stacked = reinterpret_cast<QStackedWidget*>(layout()->itemAt(1)->widget()); |
60 for (int i = 0; i < stacked->count(); i++) { | 55 for (int i = 0; i < stacked->count(); i++) { |
61 reinterpret_cast<SettingsPage*>(stacked->widget(i))->SaveInfo(); | 56 reinterpret_cast<SettingsPage*>(stacked->widget(i))->SaveInfo(); |
62 } | 57 } |
63 QDialog::accept(); | 58 QDialog::accept(); |
64 } | 59 } |
82 | 77 |
83 QFont font(sidebar->font()); | 78 QFont font(sidebar->font()); |
84 font.setPointSize(9); | 79 font.setPointSize(9); |
85 sidebar->setFont(font); | 80 sidebar->setFont(font); |
86 | 81 |
87 QPalette pal; | 82 QPalette pal(sidebar->palette()); |
88 pal.setColor(QPalette::Window, Qt::white); | 83 pal.setColor(QPalette::Base, pal.color(QPalette::Window)); |
89 sidebar->setPalette(pal); | 84 sidebar->setPalette(pal); |
90 | 85 |
91 sidebar->setFixedWidth(158); | 86 sidebar->setFixedWidth(158); |
92 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); | 87 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); |
93 | 88 |
94 QStackedWidget* stacked = new QStackedWidget; | 89 QStackedWidget* stacked = new QStackedWidget(this); |
95 stacked->addWidget(new SettingsPageServices(stacked)); | 90 stacked->addWidget(new SettingsPageServices(stacked)); |
96 stacked->addWidget(new SettingsPageApplication(stacked)); | 91 stacked->addWidget(new SettingsPageApplication(stacked)); |
97 stacked->setCurrentIndex(0); | 92 stacked->setCurrentIndex(0); |
98 | 93 |
99 connect(sidebar, &QListWidget::currentRowChanged, stacked, &QStackedWidget::setCurrentIndex); | 94 connect(sidebar, &QListWidget::currentRowChanged, stacked, &QStackedWidget::setCurrentIndex); |
100 | 95 |
101 layout = new QHBoxLayout; | 96 QHBoxLayout* layout = new QHBoxLayout(widget); |
102 layout->addWidget(sidebar); | 97 layout->addWidget(sidebar); |
103 layout->addWidget(stacked); | 98 layout->addWidget(stacked); |
104 layout->setContentsMargins(0, 0, 0, 0); | 99 layout->setContentsMargins(0, 0, 0, 0); |
105 widget->setLayout(layout); | |
106 | 100 |
107 QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); | 101 QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); |
108 connect(button_box, &QDialogButtonBox::accepted, this, &SettingsDialog::OnOK); | 102 connect(button_box, &QDialogButtonBox::accepted, this, &SettingsDialog::OnOK); |
109 connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject); | 103 connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject); |
110 | 104 |
111 QVBoxLayout* buttons_layout = new QVBoxLayout(this); | 105 QVBoxLayout* buttons_layout = new QVBoxLayout(this); |
112 buttons_layout->addWidget(widget); | 106 buttons_layout->addWidget(widget); |
113 buttons_layout->addWidget(button_box); | 107 buttons_layout->addWidget(button_box); |
114 setLayout(buttons_layout); | |
115 } | 108 } |
116 | 109 |
117 #include "gui/dialog/moc_settings.cpp" | 110 #include "gui/dialog/moc_settings.cpp" |