fix initial current page number
This commit is contained in:
2 files changed
+18
-4
No files matched your search
@@ -278,4 +278,4 @@ All colors are defined in `src/qml/Theme.qml` (a QML singleton registered via `q
|
||||
- `QSettings` for persistent state
|
||||
- Qt naming: `camelCase` properties/methods, `PascalCase` QML component names
|
||||
- `Q_INVOKABLE` for QML-callable methods; signals for C++→QML notifications
|
||||
- **Never use timers or `Qt.callLater` to wait for state to settle** — always use signals (`onRunningChanged`, `onCompleted`, etc.) or direct synchronous calls. Timeouts are fragile and mask real sequencing problems.
|
||||
- **Never use timers to wait for state to settle** — always use signals (`onRunningChanged`, `onCompleted`, etc.) or direct synchronous calls. Timeouts are fragile and mask real sequencing problems.
|
||||
@@ -95,9 +95,12 @@ Rectangle {
|
||||
}
|
||||
}
|
||||
|
||||
property bool _restoring: false
|
||||
|
||||
Connections {
|
||||
target: bookController
|
||||
function onBookReady() {
|
||||
_restoring = true
|
||||
var pos = appState.loadBookPosition(bookController.currentFilePath)
|
||||
var savedChapter = pos["chapter"]
|
||||
var savedScrollIndex = pos["scrollIndex"]
|
||||
@@ -105,13 +108,22 @@ Rectangle {
|
||||
|
||||
if (savedChapter > 0)
|
||||
readingModel.goToChapter(savedChapter)
|
||||
if (savedScrollIndex > 0)
|
||||
|
||||
Qt.callLater(function() {
|
||||
if (savedScrollIndex > 0) {
|
||||
chunkListView.positionViewAtIndex(savedScrollIndex, ListView.Beginning)
|
||||
chunkListView.contentY += savedScrollOffset
|
||||
})
|
||||
Qt.callLater(function() {
|
||||
}
|
||||
readingModel.setViewportSize(chunkListView.width, chunkListView.height)
|
||||
if (savedScrollIndex > 0) {
|
||||
var idx = chunkListView.indexAt(0, chunkListView.contentY)
|
||||
if (idx >= 0) {
|
||||
var item = chunkListView.itemAtIndex(idx)
|
||||
var offset = item ? chunkListView.contentY - item.y : 0
|
||||
readingModel.setScrollInfo(idx, offset, chunkListView.atYEnd)
|
||||
}
|
||||
}
|
||||
_restoring = false
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -119,9 +131,11 @@ Rectangle {
|
||||
Connections {
|
||||
target: readingModel
|
||||
function onChapterChanged() {
|
||||
if (!_restoring) {
|
||||
Qt.callLater(function() {
|
||||
readingModel.setViewportSize(chunkListView.width, chunkListView.height)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user