Mercurial > minori
comparison src/gui/pages/anime_list.cpp @ 64:fe719c109dbc
*: update
1. add media tracking ability, and it displays info on the `now playing` page
2. the `now playing` page now actually shows something
3. renamed every page class to be more accurate to what it is
4. ...
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sun, 01 Oct 2023 23:15:43 -0400 |
parents | 3d2decf093bb |
children | 26721c28bf22 |
comparison
equal
deleted
inserted
replaced
63:3d2decf093bb | 64:fe719c109dbc |
---|---|
25 #include <QShortcut> | 25 #include <QShortcut> |
26 #include <QStylePainter> | 26 #include <QStylePainter> |
27 #include <QStyledItemDelegate> | 27 #include <QStyledItemDelegate> |
28 #include <cmath> | 28 #include <cmath> |
29 | 29 |
30 AnimeListWidgetDelegate::AnimeListWidgetDelegate(QObject* parent) : QStyledItemDelegate(parent) { | 30 AnimeListPageDelegate::AnimeListPageDelegate(QObject* parent) : QStyledItemDelegate(parent) { |
31 } | 31 } |
32 | 32 |
33 QWidget* AnimeListWidgetDelegate::createEditor(QWidget*, const QStyleOptionViewItem&, const QModelIndex&) const { | 33 QWidget* AnimeListPageDelegate::createEditor(QWidget*, const QStyleOptionViewItem&, const QModelIndex&) const { |
34 // no edit 4 u | 34 // no edit 4 u |
35 return nullptr; | 35 return nullptr; |
36 } | 36 } |
37 | 37 |
38 void AnimeListWidgetDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, | 38 void AnimeListPageDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, |
39 const QModelIndex& index) const { | 39 const QModelIndex& index) const { |
40 switch (index.column()) { | 40 switch (index.column()) { |
41 #if 0 | 41 #if 0 |
42 case AnimeListWidgetModel::AL_PROGRESS: { | 42 case AnimeListPageModel::AL_PROGRESS: { |
43 const int progress = static_cast<int>(index.data(Qt::UserRole).toReal()); | 43 const int progress = static_cast<int>(index.data(Qt::UserRole).toReal()); |
44 const int episodes = | 44 const int episodes = |
45 static_cast<int>(index.siblingAtColumn(AnimeListWidgetModel::AL_EPISODES).data(Qt::UserRole).toReal()); | 45 static_cast<int>(index.siblingAtColumn(AnimeListPageModel::AL_EPISODES).data(Qt::UserRole).toReal()); |
46 | 46 |
47 int text_width = 59; | 47 int text_width = 59; |
48 QRectF text_rect(option.rect.x() + text_width, option.rect.y(), text_width, option.decorationSize.height()); | 48 QRectF text_rect(option.rect.x() + text_width, option.rect.y(), text_width, option.decorationSize.height()); |
49 painter->save(); | 49 painter->save(); |
50 painter->drawText(text_rect, tr("/"), QTextOption(Qt::AlignCenter | Qt::AlignVCenter)); | 50 painter->drawText(text_rect, tr("/"), QTextOption(Qt::AlignCenter | Qt::AlignVCenter)); |
61 #endif | 61 #endif |
62 default: QStyledItemDelegate::paint(painter, option, index); break; | 62 default: QStyledItemDelegate::paint(painter, option, index); break; |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 AnimeListWidgetSortFilter::AnimeListWidgetSortFilter(QObject* parent) : QSortFilterProxyModel(parent) { | 66 AnimeListPageSortFilter::AnimeListPageSortFilter(QObject* parent) : QSortFilterProxyModel(parent) { |
67 } | 67 } |
68 | 68 |
69 bool AnimeListWidgetSortFilter::lessThan(const QModelIndex& l, const QModelIndex& r) const { | 69 bool AnimeListPageSortFilter::lessThan(const QModelIndex& l, const QModelIndex& r) const { |
70 QVariant left = sourceModel()->data(l, sortRole()); | 70 QVariant left = sourceModel()->data(l, sortRole()); |
71 QVariant right = sourceModel()->data(r, sortRole()); | 71 QVariant right = sourceModel()->data(r, sortRole()); |
72 | 72 |
73 switch (left.userType()) { | 73 switch (left.userType()) { |
74 case QMetaType::Int: | 74 case QMetaType::Int: |
79 case QMetaType::QString: | 79 case QMetaType::QString: |
80 default: return QString::compare(left.toString(), right.toString(), Qt::CaseInsensitive) < 0; | 80 default: return QString::compare(left.toString(), right.toString(), Qt::CaseInsensitive) < 0; |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 AnimeListWidgetModel::AnimeListWidgetModel(QWidget* parent, Anime::ListStatus _status) : QAbstractListModel(parent) { | 84 AnimeListPageModel::AnimeListPageModel(QWidget* parent, Anime::ListStatus _status) : QAbstractListModel(parent) { |
85 status = _status; | 85 status = _status; |
86 return; | 86 return; |
87 } | 87 } |
88 | 88 |
89 int AnimeListWidgetModel::rowCount(const QModelIndex& parent) const { | 89 int AnimeListPageModel::rowCount(const QModelIndex& parent) const { |
90 return list.size(); | 90 return list.size(); |
91 (void)(parent); | 91 (void)(parent); |
92 } | 92 } |
93 | 93 |
94 int AnimeListWidgetModel::columnCount(const QModelIndex& parent) const { | 94 int AnimeListPageModel::columnCount(const QModelIndex& parent) const { |
95 return NB_COLUMNS; | 95 return NB_COLUMNS; |
96 (void)(parent); | 96 (void)(parent); |
97 } | 97 } |
98 | 98 |
99 QVariant AnimeListWidgetModel::headerData(const int section, const Qt::Orientation orientation, const int role) const { | 99 QVariant AnimeListPageModel::headerData(const int section, const Qt::Orientation orientation, const int role) const { |
100 if (role == Qt::DisplayRole) { | 100 if (role == Qt::DisplayRole) { |
101 switch (section) { | 101 switch (section) { |
102 case AL_TITLE: return tr("Anime title"); | 102 case AL_TITLE: return tr("Anime title"); |
103 case AL_PROGRESS: return tr("Progress"); | 103 case AL_PROGRESS: return tr("Progress"); |
104 case AL_EPISODES: return tr("Episodes"); | 104 case AL_EPISODES: return tr("Episodes"); |
129 } | 129 } |
130 } | 130 } |
131 return QAbstractListModel::headerData(section, orientation, role); | 131 return QAbstractListModel::headerData(section, orientation, role); |
132 } | 132 } |
133 | 133 |
134 QVariant AnimeListWidgetModel::data(const QModelIndex& index, int role) const { | 134 QVariant AnimeListPageModel::data(const QModelIndex& index, int role) const { |
135 if (!index.isValid()) | 135 if (!index.isValid()) |
136 return QVariant(); | 136 return QVariant(); |
137 switch (role) { | 137 switch (role) { |
138 case Qt::DisplayRole: | 138 case Qt::DisplayRole: |
139 switch (index.column()) { | 139 switch (index.column()) { |
188 break; | 188 break; |
189 } | 189 } |
190 return QVariant(); | 190 return QVariant(); |
191 } | 191 } |
192 | 192 |
193 void AnimeListWidgetModel::UpdateAnime(int id) { | 193 void AnimeListPageModel::UpdateAnime(int id) { |
194 /* meh... it might be better to just reinit the entire list */ | 194 /* meh... it might be better to just reinit the entire list */ |
195 int i = 0; | 195 int i = 0; |
196 for (const auto& a : Anime::db.items) { | 196 for (const auto& a : Anime::db.items) { |
197 if (a.second.IsInUserList() && a.first == id && a.second.GetUserStatus() == status) { | 197 if (a.second.IsInUserList() && a.first == id && a.second.GetUserStatus() == status) { |
198 emit dataChanged(index(i), index(i)); | 198 emit dataChanged(index(i), index(i)); |
199 } | 199 } |
200 i++; | 200 i++; |
201 } | 201 } |
202 } | 202 } |
203 | 203 |
204 Anime::Anime* AnimeListWidgetModel::GetAnimeFromIndex(QModelIndex index) { | 204 Anime::Anime* AnimeListPageModel::GetAnimeFromIndex(QModelIndex index) { |
205 return &list.at(index.row()); | 205 return &list.at(index.row()); |
206 } | 206 } |
207 | 207 |
208 void AnimeListWidgetModel::RefreshList() { | 208 void AnimeListPageModel::RefreshList() { |
209 bool has_children = !!rowCount(index(0)); | 209 bool has_children = !!rowCount(index(0)); |
210 if (has_children) | 210 if (has_children) |
211 beginResetModel(); | 211 beginResetModel(); |
212 else { | 212 else { |
213 int count = 0; | 213 int count = 0; |
229 endResetModel(); | 229 endResetModel(); |
230 else | 230 else |
231 endInsertRows(); | 231 endInsertRows(); |
232 } | 232 } |
233 | 233 |
234 int AnimeListWidget::VisibleColumnsCount() const { | 234 int AnimeListPage::VisibleColumnsCount() const { |
235 int count = 0; | 235 int count = 0; |
236 | 236 |
237 for (int i = 0, end = tree_view->header()->count(); i < end; i++) { | 237 for (int i = 0, end = tree_view->header()->count(); i < end; i++) { |
238 if (!tree_view->isColumnHidden(i)) | 238 if (!tree_view->isColumnHidden(i)) |
239 count++; | 239 count++; |
240 } | 240 } |
241 | 241 |
242 return count; | 242 return count; |
243 } | 243 } |
244 | 244 |
245 void AnimeListWidget::SetColumnDefaults() { | 245 void AnimeListPage::SetColumnDefaults() { |
246 tree_view->setColumnHidden(AnimeListWidgetModel::AL_SEASON, false); | 246 tree_view->setColumnHidden(AnimeListPageModel::AL_SEASON, false); |
247 tree_view->setColumnHidden(AnimeListWidgetModel::AL_TYPE, false); | 247 tree_view->setColumnHidden(AnimeListPageModel::AL_TYPE, false); |
248 tree_view->setColumnHidden(AnimeListWidgetModel::AL_UPDATED, false); | 248 tree_view->setColumnHidden(AnimeListPageModel::AL_UPDATED, false); |
249 tree_view->setColumnHidden(AnimeListWidgetModel::AL_PROGRESS, false); | 249 tree_view->setColumnHidden(AnimeListPageModel::AL_PROGRESS, false); |
250 tree_view->setColumnHidden(AnimeListWidgetModel::AL_SCORE, false); | 250 tree_view->setColumnHidden(AnimeListPageModel::AL_SCORE, false); |
251 tree_view->setColumnHidden(AnimeListWidgetModel::AL_TITLE, false); | 251 tree_view->setColumnHidden(AnimeListPageModel::AL_TITLE, false); |
252 tree_view->setColumnHidden(AnimeListWidgetModel::AL_EPISODES, true); | 252 tree_view->setColumnHidden(AnimeListPageModel::AL_EPISODES, true); |
253 tree_view->setColumnHidden(AnimeListWidgetModel::AL_AVG_SCORE, true); | 253 tree_view->setColumnHidden(AnimeListPageModel::AL_AVG_SCORE, true); |
254 tree_view->setColumnHidden(AnimeListWidgetModel::AL_STARTED, true); | 254 tree_view->setColumnHidden(AnimeListPageModel::AL_STARTED, true); |
255 tree_view->setColumnHidden(AnimeListWidgetModel::AL_COMPLETED, true); | 255 tree_view->setColumnHidden(AnimeListPageModel::AL_COMPLETED, true); |
256 tree_view->setColumnHidden(AnimeListWidgetModel::AL_UPDATED, true); | 256 tree_view->setColumnHidden(AnimeListPageModel::AL_UPDATED, true); |
257 tree_view->setColumnHidden(AnimeListWidgetModel::AL_NOTES, true); | 257 tree_view->setColumnHidden(AnimeListPageModel::AL_NOTES, true); |
258 } | 258 } |
259 | 259 |
260 void AnimeListWidget::DisplayColumnHeaderMenu() { | 260 void AnimeListPage::DisplayColumnHeaderMenu() { |
261 QMenu* menu = new QMenu(this); | 261 QMenu* menu = new QMenu(this); |
262 menu->setAttribute(Qt::WA_DeleteOnClose); | 262 menu->setAttribute(Qt::WA_DeleteOnClose); |
263 menu->setTitle(tr("Column visibility")); | 263 menu->setTitle(tr("Column visibility")); |
264 menu->setToolTipsVisible(true); | 264 menu->setToolTipsVisible(true); |
265 | 265 |
266 for (int i = 0; i < AnimeListWidgetModel::NB_COLUMNS; i++) { | 266 for (int i = 0; i < AnimeListPageModel::NB_COLUMNS; i++) { |
267 if (i == AnimeListWidgetModel::AL_TITLE) | 267 if (i == AnimeListPageModel::AL_TITLE) |
268 continue; | 268 continue; |
269 const auto column_name = | 269 const auto column_name = |
270 sort_models[tab_bar->currentIndex()]->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString(); | 270 sort_models[tab_bar->currentIndex()]->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString(); |
271 QAction* action = menu->addAction(column_name, this, [this, i](const bool checked) { | 271 QAction* action = menu->addAction(column_name, this, [this, i](const bool checked) { |
272 if (!checked && (VisibleColumnsCount() <= 1)) | 272 if (!checked && (VisibleColumnsCount() <= 1)) |
292 }); | 292 }); |
293 menu->popup(QCursor::pos()); | 293 menu->popup(QCursor::pos()); |
294 (void)(resetAction); | 294 (void)(resetAction); |
295 } | 295 } |
296 | 296 |
297 void AnimeListWidget::DisplayListMenu() { | 297 void AnimeListPage::DisplayListMenu() { |
298 QMenu* menu = new QMenu(this); | 298 QMenu* menu = new QMenu(this); |
299 menu->setAttribute(Qt::WA_DeleteOnClose); | 299 menu->setAttribute(Qt::WA_DeleteOnClose); |
300 menu->setTitle(tr("Column visibility")); | 300 menu->setTitle(tr("Column visibility")); |
301 menu->setToolTipsVisible(true); | 301 menu->setToolTipsVisible(true); |
302 | 302 |
305 if (!selection.indexes().first().isValid()) { | 305 if (!selection.indexes().first().isValid()) { |
306 return; | 306 return; |
307 } | 307 } |
308 | 308 |
309 QAction* action = menu->addAction(tr("Information"), [this, selection] { | 309 QAction* action = menu->addAction(tr("Information"), [this, selection] { |
310 const QModelIndex index = ((AnimeListWidgetModel*)sort_models[tab_bar->currentIndex()]->sourceModel()) | 310 AnimeListPageModel* source_model = |
311 ->index(selection.indexes().first().row()); | 311 reinterpret_cast<AnimeListPageModel*>(sort_models[tab_bar->currentIndex()]->sourceModel()); |
312 Anime::Anime* anime = | 312 const QModelIndex index = source_model->index(selection.indexes().first().row()); |
313 ((AnimeListWidgetModel*)sort_models[tab_bar->currentIndex()]->sourceModel())->GetAnimeFromIndex(index); | 313 Anime::Anime* anime = source_model->GetAnimeFromIndex(index); |
314 if (!anime) { | 314 if (!anime) { |
315 return; | 315 return; |
316 } | 316 } |
317 | 317 |
318 InformationDialog* dialog = new InformationDialog( | 318 InformationDialog* dialog = new InformationDialog( |
328 dialog->activateWindow(); | 328 dialog->activateWindow(); |
329 }); | 329 }); |
330 menu->popup(QCursor::pos()); | 330 menu->popup(QCursor::pos()); |
331 } | 331 } |
332 | 332 |
333 void AnimeListWidget::ItemDoubleClicked() { | 333 void AnimeListPage::ItemDoubleClicked() { |
334 /* throw out any other garbage */ | 334 /* throw out any other garbage */ |
335 const QItemSelection selection = | 335 const QItemSelection selection = |
336 sort_models[tab_bar->currentIndex()]->mapSelectionToSource(tree_view->selectionModel()->selection()); | 336 sort_models[tab_bar->currentIndex()]->mapSelectionToSource(tree_view->selectionModel()->selection()); |
337 if (!selection.indexes().first().isValid()) { | 337 if (!selection.indexes().first().isValid()) { |
338 return; | 338 return; |
339 } | 339 } |
340 | 340 |
341 const QModelIndex index = ((AnimeListWidgetModel*)sort_models[tab_bar->currentIndex()]->sourceModel()) | 341 AnimeListPageModel* source_model = |
342 ->index(selection.indexes().first().row()); | 342 reinterpret_cast<AnimeListPageModel*>(sort_models[tab_bar->currentIndex()]->sourceModel()); |
343 Anime::Anime* anime = | 343 |
344 ((AnimeListWidgetModel*)sort_models[tab_bar->currentIndex()]->sourceModel())->GetAnimeFromIndex(index); | 344 const QModelIndex index = source_model->index(selection.indexes().first().row()); |
345 Anime::Anime* anime = source_model->GetAnimeFromIndex(index); | |
345 | 346 |
346 InformationDialog* dialog = new InformationDialog( | 347 InformationDialog* dialog = new InformationDialog( |
347 *anime, | 348 *anime, |
348 [this, anime] { | 349 [this, anime] { |
349 Services::UpdateAnimeEntry(anime->GetId()); | 350 Services::UpdateAnimeEntry(anime->GetId()); |
354 dialog->show(); | 355 dialog->show(); |
355 dialog->raise(); | 356 dialog->raise(); |
356 dialog->activateWindow(); | 357 dialog->activateWindow(); |
357 } | 358 } |
358 | 359 |
359 void AnimeListWidget::paintEvent(QPaintEvent*) { | 360 void AnimeListPage::paintEvent(QPaintEvent*) { |
360 QStylePainter p(this); | 361 QStylePainter p(this); |
361 | 362 |
362 QStyleOptionTabWidgetFrame opt; | 363 QStyleOptionTabWidgetFrame opt; |
363 InitStyle(&opt); | 364 InitStyle(&opt); |
364 opt.rect = panelRect; | 365 opt.rect = panelRect; |
365 p.drawPrimitive(QStyle::PE_FrameTabWidget, opt); | 366 p.drawPrimitive(QStyle::PE_FrameTabWidget, opt); |
366 } | 367 } |
367 | 368 |
368 void AnimeListWidget::resizeEvent(QResizeEvent* e) { | 369 void AnimeListPage::resizeEvent(QResizeEvent* e) { |
369 QWidget::resizeEvent(e); | 370 QWidget::resizeEvent(e); |
370 SetupLayout(); | 371 SetupLayout(); |
371 } | 372 } |
372 | 373 |
373 void AnimeListWidget::showEvent(QShowEvent*) { | 374 void AnimeListPage::showEvent(QShowEvent*) { |
374 SetupLayout(); | 375 SetupLayout(); |
375 } | 376 } |
376 | 377 |
377 void AnimeListWidget::InitBasicStyle(QStyleOptionTabWidgetFrame* option) const { | 378 void AnimeListPage::InitBasicStyle(QStyleOptionTabWidgetFrame* option) const { |
378 if (!option) | 379 if (!option) |
379 return; | 380 return; |
380 | 381 |
381 option->initFrom(this); | 382 option->initFrom(this); |
382 option->lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, this); | 383 option->lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, this); |
383 option->shape = QTabBar::RoundedNorth; | 384 option->shape = QTabBar::RoundedNorth; |
384 option->tabBarRect = tab_bar->geometry(); | 385 option->tabBarRect = tab_bar->geometry(); |
385 } | 386 } |
386 | 387 |
387 void AnimeListWidget::InitStyle(QStyleOptionTabWidgetFrame* option) const { | 388 void AnimeListPage::InitStyle(QStyleOptionTabWidgetFrame* option) const { |
388 if (!option) | 389 if (!option) |
389 return; | 390 return; |
390 | 391 |
391 InitBasicStyle(option); | 392 InitBasicStyle(option); |
392 | 393 |
404 option->selectedTabRect = selected_tab_rect; | 405 option->selectedTabRect = selected_tab_rect; |
405 | 406 |
406 option->lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, this); | 407 option->lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, this); |
407 } | 408 } |
408 | 409 |
409 void AnimeListWidget::SetupLayout() { | 410 void AnimeListPage::SetupLayout() { |
410 QStyleOptionTabWidgetFrame option; | 411 QStyleOptionTabWidgetFrame option; |
411 InitStyle(&option); | 412 InitStyle(&option); |
412 | 413 |
413 QRect tabRect = style()->subElementRect(QStyle::SE_TabWidgetTabBar, &option, this); | 414 QRect tabRect = style()->subElementRect(QStyle::SE_TabWidgetTabBar, &option, this); |
414 tabRect.setLeft(tabRect.left() + 1); | 415 tabRect.setLeft(tabRect.left() + 1); |
417 | 418 |
418 tab_bar->setGeometry(tabRect); | 419 tab_bar->setGeometry(tabRect); |
419 tree_view->parentWidget()->setGeometry(contentsRect); | 420 tree_view->parentWidget()->setGeometry(contentsRect); |
420 } | 421 } |
421 | 422 |
422 AnimeListWidget::AnimeListWidget(QWidget* parent) : QWidget(parent) { | 423 AnimeListPage::AnimeListPage(QWidget* parent) : QWidget(parent) { |
423 /* Tab bar */ | 424 /* Tab bar */ |
424 tab_bar = new QTabBar(this); | 425 tab_bar = new QTabBar(this); |
425 tab_bar->setExpanding(false); | 426 tab_bar->setExpanding(false); |
426 tab_bar->setDrawBase(false); | 427 tab_bar->setDrawBase(false); |
427 | 428 |
428 /* Tree view... */ | 429 /* Tree view... */ |
429 QWidget* tree_widget = new QWidget(this); | 430 QWidget* tree_widget = new QWidget(this); |
430 tree_view = new QTreeView(tree_widget); | 431 tree_view = new QTreeView(tree_widget); |
431 tree_view->setItemDelegate(new AnimeListWidgetDelegate(tree_view)); | 432 tree_view->setItemDelegate(new AnimeListPageDelegate(tree_view)); |
432 tree_view->setUniformRowHeights(true); | 433 tree_view->setUniformRowHeights(true); |
433 tree_view->setAllColumnsShowFocus(false); | 434 tree_view->setAllColumnsShowFocus(false); |
434 tree_view->setAlternatingRowColors(true); | 435 tree_view->setAlternatingRowColors(true); |
435 tree_view->setSortingEnabled(true); | 436 tree_view->setSortingEnabled(true); |
436 tree_view->setSelectionMode(QAbstractItemView::ExtendedSelection); | 437 tree_view->setSelectionMode(QAbstractItemView::ExtendedSelection); |
440 tree_view->setFrameShape(QFrame::NoFrame); | 441 tree_view->setFrameShape(QFrame::NoFrame); |
441 | 442 |
442 for (unsigned int i = 0; i < ARRAYSIZE(sort_models); i++) { | 443 for (unsigned int i = 0; i < ARRAYSIZE(sort_models); i++) { |
443 tab_bar->addTab(QString::fromStdString(Translate::ToString(Anime::ListStatuses[i])) + " (" + | 444 tab_bar->addTab(QString::fromStdString(Translate::ToString(Anime::ListStatuses[i])) + " (" + |
444 QString::number(Anime::db.GetListsAnimeAmount(Anime::ListStatuses[i])) + ")"); | 445 QString::number(Anime::db.GetListsAnimeAmount(Anime::ListStatuses[i])) + ")"); |
445 sort_models[i] = new AnimeListWidgetSortFilter(tree_view); | 446 sort_models[i] = new AnimeListPageSortFilter(tree_view); |
446 sort_models[i]->setSourceModel(new AnimeListWidgetModel(this, Anime::ListStatuses[i])); | 447 sort_models[i]->setSourceModel(new AnimeListPageModel(this, Anime::ListStatuses[i])); |
447 sort_models[i]->setSortRole(Qt::UserRole); | 448 sort_models[i]->setSortRole(Qt::UserRole); |
448 sort_models[i]->setSortCaseSensitivity(Qt::CaseInsensitive); | 449 sort_models[i]->setSortCaseSensitivity(Qt::CaseInsensitive); |
449 } | 450 } |
450 tree_view->setModel(sort_models[0]); | 451 tree_view->setModel(sort_models[0]); |
451 | 452 |
453 layout->addWidget(tree_view); | 454 layout->addWidget(tree_view); |
454 layout->setContentsMargins(0, 0, 0, 0); | 455 layout->setContentsMargins(0, 0, 0, 0); |
455 tree_widget->setLayout(layout); | 456 tree_widget->setLayout(layout); |
456 | 457 |
457 /* Double click stuff */ | 458 /* Double click stuff */ |
458 connect(tree_view, &QAbstractItemView::doubleClicked, this, &AnimeListWidget::ItemDoubleClicked); | 459 connect(tree_view, &QAbstractItemView::doubleClicked, this, &AnimeListPage::ItemDoubleClicked); |
459 connect(tree_view, &QWidget::customContextMenuRequested, this, &AnimeListWidget::DisplayListMenu); | 460 connect(tree_view, &QWidget::customContextMenuRequested, this, &AnimeListPage::DisplayListMenu); |
460 | 461 |
461 /* Enter & return keys */ | 462 /* Enter & return keys */ |
462 connect(new QShortcut(Qt::Key_Return, tree_view, nullptr, nullptr, Qt::WidgetShortcut), &QShortcut::activated, this, | 463 connect(new QShortcut(Qt::Key_Return, tree_view, nullptr, nullptr, Qt::WidgetShortcut), &QShortcut::activated, this, |
463 &AnimeListWidget::ItemDoubleClicked); | 464 &AnimeListPage::ItemDoubleClicked); |
464 | 465 |
465 connect(new QShortcut(Qt::Key_Enter, tree_view, nullptr, nullptr, Qt::WidgetShortcut), &QShortcut::activated, this, | 466 connect(new QShortcut(Qt::Key_Enter, tree_view, nullptr, nullptr, Qt::WidgetShortcut), &QShortcut::activated, this, |
466 &AnimeListWidget::ItemDoubleClicked); | 467 &AnimeListPage::ItemDoubleClicked); |
467 | 468 |
468 tree_view->header()->setStretchLastSection(false); | 469 tree_view->header()->setStretchLastSection(false); |
469 tree_view->header()->setContextMenuPolicy(Qt::CustomContextMenu); | 470 tree_view->header()->setContextMenuPolicy(Qt::CustomContextMenu); |
470 connect(tree_view->header(), &QWidget::customContextMenuRequested, this, &AnimeListWidget::DisplayColumnHeaderMenu); | 471 connect(tree_view->header(), &QWidget::customContextMenuRequested, this, &AnimeListPage::DisplayColumnHeaderMenu); |
471 | 472 |
472 connect(tab_bar, &QTabBar::currentChanged, this, [this](int index) { | 473 connect(tab_bar, &QTabBar::currentChanged, this, [this](int index) { |
473 if (sort_models[index]) | 474 if (sort_models[index]) |
474 tree_view->setModel(sort_models[index]); | 475 tree_view->setModel(sort_models[index]); |
475 }); | 476 }); |
476 | 477 |
477 setFocusPolicy(Qt::TabFocus); | 478 setFocusPolicy(Qt::TabFocus); |
478 setFocusProxy(tab_bar); | 479 setFocusProxy(tab_bar); |
479 } | 480 } |
480 | 481 |
481 void AnimeListWidget::RefreshList() { | 482 void AnimeListPage::RefreshList() { |
482 for (unsigned int i = 0; i < ARRAYSIZE(sort_models); i++) | 483 for (unsigned int i = 0; i < ARRAYSIZE(sort_models); i++) |
483 ((AnimeListWidgetModel*)sort_models[i]->sourceModel())->RefreshList(); | 484 reinterpret_cast<AnimeListPageModel*>(sort_models[i]->sourceModel())->RefreshList(); |
484 } | 485 } |
485 | 486 |
486 void AnimeListWidget::RefreshTabs() { | 487 void AnimeListPage::RefreshTabs() { |
487 for (unsigned int i = 0; i < ARRAYSIZE(sort_models); i++) | 488 for (unsigned int i = 0; i < ARRAYSIZE(sort_models); i++) |
488 tab_bar->setTabText(i, QString::fromStdString(Translate::ToString(Anime::ListStatuses[i])) + " (" + | 489 tab_bar->setTabText(i, QString::fromStdString(Translate::ToString(Anime::ListStatuses[i])) + " (" + |
489 QString::number(Anime::db.GetListsAnimeAmount(Anime::ListStatuses[i])) + ")"); | 490 QString::number(Anime::db.GetListsAnimeAmount(Anime::ListStatuses[i])) + ")"); |
490 } | 491 } |
491 | 492 |
492 void AnimeListWidget::Refresh() { | 493 void AnimeListPage::Refresh() { |
493 RefreshList(); | 494 RefreshList(); |
494 RefreshTabs(); | 495 RefreshTabs(); |
495 } | 496 } |
496 | 497 |
497 /* This function, really, really should not be called. | 498 /* This function, really, really should not be called. |
498 Ever. Why would you ever need to clear the anime list? | 499 Ever. Why would you ever need to clear the anime list? |
499 Also, this sucks. */ | 500 Also, this sucks. */ |
500 void AnimeListWidget::Reset() { | 501 void AnimeListPage::Reset() { |
501 while (tab_bar->count()) | 502 while (tab_bar->count()) |
502 tab_bar->removeTab(0); | 503 tab_bar->removeTab(0); |
503 for (unsigned int i = 0; i < ARRAYSIZE(sort_models); i++) | 504 for (unsigned int i = 0; i < ARRAYSIZE(sort_models); i++) |
504 delete sort_models[i]; | 505 delete sort_models[i]; |
505 } | 506 } |