comparison src/gui/dialog/settings/application.cc @ 108:2004b41d4a59

*: huge commit 1. WORKING LOCALIZATION + translation for Spanish and British English 2. idk like 2 changes for the dark theme :)
author Paper <mrpapersonic@gmail.com>
date Sun, 05 Nov 2023 23:31:49 -0500
parents 6d8da6e64d61
children 80f49f623d30
comparison
equal deleted inserted replaced
107:49c8d1976869 108:2004b41d4a59
1 #include "core/session.h" 1 #include "core/session.h"
2 #include "core/strings.h"
2 #include "gui/dialog/settings.h" 3 #include "gui/dialog/settings.h"
3 #include "gui/theme.h" 4 #include "gui/theme.h"
5 #include "gui/locale.h"
4 #include <QCheckBox> 6 #include <QCheckBox>
5 #include <QComboBox> 7 #include <QComboBox>
6 #include <QGroupBox> 8 #include <QGroupBox>
7 #include <QHBoxLayout> 9 #include <QHBoxLayout>
8 #include <QLabel> 10 #include <QLabel>
9 #include <QPushButton> 11 #include <QPushButton>
10 #include <QSizePolicy> 12 #include <QSizePolicy>
11 #include <QVBoxLayout> 13 #include <QVBoxLayout>
14 #include <algorithm>
12 15
13 QWidget* SettingsPageApplication::CreateAnimeListWidget() { 16 QWidget* SettingsPageApplication::CreateAnimeListWidget() {
14 QWidget* result = new QWidget(this); 17 QWidget* result = new QWidget(this);
15 result->setAutoFillBackground(true); 18 result->setAutoFillBackground(true);
16 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); 19 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
17 20
18 QGroupBox* actions_group_box = new QGroupBox(tr("Actions"), result);
19 actions_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
20
21 /* Actions/Double click */
22 QWidget* double_click_widget = new QWidget(actions_group_box);
23 QLabel* dc_combo_box_label = new QLabel(tr("Double click:"), double_click_widget);
24 QComboBox* dc_combo_box = new QComboBox(double_click_widget);
25 dc_combo_box->addItem(tr("View anime info"));
26
27 QVBoxLayout* double_click_layout = new QVBoxLayout(double_click_widget);
28 double_click_layout->addWidget(dc_combo_box_label);
29 double_click_layout->addWidget(dc_combo_box);
30 double_click_layout->setContentsMargins(0, 0, 0, 0);
31
32 /* Actions/Middle click */
33 QWidget* middle_click_widget = new QWidget(actions_group_box);
34 QLabel* mc_combo_box_label = new QLabel(tr("Middle click:"), middle_click_widget);
35 QComboBox* mc_combo_box = new QComboBox(middle_click_widget);
36 mc_combo_box->addItem(tr("Play next episode"));
37
38 QVBoxLayout* middle_click_layout = new QVBoxLayout(middle_click_widget);
39 middle_click_layout->addWidget(mc_combo_box_label);
40 middle_click_layout->addWidget(mc_combo_box);
41 middle_click_layout->setContentsMargins(0, 0, 0, 0);
42
43 /* Actions */
44 QHBoxLayout* actions_layout = new QHBoxLayout(actions_group_box);
45 actions_layout->addWidget(double_click_widget);
46 actions_layout->addWidget(middle_click_widget);
47
48 QGroupBox* appearance_group_box = new QGroupBox(tr("Appearance"), result);
49 appearance_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
50
51 QLabel* lang_combo_box_label = new QLabel(tr("Title language preference:"), appearance_group_box);
52 QComboBox* lang_combo_box = new QComboBox(appearance_group_box);
53 lang_combo_box->addItem(tr("Romaji"));
54 lang_combo_box->addItem(tr("Native"));
55 lang_combo_box->addItem(tr("English"));
56 connect(lang_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
57 [this](int index) { language = static_cast<Anime::TitleLanguage>(index); });
58 lang_combo_box->setCurrentIndex(static_cast<int>(language));
59
60 QLabel* theme_combo_box_label = new QLabel(tr("Application theme:"), appearance_group_box);
61 QComboBox* theme_combo_box = new QComboBox(appearance_group_box);
62 theme_combo_box->addItem(tr("Default"));
63 theme_combo_box->addItem(tr("Light"));
64 theme_combo_box->addItem(tr("Dark"));
65 connect(theme_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
66 [this](int index) { theme = static_cast<Themes>(index); });
67 theme_combo_box->setCurrentIndex(static_cast<int>(theme));
68
69 QCheckBox* hl_anime_box =
70 new QCheckBox(tr("Highlight anime if next episode is available in library folders"), appearance_group_box);
71 QCheckBox* hl_above_anime_box = new QCheckBox(tr("Display highlighted anime above others"), appearance_group_box);
72 connect(hl_anime_box, &QCheckBox::stateChanged, this, [this, hl_above_anime_box](int state) {
73 highlight_anime_if_available = !(state == Qt::Unchecked);
74 hl_above_anime_box->setEnabled(state);
75 });
76 connect(hl_above_anime_box, &QCheckBox::stateChanged, this,
77 [this](int state) { highlight_anime_if_available = !(state == Qt::Unchecked); });
78 hl_anime_box->setCheckState(highlight_anime_if_available ? Qt::Checked : Qt::Unchecked);
79 hl_above_anime_box->setCheckState(highlighted_anime_above_others ? Qt::Checked : Qt::Unchecked);
80 hl_above_anime_box->setEnabled(hl_anime_box->checkState() != Qt::Unchecked);
81 hl_above_anime_box->setContentsMargins(10, 0, 0, 0);
82
83 /* Appearance */
84 QVBoxLayout* appearance_layout = new QVBoxLayout(appearance_group_box);
85 appearance_layout->addWidget(lang_combo_box_label);
86 appearance_layout->addWidget(lang_combo_box);
87 appearance_layout->addWidget(theme_combo_box_label);
88 appearance_layout->addWidget(theme_combo_box);
89 appearance_layout->addWidget(hl_anime_box);
90 appearance_layout->addWidget(hl_above_anime_box);
91
92 QGroupBox* progress_group_box = new QGroupBox(tr("Progress"), result);
93 progress_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
94
95 QCheckBox* progress_display_aired_episodes =
96 new QCheckBox(tr("Display aired episodes (estimated)"), progress_group_box);
97 connect(progress_display_aired_episodes, &QCheckBox::stateChanged, this,
98 [this](int state) { display_aired_episodes = !(state == Qt::Unchecked); });
99 progress_display_aired_episodes->setCheckState(display_aired_episodes ? Qt::Checked : Qt::Unchecked);
100
101 QCheckBox* progress_display_available_episodes =
102 new QCheckBox(tr("Display available episodes in library folders"), progress_group_box);
103 connect(progress_display_available_episodes, &QCheckBox::stateChanged, this,
104 [this](int state) { display_available_episodes = !(state == Qt::Unchecked); });
105 progress_display_available_episodes->setCheckState(display_available_episodes ? Qt::Checked : Qt::Unchecked);
106
107 QVBoxLayout* progress_layout = new QVBoxLayout(progress_group_box);
108 progress_layout->addWidget(progress_display_aired_episodes);
109 progress_layout->addWidget(progress_display_available_episodes);
110
111 QVBoxLayout* full_layout = new QVBoxLayout(result); 21 QVBoxLayout* full_layout = new QVBoxLayout(result);
112 full_layout->addWidget(actions_group_box); 22
113 full_layout->addWidget(appearance_group_box); 23 {
114 full_layout->addWidget(progress_group_box); 24 /* Actions */
25 QGroupBox* actions_group_box = new QGroupBox(tr("Actions"), result);
26 actions_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
27
28 QHBoxLayout* actions_layout = new QHBoxLayout(actions_group_box);
29
30 {
31 /* Actions/Double click */
32 QWidget* double_click_widget = new QWidget(actions_group_box);
33 QLabel* dc_combo_box_label = new QLabel(tr("Double click:"), double_click_widget);
34 QComboBox* dc_combo_box = new QComboBox(double_click_widget);
35 dc_combo_box->addItem(tr("View anime info"));
36
37 QVBoxLayout* double_click_layout = new QVBoxLayout(double_click_widget);
38 double_click_layout->addWidget(dc_combo_box_label);
39 double_click_layout->addWidget(dc_combo_box);
40 double_click_layout->setContentsMargins(0, 0, 0, 0);
41
42 actions_layout->addWidget(double_click_widget);
43 }
44
45 {
46 /* Actions/Middle click */
47 QWidget* middle_click_widget = new QWidget(actions_group_box);
48 QLabel* mc_combo_box_label = new QLabel(tr("Middle click:"), middle_click_widget);
49 QComboBox* mc_combo_box = new QComboBox(middle_click_widget);
50 mc_combo_box->addItem(tr("Play next episode"));
51
52 QVBoxLayout* middle_click_layout = new QVBoxLayout(middle_click_widget);
53 middle_click_layout->addWidget(mc_combo_box_label);
54 middle_click_layout->addWidget(mc_combo_box);
55 middle_click_layout->setContentsMargins(0, 0, 0, 0);
56
57 actions_layout->addWidget(middle_click_widget);
58 }
59
60 full_layout->addWidget(actions_group_box);
61 }
62
63 {
64 /* Appearance */
65 QGroupBox* appearance_group_box = new QGroupBox(tr("Appearance"), result);
66 appearance_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
67
68 QVBoxLayout* appearance_layout = new QVBoxLayout(appearance_group_box);
69
70 {
71 /* Title language */
72 {
73 QLabel* lang_combo_box_label = new QLabel(tr("Title language preference:"), appearance_group_box);
74 appearance_layout->addWidget(lang_combo_box_label);
75 }
76 {
77 QComboBox* lang_combo_box = new QComboBox(appearance_group_box);
78 lang_combo_box->addItem(tr("Romaji"));
79 lang_combo_box->addItem(tr("Native"));
80 lang_combo_box->addItem(tr("English"));
81 connect(lang_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
82 [this](int index) { language = static_cast<Anime::TitleLanguage>(index); });
83 lang_combo_box->setCurrentIndex(static_cast<int>(language));
84 appearance_layout->addWidget(lang_combo_box);
85 }
86 }
87
88 {
89 /* Application theme */
90 {
91 QLabel* theme_combo_box_label = new QLabel(tr("Application theme:"), appearance_group_box);
92 appearance_layout->addWidget(theme_combo_box_label);
93 }
94
95 {
96 QComboBox* theme_combo_box = new QComboBox(appearance_group_box);
97 theme_combo_box->addItem(tr("Default"));
98 theme_combo_box->addItem(tr("Light"));
99 theme_combo_box->addItem(tr("Dark"));
100 connect(theme_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
101 [this](int index) { theme = static_cast<Themes>(index); });
102 theme_combo_box->setCurrentIndex(static_cast<int>(theme));
103 appearance_layout->addWidget(theme_combo_box);
104 }
105 }
106
107 {
108 /* Application locale */
109 {
110 QLabel* locale_combo_box_label = new QLabel(tr("Set application locale (requires restart):"), appearance_group_box);
111 appearance_layout->addWidget(locale_combo_box_label);
112 }
113
114 {
115 QComboBox* locale_combo_box = new QComboBox(appearance_group_box);
116 const auto& available_locales = session.config.locale.GetAvailableLocales();
117 for (const auto& l : available_locales)
118 locale_combo_box->addItem(Strings::ToQString(Locale::GetLocaleFullName(l)), l);
119
120 connect(locale_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
121 [this, locale_combo_box](int) { locale = locale_combo_box->currentData().toLocale(); });
122
123 for (size_t i = 0; i < available_locales.size(); i++)
124 if (available_locales[i] == locale)
125 locale_combo_box->setCurrentIndex(i);
126 appearance_layout->addWidget(locale_combo_box);
127 }
128 }
129
130 {
131 /* Hopefully I made this easy to parse... */
132 QCheckBox* hl_above_anime_box = new QCheckBox(tr("Display highlighted anime above others"), appearance_group_box);
133 hl_above_anime_box->setCheckState(highlighted_anime_above_others ? Qt::Checked : Qt::Unchecked);
134 hl_above_anime_box->setEnabled(highlight_anime_if_available);
135 hl_above_anime_box->setContentsMargins(10, 0, 0, 0);
136
137 connect(hl_above_anime_box, &QCheckBox::stateChanged, this,
138 [this](int state) { highlight_anime_if_available = !(state == Qt::Unchecked); });
139
140 {
141 /* This is here because the above checkbox actually depends on it to be checked. */
142 QCheckBox* hl_anime_box = new QCheckBox(tr("Highlight anime if next episode is available in library folders"), appearance_group_box);
143 hl_anime_box->setCheckState(highlight_anime_if_available ? Qt::Checked : Qt::Unchecked);
144
145 connect(hl_anime_box, &QCheckBox::stateChanged, this, [this, hl_above_anime_box](int state) {
146 highlight_anime_if_available = !(state == Qt::Unchecked);
147 hl_above_anime_box->setEnabled(state);
148 });
149
150 appearance_layout->addWidget(hl_anime_box);
151 }
152
153 appearance_layout->addWidget(hl_above_anime_box);
154 }
155
156 full_layout->addWidget(appearance_group_box);
157 }
158
159 {
160 /* Progress */
161 QGroupBox* progress_group_box = new QGroupBox(tr("Progress"), result);
162 progress_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
163
164 QVBoxLayout* progress_layout = new QVBoxLayout(progress_group_box);
165
166 {
167 QCheckBox* progress_display_aired_episodes =
168 new QCheckBox(tr("Display aired episodes (estimated)"), progress_group_box);
169 connect(progress_display_aired_episodes, &QCheckBox::stateChanged, this,
170 [this](int state) { display_aired_episodes = !(state == Qt::Unchecked); });
171 progress_display_aired_episodes->setCheckState(display_aired_episodes ? Qt::Checked : Qt::Unchecked);
172 progress_layout->addWidget(progress_display_aired_episodes);
173 }
174 {
175 QCheckBox* progress_display_available_episodes =
176 new QCheckBox(tr("Display available episodes in library folders"), progress_group_box);
177 connect(progress_display_available_episodes, &QCheckBox::stateChanged, this,
178 [this](int state) { display_available_episodes = !(state == Qt::Unchecked); });
179 progress_display_available_episodes->setCheckState(display_available_episodes ? Qt::Checked : Qt::Unchecked);
180 progress_layout->addWidget(progress_display_available_episodes);
181 }
182
183 full_layout->addWidget(progress_group_box);
184 }
185
115 full_layout->setSpacing(10); 186 full_layout->setSpacing(10);
116 full_layout->addStretch(); 187 full_layout->addStretch();
117 188
118 return result; 189 return result;
119 } 190 }
123 session.config.anime_list.highlighted_anime_above_others = highlighted_anime_above_others; 194 session.config.anime_list.highlighted_anime_above_others = highlighted_anime_above_others;
124 session.config.anime_list.highlight_anime_if_available = highlight_anime_if_available; 195 session.config.anime_list.highlight_anime_if_available = highlight_anime_if_available;
125 session.config.anime_list.display_aired_episodes = display_aired_episodes; 196 session.config.anime_list.display_aired_episodes = display_aired_episodes;
126 session.config.anime_list.display_available_episodes = display_available_episodes; 197 session.config.anime_list.display_available_episodes = display_available_episodes;
127 session.config.theme.SetTheme(theme); 198 session.config.theme.SetTheme(theme);
199 session.config.locale.SetActiveLocale(locale);
128 } 200 }
129 201
130 SettingsPageApplication::SettingsPageApplication(QWidget* parent) : SettingsPage(parent, tr("Application")) { 202 SettingsPageApplication::SettingsPageApplication(QWidget* parent) : SettingsPage(parent, tr("Application")) {
131 language = session.config.anime_list.language; 203 language = session.config.anime_list.language;
132 theme = session.config.theme.GetTheme(); 204 theme = session.config.theme.GetTheme();
205 locale = session.config.locale.GetLocale();
133 highlighted_anime_above_others = session.config.anime_list.highlighted_anime_above_others; 206 highlighted_anime_above_others = session.config.anime_list.highlighted_anime_above_others;
134 highlight_anime_if_available = session.config.anime_list.highlight_anime_if_available; 207 highlight_anime_if_available = session.config.anime_list.highlight_anime_if_available;
135 display_aired_episodes = session.config.anime_list.display_aired_episodes; 208 display_aired_episodes = session.config.anime_list.display_aired_episodes;
136 display_available_episodes = session.config.anime_list.display_available_episodes; 209 display_available_episodes = session.config.anime_list.display_available_episodes;
137 AddTab(CreateAnimeListWidget(), tr("Anime list")); 210 AddTab(CreateAnimeListWidget(), tr("Anime list"));