Mercurial > minori
diff include/gui/pages/anime_list.h @ 10:4b198a111713
Update
things actually compile now btw
qttest wants to fuck over the model but that might be my fault so /shrug
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sat, 16 Sep 2023 02:06:01 -0400 |
parents | 5c0397762b53 |
children | cde8f67a7c7d |
line wrap: on
line diff
--- a/include/gui/pages/anime_list.h Sun Sep 10 03:59:16 2023 -0400 +++ b/include/gui/pages/anime_list.h Sat Sep 16 02:06:01 2023 -0400 @@ -1,92 +1,98 @@ -#ifndef __gui__pages__anime_list_h -#define __gui__pages__anime_list_h -#include "core/anime.h" -#include <QAbstractListModel> -#include <QSortFilterProxyModel> -#include <QStyledItemDelegate> -#include <QTreeView> -#include <QWidget> -#include <vector> - -class AnimeListWidgetDelegate : public QStyledItemDelegate { - Q_OBJECT - - public: - explicit AnimeListWidgetDelegate(QObject* parent); - - QWidget* createEditor(QWidget*, const QStyleOptionViewItem&, const QModelIndex&) const override; - void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override; -}; - -class AnimeListWidgetSortFilter : public QSortFilterProxyModel { - Q_OBJECT - - public: - AnimeListWidgetSortFilter(QObject* parent = nullptr); - - protected: - bool lessThan(const QModelIndex& l, const QModelIndex& r) const override; -}; - -class AnimeListWidgetModel : public QAbstractListModel { - Q_OBJECT - - public: - enum columns { - AL_TITLE, - AL_PROGRESS, - AL_EPISODES, - AL_SCORE, - AL_AVG_SCORE, - AL_TYPE, - AL_SEASON, - AL_STARTED, - AL_COMPLETED, - AL_UPDATED, - AL_NOTES, - AL_ID, /* Note: This is only used in Qt::UserRole to make my life easier */ - - NB_COLUMNS - }; - - AnimeListWidgetModel(QWidget* parent); - ~AnimeListWidgetModel() override = default; - int rowCount(const QModelIndex& parent = QModelIndex()) const override; - int columnCount(const QModelIndex& parent = QModelIndex()) const override; - QVariant data(const QModelIndex& index, int role) const override; - QVariant headerData(const int section, const Qt::Orientation orientation, const int role) const override; - void UpdateAnime(int id); -}; - -/* todo: rename these to "page" or something more - sensible than "widget" */ -class AnimeListWidget : public QWidget { - Q_OBJECT - - public: - AnimeListWidget(QWidget* parent); - void UpdateAnimeList(); - void Reset(); - - protected: - void paintEvent(QPaintEvent*) override; - void InitStyle(QStyleOptionTabWidgetFrame* option) const; - void InitBasicStyle(QStyleOptionTabWidgetFrame* option) const; - void SetupLayout(); - void showEvent(QShowEvent*) override; - void resizeEvent(QResizeEvent* e) override; - - private slots: - void DisplayColumnHeaderMenu(); - void DisplayListMenu(); - void ItemDoubleClicked(); - void SetColumnDefaults(); - int VisibleColumnsCount() const; - - private: - QTabBar* tab_bar; - QTreeView* tree_view; - QRect panelRect; - AnimeListWidgetSortFilter* sort_models[5]; -}; +#ifndef __gui__pages__anime_list_h +#define __gui__pages__anime_list_h +#include "core/anime.h" +#include <QAbstractListModel> +#include <QSortFilterProxyModel> +#include <QStyledItemDelegate> +#include <QTreeView> +#include <QWidget> +#include <vector> + +class AnimeListWidgetDelegate : public QStyledItemDelegate { + Q_OBJECT + + public: + explicit AnimeListWidgetDelegate(QObject* parent); + + QWidget* createEditor(QWidget*, const QStyleOptionViewItem&, const QModelIndex&) const override; + void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override; +}; + +class AnimeListWidgetSortFilter : public QSortFilterProxyModel { + Q_OBJECT + + public: + AnimeListWidgetSortFilter(QObject* parent = nullptr); + + protected: + bool lessThan(const QModelIndex& l, const QModelIndex& r) const override; +}; + +class AnimeListWidgetModel : public QAbstractListModel { + Q_OBJECT + + public: + enum columns { + AL_TITLE, + AL_PROGRESS, + AL_EPISODES, + AL_SCORE, + AL_AVG_SCORE, + AL_TYPE, + AL_SEASON, + AL_STARTED, + AL_COMPLETED, + AL_UPDATED, + AL_NOTES, + AL_ID, /* Note: This is only used in Qt::UserRole to make my life easier */ + + NB_COLUMNS + }; + + AnimeListWidgetModel(QWidget* parent, Anime::ListStatus _status); + ~AnimeListWidgetModel() override = default; + int rowCount(const QModelIndex& parent = QModelIndex()) const override; + int columnCount(const QModelIndex& parent = QModelIndex()) const override; + QVariant data(const QModelIndex& index, int role) const override; + QVariant headerData(const int section, const Qt::Orientation orientation, const int role) const override; + void UpdateAnime(int id); + void RefreshList(); + Anime::Anime* GetAnimeFromIndex(QModelIndex index); + + private: + Anime::ListStatus status; + std::vector<Anime::Anime> list; +}; + +/* todo: rename these to "page" or something more + sensible than "widget" */ +class AnimeListWidget : public QWidget { + Q_OBJECT + + public: + AnimeListWidget(QWidget* parent); + void RefreshList(); + void Reset(); + + protected: + void paintEvent(QPaintEvent*) override; + void InitStyle(QStyleOptionTabWidgetFrame* option) const; + void InitBasicStyle(QStyleOptionTabWidgetFrame* option) const; + void SetupLayout(); + void showEvent(QShowEvent*) override; + void resizeEvent(QResizeEvent* e) override; + + private slots: + void DisplayColumnHeaderMenu(); + void DisplayListMenu(); + void ItemDoubleClicked(); + void SetColumnDefaults(); + int VisibleColumnsCount() const; + + private: + QTabBar* tab_bar; + QTreeView* tree_view; + QRect panelRect; + AnimeListWidgetSortFilter* sort_models[5]; +}; #endif // __gui__pages__anime_list_h \ No newline at end of file