Mercurial > minori
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 304:2115488eb302 | 305:91ac90a34003 |
|---|---|
| 23 #include <QStringList> | 23 #include <QStringList> |
| 24 #include <QTextStream> | 24 #include <QTextStream> |
| 25 #include <QVBoxLayout> | 25 #include <QVBoxLayout> |
| 26 | 26 |
| 27 #include <functional> | 27 #include <functional> |
| 28 #include <iostream> | |
| 28 #ifdef WIN32 | 29 #ifdef WIN32 |
| 29 # include "sys/win32/dark_theme.h" | 30 # include "sys/win32/dark_theme.h" |
| 30 #endif | 31 #endif |
| 31 | 32 |
| 32 /* TODO: Taiga disables rendering of the tab widget entirely when the anime is not part of a list, | 33 /* TODO: Taiga disables rendering of the tab widget entirely when the anime is not part of a list, |
| 33 which sucks. Think of a better way to implement this later. */ | 34 which sucks. Think of a better way to implement this later. */ |
| 34 void InformationDialog::SaveData(Anime::Anime& anime) { | 35 void InformationDialog::SaveData(Anime::Anime* anime) { |
| 35 if (!anime.IsInUserList()) | 36 if (!anime->IsInUserList()) |
| 36 return; | 37 return; |
| 37 | 38 |
| 38 anime.SetUserProgress(_progress); | 39 anime->SetUserProgress(_progress); |
| 39 anime.SetUserScore(_score); | 40 anime->SetUserScore(_score); |
| 40 anime.SetUserIsRewatching(_rewatching); | 41 anime->SetUserIsRewatching(_rewatching); |
| 41 anime.SetUserStatus(_status); | 42 anime->SetUserStatus(_status); |
| 42 anime.SetUserNotes(_notes); | 43 anime->SetUserNotes(_notes); |
| 43 anime.SetUserDateStarted(_started); | 44 anime->SetUserDateStarted(_started); |
| 44 anime.SetUserDateCompleted(_completed); | 45 anime->SetUserDateCompleted(_completed); |
| 45 } | 46 } |
| 46 | 47 |
| 47 InformationDialog::InformationDialog(Anime::Anime& anime, std::function<void()> accept, enum Pages page, | 48 InformationDialog::InformationDialog(Anime::Anime* anime, std::function<void(Anime::Anime*)> accept, enum Pages page, |
| 48 QWidget* parent) | 49 QWidget* parent) |
| 49 : QDialog(parent) { | 50 : QDialog(parent) { |
| 50 /* ack. lots of brackets here, but MUCH, MUCH MUCH better than what it used to be */ | 51 /* ack. lots of brackets here, but MUCH, MUCH MUCH better than what it used to be */ |
| 51 setFixedSize(842, 613); | 52 setFixedSize(842, 613); |
| 52 setWindowTitle(tr("Anime Information")); | 53 setWindowTitle(tr("Anime Information")); |
| 53 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); | 54 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); |
| 54 | 55 |
| 69 /* Sidebar */ | 70 /* Sidebar */ |
| 70 QWidget* sidebar = new QWidget(widget); | 71 QWidget* sidebar = new QWidget(widget); |
| 71 QVBoxLayout* sidebar_layout = new QVBoxLayout(sidebar); | 72 QVBoxLayout* sidebar_layout = new QVBoxLayout(sidebar); |
| 72 { | 73 { |
| 73 /* Poster */ | 74 /* Poster */ |
| 74 Poster* poster = new Poster(anime, sidebar); | 75 Poster* poster = new Poster(*anime, sidebar); |
| 75 sidebar_layout->addWidget(poster); | 76 sidebar_layout->addWidget(poster); |
| 76 } | 77 } |
| 77 sidebar_layout->setContentsMargins(0, 0, 0, 0); | 78 sidebar_layout->setContentsMargins(0, 0, 0, 0); |
| 78 sidebar_layout->addStretch(); | 79 sidebar_layout->addStretch(); |
| 79 layout->addWidget(sidebar); | 80 layout->addWidget(sidebar); |
| 87 main_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | 88 main_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
| 88 | 89 |
| 89 { | 90 { |
| 90 /* Anime title */ | 91 /* Anime title */ |
| 91 TextWidgets::Title* anime_title = | 92 TextWidgets::Title* anime_title = |
| 92 new TextWidgets::Title(Strings::ToQString(anime.GetUserPreferredTitle()), main_widget); | 93 new TextWidgets::Title(Strings::ToQString(anime->GetUserPreferredTitle()), main_widget); |
| 93 main_layout->addWidget(anime_title); | 94 main_layout->addWidget(anime_title); |
| 94 } | 95 } |
| 95 | 96 |
| 96 { | 97 { |
| 97 /* Tab widget, contains main info and settings */ | 98 /* Tab widget, contains main info and settings */ |
| 98 QTabWidget* tabbed_widget = new QTabWidget(main_widget); | 99 QTabWidget* tabbed_widget = new QTabWidget(main_widget); |
| 99 tabbed_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | 100 tabbed_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
| 100 | 101 |
| 101 { | 102 { |
| 102 /* Main information */ | 103 /* Main information */ |
| 103 AnimeInfoWidget* main_information_widget = new AnimeInfoWidget(anime, tabbed_widget); | 104 AnimeInfoWidget* main_information_widget = new AnimeInfoWidget(*anime, tabbed_widget); |
| 104 tabbed_widget->addTab(main_information_widget, tr("Main information")); | 105 tabbed_widget->addTab(main_information_widget, tr("Main information")); |
| 105 } | 106 } |
| 106 | 107 |
| 107 if (anime.IsInUserList()) { | 108 if (anime->IsInUserList()) { |
| 108 /* My list and settings */ | 109 /* My list and settings */ |
| 109 QWidget* settings_widget = new QWidget(tabbed_widget); | 110 QWidget* settings_widget = new QWidget(tabbed_widget); |
| 110 settings_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); | 111 settings_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); |
| 111 | 112 |
| 112 QVBoxLayout* settings_layout = new QVBoxLayout(settings_widget); | 113 QVBoxLayout* settings_layout = new QVBoxLayout(settings_widget); |
| 141 layout->addWidget(new QLabel(tr("Episodes watched:"), section), 0, 0); | 142 layout->addWidget(new QLabel(tr("Episodes watched:"), section), 0, 0); |
| 142 | 143 |
| 143 QSpinBox* spin_box = new QSpinBox(section); | 144 QSpinBox* spin_box = new QSpinBox(section); |
| 144 connect(spin_box, QOverload<int>::of(&QSpinBox::valueChanged), this, | 145 connect(spin_box, QOverload<int>::of(&QSpinBox::valueChanged), this, |
| 145 [this](int i) { _progress = i; }); | 146 [this](int i) { _progress = i; }); |
| 146 spin_box->setRange(0, anime.GetEpisodes()); | 147 spin_box->setRange(0, anime->GetEpisodes()); |
| 147 spin_box->setSingleStep(1); | 148 spin_box->setSingleStep(1); |
| 148 spin_box->setValue(_progress = anime.GetUserProgress()); | 149 spin_box->setValue(_progress = anime->GetUserProgress()); |
| 149 spin_box->setFixedWidth(LAYOUT_ITEM_WIDTH); | 150 spin_box->setFixedWidth(LAYOUT_ITEM_WIDTH); |
| 150 layout->addWidget(spin_box, 1, 0); | 151 layout->addWidget(spin_box, 1, 0); |
| 151 } | 152 } |
| 152 | 153 |
| 153 { | 154 { |
| 154 /* Rewatching? */ | 155 /* Rewatching? */ |
| 155 QCheckBox* checkbox = new QCheckBox(tr("Rewatching")); | 156 QCheckBox* checkbox = new QCheckBox(tr("Rewatching")); |
| 156 connect(checkbox, QOverload<int>::of(&QCheckBox::stateChanged), this, | 157 connect(checkbox, QOverload<int>::of(&QCheckBox::stateChanged), this, |
| 157 [this](int state) { _rewatching = (state == Qt::Checked); }); | 158 [this](int state) { _rewatching = (state == Qt::Checked); }); |
| 158 checkbox->setCheckState((_rewatching = anime.GetUserIsRewatching()) ? Qt::Checked | 159 checkbox->setCheckState((_rewatching = anime->GetUserIsRewatching()) ? Qt::Checked |
| 159 : Qt::Unchecked); | 160 : Qt::Unchecked); |
| 160 checkbox->setFixedWidth(LAYOUT_ITEM_WIDTH); | 161 checkbox->setFixedWidth(LAYOUT_ITEM_WIDTH); |
| 161 layout->addWidget(checkbox, 1, 1); | 162 layout->addWidget(checkbox, 1, 1); |
| 162 } | 163 } |
| 163 layout->setColumnStretch(layout->columnCount(), 1); | 164 layout->setColumnStretch(layout->columnCount(), 1); |
| 164 }); | 165 }); |
| 168 /* Status */ | 169 /* Status */ |
| 169 layout->addWidget(new QLabel(tr("Status:"), section), 0, 0); | 170 layout->addWidget(new QLabel(tr("Status:"), section), 0, 0); |
| 170 | 171 |
| 171 QComboBox* combo_box = new QComboBox(section); | 172 QComboBox* combo_box = new QComboBox(section); |
| 172 | 173 |
| 173 for (unsigned int i = 0; i < Anime::ListStatuses.size(); i++) | 174 _status = anime->GetUserStatus(); |
| 175 for (unsigned int i = 0; i < Anime::ListStatuses.size(); i++) { | |
| 174 combo_box->addItem(Strings::ToQString(Translate::ToLocalString(Anime::ListStatuses[i])), | 176 combo_box->addItem(Strings::ToQString(Translate::ToLocalString(Anime::ListStatuses[i])), |
| 175 static_cast<int>(Anime::ListStatuses[i])); | 177 static_cast<int>(Anime::ListStatuses[i])); |
| 178 if (Anime::ListStatuses[i] == _status) | |
| 179 combo_box->setCurrentIndex(i); | |
| 180 } | |
| 176 | 181 |
| 177 connect(combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, | 182 connect(combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, |
| 178 [this, combo_box](int) { | 183 [this, combo_box](int) { |
| 179 _status = static_cast<Anime::ListStatus>(combo_box->currentData().toInt()); | 184 _status = static_cast<Anime::ListStatus>(combo_box->currentData().toInt()); |
| 180 }); | 185 }); |
| 181 | 186 |
| 182 /* this should NEVER, EVER, be NOT_IN_LIST */ | 187 /* this should NEVER, EVER, be NOT_IN_LIST */ |
| 183 combo_box->setCurrentIndex(static_cast<int>(_status = anime.GetUserStatus()) - 1); | |
| 184 combo_box->setFixedWidth(LAYOUT_ITEM_WIDTH); | 188 combo_box->setFixedWidth(LAYOUT_ITEM_WIDTH); |
| 185 layout->addWidget(combo_box, 1, 0); | 189 layout->addWidget(combo_box, 1, 0); |
| 186 } | 190 } |
| 187 | 191 |
| 188 { | 192 { |
| 192 QSpinBox* spin_box = new QSpinBox(section); | 196 QSpinBox* spin_box = new QSpinBox(section); |
| 193 connect(spin_box, QOverload<int>::of(&QSpinBox::valueChanged), this, | 197 connect(spin_box, QOverload<int>::of(&QSpinBox::valueChanged), this, |
| 194 [this](int i) { _score = i; }); | 198 [this](int i) { _score = i; }); |
| 195 spin_box->setRange(0, 100); | 199 spin_box->setRange(0, 100); |
| 196 spin_box->setSingleStep(5); | 200 spin_box->setSingleStep(5); |
| 197 spin_box->setValue(_score = anime.GetUserScore()); | 201 spin_box->setValue(_score = anime->GetUserScore()); |
| 198 spin_box->setFixedWidth(LAYOUT_ITEM_WIDTH); | 202 spin_box->setFixedWidth(LAYOUT_ITEM_WIDTH); |
| 199 layout->addWidget(spin_box, 1, 1); | 203 layout->addWidget(spin_box, 1, 1); |
| 200 } | 204 } |
| 201 layout->setColumnStretch(layout->columnCount(), 1); | 205 layout->setColumnStretch(layout->columnCount(), 1); |
| 202 }); | 206 }); |
| 207 QLineEdit* line_edit = new QLineEdit(section); | 211 QLineEdit* line_edit = new QLineEdit(section); |
| 208 connect(line_edit, &QLineEdit::textChanged, this, [this](const QString& text) { | 212 connect(line_edit, &QLineEdit::textChanged, this, [this](const QString& text) { |
| 209 /* this sucks but I don't really want to implement anything smarter :) */ | 213 /* this sucks but I don't really want to implement anything smarter :) */ |
| 210 _notes = Strings::ToUtf8String(text); | 214 _notes = Strings::ToUtf8String(text); |
| 211 }); | 215 }); |
| 212 line_edit->setText(Strings::ToQString(_notes = anime.GetUserNotes())); | 216 line_edit->setText(Strings::ToQString(_notes = anime->GetUserNotes())); |
| 213 line_edit->setPlaceholderText(tr("Enter your notes about this anime")); | 217 line_edit->setPlaceholderText(tr("Enter your notes about this anime")); |
| 214 layout->addWidget(line_edit, 1, 0); | 218 layout->addWidget(line_edit, 1, 0); |
| 215 }); | 219 }); |
| 216 | 220 |
| 217 CREATE_SECTION(sg_anime_list_content, [this, &anime](QWidget* section, QGridLayout* layout) { | 221 CREATE_SECTION(sg_anime_list_content, [this, &anime](QWidget* section, QGridLayout* layout) { |
| 221 | 225 |
| 222 OptionalDate* date = new OptionalDate(true, section); | 226 OptionalDate* date = new OptionalDate(true, section); |
| 223 connect(date, &OptionalDate::DataChanged, this, | 227 connect(date, &OptionalDate::DataChanged, this, |
| 224 [this](bool enabled, Date date) { _started = enabled ? date : Date(); }); | 228 [this](bool enabled, Date date) { _started = enabled ? date : Date(); }); |
| 225 date->setFixedWidth(LAYOUT_ITEM_WIDTH); | 229 date->setFixedWidth(LAYOUT_ITEM_WIDTH); |
| 226 _started = anime.GetUserDateStarted(); | 230 _started = anime->GetUserDateStarted(); |
| 227 if (!_started.IsValid()) { | 231 if (!_started.IsValid()) { |
| 228 date->SetEnabled(false); | 232 date->SetEnabled(false); |
| 229 _started = anime.GetAirDate(); | 233 _started = anime->GetAirDate(); |
| 230 } | 234 } |
| 231 date->SetDate(_started); | 235 date->SetDate(_started); |
| 232 layout->addWidget(date, 1, 0); | 236 layout->addWidget(date, 1, 0); |
| 233 } | 237 } |
| 234 | 238 |
| 238 | 242 |
| 239 OptionalDate* date = new OptionalDate(true, section); | 243 OptionalDate* date = new OptionalDate(true, section); |
| 240 connect(date, &OptionalDate::DataChanged, this, | 244 connect(date, &OptionalDate::DataChanged, this, |
| 241 [this](bool enabled, Date date) { _completed = enabled ? date : Date(); }); | 245 [this](bool enabled, Date date) { _completed = enabled ? date : Date(); }); |
| 242 date->setFixedWidth(LAYOUT_ITEM_WIDTH); | 246 date->setFixedWidth(LAYOUT_ITEM_WIDTH); |
| 243 _completed = anime.GetUserDateCompleted(); | 247 _completed = anime->GetUserDateCompleted(); |
| 244 if (!_completed.IsValid()) { | 248 if (!_completed.IsValid()) { |
| 245 date->SetEnabled(false); | 249 date->SetEnabled(false); |
| 246 _completed = anime.GetAirDate(); | 250 _completed = anime->GetAirDate(); |
| 247 } | 251 } |
| 248 date->SetDate(_completed); | 252 date->SetDate(_completed); |
| 249 layout->addWidget(date, 1, 1); | 253 layout->addWidget(date, 1, 1); |
| 250 } | 254 } |
| 251 layout->setColumnStretch(layout->columnCount(), 1); | 255 layout->setColumnStretch(layout->columnCount(), 1); |
| 299 } | 303 } |
| 300 | 304 |
| 301 { | 305 { |
| 302 /* Dialog box buttons */ | 306 /* Dialog box buttons */ |
| 303 QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); | 307 QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); |
| 304 connect(button_box, &QDialogButtonBox::accepted, this, [this, accept, &anime] { | 308 connect(button_box, &QDialogButtonBox::accepted, this, [this, accept, anime] { |
| 305 SaveData(anime); | 309 SaveData(anime); |
| 306 accept(); | 310 accept(anime); |
| 307 QDialog::accept(); | 311 QDialog::accept(); |
| 308 }); | 312 }); |
| 309 connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject); | 313 connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject); |
| 310 full_layout->addWidget(button_box, 0, Qt::AlignBottom); | 314 full_layout->addWidget(button_box, 0, Qt::AlignBottom); |
| 311 } | 315 } |
