restore opened file and position
This commit is contained in:
12 files changed
+491
-11
No files matched your search
+29
-1
@@ -17,7 +17,35 @@ ApplicationWindow {
|
||||
|
||||
property bool sidebarOpen: false
|
||||
property string currentPage: "starter"
|
||||
property string pageFlipMode: "scroll" // "scroll" | "page"
|
||||
property string pageFlipMode: appState.pageFlipMode
|
||||
|
||||
Component.onCompleted: {
|
||||
width = appState.windowWidth
|
||||
height = appState.windowHeight
|
||||
if (appState.windowX >= 0 && appState.windowY >= 0) {
|
||||
x = appState.windowX
|
||||
y = appState.windowY
|
||||
}
|
||||
if (appState.lastFilePath !== "")
|
||||
bookController.openBook(appState.lastFileUrl())
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: geometrySaveTimer
|
||||
interval: 500
|
||||
repeat: false
|
||||
onTriggered: {
|
||||
appState.setWindowWidth(window.width)
|
||||
appState.setWindowHeight(window.height)
|
||||
appState.setWindowX(window.x)
|
||||
appState.setWindowY(window.y)
|
||||
}
|
||||
}
|
||||
|
||||
onWidthChanged: geometrySaveTimer.restart()
|
||||
onHeightChanged: geometrySaveTimer.restart()
|
||||
onXChanged: geometrySaveTimer.restart()
|
||||
onYChanged: geometrySaveTimer.restart()
|
||||
|
||||
Row {
|
||||
anchors.fill: parent
|
||||
|
||||
@@ -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
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,7 @@ Rectangle {
|
||||
width: 100
|
||||
height: 40
|
||||
radius: 6
|
||||
color: window.pageFlipMode === modelData.value
|
||||
color: appState.pageFlipMode === modelData.value
|
||||
? Theme.primaryAccent
|
||||
: Theme.surface
|
||||
|
||||
@@ -60,7 +60,7 @@ Rectangle {
|
||||
anchors.centerIn: parent
|
||||
text: modelData.label
|
||||
font.pixelSize: 14
|
||||
color: window.pageFlipMode === modelData.value
|
||||
color: appState.pageFlipMode === modelData.value
|
||||
? Theme.readingText
|
||||
: Theme.uiText
|
||||
}
|
||||
@@ -68,7 +68,7 @@ Rectangle {
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: window.pageFlipMode = modelData.value
|
||||
onClicked: appState.pageFlipMode = modelData.value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user