Mercurial > minori
comparison src/gui/pages/seasons.cc @ 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 | dd211ff68b36 |
children | 657fda1b9cac |
comparison
equal
deleted
inserted
replaced
262:8e282d0dc282 | 263:96416310ea14 |
---|---|
18 static constexpr Date::Year GetClosestDecade(Date::Year year) { | 18 static constexpr Date::Year GetClosestDecade(Date::Year year) { |
19 return year - (year % 10); | 19 return year - (year % 10); |
20 } | 20 } |
21 | 21 |
22 void SeasonsPage::SetSeason(Anime::SeriesSeason season, Date::Year year) { | 22 void SeasonsPage::SetSeason(Anime::SeriesSeason season, Date::Year year) { |
23 if (!buttons || !season_button) | |
24 return; | |
25 | |
23 buttons->clear(); | 26 buttons->clear(); |
24 | 27 |
25 for (const auto& id : Anime::Season::GetAllAnimeForSeason(season, year)) { | 28 for (const auto& id : Anime::Season::GetAllAnimeForSeason(season, year)) { |
26 QListWidgetItem* item = new QListWidgetItem; | 29 QListWidgetItem* item = new QListWidgetItem; |
27 AnimeButton* button = new AnimeButton(this); | 30 AnimeButton* button = new AnimeButton(this); |
28 button->SetAnime(Anime::db.items[id]); | 31 button->SetAnime(Anime::db.items[id]); |
29 item->setSizeHint(button->sizeHint()); | 32 item->setSizeHint(button->sizeHint()); |
30 buttons->addItem(item); | 33 buttons->addItem(item); |
31 buttons->setItemWidget(item, button); | 34 buttons->setItemWidget(item, button); |
32 } | 35 } |
36 | |
37 season_button->setText(Strings::ToQString(Translate::ToLocalString(season)) + " " + QString::number(year)); | |
33 } | 38 } |
34 | 39 |
35 SeasonsPage::SeasonsPage(QWidget* parent) : QWidget(parent) { | 40 SeasonsPage::SeasonsPage(QWidget* parent) : QWidget(parent) { |
36 QVBoxLayout* full_layout = new QVBoxLayout(this); | 41 QVBoxLayout* full_layout = new QVBoxLayout(this); |
37 | 42 |
44 | 49 |
45 { | 50 { |
46 /* hard-coded this value */ | 51 /* hard-coded this value */ |
47 static constexpr Date::Year last_year = 1960; | 52 static constexpr Date::Year last_year = 1960; |
48 | 53 |
49 auto create_year_menu = [](QWidget* parent, QMenu* parent_menu, Date::Year year){ | 54 auto create_year_menu = [this](QWidget* parent, QMenu* parent_menu, Date::Year year){ |
50 const QString year_s = QString::number(year); | 55 const QString year_s = QString::number(year); |
51 | 56 |
52 QMenu* menu = new QMenu(year_s, parent); | 57 QMenu* menu = new QMenu(year_s, parent); |
53 for (const auto& season : Anime::SeriesSeasons) | 58 for (const auto& season : Anime::SeriesSeasons) { |
54 menu->addAction(Strings::ToQString(Translate::ToLocalString(season)) + " " + year_s); | 59 QAction* action = menu->addAction(Strings::ToQString(Translate::ToLocalString(season)) + " " + year_s); |
60 connect(action, &QAction::triggered, this, [this, season, year]{ | |
61 SetSeason(season, year); | |
62 }); | |
63 } | |
55 parent_menu->addMenu(menu); | 64 parent_menu->addMenu(menu); |
56 }; | 65 }; |
57 | 66 |
58 auto create_decade_menu = [create_year_menu](QWidget* parent, QMenu* parent_menu, Date::Year decade) { | 67 auto create_decade_menu = [create_year_menu](QWidget* parent, QMenu* parent_menu, Date::Year decade) { |
59 QMenu* menu = new QMenu(QString::number(decade) + "s", parent); | 68 QMenu* menu = new QMenu(QString::number(decade) + "s", parent); |
63 }; | 72 }; |
64 | 73 |
65 /* we'll be extinct by the time this code breaks, so I guess it's fine :) */ | 74 /* we'll be extinct by the time this code breaks, so I guess it's fine :) */ |
66 const Date::Year year = static_cast<Date::Year>(QDate::currentDate().year()); | 75 const Date::Year year = static_cast<Date::Year>(QDate::currentDate().year()); |
67 const Date::Year year_before_collapse = GetClosestDecade(year) - 10; | 76 const Date::Year year_before_collapse = GetClosestDecade(year) - 10; |
68 QToolButton* season_button = new QToolButton(toolbar); | 77 season_button = new QToolButton(toolbar); |
69 QMenu* full_season_menu = new QMenu(season_button); | 78 QMenu* full_season_menu = new QMenu(season_button); |
70 | 79 |
71 for (Date::Year c = year; c >= year_before_collapse; c--) | 80 for (Date::Year c = year; c >= year_before_collapse; c--) |
72 create_year_menu(season_button, full_season_menu, c); | 81 create_year_menu(season_button, full_season_menu, c); |
73 | 82 |
75 | 84 |
76 for (Date::Year c = year_before_collapse - 10; c >= last_year; c -= 10) | 85 for (Date::Year c = year_before_collapse - 10; c >= last_year; c -= 10) |
77 create_decade_menu(season_button, full_season_menu, c); | 86 create_decade_menu(season_button, full_season_menu, c); |
78 | 87 |
79 season_button->setMenu(full_season_menu); | 88 season_button->setMenu(full_season_menu); |
80 season_button->setText("Summer 2011"); | |
81 season_button->setPopupMode(QToolButton::InstantPopup); | 89 season_button->setPopupMode(QToolButton::InstantPopup); |
82 | 90 |
83 toolbar->addWidget(season_button); | 91 toolbar->addWidget(season_button); |
84 } | 92 } |
85 | 93 |