Mercurial > minori
comparison src/gui/pages/seasons.cc @ 348:6b0768158dcd
text: redesign almost every widget
i.e. Paragraph is now a QLabel, etc etc, some things will probably
break, idc
| author | Paper <paper@paper.us.eu.org> |
|---|---|
| date | Tue, 25 Jun 2024 11:19:54 -0400 |
| parents | b5d6c27c308f |
| children | 83e6ba09338f |
comparison
equal
deleted
inserted
replaced
| 347:a0aa8c8c4307 | 348:6b0768158dcd |
|---|---|
| 13 #include <QMenu> | 13 #include <QMenu> |
| 14 #include <QToolBar> | 14 #include <QToolBar> |
| 15 #include <QToolButton> | 15 #include <QToolButton> |
| 16 #include <QVBoxLayout> | 16 #include <QVBoxLayout> |
| 17 | 17 |
| 18 #include <iostream> | |
| 19 | |
| 18 SeasonsPageSearchThread::SeasonsPageSearchThread(QObject* parent) : QThread(parent) { | 20 SeasonsPageSearchThread::SeasonsPageSearchThread(QObject* parent) : QThread(parent) { |
| 19 } | 21 } |
| 20 | 22 |
| 21 void SeasonsPageSearchThread::AddToQueue(Anime::Season season) { | 23 void SeasonsPageSearchThread::AddToQueue(Anime::Season season) { |
| 22 queue_mutex_.lock(); | 24 queue_mutex_.lock(); |
| 54 } | 56 } |
| 55 | 57 |
| 56 void SeasonsPage::Refresh() { | 58 void SeasonsPage::Refresh() { |
| 57 setUpdatesEnabled(false); | 59 setUpdatesEnabled(false); |
| 58 | 60 |
| 59 if (!buttons || !season_button) | 61 if (!buttons) |
| 60 return; | 62 return; |
| 61 | 63 |
| 62 buttons->clear(); | 64 buttons->clear(); |
| 63 | 65 |
| 64 for (const auto& id : Anime::db.GetAllAnimeForSeason(season_)) { | 66 for (const auto& id : Anime::db.GetAllAnimeForSeason(season_)) { |
| 68 item->setSizeHint(button->sizeHint()); | 70 item->setSizeHint(button->sizeHint()); |
| 69 buttons->addItem(item); | 71 buttons->addItem(item); |
| 70 buttons->setItemWidget(item, button); | 72 buttons->setItemWidget(item, button); |
| 71 } | 73 } |
| 72 | 74 |
| 73 season_button->setText(Strings::ToQString(Translate::ToLocalString(season_))); | 75 season_button.setText(Strings::ToQString(Translate::ToLocalString(season_))); |
| 74 | 76 |
| 75 setUpdatesEnabled(true); | 77 setUpdatesEnabled(true); |
| 76 } | 78 } |
| 77 | 79 |
| 78 void SeasonsPage::SetSeason(Anime::Season season) { | 80 void SeasonsPage::SetSeason(Anime::Season season) { |
| 94 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); | 96 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); |
| 95 toolbar->setIconSize(QSize(16, 16)); | 97 toolbar->setIconSize(QSize(16, 16)); |
| 96 toolbar->setMovable(false); | 98 toolbar->setMovable(false); |
| 97 | 99 |
| 98 { | 100 { |
| 99 /* currently this is VERY hardcoded to en_US */ | 101 /* XXX this last year probably shouldn't be hardcoded */ |
| 100 static constexpr Date::Year last_year = 1960; | 102 static const Anime::Season last_season(Anime::Season::Name::Winter, 1960); |
| 101 | 103 Anime::Season current_season(Date(QDate::currentDate())); |
| 102 auto create_year_menu = [this](QWidget* parent, QMenu* parent_menu, Date::Year year){ | 104 const Date::Year year_before_collapse = GetClosestDecade(current_season.year) - 10; |
| 103 const QString year_s = QString::number(year); | 105 |
| 104 | 106 /* year -> menu for that year */ |
| 105 QMenu* menu = new QMenu(year_s, parent); | 107 std::map<Date::Year, QMenu*> menu_map; |
| 106 for (const auto& season : Anime::Season::Names) { | 108 |
| 107 QAction* action = menu->addAction(Strings::ToQString(Translate::ToLocalString(Anime::Season(season, year)))); | 109 auto create_season_menu = [&](QWidget* parent, Anime::Season season){ |
| 108 connect(action, &QAction::triggered, this, [this, season, year] { | 110 QMenu*& menu = menu_map[season.year]; |
| 109 SetSeason({season, year}); | 111 if (!menu) |
| 110 }); | 112 menu = new QMenu(QString::number(season.year), parent); |
| 111 } | 113 |
| 112 parent_menu->addMenu(menu); | 114 QAction* action = menu->addAction(Strings::ToQString(Translate::ToLocalString(season))); |
| 115 connect(action, &QAction::triggered, this, [this, season] { | |
| 116 SetSeason(season); | |
| 117 }); | |
| 113 }; | 118 }; |
| 114 | 119 |
| 115 auto create_decade_menu = [create_year_menu](QWidget* parent, QMenu* parent_menu, Date::Year decade) { | 120 for (Anime::Season s = current_season; s >= last_season; --s) |
| 116 QMenu* menu = new QMenu(QString::number(decade) + "s", parent); | 121 create_season_menu(&season_button, s); |
| 117 for (int i = 9; i >= 0; i--) | 122 |
| 118 create_year_menu(parent, menu, decade + i); | 123 /* ------------------------------------------------------- */ |
| 119 parent_menu->addMenu(menu); | 124 /* now actually generate the full menu */ |
| 120 }; | 125 |
| 121 | 126 QMenu* full_menu = new QMenu(&season_button); |
| 122 /* we'll be extinct by the time this code breaks, so I guess it's fine :) */ | 127 |
| 123 const Date::Year current_year = static_cast<Date::Year>(QDate::currentDate().year()); | 128 for (Date::Year c = current_season.year; c >= year_before_collapse; c--) |
| 124 const Date::Year year_before_collapse = GetClosestDecade(current_year) - 10; | 129 full_menu->addMenu(menu_map[c]); |
| 125 season_button = new QToolButton(toolbar); | 130 |
| 126 QMenu* full_season_menu = new QMenu(season_button); | 131 full_menu->addSeparator(); |
| 127 | 132 |
| 128 for (Date::Year c = current_year; c >= year_before_collapse; c--) | 133 /* collapse each menu into a decade */ |
| 129 create_year_menu(season_button, full_season_menu, c); | 134 for (Date::Year c = year_before_collapse - 10; c >= last_season.year; c -= 10) { |
| 130 | 135 QMenu* decade_menu = new QMenu(tr("%1s").arg(QString::number(c)), parent); |
| 131 full_season_menu->addSeparator(); | 136 for (Date::Year i = c + 9; i >= c; i--) |
| 132 | 137 decade_menu->addMenu(menu_map[i]); |
| 133 for (Date::Year c = year_before_collapse - 10; c >= last_year; c -= 10) | 138 full_menu->addMenu(decade_menu); |
| 134 create_decade_menu(season_button, full_season_menu, c); | 139 } |
| 135 | 140 |
| 136 season_button->setMenu(full_season_menu); | 141 season_button.setMenu(full_menu); |
| 137 season_button->setPopupMode(QToolButton::InstantPopup); | 142 season_button.setPopupMode(QToolButton::InstantPopup); |
| 138 | 143 |
| 139 toolbar->addWidget(season_button); | 144 toolbar->addWidget(&season_button); |
| 140 } | 145 } |
| 141 | 146 |
| 142 toolbar->addSeparator(); | 147 toolbar->addSeparator(); |
| 143 | 148 |
| 144 { | 149 { |
