Mercurial > minori
annotate src/gui/pages/anime_list.cc @ 174:f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Wed, 29 Nov 2023 13:53:56 -0500 |
parents | 39521c47c7a3 |
children | bc8d2ccff09c |
rev | line source |
---|---|
10 | 1 /** |
2 * anime_list.cpp: defines the anime list page | |
3 * and widgets. | |
4 * | |
5 * much of this file is based around | |
6 * Qt's original QTabWidget implementation, because | |
7 * I needed a somewhat native way to create a tabbed | |
8 * widget with only one subwidget that worked exactly | |
9 * like a native tabbed widget. | |
10 **/ | |
11 #include "gui/pages/anime_list.h" | |
12 #include "core/anime.h" | |
13 #include "core/anime_db.h" | |
14 #include "core/session.h" | |
76 | 15 #include "core/strings.h" |
10 | 16 #include "core/time.h" |
17 #include "gui/dialog/information.h" | |
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 | 20 #include <QDebug> |
10 | 21 #include <QHBoxLayout> |
22 #include <QHeaderView> | |
23 #include <QMenu> | |
24 #include <QProgressBar> | |
25 #include <QShortcut> | |
86 | 26 #include <QTreeView> |
10 | 27 #include <QStylePainter> |
28 #include <QStyledItemDelegate> | |
77 | 29 #include <QThreadPool> |
30 #include <set> | |
10 | 31 |
64 | 32 AnimeListPageSortFilter::AnimeListPageSortFilter(QObject* parent) : QSortFilterProxyModel(parent) { |
10 | 33 } |
34 | |
64 | 35 bool AnimeListPageSortFilter::lessThan(const QModelIndex& l, const QModelIndex& r) const { |
10 | 36 QVariant left = sourceModel()->data(l, sortRole()); |
37 QVariant right = sourceModel()->data(r, sortRole()); | |
38 | |
39 switch (left.userType()) { | |
40 case QMetaType::Int: | |
41 case QMetaType::UInt: | |
42 case QMetaType::LongLong: | |
43 case QMetaType::ULongLong: return left.toInt() < right.toInt(); | |
44 case QMetaType::QDate: return left.toDate() < right.toDate(); | |
45 case QMetaType::QString: | |
46 default: return QString::compare(left.toString(), right.toString(), Qt::CaseInsensitive) < 0; | |
47 } | |
48 } | |
49 | |
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
50 /* -------------------------------------------------- */ |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
51 |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
52 AnimeListPageModel::AnimeListPageModel(QObject* parent, Anime::ListStatus _status) : QAbstractListModel(parent) { |
10 | 53 status = _status; |
54 return; | |
55 } | |
56 | |
64 | 57 int AnimeListPageModel::rowCount(const QModelIndex& parent) const { |
10 | 58 return list.size(); |
59 (void)(parent); | |
60 } | |
61 | |
64 | 62 int AnimeListPageModel::columnCount(const QModelIndex& parent) const { |
10 | 63 return NB_COLUMNS; |
64 (void)(parent); | |
65 } | |
66 | |
64 | 67 QVariant AnimeListPageModel::headerData(const int section, const Qt::Orientation orientation, const int role) const { |
10 | 68 if (role == Qt::DisplayRole) { |
69 switch (section) { | |
47
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
70 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
|
71 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
|
72 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
|
73 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
|
74 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 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
|
81 default: return {}; |
10 | 82 } |
83 } else if (role == Qt::TextAlignmentRole) { | |
84 switch (section) { | |
47
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
85 case AL_TITLE: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
86 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
|
87 case AL_PROGRESS: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
88 case AL_EPISODES: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
89 case AL_TYPE: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
90 case AL_SCORE: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
91 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
|
92 case AL_SEASON: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
93 case AL_STARTED: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
94 case AL_COMPLETED: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
95 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
|
96 default: return QAbstractListModel::headerData(section, orientation, role); |
10 | 97 } |
98 } | |
99 return QAbstractListModel::headerData(section, orientation, role); | |
100 } | |
101 | |
64 | 102 QVariant AnimeListPageModel::data(const QModelIndex& index, int role) const { |
10 | 103 if (!index.isValid()) |
104 return QVariant(); | |
105 switch (role) { | |
106 case Qt::DisplayRole: | |
47
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
107 switch (index.column()) { |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
108 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
|
109 case AL_PROGRESS: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
110 return QString::number(list[index.row()].GetUserProgress()) + "/" + |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
111 QString::number(list[index.row()].GetEpisodes()); |
47
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
112 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
|
113 case AL_SCORE: return list[index.row()].GetUserScore(); |
65
26721c28bf22
*: avoid usage of (to|from)StdString
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
114 case AL_TYPE: return Strings::ToQString(Translate::ToString(list[index.row()].GetFormat())); |
47
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
115 case AL_SEASON: |
65
26721c28bf22
*: avoid usage of (to|from)StdString
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
116 return Strings::ToQString(Translate::ToString(list[index.row()].GetSeason())) + " " + |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
117 QString::number(list[index.row()].GetAirDate().GetYear()); |
47
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
118 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
|
119 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
|
120 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
|
121 case AL_UPDATED: { |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
122 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
|
123 return QString("-"); |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
124 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
|
125 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
|
126 } |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
127 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
|
128 default: return ""; |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
129 } |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
130 break; |
10 | 131 case Qt::UserRole: |
47
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
132 switch (index.column()) { |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
133 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
|
134 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
|
135 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
|
136 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
|
137 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
|
138 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
|
139 } |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
140 break; |
10 | 141 case Qt::TextAlignmentRole: |
47
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
142 switch (index.column()) { |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
143 case AL_TITLE: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
144 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
|
145 case AL_PROGRESS: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
146 case AL_EPISODES: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
147 case AL_TYPE: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
148 case AL_SCORE: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
149 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
|
150 case AL_SEASON: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
151 case AL_STARTED: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
152 case AL_COMPLETED: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
153 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
|
154 default: break; |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
155 } |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
156 break; |
10 | 157 } |
158 return QVariant(); | |
159 } | |
160 | |
64 | 161 Anime::Anime* AnimeListPageModel::GetAnimeFromIndex(QModelIndex index) { |
10 | 162 return &list.at(index.row()); |
163 } | |
164 | |
64 | 165 void AnimeListPageModel::RefreshList() { |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
166 /* equivalent to hasChildren()... */ |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
167 if (!rowCount(index(0))) { |
77 | 168 beginInsertRows(QModelIndex(), 0, 0); |
169 endInsertRows(); | |
15 | 170 } |
171 | |
77 | 172 beginResetModel(); |
173 | |
10 | 174 list.clear(); |
175 | |
11 | 176 for (const auto& a : Anime::db.items) { |
177 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
|
178 list.push_back(a.second); |
10 | 179 } |
180 } | |
15 | 181 |
77 | 182 endResetModel(); |
10 | 183 } |
184 | |
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
185 /* ----------------------------------------------------------------- */ |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
186 |
64 | 187 int AnimeListPage::VisibleColumnsCount() const { |
10 | 188 int count = 0; |
189 | |
190 for (int i = 0, end = tree_view->header()->count(); i < end; i++) { | |
191 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
|
192 count++; |
10 | 193 } |
194 | |
195 return count; | |
196 } | |
197 | |
64 | 198 void AnimeListPage::SetColumnDefaults() { |
199 tree_view->setColumnHidden(AnimeListPageModel::AL_SEASON, false); | |
200 tree_view->setColumnHidden(AnimeListPageModel::AL_TYPE, false); | |
201 tree_view->setColumnHidden(AnimeListPageModel::AL_UPDATED, false); | |
202 tree_view->setColumnHidden(AnimeListPageModel::AL_PROGRESS, false); | |
203 tree_view->setColumnHidden(AnimeListPageModel::AL_SCORE, false); | |
204 tree_view->setColumnHidden(AnimeListPageModel::AL_TITLE, false); | |
205 tree_view->setColumnHidden(AnimeListPageModel::AL_EPISODES, true); | |
206 tree_view->setColumnHidden(AnimeListPageModel::AL_AVG_SCORE, true); | |
207 tree_view->setColumnHidden(AnimeListPageModel::AL_STARTED, true); | |
208 tree_view->setColumnHidden(AnimeListPageModel::AL_COMPLETED, true); | |
209 tree_view->setColumnHidden(AnimeListPageModel::AL_UPDATED, true); | |
210 tree_view->setColumnHidden(AnimeListPageModel::AL_NOTES, true); | |
10 | 211 } |
212 | |
77 | 213 void AnimeListPage::UpdateAnime(int id) { |
214 QThreadPool::globalInstance()->start([this, id] { | |
215 Services::UpdateAnimeEntry(id); | |
216 Refresh(); | |
217 }); | |
218 } | |
219 | |
220 void AnimeListPage::RemoveAnime(int id) { | |
221 Anime::Anime& anime = Anime::db.items[id]; | |
222 anime.RemoveFromUserList(); | |
223 Refresh(); | |
224 } | |
225 | |
64 | 226 void AnimeListPage::DisplayColumnHeaderMenu() { |
10 | 227 QMenu* menu = new QMenu(this); |
228 menu->setAttribute(Qt::WA_DeleteOnClose); | |
229 menu->setTitle(tr("Column visibility")); | |
230 menu->setToolTipsVisible(true); | |
231 | |
64 | 232 for (int i = 0; i < AnimeListPageModel::NB_COLUMNS; i++) { |
233 if (i == AnimeListPageModel::AL_TITLE) | |
47
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
234 continue; |
10 | 235 const auto column_name = |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
236 sort_models[tab_bar->currentIndex()]->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString(); |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
237 |
10 | 238 QAction* action = menu->addAction(column_name, this, [this, i](const bool checked) { |
239 if (!checked && (VisibleColumnsCount() <= 1)) | |
240 return; | |
241 | |
242 tree_view->setColumnHidden(i, !checked); | |
243 | |
244 if (checked && (tree_view->columnWidth(i) <= 5)) | |
245 tree_view->resizeColumnToContents(i); | |
246 | |
247 // SaveSettings(); | |
248 }); | |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
249 |
10 | 250 action->setCheckable(true); |
251 action->setChecked(!tree_view->isColumnHidden(i)); | |
252 } | |
253 | |
254 menu->addSeparator(); | |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
255 menu->addAction(tr("Reset to defaults"), this, [this]() { |
10 | 256 for (int i = 0, count = tree_view->header()->count(); i < count; ++i) { |
257 SetColumnDefaults(); | |
258 } | |
259 // SaveSettings(); | |
260 }); | |
261 menu->popup(QCursor::pos()); | |
262 } | |
263 | |
64 | 264 void AnimeListPage::DisplayListMenu() { |
10 | 265 QMenu* menu = new QMenu(this); |
266 menu->setAttribute(Qt::WA_DeleteOnClose); | |
267 menu->setTitle(tr("Column visibility")); | |
268 menu->setToolTipsVisible(true); | |
269 | |
77 | 270 AnimeListPageModel* source_model = |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
271 reinterpret_cast<AnimeListPageModel*>(sort_models[tab_bar->currentIndex()]->sourceModel()); |
15 | 272 const QItemSelection selection = |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
273 sort_models[tab_bar->currentIndex()]->mapSelectionToSource(tree_view->selectionModel()->selection()); |
77 | 274 |
275 std::set<Anime::Anime*> animes; | |
276 for (const auto& index : selection.indexes()) { | |
277 if (!index.isValid()) | |
278 continue; | |
279 Anime::Anime* anime = source_model->GetAnimeFromIndex(index); | |
280 if (anime) | |
281 animes.insert(anime); | |
10 | 282 } |
283 | |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
284 menu->addAction(tr("Information"), [this, animes] { |
77 | 285 for (auto& anime : animes) { |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
286 InformationDialog* dialog = new InformationDialog(*anime, [this, anime] { |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
287 UpdateAnime(anime->GetId()); |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
288 }, InformationDialog::PAGE_MAIN_INFO, this); |
10 | 289 |
77 | 290 dialog->show(); |
291 dialog->raise(); | |
292 dialog->activateWindow(); | |
293 } | |
294 }); | |
295 menu->addSeparator(); | |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
296 menu->addAction(tr("Edit"), [this, animes] { |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
297 for (auto& anime : animes) { |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
298 InformationDialog* dialog = new InformationDialog(*anime, [this, anime] { |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
299 UpdateAnime(anime->GetId()); |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
300 }, InformationDialog::PAGE_MY_LIST, this); |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
301 |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
302 dialog->show(); |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
303 dialog->raise(); |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
304 dialog->activateWindow(); |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
305 } |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
306 }); |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
307 menu->addAction(tr("Delete from list..."), [this, animes] { |
77 | 308 for (auto& anime : animes) { |
309 RemoveAnime(anime->GetId()); | |
310 } | |
10 | 311 }); |
312 menu->popup(QCursor::pos()); | |
313 } | |
314 | |
64 | 315 void AnimeListPage::ItemDoubleClicked() { |
10 | 316 /* throw out any other garbage */ |
317 const QItemSelection selection = | |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
318 sort_models[tab_bar->currentIndex()]->mapSelectionToSource(tree_view->selectionModel()->selection()); |
10 | 319 if (!selection.indexes().first().isValid()) { |
320 return; | |
321 } | |
322 | |
64 | 323 AnimeListPageModel* source_model = |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
324 reinterpret_cast<AnimeListPageModel*>(sort_models[tab_bar->currentIndex()]->sourceModel()); |
64 | 325 |
326 const QModelIndex index = source_model->index(selection.indexes().first().row()); | |
327 Anime::Anime* anime = source_model->GetAnimeFromIndex(index); | |
10 | 328 |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
329 InformationDialog* dialog = new InformationDialog(*anime, [this, anime] { |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
330 UpdateAnime(anime->GetId()); |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
331 }, InformationDialog::PAGE_MAIN_INFO, this); |
10 | 332 |
333 dialog->show(); | |
334 dialog->raise(); | |
335 dialog->activateWindow(); | |
336 } | |
337 | |
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
338 void AnimeListPage::RefreshList() { |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
339 for (unsigned int i = 0; i < sort_models.size(); i++) |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
340 reinterpret_cast<AnimeListPageModel*>(sort_models[i]->sourceModel())->RefreshList(); |
10 | 341 } |
342 | |
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
343 void AnimeListPage::RefreshTabs() { |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
344 for (unsigned int i = 0; i < sort_models.size(); i++) |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
345 tab_bar->setTabText(i, Strings::ToQString(Translate::ToString(Anime::ListStatuses[i])) + " (" + |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
346 QString::number(Anime::db.GetListsAnimeAmount(Anime::ListStatuses[i])) + ")"); |
10 | 347 } |
348 | |
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
349 void AnimeListPage::Refresh() { |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
350 RefreshList(); |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
351 RefreshTabs(); |
10 | 352 } |
353 | |
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
354 /* -------- QTabWidget replication begin --------- */ |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
355 |
64 | 356 void AnimeListPage::InitBasicStyle(QStyleOptionTabWidgetFrame* option) const { |
10 | 357 if (!option) |
358 return; | |
359 | |
360 option->initFrom(this); | |
361 option->lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, this); | |
362 option->shape = QTabBar::RoundedNorth; | |
363 option->tabBarRect = tab_bar->geometry(); | |
364 } | |
365 | |
64 | 366 void AnimeListPage::InitStyle(QStyleOptionTabWidgetFrame* option) const { |
10 | 367 if (!option) |
368 return; | |
369 | |
370 InitBasicStyle(option); | |
371 | |
372 QSize t(0, tree_view->frameWidth()); | |
373 if (tab_bar->isVisibleTo(this)) { | |
374 t = tab_bar->sizeHint(); | |
375 t.setWidth(width()); | |
376 } | |
46 | 377 |
10 | 378 option->tabBarSize = t; |
379 | |
380 QRect selected_tab_rect = tab_bar->tabRect(tab_bar->currentIndex()); | |
381 selected_tab_rect.moveTopLeft(selected_tab_rect.topLeft() + option->tabBarRect.topLeft()); | |
382 option->selectedTabRect = selected_tab_rect; | |
383 | |
384 option->lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, this); | |
385 } | |
386 | |
64 | 387 void AnimeListPage::SetupLayout() { |
10 | 388 QStyleOptionTabWidgetFrame option; |
389 InitStyle(&option); | |
390 | |
391 QRect tabRect = style()->subElementRect(QStyle::SE_TabWidgetTabBar, &option, this); | |
392 tabRect.setLeft(tabRect.left() + 1); | |
393 panelRect = style()->subElementRect(QStyle::SE_TabWidgetTabPane, &option, this); | |
394 QRect contentsRect = style()->subElementRect(QStyle::SE_TabWidgetTabContents, &option, this); | |
395 | |
396 tab_bar->setGeometry(tabRect); | |
397 tree_view->parentWidget()->setGeometry(contentsRect); | |
398 } | |
399 | |
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
400 void AnimeListPage::paintEvent(QPaintEvent*) { |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
401 QStylePainter p(this); |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
402 |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
403 QStyleOptionTabWidgetFrame opt; |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
404 InitStyle(&opt); |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
405 opt.rect = panelRect; |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
406 p.drawPrimitive(QStyle::PE_FrameTabWidget, opt); |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
407 } |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
408 |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
409 void AnimeListPage::resizeEvent(QResizeEvent* e) { |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
410 QWidget::resizeEvent(e); |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
411 SetupLayout(); |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
412 } |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
413 |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
414 void AnimeListPage::showEvent(QShowEvent*) { |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
415 SetupLayout(); |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
416 } |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
417 |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
418 /* --------- QTabWidget replication end ---------- */ |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
419 |
64 | 420 AnimeListPage::AnimeListPage(QWidget* parent) : QWidget(parent) { |
10 | 421 /* Tab bar */ |
422 tab_bar = new QTabBar(this); | |
423 tab_bar->setExpanding(false); | |
424 tab_bar->setDrawBase(false); | |
425 | |
426 /* Tree view... */ | |
427 QWidget* tree_widget = new QWidget(this); | |
428 tree_view = new QTreeView(tree_widget); | |
429 tree_view->setUniformRowHeights(true); | |
430 tree_view->setAllColumnsShowFocus(false); | |
431 tree_view->setAlternatingRowColors(true); | |
432 tree_view->setSortingEnabled(true); | |
433 tree_view->setSelectionMode(QAbstractItemView::ExtendedSelection); | |
434 tree_view->setItemsExpandable(false); | |
435 tree_view->setRootIsDecorated(false); | |
436 tree_view->setContextMenuPolicy(Qt::CustomContextMenu); | |
437 tree_view->setFrameShape(QFrame::NoFrame); | |
438 | |
83 | 439 for (unsigned int i = 0; i < sort_models.size(); i++) { |
65
26721c28bf22
*: avoid usage of (to|from)StdString
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
440 tab_bar->addTab(Strings::ToQString(Translate::ToString(Anime::ListStatuses[i])) + " (" + |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
441 QString::number(Anime::db.GetListsAnimeAmount(Anime::ListStatuses[i])) + ")"); |
64 | 442 sort_models[i] = new AnimeListPageSortFilter(tree_view); |
443 sort_models[i]->setSourceModel(new AnimeListPageModel(this, Anime::ListStatuses[i])); | |
10 | 444 sort_models[i]->setSortRole(Qt::UserRole); |
445 sort_models[i]->setSortCaseSensitivity(Qt::CaseInsensitive); | |
446 } | |
15 | 447 tree_view->setModel(sort_models[0]); |
10 | 448 |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
65
diff
changeset
|
449 QHBoxLayout* layout = new QHBoxLayout(tree_widget); |
10 | 450 layout->addWidget(tree_view); |
62 | 451 layout->setContentsMargins(0, 0, 0, 0); |
10 | 452 |
453 /* Double click stuff */ | |
64 | 454 connect(tree_view, &QAbstractItemView::doubleClicked, this, &AnimeListPage::ItemDoubleClicked); |
455 connect(tree_view, &QWidget::customContextMenuRequested, this, &AnimeListPage::DisplayListMenu); | |
10 | 456 |
457 /* Enter & return keys */ | |
15 | 458 connect(new QShortcut(Qt::Key_Return, tree_view, nullptr, nullptr, Qt::WidgetShortcut), &QShortcut::activated, this, |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
459 &AnimeListPage::ItemDoubleClicked); |
10 | 460 |
15 | 461 connect(new QShortcut(Qt::Key_Enter, tree_view, nullptr, nullptr, Qt::WidgetShortcut), &QShortcut::activated, this, |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
462 &AnimeListPage::ItemDoubleClicked); |
10 | 463 |
464 tree_view->header()->setStretchLastSection(false); | |
465 tree_view->header()->setContextMenuPolicy(Qt::CustomContextMenu); | |
64 | 466 connect(tree_view->header(), &QWidget::customContextMenuRequested, this, &AnimeListPage::DisplayColumnHeaderMenu); |
10 | 467 |
468 connect(tab_bar, &QTabBar::currentChanged, this, [this](int index) { | |
469 if (sort_models[index]) | |
470 tree_view->setModel(sort_models[index]); | |
471 }); | |
472 | |
69 | 473 SetColumnDefaults(); |
10 | 474 setFocusPolicy(Qt::TabFocus); |
475 setFocusProxy(tab_bar); | |
112
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
476 |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
477 Refresh(); |
10 | 478 } |
479 | |
480 #include "gui/pages/moc_anime_list.cpp" |