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"
|
|
16 #include "gui/dialog/information.h"
|
|
17 #include "gui/translate/anime.h"
|
|
18 #include "services/anilist.h"
|
|
19 #include <QHBoxLayout>
|
|
20 #include <QHeaderView>
|
|
21 #include <QMenu>
|
|
22 #include <QProgressBar>
|
|
23 #include <QDebug>
|
|
24 #include <QShortcut>
|
|
25 #include <QStylePainter>
|
|
26 #include <QStyledItemDelegate>
|
|
27 #include <QAbstractItemModelTester>
|
|
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,
|
|
39 const QModelIndex& index) const {
|
|
40 switch (index.column()) {
|
|
41 /*
|
|
42 case AnimeListWidgetModel::AL_PROGRESS: {
|
|
43 const int progress = static_cast<int>(index.data(Qt::UserRole).toReal());
|
|
44 const int episodes =
|
|
45 static_cast<int>(index.siblingAtColumn(AnimeListWidgetModel::AL_EPISODES).data(Qt::UserRole).toReal());
|
|
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));
|
|
51 // drawText(const QRectF &rectangle, const QString &text, const QTextOption &option = QTextOption())
|
|
52 painter->drawText(QRectF(text_rect.x(), text_rect.y(), text_width / 2 - 2, text_rect.height()),
|
|
53 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;
|
|
60 }
|
|
61 */
|
|
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) {
|
|
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 {};
|
|
114 }
|
|
115 } else if (role == Qt::TextAlignmentRole) {
|
|
116 switch (section) {
|
|
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);
|
|
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:
|
|
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()) + "/" + QString::number(list[index.row()].GetEpisodes());
|
|
143 case AL_EPISODES: return list[index.row()].GetEpisodes();
|
|
144 case AL_SCORE: return list[index.row()].GetUserScore();
|
|
145 case AL_TYPE: return QString::fromStdString(Translate::TranslateSeriesFormat(list[index.row()].GetFormat()));
|
|
146 case AL_SEASON:
|
|
147 return QString::fromStdString(Translate::TranslateSeriesSeason(list[index.row()].GetSeason())) + " " +
|
|
148 QString::number(list[index.row()].GetAirDate().GetYear());
|
|
149 case AL_AVG_SCORE: return QString::number(list[index.row()].GetAudienceScore()) + "%";
|
|
150 case AL_STARTED: return list[index.row()].GetUserDateStarted().GetAsQDate();
|
|
151 case AL_COMPLETED: return list[index.row()].GetUserDateCompleted().GetAsQDate();
|
|
152 case AL_UPDATED: {
|
|
153 if (list[index.row()].GetUserTimeUpdated() == 0)
|
|
154 return QString("-");
|
|
155 Time::Duration duration(Time::GetSystemTime() - list[index.row()].GetUserTimeUpdated());
|
|
156 return QString::fromUtf8(duration.AsRelativeString().c_str());
|
|
157 }
|
|
158 case AL_NOTES: return QString::fromUtf8(list[index.row()].GetUserNotes().c_str());
|
|
159 default: return "";
|
|
160 }
|
|
161 break;
|
|
162 case Qt::UserRole:
|
|
163 switch (index.column()) {
|
|
164 case AL_ID: return list[index.row()].GetId();
|
|
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();
|
|
169 case AL_UPDATED: return list[index.row()].GetUserTimeUpdated();
|
|
170 default: return data(index, Qt::DisplayRole);
|
|
171 }
|
|
172 break;
|
|
173 case Qt::TextAlignmentRole:
|
|
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;
|
|
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) {
|
10
|
198 emit dataChanged(index(i), index(i));
|
|
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));
|
|
210 if (has_children) beginResetModel();
|
|
211 list.clear();
|
|
212
|
11
|
213 for (const auto& a : Anime::db.items) {
|
|
214 if (a.second.IsInUserList() && a.second.GetUserStatus() == status) {
|
|
215 list.push_back(a.second);
|
10
|
216 }
|
|
217 }
|
|
218 if (has_children) endResetModel();
|
|
219 }
|
|
220
|
|
221 int AnimeListWidget::VisibleColumnsCount() const {
|
|
222 int count = 0;
|
|
223
|
|
224 for (int i = 0, end = tree_view->header()->count(); i < end; i++) {
|
|
225 if (!tree_view->isColumnHidden(i))
|
|
226 count++;
|
|
227 }
|
|
228
|
|
229 return count;
|
|
230 }
|
|
231
|
|
232 void AnimeListWidget::SetColumnDefaults() {
|
|
233 tree_view->setColumnHidden(AnimeListWidgetModel::AL_SEASON, false);
|
|
234 tree_view->setColumnHidden(AnimeListWidgetModel::AL_TYPE, false);
|
|
235 tree_view->setColumnHidden(AnimeListWidgetModel::AL_UPDATED, false);
|
|
236 tree_view->setColumnHidden(AnimeListWidgetModel::AL_PROGRESS, false);
|
|
237 tree_view->setColumnHidden(AnimeListWidgetModel::AL_SCORE, false);
|
|
238 tree_view->setColumnHidden(AnimeListWidgetModel::AL_TITLE, false);
|
|
239 tree_view->setColumnHidden(AnimeListWidgetModel::AL_EPISODES, true);
|
|
240 tree_view->setColumnHidden(AnimeListWidgetModel::AL_AVG_SCORE, true);
|
|
241 tree_view->setColumnHidden(AnimeListWidgetModel::AL_STARTED, true);
|
|
242 tree_view->setColumnHidden(AnimeListWidgetModel::AL_COMPLETED, true);
|
|
243 tree_view->setColumnHidden(AnimeListWidgetModel::AL_UPDATED, true);
|
|
244 tree_view->setColumnHidden(AnimeListWidgetModel::AL_NOTES, true);
|
|
245 tree_view->setColumnHidden(AnimeListWidgetModel::AL_ID, true);
|
|
246 }
|
|
247
|
|
248 void AnimeListWidget::DisplayColumnHeaderMenu() {
|
|
249 QMenu* menu = new QMenu(this);
|
|
250 menu->setAttribute(Qt::WA_DeleteOnClose);
|
|
251 menu->setTitle(tr("Column visibility"));
|
|
252 menu->setToolTipsVisible(true);
|
|
253
|
|
254 for (int i = 0; i < AnimeListWidgetModel::NB_COLUMNS; i++) {
|
|
255 if (i == AnimeListWidgetModel::AL_TITLE || i == AnimeListWidgetModel::AL_ID)
|
|
256 continue;
|
|
257 const auto column_name =
|
|
258 sort_models[tab_bar->currentIndex()]->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString();
|
|
259 QAction* action = menu->addAction(column_name, this, [this, i](const bool checked) {
|
|
260 if (!checked && (VisibleColumnsCount() <= 1))
|
|
261 return;
|
|
262
|
|
263 tree_view->setColumnHidden(i, !checked);
|
|
264
|
|
265 if (checked && (tree_view->columnWidth(i) <= 5))
|
|
266 tree_view->resizeColumnToContents(i);
|
|
267
|
|
268 // SaveSettings();
|
|
269 });
|
|
270 action->setCheckable(true);
|
|
271 action->setChecked(!tree_view->isColumnHidden(i));
|
|
272 }
|
|
273
|
|
274 menu->addSeparator();
|
|
275 QAction* resetAction = menu->addAction(tr("Reset to defaults"), this, [this]() {
|
|
276 for (int i = 0, count = tree_view->header()->count(); i < count; ++i) {
|
|
277 SetColumnDefaults();
|
|
278 }
|
|
279 // SaveSettings();
|
|
280 });
|
|
281 menu->popup(QCursor::pos());
|
|
282 (void)(resetAction);
|
|
283 }
|
|
284
|
|
285 void AnimeListWidget::DisplayListMenu() {
|
|
286 QMenu* menu = new QMenu(this);
|
|
287 menu->setAttribute(Qt::WA_DeleteOnClose);
|
|
288 menu->setTitle(tr("Column visibility"));
|
|
289 menu->setToolTipsVisible(true);
|
|
290
|
|
291 const QItemSelection selection = sort_models[tab_bar->currentIndex()]->mapSelectionToSource(tree_view->selectionModel()->selection());
|
|
292 if (!selection.indexes().first().isValid()) {
|
|
293 return;
|
|
294 }
|
|
295
|
|
296 QAction* action = menu->addAction("Information", [this, selection] {
|
|
297 const QModelIndex index = ((AnimeListWidgetModel*)sort_models[tab_bar->currentIndex()]->sourceModel())
|
|
298 ->index(selection.indexes().first().row());
|
|
299 Anime::Anime* anime =
|
|
300 ((AnimeListWidgetModel*)sort_models[tab_bar->currentIndex()]->sourceModel())->GetAnimeFromIndex(index);
|
|
301 if (!anime) {
|
|
302 return;
|
|
303 }
|
|
304
|
|
305 InformationDialog* dialog = new InformationDialog(
|
|
306 *anime,
|
|
307 [this, anime] {
|
|
308 ((AnimeListWidgetModel*)sort_models[tab_bar->currentIndex()]->sourceModel())->UpdateAnime(anime->GetId());
|
|
309 },
|
|
310 this);
|
|
311
|
|
312 dialog->show();
|
|
313 dialog->raise();
|
|
314 dialog->activateWindow();
|
|
315 });
|
|
316 menu->popup(QCursor::pos());
|
|
317 }
|
|
318
|
|
319 void AnimeListWidget::ItemDoubleClicked() {
|
|
320 /* throw out any other garbage */
|
|
321 const QItemSelection selection =
|
|
322 sort_models[tab_bar->currentIndex()]->mapSelectionToSource(tree_view->selectionModel()->selection());
|
|
323 if (!selection.indexes().first().isValid()) {
|
|
324 return;
|
|
325 }
|
|
326
|
|
327 const QModelIndex index = ((AnimeListWidgetModel*)sort_models[tab_bar->currentIndex()]->sourceModel())
|
|
328 ->index(selection.indexes().first().row());
|
|
329 Anime::Anime* anime =
|
|
330 ((AnimeListWidgetModel*)sort_models[tab_bar->currentIndex()]->sourceModel())->GetAnimeFromIndex(index);
|
|
331
|
|
332 InformationDialog* dialog = new InformationDialog(
|
|
333 *anime,
|
|
334 [this, anime] {
|
|
335 ((AnimeListWidgetModel*)sort_models[tab_bar->currentIndex()]->sourceModel())->UpdateAnime(anime->GetId());
|
|
336 },
|
|
337 this);
|
|
338
|
|
339 dialog->show();
|
|
340 dialog->raise();
|
|
341 dialog->activateWindow();
|
|
342 }
|
|
343
|
|
344 void AnimeListWidget::paintEvent(QPaintEvent*) {
|
|
345 QStylePainter p(this);
|
|
346
|
|
347 QStyleOptionTabWidgetFrame opt;
|
|
348 InitStyle(&opt);
|
|
349 opt.rect = panelRect;
|
|
350 p.drawPrimitive(QStyle::PE_FrameTabWidget, opt);
|
|
351 }
|
|
352
|
|
353 void AnimeListWidget::resizeEvent(QResizeEvent* e) {
|
|
354 QWidget::resizeEvent(e);
|
|
355 SetupLayout();
|
|
356 }
|
|
357
|
|
358 void AnimeListWidget::showEvent(QShowEvent*) {
|
|
359 SetupLayout();
|
|
360 }
|
|
361
|
|
362 void AnimeListWidget::InitBasicStyle(QStyleOptionTabWidgetFrame* option) const {
|
|
363 if (!option)
|
|
364 return;
|
|
365
|
|
366 option->initFrom(this);
|
|
367 option->lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, this);
|
|
368 option->shape = QTabBar::RoundedNorth;
|
|
369 option->tabBarRect = tab_bar->geometry();
|
|
370 }
|
|
371
|
|
372 void AnimeListWidget::InitStyle(QStyleOptionTabWidgetFrame* option) const {
|
|
373 if (!option)
|
|
374 return;
|
|
375
|
|
376 InitBasicStyle(option);
|
|
377
|
|
378 // int exth = style()->pixelMetric(QStyle::PM_TabBarBaseHeight, nullptr, this);
|
|
379 QSize t(0, tree_view->frameWidth());
|
|
380 if (tab_bar->isVisibleTo(this)) {
|
|
381 t = tab_bar->sizeHint();
|
|
382 t.setWidth(width());
|
|
383 }
|
|
384 option->tabBarSize = t;
|
|
385
|
|
386 QRect selected_tab_rect = tab_bar->tabRect(tab_bar->currentIndex());
|
|
387 selected_tab_rect.moveTopLeft(selected_tab_rect.topLeft() + option->tabBarRect.topLeft());
|
|
388 option->selectedTabRect = selected_tab_rect;
|
|
389
|
|
390 option->lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, this);
|
|
391 }
|
|
392
|
|
393 void AnimeListWidget::SetupLayout() {
|
|
394 QStyleOptionTabWidgetFrame option;
|
|
395 InitStyle(&option);
|
|
396
|
|
397 QRect tabRect = style()->subElementRect(QStyle::SE_TabWidgetTabBar, &option, this);
|
|
398 tabRect.setLeft(tabRect.left() + 1);
|
|
399 panelRect = style()->subElementRect(QStyle::SE_TabWidgetTabPane, &option, this);
|
|
400 QRect contentsRect = style()->subElementRect(QStyle::SE_TabWidgetTabContents, &option, this);
|
|
401
|
|
402 tab_bar->setGeometry(tabRect);
|
|
403 tree_view->parentWidget()->setGeometry(contentsRect);
|
|
404 }
|
|
405
|
|
406 AnimeListWidget::AnimeListWidget(QWidget* parent) : QWidget(parent) {
|
|
407 /* Tab bar */
|
|
408 tab_bar = new QTabBar(this);
|
|
409 tab_bar->setExpanding(false);
|
|
410 tab_bar->setDrawBase(false);
|
|
411
|
|
412 /* Tree view... */
|
|
413 QWidget* tree_widget = new QWidget(this);
|
|
414 tree_view = new QTreeView(tree_widget);
|
|
415 tree_view->setItemDelegate(new AnimeListWidgetDelegate(tree_view));
|
|
416 tree_view->setUniformRowHeights(true);
|
|
417 tree_view->setAllColumnsShowFocus(false);
|
|
418 tree_view->setAlternatingRowColors(true);
|
|
419 tree_view->setSortingEnabled(true);
|
|
420 tree_view->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
|
421 tree_view->setItemsExpandable(false);
|
|
422 tree_view->setRootIsDecorated(false);
|
|
423 tree_view->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
424 tree_view->setFrameShape(QFrame::NoFrame);
|
|
425
|
|
426 for (unsigned int i = 0; i < ARRAYSIZE(sort_models); i++) {
|
|
427 tab_bar->addTab(QString::fromStdString(Translate::TranslateListStatus(Anime::ListStatuses[i])) + " (" + QString::number(Anime::db.GetListsAnimeAmount(Anime::ListStatuses[i])) + ")");
|
|
428 sort_models[i] = new AnimeListWidgetSortFilter(tree_view);
|
|
429 AnimeListWidgetModel* model = new AnimeListWidgetModel(this, Anime::ListStatuses[i]);
|
|
430 new QAbstractItemModelTester(model, QAbstractItemModelTester::FailureReportingMode::Fatal, this);
|
|
431 sort_models[i]->setSourceModel(model);
|
|
432 sort_models[i]->setSortRole(Qt::UserRole);
|
|
433 sort_models[i]->setSortCaseSensitivity(Qt::CaseInsensitive);
|
|
434 }
|
|
435
|
|
436 QHBoxLayout* layout = new QHBoxLayout;
|
|
437 layout->addWidget(tree_view);
|
|
438 layout->setMargin(0);
|
|
439 tree_widget->setLayout(layout);
|
|
440
|
|
441 /* Double click stuff */
|
|
442 connect(tree_view, &QAbstractItemView::doubleClicked, this, &AnimeListWidget::ItemDoubleClicked);
|
|
443 connect(tree_view, &QWidget::customContextMenuRequested, this, &AnimeListWidget::DisplayListMenu);
|
|
444
|
|
445 /* Enter & return keys */
|
|
446 connect(new QShortcut(Qt::Key_Return, tree_view, nullptr, nullptr, Qt::WidgetShortcut), &QShortcut::activated,
|
|
447 this, &AnimeListWidget::ItemDoubleClicked);
|
|
448
|
|
449 connect(new QShortcut(Qt::Key_Enter, tree_view, nullptr, nullptr, Qt::WidgetShortcut), &QShortcut::activated,
|
|
450 this, &AnimeListWidget::ItemDoubleClicked);
|
|
451
|
|
452 tree_view->header()->setStretchLastSection(false);
|
|
453 tree_view->header()->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
454 connect(tree_view->header(), &QWidget::customContextMenuRequested, this,
|
|
455 &AnimeListWidget::DisplayColumnHeaderMenu);
|
|
456
|
|
457 connect(tab_bar, &QTabBar::currentChanged, this, [this](int index) {
|
|
458 if (sort_models[index])
|
|
459 tree_view->setModel(sort_models[index]);
|
|
460 });
|
|
461
|
|
462 setFocusPolicy(Qt::TabFocus);
|
|
463 setFocusProxy(tab_bar);
|
|
464 }
|
|
465
|
|
466 void AnimeListWidget::RefreshList() {
|
|
467 for (unsigned int i = 0; i < ARRAYSIZE(sort_models); i++) {
|
|
468 ((AnimeListWidgetModel*)sort_models[i]->sourceModel())->RefreshList();
|
|
469 }
|
|
470 }
|
|
471
|
|
472 void AnimeListWidget::Reset() {
|
|
473 while (tab_bar->count())
|
|
474 tab_bar->removeTab(0);
|
|
475 for (unsigned int i = 0; i < ARRAYSIZE(sort_models); i++)
|
|
476 delete sort_models[i];
|
|
477 }
|
|
478
|
|
479 #include "gui/pages/moc_anime_list.cpp"
|