comparison src/include/anime.h @ 1:1ae666fdf9e2

*: initial commit
author Paper <mrpapersonic@gmail.com>
date Tue, 08 Aug 2023 19:49:15 -0400
parents
children 23d0d9319a00
comparison
equal deleted inserted replaced
0:5a76e1b94163 1:1ae666fdf9e2
1 #ifndef __anime_h
2 #define __anime_h
3 #include <vector>
4 #include <chrono>
5 #include <map>
6 #include "window.h"
7
8 enum AnimeWatchingStatus {
9 CURRENT,
10 PLANNING,
11 COMPLETED,
12 DROPPED,
13 PAUSED,
14 REPEATING
15 };
16
17 enum AnimeAiringStatus {
18 FINISHED,
19 RELEASING,
20 NOT_YET_RELEASED,
21 CANCELLED,
22 HIATUS
23 };
24
25 enum AnimeFormat {
26 TV,
27 TV_SHORT,
28 MOVIE,
29 SPECIAL,
30 OVA,
31 ONA,
32 MUSIC,
33 MANGA,
34 NOVEL,
35 ONE_SHOT
36 };
37
38 enum AnimeSeason {
39 WINTER,
40 SPRING,
41 SUMMER,
42 FALL
43 };
44
45 class Anime {
46 public:
47 Anime();
48 Anime(const Anime& a);
49 /* List-specific data */
50 enum AnimeWatchingStatus status;
51 int progress;
52 int score;
53 std::chrono::year_month_day started;
54 std::chrono::year_month_day completed;
55 std::wstring notes;
56
57 /* Useful information */
58 int id;
59 std::wstring title;
60 int episodes;
61 enum AnimeAiringStatus airing;
62 std::chrono::year_month_day air_date;
63 std::vector<std::string> genres;
64 std::vector<std::string> producers;
65 enum AnimeFormat type;
66 enum AnimeSeason season;
67 int audience_score;
68 std::wstring synopsis;
69 int duration;
70 };
71
72 /* This is a simple wrapper on a vector that provides
73 methods to make it easier to search the list. */
74 class AnimeList {
75 public:
76 AnimeList();
77 AnimeList(const AnimeList& l);
78 ~AnimeList();
79 void Add(Anime& anime);
80 void Insert(size_t pos, Anime& anime);
81 void Delete(size_t index);
82 void Clear();
83 std::vector<Anime>::iterator begin() noexcept;
84 std::vector<Anime>::iterator end() noexcept;
85 std::vector<Anime>::const_iterator cbegin() noexcept;
86 std::vector<Anime>::const_iterator cend() noexcept;
87 size_t Size() const;
88 Anime* AnimeById(int id);
89 bool AnimeInList(int id);
90 Anime& operator[](size_t index);
91 const Anime& operator[](size_t index) const;
92 std::wstring name;
93
94 private:
95 std::vector<Anime> anime_list;
96 std::map<int, Anime*> anime_id_to_anime;
97 };
98
99 class AnimeListWidgetModel : public QAbstractListModel {
100 Q_OBJECT
101 public:
102 enum columns {
103 AL_TITLE,
104 AL_PROGRESS,
105 AL_SCORE,
106 AL_AVG_SCORE,
107 AL_TYPE,
108 AL_SEASON,
109 AL_STARTED,
110 AL_COMPLETED,
111 AL_UPDATED,
112 AL_NOTES,
113
114 NB_COLUMNS
115 };
116
117 AnimeListWidgetModel(QWidget* parent, AnimeList* alist);
118 ~AnimeListWidgetModel() override = default;
119 //QVariant headerData(const int section, const Qt::Orientation orientation, const int role) const;
120 int rowCount(const QModelIndex& parent = QModelIndex()) const;
121 int columnCount(const QModelIndex& parent = QModelIndex()) const;
122 QVariant data(const QModelIndex& index, int role) const;
123 QVariant headerData(const int section, const Qt::Orientation orientation, const int role) const;
124 Anime* GetAnimeFromIndex(const QModelIndex& index);
125 void Update();
126
127 private:
128 //void AddAnime(AnimeList& list);
129 AnimeList& list;
130 };
131
132 class AnimeListWidget : public QTreeView {
133 Q_OBJECT
134 public:
135 AnimeListWidget(QWidget* parent, AnimeList* alist);
136
137 private slots:
138 void DisplayColumnHeaderMenu();
139 void DisplayListMenu();
140 void ItemDoubleClicked();
141 void SetColumnDefaults();
142 int VisibleColumnsCount() const;
143
144 private:
145 AnimeListWidgetModel* model = nullptr;
146 };
147
148 class AnimeListPage : public QTabWidget {
149 public:
150 AnimeListPage(QWidget* parent = nullptr);
151 void SyncAnimeList();
152 void FreeAnimeList();
153 int GetTotalAnimeAmount();
154 int GetTotalEpisodeAmount();
155 int GetTotalWatchedAmount();
156 int GetTotalPlannedAmount();
157 double GetAverageScore();
158 double GetScoreDeviation();
159
160 private:
161 std::vector<AnimeList> anime_lists;
162 };
163
164 extern std::map<enum AnimeSeason, std::string> AnimeSeasonToStringMap;
165 extern std::map<enum AnimeFormat, std::string> AnimeFormatToStringMap;
166 extern std::map<enum AnimeWatchingStatus, std::string> AnimeWatchingToStringMap;
167 extern std::map<enum AnimeAiringStatus, std::string> AnimeAiringToStringMap;
168 #endif // __anime_h