annotate src/gui/pages/anime_list.cpp @ 54:466ac9870df9

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