comparison src/include/anime_list.h @ 7:07a9095eaeed

Update Refactored some code, moved some around
author Paper <mrpapersonic@gmail.com>
date Thu, 24 Aug 2023 23:11:38 -0400
parents
children
comparison
equal deleted inserted replaced
6:1d82f6e04d7d 7:07a9095eaeed
1 #ifndef __anime_list_h
2 #define __anime_list_h
3 #include <vector>
4 #include <QStyledItemDelegate>
5 #include <QSortFilterProxyModel>
6 #include <QAbstractListModel>
7 #include <QTreeView>
8 #include <QWidget>
9 #include "anime.h"
10 #include "progress.h"
11
12 class AnimeListWidgetDelegate : public QStyledItemDelegate {
13 Q_OBJECT
14
15 public:
16 explicit AnimeListWidgetDelegate(QObject *parent);
17
18 QWidget *createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const override;
19 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
20
21 protected:
22 AnimeProgressBar progress_bar;
23 };
24
25 class AnimeListWidgetSortFilter : public QSortFilterProxyModel
26 {
27 Q_OBJECT
28
29 public:
30 AnimeListWidgetSortFilter(QObject *parent = nullptr);
31
32 protected:
33 bool lessThan(const QModelIndex &l, const QModelIndex &r) const override;
34 };
35
36 class AnimeListWidgetModel : public QAbstractListModel {
37 Q_OBJECT
38
39 public:
40 enum columns {
41 AL_TITLE,
42 AL_PROGRESS,
43 AL_EPISODES,
44 AL_SCORE,
45 AL_AVG_SCORE,
46 AL_TYPE,
47 AL_SEASON,
48 AL_STARTED,
49 AL_COMPLETED,
50 AL_UPDATED,
51 AL_NOTES,
52
53 NB_COLUMNS
54 };
55
56 AnimeListWidgetModel(QWidget* parent, AnimeList* alist);
57 ~AnimeListWidgetModel() override = default;
58 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
59 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
60 QVariant data(const QModelIndex& index, int role) const override;
61 QVariant headerData(const int section, const Qt::Orientation orientation, const int role) const override;
62 Anime* GetAnimeFromIndex(const QModelIndex& index);
63 void UpdateAnime(Anime& anime);
64 void Update(const AnimeList& new_list);
65
66 private:
67 //void AddAnime(AnimeList& list);
68 AnimeList& list;
69 };
70
71 /* todo: rename these to "page" or something more
72 sensible than "widget" */
73 class AnimeListWidget : public QWidget {
74 Q_OBJECT
75
76 public:
77 AnimeListWidget(QWidget* parent);
78 void SyncAnimeList();
79 void FreeAnimeList();
80 int GetTotalAnimeAmount();
81 int GetTotalEpisodeAmount();
82 int GetTotalWatchedAmount();
83 int GetTotalPlannedAmount();
84 double GetAverageScore();
85 double GetScoreDeviation();
86
87 protected:
88 void paintEvent(QPaintEvent*) override;
89 void InitStyle(QStyleOptionTabWidgetFrame *option) const;
90 void InitBasicStyle(QStyleOptionTabWidgetFrame *option) const;
91 void SetupLayout();
92 void showEvent(QShowEvent*) override;
93 void resizeEvent(QResizeEvent* e) override;
94
95 private slots:
96 void DisplayColumnHeaderMenu();
97 void DisplayListMenu();
98 void ItemDoubleClicked();
99 void SetColumnDefaults();
100 int VisibleColumnsCount() const;
101
102 private:
103 QTabBar* tab_bar;
104 QTreeView* tree_view;
105 QRect panelRect;
106 std::vector<AnimeListWidgetSortFilter*> sort_models;
107 std::vector<AnimeList> anime_lists;
108 };
109 #endif // __anime_list_h