comparison src/gui/dialog/settings/application.cc @ 393:963047512d34

*: clang-format
author Paper <paper@tflc.us>
date Fri, 07 Nov 2025 07:16:15 -0500
parents b1f4d1867ab1
children 2f4dc1580b84
comparison
equal deleted inserted replaced
392:a72d6d7b3568 393:963047512d34
13 #include <QLabel> 13 #include <QLabel>
14 #include <QPushButton> 14 #include <QPushButton>
15 #include <QSizePolicy> 15 #include <QSizePolicy>
16 #include <QVBoxLayout> 16 #include <QVBoxLayout>
17 17
18 QWidget* SettingsPageApplication::CreateAnimeListWidget() { 18 QWidget *SettingsPageApplication::CreateAnimeListWidget()
19 QWidget* result = new QWidget(this); 19 {
20 QWidget *result = new QWidget(this);
20 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); 21 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
21 22
22 QVBoxLayout* full_layout = new QVBoxLayout(result); 23 QVBoxLayout *full_layout = new QVBoxLayout(result);
23 24
24 { 25 {
25 /* Actions */ 26 /* Actions */
26 QGroupBox* actions_group_box = new QGroupBox(tr("Actions"), result); 27 QGroupBox *actions_group_box = new QGroupBox(tr("Actions"), result);
27 actions_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); 28 actions_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
28 29
29 QHBoxLayout* actions_layout = new QHBoxLayout(actions_group_box); 30 QHBoxLayout *actions_layout = new QHBoxLayout(actions_group_box);
30 31
31 { 32 {
32 /* Actions/Double click */ 33 /* Actions/Double click */
33 QWidget* double_click_widget = new QWidget(actions_group_box); 34 QWidget *double_click_widget = new QWidget(actions_group_box);
34 QLabel* dc_combo_box_label = new QLabel(tr("Double click:"), double_click_widget); 35 QLabel *dc_combo_box_label = new QLabel(tr("Double click:"), double_click_widget);
35 QComboBox* dc_combo_box = new QComboBox(double_click_widget); 36 QComboBox *dc_combo_box = new QComboBox(double_click_widget);
36 dc_combo_box->addItem(tr("View anime info")); 37 dc_combo_box->addItem(tr("View anime info"));
37 38
38 QVBoxLayout* double_click_layout = new QVBoxLayout(double_click_widget); 39 QVBoxLayout *double_click_layout = new QVBoxLayout(double_click_widget);
39 double_click_layout->addWidget(dc_combo_box_label); 40 double_click_layout->addWidget(dc_combo_box_label);
40 double_click_layout->addWidget(dc_combo_box); 41 double_click_layout->addWidget(dc_combo_box);
41 double_click_layout->setContentsMargins(0, 0, 0, 0); 42 double_click_layout->setContentsMargins(0, 0, 0, 0);
42 43
43 actions_layout->addWidget(double_click_widget); 44 actions_layout->addWidget(double_click_widget);
44 } 45 }
45 46
46 { 47 {
47 /* Actions/Middle click */ 48 /* Actions/Middle click */
48 QWidget* middle_click_widget = new QWidget(actions_group_box); 49 QWidget *middle_click_widget = new QWidget(actions_group_box);
49 QLabel* mc_combo_box_label = new QLabel(tr("Middle click:"), middle_click_widget); 50 QLabel *mc_combo_box_label = new QLabel(tr("Middle click:"), middle_click_widget);
50 QComboBox* mc_combo_box = new QComboBox(middle_click_widget); 51 QComboBox *mc_combo_box = new QComboBox(middle_click_widget);
51 mc_combo_box->addItem(tr("Play next episode")); 52 mc_combo_box->addItem(tr("Play next episode"));
52 53
53 QVBoxLayout* middle_click_layout = new QVBoxLayout(middle_click_widget); 54 QVBoxLayout *middle_click_layout = new QVBoxLayout(middle_click_widget);
54 middle_click_layout->addWidget(mc_combo_box_label); 55 middle_click_layout->addWidget(mc_combo_box_label);
55 middle_click_layout->addWidget(mc_combo_box); 56 middle_click_layout->addWidget(mc_combo_box);
56 middle_click_layout->setContentsMargins(0, 0, 0, 0); 57 middle_click_layout->setContentsMargins(0, 0, 0, 0);
57 58
58 actions_layout->addWidget(middle_click_widget); 59 actions_layout->addWidget(middle_click_widget);
61 full_layout->addWidget(actions_group_box); 62 full_layout->addWidget(actions_group_box);
62 } 63 }
63 64
64 { 65 {
65 /* Appearance */ 66 /* Appearance */
66 QGroupBox* appearance_group_box = new QGroupBox(tr("Appearance"), result); 67 QGroupBox *appearance_group_box = new QGroupBox(tr("Appearance"), result);
67 appearance_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); 68 appearance_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
68 69
69 QVBoxLayout* appearance_layout = new QVBoxLayout(appearance_group_box); 70 QVBoxLayout *appearance_layout = new QVBoxLayout(appearance_group_box);
70 71
71 { 72 {
72 /* Title language */ 73 /* Title language */
73 { 74 {
74 QLabel* lang_combo_box_label = new QLabel(tr("Title language preference:"), appearance_group_box); 75 QLabel *lang_combo_box_label = new QLabel(tr("Title language preference:"), appearance_group_box);
75 appearance_layout->addWidget(lang_combo_box_label); 76 appearance_layout->addWidget(lang_combo_box_label);
76 } 77 }
77 { 78 {
78 QComboBox* lang_combo_box = new QComboBox(appearance_group_box); 79 QComboBox *lang_combo_box = new QComboBox(appearance_group_box);
79 lang_combo_box->addItem(tr("Romaji")); 80 lang_combo_box->addItem(tr("Romaji"));
80 lang_combo_box->addItem(tr("Native")); 81 lang_combo_box->addItem(tr("Native"));
81 lang_combo_box->addItem(tr("English")); 82 lang_combo_box->addItem(tr("English"));
82 connect(lang_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, 83 connect(lang_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
83 [this](int index) { language = static_cast<Anime::TitleLanguage>(index); }); 84 [this](int index) { language = static_cast<Anime::TitleLanguage>(index); });
87 } 88 }
88 89
89 { 90 {
90 /* Application theme */ 91 /* Application theme */
91 { 92 {
92 QLabel* rating_combo_box_label = new QLabel(tr("Rating system:"), appearance_group_box); 93 QLabel *rating_combo_box_label = new QLabel(tr("Rating system:"), appearance_group_box);
93 appearance_layout->addWidget(rating_combo_box_label); 94 appearance_layout->addWidget(rating_combo_box_label);
94 } 95 }
95 96
96 { 97 {
97 QComboBox* rating_combo_box = new QComboBox(appearance_group_box); 98 QComboBox *rating_combo_box = new QComboBox(appearance_group_box);
98 99
99 for (const auto& score_format : Anime::ScoreFormats) 100 for (const auto &score_format : Anime::ScoreFormats)
100 rating_combo_box->addItem(Strings::ToQString(Translate::ToLocalString(score_format)), 101 rating_combo_box->addItem(Strings::ToQString(Translate::ToLocalString(score_format)),
101 static_cast<int>(score_format)); 102 static_cast<int>(score_format));
102 103
103 connect(rating_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, 104 connect(rating_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
104 [this, rating_combo_box](int index) { 105 [this, rating_combo_box](int index) {
110 } 111 }
111 } 112 }
112 113
113 { 114 {
114 /* Hopefully I made this easy to read... */ 115 /* Hopefully I made this easy to read... */
115 QCheckBox* hl_above_anime_box = 116 QCheckBox *hl_above_anime_box =
116 new QCheckBox(tr("Display highlighted anime above others"), appearance_group_box); 117 new QCheckBox(tr("Display highlighted anime above others"), appearance_group_box);
117 hl_above_anime_box->setCheckState(highlighted_anime_above_others ? Qt::Checked : Qt::Unchecked); 118 hl_above_anime_box->setCheckState(highlighted_anime_above_others ? Qt::Checked : Qt::Unchecked);
118 hl_above_anime_box->setEnabled(highlight_anime_if_available); 119 hl_above_anime_box->setEnabled(highlight_anime_if_available);
119 hl_above_anime_box->setContentsMargins(10, 0, 0, 0); 120 hl_above_anime_box->setContentsMargins(10, 0, 0, 0);
120 121
121 connect(hl_above_anime_box, &QCheckBox::stateChanged, this, 122 connect(hl_above_anime_box, &QCheckBox::stateChanged, this,
122 [this](int state) { highlight_anime_if_available = !(state == Qt::Unchecked); }); 123 [this](int state) { highlight_anime_if_available = !(state == Qt::Unchecked); });
123 124
124 { 125 {
125 /* This is here because the above checkbox actually depends on it to be checked. */ 126 /* This is here because the above checkbox actually depends on it to be checked. */
126 QCheckBox* hl_anime_box = new QCheckBox( 127 QCheckBox *hl_anime_box = new QCheckBox(
127 tr("Highlight anime if next episode is available in library folders"), appearance_group_box); 128 tr("Highlight anime if next episode is available in library folders"), appearance_group_box);
128 hl_anime_box->setCheckState(highlight_anime_if_available ? Qt::Checked : Qt::Unchecked); 129 hl_anime_box->setCheckState(highlight_anime_if_available ? Qt::Checked : Qt::Unchecked);
129 130
130 connect(hl_anime_box, &QCheckBox::stateChanged, this, [this, hl_above_anime_box](int state) { 131 connect(hl_anime_box, &QCheckBox::stateChanged, this, [this, hl_above_anime_box](int state) {
131 highlight_anime_if_available = !(state == Qt::Unchecked); 132 highlight_anime_if_available = !(state == Qt::Unchecked);
141 full_layout->addWidget(appearance_group_box); 142 full_layout->addWidget(appearance_group_box);
142 } 143 }
143 144
144 { 145 {
145 /* Progress */ 146 /* Progress */
146 QGroupBox* progress_group_box = new QGroupBox(tr("Progress"), result); 147 QGroupBox *progress_group_box = new QGroupBox(tr("Progress"), result);
147 progress_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); 148 progress_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
148 149
149 QVBoxLayout* progress_layout = new QVBoxLayout(progress_group_box); 150 QVBoxLayout *progress_layout = new QVBoxLayout(progress_group_box);
150 151
151 { 152 {
152 QCheckBox* progress_display_aired_episodes = 153 QCheckBox *progress_display_aired_episodes =
153 new QCheckBox(tr("Display aired episodes (estimated)"), progress_group_box); 154 new QCheckBox(tr("Display aired episodes (estimated)"), progress_group_box);
154 connect(progress_display_aired_episodes, &QCheckBox::stateChanged, this, 155 connect(progress_display_aired_episodes, &QCheckBox::stateChanged, this,
155 [this](int state) { display_aired_episodes = !(state == Qt::Unchecked); }); 156 [this](int state) { display_aired_episodes = !(state == Qt::Unchecked); });
156 progress_display_aired_episodes->setCheckState(display_aired_episodes ? Qt::Checked : Qt::Unchecked); 157 progress_display_aired_episodes->setCheckState(display_aired_episodes ? Qt::Checked : Qt::Unchecked);
157 progress_layout->addWidget(progress_display_aired_episodes); 158 progress_layout->addWidget(progress_display_aired_episodes);
158 } 159 }
159 { 160 {
160 QCheckBox* progress_display_available_episodes = 161 QCheckBox *progress_display_available_episodes =
161 new QCheckBox(tr("Display available episodes in library folders"), progress_group_box); 162 new QCheckBox(tr("Display available episodes in library folders"), progress_group_box);
162 connect(progress_display_available_episodes, &QCheckBox::stateChanged, this, 163 connect(progress_display_available_episodes, &QCheckBox::stateChanged, this,
163 [this](int state) { display_available_episodes = !(state == Qt::Unchecked); }); 164 [this](int state) { display_available_episodes = !(state == Qt::Unchecked); });
164 progress_display_available_episodes->setCheckState(display_available_episodes ? Qt::Checked 165 progress_display_available_episodes->setCheckState(display_available_episodes ? Qt::Checked
165 : Qt::Unchecked); 166 : Qt::Unchecked);
173 full_layout->addStretch(); 174 full_layout->addStretch();
174 175
175 return result; 176 return result;
176 } 177 }
177 178
178 QWidget* SettingsPageApplication::CreateGeneralWidget() { 179 QWidget *SettingsPageApplication::CreateGeneralWidget()
179 QWidget* result = new QWidget(this); 180 {
181 QWidget *result = new QWidget(this);
180 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); 182 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
181 183
182 QVBoxLayout* full_layout = new QVBoxLayout(result); 184 QVBoxLayout *full_layout = new QVBoxLayout(result);
183 185
184 { 186 {
185 /* Appearance */ 187 /* Appearance */
186 QGroupBox* appearance_group_box = new QGroupBox(tr("Appearance"), result); 188 QGroupBox *appearance_group_box = new QGroupBox(tr("Appearance"), result);
187 appearance_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); 189 appearance_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
188 190
189 QVBoxLayout* appearance_layout = new QVBoxLayout(appearance_group_box); 191 QVBoxLayout *appearance_layout = new QVBoxLayout(appearance_group_box);
190 192
191 { 193 {
192 /* Application theme */ 194 /* Application theme */
193 { 195 {
194 QLabel* theme_combo_box_label = new QLabel(tr("Application theme:"), appearance_group_box); 196 QLabel *theme_combo_box_label = new QLabel(tr("Application theme:"), appearance_group_box);
195 appearance_layout->addWidget(theme_combo_box_label); 197 appearance_layout->addWidget(theme_combo_box_label);
196 } 198 }
197 199
198 { 200 {
199 /* FIXME: don't hardcode these values */ 201 /* FIXME: don't hardcode these values */
200 QComboBox* theme_combo_box = new QComboBox(appearance_group_box); 202 QComboBox *theme_combo_box = new QComboBox(appearance_group_box);
201 for (const auto& theme : Theme::Themes) 203 for (const auto &theme : Theme::Themes)
202 theme_combo_box->addItem(Strings::ToQString(Translate::ToLocalString(theme))); 204 theme_combo_box->addItem(Strings::ToQString(Translate::ToLocalString(theme)));
203 205
204 connect(theme_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, 206 connect(theme_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
205 [this](int index) { theme = static_cast<Theme::Theme>(index); }); 207 [this](int index) { theme = static_cast<Theme::Theme>(index); });
206 theme_combo_box->setCurrentIndex(static_cast<int>(theme)); 208 theme_combo_box->setCurrentIndex(static_cast<int>(theme));
209 } 211 }
210 212
211 { 213 {
212 /* Application locale */ 214 /* Application locale */
213 { 215 {
214 QLabel* locale_combo_box_label = new QLabel(tr("Application locale:"), appearance_group_box); 216 QLabel *locale_combo_box_label = new QLabel(tr("Application locale:"), appearance_group_box);
215 appearance_layout->addWidget(locale_combo_box_label); 217 appearance_layout->addWidget(locale_combo_box_label);
216 } 218 }
217 219
218 { 220 {
219 QComboBox* locale_combo_box = new QComboBox(appearance_group_box); 221 QComboBox *locale_combo_box = new QComboBox(appearance_group_box);
220 const auto& available_locales = session.config.locale.GetAvailableLocales(); 222 const auto &available_locales = session.config.locale.GetAvailableLocales();
221 for (const auto& l : available_locales) 223 for (const auto &l : available_locales)
222 locale_combo_box->addItem(Strings::ToQString(Locale::GetLocaleFullName(l)), l); 224 locale_combo_box->addItem(Strings::ToQString(Locale::GetLocaleFullName(l)), l);
223 225
224 connect(locale_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, 226 connect(locale_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
225 [this, locale_combo_box](int) { locale = locale_combo_box->currentData().toLocale(); }); 227 [this, locale_combo_box](int) { locale = locale_combo_box->currentData().toLocale(); });
226 228
239 full_layout->addStretch(); 241 full_layout->addStretch();
240 242
241 return result; 243 return result;
242 } 244 }
243 245
244 void SettingsPageApplication::SaveInfo() { 246 void SettingsPageApplication::SaveInfo()
247 {
245 session.config.anime_list.language = language; 248 session.config.anime_list.language = language;
246 session.config.anime_list.highlighted_anime_above_others = highlighted_anime_above_others; 249 session.config.anime_list.highlighted_anime_above_others = highlighted_anime_above_others;
247 session.config.anime_list.highlight_anime_if_available = highlight_anime_if_available; 250 session.config.anime_list.highlight_anime_if_available = highlight_anime_if_available;
248 session.config.anime_list.display_aired_episodes = display_aired_episodes; 251 session.config.anime_list.display_aired_episodes = display_aired_episodes;
249 session.config.anime_list.display_available_episodes = display_available_episodes; 252 session.config.anime_list.display_available_episodes = display_available_episodes;
250 session.config.theme.SetTheme(theme); 253 session.config.theme.SetTheme(theme);
251 session.config.locale.SetActiveLocale(locale); 254 session.config.locale.SetActiveLocale(locale);
252 } 255 }
253 256
254 SettingsPageApplication::SettingsPageApplication(QWidget* parent) : SettingsPage(parent, tr("Application")) { 257 SettingsPageApplication::SettingsPageApplication(QWidget *parent) : SettingsPage(parent, tr("Application"))
258 {
255 language = session.config.anime_list.language; 259 language = session.config.anime_list.language;
256 format = session.config.anime_list.score_format; 260 format = session.config.anime_list.score_format;
257 theme = session.config.theme.GetTheme(); 261 theme = session.config.theme.GetTheme();
258 locale = session.config.locale.GetLocale(); 262 locale = session.config.locale.GetLocale();
259 highlighted_anime_above_others = session.config.anime_list.highlighted_anime_above_others; 263 highlighted_anime_above_others = session.config.anime_list.highlighted_anime_above_others;