restore opened file and position

This commit is contained in:
Agel committed 2026-03-16 15:34:15 +01:00
1 parent fcacd0495d
commit 2ecf9f4178
12 files changed
+491 -11

No files matched your search

+31
View File
@@ -9,6 +9,7 @@ Rectangle {
}
ListView {
id: chunkListView
anchors.fill: parent
anchors.leftMargin: 12
model: bookController.hasBook ? readingModel : null
@@ -26,6 +27,8 @@ Rectangle {
text: model.content
}
onContentYChanged: scrollTrackTimer.restart()
ScrollBar.vertical: ScrollBar {
policy: ScrollBar.AsNeeded
padding: 0
@@ -49,4 +52,32 @@ Rectangle {
color: Theme.readingText
}
}
Timer {
id: scrollTrackTimer
interval: 300
repeat: false
onTriggered: {
var idx = chunkListView.indexAt(0, chunkListView.contentY)
appState.lastScrollIndex = idx
var item = chunkListView.itemAtIndex(idx)
appState.lastScrollOffset = item ? chunkListView.contentY - item.y : 0
appState.lastScrollPosition = chunkListView.contentY
}
}
Connections {
target: bookController
function onBookReady() {
if (bookController.currentFilePath === appState.lastFilePath) {
readingModel.goToChapter(appState.lastChapter)
if (appState.lastScrollIndex > 0)
Qt.callLater(function() {
chunkListView.positionViewAtIndex(
appState.lastScrollIndex, ListView.Beginning)
chunkListView.contentY += appState.lastScrollOffset
})
}
}
}
}