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