Mercurial > minori
annotate src/gui/pages/seasons.cc @ 305:91ac90a34003
core/time: remove Duration class, use regular functions instead
this class was pretty useless anyway
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Sun, 19 May 2024 15:56:20 -0400 |
parents | 2115488eb302 |
children | 78929794e7d8 |
rev | line source |
---|---|
54
466ac9870df9
add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
1 #include "gui/pages/seasons.h" |
466ac9870df9
add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
2 |
253 | 3 #include "core/anime_db.h" |
260
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
4 #include "core/anime_season_db.h" |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
5 #include "core/strings.h" |
253 | 6 #include "gui/widgets/anime_button.h" |
260
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
7 #include "gui/translate/anime.h" |
304
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
8 #include "services/services.h" |
253 | 9 |
260
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
10 #include <QDate> |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
11 #include <QFrame> |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
12 #include <QListWidget> |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
13 #include <QListWidgetItem> |
255 | 14 #include <QMenu> |
258 | 15 #include <QToolBar> |
255 | 16 #include <QToolButton> |
258 | 17 #include <QVBoxLayout> |
253 | 18 |
260
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
19 static constexpr Date::Year GetClosestDecade(Date::Year year) { |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
20 return year - (year % 10); |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
21 } |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
22 |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
23 void SeasonsPage::SetSeason(Anime::SeriesSeason season, Date::Year year) { |
263
96416310ea14
pages/seasons: finish season menu implementation
Paper <paper@paper.us.eu.org>
parents:
260
diff
changeset
|
24 if (!buttons || !season_button) |
96416310ea14
pages/seasons: finish season menu implementation
Paper <paper@paper.us.eu.org>
parents:
260
diff
changeset
|
25 return; |
96416310ea14
pages/seasons: finish season menu implementation
Paper <paper@paper.us.eu.org>
parents:
260
diff
changeset
|
26 |
260
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
27 buttons->clear(); |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
28 |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
29 for (const auto& id : Anime::Season::GetAllAnimeForSeason(season, year)) { |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
30 QListWidgetItem* item = new QListWidgetItem; |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
31 AnimeButton* button = new AnimeButton(this); |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
32 button->SetAnime(Anime::db.items[id]); |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
33 item->setSizeHint(button->sizeHint()); |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
34 buttons->addItem(item); |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
35 buttons->setItemWidget(item, button); |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
36 } |
263
96416310ea14
pages/seasons: finish season menu implementation
Paper <paper@paper.us.eu.org>
parents:
260
diff
changeset
|
37 |
96416310ea14
pages/seasons: finish season menu implementation
Paper <paper@paper.us.eu.org>
parents:
260
diff
changeset
|
38 season_button->setText(Strings::ToQString(Translate::ToLocalString(season)) + " " + QString::number(year)); |
260
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
39 } |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
40 |
295 | 41 SeasonsPage::SeasonsPage(QWidget* parent) : QFrame(parent) { |
42 setBackgroundRole(QPalette::Base); | |
43 setFrameShape(QFrame::Box); | |
44 setFrameShadow(QFrame::Sunken); | |
45 | |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
46 QVBoxLayout* full_layout = new QVBoxLayout(this); |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
47 |
253 | 48 { |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
49 /* Toolbar */ |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
50 QToolBar* toolbar = new QToolBar(this); |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
51 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
52 toolbar->setIconSize(QSize(16, 16)); |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
53 toolbar->setMovable(false); |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
54 |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
55 { |
291 | 56 /* todo: clean this up... this sucks... */ |
260
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
57 static constexpr Date::Year last_year = 1960; |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
58 |
263
96416310ea14
pages/seasons: finish season menu implementation
Paper <paper@paper.us.eu.org>
parents:
260
diff
changeset
|
59 auto create_year_menu = [this](QWidget* parent, QMenu* parent_menu, Date::Year year){ |
260
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
60 const QString year_s = QString::number(year); |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
61 |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
62 QMenu* menu = new QMenu(year_s, parent); |
263
96416310ea14
pages/seasons: finish season menu implementation
Paper <paper@paper.us.eu.org>
parents:
260
diff
changeset
|
63 for (const auto& season : Anime::SeriesSeasons) { |
96416310ea14
pages/seasons: finish season menu implementation
Paper <paper@paper.us.eu.org>
parents:
260
diff
changeset
|
64 QAction* action = menu->addAction(Strings::ToQString(Translate::ToLocalString(season)) + " " + year_s); |
96416310ea14
pages/seasons: finish season menu implementation
Paper <paper@paper.us.eu.org>
parents:
260
diff
changeset
|
65 connect(action, &QAction::triggered, this, [this, season, year]{ |
96416310ea14
pages/seasons: finish season menu implementation
Paper <paper@paper.us.eu.org>
parents:
260
diff
changeset
|
66 SetSeason(season, year); |
96416310ea14
pages/seasons: finish season menu implementation
Paper <paper@paper.us.eu.org>
parents:
260
diff
changeset
|
67 }); |
96416310ea14
pages/seasons: finish season menu implementation
Paper <paper@paper.us.eu.org>
parents:
260
diff
changeset
|
68 } |
260
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
69 parent_menu->addMenu(menu); |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
70 }; |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
71 |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
72 auto create_decade_menu = [create_year_menu](QWidget* parent, QMenu* parent_menu, Date::Year decade) { |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
73 QMenu* menu = new QMenu(QString::number(decade) + "s", parent); |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
74 for (int i = 9; i >= 0; i--) |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
75 create_year_menu(parent, menu, decade + i); |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
76 parent_menu->addMenu(menu); |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
77 }; |
255 | 78 |
260
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
79 /* we'll be extinct by the time this code breaks, so I guess it's fine :) */ |
291 | 80 const Date::Year current_year = static_cast<Date::Year>(QDate::currentDate().year()); |
81 const Date::Year year_before_collapse = GetClosestDecade(current_year) - 10; | |
263
96416310ea14
pages/seasons: finish season menu implementation
Paper <paper@paper.us.eu.org>
parents:
260
diff
changeset
|
82 season_button = new QToolButton(toolbar); |
260
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
83 QMenu* full_season_menu = new QMenu(season_button); |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
84 |
291 | 85 for (Date::Year c = current_year; c >= year_before_collapse; c--) |
260
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
86 create_year_menu(season_button, full_season_menu, c); |
255 | 87 |
260
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
88 full_season_menu->addSeparator(); |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
89 |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
90 for (Date::Year c = year_before_collapse - 10; c >= last_year; c -= 10) |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
91 create_decade_menu(season_button, full_season_menu, c); |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
92 |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
93 season_button->setMenu(full_season_menu); |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
94 season_button->setPopupMode(QToolButton::InstantPopup); |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
95 |
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
96 toolbar->addWidget(season_button); |
255 | 97 } |
98 | |
99 toolbar->addSeparator(); | |
100 | |
304
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
101 { |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
102 toolbar->addAction(QIcon(":/icons/16x16/arrow-circle-315.png"), tr("Refresh data"), [this]{ |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
103 Services::GetSeason(Anime::SeriesSeason::Summer, 2011U); |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
104 SetSeason(Anime::SeriesSeason::Summer, 2011U); |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
105 }); |
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
106 } |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
107 |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
108 toolbar->addSeparator(); |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
109 |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
110 { |
255 | 111 QToolButton* button = new QToolButton(toolbar); |
112 | |
113 { | |
114 /* links */ | |
115 QMenu* menu = new QMenu(button); | |
291 | 116 menu->addAction(tr("Airing status")); |
117 menu->addAction(tr("List status")); | |
118 menu->addAction(tr("Type")); | |
255 | 119 button->setMenu(menu); |
120 } | |
121 | |
122 button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); | |
123 button->setIcon(QIcon(":/icons/16x16/category.png")); | |
291 | 124 button->setText(tr("Group by:")); |
255 | 125 button->setPopupMode(QToolButton::InstantPopup); |
126 toolbar->addWidget(button); | |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
127 } |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
128 |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
129 { |
255 | 130 QToolButton* button = new QToolButton(toolbar); |
131 | |
132 { | |
133 /* links */ | |
134 QMenu* menu = new QMenu(button); | |
291 | 135 menu->addAction(tr("Airing date")); |
136 menu->addAction(tr("Episodes")); | |
137 menu->addAction(tr("Popularity")); | |
138 menu->addAction(tr("Score")); | |
139 menu->addAction(tr("Title")); | |
255 | 140 button->setMenu(menu); |
141 } | |
142 | |
143 button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); | |
144 button->setIcon(QIcon(":/icons/16x16/sort-quantity-descending.png")); | |
291 | 145 button->setText(tr("Sort by:")); |
255 | 146 button->setPopupMode(QToolButton::InstantPopup); |
147 toolbar->addWidget(button); | |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
148 } |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
149 |
255 | 150 { |
151 QToolButton* button = new QToolButton(toolbar); | |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
152 |
255 | 153 { |
154 /* links */ | |
155 QMenu* menu = new QMenu(button); | |
291 | 156 menu->addAction(tr("Images")); |
157 menu->addAction(tr("Details")); | |
255 | 158 button->setMenu(menu); |
159 } | |
160 | |
161 button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); | |
162 button->setIcon(QIcon(":/icons/16x16/ui-scroll-pane-detail.png")); | |
291 | 163 button->setText(tr("View:")); |
255 | 164 button->setPopupMode(QToolButton::InstantPopup); |
165 toolbar->addWidget(button); | |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
166 } |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
167 |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
168 full_layout->addWidget(toolbar); |
253 | 169 } |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
170 |
253 | 171 { |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
172 QFrame* line = new QFrame(this); |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
173 line->setFrameShape(QFrame::HLine); |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
174 line->setFrameShadow(QFrame::Sunken); |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
175 line->setLineWidth(1); |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
176 full_layout->addWidget(line); |
253 | 177 } |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
178 |
253 | 179 { |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
180 buttons = new QListWidget(this); |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
181 buttons->setFlow(QListView::LeftToRight); |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
182 buttons->setWrapping(true); |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
183 buttons->setContentsMargins(4, 4, 4, 4); |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
184 buttons->setSpacing(2); |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
185 buttons->setResizeMode(QListView::Adjust); |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
186 |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
187 full_layout->addWidget(buttons); |
253 | 188 } |
260
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
189 |
295 | 190 full_layout->setContentsMargins(0, 0, 0, 0); |
191 full_layout->setSpacing(0); | |
192 | |
260
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
193 /* Do NOT move this up in this function, buttons HAS to be initialized */ |
304
2115488eb302
*: add very early season searcher
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
194 SetSeason(Anime::SeriesSeason::Summer, 2011U); |
54
466ac9870df9
add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
195 } |