10
|
1 #ifndef __gui__pages__anime_list_h
|
|
2 #define __gui__pages__anime_list_h
|
85
|
3
|
10
|
4 #include "core/anime.h"
|
|
5 #include <QAbstractListModel>
|
|
6 #include <QSortFilterProxyModel>
|
|
7 #include <QStyledItemDelegate>
|
|
8 #include <QWidget>
|
|
9 #include <vector>
|
|
10
|
85
|
11 class QTreeView;
|
|
12 class QTabBar;
|
|
13
|
64
|
14 class AnimeListPageDelegate : public QStyledItemDelegate {
|
63
|
15 Q_OBJECT
|
10
|
16
|
|
17 public:
|
64
|
18 explicit AnimeListPageDelegate(QObject* parent);
|
10
|
19
|
|
20 QWidget* createEditor(QWidget*, const QStyleOptionViewItem&, const QModelIndex&) const override;
|
|
21 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
|
22 };
|
|
23
|
64
|
24 class AnimeListPageSortFilter : public QSortFilterProxyModel {
|
63
|
25 Q_OBJECT
|
10
|
26
|
|
27 public:
|
64
|
28 AnimeListPageSortFilter(QObject* parent = nullptr);
|
10
|
29
|
|
30 protected:
|
|
31 bool lessThan(const QModelIndex& l, const QModelIndex& r) const override;
|
|
32 };
|
|
33
|
64
|
34 class AnimeListPageModel : public QAbstractListModel {
|
63
|
35 Q_OBJECT
|
10
|
36
|
|
37 public:
|
|
38 enum columns {
|
|
39 AL_TITLE,
|
|
40 AL_PROGRESS,
|
|
41 AL_EPISODES,
|
|
42 AL_SCORE,
|
|
43 AL_AVG_SCORE,
|
|
44 AL_TYPE,
|
|
45 AL_SEASON,
|
|
46 AL_STARTED,
|
|
47 AL_COMPLETED,
|
|
48 AL_UPDATED,
|
|
49 AL_NOTES,
|
|
50
|
|
51 NB_COLUMNS
|
|
52 };
|
|
53
|
64
|
54 AnimeListPageModel(QWidget* parent, Anime::ListStatus _status);
|
|
55 ~AnimeListPageModel() override = default;
|
10
|
56 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
|
57 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
|
|
58 QVariant data(const QModelIndex& index, int role) const override;
|
|
59 QVariant headerData(const int section, const Qt::Orientation orientation, const int role) const override;
|
|
60 void RefreshList();
|
|
61 Anime::Anime* GetAnimeFromIndex(QModelIndex index);
|
|
62
|
|
63 private:
|
|
64 Anime::ListStatus status;
|
|
65 std::vector<Anime::Anime> list;
|
|
66 };
|
|
67
|
|
68 /* todo: rename these to "page" or something more
|
|
69 sensible than "widget" */
|
64
|
70 class AnimeListPage : public QWidget {
|
63
|
71 Q_OBJECT
|
10
|
72
|
|
73 public:
|
64
|
74 AnimeListPage(QWidget* parent);
|
15
|
75 void Refresh();
|
10
|
76 void Reset();
|
|
77
|
|
78 protected:
|
|
79 void paintEvent(QPaintEvent*) override;
|
|
80 void InitStyle(QStyleOptionTabWidgetFrame* option) const;
|
|
81 void InitBasicStyle(QStyleOptionTabWidgetFrame* option) const;
|
|
82 void SetupLayout();
|
|
83 void showEvent(QShowEvent*) override;
|
|
84 void resizeEvent(QResizeEvent* e) override;
|
15
|
85 void RefreshList();
|
|
86 void RefreshTabs();
|
77
|
87 void UpdateAnime(int id);
|
|
88 void RemoveAnime(int id);
|
10
|
89
|
|
90 private slots:
|
|
91 void DisplayColumnHeaderMenu();
|
|
92 void DisplayListMenu();
|
|
93 void ItemDoubleClicked();
|
|
94 void SetColumnDefaults();
|
|
95 int VisibleColumnsCount() const;
|
|
96
|
|
97 private:
|
|
98 QTabBar* tab_bar;
|
|
99 QTreeView* tree_view;
|
|
100 QRect panelRect;
|
83
|
101 std::array<AnimeListPageSortFilter*, 5> sort_models;
|
10
|
102 };
|
85
|
103
|
9
|
104 #endif // __gui__pages__anime_list_h |