fix history book positions

This commit is contained in:
Agel committed 2026-04-17 12:28:03 +02:00
1 parent f80fefa34f
commit 8879fa9aba
5 files changed
+9 -1

No files matched your search

+1
View File
@@ -94,6 +94,7 @@ void HistoryModel::addOrUpdateBook(const QString &filePath, double progress, con
m_books.move(i, 0); m_books.move(i, 0);
endMoveRows(); endMoveRows();
} }
emit dataChanged(createIndex(0, 0), createIndex(0, 0), {ProgressRole, LastOpenedRole});
return; return;
} }
} }
+1 -1
View File
@@ -61,7 +61,7 @@ qreal ReadingModel::totalPixelHeight() const { return m_totalPixelHeight; }
double ReadingModel::progress() const double ReadingModel::progress() const
{ {
return qBound(0, static_cast<int>(m_yOffset * 100), 100); return qBound(0.0, m_yOffset, 1.0);
} }
int ReadingModel::currentPage() const { return m_currentPage; } int ReadingModel::currentPage() const { return m_currentPage; }
+1
View File
@@ -138,6 +138,7 @@ void Book::saveCurrentPosition(int chunkIndex, int intraOffset)
{ {
if (!m_reader) return; if (!m_reader) return;
m_positions.save(m_reader->contentHash(), chunkIndex, intraOffset); m_positions.save(m_reader->contentHash(), chunkIndex, intraOffset);
emit positionSaved();
} }
void Book::setContentWidth(int width) void Book::setContentWidth(int width)
+1
View File
@@ -62,6 +62,7 @@ signals:
// Emitted just before replacing the current reader with a new one. // Emitted just before replacing the current reader with a new one.
// Listeners can snapshot the outgoing book's progress before the swap. // Listeners can snapshot the outgoing book's progress before the swap.
void willOpenNewBook(); void willOpenNewBook();
void positionSaved();
void bookChanged(); void bookChanged();
void loadingChanged(); void loadingChanged();
+5
View File
@@ -175,6 +175,11 @@ int main(int argc, char *argv[])
historyModel.addOrUpdateBook(book.filePath(), readingModel.progress()); historyModel.addOrUpdateBook(book.filePath(), readingModel.progress());
}); });
// Real-time history update: fired by PageView's scrollTrackTimer on every scroll.
QObject::connect(&book, &Book::positionSaved, [&]{
historyModel.addOrUpdateBook(book.filePath(), readingModel.progress());
});
// After the new reader is installed: wire up image provider + ReadingModel // After the new reader is installed: wire up image provider + ReadingModel
QObject::connect(&book, &Book::bookChanged, [&]{ QObject::connect(&book, &Book::bookChanged, [&]{
currentImageProvider = nullptr; currentImageProvider = nullptr;