Mercurial > minori
annotate src/gui/pages/anime_list.cpp @ 38:1a34fd7469b9
ci/osx: take a different approach
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Fri, 22 Sep 2023 09:29:20 -0400 |
parents | d05b1be2f3a6 |
children | d0adc4aedfc8 |
rev | line source |
---|---|
10 | 1 /** |
2 * anime_list.cpp: defines the anime list page | |
3 * and widgets. | |
4 * | |
5 * much of this file is based around | |
6 * Qt's original QTabWidget implementation, because | |
7 * I needed a somewhat native way to create a tabbed | |
8 * widget with only one subwidget that worked exactly | |
9 * like a native tabbed widget. | |
10 **/ | |
11 #include "gui/pages/anime_list.h" | |
12 #include "core/anime.h" | |
13 #include "core/anime_db.h" | |
14 #include "core/session.h" | |
15 #include "core/time.h" | |
19
d05b1be2f3a6
anime_list.cpp: fix build failures on linux
Paper <mrpapersonic@gmail.com>
parents:
15
diff
changeset
|
16 #include "core/array.h" |
10 | 17 #include "gui/dialog/information.h" |
18 #include "gui/translate/anime.h" | |
19 #include "services/anilist.h" | |
15 | 20 #include <QDebug> |
10 | 21 #include <QHBoxLayout> |
22 #include <QHeaderView> | |
23 #include <QMenu> | |
24 #include <QProgressBar> | |
25 #include <QShortcut> | |
26 #include <QStylePainter> | |
27 #include <QStyledItemDelegate> | |
28 #include <cmath> | |
29 | |
30 AnimeListWidgetDelegate::AnimeListWidgetDelegate(QObject* parent) : QStyledItemDelegate(parent) { | |
31 } | |
32 | |
33 QWidget* AnimeListWidgetDelegate::createEditor(QWidget*, const QStyleOptionViewItem&, const QModelIndex&) const { | |
34 // no edit 4 u | |
35 return nullptr; | |
36 } | |
37 | |
38 void AnimeListWidgetDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, | |
15 | 39 const QModelIndex& index) const { |
10 | 40 switch (index.column()) { |
15 | 41 #if 0 |
10 | 42 case AnimeListWidgetModel::AL_PROGRESS: { |
43 const int progress = static_cast<int>(index.data(Qt::UserRole).toReal()); | |
44 const int episodes = | |
15 | 45 static_cast<int>(index.siblingAtColumn(AnimeListWidgetModel::AL_EPISODES).data(Qt::UserRole).toReal()); |
10 | 46 |
47 int text_width = 59; | |
48 QRectF text_rect(option.rect.x() + text_width, option.rect.y(), text_width, option.decorationSize.height()); | |
49 painter->save(); | |
50 painter->drawText(text_rect, "/", QTextOption(Qt::AlignCenter | Qt::AlignVCenter)); | |
15 | 51 // drawText(const QRectF &rectangle, const QString &text, const QTextOption &option = |
52 QTextOption()) painter->drawText(QRectF(text_rect.x(), text_rect.y(), text_width / 2 - 2, | |
53 text_rect.height()), QString::number(progress), QTextOption(Qt::AlignRight | Qt::AlignVCenter)); | |
54 painter->drawText( | |
55 QRectF(text_rect.x() + text_width / 2 + 2, text_rect.y(), text_width / 2 - 2, text_rect.height()), | |
56 QString::number(episodes), QTextOption(Qt::AlignLeft | Qt::AlignVCenter)); | |
57 painter->restore(); | |
58 QStyledItemDelegate::paint(painter, option, index); | |
59 break; | |
10 | 60 } |
15 | 61 #endif |
10 | 62 default: QStyledItemDelegate::paint(painter, option, index); break; |
63 } | |
64 } | |
65 | |
66 AnimeListWidgetSortFilter::AnimeListWidgetSortFilter(QObject* parent) : QSortFilterProxyModel(parent) { | |
67 } | |
68 | |
69 bool AnimeListWidgetSortFilter::lessThan(const QModelIndex& l, const QModelIndex& r) const { | |
70 QVariant left = sourceModel()->data(l, sortRole()); | |
71 QVariant right = sourceModel()->data(r, sortRole()); | |
72 | |
73 switch (left.userType()) { | |
74 case QMetaType::Int: | |
75 case QMetaType::UInt: | |
76 case QMetaType::LongLong: | |
77 case QMetaType::ULongLong: return left.toInt() < right.toInt(); | |
78 case QMetaType::QDate: return left.toDate() < right.toDate(); | |
79 case QMetaType::QString: | |
80 default: return QString::compare(left.toString(), right.toString(), Qt::CaseInsensitive) < 0; | |
81 } | |
82 } | |
83 | |
84 AnimeListWidgetModel::AnimeListWidgetModel(QWidget* parent, Anime::ListStatus _status) : QAbstractListModel(parent) { | |
85 status = _status; | |
86 return; | |
87 } | |
88 | |
89 int AnimeListWidgetModel::rowCount(const QModelIndex& parent) const { | |
90 return list.size(); | |
91 (void)(parent); | |
92 } | |
93 | |
94 int AnimeListWidgetModel::columnCount(const QModelIndex& parent) const { | |
95 return NB_COLUMNS; | |
96 (void)(parent); | |
97 } | |
98 | |
99 QVariant AnimeListWidgetModel::headerData(const int section, const Qt::Orientation orientation, const int role) const { | |
100 if (role == Qt::DisplayRole) { | |
101 switch (section) { | |
15 | 102 case AL_TITLE: return tr("Anime title"); |
103 case AL_PROGRESS: return tr("Progress"); | |
104 case AL_EPISODES: return tr("Episodes"); | |
105 case AL_TYPE: return tr("Type"); | |
106 case AL_SCORE: return tr("Score"); | |
107 case AL_SEASON: return tr("Season"); | |
108 case AL_STARTED: return tr("Date started"); | |
109 case AL_COMPLETED: return tr("Date completed"); | |
110 case AL_NOTES: return tr("Notes"); | |
111 case AL_AVG_SCORE: return tr("Average score"); | |
112 case AL_UPDATED: return tr("Last updated"); | |
113 default: return {}; | |
10 | 114 } |
115 } else if (role == Qt::TextAlignmentRole) { | |
116 switch (section) { | |
15 | 117 case AL_TITLE: |
118 case AL_NOTES: return QVariant(Qt::AlignLeft | Qt::AlignVCenter); | |
119 case AL_PROGRESS: | |
120 case AL_EPISODES: | |
121 case AL_TYPE: | |
122 case AL_SCORE: | |
123 case AL_AVG_SCORE: return QVariant(Qt::AlignCenter | Qt::AlignVCenter); | |
124 case AL_SEASON: | |
125 case AL_STARTED: | |
126 case AL_COMPLETED: | |
127 case AL_UPDATED: return QVariant(Qt::AlignRight | Qt::AlignVCenter); | |
128 default: return QAbstractListModel::headerData(section, orientation, role); | |
10 | 129 } |
130 } | |
131 return QAbstractListModel::headerData(section, orientation, role); | |
132 } | |
133 | |
134 QVariant AnimeListWidgetModel::data(const QModelIndex& index, int role) const { | |
135 if (!index.isValid()) | |
136 return QVariant(); | |
137 switch (role) { | |
138 case Qt::DisplayRole: | |
15 | 139 switch (index.column()) { |
140 case AL_TITLE: return QString::fromUtf8(list[index.row()].GetUserPreferredTitle().c_str()); | |
141 case AL_PROGRESS: | |
142 return QString::number(list[index.row()].GetUserProgress()) + "/" + | |
143 QString::number(list[index.row()].GetEpisodes()); | |
144 case AL_EPISODES: return list[index.row()].GetEpisodes(); | |
145 case AL_SCORE: return list[index.row()].GetUserScore(); | |
146 case AL_TYPE: return QString::fromStdString(Translate::ToString(list[index.row()].GetFormat())); | |
147 case AL_SEASON: | |
148 return QString::fromStdString(Translate::ToString(list[index.row()].GetSeason())) + " " + | |
149 QString::number(list[index.row()].GetAirDate().GetYear()); | |
150 case AL_AVG_SCORE: return QString::number(list[index.row()].GetAudienceScore()) + "%"; | |
151 case AL_STARTED: return list[index.row()].GetUserDateStarted().GetAsQDate(); | |
152 case AL_COMPLETED: return list[index.row()].GetUserDateCompleted().GetAsQDate(); | |
153 case AL_UPDATED: { | |
154 if (list[index.row()].GetUserTimeUpdated() == 0) | |
155 return QString("-"); | |
156 Time::Duration duration(Time::GetSystemTime() - list[index.row()].GetUserTimeUpdated()); | |
157 return QString::fromUtf8(duration.AsRelativeString().c_str()); | |
158 } | |
159 case AL_NOTES: return QString::fromUtf8(list[index.row()].GetUserNotes().c_str()); | |
160 default: return ""; | |
161 } | |
162 break; | |
10 | 163 case Qt::UserRole: |
15 | 164 switch (index.column()) { |
165 case AL_PROGRESS: return list[index.row()].GetUserProgress(); | |
166 case AL_TYPE: return static_cast<int>(list[index.row()].GetFormat()); | |
167 case AL_SEASON: return list[index.row()].GetAirDate().GetAsQDate(); | |
168 case AL_AVG_SCORE: return list[index.row()].GetAudienceScore(); | |
19
d05b1be2f3a6
anime_list.cpp: fix build failures on linux
Paper <mrpapersonic@gmail.com>
parents:
15
diff
changeset
|
169 case AL_UPDATED: return QVariant::fromValue(list[index.row()].GetUserTimeUpdated()); |
15 | 170 default: return data(index, Qt::DisplayRole); |
171 } | |
172 break; | |
10 | 173 case Qt::TextAlignmentRole: |
15 | 174 switch (index.column()) { |
175 case AL_TITLE: | |
176 case AL_NOTES: return QVariant(Qt::AlignLeft | Qt::AlignVCenter); | |
177 case AL_PROGRESS: | |
178 case AL_EPISODES: | |
179 case AL_TYPE: | |
180 case AL_SCORE: | |
181 case AL_AVG_SCORE: return QVariant(Qt::AlignCenter | Qt::AlignVCenter); | |
182 case AL_SEASON: | |
183 case AL_STARTED: | |
184 case AL_COMPLETED: | |
185 case AL_UPDATED: return QVariant(Qt::AlignRight | Qt::AlignVCenter); | |
186 default: break; | |
187 } | |
188 break; | |
10 | 189 } |
190 return QVariant(); | |
191 } | |
192 | |
193 void AnimeListWidgetModel::UpdateAnime(int id) { | |
194 /* meh... it might be better to just reinit the entire list */ | |
195 int i = 0; | |
11 | 196 for (const auto& a : Anime::db.items) { |
197 if (a.second.IsInUserList() && a.first == id && a.second.GetUserStatus() == status) { | |
15 | 198 emit dataChanged(index(i), index(i)); |
10 | 199 } |
200 i++; | |
201 } | |
202 } | |
203 | |
204 Anime::Anime* AnimeListWidgetModel::GetAnimeFromIndex(QModelIndex index) { | |
205 return &list.at(index.row()); | |
206 } | |
207 | |
208 void AnimeListWidgetModel::RefreshList() { | |
209 bool has_children = !!rowCount(index(0)); | |
15 | 210 if (has_children) |
211 beginResetModel(); | |
212 else { | |
213 int count = 0; | |
214 for (const auto& a : Anime::db.items) | |
215 if (a.second.IsInUserList() && a.second.GetUserStatus() == status) | |
216 count++; | |
217 beginInsertRows(index(0), 0, count - 1); | |
218 } | |
219 | |
10 | 220 list.clear(); |
221 | |
11 | 222 for (const auto& a : Anime::db.items) { |
223 if (a.second.IsInUserList() && a.second.GetUserStatus() == status) { | |
15 | 224 list.push_back(a.second); |
10 | 225 } |
226 } | |
15 | 227 |
228 if (has_children) | |
229 endResetModel(); | |
230 else | |
231 endInsertRows(); | |
10 | 232 } |
233 | |
234 int AnimeListWidget::VisibleColumnsCount() const { | |
235 int count = 0; | |
236 | |
237 for (int i = 0, end = tree_view->header()->count(); i < end; i++) { | |
238 if (!tree_view->isColumnHidden(i)) | |
15 | 239 count++; |
10 | 240 } |
241 | |
242 return count; | |
243 } | |
244 | |
245 void AnimeListWidget::SetColumnDefaults() { | |
246 tree_view->setColumnHidden(AnimeListWidgetModel::AL_SEASON, false); | |
247 tree_view->setColumnHidden(AnimeListWidgetModel::AL_TYPE, false); | |
248 tree_view->setColumnHidden(AnimeListWidgetModel::AL_UPDATED, false); | |
249 tree_view->setColumnHidden(AnimeListWidgetModel::AL_PROGRESS, false); | |
250 tree_view->setColumnHidden(AnimeListWidgetModel::AL_SCORE, false); | |
251 tree_view->setColumnHidden(AnimeListWidgetModel::AL_TITLE, false); | |
252 tree_view->setColumnHidden(AnimeListWidgetModel::AL_EPISODES, true); | |
253 tree_view->setColumnHidden(AnimeListWidgetModel::AL_AVG_SCORE, true); | |
254 tree_view->setColumnHidden(AnimeListWidgetModel::AL_STARTED, true); | |
255 tree_view->setColumnHidden(AnimeListWidgetModel::AL_COMPLETED, true); | |
256 tree_view->setColumnHidden(AnimeListWidgetModel::AL_UPDATED, true); | |
257 tree_view->setColumnHidden(AnimeListWidgetModel::AL_NOTES, true); | |
258 } | |
259 | |
260 void AnimeListWidget::DisplayColumnHeaderMenu() { | |
261 QMenu* menu = new QMenu(this); | |
262 menu->setAttribute(Qt::WA_DeleteOnClose); | |
263 menu->setTitle(tr("Column visibility")); | |
264 menu->setToolTipsVisible(true); | |
265 | |
266 for (int i = 0; i < AnimeListWidgetModel::NB_COLUMNS; i++) { | |
15 | 267 if (i == AnimeListWidgetModel::AL_TITLE) |
268 continue; | |
10 | 269 const auto column_name = |
15 | 270 sort_models[tab_bar->currentIndex()]->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString(); |
10 | 271 QAction* action = menu->addAction(column_name, this, [this, i](const bool checked) { |
272 if (!checked && (VisibleColumnsCount() <= 1)) | |
273 return; | |
274 | |
275 tree_view->setColumnHidden(i, !checked); | |
276 | |
277 if (checked && (tree_view->columnWidth(i) <= 5)) | |
278 tree_view->resizeColumnToContents(i); | |
279 | |
280 // SaveSettings(); | |
281 }); | |
282 action->setCheckable(true); | |
283 action->setChecked(!tree_view->isColumnHidden(i)); | |
284 } | |
285 | |
286 menu->addSeparator(); | |
287 QAction* resetAction = menu->addAction(tr("Reset to defaults"), this, [this]() { | |
288 for (int i = 0, count = tree_view->header()->count(); i < count; ++i) { | |
289 SetColumnDefaults(); | |
290 } | |
291 // SaveSettings(); | |
292 }); | |
293 menu->popup(QCursor::pos()); | |
294 (void)(resetAction); | |
295 } | |
296 | |
297 void AnimeListWidget::DisplayListMenu() { | |
298 QMenu* menu = new QMenu(this); | |
299 menu->setAttribute(Qt::WA_DeleteOnClose); | |
300 menu->setTitle(tr("Column visibility")); | |
301 menu->setToolTipsVisible(true); | |
302 | |
15 | 303 const QItemSelection selection = |
304 sort_models[tab_bar->currentIndex()]->mapSelectionToSource(tree_view->selectionModel()->selection()); | |
10 | 305 if (!selection.indexes().first().isValid()) { |
306 return; | |
307 } | |
308 | |
309 QAction* action = menu->addAction("Information", [this, selection] { | |
310 const QModelIndex index = ((AnimeListWidgetModel*)sort_models[tab_bar->currentIndex()]->sourceModel()) | |
15 | 311 ->index(selection.indexes().first().row()); |
10 | 312 Anime::Anime* anime = |
15 | 313 ((AnimeListWidgetModel*)sort_models[tab_bar->currentIndex()]->sourceModel())->GetAnimeFromIndex(index); |
10 | 314 if (!anime) { |
315 return; | |
316 } | |
317 | |
318 InformationDialog* dialog = new InformationDialog( | |
15 | 319 *anime, |
320 [this, anime] { | |
321 ((AnimeListWidgetModel*)sort_models[tab_bar->currentIndex()]->sourceModel()) | |
322 ->UpdateAnime(anime->GetId()); | |
323 }, | |
324 this); | |
10 | 325 |
326 dialog->show(); | |
327 dialog->raise(); | |
328 dialog->activateWindow(); | |
329 }); | |
330 menu->popup(QCursor::pos()); | |
331 } | |
332 | |
333 void AnimeListWidget::ItemDoubleClicked() { | |
334 /* throw out any other garbage */ | |
335 const QItemSelection selection = | |
15 | 336 sort_models[tab_bar->currentIndex()]->mapSelectionToSource(tree_view->selectionModel()->selection()); |
10 | 337 if (!selection.indexes().first().isValid()) { |
338 return; | |
339 } | |
340 | |
341 const QModelIndex index = ((AnimeListWidgetModel*)sort_models[tab_bar->currentIndex()]->sourceModel()) | |
15 | 342 ->index(selection.indexes().first().row()); |
10 | 343 Anime::Anime* anime = |
15 | 344 ((AnimeListWidgetModel*)sort_models[tab_bar->currentIndex()]->sourceModel())->GetAnimeFromIndex(index); |
10 | 345 |
346 InformationDialog* dialog = new InformationDialog( | |
15 | 347 *anime, |
348 [this, anime] { | |
349 ((AnimeListWidgetModel*)sort_models[tab_bar->currentIndex()]->sourceModel())->UpdateAnime(anime->GetId()); | |
350 }, | |
351 this); | |
10 | 352 |
353 dialog->show(); | |
354 dialog->raise(); | |
355 dialog->activateWindow(); | |
356 } | |
357 | |
358 void AnimeListWidget::paintEvent(QPaintEvent*) { | |
359 QStylePainter p(this); | |
360 | |
361 QStyleOptionTabWidgetFrame opt; | |
362 InitStyle(&opt); | |
363 opt.rect = panelRect; | |
364 p.drawPrimitive(QStyle::PE_FrameTabWidget, opt); | |
365 } | |
366 | |
367 void AnimeListWidget::resizeEvent(QResizeEvent* e) { | |
368 QWidget::resizeEvent(e); | |
369 SetupLayout(); | |
370 } | |
371 | |
372 void AnimeListWidget::showEvent(QShowEvent*) { | |
373 SetupLayout(); | |
374 } | |
375 | |
376 void AnimeListWidget::InitBasicStyle(QStyleOptionTabWidgetFrame* option) const { | |
377 if (!option) | |
378 return; | |
379 | |
380 option->initFrom(this); | |
381 option->lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, this); | |
382 option->shape = QTabBar::RoundedNorth; | |
383 option->tabBarRect = tab_bar->geometry(); | |
384 } | |
385 | |
386 void AnimeListWidget::InitStyle(QStyleOptionTabWidgetFrame* option) const { | |
387 if (!option) | |
388 return; | |
389 | |
390 InitBasicStyle(option); | |
391 | |
392 // int exth = style()->pixelMetric(QStyle::PM_TabBarBaseHeight, nullptr, this); | |
393 QSize t(0, tree_view->frameWidth()); | |
394 if (tab_bar->isVisibleTo(this)) { | |
395 t = tab_bar->sizeHint(); | |
396 t.setWidth(width()); | |
397 } | |
398 option->tabBarSize = t; | |
399 | |
400 QRect selected_tab_rect = tab_bar->tabRect(tab_bar->currentIndex()); | |
401 selected_tab_rect.moveTopLeft(selected_tab_rect.topLeft() + option->tabBarRect.topLeft()); | |
402 option->selectedTabRect = selected_tab_rect; | |
403 | |
404 option->lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, this); | |
405 } | |
406 | |
407 void AnimeListWidget::SetupLayout() { | |
408 QStyleOptionTabWidgetFrame option; | |
409 InitStyle(&option); | |
410 | |
411 QRect tabRect = style()->subElementRect(QStyle::SE_TabWidgetTabBar, &option, this); | |
412 tabRect.setLeft(tabRect.left() + 1); | |
413 panelRect = style()->subElementRect(QStyle::SE_TabWidgetTabPane, &option, this); | |
414 QRect contentsRect = style()->subElementRect(QStyle::SE_TabWidgetTabContents, &option, this); | |
415 | |
416 tab_bar->setGeometry(tabRect); | |
417 tree_view->parentWidget()->setGeometry(contentsRect); | |
418 } | |
419 | |
420 AnimeListWidget::AnimeListWidget(QWidget* parent) : QWidget(parent) { | |
421 /* Tab bar */ | |
422 tab_bar = new QTabBar(this); | |
423 tab_bar->setExpanding(false); | |
424 tab_bar->setDrawBase(false); | |
425 | |
426 /* Tree view... */ | |
427 QWidget* tree_widget = new QWidget(this); | |
428 tree_view = new QTreeView(tree_widget); | |
429 tree_view->setItemDelegate(new AnimeListWidgetDelegate(tree_view)); | |
430 tree_view->setUniformRowHeights(true); | |
431 tree_view->setAllColumnsShowFocus(false); | |
432 tree_view->setAlternatingRowColors(true); | |
433 tree_view->setSortingEnabled(true); | |
434 tree_view->setSelectionMode(QAbstractItemView::ExtendedSelection); | |
435 tree_view->setItemsExpandable(false); | |
436 tree_view->setRootIsDecorated(false); | |
437 tree_view->setContextMenuPolicy(Qt::CustomContextMenu); | |
438 tree_view->setFrameShape(QFrame::NoFrame); | |
439 | |
440 for (unsigned int i = 0; i < ARRAYSIZE(sort_models); i++) { | |
15 | 441 tab_bar->addTab(QString::fromStdString(Translate::ToString(Anime::ListStatuses[i])) + " (" + |
442 QString::number(Anime::db.GetListsAnimeAmount(Anime::ListStatuses[i])) + ")"); | |
10 | 443 sort_models[i] = new AnimeListWidgetSortFilter(tree_view); |
15 | 444 sort_models[i]->setSourceModel(new AnimeListWidgetModel(this, Anime::ListStatuses[i])); |
10 | 445 sort_models[i]->setSortRole(Qt::UserRole); |
446 sort_models[i]->setSortCaseSensitivity(Qt::CaseInsensitive); | |
447 } | |
15 | 448 tree_view->setModel(sort_models[0]); |
10 | 449 |
450 QHBoxLayout* layout = new QHBoxLayout; | |
451 layout->addWidget(tree_view); | |
452 layout->setMargin(0); | |
453 tree_widget->setLayout(layout); | |
454 | |
455 /* Double click stuff */ | |
456 connect(tree_view, &QAbstractItemView::doubleClicked, this, &AnimeListWidget::ItemDoubleClicked); | |
457 connect(tree_view, &QWidget::customContextMenuRequested, this, &AnimeListWidget::DisplayListMenu); | |
458 | |
459 /* Enter & return keys */ | |
15 | 460 connect(new QShortcut(Qt::Key_Return, tree_view, nullptr, nullptr, Qt::WidgetShortcut), &QShortcut::activated, this, |
461 &AnimeListWidget::ItemDoubleClicked); | |
10 | 462 |
15 | 463 connect(new QShortcut(Qt::Key_Enter, tree_view, nullptr, nullptr, Qt::WidgetShortcut), &QShortcut::activated, this, |
464 &AnimeListWidget::ItemDoubleClicked); | |
10 | 465 |
466 tree_view->header()->setStretchLastSection(false); | |
467 tree_view->header()->setContextMenuPolicy(Qt::CustomContextMenu); | |
15 | 468 connect(tree_view->header(), &QWidget::customContextMenuRequested, this, &AnimeListWidget::DisplayColumnHeaderMenu); |
10 | 469 |
470 connect(tab_bar, &QTabBar::currentChanged, this, [this](int index) { | |
471 if (sort_models[index]) | |
472 tree_view->setModel(sort_models[index]); | |
473 }); | |
474 | |
475 setFocusPolicy(Qt::TabFocus); | |
476 setFocusProxy(tab_bar); | |
477 } | |
478 | |
479 void AnimeListWidget::RefreshList() { | |
15 | 480 for (unsigned int i = 0; i < ARRAYSIZE(sort_models); i++) |
10 | 481 ((AnimeListWidgetModel*)sort_models[i]->sourceModel())->RefreshList(); |
482 } | |
483 | |
15 | 484 void AnimeListWidget::RefreshTabs() { |
485 for (unsigned int i = 0; i < ARRAYSIZE(sort_models); i++) | |
486 tab_bar->setTabText(i, QString::fromStdString(Translate::ToString(Anime::ListStatuses[i])) + " (" + | |
487 QString::number(Anime::db.GetListsAnimeAmount(Anime::ListStatuses[i])) + ")"); | |
488 } | |
489 | |
490 void AnimeListWidget::Refresh() { | |
491 RefreshList(); | |
492 RefreshTabs(); | |
493 } | |
494 | |
495 /* This function, really, really should not be called. | |
496 Ever. Why would you ever need to clear the anime list? | |
497 Also, this sucks. */ | |
10 | 498 void AnimeListWidget::Reset() { |
499 while (tab_bar->count()) | |
500 tab_bar->removeTab(0); | |
501 for (unsigned int i = 0; i < ARRAYSIZE(sort_models); i++) | |
502 delete sort_models[i]; | |
503 } | |
504 | |
505 #include "gui/pages/moc_anime_list.cpp" |