Mercurial > minori
comparison src/anime.cpp @ 2:23d0d9319a00
Update
Also converted everything to LF from CRLF
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Sat, 12 Aug 2023 03:16:26 -0400 |
| parents | 1ae666fdf9e2 |
| children | 190ded9438c0 |
comparison
equal
deleted
inserted
replaced
| 1:1ae666fdf9e2 | 2:23d0d9319a00 |
|---|---|
| 4 #include <cmath> | 4 #include <cmath> |
| 5 #include "window.h" | 5 #include "window.h" |
| 6 #include "anilist.h" | 6 #include "anilist.h" |
| 7 #include "config.h" | 7 #include "config.h" |
| 8 #include "anime.h" | 8 #include "anime.h" |
| 9 //#include "information.h" | 9 #include "date.h" |
| 10 #include "time_utils.h" | |
| 11 #include "information.h" | |
| 12 #include "ui_utils.h" | |
| 10 | 13 |
| 11 std::map<enum AnimeWatchingStatus, std::string> AnimeWatchingToStringMap = { | 14 std::map<enum AnimeWatchingStatus, std::string> AnimeWatchingToStringMap = { |
| 12 {CURRENT, "Watching"}, | 15 {CURRENT, "Watching"}, |
| 13 {PLANNING, "Planning"}, | 16 {PLANNING, "Planning"}, |
| 14 {COMPLETED, "Completed"}, | 17 {COMPLETED, "Completed"}, |
| 24 {CANCELLED, "Cancelled"}, | 27 {CANCELLED, "Cancelled"}, |
| 25 {HIATUS, "On hiatus"} | 28 {HIATUS, "On hiatus"} |
| 26 }; | 29 }; |
| 27 | 30 |
| 28 std::map<enum AnimeSeason, std::string> AnimeSeasonToStringMap = { | 31 std::map<enum AnimeSeason, std::string> AnimeSeasonToStringMap = { |
| 29 {WINTER, "Winter"}, | 32 {UNKNOWN, "Unknown"}, |
| 30 {SPRING, "Spring"}, | 33 {WINTER, "Winter"}, |
| 31 {SUMMER, "Summer"}, | 34 {SPRING, "Spring"}, |
| 32 {FALL, "Fall"} | 35 {SUMMER, "Summer"}, |
| 36 {FALL, "Fall"} | |
| 33 }; | 37 }; |
| 34 | 38 |
| 35 std::map<enum AnimeFormat, std::string> AnimeFormatToStringMap = { | 39 std::map<enum AnimeFormat, std::string> AnimeFormatToStringMap = { |
| 36 {TV, "TV"}, | 40 {TV, "TV"}, |
| 37 {TV_SHORT, "TV short"}, | 41 {TV_SHORT, "TV short"}, |
| 52 status = a.status; | 56 status = a.status; |
| 53 progress = a.progress; | 57 progress = a.progress; |
| 54 score = a.score; | 58 score = a.score; |
| 55 started = a.started; | 59 started = a.started; |
| 56 completed = a.completed; | 60 completed = a.completed; |
| 61 updated = a.updated; | |
| 57 notes = a.notes; | 62 notes = a.notes; |
| 58 id = a.id; | 63 id = a.id; |
| 59 title = a.title; | 64 title = a.title; |
| 60 episodes = a.episodes; | 65 episodes = a.episodes; |
| 61 airing = a.airing; | 66 airing = a.airing; |
| 128 return anime_id_to_anime.contains(id) ? anime_id_to_anime[id] : nullptr; | 133 return anime_id_to_anime.contains(id) ? anime_id_to_anime[id] : nullptr; |
| 129 } | 134 } |
| 130 | 135 |
| 131 bool AnimeList::AnimeInList(int id) { | 136 bool AnimeList::AnimeInList(int id) { |
| 132 return anime_id_to_anime.contains(id); | 137 return anime_id_to_anime.contains(id); |
| 138 } | |
| 139 | |
| 140 int AnimeList::GetAnimeIndex(Anime& anime) const { | |
| 141 for (int i = 0; i < Size(); i++) { | |
| 142 if (&anime_list.at(i) == &anime) { // lazy | |
| 143 return i; | |
| 144 } | |
| 145 } | |
| 146 return -1; | |
| 133 } | 147 } |
| 134 | 148 |
| 135 Anime& AnimeList::operator[](std::size_t index) { | 149 Anime& AnimeList::operator[](std::size_t index) { |
| 136 return anime_list.at(index); | 150 return anime_list.at(index); |
| 137 } | 151 } |
| 205 } | 219 } |
| 206 return QAbstractListModel::headerData(section, orientation, role); | 220 return QAbstractListModel::headerData(section, orientation, role); |
| 207 } | 221 } |
| 208 | 222 |
| 209 Anime* AnimeListWidgetModel::GetAnimeFromIndex(const QModelIndex& index) { | 223 Anime* AnimeListWidgetModel::GetAnimeFromIndex(const QModelIndex& index) { |
| 210 return (!index.isValid()) ? &(list[index.row()]) : nullptr; | 224 return (index.isValid()) ? &(list[index.row()]) : nullptr; |
| 211 } | 225 } |
| 212 | 226 |
| 213 QVariant AnimeListWidgetModel::data(const QModelIndex& index, int role) const { | 227 QVariant AnimeListWidgetModel::data(const QModelIndex& index, int role) const { |
| 214 if (!index.isValid()) | 228 if (!index.isValid()) |
| 215 return QVariant(); | 229 return QVariant(); |
| 216 if (role == Qt::DisplayRole) { | 230 if (role == Qt::DisplayRole) { |
| 217 switch (index.column()) { | 231 switch (index.column()) { |
| 218 case AL_TITLE: | 232 case AL_TITLE: |
| 219 return QString::fromWCharArray(list[index.row()].title.c_str()); | 233 return QString::fromWCharArray(list[index.row()].title.english.c_str()); |
| 220 case AL_PROGRESS: | 234 case AL_PROGRESS: |
| 221 return list[index.row()].progress; | 235 return list[index.row()].progress; |
| 222 case AL_SCORE: | 236 case AL_SCORE: |
| 223 return list[index.row()].score; | 237 return list[index.row()].score; |
| 224 case AL_TYPE: | 238 case AL_TYPE: |
| 225 return QString::fromStdString(AnimeFormatToStringMap[list[index.row()].type]); | 239 return QString::fromStdString(AnimeFormatToStringMap[list[index.row()].type]); |
| 226 case AL_SEASON: | 240 case AL_SEASON: |
| 227 return QString::fromStdString(AnimeSeasonToStringMap[list[index.row()].season]) + " " + QString::number((int)list[index.row()].air_date.year()); | 241 return QString::fromStdString(AnimeSeasonToStringMap[list[index.row()].season]) + " " + QString::number(list[index.row()].air_date.GetYear()); |
| 228 case AL_AVG_SCORE: | 242 case AL_AVG_SCORE: |
| 229 return list[index.row()].audience_score; | 243 return list[index.row()].audience_score; |
| 230 case AL_STARTED: | 244 case AL_STARTED: |
| 231 /* why c++20 chrono is stinky: the game */ | 245 return list[index.row()].started.GetAsQDate(); |
| 232 return QDate(int(list[index.row()].started.year()), static_cast<int>((unsigned int)list[index.row()].started.month()), static_cast<int>((unsigned int)list[index.row()].started.day())); | |
| 233 case AL_COMPLETED: | 246 case AL_COMPLETED: |
| 234 return QDate(int(list[index.row()].completed.year()), static_cast<int>((unsigned int)list[index.row()].completed.month()), static_cast<int>((unsigned int)list[index.row()].completed.day())); | 247 return list[index.row()].completed.GetAsQDate(); |
| 248 case AL_UPDATED: { | |
| 249 if (list[index.row()].updated == 0) | |
| 250 return QString("-"); | |
| 251 Time::Duration duration(Time::GetSystemTime() - list[index.row()].updated); | |
| 252 return QString::fromStdString(duration.AsRelativeString()); | |
| 253 } | |
| 235 case AL_NOTES: | 254 case AL_NOTES: |
| 236 return QString::fromWCharArray(list[index.row()].notes.c_str()); | 255 return QString::fromWCharArray(list[index.row()].notes.c_str()); |
| 237 default: | 256 default: |
| 238 return ""; | 257 return ""; |
| 239 } | 258 } |
| 248 case AL_AVG_SCORE: | 267 case AL_AVG_SCORE: |
| 249 return QVariant(Qt::AlignCenter | Qt::AlignVCenter); | 268 return QVariant(Qt::AlignCenter | Qt::AlignVCenter); |
| 250 case AL_SEASON: | 269 case AL_SEASON: |
| 251 case AL_STARTED: | 270 case AL_STARTED: |
| 252 case AL_COMPLETED: | 271 case AL_COMPLETED: |
| 272 case AL_UPDATED: | |
| 253 return QVariant(Qt::AlignRight | Qt::AlignVCenter); | 273 return QVariant(Qt::AlignRight | Qt::AlignVCenter); |
| 254 default: | 274 default: |
| 255 break; | 275 break; |
| 256 } | 276 } |
| 257 } | 277 } |
| 258 return QVariant(); | 278 return QVariant(); |
| 259 } | 279 } |
| 260 | 280 |
| 261 /* this should ALWAYS be called if the list is edited */ | 281 void AnimeListWidgetModel::UpdateAnime(Anime& anime) { |
| 262 void AnimeListWidgetModel::Update() { | 282 int i = list.GetAnimeIndex(anime); |
| 263 | 283 emit dataChanged(index(i), index(i)); |
| 264 } | 284 } |
| 265 | 285 |
| 266 /* Most of this stuff is const and/or should be edited in the Information dialog | 286 /* Most of this stuff is const and/or should be edited in the Information dialog |
| 267 | 287 |
| 268 bool AnimeListWidgetModel::setData(const QModelIndex &index, const QVariant &value, int role) { | 288 bool AnimeListWidgetModel::setData(const QModelIndex &index, const QVariant &value, int role) { |
| 372 const QModelIndex index = model->index(selected_items.first().row()); | 392 const QModelIndex index = model->index(selected_items.first().row()); |
| 373 Anime* anime = model->GetAnimeFromIndex(index); | 393 Anime* anime = model->GetAnimeFromIndex(index); |
| 374 if (!anime) | 394 if (!anime) |
| 375 return; | 395 return; |
| 376 | 396 |
| 377 /* todo: open information dialog... */ | 397 InformationDialog* dialog = new InformationDialog(*anime, model, this); |
| 398 | |
| 399 dialog->show(); | |
| 400 dialog->raise(); | |
| 401 dialog->activateWindow(); | |
| 378 } | 402 } |
| 379 | 403 |
| 380 AnimeListWidget::AnimeListWidget(QWidget* parent, AnimeList* alist) | 404 AnimeListWidget::AnimeListWidget(QWidget* parent, AnimeList* alist) |
| 381 : QTreeView(parent) { | 405 : QTreeView(parent) { |
| 382 model = new AnimeListWidgetModel(parent, alist); | 406 model = new AnimeListWidgetModel(parent, alist); |
| 383 this->setModel(model); | 407 setModel(model); |
| 408 setObjectName("listwidget"); | |
| 409 setStyleSheet("QTreeView#listwidget{border-top:0px;}"); | |
| 384 setUniformRowHeights(true); | 410 setUniformRowHeights(true); |
| 385 setAllColumnsShowFocus(false); | 411 setAllColumnsShowFocus(false); |
| 386 setSortingEnabled(true); | 412 setSortingEnabled(true); |
| 387 setSelectionMode(QAbstractItemView::ExtendedSelection); | 413 setSelectionMode(QAbstractItemView::ExtendedSelection); |
| 388 setItemsExpandable(false); | 414 setItemsExpandable(false); |
| 405 SetColumnDefaults(); | 431 SetColumnDefaults(); |
| 406 // } | 432 // } |
| 407 } | 433 } |
| 408 | 434 |
| 409 AnimeListPage::AnimeListPage(QWidget* parent) : QTabWidget (parent) { | 435 AnimeListPage::AnimeListPage(QWidget* parent) : QTabWidget (parent) { |
| 410 setDocumentMode(true); | 436 setDocumentMode(false); |
| 411 SyncAnimeList(); | 437 SyncAnimeList(); |
| 412 for (AnimeList& list : anime_lists) { | 438 for (AnimeList& list : anime_lists) { |
| 413 addTab(new AnimeListWidget(this, &list), QString::fromWCharArray(list.name.c_str())); | 439 addTab(new AnimeListWidget(this, &list), QString::fromWCharArray(list.name.c_str())); |
| 414 } | 440 } |
| 415 } | 441 } |
