annotate src/gui/dialog/settings/application.cpp @ 68:2417121d894e

*: normalize usage of layouts before, I used them two ways, once was by setting the layout later by using setLayout(QWidget), and the other was just using the constructor. I find the constructor to be easier to read, so I chose that one.
author Paper <mrpapersonic@gmail.com>
date Mon, 02 Oct 2023 21:33:25 -0400
parents 4c6dd5999b39
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
1 #include "core/session.h"
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
2 #include "gui/dialog/settings.h"
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
3 #include <QCheckBox>
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
4 #include <QComboBox>
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
5 #include <QGroupBox>
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
6 #include <QHBoxLayout>
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
7 #include <QLabel>
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
8 #include <QPushButton>
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
9 #include <QSizePolicy>
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
10 #include <QVBoxLayout>
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
11
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
12 QWidget* SettingsPageApplication::CreateAnimeListWidget() {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
13 QWidget* result = new QWidget(this);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
14 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
15
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
16 QGroupBox* actions_group_box = new QGroupBox(tr("Actions"), result);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
17 actions_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
18
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
19 /* Actions/Double click */
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
20 QWidget* double_click_widget = new QWidget(actions_group_box);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
21 QLabel* dc_combo_box_label = new QLabel(tr("Double click:"), double_click_widget);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
22 QComboBox* dc_combo_box = new QComboBox(double_click_widget);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
23 dc_combo_box->addItem(tr("View anime info"));
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
24
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
25 QVBoxLayout* double_click_layout = new QVBoxLayout(double_click_widget);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
26 double_click_layout->addWidget(dc_combo_box_label);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
27 double_click_layout->addWidget(dc_combo_box);
62
4c6dd5999b39 *: update
Paper <mrpapersonic@gmail.com>
parents: 36
diff changeset
28 double_click_layout->setContentsMargins(0, 0, 0, 0);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
29
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
30 /* Actions/Middle click */
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
31 QWidget* middle_click_widget = new QWidget(actions_group_box);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
32 QLabel* mc_combo_box_label = new QLabel(tr("Middle click:"), middle_click_widget);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
33 QComboBox* mc_combo_box = new QComboBox(middle_click_widget);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
34 mc_combo_box->addItem(tr("Play next episode"));
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
35
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
36 QVBoxLayout* middle_click_layout = new QVBoxLayout(middle_click_widget);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
37 middle_click_layout->addWidget(mc_combo_box_label);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
38 middle_click_layout->addWidget(mc_combo_box);
62
4c6dd5999b39 *: update
Paper <mrpapersonic@gmail.com>
parents: 36
diff changeset
39 middle_click_layout->setContentsMargins(0, 0, 0, 0);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
40
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
41 /* Actions */
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
42 QHBoxLayout* actions_layout = new QHBoxLayout(actions_group_box);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
43 actions_layout->addWidget(double_click_widget);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
44 actions_layout->addWidget(middle_click_widget);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
45
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
46 QGroupBox* appearance_group_box = new QGroupBox(tr("Appearance"), result);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
47 appearance_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
48
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
49 QLabel* lang_combo_box_label = new QLabel(tr("Title language preference:"), appearance_group_box);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
50 QComboBox* lang_combo_box = new QComboBox(appearance_group_box);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
51 lang_combo_box->addItem(tr("Romaji"));
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
52 lang_combo_box->addItem(tr("Native"));
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
53 lang_combo_box->addItem(tr("English"));
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
54 connect(lang_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
55 [this](int index) { language = static_cast<Anime::TitleLanguage>(index); });
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
56 lang_combo_box->setCurrentIndex(static_cast<int>(language));
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
57
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
58 QCheckBox* hl_anime_box =
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
59 new QCheckBox(tr("Highlight anime if next episode is available in library folders"), appearance_group_box);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
60 QCheckBox* hl_above_anime_box = new QCheckBox(tr("Display highlighted anime above others"), appearance_group_box);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
61 connect(hl_anime_box, &QCheckBox::stateChanged, this, [this, hl_above_anime_box](int state) {
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
62 highlight_anime_if_available = !(state == Qt::Unchecked);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
63 hl_above_anime_box->setEnabled(state);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
64 });
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
65 connect(hl_above_anime_box, &QCheckBox::stateChanged, this,
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
66 [this](int state) { highlight_anime_if_available = !(state == Qt::Unchecked); });
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
67 hl_anime_box->setCheckState(highlight_anime_if_available ? Qt::Checked : Qt::Unchecked);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
68 hl_above_anime_box->setCheckState(highlighted_anime_above_others ? Qt::Checked : Qt::Unchecked);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
69 hl_above_anime_box->setEnabled(hl_anime_box->checkState() != Qt::Unchecked);
36
2743011a6042 *: mass update
Paper <mrpapersonic@gmail.com>
parents: 15
diff changeset
70 hl_above_anime_box->setContentsMargins(10, 0, 0, 0);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
71
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
72 /* Appearance */
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
73 QVBoxLayout* appearance_layout = new QVBoxLayout(appearance_group_box);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
74 appearance_layout->addWidget(lang_combo_box_label);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
75 appearance_layout->addWidget(lang_combo_box);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
76 appearance_layout->addWidget(hl_anime_box);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
77 appearance_layout->addWidget(hl_above_anime_box);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
78
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
79 QGroupBox* progress_group_box = new QGroupBox(tr("Progress"), result);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
80 progress_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
81
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
82 QCheckBox* progress_display_aired_episodes =
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
83 new QCheckBox(tr("Display aired episodes (estimated)"), progress_group_box);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
84 connect(progress_display_aired_episodes, &QCheckBox::stateChanged, this,
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
85 [this](int state) { display_aired_episodes = !(state == Qt::Unchecked); });
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
86 progress_display_aired_episodes->setCheckState(display_aired_episodes ? Qt::Checked : Qt::Unchecked);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
87
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
88 QCheckBox* progress_display_available_episodes =
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
89 new QCheckBox(tr("Display available episodes in library folders"), progress_group_box);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
90 connect(progress_display_available_episodes, &QCheckBox::stateChanged, this,
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
91 [this](int state) { display_available_episodes = !(state == Qt::Unchecked); });
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
92 progress_display_available_episodes->setCheckState(display_available_episodes ? Qt::Checked : Qt::Unchecked);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
93
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
94 QVBoxLayout* progress_layout = new QVBoxLayout(progress_group_box);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
95 progress_layout->addWidget(progress_display_aired_episodes);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
96 progress_layout->addWidget(progress_display_available_episodes);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
97
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
98 QVBoxLayout* full_layout = new QVBoxLayout(result);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
99 full_layout->addWidget(actions_group_box);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
100 full_layout->addWidget(appearance_group_box);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
101 full_layout->addWidget(progress_group_box);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
102 full_layout->setSpacing(10);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
103 full_layout->addStretch();
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 62
diff changeset
104
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
105 return result;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
106 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
107
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
108 void SettingsPageApplication::SaveInfo() {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
109 session.config.anime_list.language = language;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
110 session.config.anime_list.highlighted_anime_above_others = highlighted_anime_above_others;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
111 session.config.anime_list.highlight_anime_if_available = highlight_anime_if_available;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
112 session.config.anime_list.display_aired_episodes = display_aired_episodes;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
113 session.config.anime_list.display_available_episodes = display_available_episodes;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
114 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
115
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
116 SettingsPageApplication::SettingsPageApplication(QWidget* parent) : SettingsPage(parent, tr("Application")) {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
117 language = session.config.anime_list.language;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
118 highlighted_anime_above_others = session.config.anime_list.highlighted_anime_above_others;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
119 highlight_anime_if_available = session.config.anime_list.highlight_anime_if_available;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
120 display_aired_episodes = session.config.anime_list.display_aired_episodes;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
121 display_available_episodes = session.config.anime_list.display_available_episodes;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
122 AddTab(CreateAnimeListWidget(), tr("Anime list"));
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
123 }