fixed pagination

This commit is contained in:
Agel committed 2026-03-19 23:00:10 +01:00
1 parent 43e75d3d8f
commit 10f0fc52c7
3 files changed
+8 -4

No files matched your search

+5 -2
View File
@@ -77,19 +77,20 @@ void ReadingModel::setViewportSize(qreal width, qreal height)
m_viewportWidth = width;
m_viewportHeight = height;
if (widthChanged && !m_chunks.isEmpty())
if (!m_chunks.isEmpty() && (widthChanged || m_chunkHeights.isEmpty()))
computeChunkHeights();
recalculateTotalPages();
recalculateCurrentPage();
}
void ReadingModel::setScrollInfo(int topChunkIndex, qreal offsetInChunk)
void ReadingModel::setScrollInfo(int topChunkIndex, qreal offsetInChunk, bool atYEnd)
{
if (topChunkIndex < 0 || topChunkIndex >= m_chunkOffsets.size())
return;
m_absoluteScrollY = m_chunkOffsets.at(topChunkIndex) + offsetInChunk;
m_atYEnd = atYEnd;
recalculateCurrentPage();
}
@@ -156,6 +157,8 @@ void ReadingModel::recalculateCurrentPage()
int page = 0;
if (m_viewportHeight > 0 && m_totalPages > 0) {
page = static_cast<int>(std::floor(m_absoluteScrollY / m_viewportHeight)) + 1;
if (m_atYEnd)
page = m_totalPages;
page = std::max(1, std::min(page, m_totalPages));
}
if (m_currentPage == page)
+2 -1
View File
@@ -42,7 +42,7 @@ public:
// Called from QML on resize
Q_INVOKABLE void setViewportSize(qreal width, qreal height);
// Called from QML on every scroll (real-time)
Q_INVOKABLE void setScrollInfo(int topChunkIndex, qreal offsetInChunk);
Q_INVOKABLE void setScrollInfo(int topChunkIndex, qreal offsetInChunk, bool atYEnd = false);
Q_INVOKABLE void nextChapter();
Q_INVOKABLE void previousChapter();
@@ -73,6 +73,7 @@ private:
QVector<qreal> m_chunkHeights; // rendered height of each chunk
QVector<qreal> m_chunkOffsets; // prefix sums: offset[i] = sum of heights[0..i-1]
qreal m_totalContentHeight = 0;
bool m_atYEnd = false;
QString m_chapterTitle;
};