comparison src/gui/pages/anime_list.cc @ 114:ab191e28e69d

*: add initial torrent stuff WOAH! these checkboxes are a pain in my fucking ass
author Paper <mrpapersonic@gmail.com>
date Tue, 07 Nov 2023 08:03:42 -0500
parents 80f49f623d30
children 39521c47c7a3
comparison
equal deleted inserted replaced
113:32afe0e940bf 114:ab191e28e69d
45 case QMetaType::QString: 45 case QMetaType::QString:
46 default: return QString::compare(left.toString(), right.toString(), Qt::CaseInsensitive) < 0; 46 default: return QString::compare(left.toString(), right.toString(), Qt::CaseInsensitive) < 0;
47 } 47 }
48 } 48 }
49 49
50 AnimeListPageModel::AnimeListPageModel(QWidget* parent, Anime::ListStatus _status) : QAbstractListModel(parent) { 50 /* -------------------------------------------------- */
51
52 AnimeListPageModel::AnimeListPageModel(QObject* parent, Anime::ListStatus _status) : QAbstractListModel(parent) {
51 status = _status; 53 status = _status;
52 return; 54 return;
53 } 55 }
54 56
55 int AnimeListPageModel::rowCount(const QModelIndex& parent) const { 57 int AnimeListPageModel::rowCount(const QModelIndex& parent) const {
178 } 180 }
179 181
180 endResetModel(); 182 endResetModel();
181 } 183 }
182 184
185 /* ----------------------------------------------------------------- */
186
183 int AnimeListPage::VisibleColumnsCount() const { 187 int AnimeListPage::VisibleColumnsCount() const {
184 int count = 0; 188 int count = 0;
185 189
186 for (int i = 0, end = tree_view->header()->count(); i < end; i++) { 190 for (int i = 0, end = tree_view->header()->count(); i < end; i++) {
187 if (!tree_view->isColumnHidden(i)) 191 if (!tree_view->isColumnHidden(i))
314 dialog->show(); 318 dialog->show();
315 dialog->raise(); 319 dialog->raise();
316 dialog->activateWindow(); 320 dialog->activateWindow();
317 } 321 }
318 322
323 void AnimeListPage::RefreshList() {
324 for (unsigned int i = 0; i < sort_models.size(); i++)
325 reinterpret_cast<AnimeListPageModel*>(sort_models[i]->sourceModel())->RefreshList();
326 }
327
328 void AnimeListPage::RefreshTabs() {
329 for (unsigned int i = 0; i < sort_models.size(); i++)
330 tab_bar->setTabText(i, Strings::ToQString(Translate::ToString(Anime::ListStatuses[i])) + " (" +
331 QString::number(Anime::db.GetListsAnimeAmount(Anime::ListStatuses[i])) + ")");
332 }
333
334 void AnimeListPage::Refresh() {
335 RefreshList();
336 RefreshTabs();
337 }
338
339 /* -------- QTabWidget replication begin --------- */
340
341 void AnimeListPage::InitBasicStyle(QStyleOptionTabWidgetFrame* option) const {
342 if (!option)
343 return;
344
345 option->initFrom(this);
346 option->lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, this);
347 option->shape = QTabBar::RoundedNorth;
348 option->tabBarRect = tab_bar->geometry();
349 }
350
351 void AnimeListPage::InitStyle(QStyleOptionTabWidgetFrame* option) const {
352 if (!option)
353 return;
354
355 InitBasicStyle(option);
356
357 QSize t(0, tree_view->frameWidth());
358 if (tab_bar->isVisibleTo(this)) {
359 t = tab_bar->sizeHint();
360 t.setWidth(width());
361 }
362
363 option->tabBarSize = t;
364
365 QRect selected_tab_rect = tab_bar->tabRect(tab_bar->currentIndex());
366 selected_tab_rect.moveTopLeft(selected_tab_rect.topLeft() + option->tabBarRect.topLeft());
367 option->selectedTabRect = selected_tab_rect;
368
369 option->lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, this);
370 }
371
372 void AnimeListPage::SetupLayout() {
373 QStyleOptionTabWidgetFrame option;
374 InitStyle(&option);
375
376 QRect tabRect = style()->subElementRect(QStyle::SE_TabWidgetTabBar, &option, this);
377 tabRect.setLeft(tabRect.left() + 1);
378 panelRect = style()->subElementRect(QStyle::SE_TabWidgetTabPane, &option, this);
379 QRect contentsRect = style()->subElementRect(QStyle::SE_TabWidgetTabContents, &option, this);
380
381 tab_bar->setGeometry(tabRect);
382 tree_view->parentWidget()->setGeometry(contentsRect);
383 }
384
319 void AnimeListPage::paintEvent(QPaintEvent*) { 385 void AnimeListPage::paintEvent(QPaintEvent*) {
320 QStylePainter p(this); 386 QStylePainter p(this);
321 387
322 QStyleOptionTabWidgetFrame opt; 388 QStyleOptionTabWidgetFrame opt;
323 InitStyle(&opt); 389 InitStyle(&opt);
332 398
333 void AnimeListPage::showEvent(QShowEvent*) { 399 void AnimeListPage::showEvent(QShowEvent*) {
334 SetupLayout(); 400 SetupLayout();
335 } 401 }
336 402
337 void AnimeListPage::InitBasicStyle(QStyleOptionTabWidgetFrame* option) const { 403 /* --------- QTabWidget replication end ---------- */
338 if (!option)
339 return;
340
341 option->initFrom(this);
342 option->lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, this);
343 option->shape = QTabBar::RoundedNorth;
344 option->tabBarRect = tab_bar->geometry();
345 }
346
347 void AnimeListPage::InitStyle(QStyleOptionTabWidgetFrame* option) const {
348 if (!option)
349 return;
350
351 InitBasicStyle(option);
352
353 QSize t(0, tree_view->frameWidth());
354 if (tab_bar->isVisibleTo(this)) {
355 t = tab_bar->sizeHint();
356 t.setWidth(width());
357 }
358
359 option->tabBarSize = t;
360
361 QRect selected_tab_rect = tab_bar->tabRect(tab_bar->currentIndex());
362 selected_tab_rect.moveTopLeft(selected_tab_rect.topLeft() + option->tabBarRect.topLeft());
363 option->selectedTabRect = selected_tab_rect;
364
365 option->lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, this);
366 }
367
368 void AnimeListPage::SetupLayout() {
369 QStyleOptionTabWidgetFrame option;
370 InitStyle(&option);
371
372 QRect tabRect = style()->subElementRect(QStyle::SE_TabWidgetTabBar, &option, this);
373 tabRect.setLeft(tabRect.left() + 1);
374 panelRect = style()->subElementRect(QStyle::SE_TabWidgetTabPane, &option, this);
375 QRect contentsRect = style()->subElementRect(QStyle::SE_TabWidgetTabContents, &option, this);
376
377 tab_bar->setGeometry(tabRect);
378 tree_view->parentWidget()->setGeometry(contentsRect);
379 }
380 404
381 AnimeListPage::AnimeListPage(QWidget* parent) : QWidget(parent) { 405 AnimeListPage::AnimeListPage(QWidget* parent) : QWidget(parent) {
382 /* Tab bar */ 406 /* Tab bar */
383 tab_bar = new QTabBar(this); 407 tab_bar = new QTabBar(this);
384 tab_bar->setExpanding(false); 408 tab_bar->setExpanding(false);
436 setFocusProxy(tab_bar); 460 setFocusProxy(tab_bar);
437 461
438 Refresh(); 462 Refresh();
439 } 463 }
440 464
441 void AnimeListPage::RefreshList() {
442 for (unsigned int i = 0; i < sort_models.size(); i++)
443 reinterpret_cast<AnimeListPageModel*>(sort_models[i]->sourceModel())->RefreshList();
444 }
445
446 void AnimeListPage::RefreshTabs() {
447 for (unsigned int i = 0; i < sort_models.size(); i++)
448 tab_bar->setTabText(i, Strings::ToQString(Translate::ToString(Anime::ListStatuses[i])) + " (" +
449 QString::number(Anime::db.GetListsAnimeAmount(Anime::ListStatuses[i])) + ")");
450 }
451
452 void AnimeListPage::Refresh() {
453 RefreshList();
454 RefreshTabs();
455 }
456
457 /* This function, really, really should not be called.
458 Ever. Why would you ever need to clear the anime list?
459 Also, this sucks. */
460 void AnimeListPage::Reset() {
461 while (tab_bar->count())
462 tab_bar->removeTab(0);
463 for (unsigned int i = 0; i < sort_models.size(); i++)
464 delete sort_models[i];
465 }
466
467 #include "gui/pages/moc_anime_list.cpp" 465 #include "gui/pages/moc_anime_list.cpp"