add library with reading history, progress tracking, and view persistence

This commit is contained in:
Agel committed 2026-03-20 11:20:16 +01:00
1 parent c62733bc26
commit c4046d8533
15 files changed
+685 -40

No files matched your search

+20 -1
View File
@@ -19,6 +19,8 @@ ApplicationWindow {
property string currentPage: "starter"
property string pageFlipMode: appState.pageFlipMode
onCurrentPageChanged: appState.lastPage = currentPage
Component.onCompleted: {
width = appState.windowWidth
height = appState.windowHeight
@@ -28,6 +30,9 @@ ApplicationWindow {
}
if (appState.lastFilePath !== "")
bookController.openBook(appState.lastFileUrl())
var savedPage = appState.lastPage
if (savedPage === "library" || savedPage === "settings")
window.currentPage = savedPage
}
Timer {
@@ -57,10 +62,15 @@ ApplicationWindow {
onCloseDrawer: window.sidebarOpen = false
onNavigateTo: function(page) {
window.currentPage = page
window.sidebarOpen = false
}
onOpenFile: {
bookController.browseAndOpen()
}
onCloseBook: {
bookController.closeBook()
window.sidebarOpen = false
}
}
Column {
@@ -82,7 +92,7 @@ ApplicationWindow {
StarterPage {
anchors.fill: parent
visible: window.currentPage !== "reader" && window.currentPage !== "settings"
visible: window.currentPage === "starter"
}
ReaderPage {
@@ -94,6 +104,11 @@ ApplicationWindow {
anchors.fill: parent
visible: window.currentPage === "settings"
}
LibraryPage {
anchors.fill: parent
visible: window.currentPage === "library"
}
}
Loader {
@@ -115,5 +130,9 @@ ApplicationWindow {
function onBookReady() {
window.currentPage = "reader"
}
function onBookChanged() {
if (!bookController.hasBook && window.currentPage === "reader")
window.currentPage = "starter"
}
}
}
+39 -24
View File
@@ -12,36 +12,51 @@ Rectangle {
onClicked: {} // Block clicks through overlay
}
Column {
Rectangle {
anchors.centerIn: parent
spacing: 20
width: Math.min(overlay.width * 0.7, 440)
height: dialogColumn.implicitHeight + 48
color: Theme.surface
radius: 8
Text {
anchors.horizontalCenter: parent.horizontalCenter
text: bookController.errorMessage
font.pixelSize: 15
color: Theme.readingText
horizontalAlignment: Text.AlignHCenter
wrapMode: Text.Wrap
width: Math.min(overlay.width * 0.6, 400)
}
Column {
id: dialogColumn
anchors {
top: parent.top
left: parent.left
right: parent.right
topMargin: 24
leftMargin: 24
rightMargin: 24
}
spacing: 20
Button {
anchors.horizontalCenter: parent.horizontalCenter
text: "Ok"
contentItem: Text {
text: parent.text
font.pixelSize: 14
color: "#ffffff"
Text {
width: parent.width
text: bookController.errorMessage
font.pixelSize: 15
color: Theme.readingText
horizontalAlignment: Text.AlignHCenter
wrapMode: Text.Wrap
}
background: Rectangle {
implicitWidth: 80
implicitHeight: 36
radius: 4
color: parent.hovered ? Qt.lighter(Theme.primaryAccent, 1.15) : Theme.primaryAccent
Button {
anchors.horizontalCenter: parent.horizontalCenter
text: "Ok"
contentItem: Text {
text: parent.text
font.pixelSize: 14
color: "#ffffff"
horizontalAlignment: Text.AlignHCenter
}
background: Rectangle {
implicitWidth: 80
implicitHeight: 36
radius: 4
color: parent.hovered ? Qt.lighter(Theme.primaryAccent, 1.15) : Theme.primaryAccent
}
onClicked: bookController.clearError()
}
onClicked: bookController.errorMessage = ""
}
}
}
+17 -10
View File
@@ -77,23 +77,30 @@ Rectangle {
var idx = chunkListView.indexAt(0, chunkListView.contentY)
appState.lastScrollIndex = idx
var item = chunkListView.itemAtIndex(idx)
appState.lastScrollOffset = item ? chunkListView.contentY - item.y : 0
var offset = item ? chunkListView.contentY - item.y : 0
appState.lastScrollOffset = offset
appState.lastScrollPosition = chunkListView.contentY
if (bookController.hasBook)
appState.saveBookPosition(bookController.currentFilePath,
readingModel.currentChapter, idx, offset)
}
}
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
})
}
var pos = appState.loadBookPosition(bookController.currentFilePath)
var savedChapter = pos["chapter"]
var savedScrollIndex = pos["scrollIndex"]
var savedScrollOffset = pos["scrollOffset"]
if (savedChapter > 0)
readingModel.goToChapter(savedChapter)
if (savedScrollIndex > 0)
Qt.callLater(function() {
chunkListView.positionViewAtIndex(savedScrollIndex, ListView.Beginning)
chunkListView.contentY += savedScrollOffset
})
Qt.callLater(function() {
readingModel.setViewportSize(chunkListView.width, chunkListView.height)
})
+14
View File
@@ -13,6 +13,7 @@ Rectangle {
signal closeDrawer()
signal navigateTo(string page)
signal openFile()
signal closeBook()
Behavior on width {
NumberAnimation {
@@ -59,12 +60,25 @@ Rectangle {
onClicked: sidebar.navigateTo("reader")
}
SideBarButton {
iconText: "\ue02f"
title: "Library"
onClicked: sidebar.navigateTo("library")
}
SideBarButton {
iconText: "\ue30a"
title: "Files"
onClicked: sidebar.openFile()
}
SideBarButton {
visible: bookController.hasBook
iconText: "\ue5cd"
title: "Close Book"
onClicked: sidebar.closeBook()
}
// Divider
Rectangle {
width: parent.width
+96
View File
@@ -0,0 +1,96 @@
import QtQuick
import QtQuick.Controls
import Asteria
Rectangle {
color: Theme.backgroundDefault
Text {
visible: appState.libraryBooks.length === 0
anchors.centerIn: parent
text: "No books read yet.\nOpen a book to start your library."
horizontalAlignment: Text.AlignHCenter
color: Theme.dimText
font.pixelSize: 14
lineHeight: 1.6
}
ListView {
visible: appState.libraryBooks.length > 0
anchors.fill: parent
anchors.margins: 16
spacing: 8
clip: true
model: appState.libraryBooks
delegate: Rectangle {
id: bookRow
width: ListView.view.width
height: bookInfoCol.implicitHeight + 24
color: Theme.surface
radius: 4
Row {
anchors.fill: parent
anchors.leftMargin: 14
anchors.rightMargin: 14
anchors.topMargin: 12
anchors.bottomMargin: 12
spacing: 8
Column {
id: bookInfoCol
width: parent.width - removeBtn.width - parent.spacing
anchors.verticalCenter: parent.verticalCenter
spacing: 3
Text {
width: parent.width
text: modelData.title || "Unknown Title"
color: Theme.uiText
font.pixelSize: 14
font.bold: true
elide: Text.ElideRight
}
Text {
visible: modelData.author !== ""
width: parent.width
text: modelData.author
color: Theme.dimText
font.pixelSize: 12
elide: Text.ElideRight
}
Text {
text: Math.round(modelData.progress * 100) + "%"
color: Theme.buttonAccent
font.pixelSize: 12
}
}
Button {
id: removeBtn
anchors.verticalCenter: parent.verticalCenter
flat: true
contentItem: Text {
text: "\ue872"
font.family: "Material Icons Outlined"
font.pixelSize: 20
color: Theme.dimText
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
background: Item {}
onClicked: appState.removeLibraryBook(modelData.filePath)
}
}
MouseArea {
anchors.fill: parent
z: -1
onClicked: bookController.openBookFromPath(modelData.filePath)
}
}
}
}