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