Mercurial > minori
annotate src/include/anime.h @ 6:1d82f6e04d7d
Update: add first parts to the settings dialog
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Wed, 16 Aug 2023 00:49:17 -0400 |
parents | 5af270662505 |
children | 07a9095eaeed |
rev | line source |
---|---|
2 | 1 #ifndef __anime_h |
2 #define __anime_h | |
3 #include <vector> | |
4 #include <map> | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
5 #include <QStyledItemDelegate> |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
6 #include <QProgressBar> |
2 | 7 #include "date.h" |
8 #include "window.h" | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
9 #include "progress.h" |
2 | 10 |
11 enum AnimeWatchingStatus { | |
12 CURRENT, | |
13 PLANNING, | |
14 COMPLETED, | |
15 DROPPED, | |
16 PAUSED, | |
17 REPEATING | |
18 }; | |
19 | |
20 enum AnimeAiringStatus { | |
21 FINISHED, | |
22 RELEASING, | |
23 NOT_YET_RELEASED, | |
24 CANCELLED, | |
25 HIATUS | |
26 }; | |
27 | |
28 enum AnimeFormat { | |
29 TV, | |
30 TV_SHORT, | |
31 MOVIE, | |
32 SPECIAL, | |
33 OVA, | |
34 ONA, | |
35 MUSIC, | |
36 MANGA, | |
37 NOVEL, | |
38 ONE_SHOT | |
39 }; | |
40 | |
41 enum AnimeSeason { | |
42 UNKNOWN, | |
43 WINTER, | |
44 SPRING, | |
45 SUMMER, | |
46 FALL | |
47 }; | |
48 | |
49 class Anime { | |
50 public: | |
51 Anime(); | |
52 Anime(const Anime& a); | |
53 /* List-specific data */ | |
54 enum AnimeWatchingStatus status; | |
55 int progress; | |
56 int score; | |
57 Date started; | |
58 Date completed; | |
59 int updated; /* this should be 64-bit */ | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
60 std::string notes; |
2 | 61 |
62 /* Useful information */ | |
63 int id; | |
64 struct { | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
65 std::string romaji; |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
66 std::string english; |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
67 std::string native; |
2 | 68 } title; |
69 int episodes; | |
70 enum AnimeAiringStatus airing; | |
71 Date air_date; | |
72 std::vector<std::string> genres; | |
73 std::vector<std::string> producers; | |
74 enum AnimeFormat type; | |
75 enum AnimeSeason season; | |
76 int audience_score; | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
77 std::string synopsis; |
2 | 78 int duration; |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
79 |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
80 std::string GetUserPreferredTitle(); |
2 | 81 }; |
82 | |
83 /* This is a simple wrapper on a vector that provides | |
84 methods to make it easier to search the list. */ | |
85 class AnimeList { | |
86 public: | |
87 AnimeList(); | |
88 AnimeList(const AnimeList& l); | |
89 ~AnimeList(); | |
90 void Add(Anime& anime); | |
91 void Insert(size_t pos, Anime& anime); | |
92 void Delete(size_t index); | |
93 void Clear(); | |
94 std::vector<Anime>::iterator begin() noexcept; | |
95 std::vector<Anime>::iterator end() noexcept; | |
96 std::vector<Anime>::const_iterator cbegin() noexcept; | |
97 std::vector<Anime>::const_iterator cend() noexcept; | |
98 size_t Size() const; | |
99 Anime* AnimeById(int id); | |
100 int GetAnimeIndex(Anime& anime) const; | |
101 bool AnimeInList(int id); | |
102 Anime& operator[](size_t index); | |
103 const Anime& operator[](size_t index) const; | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
104 std::string name; |
2 | 105 |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
106 protected: |
2 | 107 std::vector<Anime> anime_list; |
108 std::map<int, Anime*> anime_id_to_anime; | |
109 }; | |
110 | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
111 class AnimeListWidgetDelegate : public QStyledItemDelegate { |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
112 Q_OBJECT |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
113 |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
114 public: |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
115 explicit AnimeListWidgetDelegate(QObject *parent); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
116 |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
117 QWidget *createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const override; |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
118 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
119 |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
120 protected: |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
121 AnimeProgressBar progress_bar; |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
122 }; |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
123 |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
124 class AnimeListWidgetSortFilter : public QSortFilterProxyModel |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
125 { |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
126 Q_OBJECT |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
127 |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
128 public: |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
129 AnimeListWidgetSortFilter(QObject *parent = nullptr); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
130 |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
131 protected: |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
132 bool lessThan(const QModelIndex &l, const QModelIndex &r) const override; |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
133 }; |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
134 |
2 | 135 class AnimeListWidgetModel : public QAbstractListModel { |
136 Q_OBJECT | |
137 public: | |
138 enum columns { | |
139 AL_TITLE, | |
140 AL_PROGRESS, | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
141 AL_EPISODES, |
2 | 142 AL_SCORE, |
143 AL_AVG_SCORE, | |
144 AL_TYPE, | |
145 AL_SEASON, | |
146 AL_STARTED, | |
147 AL_COMPLETED, | |
148 AL_UPDATED, | |
149 AL_NOTES, | |
150 | |
151 NB_COLUMNS | |
152 }; | |
153 | |
154 AnimeListWidgetModel(QWidget* parent, AnimeList* alist); | |
155 ~AnimeListWidgetModel() override = default; | |
4
5af270662505
Set override functions as override
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
156 int rowCount(const QModelIndex& parent = QModelIndex()) const override; |
5af270662505
Set override functions as override
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
157 int columnCount(const QModelIndex& parent = QModelIndex()) const override; |
5af270662505
Set override functions as override
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
158 QVariant data(const QModelIndex& index, int role) const override; |
5af270662505
Set override functions as override
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
159 QVariant headerData(const int section, const Qt::Orientation orientation, const int role) const override; |
2 | 160 Anime* GetAnimeFromIndex(const QModelIndex& index); |
161 void UpdateAnime(Anime& anime); | |
162 | |
163 private: | |
164 //void AddAnime(AnimeList& list); | |
165 AnimeList& list; | |
166 }; | |
167 | |
168 class AnimeListWidget : public QTreeView { | |
169 Q_OBJECT | |
170 public: | |
171 AnimeListWidget(QWidget* parent, AnimeList* alist); | |
172 | |
173 private slots: | |
174 void DisplayColumnHeaderMenu(); | |
175 void DisplayListMenu(); | |
176 void ItemDoubleClicked(); | |
177 void SetColumnDefaults(); | |
178 int VisibleColumnsCount() const; | |
179 | |
180 private: | |
181 AnimeListWidgetModel* model = nullptr; | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
4
diff
changeset
|
182 AnimeListWidgetSortFilter* sort_model = nullptr; |
2 | 183 }; |
184 | |
185 class AnimeListPage : public QTabWidget { | |
186 public: | |
187 AnimeListPage(QWidget* parent = nullptr); | |
188 void SyncAnimeList(); | |
189 void FreeAnimeList(); | |
190 int GetTotalAnimeAmount(); | |
191 int GetTotalEpisodeAmount(); | |
192 int GetTotalWatchedAmount(); | |
193 int GetTotalPlannedAmount(); | |
194 double GetAverageScore(); | |
195 double GetScoreDeviation(); | |
196 | |
197 private: | |
198 std::vector<AnimeList> anime_lists; | |
199 }; | |
200 | |
201 extern std::map<enum AnimeSeason, std::string> AnimeSeasonToStringMap; | |
202 extern std::map<enum AnimeFormat, std::string> AnimeFormatToStringMap; | |
203 extern std::map<enum AnimeWatchingStatus, std::string> AnimeWatchingToStringMap; | |
204 extern std::map<enum AnimeAiringStatus, std::string> AnimeAiringToStringMap; | |
1 | 205 #endif // __anime_h |