Mercurial > minori
diff 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 |
line wrap: on
line diff
--- a/src/gui/dialog/information.cpp Mon Sep 25 13:50:56 2023 -0400 +++ b/src/gui/dialog/information.cpp Mon Sep 25 20:29:26 2023 -0400 @@ -25,6 +25,13 @@ which sucks. Think of a better way to implement this later. */ void InformationDialog::SaveData() { Anime::Anime& anime = Anime::db.items[id]; + anime.SetUserProgress(progress); + anime.SetUserScore(score); + anime.SetUserIsRewatching(rewatching); + anime.SetUserStatus(status); + anime.SetUserNotes(notes); + anime.SetUserDateStarted(started); + anime.SetUserDateCompleted(completed); } InformationDialog::InformationDialog(const Anime::Anime& anime, std::function<void()> accept, QWidget* parent) @@ -56,6 +63,7 @@ main_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + id = anime.GetId(); /* anime title header text */ TextWidgets::Paragraph* anime_title = new TextWidgets::Paragraph(QString::fromUtf8(anime.GetUserPreferredTitle().c_str()), main_widget); @@ -89,7 +97,7 @@ /* alt titles */ main_information_widget->layout()->addWidget(new TextWidgets::SelectableTextParagraph( - "Alternative titles", QString::fromUtf8(Strings::Implode(anime.GetTitleSynonyms(), ", ").c_str()), + tr("Alternative titles"), QString::fromUtf8(Strings::Implode(anime.GetTitleSynonyms(), ", ").c_str()), main_information_widget)); /* details */ @@ -102,11 +110,11 @@ << Strings::Implode(anime.GetGenres(), ", ").c_str() << "\n" << anime.GetAudienceScore() << "%"; main_information_widget->layout()->addWidget(new TextWidgets::LabelledTextParagraph( - "Details", "Type:\nEpisodes:\nStatus:\nSeason:\nGenres:\nScore:", details_data, main_information_widget)); + tr("Details"), tr("Type:\nEpisodes:\nStatus:\nSeason:\nGenres:\nScore:"), details_data, main_information_widget)); /* synopsis */ TextWidgets::SelectableTextParagraph* synopsis = new TextWidgets::SelectableTextParagraph( - "Synopsis", QString::fromUtf8(anime.GetSynopsis().c_str()), main_information_widget); + tr("Synopsis"), QString::fromUtf8(anime.GetSynopsis().c_str()), main_information_widget); synopsis->GetParagraph()->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); main_information_widget->layout()->addWidget(synopsis); @@ -178,16 +186,23 @@ subsection->layout()->addWidget(new QLabel(tr("Episodes watched:"), subsection)); QSpinBox* spin_box = new QSpinBox(subsection); + connect(spin_box, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int i) { + progress = i; + }); spin_box->setRange(0, anime.GetEpisodes()); spin_box->setSingleStep(1); - spin_box->setValue(anime.GetUserProgress()); + spin_box->setValue(progress = anime.GetUserProgress()); subsection->layout()->addWidget(spin_box); }); CREATE_SUBSECTION({ subsection->layout()->addWidget(new QLabel(tr(" "), subsection)); - QCheckBox* rewatched_checkbox = new QCheckBox("Rewatching"); - subsection->layout()->addWidget(rewatched_checkbox); + QCheckBox* checkbox = new QCheckBox(tr("Rewatching")); + connect(checkbox, QOverload<int>::of(&QCheckBox::stateChanged), this, [this](int state) { + rewatching = (state == Qt::Checked); + }); + checkbox->setCheckState(anime.GetUserIsRewatching() ? Qt::Checked : Qt::Unchecked); + subsection->layout()->addWidget(checkbox); }); }); CREATE_SECTION(sg_anime_list_content, { @@ -201,15 +216,22 @@ QComboBox* combo_box = new QComboBox(subsection); combo_box->addItems(string_list); + connect(combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this](int i) { + status = Anime::ListStatuses[i]; + }); + combo_box->setCurrentIndex(static_cast<int>(status = anime.GetUserStatus())-1); subsection->layout()->addWidget(combo_box); }); CREATE_SUBSECTION({ subsection->layout()->addWidget(new QLabel(tr("Score:"), subsection)); QSpinBox* spin_box = new QSpinBox(subsection); + connect(spin_box, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int i) { + score = i; + }); spin_box->setRange(0, 100); spin_box->setSingleStep(5); - spin_box->setValue(anime.GetUserScore()); + spin_box->setValue(score = anime.GetUserScore()); subsection->layout()->addWidget(spin_box); }); }); @@ -218,7 +240,12 @@ CREATE_FULL_WIDTH_SUBSECTION({ subsection->layout()->addWidget(new QLabel(tr("Notes:"), subsection)); - QLineEdit* line_edit = new QLineEdit(QString::fromStdString(anime.GetUserNotes()), subsection); + QLineEdit* line_edit = new QLineEdit(subsection); + connect(line_edit, &QLineEdit::textChanged, this, [this](const QString& text) { + /* this sucks but I don't really want to implement anything smarter :) */ + notes = text.toStdString(); + }); + line_edit->setText(QString::fromStdString(notes = anime.GetUserNotes())); line_edit->setPlaceholderText(tr("Enter your notes about this anime")); subsection->layout()->addWidget(line_edit); }); @@ -229,14 +256,30 @@ subsection->layout()->addWidget(new QLabel(tr("Date started:"), subsection)); OptionalDate* date = new OptionalDate(true, subsection); - date->SetDate(QDate(2000, 1, 1)); + connect(date, &OptionalDate::DataChanged, this, [this](bool enabled, Date date) { + started = (enabled) ? date : Date(); + }); + started = anime.GetUserDateStarted(); + if (!started.IsValid()) { + date->SetEnabled(false); + started = anime.GetAirDate(); + } + date->SetDate(started); subsection->layout()->addWidget(date); }); CREATE_SUBSECTION({ subsection->layout()->addWidget(new QLabel(tr("Date completed:"), subsection)); OptionalDate* date = new OptionalDate(true, subsection); - date->SetDate(QDate(2000, 1, 1)); + connect(date, &OptionalDate::DataChanged, this, [this](bool enabled, Date date) { + completed = (enabled) ? date : Date(); + }); + completed = anime.GetUserDateCompleted(); + if (!completed.IsValid()) { + date->SetEnabled(false); + completed = anime.GetAirDate(); + } + date->SetDate(completed); subsection->layout()->addWidget(date); }); }); @@ -259,7 +302,7 @@ tr("Enter alternative titles here, separated by a semicolon (i.e. Title 1; Title 2)")); subsection->layout()->addWidget(line_edit); - QCheckBox* checkbox = new QCheckBox("Use the first alternative title to search for torrents"); + QCheckBox* checkbox = new QCheckBox(tr("Use the first alternative title to search for torrents")); subsection->layout()->addWidget(checkbox); }); }); @@ -270,8 +313,8 @@ static_cast<QBoxLayout*>(settings_widget->layout())->addStretch(); - tabbed_widget->addTab(main_information_widget, "Main information"); - tabbed_widget->addTab(settings_widget, "My list and settings"); + tabbed_widget->addTab(main_information_widget, tr("Main information")); + tabbed_widget->addTab(settings_widget, tr("My list and settings")); QVBoxLayout* main_layout = new QVBoxLayout; main_layout->addWidget(anime_title); @@ -286,6 +329,7 @@ QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); connect(button_box, &QDialogButtonBox::accepted, this, [this, accept] { + SaveData(); accept(); QDialog::accept(); });