Mercurial > minori
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 5:51ae25154b70 | 6:1d82f6e04d7d |
|---|---|
| 1 #ifndef __anime_h | 1 #ifndef __anime_h |
| 2 #define __anime_h | 2 #define __anime_h |
| 3 #include <vector> | 3 #include <vector> |
| 4 #include <map> | 4 #include <map> |
| 5 #include <QStyledItemDelegate> | |
| 6 #include <QProgressBar> | |
| 5 #include "date.h" | 7 #include "date.h" |
| 6 #include "window.h" | 8 #include "window.h" |
| 9 #include "progress.h" | |
| 7 | 10 |
| 8 enum AnimeWatchingStatus { | 11 enum AnimeWatchingStatus { |
| 9 CURRENT, | 12 CURRENT, |
| 10 PLANNING, | 13 PLANNING, |
| 11 COMPLETED, | 14 COMPLETED, |
| 52 int progress; | 55 int progress; |
| 53 int score; | 56 int score; |
| 54 Date started; | 57 Date started; |
| 55 Date completed; | 58 Date completed; |
| 56 int updated; /* this should be 64-bit */ | 59 int updated; /* this should be 64-bit */ |
| 57 std::wstring notes; | 60 std::string notes; |
| 58 | 61 |
| 59 /* Useful information */ | 62 /* Useful information */ |
| 60 int id; | 63 int id; |
| 61 struct { | 64 struct { |
| 62 std::wstring romaji; | 65 std::string romaji; |
| 63 std::wstring english; | 66 std::string english; |
| 64 std::wstring native; | 67 std::string native; |
| 65 } title; | 68 } title; |
| 66 int episodes; | 69 int episodes; |
| 67 enum AnimeAiringStatus airing; | 70 enum AnimeAiringStatus airing; |
| 68 Date air_date; | 71 Date air_date; |
| 69 std::vector<std::string> genres; | 72 std::vector<std::string> genres; |
| 70 std::vector<std::string> producers; | 73 std::vector<std::string> producers; |
| 71 enum AnimeFormat type; | 74 enum AnimeFormat type; |
| 72 enum AnimeSeason season; | 75 enum AnimeSeason season; |
| 73 int audience_score; | 76 int audience_score; |
| 74 std::wstring synopsis; | 77 std::string synopsis; |
| 75 int duration; | 78 int duration; |
| 79 | |
| 80 std::string GetUserPreferredTitle(); | |
| 76 }; | 81 }; |
| 77 | 82 |
| 78 /* This is a simple wrapper on a vector that provides | 83 /* This is a simple wrapper on a vector that provides |
| 79 methods to make it easier to search the list. */ | 84 methods to make it easier to search the list. */ |
| 80 class AnimeList { | 85 class AnimeList { |
| 94 Anime* AnimeById(int id); | 99 Anime* AnimeById(int id); |
| 95 int GetAnimeIndex(Anime& anime) const; | 100 int GetAnimeIndex(Anime& anime) const; |
| 96 bool AnimeInList(int id); | 101 bool AnimeInList(int id); |
| 97 Anime& operator[](size_t index); | 102 Anime& operator[](size_t index); |
| 98 const Anime& operator[](size_t index) const; | 103 const Anime& operator[](size_t index) const; |
| 99 std::wstring name; | 104 std::string name; |
| 100 | 105 |
| 101 private: | 106 protected: |
| 102 std::vector<Anime> anime_list; | 107 std::vector<Anime> anime_list; |
| 103 std::map<int, Anime*> anime_id_to_anime; | 108 std::map<int, Anime*> anime_id_to_anime; |
| 109 }; | |
| 110 | |
| 111 class AnimeListWidgetDelegate : public QStyledItemDelegate { | |
| 112 Q_OBJECT | |
| 113 | |
| 114 public: | |
| 115 explicit AnimeListWidgetDelegate(QObject *parent); | |
| 116 | |
| 117 QWidget *createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const override; | |
| 118 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; | |
| 119 | |
| 120 protected: | |
| 121 AnimeProgressBar progress_bar; | |
| 122 }; | |
| 123 | |
| 124 class AnimeListWidgetSortFilter : public QSortFilterProxyModel | |
| 125 { | |
| 126 Q_OBJECT | |
| 127 | |
| 128 public: | |
| 129 AnimeListWidgetSortFilter(QObject *parent = nullptr); | |
| 130 | |
| 131 protected: | |
| 132 bool lessThan(const QModelIndex &l, const QModelIndex &r) const override; | |
| 104 }; | 133 }; |
| 105 | 134 |
| 106 class AnimeListWidgetModel : public QAbstractListModel { | 135 class AnimeListWidgetModel : public QAbstractListModel { |
| 107 Q_OBJECT | 136 Q_OBJECT |
| 108 public: | 137 public: |
| 109 enum columns { | 138 enum columns { |
| 110 AL_TITLE, | 139 AL_TITLE, |
| 111 AL_PROGRESS, | 140 AL_PROGRESS, |
| 141 AL_EPISODES, | |
| 112 AL_SCORE, | 142 AL_SCORE, |
| 113 AL_AVG_SCORE, | 143 AL_AVG_SCORE, |
| 114 AL_TYPE, | 144 AL_TYPE, |
| 115 AL_SEASON, | 145 AL_SEASON, |
| 116 AL_STARTED, | 146 AL_STARTED, |
| 121 NB_COLUMNS | 151 NB_COLUMNS |
| 122 }; | 152 }; |
| 123 | 153 |
| 124 AnimeListWidgetModel(QWidget* parent, AnimeList* alist); | 154 AnimeListWidgetModel(QWidget* parent, AnimeList* alist); |
| 125 ~AnimeListWidgetModel() override = default; | 155 ~AnimeListWidgetModel() override = default; |
| 126 //QVariant headerData(const int section, const Qt::Orientation orientation, const int role) const; | |
| 127 int rowCount(const QModelIndex& parent = QModelIndex()) const override; | 156 int rowCount(const QModelIndex& parent = QModelIndex()) const override; |
| 128 int columnCount(const QModelIndex& parent = QModelIndex()) const override; | 157 int columnCount(const QModelIndex& parent = QModelIndex()) const override; |
| 129 QVariant data(const QModelIndex& index, int role) const override; | 158 QVariant data(const QModelIndex& index, int role) const override; |
| 130 QVariant headerData(const int section, const Qt::Orientation orientation, const int role) const override; | 159 QVariant headerData(const int section, const Qt::Orientation orientation, const int role) const override; |
| 131 Anime* GetAnimeFromIndex(const QModelIndex& index); | 160 Anime* GetAnimeFromIndex(const QModelIndex& index); |
| 148 void SetColumnDefaults(); | 177 void SetColumnDefaults(); |
| 149 int VisibleColumnsCount() const; | 178 int VisibleColumnsCount() const; |
| 150 | 179 |
| 151 private: | 180 private: |
| 152 AnimeListWidgetModel* model = nullptr; | 181 AnimeListWidgetModel* model = nullptr; |
| 182 AnimeListWidgetSortFilter* sort_model = nullptr; | |
| 153 }; | 183 }; |
| 154 | 184 |
| 155 class AnimeListPage : public QTabWidget { | 185 class AnimeListPage : public QTabWidget { |
| 156 public: | 186 public: |
| 157 AnimeListPage(QWidget* parent = nullptr); | 187 AnimeListPage(QWidget* parent = nullptr); |
