annotate src/gui/dialog/settings.cc @ 102:b315f3759c56

*: big patch 1. use a wrapper for mINI that enables case sensitivity (personal preference) 2. rename dark_theme.cc to theme.cc and change it to be a class 3. include the "dep" folder so we don't have stupidity in json.h or ini.h 4. I think the graph was also tweaked a lot in this, nothing is constexpr and size is found at runtime...
author Paper <mrpapersonic@gmail.com>
date Fri, 03 Nov 2023 21:32:52 -0400
parents 9b2b41f83a5e
children 2004b41d4a59
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
1 #include "gui/dialog/settings.h"
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents: 36
diff changeset
2 #include "gui/widgets/sidebar.h"
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents: 36
diff changeset
3 #include "gui/widgets/text.h"
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
4 #include <QDialogButtonBox>
76
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 74
diff changeset
5 #include <QHBoxLayout>
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 74
diff changeset
6 #include <QLabel>
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
7 #include <QStackedWidget>
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
8 #include <QVBoxLayout>
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
9 #include <QWidget>
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
10
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
11 SettingsPage::SettingsPage(QWidget* parent, QString title) : QWidget(parent) {
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
12 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
13 page_title = new QLabel(title, this);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
14 page_title->setWordWrap(false);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
15 page_title->setFrameShape(QFrame::Panel);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
16 page_title->setFrameShadow(QFrame::Sunken);
36
2743011a6042 *: mass update
Paper <mrpapersonic@gmail.com>
parents: 15
diff changeset
17
2743011a6042 *: mass update
Paper <mrpapersonic@gmail.com>
parents: 15
diff changeset
18 QFont font(page_title->font());
77
6f7385bd334c *: update
Paper <mrpapersonic@gmail.com>
parents: 76
diff changeset
19 font.setPixelSize(12);
36
2743011a6042 *: mass update
Paper <mrpapersonic@gmail.com>
parents: 15
diff changeset
20 font.setWeight(QFont::Bold);
2743011a6042 *: mass update
Paper <mrpapersonic@gmail.com>
parents: 15
diff changeset
21 page_title->setFont(font);
2743011a6042 *: mass update
Paper <mrpapersonic@gmail.com>
parents: 15
diff changeset
22
102
b315f3759c56 *: big patch
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
23 {
b315f3759c56 *: big patch
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
24 QPalette pal = page_title->palette();
b315f3759c56 *: big patch
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
25 pal.setColor(QPalette::Window, QColor(0xAB, 0xAB, 0xAB));
b315f3759c56 *: big patch
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
26 pal.setColor(QPalette::WindowText, Qt::white);
b315f3759c56 *: big patch
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
27 page_title->setPalette(pal);
b315f3759c56 *: big patch
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
28 }
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents: 36
diff changeset
29 page_title->setAutoFillBackground(true);
36
2743011a6042 *: mass update
Paper <mrpapersonic@gmail.com>
parents: 15
diff changeset
30
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
31 page_title->setFixedHeight(23);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
32 page_title->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
33 page_title->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents: 36
diff changeset
34
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
35 tab_widget = new QTabWidget(this);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
36 tab_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
37
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 64
diff changeset
38 QVBoxLayout* layout = new QVBoxLayout(this);
62
4c6dd5999b39 *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
39 layout->setContentsMargins(0, 0, 0, 0);
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
40 layout->addWidget(page_title);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
41 layout->addWidget(tab_widget);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
42 }
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
43
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
44 void SettingsPage::SetTitle(QString title) {
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
45 page_title->setText(title);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
46 }
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
47
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
48 void SettingsPage::AddTab(QWidget* tab, QString title) {
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
49 tab_widget->addTab(tab, title);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
50 }
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
51
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
52 void SettingsPage::SaveInfo() {
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
53 // no-op... child classes will implement this
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
54 }
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
55
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
56 void SettingsDialog::OnOK() {
7
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
57 for (int i = 0; i < stacked->count(); i++) {
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
58 reinterpret_cast<SettingsPage*>(stacked->widget(i))->SaveInfo();
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
59 }
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
60 QDialog::accept();
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
61 }
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
62
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
63 SettingsDialog::SettingsDialog(QWidget* parent) : QDialog(parent) {
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
64 setFixedSize(755, 566);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
65 setWindowTitle(tr("Settings"));
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
66 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
67 QWidget* widget = new QWidget(this);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
68 widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
69 sidebar = new SideBar(widget);
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
70 sidebar->setCurrentItem(sidebar->AddItem(tr("Services"), SideBar::CreateIcon(":/icons/24x24/globe.png")));
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
71 // sidebar->AddItem(tr("Library"), SideBar::CreateIcon(":/icons/24x24/inbox-film.png"));
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
72 sidebar->AddItem(tr("Application"), SideBar::CreateIcon(":/icons/24x24/application-sidebar-list.png"));
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
73 // sidebar->AddItem(tr("Recognition"), SideBar::CreateIcon(":/icons/24x24/question.png"));
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
74 // sidebar->AddItem(tr("Sharing"), SideBar::CreateIcon(":/icons/24x24/megaphone.png"));
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
75 // sidebar->AddItem(tr("Torrents"), SideBar::CreateIcon(":/icons/24x24/feed.png"));
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
76 // sidebar->AddItem(tr("Advanced"), SideBar::CreateIcon(":/icons/24x24/gear.png"));
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
77 sidebar->setIconSize(QSize(24, 24));
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
78 sidebar->setFrameShape(QFrame::Box);
36
2743011a6042 *: mass update
Paper <mrpapersonic@gmail.com>
parents: 15
diff changeset
79
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 64
diff changeset
80 QPalette pal(sidebar->palette());
69
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
81 sidebar->SetBackgroundColor(pal.color(QPalette::Base));
36
2743011a6042 *: mass update
Paper <mrpapersonic@gmail.com>
parents: 15
diff changeset
82
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
83 sidebar->setFixedWidth(158);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
84 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
85
69
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
86 stacked = new QStackedWidget(this);
7
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
87 stacked->addWidget(new SettingsPageServices(stacked));
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
88 stacked->addWidget(new SettingsPageApplication(stacked));
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
89 stacked->setCurrentIndex(0);
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
90
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
91 connect(sidebar, &QListWidget::currentRowChanged, stacked, &QStackedWidget::setCurrentIndex);
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
92
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 64
diff changeset
93 QHBoxLayout* layout = new QHBoxLayout(widget);
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
94 layout->addWidget(sidebar);
7
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
95 layout->addWidget(stacked);
62
4c6dd5999b39 *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
96 layout->setContentsMargins(0, 0, 0, 0);
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
97
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
98 QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
99 connect(button_box, &QDialogButtonBox::accepted, this, &SettingsDialog::OnOK);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
100 connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
101
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
102 QVBoxLayout* buttons_layout = new QVBoxLayout(this);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
103 buttons_layout->addWidget(widget);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
104 buttons_layout->addWidget(button_box);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
105 }
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
106
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
107 #include "gui/dialog/moc_settings.cpp"