Mercurial > minori
annotate include/gui/pages/anime_list.h @ 315:34347fd2a2de
session: allow printing status messages
...!
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Tue, 11 Jun 2024 14:16:40 -0400 |
parents | 8769c5d50b06 |
children | 1b5c04268d6a |
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 { |
307
8769c5d50b06
pages/anime_list: don't call GUI functions in a non-GUI thread
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
18 Q_OBJECT |
8769c5d50b06
pages/anime_list: don't call GUI functions in a non-GUI thread
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
19 |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
20 public: |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
21 AnimeListPageUpdateEntryThread(AnimeListPage* parent); |
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 void AddToQueue(int id); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
24 |
307
8769c5d50b06
pages/anime_list: don't call GUI functions in a non-GUI thread
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
25 signals: |
8769c5d50b06
pages/anime_list: don't call GUI functions in a non-GUI thread
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
26 void NeedRefresh(); |
8769c5d50b06
pages/anime_list: don't call GUI functions in a non-GUI thread
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
27 |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
28 protected: |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
29 void run() override; |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
30 |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
31 private: |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
32 AnimeListPage* page_ = nullptr; |
274
f6a756c19bfb
anime_list.cc: use mutexes so we don't sex the stack
Paper <paper@paper.us.eu.org>
parents:
273
diff
changeset
|
33 std::mutex _queue_mutex; |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
34 std::queue<int> queue_; |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
35 }; |
85 | 36 |
95
8043152ef9d4
include: set classes as final where appropriate
Paper <mrpapersonic@gmail.com>
parents:
85
diff
changeset
|
37 class AnimeListPageSortFilter final : public QSortFilterProxyModel { |
258 | 38 Q_OBJECT |
10 | 39 |
258 | 40 public: |
41 AnimeListPageSortFilter(QObject* parent = nullptr); | |
10 | 42 |
258 | 43 protected: |
44 bool lessThan(const QModelIndex& l, const QModelIndex& r) const override; | |
10 | 45 }; |
46 | |
95
8043152ef9d4
include: set classes as final where appropriate
Paper <mrpapersonic@gmail.com>
parents:
85
diff
changeset
|
47 class AnimeListPageModel final : public QAbstractListModel { |
258 | 48 Q_OBJECT |
10 | 49 |
258 | 50 public: |
51 enum columns { | |
52 AL_TITLE, | |
53 AL_PROGRESS, | |
54 AL_EPISODES, | |
55 AL_SCORE, | |
56 AL_AVG_SCORE, | |
57 AL_TYPE, | |
58 AL_SEASON, | |
59 AL_STARTED, | |
60 AL_COMPLETED, | |
61 AL_UPDATED, | |
62 AL_NOTES, | |
10 | 63 |
258 | 64 NB_COLUMNS |
65 }; | |
10 | 66 |
258 | 67 AnimeListPageModel(QObject* parent, Anime::ListStatus _status); |
68 ~AnimeListPageModel() override = default; | |
69 int rowCount(const QModelIndex& parent = QModelIndex()) const override; | |
70 int columnCount(const QModelIndex& parent = QModelIndex()) const override; | |
71 QVariant data(const QModelIndex& index, int role) const override; | |
72 QVariant headerData(const int section, const Qt::Orientation orientation, const int role) const override; | |
73 void RefreshList(); | |
74 Anime::Anime* GetAnimeFromIndex(QModelIndex index); | |
10 | 75 |
258 | 76 private: |
77 Anime::ListStatus status; | |
78 std::vector<Anime::Anime> list; | |
10 | 79 }; |
80 | |
95
8043152ef9d4
include: set classes as final where appropriate
Paper <mrpapersonic@gmail.com>
parents:
85
diff
changeset
|
81 class AnimeListPage final : public QWidget { |
258 | 82 Q_OBJECT |
10 | 83 |
258 | 84 public: |
291 | 85 AnimeListPage(QWidget* parent = nullptr); |
307
8769c5d50b06
pages/anime_list: don't call GUI functions in a non-GUI thread
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
86 |
8769c5d50b06
pages/anime_list: don't call GUI functions in a non-GUI thread
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
87 public slots: |
258 | 88 void Refresh(); |
10 | 89 |
258 | 90 protected: |
91 void paintEvent(QPaintEvent*) override; | |
92 void InitStyle(QStyleOptionTabWidgetFrame* option) const; | |
93 void InitBasicStyle(QStyleOptionTabWidgetFrame* option) const; | |
94 void SetupLayout(); | |
95 void showEvent(QShowEvent*) override; | |
96 void resizeEvent(QResizeEvent* e) override; | |
97 void RefreshList(); | |
98 void RefreshTabs(); | |
99 void UpdateAnime(int id); | |
100 void RemoveAnime(int id); | |
10 | 101 |
258 | 102 private slots: |
103 void DisplayColumnHeaderMenu(); | |
104 void DisplayListMenu(); | |
105 void ItemDoubleClicked(); | |
106 void SetColumnDefaults(); | |
107 int VisibleColumnsCount() const; | |
10 | 108 |
258 | 109 private: |
110 QTabBar* tab_bar; | |
111 QTreeView* tree_view; | |
112 QRect panelRect; | |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
113 |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
114 AnimeListPageUpdateEntryThread update_entry_thread_; |
258 | 115 std::array<AnimeListPageSortFilter*, 5> sort_models; |
10 | 116 }; |
85 | 117 |
261
3ec7804abf17
include: make header guards more sane
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
118 #endif // MINORI_GUI_PAGES_ANIME_LIST_H_ |