comparison src/gui/dialog/settings/application.cc @ 202:71832ffe425a

animia: re-add kvm fd source this is all being merged from my wildly out-of-date laptop. SORRY! in other news, I edited the CI file to install the wayland client as well, so the linux CI build might finally get wayland stuff.
author Paper <paper@paper.us.eu.org>
date Tue, 02 Jan 2024 06:05:06 -0500
parents 975a3f0965e2
children ff0061e75f0f
comparison
equal deleted inserted replaced
201:8f6f8dd2eb23 202:71832ffe425a
1 #include "core/session.h" 1 #include "core/session.h"
2 #include "core/strings.h" 2 #include "core/strings.h"
3 #include "gui/dialog/settings.h" 3 #include "gui/dialog/settings.h"
4 #include "gui/theme.h" 4 #include "gui/theme.h"
5 #include "gui/locale.h" 5 #include "gui/locale.h"
6 #include "gui/translate/anime.h"
7
6 #include <QCheckBox> 8 #include <QCheckBox>
7 #include <QComboBox> 9 #include <QComboBox>
8 #include <QGroupBox> 10 #include <QGroupBox>
9 #include <QHBoxLayout> 11 #include <QHBoxLayout>
10 #include <QLabel> 12 #include <QLabel>
11 #include <QPushButton> 13 #include <QPushButton>
12 #include <QSizePolicy> 14 #include <QSizePolicy>
13 #include <QVBoxLayout> 15 #include <QVBoxLayout>
16
14 #include <algorithm> 17 #include <algorithm>
15 18
16 QWidget* SettingsPageApplication::CreateAnimeListWidget() { 19 QWidget* SettingsPageApplication::CreateAnimeListWidget() {
17 QWidget* result = new QWidget(this); 20 QWidget* result = new QWidget(this);
18 result->setAutoFillBackground(true); 21 result->setAutoFillBackground(true);
86 } 89 }
87 90
88 { 91 {
89 /* Application theme */ 92 /* Application theme */
90 { 93 {
94 QLabel* rating_combo_box_label = new QLabel(tr("Rating system:"), appearance_group_box);
95 appearance_layout->addWidget(rating_combo_box_label);
96 }
97
98 {
99 QComboBox* rating_combo_box = new QComboBox(appearance_group_box);
100
101 for (const auto& score_format : Anime::ScoreFormats)
102 rating_combo_box->addItem(Strings::ToQString(Translate::ToLocalString(score_format)), static_cast<int>(score_format));
103
104 connect(rating_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
105 [this, rating_combo_box](int index) { format = static_cast<Anime::ScoreFormat>(rating_combo_box->itemData(index).toInt()); });
106
107 rating_combo_box->setCurrentIndex(static_cast<int>(format));
108 appearance_layout->addWidget(rating_combo_box);
109 }
110 }
111
112 {
113 /* Hopefully I made this easy to parse... */
114 QCheckBox* hl_above_anime_box = new QCheckBox(tr("Display highlighted anime above others"), appearance_group_box);
115 hl_above_anime_box->setCheckState(highlighted_anime_above_others ? Qt::Checked : Qt::Unchecked);
116 hl_above_anime_box->setEnabled(highlight_anime_if_available);
117 hl_above_anime_box->setContentsMargins(10, 0, 0, 0);
118
119 connect(hl_above_anime_box, &QCheckBox::stateChanged, this,
120 [this](int state) { highlight_anime_if_available = !(state == Qt::Unchecked); });
121
122 {
123 /* This is here because the above checkbox actually depends on it to be checked. */
124 QCheckBox* hl_anime_box = new QCheckBox(tr("Highlight anime if next episode is available in library folders"), appearance_group_box);
125 hl_anime_box->setCheckState(highlight_anime_if_available ? Qt::Checked : Qt::Unchecked);
126
127 connect(hl_anime_box, &QCheckBox::stateChanged, this, [this, hl_above_anime_box](int state) {
128 highlight_anime_if_available = !(state == Qt::Unchecked);
129 hl_above_anime_box->setEnabled(state);
130 });
131
132 appearance_layout->addWidget(hl_anime_box);
133 }
134
135 appearance_layout->addWidget(hl_above_anime_box);
136 }
137
138 full_layout->addWidget(appearance_group_box);
139 }
140
141 {
142 /* Progress */
143 QGroupBox* progress_group_box = new QGroupBox(tr("Progress"), result);
144 progress_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
145
146 QVBoxLayout* progress_layout = new QVBoxLayout(progress_group_box);
147
148 {
149 QCheckBox* progress_display_aired_episodes =
150 new QCheckBox(tr("Display aired episodes (estimated)"), progress_group_box);
151 connect(progress_display_aired_episodes, &QCheckBox::stateChanged, this,
152 [this](int state) { display_aired_episodes = !(state == Qt::Unchecked); });
153 progress_display_aired_episodes->setCheckState(display_aired_episodes ? Qt::Checked : Qt::Unchecked);
154 progress_layout->addWidget(progress_display_aired_episodes);
155 }
156 {
157 QCheckBox* progress_display_available_episodes =
158 new QCheckBox(tr("Display available episodes in library folders"), progress_group_box);
159 connect(progress_display_available_episodes, &QCheckBox::stateChanged, this,
160 [this](int state) { display_available_episodes = !(state == Qt::Unchecked); });
161 progress_display_available_episodes->setCheckState(display_available_episodes ? Qt::Checked : Qt::Unchecked);
162 progress_layout->addWidget(progress_display_available_episodes);
163 }
164
165 full_layout->addWidget(progress_group_box);
166 }
167
168 full_layout->setSpacing(10);
169 full_layout->addStretch();
170
171 return result;
172 }
173
174 QWidget* SettingsPageApplication::CreateGeneralWidget() {
175 QWidget* result = new QWidget(this);
176 result->setAutoFillBackground(true);
177 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
178
179 QVBoxLayout* full_layout = new QVBoxLayout(result);
180
181 {
182 /* Appearance */
183 QGroupBox* appearance_group_box = new QGroupBox(tr("Appearance"), result);
184 appearance_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
185
186 QVBoxLayout* appearance_layout = new QVBoxLayout(appearance_group_box);
187
188 {
189 /* Application theme */
190 {
91 QLabel* theme_combo_box_label = new QLabel(tr("Application theme:"), appearance_group_box); 191 QLabel* theme_combo_box_label = new QLabel(tr("Application theme:"), appearance_group_box);
92 appearance_layout->addWidget(theme_combo_box_label); 192 appearance_layout->addWidget(theme_combo_box_label);
93 } 193 }
94 194
95 { 195 {
105 } 205 }
106 206
107 { 207 {
108 /* Application locale */ 208 /* Application locale */
109 { 209 {
110 QLabel* locale_combo_box_label = new QLabel(tr("Set application locale:"), appearance_group_box); 210 QLabel* locale_combo_box_label = new QLabel(tr("Application locale:"), appearance_group_box);
111 appearance_layout->addWidget(locale_combo_box_label); 211 appearance_layout->addWidget(locale_combo_box_label);
112 } 212 }
113 213
114 { 214 {
115 QComboBox* locale_combo_box = new QComboBox(appearance_group_box); 215 QComboBox* locale_combo_box = new QComboBox(appearance_group_box);
121 [this, locale_combo_box](int) { locale = locale_combo_box->currentData().toLocale(); }); 221 [this, locale_combo_box](int) { locale = locale_combo_box->currentData().toLocale(); });
122 222
123 for (size_t i = 0; i < available_locales.size(); i++) 223 for (size_t i = 0; i < available_locales.size(); i++)
124 if (available_locales[i] == locale) 224 if (available_locales[i] == locale)
125 locale_combo_box->setCurrentIndex(i); 225 locale_combo_box->setCurrentIndex(i);
226
126 appearance_layout->addWidget(locale_combo_box); 227 appearance_layout->addWidget(locale_combo_box);
127 } 228 }
128 } 229 }
129 230
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); 231 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 } 232 }
185 233
186 full_layout->setSpacing(10); 234 full_layout->setSpacing(10);
187 full_layout->addStretch(); 235 full_layout->addStretch();
188 236
189 return result; 237 return result;
190 } 238 }
239
191 240
192 void SettingsPageApplication::SaveInfo() { 241 void SettingsPageApplication::SaveInfo() {
193 session.config.anime_list.language = language; 242 session.config.anime_list.language = language;
194 session.config.anime_list.highlighted_anime_above_others = highlighted_anime_above_others; 243 session.config.anime_list.highlighted_anime_above_others = highlighted_anime_above_others;
195 session.config.anime_list.highlight_anime_if_available = highlight_anime_if_available; 244 session.config.anime_list.highlight_anime_if_available = highlight_anime_if_available;
199 session.config.locale.SetActiveLocale(locale); 248 session.config.locale.SetActiveLocale(locale);
200 } 249 }
201 250
202 SettingsPageApplication::SettingsPageApplication(QWidget* parent) : SettingsPage(parent, tr("Application")) { 251 SettingsPageApplication::SettingsPageApplication(QWidget* parent) : SettingsPage(parent, tr("Application")) {
203 language = session.config.anime_list.language; 252 language = session.config.anime_list.language;
253 format = session.config.anime_list.score_format;
204 theme = session.config.theme.GetTheme(); 254 theme = session.config.theme.GetTheme();
205 locale = session.config.locale.GetLocale(); 255 locale = session.config.locale.GetLocale();
206 highlighted_anime_above_others = session.config.anime_list.highlighted_anime_above_others; 256 highlighted_anime_above_others = session.config.anime_list.highlighted_anime_above_others;
207 highlight_anime_if_available = session.config.anime_list.highlight_anime_if_available; 257 highlight_anime_if_available = session.config.anime_list.highlight_anime_if_available;
208 display_aired_episodes = session.config.anime_list.display_aired_episodes; 258 display_aired_episodes = session.config.anime_list.display_aired_episodes;
209 display_available_episodes = session.config.anime_list.display_available_episodes; 259 display_available_episodes = session.config.anime_list.display_available_episodes;
260 AddTab(CreateGeneralWidget(), tr("General"));
210 AddTab(CreateAnimeListWidget(), tr("Anime list")); 261 AddTab(CreateAnimeListWidget(), tr("Anime list"));
211 } 262 }