comparison src/gui/dialog/information.cpp @ 51:75c804f713b2

window: add about window, *: use tr() when applicable (useful for i18n)
author Paper <mrpapersonic@gmail.com>
date Mon, 25 Sep 2023 20:29:26 -0400
parents d8eb763e6661
children 4c6dd5999b39
comparison
equal deleted inserted replaced
50:10868c3fb2be 51:75c804f713b2
23 23
24 /* TODO: Taiga disables rendering of the tab widget entirely when the anime is not part of a list, 24 /* TODO: Taiga disables rendering of the tab widget entirely when the anime is not part of a list,
25 which sucks. Think of a better way to implement this later. */ 25 which sucks. Think of a better way to implement this later. */
26 void InformationDialog::SaveData() { 26 void InformationDialog::SaveData() {
27 Anime::Anime& anime = Anime::db.items[id]; 27 Anime::Anime& anime = Anime::db.items[id];
28 anime.SetUserProgress(progress);
29 anime.SetUserScore(score);
30 anime.SetUserIsRewatching(rewatching);
31 anime.SetUserStatus(status);
32 anime.SetUserNotes(notes);
33 anime.SetUserDateStarted(started);
34 anime.SetUserDateCompleted(completed);
28 } 35 }
29 36
30 InformationDialog::InformationDialog(const Anime::Anime& anime, std::function<void()> accept, QWidget* parent) 37 InformationDialog::InformationDialog(const Anime::Anime& anime, std::function<void()> accept, QWidget* parent)
31 : QDialog(parent) { 38 : QDialog(parent) {
32 setFixedSize(842, 613); 39 setFixedSize(842, 613);
54 main_widget->setPalette(pal); 61 main_widget->setPalette(pal);
55 } 62 }
56 63
57 main_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); 64 main_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
58 65
66 id = anime.GetId();
59 /* anime title header text */ 67 /* anime title header text */
60 TextWidgets::Paragraph* anime_title = 68 TextWidgets::Paragraph* anime_title =
61 new TextWidgets::Paragraph(QString::fromUtf8(anime.GetUserPreferredTitle().c_str()), main_widget); 69 new TextWidgets::Paragraph(QString::fromUtf8(anime.GetUserPreferredTitle().c_str()), main_widget);
62 anime_title->setReadOnly(true); 70 anime_title->setReadOnly(true);
63 anime_title->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 71 anime_title->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
87 QWidget* main_information_widget = new QWidget(tabbed_widget); 95 QWidget* main_information_widget = new QWidget(tabbed_widget);
88 main_information_widget->setLayout(new QVBoxLayout); 96 main_information_widget->setLayout(new QVBoxLayout);
89 97
90 /* alt titles */ 98 /* alt titles */
91 main_information_widget->layout()->addWidget(new TextWidgets::SelectableTextParagraph( 99 main_information_widget->layout()->addWidget(new TextWidgets::SelectableTextParagraph(
92 "Alternative titles", QString::fromUtf8(Strings::Implode(anime.GetTitleSynonyms(), ", ").c_str()), 100 tr("Alternative titles"), QString::fromUtf8(Strings::Implode(anime.GetTitleSynonyms(), ", ").c_str()),
93 main_information_widget)); 101 main_information_widget));
94 102
95 /* details */ 103 /* details */
96 QString details_data; 104 QString details_data;
97 QTextStream details_data_s(&details_data); 105 QTextStream details_data_s(&details_data);
100 << Translate::ToString(anime.GetUserStatus()).c_str() << "\n" 108 << Translate::ToString(anime.GetUserStatus()).c_str() << "\n"
101 << Translate::ToString(anime.GetSeason()).c_str() << " " << anime.GetAirDate().GetYear() << "\n" 109 << Translate::ToString(anime.GetSeason()).c_str() << " " << anime.GetAirDate().GetYear() << "\n"
102 << Strings::Implode(anime.GetGenres(), ", ").c_str() << "\n" 110 << Strings::Implode(anime.GetGenres(), ", ").c_str() << "\n"
103 << anime.GetAudienceScore() << "%"; 111 << anime.GetAudienceScore() << "%";
104 main_information_widget->layout()->addWidget(new TextWidgets::LabelledTextParagraph( 112 main_information_widget->layout()->addWidget(new TextWidgets::LabelledTextParagraph(
105 "Details", "Type:\nEpisodes:\nStatus:\nSeason:\nGenres:\nScore:", details_data, main_information_widget)); 113 tr("Details"), tr("Type:\nEpisodes:\nStatus:\nSeason:\nGenres:\nScore:"), details_data, main_information_widget));
106 114
107 /* synopsis */ 115 /* synopsis */
108 TextWidgets::SelectableTextParagraph* synopsis = new TextWidgets::SelectableTextParagraph( 116 TextWidgets::SelectableTextParagraph* synopsis = new TextWidgets::SelectableTextParagraph(
109 "Synopsis", QString::fromUtf8(anime.GetSynopsis().c_str()), main_information_widget); 117 tr("Synopsis"), QString::fromUtf8(anime.GetSynopsis().c_str()), main_information_widget);
110 118
111 synopsis->GetParagraph()->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); 119 synopsis->GetParagraph()->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
112 main_information_widget->layout()->addWidget(synopsis); 120 main_information_widget->layout()->addWidget(synopsis);
113 121
114 QWidget* settings_widget = new QWidget(tabbed_widget); 122 QWidget* settings_widget = new QWidget(tabbed_widget);
176 /* Episodes watched section */ 184 /* Episodes watched section */
177 CREATE_SUBSECTION({ 185 CREATE_SUBSECTION({
178 subsection->layout()->addWidget(new QLabel(tr("Episodes watched:"), subsection)); 186 subsection->layout()->addWidget(new QLabel(tr("Episodes watched:"), subsection));
179 187
180 QSpinBox* spin_box = new QSpinBox(subsection); 188 QSpinBox* spin_box = new QSpinBox(subsection);
189 connect(spin_box, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int i) {
190 progress = i;
191 });
181 spin_box->setRange(0, anime.GetEpisodes()); 192 spin_box->setRange(0, anime.GetEpisodes());
182 spin_box->setSingleStep(1); 193 spin_box->setSingleStep(1);
183 spin_box->setValue(anime.GetUserProgress()); 194 spin_box->setValue(progress = anime.GetUserProgress());
184 subsection->layout()->addWidget(spin_box); 195 subsection->layout()->addWidget(spin_box);
185 }); 196 });
186 CREATE_SUBSECTION({ 197 CREATE_SUBSECTION({
187 subsection->layout()->addWidget(new QLabel(tr(" "), subsection)); 198 subsection->layout()->addWidget(new QLabel(tr(" "), subsection));
188 199
189 QCheckBox* rewatched_checkbox = new QCheckBox("Rewatching"); 200 QCheckBox* checkbox = new QCheckBox(tr("Rewatching"));
190 subsection->layout()->addWidget(rewatched_checkbox); 201 connect(checkbox, QOverload<int>::of(&QCheckBox::stateChanged), this, [this](int state) {
202 rewatching = (state == Qt::Checked);
203 });
204 checkbox->setCheckState(anime.GetUserIsRewatching() ? Qt::Checked : Qt::Unchecked);
205 subsection->layout()->addWidget(checkbox);
191 }); 206 });
192 }); 207 });
193 CREATE_SECTION(sg_anime_list_content, { 208 CREATE_SECTION(sg_anime_list_content, {
194 /* Status & score section */ 209 /* Status & score section */
195 CREATE_SUBSECTION({ 210 CREATE_SUBSECTION({
199 for (unsigned int i = 0; i < ARRAYSIZE(Anime::ListStatuses); i++) 214 for (unsigned int i = 0; i < ARRAYSIZE(Anime::ListStatuses); i++)
200 string_list.append(QString::fromStdString(Translate::ToString(Anime::ListStatuses[i]))); 215 string_list.append(QString::fromStdString(Translate::ToString(Anime::ListStatuses[i])));
201 216
202 QComboBox* combo_box = new QComboBox(subsection); 217 QComboBox* combo_box = new QComboBox(subsection);
203 combo_box->addItems(string_list); 218 combo_box->addItems(string_list);
219 connect(combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this](int i) {
220 status = Anime::ListStatuses[i];
221 });
222 combo_box->setCurrentIndex(static_cast<int>(status = anime.GetUserStatus())-1);
204 subsection->layout()->addWidget(combo_box); 223 subsection->layout()->addWidget(combo_box);
205 }); 224 });
206 CREATE_SUBSECTION({ 225 CREATE_SUBSECTION({
207 subsection->layout()->addWidget(new QLabel(tr("Score:"), subsection)); 226 subsection->layout()->addWidget(new QLabel(tr("Score:"), subsection));
208 227
209 QSpinBox* spin_box = new QSpinBox(subsection); 228 QSpinBox* spin_box = new QSpinBox(subsection);
229 connect(spin_box, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int i) {
230 score = i;
231 });
210 spin_box->setRange(0, 100); 232 spin_box->setRange(0, 100);
211 spin_box->setSingleStep(5); 233 spin_box->setSingleStep(5);
212 spin_box->setValue(anime.GetUserScore()); 234 spin_box->setValue(score = anime.GetUserScore());
213 subsection->layout()->addWidget(spin_box); 235 subsection->layout()->addWidget(spin_box);
214 }); 236 });
215 }); 237 });
216 CREATE_FULL_WIDTH_SECTION(sg_anime_list_content, { 238 CREATE_FULL_WIDTH_SECTION(sg_anime_list_content, {
217 /* Notes section */ 239 /* Notes section */
218 CREATE_FULL_WIDTH_SUBSECTION({ 240 CREATE_FULL_WIDTH_SUBSECTION({
219 subsection->layout()->addWidget(new QLabel(tr("Notes:"), subsection)); 241 subsection->layout()->addWidget(new QLabel(tr("Notes:"), subsection));
220 242
221 QLineEdit* line_edit = new QLineEdit(QString::fromStdString(anime.GetUserNotes()), subsection); 243 QLineEdit* line_edit = new QLineEdit(subsection);
244 connect(line_edit, &QLineEdit::textChanged, this, [this](const QString& text) {
245 /* this sucks but I don't really want to implement anything smarter :) */
246 notes = text.toStdString();
247 });
248 line_edit->setText(QString::fromStdString(notes = anime.GetUserNotes()));
222 line_edit->setPlaceholderText(tr("Enter your notes about this anime")); 249 line_edit->setPlaceholderText(tr("Enter your notes about this anime"));
223 subsection->layout()->addWidget(line_edit); 250 subsection->layout()->addWidget(line_edit);
224 }); 251 });
225 }); 252 });
226 CREATE_SECTION(sg_anime_list_content, { 253 CREATE_SECTION(sg_anime_list_content, {
227 /* Dates section */ 254 /* Dates section */
228 CREATE_SUBSECTION({ 255 CREATE_SUBSECTION({
229 subsection->layout()->addWidget(new QLabel(tr("Date started:"), subsection)); 256 subsection->layout()->addWidget(new QLabel(tr("Date started:"), subsection));
230 257
231 OptionalDate* date = new OptionalDate(true, subsection); 258 OptionalDate* date = new OptionalDate(true, subsection);
232 date->SetDate(QDate(2000, 1, 1)); 259 connect(date, &OptionalDate::DataChanged, this, [this](bool enabled, Date date) {
260 started = (enabled) ? date : Date();
261 });
262 started = anime.GetUserDateStarted();
263 if (!started.IsValid()) {
264 date->SetEnabled(false);
265 started = anime.GetAirDate();
266 }
267 date->SetDate(started);
233 subsection->layout()->addWidget(date); 268 subsection->layout()->addWidget(date);
234 }); 269 });
235 CREATE_SUBSECTION({ 270 CREATE_SUBSECTION({
236 subsection->layout()->addWidget(new QLabel(tr("Date completed:"), subsection)); 271 subsection->layout()->addWidget(new QLabel(tr("Date completed:"), subsection));
237 272
238 OptionalDate* date = new OptionalDate(true, subsection); 273 OptionalDate* date = new OptionalDate(true, subsection);
239 date->SetDate(QDate(2000, 1, 1)); 274 connect(date, &OptionalDate::DataChanged, this, [this](bool enabled, Date date) {
275 completed = (enabled) ? date : Date();
276 });
277 completed = anime.GetUserDateCompleted();
278 if (!completed.IsValid()) {
279 date->SetEnabled(false);
280 completed = anime.GetAirDate();
281 }
282 date->SetDate(completed);
240 subsection->layout()->addWidget(date); 283 subsection->layout()->addWidget(date);
241 }); 284 });
242 }); 285 });
243 286
244 settings_widget->layout()->addWidget(new TextWidgets::Header(tr("Local settings"), settings_widget)); 287 settings_widget->layout()->addWidget(new TextWidgets::Header(tr("Local settings"), settings_widget));
257 QLineEdit* line_edit = new QLineEdit(QString::fromStdString(anime.GetUserNotes()), subsection); 300 QLineEdit* line_edit = new QLineEdit(QString::fromStdString(anime.GetUserNotes()), subsection);
258 line_edit->setPlaceholderText( 301 line_edit->setPlaceholderText(
259 tr("Enter alternative titles here, separated by a semicolon (i.e. Title 1; Title 2)")); 302 tr("Enter alternative titles here, separated by a semicolon (i.e. Title 1; Title 2)"));
260 subsection->layout()->addWidget(line_edit); 303 subsection->layout()->addWidget(line_edit);
261 304
262 QCheckBox* checkbox = new QCheckBox("Use the first alternative title to search for torrents"); 305 QCheckBox* checkbox = new QCheckBox(tr("Use the first alternative title to search for torrents"));
263 subsection->layout()->addWidget(checkbox); 306 subsection->layout()->addWidget(checkbox);
264 }); 307 });
265 }); 308 });
266 #undef CREATE_SECTION 309 #undef CREATE_SECTION
267 #undef CREATE_SUBSECTION 310 #undef CREATE_SUBSECTION
268 #undef CREATE_FULL_WIDTH_SECTION 311 #undef CREATE_FULL_WIDTH_SECTION
269 #undef CREATE_FULL_WIDTH_SUBSECTION 312 #undef CREATE_FULL_WIDTH_SUBSECTION
270 313
271 static_cast<QBoxLayout*>(settings_widget->layout())->addStretch(); 314 static_cast<QBoxLayout*>(settings_widget->layout())->addStretch();
272 315
273 tabbed_widget->addTab(main_information_widget, "Main information"); 316 tabbed_widget->addTab(main_information_widget, tr("Main information"));
274 tabbed_widget->addTab(settings_widget, "My list and settings"); 317 tabbed_widget->addTab(settings_widget, tr("My list and settings"));
275 318
276 QVBoxLayout* main_layout = new QVBoxLayout; 319 QVBoxLayout* main_layout = new QVBoxLayout;
277 main_layout->addWidget(anime_title); 320 main_layout->addWidget(anime_title);
278 main_layout->addWidget(tabbed_widget); 321 main_layout->addWidget(tabbed_widget);
279 main_layout->setMargin(0); 322 main_layout->setMargin(0);
284 layout->addWidget(main_widget); 327 layout->addWidget(main_widget);
285 widget->setLayout(layout); 328 widget->setLayout(layout);
286 329
287 QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); 330 QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
288 connect(button_box, &QDialogButtonBox::accepted, this, [this, accept] { 331 connect(button_box, &QDialogButtonBox::accepted, this, [this, accept] {
332 SaveData();
289 accept(); 333 accept();
290 QDialog::accept(); 334 QDialog::accept();
291 }); 335 });
292 connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject); 336 connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject);
293 337