changeset 263:96416310ea14

pages/seasons: finish season menu implementation
author Paper <paper@paper.us.eu.org>
date Wed, 03 Apr 2024 20:46:40 -0400
parents 8e282d0dc282
children 9a04802848c0
files include/gui/pages/seasons.h src/gui/pages/seasons.cc
diffstat 2 files changed, 15 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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_
--- 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<Date::Year>(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);