Upgrade to Qt 6.10.3, refactor AppState for LibraryModel integration, add ChunkMeasurer tests, and update CI/docker configurations.
This commit is contained in:
53 files changed
+2095
-880
No files matched your search
+104
-54
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user