Mercurial > minori
annotate src/gui/dialog/settings/application.cc @ 119:4eae379cb1ff
settings: add a very early recognition tab for configuring players and extensions
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Wed, 08 Nov 2023 13:50:00 -0500 |
| parents | 80f49f623d30 |
| children | 9613d72b097e |
| 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 { | |
| 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); }); | |
| 10 | 139 |
| 108 | 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); | |
| 10 | 144 |
| 108 | 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 } | |
| 10 | 158 |
| 108 | 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); | |
| 10 | 165 |
| 108 | 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 } | |
| 10 | 182 |
| 108 | 183 full_layout->addWidget(progress_group_box); |
| 184 } | |
| 10 | 185 |
| 186 full_layout->setSpacing(10); | |
| 187 full_layout->addStretch(); | |
|
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
62
diff
changeset
|
188 |
| 10 | 189 return result; |
| 190 } | |
| 191 | |
| 192 void SettingsPageApplication::SaveInfo() { | |
| 193 session.config.anime_list.language = language; | |
| 194 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; | |
| 196 session.config.anime_list.display_aired_episodes = display_aired_episodes; | |
| 197 session.config.anime_list.display_available_episodes = display_available_episodes; | |
| 102 | 198 session.config.theme.SetTheme(theme); |
| 108 | 199 session.config.locale.SetActiveLocale(locale); |
| 10 | 200 } |
| 201 | |
| 202 SettingsPageApplication::SettingsPageApplication(QWidget* parent) : SettingsPage(parent, tr("Application")) { | |
| 203 language = session.config.anime_list.language; | |
| 102 | 204 theme = session.config.theme.GetTheme(); |
| 108 | 205 locale = session.config.locale.GetLocale(); |
| 10 | 206 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; | |
| 208 display_aired_episodes = session.config.anime_list.display_aired_episodes; | |
| 209 display_available_episodes = session.config.anime_list.display_available_episodes; | |
| 210 AddTab(CreateAnimeListWidget(), tr("Anime list")); | |
| 211 } |
