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