Mercurial > minori
annotate src/gui/dialog/settings/application.cc @ 101:c537996cf67b
*: multitude of config changes
1. theme is now configurable from the settings menu
(but you have to restart for it to apply)
2. config is now stored in an INI file, with no method of
conversion from json (this repo is private-ish anyway)
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Fri, 03 Nov 2023 14:06:02 -0400 |
parents | 9b2b41f83a5e |
children | b315f3759c56 |
rev | line source |
---|---|
10 | 1 #include "core/session.h" |
2 #include "gui/dialog/settings.h" | |
101
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
3 #include "gui/dark_theme.h" |
10 | 4 #include <QCheckBox> |
5 #include <QComboBox> | |
6 #include <QGroupBox> | |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
62
diff
changeset
|
7 #include <QHBoxLayout> |
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
62
diff
changeset
|
8 #include <QLabel> |
10 | 9 #include <QPushButton> |
10 #include <QSizePolicy> | |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
62
diff
changeset
|
11 #include <QVBoxLayout> |
10 | 12 |
13 QWidget* SettingsPageApplication::CreateAnimeListWidget() { | |
14 QWidget* result = new QWidget(this); | |
15 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
16 | |
17 QGroupBox* actions_group_box = new QGroupBox(tr("Actions"), result); | |
18 actions_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
19 | |
20 /* Actions/Double click */ | |
21 QWidget* double_click_widget = new QWidget(actions_group_box); | |
22 QLabel* dc_combo_box_label = new QLabel(tr("Double click:"), double_click_widget); | |
23 QComboBox* dc_combo_box = new QComboBox(double_click_widget); | |
24 dc_combo_box->addItem(tr("View anime info")); | |
25 | |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
62
diff
changeset
|
26 QVBoxLayout* double_click_layout = new QVBoxLayout(double_click_widget); |
10 | 27 double_click_layout->addWidget(dc_combo_box_label); |
28 double_click_layout->addWidget(dc_combo_box); | |
62 | 29 double_click_layout->setContentsMargins(0, 0, 0, 0); |
10 | 30 |
31 /* Actions/Middle click */ | |
32 QWidget* middle_click_widget = new QWidget(actions_group_box); | |
33 QLabel* mc_combo_box_label = new QLabel(tr("Middle click:"), middle_click_widget); | |
34 QComboBox* mc_combo_box = new QComboBox(middle_click_widget); | |
35 mc_combo_box->addItem(tr("Play next episode")); | |
36 | |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
62
diff
changeset
|
37 QVBoxLayout* middle_click_layout = new QVBoxLayout(middle_click_widget); |
10 | 38 middle_click_layout->addWidget(mc_combo_box_label); |
39 middle_click_layout->addWidget(mc_combo_box); | |
62 | 40 middle_click_layout->setContentsMargins(0, 0, 0, 0); |
10 | 41 |
42 /* Actions */ | |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
62
diff
changeset
|
43 QHBoxLayout* actions_layout = new QHBoxLayout(actions_group_box); |
10 | 44 actions_layout->addWidget(double_click_widget); |
45 actions_layout->addWidget(middle_click_widget); | |
46 | |
47 QGroupBox* appearance_group_box = new QGroupBox(tr("Appearance"), result); | |
48 appearance_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
49 | |
50 QLabel* lang_combo_box_label = new QLabel(tr("Title language preference:"), 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")); | |
54 lang_combo_box->addItem(tr("English")); | |
55 connect(lang_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, | |
15 | 56 [this](int index) { language = static_cast<Anime::TitleLanguage>(index); }); |
10 | 57 lang_combo_box->setCurrentIndex(static_cast<int>(language)); |
58 | |
101
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
59 QLabel* theme_combo_box_label = new QLabel(tr("Application theme:"), appearance_group_box); |
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
60 QComboBox* theme_combo_box = new QComboBox(appearance_group_box); |
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
61 theme_combo_box->addItem(tr("Default")); |
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
62 theme_combo_box->addItem(tr("Light")); |
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
63 theme_combo_box->addItem(tr("Dark")); |
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
64 connect(theme_combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, |
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
65 [this](int index) { theme = static_cast<Themes>(index); }); |
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
66 theme_combo_box->setCurrentIndex(static_cast<int>(theme)); |
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
67 |
10 | 68 QCheckBox* hl_anime_box = |
15 | 69 new QCheckBox(tr("Highlight anime if next episode is available in library folders"), appearance_group_box); |
10 | 70 QCheckBox* hl_above_anime_box = new QCheckBox(tr("Display highlighted anime above others"), appearance_group_box); |
71 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
|
72 highlight_anime_if_available = !(state == Qt::Unchecked); |
10 | 73 hl_above_anime_box->setEnabled(state); |
74 }); | |
75 connect(hl_above_anime_box, &QCheckBox::stateChanged, this, | |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
62
diff
changeset
|
76 [this](int state) { highlight_anime_if_available = !(state == Qt::Unchecked); }); |
10 | 77 hl_anime_box->setCheckState(highlight_anime_if_available ? Qt::Checked : Qt::Unchecked); |
78 hl_above_anime_box->setCheckState(highlighted_anime_above_others ? Qt::Checked : Qt::Unchecked); | |
79 hl_above_anime_box->setEnabled(hl_anime_box->checkState() != Qt::Unchecked); | |
36 | 80 hl_above_anime_box->setContentsMargins(10, 0, 0, 0); |
10 | 81 |
82 /* Appearance */ | |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
62
diff
changeset
|
83 QVBoxLayout* appearance_layout = new QVBoxLayout(appearance_group_box); |
10 | 84 appearance_layout->addWidget(lang_combo_box_label); |
85 appearance_layout->addWidget(lang_combo_box); | |
101
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
86 appearance_layout->addWidget(theme_combo_box_label); |
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
87 appearance_layout->addWidget(theme_combo_box); |
10 | 88 appearance_layout->addWidget(hl_anime_box); |
89 appearance_layout->addWidget(hl_above_anime_box); | |
90 | |
91 QGroupBox* progress_group_box = new QGroupBox(tr("Progress"), result); | |
92 progress_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
93 | |
94 QCheckBox* progress_display_aired_episodes = | |
15 | 95 new QCheckBox(tr("Display aired episodes (estimated)"), progress_group_box); |
10 | 96 connect(progress_display_aired_episodes, &QCheckBox::stateChanged, this, |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
62
diff
changeset
|
97 [this](int state) { display_aired_episodes = !(state == Qt::Unchecked); }); |
10 | 98 progress_display_aired_episodes->setCheckState(display_aired_episodes ? Qt::Checked : Qt::Unchecked); |
99 | |
100 QCheckBox* progress_display_available_episodes = | |
15 | 101 new QCheckBox(tr("Display available episodes in library folders"), progress_group_box); |
10 | 102 connect(progress_display_available_episodes, &QCheckBox::stateChanged, this, |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
62
diff
changeset
|
103 [this](int state) { display_available_episodes = !(state == Qt::Unchecked); }); |
10 | 104 progress_display_available_episodes->setCheckState(display_available_episodes ? Qt::Checked : Qt::Unchecked); |
105 | |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
62
diff
changeset
|
106 QVBoxLayout* progress_layout = new QVBoxLayout(progress_group_box); |
10 | 107 progress_layout->addWidget(progress_display_aired_episodes); |
108 progress_layout->addWidget(progress_display_available_episodes); | |
109 | |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
62
diff
changeset
|
110 QVBoxLayout* full_layout = new QVBoxLayout(result); |
10 | 111 full_layout->addWidget(actions_group_box); |
112 full_layout->addWidget(appearance_group_box); | |
113 full_layout->addWidget(progress_group_box); | |
114 full_layout->setSpacing(10); | |
115 full_layout->addStretch(); | |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
62
diff
changeset
|
116 |
10 | 117 return result; |
118 } | |
119 | |
120 void SettingsPageApplication::SaveInfo() { | |
121 session.config.anime_list.language = language; | |
122 session.config.anime_list.highlighted_anime_above_others = highlighted_anime_above_others; | |
123 session.config.anime_list.highlight_anime_if_available = highlight_anime_if_available; | |
124 session.config.anime_list.display_aired_episodes = display_aired_episodes; | |
125 session.config.anime_list.display_available_episodes = display_available_episodes; | |
101
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
126 session.config.theme = theme; |
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
127 DarkTheme::SetTheme(session.config.theme); |
10 | 128 } |
129 | |
130 SettingsPageApplication::SettingsPageApplication(QWidget* parent) : SettingsPage(parent, tr("Application")) { | |
131 language = session.config.anime_list.language; | |
101
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
132 theme = session.config.theme; |
10 | 133 highlighted_anime_above_others = session.config.anime_list.highlighted_anime_above_others; |
134 highlight_anime_if_available = session.config.anime_list.highlight_anime_if_available; | |
135 display_aired_episodes = session.config.anime_list.display_aired_episodes; | |
136 display_available_episodes = session.config.anime_list.display_available_episodes; | |
137 AddTab(CreateAnimeListWidget(), tr("Anime list")); | |
138 } |