Mercurial > minori
comparison src/gui/dialog/information.cc @ 83:d02fdf1d6708
*: huuuge update
1. make the now playing page function correctly
2. de-constructorfy many of our custom widgets,
allowing them to be changed on-the-fly from
the Now Playing page
3. ... :)
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Tue, 24 Oct 2023 22:01:02 -0400 |
parents | 9b2b41f83a5e |
children | c912128af0eb |
comparison
equal
deleted
inserted
replaced
82:8b65c417c225 | 83:d02fdf1d6708 |
---|---|
1 #include "gui/dialog/information.h" | 1 #include "gui/dialog/information.h" |
2 #include "core/anime.h" | 2 #include "core/anime.h" |
3 #include "core/anime_db.h" | 3 #include "core/anime_db.h" |
4 #include "core/array.h" | |
5 #include "core/strings.h" | 4 #include "core/strings.h" |
6 #include "gui/pages/anime_list.h" | 5 #include "gui/pages/anime_list.h" |
7 #include "gui/translate/anime.h" | 6 #include "gui/translate/anime.h" |
8 #include "gui/widgets/anime_info.h" | 7 #include "gui/widgets/anime_info.h" |
9 #include "gui/widgets/optional_date.h" | 8 #include "gui/widgets/optional_date.h" |
24 #include <QVBoxLayout> | 23 #include <QVBoxLayout> |
25 #include <functional> | 24 #include <functional> |
26 | 25 |
27 /* TODO: Taiga disables rendering of the tab widget entirely when the anime is not part of a list, | 26 /* TODO: Taiga disables rendering of the tab widget entirely when the anime is not part of a list, |
28 which sucks. Think of a better way to implement this later. */ | 27 which sucks. Think of a better way to implement this later. */ |
29 void InformationDialog::SaveData() { | 28 void InformationDialog::SaveData(Anime::Anime& anime) { |
30 Anime::Anime& anime = Anime::db.items[id]; | 29 anime.SetUserProgress(_progress); |
31 anime.SetUserProgress(progress); | 30 anime.SetUserScore(_score); |
32 anime.SetUserScore(score); | 31 anime.SetUserIsRewatching(_rewatching); |
33 anime.SetUserIsRewatching(rewatching); | 32 anime.SetUserStatus(_status); |
34 anime.SetUserStatus(status); | 33 anime.SetUserNotes(_notes); |
35 anime.SetUserNotes(notes); | 34 anime.SetUserDateStarted(_started); |
36 anime.SetUserDateStarted(started); | 35 anime.SetUserDateCompleted(_completed); |
37 anime.SetUserDateCompleted(completed); | |
38 } | 36 } |
39 | 37 |
40 InformationDialog::InformationDialog(const Anime::Anime& anime, std::function<void()> accept, QWidget* parent) | 38 InformationDialog::InformationDialog(Anime::Anime& anime, std::function<void()> accept, QWidget* parent) |
41 : QDialog(parent) { | 39 : QDialog(parent) { |
42 setFixedSize(842, 613); | 40 setFixedSize(842, 613); |
43 setWindowTitle(tr("Anime Information")); | 41 setWindowTitle(tr("Anime Information")); |
44 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); | 42 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); |
45 | 43 |
52 QWidget* widget = new QWidget(this); | 50 QWidget* widget = new QWidget(this); |
53 | 51 |
54 /* "sidebar", includes... just the anime image :) */ | 52 /* "sidebar", includes... just the anime image :) */ |
55 QWidget* sidebar = new QWidget(widget); | 53 QWidget* sidebar = new QWidget(widget); |
56 QVBoxLayout* sidebar_layout = new QVBoxLayout(sidebar); | 54 QVBoxLayout* sidebar_layout = new QVBoxLayout(sidebar); |
57 Poster* poster = new Poster(anime.GetId(), sidebar); | 55 Poster* poster = new Poster(anime, sidebar); |
58 sidebar_layout->addWidget(poster); | 56 sidebar_layout->addWidget(poster); |
59 sidebar_layout->setContentsMargins(0, 0, 0, 0); | 57 sidebar_layout->setContentsMargins(0, 0, 0, 0); |
60 sidebar_layout->addStretch(); | 58 sidebar_layout->addStretch(); |
61 | 59 |
62 /* main widget */ | 60 /* main widget */ |
63 QWidget* main_widget = new QWidget(widget); | 61 QWidget* main_widget = new QWidget(widget); |
64 | 62 |
65 main_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | 63 main_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
66 | 64 |
67 id = anime.GetId(); | |
68 /* anime title header text */ | 65 /* anime title header text */ |
69 TextWidgets::Title* anime_title = | 66 TextWidgets::Title* anime_title = |
70 new TextWidgets::Title(Strings::ToQString(anime.GetUserPreferredTitle()), main_widget); | 67 new TextWidgets::Title(Strings::ToQString(anime.GetUserPreferredTitle()), main_widget); |
71 | 68 |
72 /* tabbed widget */ | 69 /* tabbed widget */ |
129 /* Episodes watched section */ | 126 /* Episodes watched section */ |
130 CREATE_SUBSECTION({ | 127 CREATE_SUBSECTION({ |
131 subsection_layout->addWidget(new QLabel(tr("Episodes watched:"), subsection)); | 128 subsection_layout->addWidget(new QLabel(tr("Episodes watched:"), subsection)); |
132 | 129 |
133 QSpinBox* spin_box = new QSpinBox(subsection); | 130 QSpinBox* spin_box = new QSpinBox(subsection); |
134 connect(spin_box, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int i) { progress = i; }); | 131 connect(spin_box, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int i) { _progress = i; }); |
135 spin_box->setRange(0, anime.GetEpisodes()); | 132 spin_box->setRange(0, anime.GetEpisodes()); |
136 spin_box->setSingleStep(1); | 133 spin_box->setSingleStep(1); |
137 spin_box->setValue(progress = anime.GetUserProgress()); | 134 spin_box->setValue(_progress = anime.GetUserProgress()); |
138 subsection_layout->addWidget(spin_box); | 135 subsection_layout->addWidget(spin_box); |
139 }); | 136 }); |
140 CREATE_SUBSECTION({ | 137 CREATE_SUBSECTION({ |
141 subsection_layout->addWidget(new QLabel(tr(" "), subsection)); | 138 subsection_layout->addWidget(new QLabel(tr(" "), subsection)); |
142 | 139 |
143 QCheckBox* checkbox = new QCheckBox(tr("Rewatching")); | 140 QCheckBox* checkbox = new QCheckBox(tr("Rewatching")); |
144 connect(checkbox, QOverload<int>::of(&QCheckBox::stateChanged), this, | 141 connect(checkbox, QOverload<int>::of(&QCheckBox::stateChanged), this, |
145 [this](int state) { rewatching = (state == Qt::Checked); }); | 142 [this](int state) { _rewatching = (state == Qt::Checked); }); |
146 checkbox->setCheckState(anime.GetUserIsRewatching() ? Qt::Checked : Qt::Unchecked); | 143 checkbox->setCheckState((_rewatching = anime.GetUserIsRewatching()) ? Qt::Checked : Qt::Unchecked); |
147 subsection_layout->addWidget(checkbox); | 144 subsection_layout->addWidget(checkbox); |
148 }); | 145 }); |
149 }); | 146 }); |
150 CREATE_SECTION(sg_anime_list_content, { | 147 CREATE_SECTION(sg_anime_list_content, { |
151 /* Status & score section */ | 148 /* Status & score section */ |
152 CREATE_SUBSECTION({ | 149 CREATE_SUBSECTION({ |
153 subsection_layout->addWidget(new QLabel(tr("Status:"), subsection)); | 150 subsection_layout->addWidget(new QLabel(tr("Status:"), subsection)); |
154 | 151 |
155 QStringList string_list; | 152 QStringList string_list; |
156 for (unsigned int i = 0; i < ARRAYSIZE(Anime::ListStatuses); i++) | 153 for (unsigned int i = 0; i < Anime::ListStatuses.size(); i++) |
157 string_list.append(Strings::ToQString(Translate::ToString(Anime::ListStatuses[i]))); | 154 string_list.append(Strings::ToQString(Translate::ToString(Anime::ListStatuses[i]))); |
158 | 155 |
159 QComboBox* combo_box = new QComboBox(subsection); | 156 QComboBox* combo_box = new QComboBox(subsection); |
160 combo_box->addItems(string_list); | 157 combo_box->addItems(string_list); |
161 connect(combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, | 158 connect(combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, |
162 [this](int i) { status = Anime::ListStatuses[i]; }); | 159 [this](int i) { _status = Anime::ListStatuses[i]; }); |
163 combo_box->setCurrentIndex(static_cast<int>(status = anime.GetUserStatus()) - 1); | 160 combo_box->setCurrentIndex(static_cast<int>(_status = anime.GetUserStatus()) - 1); |
164 subsection_layout->addWidget(combo_box); | 161 subsection_layout->addWidget(combo_box); |
165 }); | 162 }); |
166 CREATE_SUBSECTION({ | 163 CREATE_SUBSECTION({ |
167 subsection_layout->addWidget(new QLabel(tr("Score:"), subsection)); | 164 subsection_layout->addWidget(new QLabel(tr("Score:"), subsection)); |
168 | 165 |
169 QSpinBox* spin_box = new QSpinBox(subsection); | 166 QSpinBox* spin_box = new QSpinBox(subsection); |
170 connect(spin_box, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int i) { score = i; }); | 167 connect(spin_box, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int i) { _score = i; }); |
171 spin_box->setRange(0, 100); | 168 spin_box->setRange(0, 100); |
172 spin_box->setSingleStep(5); | 169 spin_box->setSingleStep(5); |
173 spin_box->setValue(score = anime.GetUserScore()); | 170 spin_box->setValue(_score = anime.GetUserScore()); |
174 subsection_layout->addWidget(spin_box); | 171 subsection_layout->addWidget(spin_box); |
175 }); | 172 }); |
176 }); | 173 }); |
177 CREATE_FULL_WIDTH_SECTION(sg_anime_list_content, { | 174 CREATE_FULL_WIDTH_SECTION(sg_anime_list_content, { |
178 /* Notes section */ | 175 /* Notes section */ |
180 subsection_layout->addWidget(new QLabel(tr("Notes:"), subsection)); | 177 subsection_layout->addWidget(new QLabel(tr("Notes:"), subsection)); |
181 | 178 |
182 QLineEdit* line_edit = new QLineEdit(subsection); | 179 QLineEdit* line_edit = new QLineEdit(subsection); |
183 connect(line_edit, &QLineEdit::textChanged, this, [this](const QString& text) { | 180 connect(line_edit, &QLineEdit::textChanged, this, [this](const QString& text) { |
184 /* this sucks but I don't really want to implement anything smarter :) */ | 181 /* this sucks but I don't really want to implement anything smarter :) */ |
185 notes = Strings::ToUtf8String(text); | 182 _notes = Strings::ToUtf8String(text); |
186 }); | 183 }); |
187 line_edit->setText(Strings::ToQString(notes = anime.GetUserNotes())); | 184 line_edit->setText(Strings::ToQString(_notes = anime.GetUserNotes())); |
188 line_edit->setPlaceholderText(tr("Enter your notes about this anime")); | 185 line_edit->setPlaceholderText(tr("Enter your notes about this anime")); |
189 subsection_layout->addWidget(line_edit); | 186 subsection_layout->addWidget(line_edit); |
190 }); | 187 }); |
191 }); | 188 }); |
192 CREATE_SECTION(sg_anime_list_content, { | 189 CREATE_SECTION(sg_anime_list_content, { |
194 CREATE_SUBSECTION({ | 191 CREATE_SUBSECTION({ |
195 subsection_layout->addWidget(new QLabel(tr("Date started:"), subsection)); | 192 subsection_layout->addWidget(new QLabel(tr("Date started:"), subsection)); |
196 | 193 |
197 OptionalDate* date = new OptionalDate(true, subsection); | 194 OptionalDate* date = new OptionalDate(true, subsection); |
198 connect(date, &OptionalDate::DataChanged, this, | 195 connect(date, &OptionalDate::DataChanged, this, |
199 [this](bool enabled, Date date) { started = (enabled) ? date : Date(); }); | 196 [this](bool enabled, Date date) { _started = (enabled) ? date : Date(); }); |
200 started = anime.GetUserDateStarted(); | 197 _started = anime.GetUserDateStarted(); |
201 if (!started.IsValid()) { | 198 if (!_started.IsValid()) { |
202 date->SetEnabled(false); | 199 date->SetEnabled(false); |
203 started = anime.GetAirDate(); | 200 _started = anime.GetAirDate(); |
204 } | 201 } |
205 date->SetDate(started); | 202 date->SetDate(_started); |
206 subsection_layout->addWidget(date); | 203 subsection_layout->addWidget(date); |
207 }); | 204 }); |
208 CREATE_SUBSECTION({ | 205 CREATE_SUBSECTION({ |
209 subsection_layout->addWidget(new QLabel(tr("Date completed:"), subsection)); | 206 subsection_layout->addWidget(new QLabel(tr("Date completed:"), subsection)); |
210 | 207 |
211 OptionalDate* date = new OptionalDate(true, subsection); | 208 OptionalDate* date = new OptionalDate(true, subsection); |
212 connect(date, &OptionalDate::DataChanged, this, | 209 connect(date, &OptionalDate::DataChanged, this, |
213 [this](bool enabled, Date date) { completed = (enabled) ? date : Date(); }); | 210 [this](bool enabled, Date date) { _completed = (enabled) ? date : Date(); }); |
214 completed = anime.GetUserDateCompleted(); | 211 _completed = anime.GetUserDateCompleted(); |
215 if (!completed.IsValid()) { | 212 if (!_completed.IsValid()) { |
216 date->SetEnabled(false); | 213 date->SetEnabled(false); |
217 completed = anime.GetAirDate(); | 214 _completed = anime.GetAirDate(); |
218 } | 215 } |
219 date->SetDate(completed); | 216 date->SetDate(_completed); |
220 subsection_layout->addWidget(date); | 217 subsection_layout->addWidget(date); |
221 }); | 218 }); |
222 }); | 219 }); |
223 | 220 |
224 settings_layout->addWidget(sg_anime_list_content); | 221 settings_layout->addWidget(sg_anime_list_content); |
264 layout->addWidget(sidebar); | 261 layout->addWidget(sidebar); |
265 layout->addWidget(main_widget); | 262 layout->addWidget(main_widget); |
266 layout->setSpacing(12); | 263 layout->setSpacing(12); |
267 | 264 |
268 QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); | 265 QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); |
269 connect(button_box, &QDialogButtonBox::accepted, this, [this, accept] { | 266 connect(button_box, &QDialogButtonBox::accepted, this, [this, accept, &anime] { |
270 SaveData(); | 267 SaveData(anime); |
271 accept(); | 268 accept(); |
272 QDialog::accept(); | 269 QDialog::accept(); |
273 }); | 270 }); |
274 connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject); | 271 connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject); |
275 | 272 |