Mercurial > minori
annotate src/gui/dialog/settings/application.cc @ 189:649786bae914
*: etc. code cleanup
I've removed most macros and stuff
dep/animia: [UNTESTED] use raw C++ instead of Objective-C++
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Wed, 06 Dec 2023 19:42:33 -0500 |
| parents | 9613d72b097e |
| children | 975a3f0965e2 |
| 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" |
| 189 | 6 #include "gui/translate/anime.h" |
| 7 | |
| 10 | 8 #include <QCheckBox> |
| 9 #include <QComboBox> | |
| 10 #include <QGroupBox> | |
|
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
62
diff
changeset
|
11 #include <QHBoxLayout> |
|
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
62
diff
changeset
|
12 #include <QLabel> |
| 10 | 13 #include <QPushButton> |
| 14 #include <QSizePolicy> | |
|
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
62
diff
changeset
|
15 #include <QVBoxLayout> |
| 189 | 16 |
| 108 | 17 #include <algorithm> |
| 10 | 18 |
| 19 QWidget* SettingsPageApplication::CreateAnimeListWidget() { | |
| 20 QWidget* result = new QWidget(this); | |
|
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
21 result->setAutoFillBackground(true); |
| 10 | 22 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); |
| 23 | |
| 108 | 24 QVBoxLayout* full_layout = new QVBoxLayout(result); |
| 10 | 25 |
| 108 | 26 { |
| 27 /* Actions */ | |
| 28 QGroupBox* actions_group_box = new QGroupBox(tr("Actions"), result); | |
| 29 actions_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
| 30 | |
| 31 QHBoxLayout* actions_layout = new QHBoxLayout(actions_group_box); | |
| 10 | 32 |
| 108 | 33 { |
| 34 /* Actions/Double click */ | |
| 35 QWidget* double_click_widget = new QWidget(actions_group_box); | |
| 36 QLabel* dc_combo_box_label = new QLabel(tr("Double click:"), double_click_widget); | |
| 37 QComboBox* dc_combo_box = new QComboBox(double_click_widget); | |
| 38 dc_combo_box->addItem(tr("View anime info")); | |
| 10 | 39 |
| 108 | 40 QVBoxLayout* double_click_layout = new QVBoxLayout(double_click_widget); |
| 41 double_click_layout->addWidget(dc_combo_box_label); | |
| 42 double_click_layout->addWidget(dc_combo_box); | |
| 43 double_click_layout->setContentsMargins(0, 0, 0, 0); | |
| 44 | |
| 45 actions_layout->addWidget(double_click_widget); | |
| 46 } | |
| 47 | |
| 48 { | |
| 49 /* Actions/Middle click */ | |
| 50 QWidget* middle_click_widget = new QWidget(actions_group_box); | |
| 51 QLabel* mc_combo_box_label = new QLabel(tr("Middle click:"), middle_click_widget); | |
| 52 QComboBox* mc_combo_box = new QComboBox(middle_click_widget); | |
| 53 mc_combo_box->addItem(tr("Play next episode")); | |
| 10 | 54 |
| 108 | 55 QVBoxLayout* middle_click_layout = new QVBoxLayout(middle_click_widget); |
| 56 middle_click_layout->addWidget(mc_combo_box_label); | |
| 57 middle_click_layout->addWidget(mc_combo_box); | |
| 58 middle_click_layout->setContentsMargins(0, 0, 0, 0); | |
| 59 | |
| 60 actions_layout->addWidget(middle_click_widget); | |
| 61 } | |
| 10 | 62 |
| 108 | 63 full_layout->addWidget(actions_group_box); |
| 64 } | |
| 65 | |
| 66 { | |
| 67 /* Appearance */ | |
| 68 QGroupBox* appearance_group_box = new QGroupBox(tr("Appearance"), result); | |
| 69 appearance_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
| 70 | |
| 71 QVBoxLayout* appearance_layout = new QVBoxLayout(appearance_group_box); | |
| 10 | 72 |
| 108 | 73 { |
| 74 /* Title language */ | |
| 75 { | |
| 76 QLabel* lang_combo_box_label = new QLabel(tr("Title language preference:"), appearance_group_box); | |
| 77 appearance_layout->addWidget(lang_combo_box_label); | |
| 78 } | |
| 79 { | |
| 80 QComboBox* lang_combo_box = new QComboBox(appearance_group_box); | |
| 81 lang_combo_box->addItem(tr("Romaji")); | |
| 82 lang_combo_box->addItem(tr("Native")); | |
| 83 lang_combo_box->addItem(tr("English")); | |
| 84 connect(lang_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, | |
| 85 [this](int index) { language = static_cast<Anime::TitleLanguage>(index); }); | |
| 86 lang_combo_box->setCurrentIndex(static_cast<int>(language)); | |
| 87 appearance_layout->addWidget(lang_combo_box); | |
| 88 } | |
| 89 } | |
| 10 | 90 |
| 108 | 91 { |
| 92 /* Application theme */ | |
| 93 { | |
| 94 QLabel* theme_combo_box_label = new QLabel(tr("Application theme:"), appearance_group_box); | |
| 95 appearance_layout->addWidget(theme_combo_box_label); | |
| 96 } | |
| 10 | 97 |
| 108 | 98 { |
| 99 QComboBox* theme_combo_box = new QComboBox(appearance_group_box); | |
| 100 theme_combo_box->addItem(tr("Default")); | |
| 101 theme_combo_box->addItem(tr("Light")); | |
| 102 theme_combo_box->addItem(tr("Dark")); | |
| 103 connect(theme_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, | |
| 104 [this](int index) { theme = static_cast<Themes>(index); }); | |
| 105 theme_combo_box->setCurrentIndex(static_cast<int>(theme)); | |
| 106 appearance_layout->addWidget(theme_combo_box); | |
| 107 } | |
| 108 } | |
| 109 | |
| 110 { | |
| 111 /* Application locale */ | |
| 112 { | |
| 189 | 113 QLabel* locale_combo_box_label = new QLabel(tr("Application locale:"), appearance_group_box); |
| 108 | 114 appearance_layout->addWidget(locale_combo_box_label); |
| 115 } | |
|
101
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
116 |
| 108 | 117 { |
| 118 QComboBox* locale_combo_box = new QComboBox(appearance_group_box); | |
| 119 const auto& available_locales = session.config.locale.GetAvailableLocales(); | |
| 120 for (const auto& l : available_locales) | |
| 121 locale_combo_box->addItem(Strings::ToQString(Locale::GetLocaleFullName(l)), l); | |
| 122 | |
| 123 connect(locale_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, | |
| 124 [this, locale_combo_box](int) { locale = locale_combo_box->currentData().toLocale(); }); | |
| 125 | |
| 126 for (size_t i = 0; i < available_locales.size(); i++) | |
| 127 if (available_locales[i] == locale) | |
| 128 locale_combo_box->setCurrentIndex(i); | |
| 189 | 129 |
| 108 | 130 appearance_layout->addWidget(locale_combo_box); |
| 131 } | |
| 132 } | |
| 133 | |
| 134 { | |
|
187
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
135 /* Application theme */ |
|
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
136 { |
| 189 | 137 QLabel* rating_combo_box_label = new QLabel(tr("Rating system:"), appearance_group_box); |
| 138 appearance_layout->addWidget(rating_combo_box_label); | |
|
187
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
139 } |
|
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
140 |
|
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
141 { |
| 189 | 142 QComboBox* rating_combo_box = new QComboBox(appearance_group_box); |
| 143 | |
| 144 for (const auto& score_format : Anime::ScoreFormats) | |
| 145 rating_combo_box->addItem(Strings::ToQString(Translate::ToLocalString(score_format)), static_cast<int>(score_format)); | |
| 146 | |
| 147 connect(rating_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, | |
| 148 [this, rating_combo_box](int index) { format = static_cast<Anime::ScoreFormat>(rating_combo_box->itemData(index).toInt()); }); | |
| 149 | |
| 150 rating_combo_box->setCurrentIndex(static_cast<int>(format)); | |
| 151 appearance_layout->addWidget(rating_combo_box); | |
|
187
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
152 } |
|
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
153 } |
|
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
154 |
|
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
155 { |
| 108 | 156 /* Hopefully I made this easy to parse... */ |
| 157 QCheckBox* hl_above_anime_box = new QCheckBox(tr("Display highlighted anime above others"), appearance_group_box); | |
| 158 hl_above_anime_box->setCheckState(highlighted_anime_above_others ? Qt::Checked : Qt::Unchecked); | |
| 159 hl_above_anime_box->setEnabled(highlight_anime_if_available); | |
| 160 hl_above_anime_box->setContentsMargins(10, 0, 0, 0); | |
| 161 | |
| 162 connect(hl_above_anime_box, &QCheckBox::stateChanged, this, | |
| 163 [this](int state) { highlight_anime_if_available = !(state == Qt::Unchecked); }); | |
| 10 | 164 |
| 108 | 165 { |
| 166 /* This is here because the above checkbox actually depends on it to be checked. */ | |
| 167 QCheckBox* hl_anime_box = new QCheckBox(tr("Highlight anime if next episode is available in library folders"), appearance_group_box); | |
| 168 hl_anime_box->setCheckState(highlight_anime_if_available ? Qt::Checked : Qt::Unchecked); | |
| 10 | 169 |
| 108 | 170 connect(hl_anime_box, &QCheckBox::stateChanged, this, [this, hl_above_anime_box](int state) { |
| 171 highlight_anime_if_available = !(state == Qt::Unchecked); | |
| 172 hl_above_anime_box->setEnabled(state); | |
| 173 }); | |
| 174 | |
| 175 appearance_layout->addWidget(hl_anime_box); | |
| 176 } | |
| 177 | |
| 178 appearance_layout->addWidget(hl_above_anime_box); | |
| 179 } | |
| 180 | |
| 181 full_layout->addWidget(appearance_group_box); | |
| 182 } | |
| 10 | 183 |
| 108 | 184 { |
| 185 /* Progress */ | |
| 186 QGroupBox* progress_group_box = new QGroupBox(tr("Progress"), result); | |
| 187 progress_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
| 188 | |
| 189 QVBoxLayout* progress_layout = new QVBoxLayout(progress_group_box); | |
| 10 | 190 |
| 108 | 191 { |
| 192 QCheckBox* progress_display_aired_episodes = | |
| 193 new QCheckBox(tr("Display aired episodes (estimated)"), progress_group_box); | |
| 194 connect(progress_display_aired_episodes, &QCheckBox::stateChanged, this, | |
| 195 [this](int state) { display_aired_episodes = !(state == Qt::Unchecked); }); | |
| 196 progress_display_aired_episodes->setCheckState(display_aired_episodes ? Qt::Checked : Qt::Unchecked); | |
| 197 progress_layout->addWidget(progress_display_aired_episodes); | |
| 198 } | |
| 199 { | |
| 200 QCheckBox* progress_display_available_episodes = | |
| 201 new QCheckBox(tr("Display available episodes in library folders"), progress_group_box); | |
| 202 connect(progress_display_available_episodes, &QCheckBox::stateChanged, this, | |
| 203 [this](int state) { display_available_episodes = !(state == Qt::Unchecked); }); | |
| 204 progress_display_available_episodes->setCheckState(display_available_episodes ? Qt::Checked : Qt::Unchecked); | |
| 205 progress_layout->addWidget(progress_display_available_episodes); | |
| 206 } | |
| 10 | 207 |
| 108 | 208 full_layout->addWidget(progress_group_box); |
| 209 } | |
| 10 | 210 |
| 211 full_layout->setSpacing(10); | |
| 212 full_layout->addStretch(); | |
|
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
62
diff
changeset
|
213 |
| 10 | 214 return result; |
| 215 } | |
| 216 | |
| 217 void SettingsPageApplication::SaveInfo() { | |
| 218 session.config.anime_list.language = language; | |
| 219 session.config.anime_list.highlighted_anime_above_others = highlighted_anime_above_others; | |
| 220 session.config.anime_list.highlight_anime_if_available = highlight_anime_if_available; | |
| 221 session.config.anime_list.display_aired_episodes = display_aired_episodes; | |
| 222 session.config.anime_list.display_available_episodes = display_available_episodes; | |
| 102 | 223 session.config.theme.SetTheme(theme); |
| 108 | 224 session.config.locale.SetActiveLocale(locale); |
| 10 | 225 } |
| 226 | |
| 227 SettingsPageApplication::SettingsPageApplication(QWidget* parent) : SettingsPage(parent, tr("Application")) { | |
| 228 language = session.config.anime_list.language; | |
| 189 | 229 format = session.config.anime_list.score_format; |
| 102 | 230 theme = session.config.theme.GetTheme(); |
| 108 | 231 locale = session.config.locale.GetLocale(); |
| 10 | 232 highlighted_anime_above_others = session.config.anime_list.highlighted_anime_above_others; |
| 233 highlight_anime_if_available = session.config.anime_list.highlight_anime_if_available; | |
| 234 display_aired_episodes = session.config.anime_list.display_aired_episodes; | |
| 235 display_available_episodes = session.config.anime_list.display_available_episodes; | |
| 236 AddTab(CreateAnimeListWidget(), tr("Anime list")); | |
| 237 } |
