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