1414#include " ../src/LevelViewList.hpp"
1515
1616#include < QDateTime>
17- #include " ../src/staticData .hpp"
17+ #include " ../src/staticViewData .hpp"
1818
19+
20+ LevelViewList::LevelViewList (QWidget *parent)
21+ : QListView(parent)
22+ {
23+ }
24+
25+ void LevelViewList::scrollContentsBy (int dx, int dy)
26+ {
27+ // qDebug() << "LevelViewList::scrollContentsBy: " << "";
28+ QListView::scrollContentsBy (dx, dy);
29+ // updateVisibleItems();
30+ }
31+
32+ void LevelViewList::resizeEvent (QResizeEvent *event)
33+ {
34+ // qDebug() << "LevelViewList::resizeEvent: " << "";
35+ QListView::resizeEvent (event);
36+ // updateVisibleItems();
37+ }
38+
39+ void LevelViewList::paintEvent (QPaintEvent *event)
40+ {
41+ // qDebug() << "LevelViewList::paintEvent: " << "";
42+ QListView::paintEvent (event);
43+ // updateVisibleItems();
44+ }
45+
46+ QModelIndexList LevelViewList::visibleIndexes () const
47+ {
48+ QModelIndexList result;
49+ auto r = viewport ()->rect ();
50+ auto topLeft = indexAt (r.topLeft ());
51+ auto bottomRight = indexAt (r.bottomRight ());
52+
53+ if (!topLeft.isValid () || !bottomRight.isValid ())
54+ return result;
55+
56+ int top = topLeft.row ();
57+ int bottom = bottomRight.row ();
58+ for (int row = top; row <= bottom; ++row) {
59+ auto idx = indexAt (QPoint (0 , visualRect (model ()->index (row, 0 )).center ().y ()));
60+ if (idx.isValid ())
61+ result << idx;
62+ }
63+ return result;
64+ }
65+
66+ void LevelViewList::updateVisibleItems ()
67+ {
68+ QModelIndexList vis = visibleIndexes ();
69+ for (auto &idx : vis) {
70+ if (!idx.isValid ())
71+ continue ;
72+ // Map proxy index to source index if model is a proxy
73+ QModelIndex sourceIdx = idx;
74+ // Try cast to QAbstractProxyModel to map
75+ if (auto proxy = qobject_cast<QAbstractProxyModel *>(model ())) {
76+ sourceIdx = proxy->mapToSource (idx);
77+ }
78+
79+ // Now fetch LevelPtr from the source model, not the proxy (if available)
80+ QVariant varLvl;
81+ /*
82+ if (sourceIdx.isValid()) {
83+ // If we have proxy, get sourceModel, else fallback to model()
84+ if (auto proxy = qobject_cast<QAbstractProxyModel *>(model())) {
85+ varLvl = proxy->sourceModel()->data(sourceIdx, LevelModel::RoleLevel);
86+ } else {
87+ varLvl = model()->data(sourceIdx, LevelModel::RoleLevel);
88+ }
89+ } else {
90+ varLvl = model()->data(idx, LevelModel::RoleLevel);
91+ }
92+ auto lvl = varLvl.value<LevelPtr>();
93+ if (lvl) {
94+ // do update, e.g. preload something
95+ lvl->requestThumb();
96+ }
97+ */
98+ }
99+ }
100+
101+ // The Model
19102void LevelListModel::setLevels (
20103 const QVector<QSharedPointer<ListItemData>>& levels) {
21104 beginResetModel ();
@@ -50,13 +133,15 @@ inline quint64 LevelListModel::indexInBounds(const quint64 index) const {
50133 return qMin (index, quint64 (m_levels.size ()));
51134}
52135
53- void LevelListModel::setScrollChange (const quint64 index ) {
136+ void LevelListModel::setScrollChange () {
54137 if (!m_levels.empty ()) {
55138 m_scrollCursorChanged = true ;
56- m_scroll_cursor_a = indexInBounds (index);;
57139 }
58140}
59141
142+ void LevelListModel::addScrollItem (const quint64 index) {
143+ }
144+
60145QVector<QSharedPointer<ListItemData>>
61146 LevelListModel::getChunk (const quint64 cursor, const quint64 items) {
62147 const quint64 len = indexInBounds (cursor + items) - cursor;
@@ -66,10 +151,9 @@ QVector<QSharedPointer<ListItemData>>
66151QVector<QSharedPointer<ListItemData>>
67152 LevelListModel::getDataBuffer (quint64 items) {
68153 QVector<QSharedPointer<ListItemData>> chunk;
69- if ((items > 0 ) && !m_levels.isEmpty ()) {
154+ if (!m_levels.isEmpty ()) {
70155 if (m_scrollCursorChanged == true ) {
71- m_scroll_cursor_b = indexInBounds (m_scroll_cursor_a + items);
72- chunk = getChunk (m_scroll_cursor_a, items);
156+ // chunk = m_scrollBuffer;
73157 } else {
74158 m_cursor_b = indexInBounds (m_cursor_a + items);
75159 chunk = getChunk (m_cursor_a, items);
@@ -91,8 +175,9 @@ void LevelListModel::updateCovers(quint64 a, quint64 b) {
91175
92176void LevelListModel::reset () {
93177 if (m_scrollCursorChanged == true ) {
94- updateCovers (m_scroll_cursor_a, m_scroll_cursor_b);
95- m_scroll_cursor_a = m_scroll_cursor_b;
178+ QModelIndex index_b (index (0 , 0 ));
179+ // updateCovers(m_scrollBuffer);
180+ // m_scrollBuffer.clear();
96181 m_scrollCursorChanged = false ;
97182 } else {
98183 updateCovers (m_cursor_a, m_cursor_b);
@@ -168,9 +253,15 @@ void LevelListProxy::setInstalledFilter(bool on) {
168253}
169254
170255void LevelListProxy::setSortMode (SortMode mode) {
171- m_sortMode = mode;
256+ Qt::SortOrder order;
257+ if (m_sortMode == mode){
258+ order = Qt::AscendingOrder;
259+ } else {
260+ m_sortMode = mode;
261+ order = Qt::DescendingOrder;
262+ }
172263 invalidate ();
173- this ->sort (0 , Qt::DescendingOrder );
264+ this ->sort (0 , order );
174265}
175266
176267bool LevelListProxy::lessThan (const QModelIndex &left,
@@ -182,7 +273,7 @@ bool LevelListProxy::lessThan(const QModelIndex &left,
182273 bool less = false ;
183274 switch (m_sortMode) {
184275 case Title:
185- less = l.toString ().localeAwareCompare (r.toString ()) < 0 ;
276+ less = l.toString ().localeAwareCompare (r.toString (). toUpper () ) < 0 ;
186277 break ;
187278 case ReleaseDate:
188279 less = l.toDateTime () < r.toDateTime ();
0 commit comments