Mercurial > minori
annotate src/gui/dialog/settings/application.cc @ 187:9613d72b097e
*: multiple performance improvements
like marking `static const` when it makes sense...
date: change old stupid heap-based method to a structure which should
make copying the thing actually make a copy.
also many performance-based changes, like removing the std::tie
dependency and forward-declaring nlohmann json
*: replace every instance of QString::fromUtf8 to Strings::ToQString.
the main difference is that our function will always convert exactly
what is in the string, while some other times it would only convert
up to the nearest NUL byte
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Wed, 06 Dec 2023 13:43:54 -0500 |
parents | 80f49f623d30 |
children | 649786bae914 |
rev | line source |
---|---|
10 | 1 #include "core/session.h" |
108 | 2 #include "core/strings.h" |
10 | 3 #include "gui/dialog/settings.h" |
102 | 4 #include "gui/theme.h" |
108 | 5 #include "gui/locale.h" |
10 | 6 #include <QCheckBox> |
7 #include <QComboBox> | |
8 #include <QGroupBox> | |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
62
diff
changeset
|
9 #include <QHBoxLayout> |
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
62
diff
changeset
|
10 #include <QLabel> |
10 | 11 #include <QPushButton> |
12 #include <QSizePolicy> | |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
62
diff
changeset
|
13 #include <QVBoxLayout> |
108 | 14 #include <algorithm> |
10 | 15 |
16 QWidget* SettingsPageApplication::CreateAnimeListWidget() { | |
17 QWidget* result = new QWidget(this); | |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
18 result->setAutoFillBackground(true); |
10 | 19 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); |
20 | |
108 | 21 QVBoxLayout* full_layout = new QVBoxLayout(result); |
10 | 22 |
108 | 23 { |
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); | |
10 | 29 |
108 | 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")); | |
10 | 36 |
108 | 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")); | |
10 | 51 |
108 | 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 } | |
10 | 59 |
108 | 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); | |
10 | 69 |
108 | 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 } | |
10 | 87 |
108 | 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 } | |
10 | 94 |
108 | 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 { | |
112
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
110 QLabel* locale_combo_box_label = new QLabel(tr("Set application locale:"), appearance_group_box); |
108 | 111 appearance_layout->addWidget(locale_combo_box_label); |
112 } | |
101
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
113 |
108 | 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 { | |
187
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
131 /* Application theme */ |
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
132 { |
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
133 QLabel* theme_combo_box_label = new QLabel(tr("Application theme:"), appearance_group_box); |
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
134 appearance_layout->addWidget(theme_combo_box_label); |
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
135 } |
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
136 |
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
137 { |
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
138 QComboBox* theme_combo_box = new QComboBox(appearance_group_box); |
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
139 theme_combo_box->addItem(tr("Default")); |
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
140 theme_combo_box->addItem(tr("Light")); |
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
141 theme_combo_box->addItem(tr("Dark")); |
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
142 connect(theme_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, |
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
143 [this](int index) { theme = static_cast<Themes>(index); }); |
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
144 theme_combo_box->setCurrentIndex(static_cast<int>(theme)); |
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
145 appearance_layout->addWidget(theme_combo_box); |
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
146 } |
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
147 } |
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
148 |
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
149 { |
108 | 150 /* Hopefully I made this easy to parse... */ |
151 QCheckBox* hl_above_anime_box = new QCheckBox(tr("Display highlighted anime above others"), appearance_group_box); | |
152 hl_above_anime_box->setCheckState(highlighted_anime_above_others ? Qt::Checked : Qt::Unchecked); | |
153 hl_above_anime_box->setEnabled(highlight_anime_if_available); | |
154 hl_above_anime_box->setContentsMargins(10, 0, 0, 0); | |
155 | |
156 connect(hl_above_anime_box, &QCheckBox::stateChanged, this, | |
157 [this](int state) { highlight_anime_if_available = !(state == Qt::Unchecked); }); | |
10 | 158 |
108 | 159 { |
160 /* This is here because the above checkbox actually depends on it to be checked. */ | |
161 QCheckBox* hl_anime_box = new QCheckBox(tr("Highlight anime if next episode is available in library folders"), appearance_group_box); | |
162 hl_anime_box->setCheckState(highlight_anime_if_available ? Qt::Checked : Qt::Unchecked); | |
10 | 163 |
108 | 164 connect(hl_anime_box, &QCheckBox::stateChanged, this, [this, hl_above_anime_box](int state) { |
165 highlight_anime_if_available = !(state == Qt::Unchecked); | |
166 hl_above_anime_box->setEnabled(state); | |
167 }); | |
168 | |
169 appearance_layout->addWidget(hl_anime_box); | |
170 } | |
171 | |
172 appearance_layout->addWidget(hl_above_anime_box); | |
173 } | |
174 | |
175 full_layout->addWidget(appearance_group_box); | |
176 } | |
10 | 177 |
108 | 178 { |
179 /* Progress */ | |
180 QGroupBox* progress_group_box = new QGroupBox(tr("Progress"), result); | |
181 progress_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
182 | |
183 QVBoxLayout* progress_layout = new QVBoxLayout(progress_group_box); | |
10 | 184 |
108 | 185 { |
186 QCheckBox* progress_display_aired_episodes = | |
187 new QCheckBox(tr("Display aired episodes (estimated)"), progress_group_box); | |
188 connect(progress_display_aired_episodes, &QCheckBox::stateChanged, this, | |
189 [this](int state) { display_aired_episodes = !(state == Qt::Unchecked); }); | |
190 progress_display_aired_episodes->setCheckState(display_aired_episodes ? Qt::Checked : Qt::Unchecked); | |
191 progress_layout->addWidget(progress_display_aired_episodes); | |
192 } | |
193 { | |
194 QCheckBox* progress_display_available_episodes = | |
195 new QCheckBox(tr("Display available episodes in library folders"), progress_group_box); | |
196 connect(progress_display_available_episodes, &QCheckBox::stateChanged, this, | |
197 [this](int state) { display_available_episodes = !(state == Qt::Unchecked); }); | |
198 progress_display_available_episodes->setCheckState(display_available_episodes ? Qt::Checked : Qt::Unchecked); | |
199 progress_layout->addWidget(progress_display_available_episodes); | |
200 } | |
10 | 201 |
108 | 202 full_layout->addWidget(progress_group_box); |
203 } | |
10 | 204 |
205 full_layout->setSpacing(10); | |
206 full_layout->addStretch(); | |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
62
diff
changeset
|
207 |
10 | 208 return result; |
209 } | |
210 | |
211 void SettingsPageApplication::SaveInfo() { | |
212 session.config.anime_list.language = language; | |
213 session.config.anime_list.highlighted_anime_above_others = highlighted_anime_above_others; | |
214 session.config.anime_list.highlight_anime_if_available = highlight_anime_if_available; | |
215 session.config.anime_list.display_aired_episodes = display_aired_episodes; | |
216 session.config.anime_list.display_available_episodes = display_available_episodes; | |
102 | 217 session.config.theme.SetTheme(theme); |
108 | 218 session.config.locale.SetActiveLocale(locale); |
10 | 219 } |
220 | |
221 SettingsPageApplication::SettingsPageApplication(QWidget* parent) : SettingsPage(parent, tr("Application")) { | |
222 language = session.config.anime_list.language; | |
102 | 223 theme = session.config.theme.GetTheme(); |
108 | 224 locale = session.config.locale.GetLocale(); |
10 | 225 highlighted_anime_above_others = session.config.anime_list.highlighted_anime_above_others; |
226 highlight_anime_if_available = session.config.anime_list.highlight_anime_if_available; | |
227 display_aired_episodes = session.config.anime_list.display_aired_episodes; | |
228 display_available_episodes = session.config.anime_list.display_available_episodes; | |
229 AddTab(CreateAnimeListWidget(), tr("Anime list")); | |
230 } |