Upgrade to Qt 6.10.3, refactor AppState for LibraryModel integration, add ChunkMeasurer tests, and update CI/docker configurations.

This commit is contained in:
Agel committed 2026-04-03 13:55:28 +02:00
1 parent 0303107fa2
commit a31b20534a
53 files changed
+2095 -880

No files matched your search

+28 -15
View File
@@ -7,6 +7,7 @@ ApplicationWindow {
id: window
width: 1024
height: 768
opacity: 0
visible: true
title: "Asteria"
color: ThemeManager.currentTheme.backgroundDeepest
@@ -19,7 +20,6 @@ ApplicationWindow {
property bool sidebarOpen: appState.sidebarOpen
onSidebarOpenChanged: appState.sidebarOpen = sidebarOpen
property string currentPage: "starter"
property bool _restoringState: false
property bool barsVisible: true
onCurrentPageChanged: appState.lastPage = currentPage
@@ -31,23 +31,12 @@ ApplicationWindow {
x = appState.windowX
y = appState.windowY
}
// Initialize theme from AppState
if (appState.themeName !== "") {
ThemeManager.currentThemeName = appState.themeName
}
if (appState.lastFilePath !== "") {
window._restoringState = true
bookController.openBook(appState.lastFileUrl())
} else {
window.sidebarOpen = true
var savedPage = appState.lastPage
if (savedPage === "library" || savedPage === "settings")
window.currentPage = savedPage
}
}
Connections {
target: appState
function onThemeNameChanged() {
@@ -129,6 +118,13 @@ ApplicationWindow {
anchors.fill: parent
visible: window.currentPage === "library"
}
BusyIndicator {
anchors.centerIn: parent
running: bookController.loading || readingModel.measuring
visible: running
z: 10
}
}
Loader {
@@ -224,8 +220,7 @@ ApplicationWindow {
Connections {
target: bookController
function onBookReady() {
if (window._restoringState) {
window._restoringState = false
if (bookController.startupRestore) {
var savedPage = appState.lastPage
if (savedPage === "library" || savedPage === "settings")
window.currentPage = savedPage
@@ -239,5 +234,23 @@ ApplicationWindow {
if (!bookController.hasBook && window.currentPage === "reader")
window.currentPage = "starter"
}
function onNoSavedBook() {
window.sidebarOpen = true
var savedPage = appState.lastPage
if (savedPage === "library" || savedPage === "settings")
window.currentPage = savedPage
}
}
Timer {
running: true
repeat: false
interval: 1
triggeredOnStart: false
onTriggered: {
window.opacity = 1
readerPage.pageView.updateContentWidth()
bookController.uiReady()
}
}
}
+104 -54
View File
@@ -5,6 +5,12 @@ import Asteria
Rectangle {
focus: true
property bool contentReady: false
property bool resizing: false
property bool restoreReady: false
property int initialIndex: -1
property int initialOffset: -1
// Animation for smooth scrolling
property Animation scrollAnimation: PropertyAnimation {
target: chunkListView
@@ -19,14 +25,14 @@ Rectangle {
var targetY = Math.max(0, chunkListView.contentY - scrollAmount);
animateScrollTo(targetY);
}
function handlePageDown() {
var scrollAmount = chunkListView.height * 0.95;
var maxY = Math.max(0, chunkListView.contentHeight - chunkListView.height);
var targetY = Math.min(maxY, chunkListView.contentY + scrollAmount);
animateScrollTo(targetY);
}
function handleScrollUp() {
// Scroll up by approximately 2-3 lines
var lineHeight = appState.fontSize * appState.lineSpacing;
@@ -34,7 +40,7 @@ Rectangle {
var targetY = Math.max(0, chunkListView.contentY - scrollAmount);
animateScrollTo(targetY);
}
function handleScrollDown() {
// Scroll down by approximately 2-3 lines
var lineHeight = appState.fontSize * appState.lineSpacing;
@@ -62,37 +68,72 @@ Rectangle {
}
Component.onCompleted: updateContentWidth()
onWidthChanged: updateContentWidth()
onWidthChanged: {
resizing = true;
remeasureTimer.restart()
}
Timer {
id: remeasureTimer
interval: 150
repeat: false
onTriggered: {
updateContentWidth()
resizing = false;
}
}
ListView {
id: chunkListView
anchors.fill: parent
model: bookController.hasBook ? readingModel : null
model: contentReady ? readingModel : null
header: Item { height: appState.verticalMargin }
footer: Item { height: appState.verticalMargin }
cacheBuffer: 2000
cacheBuffer: 20
clip: true
delegate: Text {
width: ListView.view.width - 18
leftPadding: appState.horizontalMargin
rightPadding: appState.horizontalMargin
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
textFormat: Text.RichText
font.pixelSize: appState.fontSize
lineHeight: appState.lineSpacing
color: ThemeManager.currentTheme.readingText
text: model.content
delegate: Item {
id: chunkDelegate
readonly property int chunkIdx: model.index
width: chunkListView.width
height: resizing || readingModel.measuring ? contentText.implicitHeight : model.pixelHeight
Text {
visible: isDebugBuild
leftPadding: 0
text: model.index
color: "#FFFFFF"
height: 0
}
Text {
id: contentText
width: parent.width - 18 // subtract scrollbar
leftPadding: appState.horizontalMargin
rightPadding: appState.horizontalMargin
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
textFormat: Text.RichText
font.pixelSize: appState.fontSize
lineHeight: appState.lineSpacing
color: ThemeManager.currentTheme.readingText
text: model.content
visible: model.content !== ""
// TODO: remove when we're good with measurer
onImplicitHeightChanged: {
if (model.pixelHeight > 0 && implicitHeight > 0) {
var diff = model.pixelHeight - implicitHeight
if (Math.abs(diff) > 1) {
console.warn("Chunk", model.index,
"height mismatch: measured=" + model.pixelHeight,
"actual=" + Math.round(implicitHeight),
"diff=" + Math.round(diff))
}
}
}
}
}
onContentYChanged: {
scrollTrackTimer.restart()
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)
}
}
ScrollBar.vertical: ScrollBar {
@@ -125,60 +166,69 @@ Rectangle {
interval: 150
onTriggered: {
window.barsVisible = !window.barsVisible
window.sidebarOpen = false
window.sidebarOpen = !window.sidebarOpen
}
}
}
Timer {
id: scrollTrackTimer
interval: 300
repeat: false
onTriggered: {
var idx = chunkListView.indexAt(0, chunkListView.contentY)
appState.lastScrollIndex = idx
var item = chunkListView.itemAtIndex(idx)
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)
if (bookController.hasBook && contentReady && restoreReady) {
var topIdx = chunkListView.indexAt(0, chunkListView.contentY)
if (topIdx < 0) topIdx = 0
var topItem = chunkListView.itemAtIndex(topIdx)
var intraOffset = topItem ? (chunkListView.contentY - topItem.y) : 0
readingModel.setScrollInfo(topIdx, chunkListView.visibleArea.yPosition)
appState.saveBookPosition(bookController.currentFilePath, topIdx, intraOffset)
}
}
}
property bool _restoring: false
Connections {
target: bookController
function onBookReady() {
_restoring = true
var pos = appState.loadBookPosition(bookController.currentFilePath)
var savedScrollIndex = pos["scrollIndex"]
var savedScrollOffset = pos["scrollOffset"]
Qt.callLater(function() {
if (savedScrollIndex > 0) {
chunkListView.positionViewAtIndex(savedScrollIndex, ListView.Beginning)
chunkListView.contentY += savedScrollOffset
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
})
function onLoadingChanged() {
if (bookController.loading)
contentReady = false
}
}
Connections {
target: readingModel
function onRestoreReady(chunkIndex, intraOffset) {
contentReady = true
initialIndex = chunkIndex
initialOffset = intraOffset
restoreTimer.start()
}
function onScrollToChunkRequested(chunkIndex) {
chunkListView.positionViewAtIndex(chunkIndex, ListView.Beginning)
}
}
Connections {
target: appState
function onFontSizeChanged() {
readingModel.setFontParams(appState.fontSize, appState.lineSpacing)
}
function onLineSpacingChanged() {
readingModel.setFontParams(appState.fontSize, appState.lineSpacing)
}
}
Timer {
id: restoreTimer
interval: 1
repeat: false
onTriggered: {
console.info("Restoring contentHeight:", chunkListView.contentHeight, "originY:", chunkListView.originY, "chunkIndex:", initialIndex, "intraOffset:", initialOffset)
chunkListView.positionViewAtIndex(initialIndex, ListView.Beginning)
chunkListView.contentY += initialOffset
restoreReady = true
}
}
}
+20 -10
View File
@@ -6,7 +6,7 @@ Rectangle {
color: ThemeManager.currentTheme.backgroundDefault
Text {
visible: appState.libraryBooks.length === 0
visible: appState.libraryModel.count === 0
anchors.centerIn: parent
text: "No books read yet.\nOpen a book to start your library."
horizontalAlignment: Text.AlignHCenter
@@ -16,12 +16,12 @@ Rectangle {
}
ListView {
visible: appState.libraryBooks.length > 0
visible: appState.libraryModel.count > 0
anchors.fill: parent
anchors.margins: 16
spacing: 8
clip: true
model: appState.libraryBooks
model: appState.libraryModel
delegate: Rectangle {
id: bookRow
@@ -38,15 +38,25 @@ Rectangle {
anchors.bottomMargin: 12
spacing: 8
Image {
id: coverImage
visible: filePath !== ""
width: 60
height: 80
source: coverImageUrl
fillMode: Image.PreserveAspectFit
anchors.verticalCenter: parent.verticalCenter
}
Column {
id: bookInfoCol
width: parent.width - removeBtn.width - parent.spacing
width: parent.width - removeBtn.width - parent.spacing - (coverImage.visible ? coverImage.width + 8 : 0)
anchors.verticalCenter: parent.verticalCenter
spacing: 3
Text {
width: parent.width
text: modelData.title || "Unknown Title"
text: title || "Unknown Title"
color: ThemeManager.currentTheme.uiText
font.pixelSize: 14
font.bold: true
@@ -54,16 +64,16 @@ Rectangle {
}
Text {
visible: modelData.author !== ""
visible: author !== ""
width: parent.width
text: modelData.author
text: author
color: ThemeManager.currentTheme.dimText
font.pixelSize: 12
elide: Text.ElideRight
}
Text {
text: Math.round(modelData.progress * 100) + "%"
text: Math.round(progress * 100) + "%"
color: ThemeManager.currentTheme.buttonAccent
font.pixelSize: 12
}
@@ -82,14 +92,14 @@ Rectangle {
verticalAlignment: Text.AlignVCenter
}
background: Item {}
onClicked: appState.removeLibraryBook(modelData.filePath)
onClicked: appState.removeLibraryBook(filePath)
}
}
MouseArea {
anchors.fill: parent
z: -1
onClicked: bookController.openBookFromPath(modelData.filePath)
onClicked: bookController.openBookFromPath(filePath)
}
}
}
+49 -9
View File
@@ -44,7 +44,7 @@ Rectangle {
}
Text {
id: valueH
text: appState.horizontalMargin + " px"
text: hmSlider.value + " px"
font.pixelSize: 13
color: ThemeManager.currentTheme.dimText
anchors.right: parent.right
@@ -53,13 +53,23 @@ Rectangle {
}
}
Timer {
id: hmTimer
interval: 250
onTriggered: appState.horizontalMargin = hmSlider.value
}
Slider {
id: hmSlider
width: parent.width
from: 0
to: 120
stepSize: 1
value: appState.horizontalMargin
onValueChanged: appState.horizontalMargin = value
onValueChanged: {
if (value !== appState.horizontalMargin)
hmTimer.restart()
}
}
}
@@ -81,7 +91,7 @@ Rectangle {
}
Text {
id: valueV
text: appState.verticalMargin + " px"
text: vmSlider.value + " px"
font.pixelSize: 13
color: ThemeManager.currentTheme.dimText
anchors.right: parent.right
@@ -90,13 +100,23 @@ Rectangle {
}
}
Timer {
id: vmTimer
interval: 250
onTriggered: appState.verticalMargin = vmSlider.value
}
Slider {
id: vmSlider
width: parent.width
from: 0
to: 80
stepSize: 1
value: appState.verticalMargin
onValueChanged: appState.verticalMargin = value
onValueChanged: {
if (value !== appState.verticalMargin)
vmTimer.restart()
}
}
}
@@ -118,7 +138,7 @@ Rectangle {
}
Text {
id: valueF
text: appState.fontSize + " px"
text: fsSlider.value + " px"
font.pixelSize: 13
color: ThemeManager.currentTheme.dimText
anchors.right: parent.right
@@ -127,13 +147,23 @@ Rectangle {
}
}
Timer {
id: fsTimer
interval: 250
onTriggered: appState.fontSize = fsSlider.value
}
Slider {
id: fsSlider
width: parent.width
from: 10
to: 32
stepSize: 1
value: appState.fontSize
onValueChanged: appState.fontSize = value
onValueChanged: {
if (value !== appState.fontSize)
fsTimer.restart()
}
}
}
@@ -155,7 +185,7 @@ Rectangle {
}
Text {
id: valueL
text: appState.lineSpacing.toFixed(1) + "×"
text: lsSlider.value.toFixed(1) + "×"
font.pixelSize: 13
color: ThemeManager.currentTheme.dimText
anchors.right: parent.right
@@ -164,15 +194,25 @@ Rectangle {
}
}
Timer {
id: lsTimer
interval: 250
onTriggered: appState.lineSpacing = lsSlider.value
}
Slider {
id: lsSlider
width: parent.width
from: 0.5
to: 3.0
stepSize: 0.1
value: appState.lineSpacing
onValueChanged: appState.lineSpacing = value
onValueChanged: {
if (Math.abs(value - appState.lineSpacing) > 0.01)
lsTimer.restart()
}
}
}
}
}
}
}