view include/gui/pages/anime_list.h @ 258:862d0d8619f6

*: HUUUGE changes animia has been renamed to animone, so instead of thinking of a health condition, you think of a beautiful flower :) I've also edited some of the code for animone, but I have no idea if it even works or not because I don't have a mac or windows machine lying around. whoops! ... anyway, all of the changes divergent from Anisthesia are now licensed under BSD. it's possible that I could even rewrite most of the code to where I don't even have to keep the MIT license, but that's thinking too far into the future I've been slacking off on implementing the anime seasons page, mostly out of laziness. I think I'd have to create another db file specifically for the seasons anyway, this code is being pushed *primarily* because the hard drive it's on is failing! yay :)
author Paper <paper@paper.us.eu.org>
date Mon, 01 Apr 2024 02:43:44 -0400
parents ab191e28e69d
children 3ec7804abf17
line wrap: on
line source

#ifndef __gui__pages__anime_list_h
#define __gui__pages__anime_list_h

#include "core/anime.h"
#include <QAbstractListModel>
#include <QSortFilterProxyModel>
#include <QStyledItemDelegate>
#include <QWidget>
#include <vector>

class QTreeView;
class QTabBar;

class AnimeListPageSortFilter final : public QSortFilterProxyModel {
	Q_OBJECT

public:
	AnimeListPageSortFilter(QObject* parent = nullptr);

protected:
	bool lessThan(const QModelIndex& l, const QModelIndex& r) const override;
};

class AnimeListPageModel final : 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,

		NB_COLUMNS
	};

	AnimeListPageModel(QObject* parent, Anime::ListStatus _status);
	~AnimeListPageModel() 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 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 AnimeListPage final : public QWidget {
	Q_OBJECT

public:
	AnimeListPage(QWidget* parent);
	void Refresh();

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;
	void RefreshList();
	void RefreshTabs();
	void UpdateAnime(int id);
	void RemoveAnime(int id);

private slots:
	void DisplayColumnHeaderMenu();
	void DisplayListMenu();
	void ItemDoubleClicked();
	void SetColumnDefaults();
	int VisibleColumnsCount() const;

private:
	QTabBar* tab_bar;
	QTreeView* tree_view;
	QRect panelRect;
	std::array<AnimeListPageSortFilter*, 5> sort_models;
};

#endif // __gui__pages__anime_list_h