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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
1 #ifndef __anime_h
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
2 #define __anime_h
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
3 #include <vector>
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
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
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
7 #include "date.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
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
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
10
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
11 enum AnimeWatchingStatus {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
12 CURRENT,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
13 PLANNING,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
14 COMPLETED,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
15 DROPPED,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
16 PAUSED,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
17 REPEATING
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
18 };
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
19
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
20 enum AnimeAiringStatus {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
21 FINISHED,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
22 RELEASING,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
23 NOT_YET_RELEASED,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
24 CANCELLED,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
25 HIATUS
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
26 };
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
27
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
28 enum AnimeFormat {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
29 TV,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
30 TV_SHORT,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
31 MOVIE,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
32 SPECIAL,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
33 OVA,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
34 ONA,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
35 MUSIC,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
36 MANGA,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
37 NOVEL,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
38 ONE_SHOT
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
39 };
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
40
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
41 enum AnimeSeason {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
42 UNKNOWN,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
43 WINTER,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
44 SPRING,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
45 SUMMER,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
46 FALL
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
47 };
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
48
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
49 class Anime {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
50 public:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
51 Anime();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
52 Anime(const Anime& a);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
53 /* List-specific data */
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
54 enum AnimeWatchingStatus status;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
55 int progress;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
56 int score;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
57 Date started;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
58 Date completed;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
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
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
61
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
62 /* Useful information */
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
63 int id;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
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
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
68 } title;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
69 int episodes;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
70 enum AnimeAiringStatus airing;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
71 Date air_date;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
72 std::vector<std::string> genres;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
73 std::vector<std::string> producers;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
74 enum AnimeFormat type;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
75 enum AnimeSeason season;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
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
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
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
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
81 };
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
82
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
83 /* This is a simple wrapper on a vector that provides
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
84 methods to make it easier to search the list. */
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
85 class AnimeList {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
86 public:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
87 AnimeList();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
88 AnimeList(const AnimeList& l);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
89 ~AnimeList();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
90 void Add(Anime& anime);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
91 void Insert(size_t pos, Anime& anime);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
92 void Delete(size_t index);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
93 void Clear();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
94 std::vector<Anime>::iterator begin() noexcept;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
95 std::vector<Anime>::iterator end() noexcept;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
96 std::vector<Anime>::const_iterator cbegin() noexcept;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
97 std::vector<Anime>::const_iterator cend() noexcept;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
98 size_t Size() const;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
99 Anime* AnimeById(int id);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
100 int GetAnimeIndex(Anime& anime) const;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
101 bool AnimeInList(int id);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
102 Anime& operator[](size_t index);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
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
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
105
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 4
diff changeset
106 protected:
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
107 std::vector<Anime> anime_list;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
108 std::map<int, Anime*> anime_id_to_anime;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
109 };
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
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
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
135 class AnimeListWidgetModel : public QAbstractListModel {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
136 Q_OBJECT
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
137 public:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
138 enum columns {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
139 AL_TITLE,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
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
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
142 AL_SCORE,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
143 AL_AVG_SCORE,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
144 AL_TYPE,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
145 AL_SEASON,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
146 AL_STARTED,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
147 AL_COMPLETED,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
148 AL_UPDATED,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
149 AL_NOTES,
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
150
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
151 NB_COLUMNS
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
152 };
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
153
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
154 AnimeListWidgetModel(QWidget* parent, AnimeList* alist);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
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
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
160 Anime* GetAnimeFromIndex(const QModelIndex& index);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
161 void UpdateAnime(Anime& anime);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
162
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
163 private:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
164 //void AddAnime(AnimeList& list);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
165 AnimeList& list;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
166 };
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
167
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
168 class AnimeListWidget : public QTreeView {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
169 Q_OBJECT
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
170 public:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
171 AnimeListWidget(QWidget* parent, AnimeList* alist);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
172
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
173 private slots:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
174 void DisplayColumnHeaderMenu();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
175 void DisplayListMenu();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
176 void ItemDoubleClicked();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
177 void SetColumnDefaults();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
178 int VisibleColumnsCount() const;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
179
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
180 private:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
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
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
183 };
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
184
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
185 class AnimeListPage : public QTabWidget {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
186 public:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
187 AnimeListPage(QWidget* parent = nullptr);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
188 void SyncAnimeList();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
189 void FreeAnimeList();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
190 int GetTotalAnimeAmount();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
191 int GetTotalEpisodeAmount();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
192 int GetTotalWatchedAmount();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
193 int GetTotalPlannedAmount();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
194 double GetAverageScore();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
195 double GetScoreDeviation();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
196
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
197 private:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
198 std::vector<AnimeList> anime_lists;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
199 };
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
200
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
201 extern std::map<enum AnimeSeason, std::string> AnimeSeasonToStringMap;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
202 extern std::map<enum AnimeFormat, std::string> AnimeFormatToStringMap;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
203 extern std::map<enum AnimeWatchingStatus, std::string> AnimeWatchingToStringMap;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
204 extern std::map<enum AnimeAiringStatus, std::string> AnimeAiringToStringMap;
1
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
205 #endif // __anime_h