Mercurial > minori
diff 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 |
line wrap: on
line diff
--- a/src/gui/dialog/information.cc Mon Oct 23 13:37:42 2023 -0400 +++ b/src/gui/dialog/information.cc Tue Oct 24 22:01:02 2023 -0400 @@ -1,7 +1,6 @@ #include "gui/dialog/information.h" #include "core/anime.h" #include "core/anime_db.h" -#include "core/array.h" #include "core/strings.h" #include "gui/pages/anime_list.h" #include "gui/translate/anime.h" @@ -26,18 +25,17 @@ /* TODO: Taiga disables rendering of the tab widget entirely when the anime is not part of a list, 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); +void InformationDialog::SaveData(Anime::Anime& anime) { + 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) +InformationDialog::InformationDialog(Anime::Anime& anime, std::function<void()> accept, QWidget* parent) : QDialog(parent) { setFixedSize(842, 613); setWindowTitle(tr("Anime Information")); @@ -54,7 +52,7 @@ /* "sidebar", includes... just the anime image :) */ QWidget* sidebar = new QWidget(widget); QVBoxLayout* sidebar_layout = new QVBoxLayout(sidebar); - Poster* poster = new Poster(anime.GetId(), sidebar); + Poster* poster = new Poster(anime, sidebar); sidebar_layout->addWidget(poster); sidebar_layout->setContentsMargins(0, 0, 0, 0); sidebar_layout->addStretch(); @@ -64,7 +62,6 @@ main_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - id = anime.GetId(); /* anime title header text */ TextWidgets::Title* anime_title = new TextWidgets::Title(Strings::ToQString(anime.GetUserPreferredTitle()), main_widget); @@ -131,10 +128,10 @@ 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; }); + 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(progress = anime.GetUserProgress()); + spin_box->setValue(_progress = anime.GetUserProgress()); subsection_layout->addWidget(spin_box); }); CREATE_SUBSECTION({ @@ -142,8 +139,8 @@ 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); + [this](int state) { _rewatching = (state == Qt::Checked); }); + checkbox->setCheckState((_rewatching = anime.GetUserIsRewatching()) ? Qt::Checked : Qt::Unchecked); subsection_layout->addWidget(checkbox); }); }); @@ -153,24 +150,24 @@ subsection_layout->addWidget(new QLabel(tr("Status:"), subsection)); QStringList string_list; - for (unsigned int i = 0; i < ARRAYSIZE(Anime::ListStatuses); i++) + for (unsigned int i = 0; i < Anime::ListStatuses.size(); i++) string_list.append(Strings::ToQString(Translate::ToString(Anime::ListStatuses[i]))); 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); + [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; }); + 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(score = anime.GetUserScore()); + spin_box->setValue(_score = anime.GetUserScore()); subsection_layout->addWidget(spin_box); }); }); @@ -182,9 +179,9 @@ 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 = Strings::ToUtf8String(text); + _notes = Strings::ToUtf8String(text); }); - line_edit->setText(Strings::ToQString(notes = anime.GetUserNotes())); + line_edit->setText(Strings::ToQString(_notes = anime.GetUserNotes())); line_edit->setPlaceholderText(tr("Enter your notes about this anime")); subsection_layout->addWidget(line_edit); }); @@ -196,13 +193,13 @@ OptionalDate* date = new OptionalDate(true, subsection); connect(date, &OptionalDate::DataChanged, this, - [this](bool enabled, Date date) { started = (enabled) ? date : Date(); }); - started = anime.GetUserDateStarted(); - if (!started.IsValid()) { + [this](bool enabled, Date date) { _started = (enabled) ? date : Date(); }); + _started = anime.GetUserDateStarted(); + if (!_started.IsValid()) { date->SetEnabled(false); - started = anime.GetAirDate(); + _started = anime.GetAirDate(); } - date->SetDate(started); + date->SetDate(_started); subsection_layout->addWidget(date); }); CREATE_SUBSECTION({ @@ -210,13 +207,13 @@ OptionalDate* date = new OptionalDate(true, subsection); connect(date, &OptionalDate::DataChanged, this, - [this](bool enabled, Date date) { completed = (enabled) ? date : Date(); }); - completed = anime.GetUserDateCompleted(); - if (!completed.IsValid()) { + [this](bool enabled, Date date) { _completed = (enabled) ? date : Date(); }); + _completed = anime.GetUserDateCompleted(); + if (!_completed.IsValid()) { date->SetEnabled(false); - completed = anime.GetAirDate(); + _completed = anime.GetAirDate(); } - date->SetDate(completed); + date->SetDate(_completed); subsection_layout->addWidget(date); }); }); @@ -266,8 +263,8 @@ layout->setSpacing(12); QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); - connect(button_box, &QDialogButtonBox::accepted, this, [this, accept] { - SaveData(); + connect(button_box, &QDialogButtonBox::accepted, this, [this, accept, &anime] { + SaveData(anime); accept(); QDialog::accept(); });