Mercurial > minori
diff src/gui/dialog/information.cc @ 305:91ac90a34003
core/time: remove Duration class, use regular functions instead
this class was pretty useless anyway
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Sun, 19 May 2024 15:56:20 -0400 |
parents | 99cbc51433e4 |
children | 5d3c9b31aa6e |
line wrap: on
line diff
--- a/src/gui/dialog/information.cc Mon May 13 17:02:35 2024 -0400 +++ b/src/gui/dialog/information.cc Sun May 19 15:56:20 2024 -0400 @@ -25,28 +25,29 @@ #include <QVBoxLayout> #include <functional> +#include <iostream> #ifdef WIN32 # include "sys/win32/dark_theme.h" #endif /* 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) { - if (!anime.IsInUserList()) +void InformationDialog::SaveData(Anime::Anime* anime) { + if (!anime->IsInUserList()) return; - anime.SetUserProgress(_progress); - anime.SetUserScore(_score); - anime.SetUserIsRewatching(_rewatching); - anime.SetUserStatus(_status); - anime.SetUserNotes(_notes); - anime.SetUserDateStarted(_started); - anime.SetUserDateCompleted(_completed); + anime->SetUserProgress(_progress); + anime->SetUserScore(_score); + anime->SetUserIsRewatching(_rewatching); + anime->SetUserStatus(_status); + anime->SetUserNotes(_notes); + anime->SetUserDateStarted(_started); + anime->SetUserDateCompleted(_completed); } -InformationDialog::InformationDialog(Anime::Anime& anime, std::function<void()> accept, enum Pages page, +InformationDialog::InformationDialog(Anime::Anime* anime, std::function<void(Anime::Anime*)> accept, enum Pages page, QWidget* parent) - : QDialog(parent) { + : QDialog(parent) { /* ack. lots of brackets here, but MUCH, MUCH MUCH better than what it used to be */ setFixedSize(842, 613); setWindowTitle(tr("Anime Information")); @@ -71,7 +72,7 @@ QVBoxLayout* sidebar_layout = new QVBoxLayout(sidebar); { /* Poster */ - Poster* poster = new Poster(anime, sidebar); + Poster* poster = new Poster(*anime, sidebar); sidebar_layout->addWidget(poster); } sidebar_layout->setContentsMargins(0, 0, 0, 0); @@ -89,7 +90,7 @@ { /* Anime title */ TextWidgets::Title* anime_title = - new TextWidgets::Title(Strings::ToQString(anime.GetUserPreferredTitle()), main_widget); + new TextWidgets::Title(Strings::ToQString(anime->GetUserPreferredTitle()), main_widget); main_layout->addWidget(anime_title); } @@ -100,11 +101,11 @@ { /* Main information */ - AnimeInfoWidget* main_information_widget = new AnimeInfoWidget(anime, tabbed_widget); + AnimeInfoWidget* main_information_widget = new AnimeInfoWidget(*anime, tabbed_widget); tabbed_widget->addTab(main_information_widget, tr("Main information")); } - if (anime.IsInUserList()) { + if (anime->IsInUserList()) { /* My list and settings */ QWidget* settings_widget = new QWidget(tabbed_widget); settings_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); @@ -143,9 +144,9 @@ QSpinBox* spin_box = new QSpinBox(section); connect(spin_box, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int i) { _progress = i; }); - spin_box->setRange(0, anime.GetEpisodes()); + spin_box->setRange(0, anime->GetEpisodes()); spin_box->setSingleStep(1); - spin_box->setValue(_progress = anime.GetUserProgress()); + spin_box->setValue(_progress = anime->GetUserProgress()); spin_box->setFixedWidth(LAYOUT_ITEM_WIDTH); layout->addWidget(spin_box, 1, 0); } @@ -155,8 +156,8 @@ QCheckBox* checkbox = new QCheckBox(tr("Rewatching")); connect(checkbox, QOverload<int>::of(&QCheckBox::stateChanged), this, [this](int state) { _rewatching = (state == Qt::Checked); }); - checkbox->setCheckState((_rewatching = anime.GetUserIsRewatching()) ? Qt::Checked - : Qt::Unchecked); + checkbox->setCheckState((_rewatching = anime->GetUserIsRewatching()) ? Qt::Checked + : Qt::Unchecked); checkbox->setFixedWidth(LAYOUT_ITEM_WIDTH); layout->addWidget(checkbox, 1, 1); } @@ -170,9 +171,13 @@ QComboBox* combo_box = new QComboBox(section); - for (unsigned int i = 0; i < Anime::ListStatuses.size(); i++) + _status = anime->GetUserStatus(); + for (unsigned int i = 0; i < Anime::ListStatuses.size(); i++) { combo_box->addItem(Strings::ToQString(Translate::ToLocalString(Anime::ListStatuses[i])), static_cast<int>(Anime::ListStatuses[i])); + if (Anime::ListStatuses[i] == _status) + combo_box->setCurrentIndex(i); + } connect(combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this, combo_box](int) { @@ -180,7 +185,6 @@ }); /* this should NEVER, EVER, be NOT_IN_LIST */ - combo_box->setCurrentIndex(static_cast<int>(_status = anime.GetUserStatus()) - 1); combo_box->setFixedWidth(LAYOUT_ITEM_WIDTH); layout->addWidget(combo_box, 1, 0); } @@ -194,7 +198,7 @@ [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()); spin_box->setFixedWidth(LAYOUT_ITEM_WIDTH); layout->addWidget(spin_box, 1, 1); } @@ -209,7 +213,7 @@ /* this sucks but I don't really want to implement anything smarter :) */ _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")); layout->addWidget(line_edit, 1, 0); }); @@ -223,10 +227,10 @@ connect(date, &OptionalDate::DataChanged, this, [this](bool enabled, Date date) { _started = enabled ? date : Date(); }); date->setFixedWidth(LAYOUT_ITEM_WIDTH); - _started = anime.GetUserDateStarted(); + _started = anime->GetUserDateStarted(); if (!_started.IsValid()) { date->SetEnabled(false); - _started = anime.GetAirDate(); + _started = anime->GetAirDate(); } date->SetDate(_started); layout->addWidget(date, 1, 0); @@ -240,10 +244,10 @@ connect(date, &OptionalDate::DataChanged, this, [this](bool enabled, Date date) { _completed = enabled ? date : Date(); }); date->setFixedWidth(LAYOUT_ITEM_WIDTH); - _completed = anime.GetUserDateCompleted(); + _completed = anime->GetUserDateCompleted(); if (!_completed.IsValid()) { date->SetEnabled(false); - _completed = anime.GetAirDate(); + _completed = anime->GetAirDate(); } date->SetDate(_completed); layout->addWidget(date, 1, 1); @@ -301,9 +305,9 @@ { /* Dialog box buttons */ QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); - connect(button_box, &QDialogButtonBox::accepted, this, [this, accept, &anime] { + connect(button_box, &QDialogButtonBox::accepted, this, [this, accept, anime] { SaveData(anime); - accept(); + accept(anime); QDialog::accept(); }); connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject);