Mercurial > minori
comparison src/gui/pages/seasons.cc @ 260:dd211ff68b36
pages/seasons: add initial functionality
the menu doesn't work yet, but it's a good start
| author | Paper <paper@paper.us.eu.org> |
|---|---|
| date | Wed, 03 Apr 2024 19:48:38 -0400 |
| parents | 862d0d8619f6 |
| children | 96416310ea14 |
comparison
equal
deleted
inserted
replaced
| 259:0362f3c4534c | 260:dd211ff68b36 |
|---|---|
| 1 #include "gui/pages/seasons.h" | 1 #include "gui/pages/seasons.h" |
| 2 | 2 |
| 3 #include "core/anime_db.h" | 3 #include "core/anime_db.h" |
| 4 #include "core/anime_season_db.h" | |
| 5 #include "core/strings.h" | |
| 4 #include "gui/widgets/anime_button.h" | 6 #include "gui/widgets/anime_button.h" |
| 7 #include "gui/translate/anime.h" | |
| 5 | 8 |
| 9 #include <QDate> | |
| 6 #include <QFrame> | 10 #include <QFrame> |
| 7 #include <QListWidget> | 11 #include <QListWidget> |
| 8 #include <QListWidgetItem> | 12 #include <QListWidgetItem> |
| 9 #include <QMenu> | 13 #include <QMenu> |
| 10 #include <QToolBar> | 14 #include <QToolBar> |
| 11 #include <QToolButton> | 15 #include <QToolButton> |
| 12 #include <QVBoxLayout> | 16 #include <QVBoxLayout> |
| 17 | |
| 18 static constexpr Date::Year GetClosestDecade(Date::Year year) { | |
| 19 return year - (year % 10); | |
| 20 } | |
| 21 | |
| 22 void SeasonsPage::SetSeason(Anime::SeriesSeason season, Date::Year year) { | |
| 23 buttons->clear(); | |
| 24 | |
| 25 for (const auto& id : Anime::Season::GetAllAnimeForSeason(season, year)) { | |
| 26 QListWidgetItem* item = new QListWidgetItem; | |
| 27 AnimeButton* button = new AnimeButton(this); | |
| 28 button->SetAnime(Anime::db.items[id]); | |
| 29 item->setSizeHint(button->sizeHint()); | |
| 30 buttons->addItem(item); | |
| 31 buttons->setItemWidget(item, button); | |
| 32 } | |
| 33 } | |
| 13 | 34 |
| 14 SeasonsPage::SeasonsPage(QWidget* parent) : QWidget(parent) { | 35 SeasonsPage::SeasonsPage(QWidget* parent) : QWidget(parent) { |
| 15 QVBoxLayout* full_layout = new QVBoxLayout(this); | 36 QVBoxLayout* full_layout = new QVBoxLayout(this); |
| 16 | 37 |
| 17 { | 38 { |
| 20 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); | 41 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); |
| 21 toolbar->setIconSize(QSize(16, 16)); | 42 toolbar->setIconSize(QSize(16, 16)); |
| 22 toolbar->setMovable(false); | 43 toolbar->setMovable(false); |
| 23 | 44 |
| 24 { | 45 { |
| 25 { | 46 /* hard-coded this value */ |
| 26 QAction* action = new QAction(toolbar); | 47 static constexpr Date::Year last_year = 1960; |
| 27 action->setIcon(QIcon(":/icons/16x16/calendar-previous.png")); | |
| 28 action->setToolTip(tr("Previous season")); | |
| 29 toolbar->addAction(action); | |
| 30 } | |
| 31 | 48 |
| 32 { | 49 auto create_year_menu = [](QWidget* parent, QMenu* parent_menu, Date::Year year){ |
| 33 QAction* action = new QAction(toolbar); | 50 const QString year_s = QString::number(year); |
| 34 action->setIcon(QIcon(":/icons/16x16/calendar-next.png")); | |
| 35 action->setToolTip(tr("Next season")); | |
| 36 toolbar->addAction(action); | |
| 37 } | |
| 38 | 51 |
| 39 toolbar->addAction(QIcon(":/icons/16x16/calendar.png"), | 52 QMenu* menu = new QMenu(year_s, parent); |
| 40 "Fall 2024"); // this must be named the name of the season | 53 for (const auto& season : Anime::SeriesSeasons) |
| 54 menu->addAction(Strings::ToQString(Translate::ToLocalString(season)) + " " + year_s); | |
| 55 parent_menu->addMenu(menu); | |
| 56 }; | |
| 57 | |
| 58 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); | |
| 60 for (int i = 9; i >= 0; i--) | |
| 61 create_year_menu(parent, menu, decade + i); | |
| 62 parent_menu->addMenu(menu); | |
| 63 }; | |
| 64 | |
| 65 /* 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()); | |
| 67 const Date::Year year_before_collapse = GetClosestDecade(year) - 10; | |
| 68 QToolButton* season_button = new QToolButton(toolbar); | |
| 69 QMenu* full_season_menu = new QMenu(season_button); | |
| 70 | |
| 71 for (Date::Year c = year; c >= year_before_collapse; c--) | |
| 72 create_year_menu(season_button, full_season_menu, c); | |
| 73 | |
| 74 full_season_menu->addSeparator(); | |
| 75 | |
| 76 for (Date::Year c = year_before_collapse - 10; c >= last_year; c -= 10) | |
| 77 create_decade_menu(season_button, full_season_menu, c); | |
| 78 | |
| 79 season_button->setMenu(full_season_menu); | |
| 80 season_button->setText("Summer 2011"); | |
| 81 season_button->setPopupMode(QToolButton::InstantPopup); | |
| 82 | |
| 83 toolbar->addWidget(season_button); | |
| 41 } | 84 } |
| 42 | 85 |
| 43 toolbar->addSeparator(); | 86 toolbar->addSeparator(); |
| 44 | 87 |
| 45 { toolbar->addAction(QIcon(":/icons/16x16/arrow-circle-315.png"), tr("Refresh data")); } | 88 { toolbar->addAction(QIcon(":/icons/16x16/arrow-circle-315.png"), tr("Refresh data")); } |
| 121 buttons->setWrapping(true); | 164 buttons->setWrapping(true); |
| 122 buttons->setContentsMargins(4, 4, 4, 4); | 165 buttons->setContentsMargins(4, 4, 4, 4); |
| 123 buttons->setSpacing(2); | 166 buttons->setSpacing(2); |
| 124 buttons->setResizeMode(QListView::Adjust); | 167 buttons->setResizeMode(QListView::Adjust); |
| 125 | 168 |
| 126 { | |
| 127 QListWidgetItem* item = new QListWidgetItem; | |
| 128 AnimeButton* button = new AnimeButton(this); | |
| 129 button->SetAnime(Anime::db.items[Anime::db.GetAnimeFromTitle("Another")]); | |
| 130 item->setSizeHint(button->sizeHint()); | |
| 131 buttons->addItem(item); | |
| 132 buttons->setItemWidget(item, button); | |
| 133 } | |
| 134 { | |
| 135 QListWidgetItem* item = new QListWidgetItem; | |
| 136 AnimeButton* button = new AnimeButton(this); | |
| 137 button->SetAnime(Anime::db.items[Anime::db.GetAnimeFromTitle("Another")]); | |
| 138 item->setSizeHint(button->sizeHint()); | |
| 139 buttons->addItem(item); | |
| 140 buttons->setItemWidget(item, button); | |
| 141 } | |
| 142 { | |
| 143 QListWidgetItem* item = new QListWidgetItem; | |
| 144 AnimeButton* button = new AnimeButton(this); | |
| 145 button->SetAnime(Anime::db.items[Anime::db.GetAnimeFromTitle("Another")]); | |
| 146 item->setSizeHint(button->sizeHint()); | |
| 147 buttons->addItem(item); | |
| 148 buttons->setItemWidget(item, button); | |
| 149 } | |
| 150 { | |
| 151 QListWidgetItem* item = new QListWidgetItem; | |
| 152 AnimeButton* button = new AnimeButton(this); | |
| 153 button->SetAnime(Anime::db.items[Anime::db.GetAnimeFromTitle("Another")]); | |
| 154 item->setSizeHint(button->sizeHint()); | |
| 155 buttons->addItem(item); | |
| 156 buttons->setItemWidget(item, button); | |
| 157 } | |
| 158 | |
| 159 full_layout->addWidget(buttons); | 169 full_layout->addWidget(buttons); |
| 160 } | 170 } |
| 171 | |
| 172 /* Do NOT move this up in this function, buttons HAS to be initialized */ | |
| 173 SetSeason(Anime::SeriesSeason::SUMMER, 2011); | |
| 161 } | 174 } |
