comparison include/gui/pages/anime_list.h @ 9:5c0397762b53

INCOMPLETE: megacommit :)
author Paper <mrpapersonic@gmail.com>
date Sun, 10 Sep 2023 03:59:16 -0400
parents src/include/anime_list.h@07a9095eaeed
children 4b198a111713
comparison
equal deleted inserted replaced
8:b1f73678ef61 9:5c0397762b53
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 {
12 Q_OBJECT
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 {
22 Q_OBJECT
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 {
32 Q_OBJECT
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 AL_ID, /* Note: This is only used in Qt::UserRole to make my life easier */
48
49 NB_COLUMNS
50 };
51
52 AnimeListWidgetModel(QWidget* parent);
53 ~AnimeListWidgetModel() override = default;
54 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
55 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
56 QVariant data(const QModelIndex& index, int role) const override;
57 QVariant headerData(const int section, const Qt::Orientation orientation, const int role) const override;
58 void UpdateAnime(int id);
59 };
60
61 /* todo: rename these to "page" or something more
62 sensible than "widget" */
63 class AnimeListWidget : public QWidget {
64 Q_OBJECT
65
66 public:
67 AnimeListWidget(QWidget* parent);
68 void UpdateAnimeList();
69 void Reset();
70
71 protected:
72 void paintEvent(QPaintEvent*) override;
73 void InitStyle(QStyleOptionTabWidgetFrame* option) const;
74 void InitBasicStyle(QStyleOptionTabWidgetFrame* option) const;
75 void SetupLayout();
76 void showEvent(QShowEvent*) override;
77 void resizeEvent(QResizeEvent* e) override;
78
79 private slots:
80 void DisplayColumnHeaderMenu();
81 void DisplayListMenu();
82 void ItemDoubleClicked();
83 void SetColumnDefaults();
84 int VisibleColumnsCount() const;
85
86 private:
87 QTabBar* tab_bar;
88 QTreeView* tree_view;
89 QRect panelRect;
90 AnimeListWidgetSortFilter* sort_models[5];
91 };
92 #endif // __gui__pages__anime_list_h