Mercurial > minori
diff src/gui/pages/anime_list.cpp @ 64:fe719c109dbc
*: update
1. add media tracking ability, and it displays info on the `now playing` page
2. the `now playing` page now actually shows something
3. renamed every page class to be more accurate to what it is
4. ...
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sun, 01 Oct 2023 23:15:43 -0400 |
parents | 3d2decf093bb |
children | 26721c28bf22 |
line wrap: on
line diff
--- a/src/gui/pages/anime_list.cpp Sun Oct 01 06:39:47 2023 -0400 +++ b/src/gui/pages/anime_list.cpp Sun Oct 01 23:15:43 2023 -0400 @@ -27,22 +27,22 @@ #include <QStyledItemDelegate> #include <cmath> -AnimeListWidgetDelegate::AnimeListWidgetDelegate(QObject* parent) : QStyledItemDelegate(parent) { +AnimeListPageDelegate::AnimeListPageDelegate(QObject* parent) : QStyledItemDelegate(parent) { } -QWidget* AnimeListWidgetDelegate::createEditor(QWidget*, const QStyleOptionViewItem&, const QModelIndex&) const { +QWidget* AnimeListPageDelegate::createEditor(QWidget*, const QStyleOptionViewItem&, const QModelIndex&) const { // no edit 4 u return nullptr; } -void AnimeListWidgetDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, - const QModelIndex& index) const { +void AnimeListPageDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, + const QModelIndex& index) const { switch (index.column()) { #if 0 - case AnimeListWidgetModel::AL_PROGRESS: { + case AnimeListPageModel::AL_PROGRESS: { const int progress = static_cast<int>(index.data(Qt::UserRole).toReal()); const int episodes = - static_cast<int>(index.siblingAtColumn(AnimeListWidgetModel::AL_EPISODES).data(Qt::UserRole).toReal()); + static_cast<int>(index.siblingAtColumn(AnimeListPageModel::AL_EPISODES).data(Qt::UserRole).toReal()); int text_width = 59; QRectF text_rect(option.rect.x() + text_width, option.rect.y(), text_width, option.decorationSize.height()); @@ -63,10 +63,10 @@ } } -AnimeListWidgetSortFilter::AnimeListWidgetSortFilter(QObject* parent) : QSortFilterProxyModel(parent) { +AnimeListPageSortFilter::AnimeListPageSortFilter(QObject* parent) : QSortFilterProxyModel(parent) { } -bool AnimeListWidgetSortFilter::lessThan(const QModelIndex& l, const QModelIndex& r) const { +bool AnimeListPageSortFilter::lessThan(const QModelIndex& l, const QModelIndex& r) const { QVariant left = sourceModel()->data(l, sortRole()); QVariant right = sourceModel()->data(r, sortRole()); @@ -81,22 +81,22 @@ } } -AnimeListWidgetModel::AnimeListWidgetModel(QWidget* parent, Anime::ListStatus _status) : QAbstractListModel(parent) { +AnimeListPageModel::AnimeListPageModel(QWidget* parent, Anime::ListStatus _status) : QAbstractListModel(parent) { status = _status; return; } -int AnimeListWidgetModel::rowCount(const QModelIndex& parent) const { +int AnimeListPageModel::rowCount(const QModelIndex& parent) const { return list.size(); (void)(parent); } -int AnimeListWidgetModel::columnCount(const QModelIndex& parent) const { +int AnimeListPageModel::columnCount(const QModelIndex& parent) const { return NB_COLUMNS; (void)(parent); } -QVariant AnimeListWidgetModel::headerData(const int section, const Qt::Orientation orientation, const int role) const { +QVariant AnimeListPageModel::headerData(const int section, const Qt::Orientation orientation, const int role) const { if (role == Qt::DisplayRole) { switch (section) { case AL_TITLE: return tr("Anime title"); @@ -131,7 +131,7 @@ return QAbstractListModel::headerData(section, orientation, role); } -QVariant AnimeListWidgetModel::data(const QModelIndex& index, int role) const { +QVariant AnimeListPageModel::data(const QModelIndex& index, int role) const { if (!index.isValid()) return QVariant(); switch (role) { @@ -190,7 +190,7 @@ return QVariant(); } -void AnimeListWidgetModel::UpdateAnime(int id) { +void AnimeListPageModel::UpdateAnime(int id) { /* meh... it might be better to just reinit the entire list */ int i = 0; for (const auto& a : Anime::db.items) { @@ -201,11 +201,11 @@ } } -Anime::Anime* AnimeListWidgetModel::GetAnimeFromIndex(QModelIndex index) { +Anime::Anime* AnimeListPageModel::GetAnimeFromIndex(QModelIndex index) { return &list.at(index.row()); } -void AnimeListWidgetModel::RefreshList() { +void AnimeListPageModel::RefreshList() { bool has_children = !!rowCount(index(0)); if (has_children) beginResetModel(); @@ -231,7 +231,7 @@ endInsertRows(); } -int AnimeListWidget::VisibleColumnsCount() const { +int AnimeListPage::VisibleColumnsCount() const { int count = 0; for (int i = 0, end = tree_view->header()->count(); i < end; i++) { @@ -242,29 +242,29 @@ return count; } -void AnimeListWidget::SetColumnDefaults() { - tree_view->setColumnHidden(AnimeListWidgetModel::AL_SEASON, false); - tree_view->setColumnHidden(AnimeListWidgetModel::AL_TYPE, false); - tree_view->setColumnHidden(AnimeListWidgetModel::AL_UPDATED, false); - tree_view->setColumnHidden(AnimeListWidgetModel::AL_PROGRESS, false); - tree_view->setColumnHidden(AnimeListWidgetModel::AL_SCORE, false); - tree_view->setColumnHidden(AnimeListWidgetModel::AL_TITLE, false); - tree_view->setColumnHidden(AnimeListWidgetModel::AL_EPISODES, true); - tree_view->setColumnHidden(AnimeListWidgetModel::AL_AVG_SCORE, true); - tree_view->setColumnHidden(AnimeListWidgetModel::AL_STARTED, true); - tree_view->setColumnHidden(AnimeListWidgetModel::AL_COMPLETED, true); - tree_view->setColumnHidden(AnimeListWidgetModel::AL_UPDATED, true); - tree_view->setColumnHidden(AnimeListWidgetModel::AL_NOTES, true); +void AnimeListPage::SetColumnDefaults() { + tree_view->setColumnHidden(AnimeListPageModel::AL_SEASON, false); + tree_view->setColumnHidden(AnimeListPageModel::AL_TYPE, false); + tree_view->setColumnHidden(AnimeListPageModel::AL_UPDATED, false); + tree_view->setColumnHidden(AnimeListPageModel::AL_PROGRESS, false); + tree_view->setColumnHidden(AnimeListPageModel::AL_SCORE, false); + tree_view->setColumnHidden(AnimeListPageModel::AL_TITLE, false); + tree_view->setColumnHidden(AnimeListPageModel::AL_EPISODES, true); + tree_view->setColumnHidden(AnimeListPageModel::AL_AVG_SCORE, true); + tree_view->setColumnHidden(AnimeListPageModel::AL_STARTED, true); + tree_view->setColumnHidden(AnimeListPageModel::AL_COMPLETED, true); + tree_view->setColumnHidden(AnimeListPageModel::AL_UPDATED, true); + tree_view->setColumnHidden(AnimeListPageModel::AL_NOTES, true); } -void AnimeListWidget::DisplayColumnHeaderMenu() { +void AnimeListPage::DisplayColumnHeaderMenu() { QMenu* menu = new QMenu(this); menu->setAttribute(Qt::WA_DeleteOnClose); menu->setTitle(tr("Column visibility")); menu->setToolTipsVisible(true); - for (int i = 0; i < AnimeListWidgetModel::NB_COLUMNS; i++) { - if (i == AnimeListWidgetModel::AL_TITLE) + for (int i = 0; i < AnimeListPageModel::NB_COLUMNS; i++) { + if (i == AnimeListPageModel::AL_TITLE) continue; const auto column_name = sort_models[tab_bar->currentIndex()]->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString(); @@ -294,7 +294,7 @@ (void)(resetAction); } -void AnimeListWidget::DisplayListMenu() { +void AnimeListPage::DisplayListMenu() { QMenu* menu = new QMenu(this); menu->setAttribute(Qt::WA_DeleteOnClose); menu->setTitle(tr("Column visibility")); @@ -307,10 +307,10 @@ } QAction* action = menu->addAction(tr("Information"), [this, selection] { - const QModelIndex index = ((AnimeListWidgetModel*)sort_models[tab_bar->currentIndex()]->sourceModel()) - ->index(selection.indexes().first().row()); - Anime::Anime* anime = - ((AnimeListWidgetModel*)sort_models[tab_bar->currentIndex()]->sourceModel())->GetAnimeFromIndex(index); + AnimeListPageModel* source_model = + reinterpret_cast<AnimeListPageModel*>(sort_models[tab_bar->currentIndex()]->sourceModel()); + const QModelIndex index = source_model->index(selection.indexes().first().row()); + Anime::Anime* anime = source_model->GetAnimeFromIndex(index); if (!anime) { return; } @@ -330,7 +330,7 @@ menu->popup(QCursor::pos()); } -void AnimeListWidget::ItemDoubleClicked() { +void AnimeListPage::ItemDoubleClicked() { /* throw out any other garbage */ const QItemSelection selection = sort_models[tab_bar->currentIndex()]->mapSelectionToSource(tree_view->selectionModel()->selection()); @@ -338,10 +338,11 @@ return; } - const QModelIndex index = ((AnimeListWidgetModel*)sort_models[tab_bar->currentIndex()]->sourceModel()) - ->index(selection.indexes().first().row()); - Anime::Anime* anime = - ((AnimeListWidgetModel*)sort_models[tab_bar->currentIndex()]->sourceModel())->GetAnimeFromIndex(index); + AnimeListPageModel* source_model = + reinterpret_cast<AnimeListPageModel*>(sort_models[tab_bar->currentIndex()]->sourceModel()); + + const QModelIndex index = source_model->index(selection.indexes().first().row()); + Anime::Anime* anime = source_model->GetAnimeFromIndex(index); InformationDialog* dialog = new InformationDialog( *anime, @@ -356,7 +357,7 @@ dialog->activateWindow(); } -void AnimeListWidget::paintEvent(QPaintEvent*) { +void AnimeListPage::paintEvent(QPaintEvent*) { QStylePainter p(this); QStyleOptionTabWidgetFrame opt; @@ -365,16 +366,16 @@ p.drawPrimitive(QStyle::PE_FrameTabWidget, opt); } -void AnimeListWidget::resizeEvent(QResizeEvent* e) { +void AnimeListPage::resizeEvent(QResizeEvent* e) { QWidget::resizeEvent(e); SetupLayout(); } -void AnimeListWidget::showEvent(QShowEvent*) { +void AnimeListPage::showEvent(QShowEvent*) { SetupLayout(); } -void AnimeListWidget::InitBasicStyle(QStyleOptionTabWidgetFrame* option) const { +void AnimeListPage::InitBasicStyle(QStyleOptionTabWidgetFrame* option) const { if (!option) return; @@ -384,7 +385,7 @@ option->tabBarRect = tab_bar->geometry(); } -void AnimeListWidget::InitStyle(QStyleOptionTabWidgetFrame* option) const { +void AnimeListPage::InitStyle(QStyleOptionTabWidgetFrame* option) const { if (!option) return; @@ -406,7 +407,7 @@ option->lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, this); } -void AnimeListWidget::SetupLayout() { +void AnimeListPage::SetupLayout() { QStyleOptionTabWidgetFrame option; InitStyle(&option); @@ -419,7 +420,7 @@ tree_view->parentWidget()->setGeometry(contentsRect); } -AnimeListWidget::AnimeListWidget(QWidget* parent) : QWidget(parent) { +AnimeListPage::AnimeListPage(QWidget* parent) : QWidget(parent) { /* Tab bar */ tab_bar = new QTabBar(this); tab_bar->setExpanding(false); @@ -428,7 +429,7 @@ /* Tree view... */ QWidget* tree_widget = new QWidget(this); tree_view = new QTreeView(tree_widget); - tree_view->setItemDelegate(new AnimeListWidgetDelegate(tree_view)); + tree_view->setItemDelegate(new AnimeListPageDelegate(tree_view)); tree_view->setUniformRowHeights(true); tree_view->setAllColumnsShowFocus(false); tree_view->setAlternatingRowColors(true); @@ -442,8 +443,8 @@ for (unsigned int i = 0; i < ARRAYSIZE(sort_models); i++) { tab_bar->addTab(QString::fromStdString(Translate::ToString(Anime::ListStatuses[i])) + " (" + QString::number(Anime::db.GetListsAnimeAmount(Anime::ListStatuses[i])) + ")"); - sort_models[i] = new AnimeListWidgetSortFilter(tree_view); - sort_models[i]->setSourceModel(new AnimeListWidgetModel(this, Anime::ListStatuses[i])); + sort_models[i] = new AnimeListPageSortFilter(tree_view); + sort_models[i]->setSourceModel(new AnimeListPageModel(this, Anime::ListStatuses[i])); sort_models[i]->setSortRole(Qt::UserRole); sort_models[i]->setSortCaseSensitivity(Qt::CaseInsensitive); } @@ -455,19 +456,19 @@ tree_widget->setLayout(layout); /* Double click stuff */ - connect(tree_view, &QAbstractItemView::doubleClicked, this, &AnimeListWidget::ItemDoubleClicked); - connect(tree_view, &QWidget::customContextMenuRequested, this, &AnimeListWidget::DisplayListMenu); + connect(tree_view, &QAbstractItemView::doubleClicked, this, &AnimeListPage::ItemDoubleClicked); + connect(tree_view, &QWidget::customContextMenuRequested, this, &AnimeListPage::DisplayListMenu); /* Enter & return keys */ connect(new QShortcut(Qt::Key_Return, tree_view, nullptr, nullptr, Qt::WidgetShortcut), &QShortcut::activated, this, - &AnimeListWidget::ItemDoubleClicked); + &AnimeListPage::ItemDoubleClicked); connect(new QShortcut(Qt::Key_Enter, tree_view, nullptr, nullptr, Qt::WidgetShortcut), &QShortcut::activated, this, - &AnimeListWidget::ItemDoubleClicked); + &AnimeListPage::ItemDoubleClicked); tree_view->header()->setStretchLastSection(false); tree_view->header()->setContextMenuPolicy(Qt::CustomContextMenu); - connect(tree_view->header(), &QWidget::customContextMenuRequested, this, &AnimeListWidget::DisplayColumnHeaderMenu); + connect(tree_view->header(), &QWidget::customContextMenuRequested, this, &AnimeListPage::DisplayColumnHeaderMenu); connect(tab_bar, &QTabBar::currentChanged, this, [this](int index) { if (sort_models[index]) @@ -478,18 +479,18 @@ setFocusProxy(tab_bar); } -void AnimeListWidget::RefreshList() { +void AnimeListPage::RefreshList() { for (unsigned int i = 0; i < ARRAYSIZE(sort_models); i++) - ((AnimeListWidgetModel*)sort_models[i]->sourceModel())->RefreshList(); + reinterpret_cast<AnimeListPageModel*>(sort_models[i]->sourceModel())->RefreshList(); } -void AnimeListWidget::RefreshTabs() { +void AnimeListPage::RefreshTabs() { for (unsigned int i = 0; i < ARRAYSIZE(sort_models); i++) tab_bar->setTabText(i, QString::fromStdString(Translate::ToString(Anime::ListStatuses[i])) + " (" + QString::number(Anime::db.GetListsAnimeAmount(Anime::ListStatuses[i])) + ")"); } -void AnimeListWidget::Refresh() { +void AnimeListPage::Refresh() { RefreshList(); RefreshTabs(); } @@ -497,7 +498,7 @@ /* This function, really, really should not be called. Ever. Why would you ever need to clear the anime list? Also, this sucks. */ -void AnimeListWidget::Reset() { +void AnimeListPage::Reset() { while (tab_bar->count()) tab_bar->removeTab(0); for (unsigned int i = 0; i < ARRAYSIZE(sort_models); i++)