comparison 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
comparison
equal deleted inserted replaced
67:442065432549 68:2417121d894e
1 #include "core/session.h" 1 #include "core/session.h"
2 #include "gui/dialog/settings.h" 2 #include "gui/dialog/settings.h"
3 #include <QCheckBox> 3 #include <QCheckBox>
4 #include <QComboBox> 4 #include <QComboBox>
5 #include <QGroupBox> 5 #include <QGroupBox>
6 #include <QHBoxLayout>
7 #include <QLabel>
6 #include <QPushButton> 8 #include <QPushButton>
7 #include <QSizePolicy> 9 #include <QSizePolicy>
10 #include <QVBoxLayout>
8 11
9 QWidget* SettingsPageApplication::CreateAnimeListWidget() { 12 QWidget* SettingsPageApplication::CreateAnimeListWidget() {
10 QWidget* result = new QWidget(this); 13 QWidget* result = new QWidget(this);
11 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); 14 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
12 15
17 QWidget* double_click_widget = new QWidget(actions_group_box); 20 QWidget* double_click_widget = new QWidget(actions_group_box);
18 QLabel* dc_combo_box_label = new QLabel(tr("Double click:"), double_click_widget); 21 QLabel* dc_combo_box_label = new QLabel(tr("Double click:"), double_click_widget);
19 QComboBox* dc_combo_box = new QComboBox(double_click_widget); 22 QComboBox* dc_combo_box = new QComboBox(double_click_widget);
20 dc_combo_box->addItem(tr("View anime info")); 23 dc_combo_box->addItem(tr("View anime info"));
21 24
22 QVBoxLayout* double_click_layout = new QVBoxLayout; 25 QVBoxLayout* double_click_layout = new QVBoxLayout(double_click_widget);
23 double_click_layout->addWidget(dc_combo_box_label); 26 double_click_layout->addWidget(dc_combo_box_label);
24 double_click_layout->addWidget(dc_combo_box); 27 double_click_layout->addWidget(dc_combo_box);
25 double_click_layout->setContentsMargins(0, 0, 0, 0); 28 double_click_layout->setContentsMargins(0, 0, 0, 0);
26 double_click_widget->setLayout(double_click_layout);
27 29
28 /* Actions/Middle click */ 30 /* Actions/Middle click */
29 QWidget* middle_click_widget = new QWidget(actions_group_box); 31 QWidget* middle_click_widget = new QWidget(actions_group_box);
30 QLabel* mc_combo_box_label = new QLabel(tr("Middle click:"), middle_click_widget); 32 QLabel* mc_combo_box_label = new QLabel(tr("Middle click:"), middle_click_widget);
31 QComboBox* mc_combo_box = new QComboBox(middle_click_widget); 33 QComboBox* mc_combo_box = new QComboBox(middle_click_widget);
32 mc_combo_box->addItem(tr("Play next episode")); 34 mc_combo_box->addItem(tr("Play next episode"));
33 35
34 QVBoxLayout* middle_click_layout = new QVBoxLayout; 36 QVBoxLayout* middle_click_layout = new QVBoxLayout(middle_click_widget);
35 middle_click_layout->addWidget(mc_combo_box_label); 37 middle_click_layout->addWidget(mc_combo_box_label);
36 middle_click_layout->addWidget(mc_combo_box); 38 middle_click_layout->addWidget(mc_combo_box);
37 middle_click_layout->setContentsMargins(0, 0, 0, 0); 39 middle_click_layout->setContentsMargins(0, 0, 0, 0);
38 middle_click_widget->setLayout(middle_click_layout);
39 40
40 /* Actions */ 41 /* Actions */
41 QHBoxLayout* actions_layout = new QHBoxLayout; 42 QHBoxLayout* actions_layout = new QHBoxLayout(actions_group_box);
42 actions_layout->addWidget(double_click_widget); 43 actions_layout->addWidget(double_click_widget);
43 actions_layout->addWidget(middle_click_widget); 44 actions_layout->addWidget(middle_click_widget);
44 actions_group_box->setLayout(actions_layout);
45 45
46 QGroupBox* appearance_group_box = new QGroupBox(tr("Appearance"), result); 46 QGroupBox* appearance_group_box = new QGroupBox(tr("Appearance"), result);
47 appearance_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); 47 appearance_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
48 48
49 QLabel* lang_combo_box_label = new QLabel(tr("Title language preference:"), appearance_group_box); 49 QLabel* lang_combo_box_label = new QLabel(tr("Title language preference:"), appearance_group_box);
57 57
58 QCheckBox* hl_anime_box = 58 QCheckBox* hl_anime_box =
59 new QCheckBox(tr("Highlight anime if next episode is available in library folders"), appearance_group_box); 59 new QCheckBox(tr("Highlight anime if next episode is available in library folders"), appearance_group_box);
60 QCheckBox* hl_above_anime_box = new QCheckBox(tr("Display highlighted anime above others"), appearance_group_box); 60 QCheckBox* hl_above_anime_box = new QCheckBox(tr("Display highlighted anime above others"), appearance_group_box);
61 connect(hl_anime_box, &QCheckBox::stateChanged, this, [this, hl_above_anime_box](int state) { 61 connect(hl_anime_box, &QCheckBox::stateChanged, this, [this, hl_above_anime_box](int state) {
62 highlight_anime_if_available = (state == Qt::Unchecked) ? false : true; 62 highlight_anime_if_available = !(state == Qt::Unchecked);
63 hl_above_anime_box->setEnabled(state); 63 hl_above_anime_box->setEnabled(state);
64 }); 64 });
65 connect(hl_above_anime_box, &QCheckBox::stateChanged, this, 65 connect(hl_above_anime_box, &QCheckBox::stateChanged, this,
66 [this](int state) { highlight_anime_if_available = (state == Qt::Unchecked) ? false : true; }); 66 [this](int state) { highlight_anime_if_available = !(state == Qt::Unchecked); });
67 hl_anime_box->setCheckState(highlight_anime_if_available ? Qt::Checked : Qt::Unchecked); 67 hl_anime_box->setCheckState(highlight_anime_if_available ? Qt::Checked : Qt::Unchecked);
68 hl_above_anime_box->setCheckState(highlighted_anime_above_others ? Qt::Checked : Qt::Unchecked); 68 hl_above_anime_box->setCheckState(highlighted_anime_above_others ? Qt::Checked : Qt::Unchecked);
69 hl_above_anime_box->setEnabled(hl_anime_box->checkState() != Qt::Unchecked); 69 hl_above_anime_box->setEnabled(hl_anime_box->checkState() != Qt::Unchecked);
70 hl_above_anime_box->setContentsMargins(10, 0, 0, 0); 70 hl_above_anime_box->setContentsMargins(10, 0, 0, 0);
71 71
72 /* Appearance */ 72 /* Appearance */
73 QVBoxLayout* appearance_layout = new QVBoxLayout; 73 QVBoxLayout* appearance_layout = new QVBoxLayout(appearance_group_box);
74 appearance_layout->addWidget(lang_combo_box_label); 74 appearance_layout->addWidget(lang_combo_box_label);
75 appearance_layout->addWidget(lang_combo_box); 75 appearance_layout->addWidget(lang_combo_box);
76 appearance_layout->addWidget(hl_anime_box); 76 appearance_layout->addWidget(hl_anime_box);
77 appearance_layout->addWidget(hl_above_anime_box); 77 appearance_layout->addWidget(hl_above_anime_box);
78 appearance_group_box->setLayout(appearance_layout);
79 78
80 QGroupBox* progress_group_box = new QGroupBox(tr("Progress"), result); 79 QGroupBox* progress_group_box = new QGroupBox(tr("Progress"), result);
81 progress_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); 80 progress_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
82 81
83 QCheckBox* progress_display_aired_episodes = 82 QCheckBox* progress_display_aired_episodes =
84 new QCheckBox(tr("Display aired episodes (estimated)"), progress_group_box); 83 new QCheckBox(tr("Display aired episodes (estimated)"), progress_group_box);
85 connect(progress_display_aired_episodes, &QCheckBox::stateChanged, this, 84 connect(progress_display_aired_episodes, &QCheckBox::stateChanged, this,
86 [this](int state) { display_aired_episodes = (state == Qt::Unchecked) ? false : true; }); 85 [this](int state) { display_aired_episodes = !(state == Qt::Unchecked); });
87 progress_display_aired_episodes->setCheckState(display_aired_episodes ? Qt::Checked : Qt::Unchecked); 86 progress_display_aired_episodes->setCheckState(display_aired_episodes ? Qt::Checked : Qt::Unchecked);
88 87
89 QCheckBox* progress_display_available_episodes = 88 QCheckBox* progress_display_available_episodes =
90 new QCheckBox(tr("Display available episodes in library folders"), progress_group_box); 89 new QCheckBox(tr("Display available episodes in library folders"), progress_group_box);
91 connect(progress_display_available_episodes, &QCheckBox::stateChanged, this, 90 connect(progress_display_available_episodes, &QCheckBox::stateChanged, this,
92 [this](int state) { display_available_episodes = (state == Qt::Unchecked) ? false : true; }); 91 [this](int state) { display_available_episodes = !(state == Qt::Unchecked); });
93 progress_display_available_episodes->setCheckState(display_available_episodes ? Qt::Checked : Qt::Unchecked); 92 progress_display_available_episodes->setCheckState(display_available_episodes ? Qt::Checked : Qt::Unchecked);
94 93
95 QVBoxLayout* progress_layout = new QVBoxLayout; 94 QVBoxLayout* progress_layout = new QVBoxLayout(progress_group_box);
96 progress_layout->addWidget(progress_display_aired_episodes); 95 progress_layout->addWidget(progress_display_aired_episodes);
97 progress_layout->addWidget(progress_display_available_episodes); 96 progress_layout->addWidget(progress_display_available_episodes);
98 progress_group_box->setLayout(progress_layout);
99 97
100 QVBoxLayout* full_layout = new QVBoxLayout; 98 QVBoxLayout* full_layout = new QVBoxLayout(result);
101 full_layout->addWidget(actions_group_box); 99 full_layout->addWidget(actions_group_box);
102 full_layout->addWidget(appearance_group_box); 100 full_layout->addWidget(appearance_group_box);
103 full_layout->addWidget(progress_group_box); 101 full_layout->addWidget(progress_group_box);
104 full_layout->setSpacing(10); 102 full_layout->setSpacing(10);
105 full_layout->addStretch(); 103 full_layout->addStretch();
106 result->setLayout(full_layout); 104
107 return result; 105 return result;
108 } 106 }
109 107
110 void SettingsPageApplication::SaveInfo() { 108 void SettingsPageApplication::SaveInfo() {
111 session.config.anime_list.language = language; 109 session.config.anime_list.language = language;