Mercurial > minori
annotate include/gui/pages/anime_list.h @ 273:f31305b9f60a
*: various code safety changes
this also makes the code build on Qt 5.7. I can't test it though
because I don't have it working... FAIL!
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Thu, 18 Apr 2024 16:53:17 -0400 |
parents | 3ec7804abf17 |
children | f6a756c19bfb |
rev | line source |
---|---|
261
3ec7804abf17
include: make header guards more sane
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
1 #ifndef MINORI_GUI_PAGES_ANIME_LIST_H_ |
3ec7804abf17
include: make header guards more sane
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
2 #define MINORI_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> | |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
9 #include <QThread> |
10 | 10 #include <vector> |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
11 #include <queue> |
10 | 12 |
85 | 13 class QTreeView; |
14 class QTabBar; | |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
15 class AnimeListPage; |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
16 |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
17 class AnimeListPageUpdateEntryThread final : public QThread { |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
18 public: |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
19 AnimeListPageUpdateEntryThread(AnimeListPage* parent); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
20 |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
21 void AddToQueue(int id); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
22 |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
23 protected: |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
24 void run() override; |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
25 |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
26 private: |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
27 AnimeListPage* page_ = nullptr; |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
28 std::queue<int> queue_; |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
29 }; |
85 | 30 |
95
8043152ef9d4
include: set classes as final where appropriate
Paper <mrpapersonic@gmail.com>
parents:
85
diff
changeset
|
31 class AnimeListPageSortFilter final : public QSortFilterProxyModel { |
258 | 32 Q_OBJECT |
10 | 33 |
258 | 34 public: |
35 AnimeListPageSortFilter(QObject* parent = nullptr); | |
10 | 36 |
258 | 37 protected: |
38 bool lessThan(const QModelIndex& l, const QModelIndex& r) const override; | |
10 | 39 }; |
40 | |
95
8043152ef9d4
include: set classes as final where appropriate
Paper <mrpapersonic@gmail.com>
parents:
85
diff
changeset
|
41 class AnimeListPageModel final : public QAbstractListModel { |
258 | 42 Q_OBJECT |
10 | 43 |
258 | 44 public: |
45 enum columns { | |
46 AL_TITLE, | |
47 AL_PROGRESS, | |
48 AL_EPISODES, | |
49 AL_SCORE, | |
50 AL_AVG_SCORE, | |
51 AL_TYPE, | |
52 AL_SEASON, | |
53 AL_STARTED, | |
54 AL_COMPLETED, | |
55 AL_UPDATED, | |
56 AL_NOTES, | |
10 | 57 |
258 | 58 NB_COLUMNS |
59 }; | |
10 | 60 |
258 | 61 AnimeListPageModel(QObject* parent, Anime::ListStatus _status); |
62 ~AnimeListPageModel() override = default; | |
63 int rowCount(const QModelIndex& parent = QModelIndex()) const override; | |
64 int columnCount(const QModelIndex& parent = QModelIndex()) const override; | |
65 QVariant data(const QModelIndex& index, int role) const override; | |
66 QVariant headerData(const int section, const Qt::Orientation orientation, const int role) const override; | |
67 void RefreshList(); | |
68 Anime::Anime* GetAnimeFromIndex(QModelIndex index); | |
10 | 69 |
258 | 70 private: |
71 Anime::ListStatus status; | |
72 std::vector<Anime::Anime> list; | |
10 | 73 }; |
74 | |
75 /* todo: rename these to "page" or something more | |
76 sensible than "widget" */ | |
95
8043152ef9d4
include: set classes as final where appropriate
Paper <mrpapersonic@gmail.com>
parents:
85
diff
changeset
|
77 class AnimeListPage final : public QWidget { |
258 | 78 Q_OBJECT |
10 | 79 |
258 | 80 public: |
81 AnimeListPage(QWidget* parent); | |
82 void Refresh(); | |
10 | 83 |
258 | 84 protected: |
85 void paintEvent(QPaintEvent*) override; | |
86 void InitStyle(QStyleOptionTabWidgetFrame* option) const; | |
87 void InitBasicStyle(QStyleOptionTabWidgetFrame* option) const; | |
88 void SetupLayout(); | |
89 void showEvent(QShowEvent*) override; | |
90 void resizeEvent(QResizeEvent* e) override; | |
91 void RefreshList(); | |
92 void RefreshTabs(); | |
93 void UpdateAnime(int id); | |
94 void RemoveAnime(int id); | |
10 | 95 |
258 | 96 private slots: |
97 void DisplayColumnHeaderMenu(); | |
98 void DisplayListMenu(); | |
99 void ItemDoubleClicked(); | |
100 void SetColumnDefaults(); | |
101 int VisibleColumnsCount() const; | |
10 | 102 |
258 | 103 private: |
104 QTabBar* tab_bar; | |
105 QTreeView* tree_view; | |
106 QRect panelRect; | |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
107 |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
108 AnimeListPageUpdateEntryThread update_entry_thread_; |
258 | 109 std::array<AnimeListPageSortFilter*, 5> sort_models; |
10 | 110 }; |
85 | 111 |
261
3ec7804abf17
include: make header guards more sane
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
112 #endif // MINORI_GUI_PAGES_ANIME_LIST_H_ |