Mercurial > minori
annotate src/gui/pages/anime_list.cc @ 370:ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
author | Paper <paper@tflc.us> |
---|---|
date | Fri, 25 Jul 2025 10:22:04 -0400 |
parents | 886f66775f31 |
children | f7bb2978de48 |
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" | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
19 #include "library/library.h" |
52
0c4138de2ea7
anime list: we are finally read-write
Paper <mrpapersonic@gmail.com>
parents:
51
diff
changeset
|
20 #include "services/services.h" |
178
bc8d2ccff09c
win32/dark: use existing STL classes for dwmapi
Paper <mrpapersonic@gmail.com>
parents:
118
diff
changeset
|
21 |
187
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
185
diff
changeset
|
22 #include <QDate> |
15 | 23 #include <QDebug> |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
24 #include <QDesktopServices> |
10 | 25 #include <QHBoxLayout> |
26 #include <QHeaderView> | |
27 #include <QMenu> | |
28 #include <QProgressBar> | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
29 #include <QRunnable> |
10 | 30 #include <QShortcut> |
31 #include <QStylePainter> | |
32 #include <QStyledItemDelegate> | |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
33 #include <QThreadPool> |
258 | 34 #include <QTreeView> |
366
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
35 #include <QUrl> |
178
bc8d2ccff09c
win32/dark: use existing STL classes for dwmapi
Paper <mrpapersonic@gmail.com>
parents:
118
diff
changeset
|
36 |
366
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
37 #include <iostream> |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
38 #include <vector> |
10 | 39 |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
40 AnimeListPageUpdateEntryThread::AnimeListPageUpdateEntryThread(QObject *parent) : QThread(parent) |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
41 { |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
42 } |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
43 |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
44 void AnimeListPageUpdateEntryThread::AddToQueue(int id) |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
45 { |
320
1b5c04268d6a
services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
46 const std::lock_guard<std::mutex> guard(queue_mutex_); |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
47 queue_.push(id); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
48 } |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
49 |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
50 /* processes the queue... */ |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
51 void AnimeListPageUpdateEntryThread::run() |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
52 { |
320
1b5c04268d6a
services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
53 queue_mutex_.lock(); |
1b5c04268d6a
services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
54 while (!queue_.empty() && !isInterruptionRequested()) { |
1b5c04268d6a
services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
55 int id = queue_.front(); |
1b5c04268d6a
services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
56 |
1b5c04268d6a
services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
57 /* unlock the mutex for a long blocking operation, so items |
1b5c04268d6a
services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
58 * can be added without worry */ |
1b5c04268d6a
services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
59 queue_mutex_.unlock(); |
1b5c04268d6a
services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
60 Services::UpdateAnimeEntry(id); |
1b5c04268d6a
services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
61 queue_mutex_.lock(); |
1b5c04268d6a
services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
62 |
1b5c04268d6a
services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
63 queue_.pop(); |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
64 } |
320
1b5c04268d6a
services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
65 queue_mutex_.unlock(); |
1b5c04268d6a
services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
66 |
307
8769c5d50b06
pages/anime_list: don't call GUI functions in a non-GUI thread
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
67 emit NeedRefresh(); |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
68 } |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
69 |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
70 AnimeListPageSortFilter::AnimeListPageSortFilter(QObject *parent) : QSortFilterProxyModel(parent) |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
71 { |
10 | 72 } |
73 | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
74 bool AnimeListPageSortFilter::lessThan(const QModelIndex &l, const QModelIndex &r) const |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
75 { |
10 | 76 QVariant left = sourceModel()->data(l, sortRole()); |
77 QVariant right = sourceModel()->data(r, sortRole()); | |
78 | |
79 switch (left.userType()) { | |
80 case QMetaType::Int: | |
81 case QMetaType::UInt: | |
82 case QMetaType::LongLong: | |
83 case QMetaType::ULongLong: return left.toInt() < right.toInt(); | |
84 case QMetaType::QDate: return left.toDate() < right.toDate(); | |
85 case QMetaType::QString: | |
86 default: return QString::compare(left.toString(), right.toString(), Qt::CaseInsensitive) < 0; | |
87 } | |
88 } | |
89 | |
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
90 /* -------------------------------------------------- */ |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
91 |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
92 AnimeListPageModel::AnimeListPageModel(QObject *parent, Anime::ListStatus _status) : QAbstractListModel(parent) |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
93 { |
10 | 94 status = _status; |
95 return; | |
96 } | |
97 | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
98 int AnimeListPageModel::rowCount(const QModelIndex &parent) const |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
99 { |
10 | 100 return list.size(); |
101 (void)(parent); | |
102 } | |
103 | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
104 int AnimeListPageModel::columnCount(const QModelIndex &parent) const |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
105 { |
10 | 106 return NB_COLUMNS; |
107 (void)(parent); | |
108 } | |
109 | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
110 QVariant AnimeListPageModel::headerData(const int section, const Qt::Orientation orientation, const int role) const |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
111 { |
10 | 112 if (role == Qt::DisplayRole) { |
113 switch (section) { | |
47
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
114 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 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
|
123 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
|
124 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
|
125 default: return {}; |
10 | 126 } |
127 } else if (role == Qt::TextAlignmentRole) { | |
128 switch (section) { | |
47
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
129 case AL_TITLE: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
130 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
|
131 case AL_PROGRESS: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
132 case AL_EPISODES: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
133 case AL_TYPE: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
134 case AL_SCORE: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
135 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
|
136 case AL_SEASON: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
137 case AL_STARTED: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
138 case AL_COMPLETED: |
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(Qt::AlignRight | Qt::AlignVCenter); |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
140 default: return QAbstractListModel::headerData(section, orientation, role); |
10 | 141 } |
142 } | |
143 return QAbstractListModel::headerData(section, orientation, role); | |
144 } | |
145 | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
146 QVariant AnimeListPageModel::data(const QModelIndex &index, int role) const |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
147 { |
10 | 148 if (!index.isValid()) |
149 return QVariant(); | |
150 switch (role) { | |
151 case Qt::DisplayRole: | |
47
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
152 switch (index.column()) { |
185
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
178
diff
changeset
|
153 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
|
154 case AL_PROGRESS: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
155 return QString::number(list[index.row()].GetUserProgress()) + "/" + |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
156 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
|
157 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
|
158 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
|
159 case AL_TYPE: return Strings::ToQString(Translate::ToString(list[index.row()].GetFormat())); |
327
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
160 case AL_SEASON: return Strings::ToQString(Translate::ToLocalString(list[index.row()].GetSeason())); |
47
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
161 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
|
162 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
|
163 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
|
164 case AL_UPDATED: { |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
165 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
|
166 return QString("-"); |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
167 return Strings::ToQString(Time::GetSecondsAsRelativeString(Time::GetSystemTime() - |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
168 list[index.row()].GetUserTimeUpdated())); |
47
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
169 } |
185
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
178
diff
changeset
|
170 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
|
171 default: return ""; |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
172 } |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
173 break; |
10 | 174 case Qt::UserRole: |
47
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
175 switch (index.column()) { |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
176 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
|
177 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
|
178 case AL_TYPE: return static_cast<int>(list[index.row()].GetFormat()); |
324
5d3c9b31aa6e
anime: add completed date member
Paper <paper@paper.us.eu.org>
parents:
320
diff
changeset
|
179 case AL_SEASON: return list[index.row()].GetStartedDate().GetAsQDate(); |
47
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
180 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
|
181 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
|
182 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
|
183 } |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
184 break; |
10 | 185 case Qt::TextAlignmentRole: |
47
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
186 switch (index.column()) { |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
187 case AL_TITLE: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
188 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
|
189 case AL_PROGRESS: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
190 case AL_EPISODES: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
191 case AL_TYPE: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
192 case AL_SCORE: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
193 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
|
194 case AL_SEASON: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
195 case AL_STARTED: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
196 case AL_COMPLETED: |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
197 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
|
198 default: break; |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
199 } |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
200 break; |
10 | 201 } |
202 return QVariant(); | |
203 } | |
204 | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
205 Anime::Anime *AnimeListPageModel::GetAnimeFromIndex(QModelIndex index) |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
206 { |
10 | 207 return &list.at(index.row()); |
208 } | |
209 | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
210 void AnimeListPageModel::RefreshList() |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
211 { |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
212 /* equivalent to hasChildren()... */ |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
213 if (!rowCount(index(0))) { |
77 | 214 beginInsertRows(QModelIndex(), 0, 0); |
215 endInsertRows(); | |
15 | 216 } |
217 | |
77 | 218 beginResetModel(); |
219 | |
10 | 220 list.clear(); |
221 | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
222 for (const auto &a : Anime::db.items) |
305
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
223 if (a.second.IsInUserList() && a.second.GetUserStatus() == status) |
47
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
224 list.push_back(a.second); |
15 | 225 |
77 | 226 endResetModel(); |
10 | 227 } |
228 | |
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
229 /* ----------------------------------------------------------------- */ |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
230 |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
231 int AnimeListPage::VisibleColumnsCount() const |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
232 { |
10 | 233 int count = 0; |
234 | |
235 for (int i = 0, end = tree_view->header()->count(); i < end; i++) { | |
236 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
|
237 count++; |
10 | 238 } |
239 | |
240 return count; | |
241 } | |
242 | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
243 void AnimeListPage::SetColumnDefaults() |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
244 { |
64 | 245 tree_view->setColumnHidden(AnimeListPageModel::AL_SEASON, false); |
246 tree_view->setColumnHidden(AnimeListPageModel::AL_TYPE, false); | |
247 tree_view->setColumnHidden(AnimeListPageModel::AL_UPDATED, false); | |
248 tree_view->setColumnHidden(AnimeListPageModel::AL_PROGRESS, false); | |
249 tree_view->setColumnHidden(AnimeListPageModel::AL_SCORE, false); | |
250 tree_view->setColumnHidden(AnimeListPageModel::AL_TITLE, false); | |
251 tree_view->setColumnHidden(AnimeListPageModel::AL_EPISODES, true); | |
252 tree_view->setColumnHidden(AnimeListPageModel::AL_AVG_SCORE, true); | |
253 tree_view->setColumnHidden(AnimeListPageModel::AL_STARTED, true); | |
254 tree_view->setColumnHidden(AnimeListPageModel::AL_COMPLETED, true); | |
255 tree_view->setColumnHidden(AnimeListPageModel::AL_UPDATED, true); | |
256 tree_view->setColumnHidden(AnimeListPageModel::AL_NOTES, true); | |
10 | 257 } |
258 | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
259 void AnimeListPage::UpdateAnime(int id) |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
260 { |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
261 /* this ought to just add to the thread's buffer. */ |
274
f6a756c19bfb
anime_list.cc: use mutexes so we don't sex the stack
Paper <paper@paper.us.eu.org>
parents:
273
diff
changeset
|
262 if (update_entry_thread_.isRunning()) |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
263 update_entry_thread_.requestInterruption(); |
230
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
211
diff
changeset
|
264 |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
265 update_entry_thread_.AddToQueue(id); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
266 update_entry_thread_.start(); |
77 | 267 } |
268 | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
269 void AnimeListPage::RemoveAnime(int id) |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
270 { |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
271 Anime::Anime &anime = Anime::db.items[id]; |
77 | 272 anime.RemoveFromUserList(); |
273 Refresh(); | |
274 } | |
275 | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
276 void AnimeListPage::DisplayColumnHeaderMenu() |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
277 { |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
278 QMenu *menu = new QMenu(this); |
10 | 279 menu->setAttribute(Qt::WA_DeleteOnClose); |
280 menu->setTitle(tr("Column visibility")); | |
281 menu->setToolTipsVisible(true); | |
282 | |
64 | 283 for (int i = 0; i < AnimeListPageModel::NB_COLUMNS; i++) { |
284 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
|
285 continue; |
10 | 286 const auto column_name = |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
287 sort_models[tab_bar->currentIndex()]->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString(); |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
288 |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
289 QAction *action = menu->addAction(column_name, this, [this, i](const bool checked) { |
10 | 290 if (!checked && (VisibleColumnsCount() <= 1)) |
291 return; | |
292 | |
293 tree_view->setColumnHidden(i, !checked); | |
294 | |
295 if (checked && (tree_view->columnWidth(i) <= 5)) | |
296 tree_view->resizeColumnToContents(i); | |
297 | |
366
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
298 // FIXME save the state of this |
10 | 299 }); |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
300 |
10 | 301 action->setCheckable(true); |
302 action->setChecked(!tree_view->isColumnHidden(i)); | |
303 } | |
304 | |
305 menu->addSeparator(); | |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
306 menu->addAction(tr("Reset to defaults"), this, [this]() { |
10 | 307 for (int i = 0, count = tree_view->header()->count(); i < count; ++i) { |
308 SetColumnDefaults(); | |
309 } | |
310 // SaveSettings(); | |
311 }); | |
312 menu->popup(QCursor::pos()); | |
313 } | |
314 | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
315 void AnimeListPage::DisplayListMenu() |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
316 { |
366
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
317 QMenu *const menu = new QMenu(this); |
10 | 318 menu->setAttribute(Qt::WA_DeleteOnClose); |
319 menu->setToolTipsVisible(true); | |
320 | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
321 AnimeListPageModel *source_model = |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
322 reinterpret_cast<AnimeListPageModel *>(sort_models[tab_bar->currentIndex()]->sourceModel()); |
15 | 323 const QItemSelection selection = |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
324 sort_models[tab_bar->currentIndex()]->mapSelectionToSource(tree_view->selectionModel()->selection()); |
77 | 325 |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
326 std::set<Anime::Anime *> animes; |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
327 for (const auto &index : selection.indexes()) { |
77 | 328 if (!index.isValid()) |
329 continue; | |
366
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
330 |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
331 Anime::Anime *const anime = source_model->GetAnimeFromIndex(index); |
315
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
307
diff
changeset
|
332 if (!anime) |
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
307
diff
changeset
|
333 continue; |
366
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
334 |
315
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
307
diff
changeset
|
335 animes.insert(&Anime::db.items[anime->GetId()]); |
10 | 336 } |
337 | |
366
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
338 if (animes.size() > 1) { |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
339 // menu in Taiga: |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
340 // |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
341 // Set date started -> |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
342 // Clear |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
343 // Set to date started airing |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
344 // Set date completed -> |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
345 // Clear |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
346 // Set to date finished airing |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
347 // Set to last updated |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
348 // Set episode... |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
349 // Set score -> |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
350 // 0 |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
351 // 10 |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
352 // ... |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
353 // 100 |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
354 // Set status -> |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
355 // Currently watching |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
356 // ... |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
357 // Plan to watch |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
358 // Set notes... |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
359 // ---------------- |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
360 // Invert selection |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
361 // ---------------- |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
362 // Delete from list... <Del> |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
363 } else if (animes.size() > 0) { |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
364 // menu in Taiga: |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
365 // |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
366 // Information |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
367 // Search -> |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
368 // AniDB |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
369 // AniList |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
370 // Anime News Network |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
371 // Kitsu |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
372 // MyAnimeList |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
373 // Reddit |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
374 // Wikipedia |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
375 // YouTube |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
376 // ---------------- |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
377 // Custom RSS feed |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
378 // Nyaa.si |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
379 // ---------------- |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
380 // Edit |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
381 // Delete from list... <Del> |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
382 // ---------------- |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
383 // Open folder <Ctrl+O> |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
384 // Scan available episodes <F5> |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
385 // ---------------- |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
386 // Play episode -> |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
387 // grid of episodes (dunno how to implement this) |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
388 // Play last episode (#<episode>) |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
389 // Play next episode (#<episode>) <Ctrl+N> |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
390 // Play random episode <Ctrl+R> (why?) |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
391 |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
392 Anime::Anime *anime = *animes.begin(); |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
393 |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
394 menu->addAction(tr("Information"), [this, anime] { |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
395 InformationDialog *dialog = new InformationDialog( |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
396 anime, [this](Anime::Anime *anime) { UpdateAnime(anime->GetId()); }, InformationDialog::PAGE_MAIN_INFO, |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
397 this); |
10 | 398 |
77 | 399 dialog->show(); |
400 dialog->raise(); | |
401 dialog->activateWindow(); | |
291 | 402 connect(dialog, &InformationDialog::finished, dialog, &InformationDialog::deleteLater); |
366
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
403 }); |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
404 |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
405 menu->addSeparator(); |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
406 |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
407 menu->addAction(tr("Edit"), [this, anime] { |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
408 InformationDialog *dialog = new InformationDialog( |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
409 anime, [this](Anime::Anime *anime) { UpdateAnime(anime->GetId()); }, InformationDialog::PAGE_MY_LIST, |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
410 this); |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
411 |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
412 dialog->show(); |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
413 dialog->raise(); |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
414 dialog->activateWindow(); |
291 | 415 connect(dialog, &InformationDialog::finished, dialog, &InformationDialog::deleteLater); |
366
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
416 }); |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
417 menu->addAction( |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
418 tr("Delete from list..."), [this, anime] { RemoveAnime(anime->GetId()); }, |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
419 QKeySequence(QKeySequence::Delete)); |
366
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
420 |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
421 menu->addSeparator(); |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
422 |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
423 menu->addAction(tr("Open folder"), [this, anime] { |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
424 std::optional<std::filesystem::path> path = Library::db.GetAnimeFolder(anime->GetId()); |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
425 if (!path) // ... |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
426 return; |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
427 |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
428 QDesktopServices::openUrl(QUrl::fromLocalFile(Strings::ToQString(path.value().u8string()))); |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
429 }); |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
430 menu->addAction(tr("Scan available episodes"), [this, anime] { Library::db.Refresh(anime->GetId()); }); |
366
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
431 |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
432 menu->addSeparator(); |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
433 |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
434 { |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
435 QMenu *submenu = menu->addMenu(tr("Play episode")); |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
436 |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
437 // this submenu actually uses win32 API magic to |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
438 // make a *grid* of episodes (weird!) |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
439 |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
440 (void)submenu; |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
441 } |
366
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
442 |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
443 const int progress = anime->GetUserProgress(); |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
444 const int episodes = anime->GetEpisodes(); |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
445 |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
446 // I think this is right? |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
447 if (progress > 0) { |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
448 menu->addAction(tr("Play last episode (#%1)").arg(progress), [this, anime, progress] { |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
449 const int id = anime->GetId(); |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
450 |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
451 if (Library::db.items.find(id) == Library::db.items.end() || |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
452 Library::db.items[id].find(progress) == Library::db.items[id].end()) |
366
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
453 return; |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
454 |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
455 QDesktopServices::openUrl( |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
456 QUrl::fromLocalFile(Strings::ToQString(Library::db.items[id][progress].u8string()))); |
366
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
457 }); |
77 | 458 } |
366
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
459 |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
460 if (progress < episodes) { |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
461 menu->addAction( |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
462 tr("Play next episode (#%1)").arg(progress + 1), |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
463 [this, anime, progress] { |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
464 const int id = anime->GetId(); |
366
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
465 |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
466 if (Library::db.items.find(id) == Library::db.items.end() || |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
467 Library::db.items[id].find(progress + 1) == Library::db.items[id].end()) |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
468 return; |
366
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
469 |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
470 QDesktopServices::openUrl( |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
471 QUrl::fromLocalFile(Strings::ToQString(Library::db.items[id][progress + 1].u8string()))); |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
472 }, |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
473 QKeySequence(Qt::CTRL | Qt::Key_N)); |
366
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
474 } |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
475 |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
476 menu->addAction( |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
477 tr("Play random episode"), |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
478 [this, anime, episodes] { |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
479 const int id = anime->GetId(); |
366
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
480 |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
481 std::uniform_int_distribution<int> distrib(1, episodes); |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
482 const int episode = distrib(session.gen); |
366
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
483 |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
484 if (Library::db.items.find(id) == Library::db.items.end() || |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
485 Library::db.items[id].find(episode) == Library::db.items[id].end()) |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
486 return; |
366
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
487 |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
488 QDesktopServices::openUrl( |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
489 QUrl::fromLocalFile(Strings::ToQString(Library::db.items[id][episode].u8string()))); |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
490 }, |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
491 QKeySequence(Qt::CTRL | Qt::Key_R)); |
366
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
492 |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
493 menu->popup(QCursor::pos()); |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
494 } else { |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
495 // Where are we now? |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
327
diff
changeset
|
496 } |
10 | 497 } |
498 | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
499 void AnimeListPage::ItemDoubleClicked() |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
500 { |
10 | 501 /* throw out any other garbage */ |
502 const QItemSelection selection = | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
503 sort_models[tab_bar->currentIndex()]->mapSelectionToSource(tree_view->selectionModel()->selection()); |
10 | 504 if (!selection.indexes().first().isValid()) { |
505 return; | |
506 } | |
507 | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
508 AnimeListPageModel *source_model = |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
509 reinterpret_cast<AnimeListPageModel *>(sort_models[tab_bar->currentIndex()]->sourceModel()); |
64 | 510 |
511 const QModelIndex index = source_model->index(selection.indexes().first().row()); | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
512 Anime::Anime &anime = Anime::db.items[source_model->GetAnimeFromIndex(index)->GetId()]; |
10 | 513 |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
514 InformationDialog *dialog = new InformationDialog( |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
515 &anime, [this](Anime::Anime *anime) { UpdateAnime(anime->GetId()); }, InformationDialog::PAGE_MAIN_INFO, this); |
10 | 516 |
517 dialog->show(); | |
518 dialog->raise(); | |
519 dialog->activateWindow(); | |
291 | 520 connect(dialog, &InformationDialog::finished, dialog, &InformationDialog::deleteLater); |
10 | 521 } |
522 | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
523 void AnimeListPage::RefreshList() |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
524 { |
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
525 for (unsigned int i = 0; i < sort_models.size(); i++) |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
526 reinterpret_cast<AnimeListPageModel *>(sort_models[i]->sourceModel())->RefreshList(); |
10 | 527 } |
528 | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
529 void AnimeListPage::RefreshTabs() |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
530 { |
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
531 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
|
532 tab_bar->setTabText(i, Strings::ToQString(Translate::ToString(Anime::ListStatuses[i])) + " (" + |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
533 QString::number(Anime::db.GetListsAnimeAmount(Anime::ListStatuses[i])) + ")"); |
10 | 534 } |
535 | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
536 void AnimeListPage::Refresh() |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
537 { |
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
538 RefreshList(); |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
539 RefreshTabs(); |
10 | 540 } |
541 | |
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
542 /* -------- QTabWidget replication begin --------- */ |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
543 |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
544 void AnimeListPage::InitBasicStyle(QStyleOptionTabWidgetFrame *option) const |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
545 { |
10 | 546 if (!option) |
547 return; | |
548 | |
549 option->initFrom(this); | |
550 option->lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, this); | |
551 option->shape = QTabBar::RoundedNorth; | |
552 option->tabBarRect = tab_bar->geometry(); | |
553 } | |
554 | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
555 void AnimeListPage::InitStyle(QStyleOptionTabWidgetFrame *option) const |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
556 { |
10 | 557 if (!option) |
558 return; | |
559 | |
560 InitBasicStyle(option); | |
561 | |
562 QSize t(0, tree_view->frameWidth()); | |
563 if (tab_bar->isVisibleTo(this)) { | |
564 t = tab_bar->sizeHint(); | |
565 t.setWidth(width()); | |
566 } | |
46 | 567 |
10 | 568 option->tabBarSize = t; |
569 | |
570 QRect selected_tab_rect = tab_bar->tabRect(tab_bar->currentIndex()); | |
571 selected_tab_rect.moveTopLeft(selected_tab_rect.topLeft() + option->tabBarRect.topLeft()); | |
572 option->selectedTabRect = selected_tab_rect; | |
573 | |
574 option->lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, this); | |
575 } | |
576 | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
577 void AnimeListPage::SetupLayout() |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
578 { |
10 | 579 QStyleOptionTabWidgetFrame option; |
580 InitStyle(&option); | |
581 | |
582 QRect tabRect = style()->subElementRect(QStyle::SE_TabWidgetTabBar, &option, this); | |
583 tabRect.setLeft(tabRect.left() + 1); | |
584 panelRect = style()->subElementRect(QStyle::SE_TabWidgetTabPane, &option, this); | |
585 QRect contentsRect = style()->subElementRect(QStyle::SE_TabWidgetTabContents, &option, this); | |
586 | |
587 tab_bar->setGeometry(tabRect); | |
588 tree_view->parentWidget()->setGeometry(contentsRect); | |
589 } | |
590 | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
591 void AnimeListPage::paintEvent(QPaintEvent *) |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
592 { |
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
593 QStylePainter p(this); |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
594 |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
595 QStyleOptionTabWidgetFrame opt; |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
596 InitStyle(&opt); |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
597 opt.rect = panelRect; |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
598 p.drawPrimitive(QStyle::PE_FrameTabWidget, opt); |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
599 } |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
600 |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
601 void AnimeListPage::resizeEvent(QResizeEvent *e) |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
602 { |
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
603 QWidget::resizeEvent(e); |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
604 SetupLayout(); |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
605 } |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
606 |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
607 void AnimeListPage::showEvent(QShowEvent *) |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
608 { |
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
609 SetupLayout(); |
250 | 610 Refresh(); |
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
611 } |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
612 |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
613 /* --------- QTabWidget replication end ---------- */ |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
614 |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
615 AnimeListPage::AnimeListPage(QWidget *parent) : QWidget(parent) |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
616 { |
10 | 617 /* Tab bar */ |
618 tab_bar = new QTabBar(this); | |
619 tab_bar->setExpanding(false); | |
620 tab_bar->setDrawBase(false); | |
621 | |
622 /* Tree view... */ | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
623 QWidget *tree_widget = new QWidget(this); |
10 | 624 tree_view = new QTreeView(tree_widget); |
625 tree_view->setUniformRowHeights(true); | |
626 tree_view->setAllColumnsShowFocus(false); | |
627 tree_view->setAlternatingRowColors(true); | |
628 tree_view->setSortingEnabled(true); | |
629 tree_view->setSelectionMode(QAbstractItemView::ExtendedSelection); | |
630 tree_view->setItemsExpandable(false); | |
631 tree_view->setRootIsDecorated(false); | |
632 tree_view->setContextMenuPolicy(Qt::CustomContextMenu); | |
633 tree_view->setFrameShape(QFrame::NoFrame); | |
634 | |
83 | 635 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
|
636 tab_bar->addTab(Strings::ToQString(Translate::ToString(Anime::ListStatuses[i])) + " (" + |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
637 QString::number(Anime::db.GetListsAnimeAmount(Anime::ListStatuses[i])) + ")"); |
64 | 638 sort_models[i] = new AnimeListPageSortFilter(tree_view); |
639 sort_models[i]->setSourceModel(new AnimeListPageModel(this, Anime::ListStatuses[i])); | |
10 | 640 sort_models[i]->setSortRole(Qt::UserRole); |
641 sort_models[i]->setSortCaseSensitivity(Qt::CaseInsensitive); | |
642 } | |
236
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
232
diff
changeset
|
643 |
15 | 644 tree_view->setModel(sort_models[0]); |
10 | 645 |
236
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
232
diff
changeset
|
646 /* Set column widths */ |
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
232
diff
changeset
|
647 tree_view->setColumnWidth(AnimeListPageModel::AL_TITLE, 300); |
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
232
diff
changeset
|
648 tree_view->setColumnWidth(AnimeListPageModel::AL_PROGRESS, 200); |
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
232
diff
changeset
|
649 tree_view->setColumnWidth(AnimeListPageModel::AL_SCORE, 50); |
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
232
diff
changeset
|
650 tree_view->setColumnWidth(AnimeListPageModel::AL_AVG_SCORE, 55); |
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
232
diff
changeset
|
651 tree_view->setColumnWidth(AnimeListPageModel::AL_TYPE, 65); |
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
232
diff
changeset
|
652 tree_view->setColumnWidth(AnimeListPageModel::AL_SEASON, 95); |
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
232
diff
changeset
|
653 tree_view->setColumnWidth(AnimeListPageModel::AL_STARTED, 90); |
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
232
diff
changeset
|
654 tree_view->setColumnWidth(AnimeListPageModel::AL_COMPLETED, 90); |
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
232
diff
changeset
|
655 tree_view->setColumnWidth(AnimeListPageModel::AL_UPDATED, 100); |
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
232
diff
changeset
|
656 tree_view->setColumnWidth(AnimeListPageModel::AL_NOTES, 100); |
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
232
diff
changeset
|
657 |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
658 QHBoxLayout *layout = new QHBoxLayout(tree_widget); |
10 | 659 layout->addWidget(tree_view); |
62 | 660 layout->setContentsMargins(0, 0, 0, 0); |
10 | 661 |
662 /* Double click stuff */ | |
64 | 663 connect(tree_view, &QAbstractItemView::doubleClicked, this, &AnimeListPage::ItemDoubleClicked); |
664 connect(tree_view, &QWidget::customContextMenuRequested, this, &AnimeListPage::DisplayListMenu); | |
10 | 665 |
666 /* Enter & return keys */ | |
15 | 667 connect(new QShortcut(Qt::Key_Return, tree_view, nullptr, nullptr, Qt::WidgetShortcut), &QShortcut::activated, this, |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
668 &AnimeListPage::ItemDoubleClicked); |
10 | 669 |
15 | 670 connect(new QShortcut(Qt::Key_Enter, tree_view, nullptr, nullptr, Qt::WidgetShortcut), &QShortcut::activated, this, |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
366
diff
changeset
|
671 &AnimeListPage::ItemDoubleClicked); |
10 | 672 |
673 tree_view->header()->setStretchLastSection(false); | |
674 tree_view->header()->setContextMenuPolicy(Qt::CustomContextMenu); | |
64 | 675 connect(tree_view->header(), &QWidget::customContextMenuRequested, this, &AnimeListPage::DisplayColumnHeaderMenu); |
10 | 676 |
677 connect(tab_bar, &QTabBar::currentChanged, this, [this](int index) { | |
678 if (sort_models[index]) | |
679 tree_view->setModel(sort_models[index]); | |
680 }); | |
681 | |
307
8769c5d50b06
pages/anime_list: don't call GUI functions in a non-GUI thread
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
682 connect(&update_entry_thread_, &AnimeListPageUpdateEntryThread::NeedRefresh, this, &AnimeListPage::Refresh); |
8769c5d50b06
pages/anime_list: don't call GUI functions in a non-GUI thread
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
683 |
69 | 684 SetColumnDefaults(); |
10 | 685 setFocusPolicy(Qt::TabFocus); |
686 setFocusProxy(tab_bar); | |
687 } |