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