Mercurial > minori
annotate src/gui/dialog/settings/application.cc @ 301:b1f625b0227c
*: convert all files CRLF -> LF
some files were in DOS format, others were in unix. now everything
(that at least is under our control) should all be the same format
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Mon, 13 May 2024 15:04:51 -0400 |
parents | 657fda1b9cac |
children | b1f4d1867ab1 |
rev | line source |
---|---|
10 | 1 #include "core/session.h" |
108 | 2 #include "core/strings.h" |
10 | 3 #include "gui/dialog/settings.h" |
258 | 4 #include "gui/locale.h" |
102 | 5 #include "gui/theme.h" |
189 | 6 #include "gui/translate/anime.h" |
279 | 7 #include "gui/translate/config.h" |
189 | 8 |
10 | 9 #include <QCheckBox> |
10 #include <QComboBox> | |
11 #include <QGroupBox> | |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
62
diff
changeset
|
12 #include <QHBoxLayout> |
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
62
diff
changeset
|
13 #include <QLabel> |
10 | 14 #include <QPushButton> |
15 #include <QSizePolicy> | |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
62
diff
changeset
|
16 #include <QVBoxLayout> |
189 | 17 |
10 | 18 QWidget* SettingsPageApplication::CreateAnimeListWidget() { |
19 QWidget* result = new QWidget(this); | |
20 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
21 | |
108 | 22 QVBoxLayout* full_layout = new QVBoxLayout(result); |
10 | 23 |
108 | 24 { |
25 /* Actions */ | |
26 QGroupBox* actions_group_box = new QGroupBox(tr("Actions"), result); | |
27 actions_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
28 | |
29 QHBoxLayout* actions_layout = new QHBoxLayout(actions_group_box); | |
10 | 30 |
108 | 31 { |
32 /* Actions/Double click */ | |
33 QWidget* double_click_widget = new QWidget(actions_group_box); | |
34 QLabel* dc_combo_box_label = new QLabel(tr("Double click:"), double_click_widget); | |
35 QComboBox* dc_combo_box = new QComboBox(double_click_widget); | |
36 dc_combo_box->addItem(tr("View anime info")); | |
10 | 37 |
108 | 38 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); | |
41 double_click_layout->setContentsMargins(0, 0, 0, 0); | |
42 | |
43 actions_layout->addWidget(double_click_widget); | |
44 } | |
45 | |
46 { | |
47 /* Actions/Middle click */ | |
48 QWidget* middle_click_widget = new QWidget(actions_group_box); | |
49 QLabel* mc_combo_box_label = new QLabel(tr("Middle click:"), middle_click_widget); | |
50 QComboBox* mc_combo_box = new QComboBox(middle_click_widget); | |
51 mc_combo_box->addItem(tr("Play next episode")); | |
10 | 52 |
108 | 53 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); | |
56 middle_click_layout->setContentsMargins(0, 0, 0, 0); | |
258 | 57 |
108 | 58 actions_layout->addWidget(middle_click_widget); |
59 } | |
10 | 60 |
108 | 61 full_layout->addWidget(actions_group_box); |
62 } | |
63 | |
64 { | |
65 /* Appearance */ | |
66 QGroupBox* appearance_group_box = new QGroupBox(tr("Appearance"), result); | |
67 appearance_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
68 | |
69 QVBoxLayout* appearance_layout = new QVBoxLayout(appearance_group_box); | |
10 | 70 |
108 | 71 { |
72 /* Title language */ | |
73 { | |
74 QLabel* lang_combo_box_label = new QLabel(tr("Title language preference:"), appearance_group_box); | |
75 appearance_layout->addWidget(lang_combo_box_label); | |
76 } | |
77 { | |
78 QComboBox* lang_combo_box = new QComboBox(appearance_group_box); | |
79 lang_combo_box->addItem(tr("Romaji")); | |
80 lang_combo_box->addItem(tr("Native")); | |
81 lang_combo_box->addItem(tr("English")); | |
82 connect(lang_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, | |
83 [this](int index) { language = static_cast<Anime::TitleLanguage>(index); }); | |
84 lang_combo_box->setCurrentIndex(static_cast<int>(language)); | |
85 appearance_layout->addWidget(lang_combo_box); | |
86 } | |
87 } | |
10 | 88 |
108 | 89 { |
90 /* Application theme */ | |
91 { | |
189 | 92 QLabel* rating_combo_box_label = new QLabel(tr("Rating system:"), appearance_group_box); |
93 appearance_layout->addWidget(rating_combo_box_label); | |
187
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
94 } |
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
95 |
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
96 { |
189 | 97 QComboBox* rating_combo_box = new QComboBox(appearance_group_box); |
98 | |
99 for (const auto& score_format : Anime::ScoreFormats) | |
258 | 100 rating_combo_box->addItem(Strings::ToQString(Translate::ToLocalString(score_format)), |
101 static_cast<int>(score_format)); | |
189 | 102 |
103 connect(rating_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, | |
258 | 104 [this, rating_combo_box](int index) { |
105 format = static_cast<Anime::ScoreFormat>(rating_combo_box->itemData(index).toInt()); | |
106 }); | |
189 | 107 |
108 rating_combo_box->setCurrentIndex(static_cast<int>(format)); | |
109 appearance_layout->addWidget(rating_combo_box); | |
187
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
110 } |
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
111 } |
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
112 |
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
113 { |
108 | 114 /* Hopefully I made this easy to parse... */ |
258 | 115 QCheckBox* hl_above_anime_box = |
116 new QCheckBox(tr("Display highlighted anime above others"), appearance_group_box); | |
108 | 117 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->setContentsMargins(10, 0, 0, 0); | |
120 | |
121 connect(hl_above_anime_box, &QCheckBox::stateChanged, this, | |
122 [this](int state) { highlight_anime_if_available = !(state == Qt::Unchecked); }); | |
10 | 123 |
108 | 124 { |
125 /* This is here because the above checkbox actually depends on it to be checked. */ | |
258 | 126 QCheckBox* hl_anime_box = new QCheckBox( |
127 tr("Highlight anime if next episode is available in library folders"), appearance_group_box); | |
108 | 128 hl_anime_box->setCheckState(highlight_anime_if_available ? Qt::Checked : Qt::Unchecked); |
10 | 129 |
108 | 130 connect(hl_anime_box, &QCheckBox::stateChanged, this, [this, hl_above_anime_box](int state) { |
131 highlight_anime_if_available = !(state == Qt::Unchecked); | |
132 hl_above_anime_box->setEnabled(state); | |
133 }); | |
134 | |
135 appearance_layout->addWidget(hl_anime_box); | |
136 } | |
137 | |
138 appearance_layout->addWidget(hl_above_anime_box); | |
139 } | |
140 | |
141 full_layout->addWidget(appearance_group_box); | |
142 } | |
10 | 143 |
108 | 144 { |
145 /* Progress */ | |
146 QGroupBox* progress_group_box = new QGroupBox(tr("Progress"), result); | |
147 progress_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
148 | |
149 QVBoxLayout* progress_layout = new QVBoxLayout(progress_group_box); | |
10 | 150 |
108 | 151 { |
152 QCheckBox* progress_display_aired_episodes = | |
153 new QCheckBox(tr("Display aired episodes (estimated)"), progress_group_box); | |
154 connect(progress_display_aired_episodes, &QCheckBox::stateChanged, this, | |
155 [this](int state) { display_aired_episodes = !(state == Qt::Unchecked); }); | |
156 progress_display_aired_episodes->setCheckState(display_aired_episodes ? Qt::Checked : Qt::Unchecked); | |
157 progress_layout->addWidget(progress_display_aired_episodes); | |
158 } | |
159 { | |
160 QCheckBox* progress_display_available_episodes = | |
161 new QCheckBox(tr("Display available episodes in library folders"), progress_group_box); | |
162 connect(progress_display_available_episodes, &QCheckBox::stateChanged, this, | |
163 [this](int state) { display_available_episodes = !(state == Qt::Unchecked); }); | |
258 | 164 progress_display_available_episodes->setCheckState(display_available_episodes ? Qt::Checked |
165 : Qt::Unchecked); | |
108 | 166 progress_layout->addWidget(progress_display_available_episodes); |
167 } | |
10 | 168 |
108 | 169 full_layout->addWidget(progress_group_box); |
170 } | |
10 | 171 |
172 full_layout->setSpacing(10); | |
173 full_layout->addStretch(); | |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
62
diff
changeset
|
174 |
10 | 175 return result; |
176 } | |
177 | |
195
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
178 QWidget* SettingsPageApplication::CreateGeneralWidget() { |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
179 QWidget* result = new QWidget(this); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
180 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
181 |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
182 QVBoxLayout* full_layout = new QVBoxLayout(result); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
183 |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
184 { |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
185 /* Appearance */ |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
186 QGroupBox* appearance_group_box = new QGroupBox(tr("Appearance"), result); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
187 appearance_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
188 |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
189 QVBoxLayout* appearance_layout = new QVBoxLayout(appearance_group_box); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
190 |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
191 { |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
192 /* Application theme */ |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
193 { |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
194 QLabel* theme_combo_box_label = new QLabel(tr("Application theme:"), appearance_group_box); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
195 appearance_layout->addWidget(theme_combo_box_label); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
196 } |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
197 |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
198 { |
279 | 199 /* FIXME: don't hardcode these values */ |
195
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
200 QComboBox* theme_combo_box = new QComboBox(appearance_group_box); |
279 | 201 for (const auto& theme : Theme::Themes) |
202 theme_combo_box->addItem(Strings::ToQString(Translate::ToLocalString(theme))); | |
203 | |
195
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
204 connect(theme_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, |
279 | 205 [this](int index) { theme = static_cast<Theme::Theme>(index); }); |
195
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
206 theme_combo_box->setCurrentIndex(static_cast<int>(theme)); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
207 appearance_layout->addWidget(theme_combo_box); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
208 } |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
209 } |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
210 |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
211 { |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
212 /* Application locale */ |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
213 { |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
214 QLabel* locale_combo_box_label = new QLabel(tr("Application locale:"), appearance_group_box); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
215 appearance_layout->addWidget(locale_combo_box_label); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
216 } |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
217 |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
218 { |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
219 QComboBox* locale_combo_box = new QComboBox(appearance_group_box); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
220 const auto& available_locales = session.config.locale.GetAvailableLocales(); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
221 for (const auto& l : available_locales) |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
222 locale_combo_box->addItem(Strings::ToQString(Locale::GetLocaleFullName(l)), l); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
223 |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
224 connect(locale_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, |
258 | 225 [this, locale_combo_box](int) { locale = locale_combo_box->currentData().toLocale(); }); |
195
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
226 |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
227 for (size_t i = 0; i < available_locales.size(); i++) |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
228 if (available_locales[i] == locale) |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
229 locale_combo_box->setCurrentIndex(i); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
230 |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
231 appearance_layout->addWidget(locale_combo_box); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
232 } |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
233 } |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
234 |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
235 full_layout->addWidget(appearance_group_box); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
236 } |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
237 |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
238 full_layout->setSpacing(10); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
239 full_layout->addStretch(); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
240 |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
241 return result; |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
242 } |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
243 |
10 | 244 void SettingsPageApplication::SaveInfo() { |
245 session.config.anime_list.language = language; | |
246 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; | |
248 session.config.anime_list.display_aired_episodes = display_aired_episodes; | |
249 session.config.anime_list.display_available_episodes = display_available_episodes; | |
102 | 250 session.config.theme.SetTheme(theme); |
108 | 251 session.config.locale.SetActiveLocale(locale); |
10 | 252 } |
253 | |
254 SettingsPageApplication::SettingsPageApplication(QWidget* parent) : SettingsPage(parent, tr("Application")) { | |
255 language = session.config.anime_list.language; | |
189 | 256 format = session.config.anime_list.score_format; |
102 | 257 theme = session.config.theme.GetTheme(); |
108 | 258 locale = session.config.locale.GetLocale(); |
10 | 259 highlighted_anime_above_others = session.config.anime_list.highlighted_anime_above_others; |
260 highlight_anime_if_available = session.config.anime_list.highlight_anime_if_available; | |
261 display_aired_episodes = session.config.anime_list.display_aired_episodes; | |
262 display_available_episodes = session.config.anime_list.display_available_episodes; | |
195
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
189
diff
changeset
|
263 AddTab(CreateGeneralWidget(), tr("General")); |
10 | 264 AddTab(CreateAnimeListWidget(), tr("Anime list")); |
265 } |