annotate src/gui/pages/anime_list.cc @ 253:b3549da699a6

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