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