# HG changeset patch # User Paper # Date 1712191600 14400 # Node ID 96416310ea14b2dbfab138b5ce358f689636afc4 # Parent 8e282d0dc282dcb62e679ad7327ab108499d9a98 pages/seasons: finish season menu implementation diff -r 8e282d0dc282 -r 96416310ea14 include/gui/pages/seasons.h --- a/include/gui/pages/seasons.h Wed Apr 03 20:26:03 2024 -0400 +++ b/include/gui/pages/seasons.h Wed Apr 03 20:46:40 2024 -0400 @@ -7,7 +7,7 @@ #include "core/date.h" class QListWidget; -class QResizeEvent; +class QToolButton; class SeasonsPage final : public QWidget { Q_OBJECT @@ -18,6 +18,7 @@ protected: QListWidget* buttons = nullptr; + QToolButton* season_button = nullptr; }; #endif // MINORI_GUI_PAGES_SEASONS_H_ diff -r 8e282d0dc282 -r 96416310ea14 src/gui/pages/seasons.cc --- a/src/gui/pages/seasons.cc Wed Apr 03 20:26:03 2024 -0400 +++ b/src/gui/pages/seasons.cc Wed Apr 03 20:46:40 2024 -0400 @@ -20,6 +20,9 @@ } void SeasonsPage::SetSeason(Anime::SeriesSeason season, Date::Year year) { + if (!buttons || !season_button) + return; + buttons->clear(); for (const auto& id : Anime::Season::GetAllAnimeForSeason(season, year)) { @@ -30,6 +33,8 @@ buttons->addItem(item); buttons->setItemWidget(item, button); } + + season_button->setText(Strings::ToQString(Translate::ToLocalString(season)) + " " + QString::number(year)); } SeasonsPage::SeasonsPage(QWidget* parent) : QWidget(parent) { @@ -46,12 +51,16 @@ /* hard-coded this value */ static constexpr Date::Year last_year = 1960; - auto create_year_menu = [](QWidget* parent, QMenu* parent_menu, Date::Year year){ + auto create_year_menu = [this](QWidget* parent, QMenu* parent_menu, Date::Year year){ const QString year_s = QString::number(year); QMenu* menu = new QMenu(year_s, parent); - for (const auto& season : Anime::SeriesSeasons) - menu->addAction(Strings::ToQString(Translate::ToLocalString(season)) + " " + year_s); + for (const auto& season : Anime::SeriesSeasons) { + QAction* action = menu->addAction(Strings::ToQString(Translate::ToLocalString(season)) + " " + year_s); + connect(action, &QAction::triggered, this, [this, season, year]{ + SetSeason(season, year); + }); + } parent_menu->addMenu(menu); }; @@ -65,7 +74,7 @@ /* we'll be extinct by the time this code breaks, so I guess it's fine :) */ const Date::Year year = static_cast(QDate::currentDate().year()); const Date::Year year_before_collapse = GetClosestDecade(year) - 10; - QToolButton* season_button = new QToolButton(toolbar); + season_button = new QToolButton(toolbar); QMenu* full_season_menu = new QMenu(season_button); for (Date::Year c = year; c >= year_before_collapse; c--) @@ -77,7 +86,6 @@ create_decade_menu(season_button, full_season_menu, c); season_button->setMenu(full_season_menu); - season_button->setText("Summer 2011"); season_button->setPopupMode(QToolButton::InstantPopup); toolbar->addWidget(season_button);