Mercurial > minori
comparison src/dialog/settings/application.cpp @ 7:07a9095eaeed
Update
Refactored some code, moved some around
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Thu, 24 Aug 2023 23:11:38 -0400 |
| parents | 1d82f6e04d7d |
| children |
comparison
equal
deleted
inserted
replaced
| 6:1d82f6e04d7d | 7:07a9095eaeed |
|---|---|
| 1 #include "settings.h" | 1 #include "settings.h" |
| 2 #include "anilist.h" | 2 #include "anilist.h" |
| 3 #include "window.h" | 3 #include "session.h" |
| 4 #include <QGroupBox> | 4 #include <QGroupBox> |
| 5 #include <QComboBox> | 5 #include <QComboBox> |
| 6 #include <QCheckBox> | 6 #include <QCheckBox> |
| 7 #include <QPushButton> | 7 #include <QPushButton> |
| 8 #include <QSizePolicy> | 8 #include <QSizePolicy> |
| 9 | 9 |
| 10 QWidget* SettingsPageApplication::CreateAnimeListPage() { | 10 QWidget* SettingsPageApplication::CreateAnimeListWidget() { |
| 11 QWidget* result = new QWidget(this); | 11 QWidget* result = new QWidget(this); |
| 12 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | 12 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); |
| 13 | 13 |
| 14 QGroupBox* actions_group_box = new QGroupBox(tr("Actions"), result); | 14 QGroupBox* actions_group_box = new QGroupBox(tr("Actions"), result); |
| 15 actions_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | 15 actions_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); |
| 21 dc_combo_box->addItem(tr("View anime info")); | 21 dc_combo_box->addItem(tr("View anime info")); |
| 22 | 22 |
| 23 QVBoxLayout* double_click_layout = new QVBoxLayout; | 23 QVBoxLayout* double_click_layout = new QVBoxLayout; |
| 24 double_click_layout->addWidget(dc_combo_box_label); | 24 double_click_layout->addWidget(dc_combo_box_label); |
| 25 double_click_layout->addWidget(dc_combo_box); | 25 double_click_layout->addWidget(dc_combo_box); |
| 26 double_click_layout->setMargin(0); | |
| 26 double_click_widget->setLayout(double_click_layout); | 27 double_click_widget->setLayout(double_click_layout); |
| 27 | 28 |
| 28 /* Actions/Middle click */ | 29 /* Actions/Middle click */ |
| 29 QWidget* middle_click_widget = new QWidget(actions_group_box); | 30 QWidget* middle_click_widget = new QWidget(actions_group_box); |
| 30 QLabel* mc_combo_box_label = new QLabel(tr("Middle click:"), middle_click_widget); | 31 QLabel* mc_combo_box_label = new QLabel(tr("Middle click:"), middle_click_widget); |
| 32 mc_combo_box->addItem(tr("Play next episode")); | 33 mc_combo_box->addItem(tr("Play next episode")); |
| 33 | 34 |
| 34 QVBoxLayout* middle_click_layout = new QVBoxLayout; | 35 QVBoxLayout* middle_click_layout = new QVBoxLayout; |
| 35 middle_click_layout->addWidget(mc_combo_box_label); | 36 middle_click_layout->addWidget(mc_combo_box_label); |
| 36 middle_click_layout->addWidget(mc_combo_box); | 37 middle_click_layout->addWidget(mc_combo_box); |
| 38 middle_click_layout->setMargin(0); | |
| 37 middle_click_widget->setLayout(middle_click_layout); | 39 middle_click_widget->setLayout(middle_click_layout); |
| 38 | 40 |
| 39 /* Actions */ | 41 /* Actions */ |
| 40 QHBoxLayout* actions_layout = new QHBoxLayout; | 42 QHBoxLayout* actions_layout = new QHBoxLayout; |
| 41 actions_layout->addWidget(double_click_widget); | 43 actions_layout->addWidget(double_click_widget); |
| 45 QGroupBox* appearance_group_box = new QGroupBox(tr("Appearance"), result); | 47 QGroupBox* appearance_group_box = new QGroupBox(tr("Appearance"), result); |
| 46 appearance_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | 48 appearance_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); |
| 47 | 49 |
| 48 QLabel* lang_combo_box_label = new QLabel(tr("Title language preference:"), appearance_group_box); | 50 QLabel* lang_combo_box_label = new QLabel(tr("Title language preference:"), appearance_group_box); |
| 49 QComboBox* lang_combo_box = new QComboBox(appearance_group_box); | 51 QComboBox* lang_combo_box = new QComboBox(appearance_group_box); |
| 52 lang_combo_box->addItem(tr("Romaji")); | |
| 53 lang_combo_box->addItem(tr("Native")); | |
| 50 lang_combo_box->addItem(tr("English")); | 54 lang_combo_box->addItem(tr("English")); |
| 55 connect(lang_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this](int index){ | |
| 56 language = static_cast<enum AnimeTitleLanguage>(index); | |
| 57 }); | |
| 58 lang_combo_box->setCurrentIndex(language); | |
| 59 | |
| 51 QCheckBox* hl_anime_box = new QCheckBox(tr("Highlight anime if next episode is available in library folders"), appearance_group_box); | 60 QCheckBox* hl_anime_box = new QCheckBox(tr("Highlight anime if next episode is available in library folders"), appearance_group_box); |
| 52 QCheckBox* hl_above_anime_box = new QCheckBox(tr("Display highlighted anime above others"), appearance_group_box); | 61 QCheckBox* hl_above_anime_box = new QCheckBox(tr("Display highlighted anime above others"), appearance_group_box); |
| 53 hl_above_anime_box->setEnabled((hl_anime_box->checkState() == Qt::Unchecked) ? 0 : 1); | 62 connect(hl_anime_box, &QCheckBox::stateChanged, this, [this, hl_above_anime_box](int state){ |
| 54 hl_above_anime_box->setStyleSheet("margin-left: 10px;"); | 63 highlight_anime_if_available = (state == Qt::Unchecked) ? false : true; |
| 55 | |
| 56 connect(hl_anime_box, &QCheckBox::stateChanged, this, [hl_above_anime_box](int state){ | |
| 57 hl_above_anime_box->setEnabled(state); | 64 hl_above_anime_box->setEnabled(state); |
| 58 }); | 65 }); |
| 66 connect(hl_above_anime_box, &QCheckBox::stateChanged, this, [this](int state){ | |
| 67 highlight_anime_if_available = (state == Qt::Unchecked) ? false : true; | |
| 68 }); | |
| 69 hl_anime_box->setCheckState(highlight_anime_if_available ? Qt::Checked : Qt::Unchecked); | |
| 70 hl_above_anime_box->setCheckState(highlighted_anime_above_others ? Qt::Checked : Qt::Unchecked); | |
| 71 hl_above_anime_box->setEnabled(hl_anime_box->checkState() != Qt::Unchecked); | |
| 72 hl_above_anime_box->setStyleSheet("margin-left: 10px;"); | |
| 59 | 73 |
| 60 /* Appearance */ | 74 /* Appearance */ |
| 61 QVBoxLayout* appearance_layout = new QVBoxLayout; | 75 QVBoxLayout* appearance_layout = new QVBoxLayout; |
| 62 appearance_layout->addWidget(lang_combo_box_label); | 76 appearance_layout->addWidget(lang_combo_box_label); |
| 63 appearance_layout->addWidget(lang_combo_box); | 77 appearance_layout->addWidget(lang_combo_box); |
| 66 appearance_group_box->setLayout(appearance_layout); | 80 appearance_group_box->setLayout(appearance_layout); |
| 67 | 81 |
| 68 QGroupBox* progress_group_box = new QGroupBox(tr("Progress"), result); | 82 QGroupBox* progress_group_box = new QGroupBox(tr("Progress"), result); |
| 69 progress_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | 83 progress_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); |
| 70 | 84 |
| 71 QCheckBox* display_aired_episodes = new QCheckBox(tr("Display aired episodes (estimated)"), progress_group_box); | 85 QCheckBox* progress_display_aired_episodes = new QCheckBox(tr("Display aired episodes (estimated)"), progress_group_box); |
| 72 QCheckBox* display_available_episodes = new QCheckBox(tr("Display available episodes in library folders"), progress_group_box); | 86 connect(progress_display_aired_episodes, &QCheckBox::stateChanged, this, [this](int state){ |
| 87 display_aired_episodes = (state == Qt::Unchecked) ? false : true; | |
| 88 }); | |
| 89 progress_display_aired_episodes->setCheckState(display_aired_episodes ? Qt::Checked : Qt::Unchecked); | |
| 90 | |
| 91 QCheckBox* progress_display_available_episodes = new QCheckBox(tr("Display available episodes in library folders"), progress_group_box); | |
| 92 connect(progress_display_available_episodes, &QCheckBox::stateChanged, this, [this](int state){ | |
| 93 display_available_episodes = (state == Qt::Unchecked) ? false : true; | |
| 94 }); | |
| 95 progress_display_available_episodes->setCheckState(display_available_episodes ? Qt::Checked : Qt::Unchecked); | |
| 73 | 96 |
| 74 QVBoxLayout* progress_layout = new QVBoxLayout; | 97 QVBoxLayout* progress_layout = new QVBoxLayout; |
| 75 progress_layout->addWidget(display_aired_episodes); | 98 progress_layout->addWidget(progress_display_aired_episodes); |
| 76 progress_layout->addWidget(display_available_episodes); | 99 progress_layout->addWidget(progress_display_available_episodes); |
| 77 progress_group_box->setLayout(progress_layout); | 100 progress_group_box->setLayout(progress_layout); |
| 78 | 101 |
| 79 QVBoxLayout* full_layout = new QVBoxLayout; | 102 QVBoxLayout* full_layout = new QVBoxLayout; |
| 80 full_layout->addWidget(actions_group_box); | 103 full_layout->addWidget(actions_group_box); |
| 81 full_layout->addWidget(appearance_group_box); | 104 full_layout->addWidget(appearance_group_box); |
| 84 result->setLayout(full_layout); | 107 result->setLayout(full_layout); |
| 85 return result; | 108 return result; |
| 86 } | 109 } |
| 87 | 110 |
| 88 void SettingsPageApplication::SaveInfo() { | 111 void SettingsPageApplication::SaveInfo() { |
| 89 | 112 session.config.anime_list.language = language; |
| 113 session.config.anime_list.highlighted_anime_above_others = highlighted_anime_above_others; | |
| 114 session.config.anime_list.highlight_anime_if_available = highlight_anime_if_available; | |
| 115 session.config.anime_list.display_aired_episodes = display_aired_episodes; | |
| 116 session.config.anime_list.display_available_episodes = display_available_episodes; | |
| 90 } | 117 } |
| 91 | 118 |
| 92 SettingsPageApplication::SettingsPageApplication(QWidget* parent) | 119 SettingsPageApplication::SettingsPageApplication(QWidget* parent) |
| 93 : SettingsPage(parent, tr("Application")) { | 120 : SettingsPage(parent, tr("Application")) { |
| 94 AddTab(CreateAnimeListPage(), tr("Anime list")); | 121 language = session.config.anime_list.language; |
| 122 highlighted_anime_above_others = session.config.anime_list.highlighted_anime_above_others; | |
| 123 highlight_anime_if_available = session.config.anime_list.highlight_anime_if_available; | |
| 124 display_aired_episodes = session.config.anime_list.display_aired_episodes; | |
| 125 display_available_episodes = session.config.anime_list.display_available_episodes; | |
| 126 AddTab(CreateAnimeListWidget(), tr("Anime list")); | |
| 95 } | 127 } |
