annotate src/gui/dialog/settings/application.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 c537996cf67b
children 6d8da6e64d61
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
1 #include "core/session.h"
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
2 #include "gui/dialog/settings.h"
102
b315f3759c56 *: big patch
Paper <mrpapersonic@gmail.com>
parents: 101
diff changeset
3 #include "gui/theme.h"
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
4 #include <QCheckBox>
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
5 #include <QComboBox>
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
6 #include <QGroupBox>
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
7 #include <QHBoxLayout>
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
8 #include <QLabel>
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
9 #include <QPushButton>
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
10 #include <QSizePolicy>
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
11 #include <QVBoxLayout>
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
12
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
13 QWidget* SettingsPageApplication::CreateAnimeListWidget() {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
14 QWidget* result = new QWidget(this);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
15 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
16
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
17 QGroupBox* actions_group_box = new QGroupBox(tr("Actions"), result);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
18 actions_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
19
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
20 /* Actions/Double click */
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
21 QWidget* double_click_widget = new QWidget(actions_group_box);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
22 QLabel* dc_combo_box_label = new QLabel(tr("Double click:"), double_click_widget);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
23 QComboBox* dc_combo_box = new QComboBox(double_click_widget);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
24 dc_combo_box->addItem(tr("View anime info"));
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
25
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
26 QVBoxLayout* double_click_layout = new QVBoxLayout(double_click_widget);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
27 double_click_layout->addWidget(dc_combo_box_label);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
28 double_click_layout->addWidget(dc_combo_box);
62
4c6dd5999b39 *: update
Paper <mrpapersonic@gmail.com>
parents: 36
diff changeset
29 double_click_layout->setContentsMargins(0, 0, 0, 0);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
30
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
31 /* Actions/Middle click */
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
32 QWidget* middle_click_widget = new QWidget(actions_group_box);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
33 QLabel* mc_combo_box_label = new QLabel(tr("Middle click:"), middle_click_widget);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
34 QComboBox* mc_combo_box = new QComboBox(middle_click_widget);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
35 mc_combo_box->addItem(tr("Play next episode"));
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
36
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
37 QVBoxLayout* middle_click_layout = new QVBoxLayout(middle_click_widget);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
38 middle_click_layout->addWidget(mc_combo_box_label);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
39 middle_click_layout->addWidget(mc_combo_box);
62
4c6dd5999b39 *: update
Paper <mrpapersonic@gmail.com>
parents: 36
diff changeset
40 middle_click_layout->setContentsMargins(0, 0, 0, 0);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
41
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
42 /* Actions */
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
43 QHBoxLayout* actions_layout = new QHBoxLayout(actions_group_box);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
44 actions_layout->addWidget(double_click_widget);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
45 actions_layout->addWidget(middle_click_widget);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
46
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
47 QGroupBox* appearance_group_box = new QGroupBox(tr("Appearance"), result);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
48 appearance_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
49
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
50 QLabel* lang_combo_box_label = new QLabel(tr("Title language preference:"), appearance_group_box);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
51 QComboBox* lang_combo_box = new QComboBox(appearance_group_box);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
52 lang_combo_box->addItem(tr("Romaji"));
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
53 lang_combo_box->addItem(tr("Native"));
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
54 lang_combo_box->addItem(tr("English"));
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
55 connect(lang_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
56 [this](int index) { language = static_cast<Anime::TitleLanguage>(index); });
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
57 lang_combo_box->setCurrentIndex(static_cast<int>(language));
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
58
101
c537996cf67b *: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
59 QLabel* theme_combo_box_label = new QLabel(tr("Application theme:"), appearance_group_box);
c537996cf67b *: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
60 QComboBox* theme_combo_box = new QComboBox(appearance_group_box);
c537996cf67b *: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
61 theme_combo_box->addItem(tr("Default"));
c537996cf67b *: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
62 theme_combo_box->addItem(tr("Light"));
c537996cf67b *: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
63 theme_combo_box->addItem(tr("Dark"));
c537996cf67b *: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
64 connect(theme_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
c537996cf67b *: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
65 [this](int index) { theme = static_cast<Themes>(index); });
c537996cf67b *: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
66 theme_combo_box->setCurrentIndex(static_cast<int>(theme));
c537996cf67b *: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
67
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
68 QCheckBox* hl_anime_box =
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
69 new QCheckBox(tr("Highlight anime if next episode is available in library folders"), appearance_group_box);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
70 QCheckBox* hl_above_anime_box = new QCheckBox(tr("Display highlighted anime above others"), appearance_group_box);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
71 connect(hl_anime_box, &QCheckBox::stateChanged, this, [this, hl_above_anime_box](int state) {
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
72 highlight_anime_if_available = !(state == Qt::Unchecked);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
73 hl_above_anime_box->setEnabled(state);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
74 });
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
75 connect(hl_above_anime_box, &QCheckBox::stateChanged, this,
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
76 [this](int state) { highlight_anime_if_available = !(state == Qt::Unchecked); });
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
77 hl_anime_box->setCheckState(highlight_anime_if_available ? Qt::Checked : Qt::Unchecked);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
78 hl_above_anime_box->setCheckState(highlighted_anime_above_others ? Qt::Checked : Qt::Unchecked);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
79 hl_above_anime_box->setEnabled(hl_anime_box->checkState() != Qt::Unchecked);
36
2743011a6042 *: mass update
Paper <mrpapersonic@gmail.com>
parents: 15
diff changeset
80 hl_above_anime_box->setContentsMargins(10, 0, 0, 0);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
81
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
82 /* Appearance */
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
83 QVBoxLayout* appearance_layout = new QVBoxLayout(appearance_group_box);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
84 appearance_layout->addWidget(lang_combo_box_label);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
85 appearance_layout->addWidget(lang_combo_box);
101
c537996cf67b *: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
86 appearance_layout->addWidget(theme_combo_box_label);
c537996cf67b *: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
87 appearance_layout->addWidget(theme_combo_box);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
88 appearance_layout->addWidget(hl_anime_box);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
89 appearance_layout->addWidget(hl_above_anime_box);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
90
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
91 QGroupBox* progress_group_box = new QGroupBox(tr("Progress"), result);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
92 progress_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
93
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
94 QCheckBox* progress_display_aired_episodes =
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
95 new QCheckBox(tr("Display aired episodes (estimated)"), progress_group_box);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
96 connect(progress_display_aired_episodes, &QCheckBox::stateChanged, this,
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
97 [this](int state) { display_aired_episodes = !(state == Qt::Unchecked); });
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
98 progress_display_aired_episodes->setCheckState(display_aired_episodes ? Qt::Checked : Qt::Unchecked);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
99
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
100 QCheckBox* progress_display_available_episodes =
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
101 new QCheckBox(tr("Display available episodes in library folders"), progress_group_box);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
102 connect(progress_display_available_episodes, &QCheckBox::stateChanged, this,
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
103 [this](int state) { display_available_episodes = !(state == Qt::Unchecked); });
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
104 progress_display_available_episodes->setCheckState(display_available_episodes ? Qt::Checked : Qt::Unchecked);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
105
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
106 QVBoxLayout* progress_layout = new QVBoxLayout(progress_group_box);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
107 progress_layout->addWidget(progress_display_aired_episodes);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
108 progress_layout->addWidget(progress_display_available_episodes);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
109
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
110 QVBoxLayout* full_layout = new QVBoxLayout(result);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
111 full_layout->addWidget(actions_group_box);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
112 full_layout->addWidget(appearance_group_box);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
113 full_layout->addWidget(progress_group_box);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
114 full_layout->setSpacing(10);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
115 full_layout->addStretch();
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
116
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
117 return result;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
118 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
119
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
120 void SettingsPageApplication::SaveInfo() {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
121 session.config.anime_list.language = language;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
122 session.config.anime_list.highlighted_anime_above_others = highlighted_anime_above_others;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
123 session.config.anime_list.highlight_anime_if_available = highlight_anime_if_available;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
124 session.config.anime_list.display_aired_episodes = display_aired_episodes;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
125 session.config.anime_list.display_available_episodes = display_available_episodes;
102
b315f3759c56 *: big patch
Paper <mrpapersonic@gmail.com>
parents: 101
diff changeset
126 session.config.theme.SetTheme(theme);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
127 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
128
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
129 SettingsPageApplication::SettingsPageApplication(QWidget* parent) : SettingsPage(parent, tr("Application")) {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
130 language = session.config.anime_list.language;
102
b315f3759c56 *: big patch
Paper <mrpapersonic@gmail.com>
parents: 101
diff changeset
131 theme = session.config.theme.GetTheme();
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
132 highlighted_anime_above_others = session.config.anime_list.highlighted_anime_above_others;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
133 highlight_anime_if_available = session.config.anime_list.highlight_anime_if_available;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
134 display_aired_episodes = session.config.anime_list.display_aired_episodes;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
135 display_available_episodes = session.config.anime_list.display_available_episodes;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
136 AddTab(CreateAnimeListWidget(), tr("Anime list"));
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
137 }