Some refactor

This commit is contained in:
Agel committed 2026-04-08 14:01:03 +02:00
1 parent 7ecb7f4f4f
commit 9280c838b2
37 files changed
+1599 -981

No files matched your search

+3 -3
View File
@@ -5,7 +5,7 @@ import Asteria
Rectangle {
id: overlay
color: ThemeManager.currentTheme.overlayBg
visible: bookController.errorMessage !== ""
visible: book.errorMessage !== ""
MouseArea {
anchors.fill: parent
@@ -33,7 +33,7 @@ Rectangle {
Text {
width: parent.width
text: bookController.errorMessage
text: book.errorMessage
font.pixelSize: 15
color: ThemeManager.currentTheme.readingText
horizontalAlignment: Text.AlignHCenter
@@ -55,7 +55,7 @@ Rectangle {
radius: 4
color: parent.hovered ? Qt.lighter(ThemeManager.currentTheme.primaryAccent, 1.15) : ThemeManager.currentTheme.primaryAccent
}
onClicked: bookController.clearError()
onClicked: book.clearError()
}
}
}
+5 -5
View File
@@ -18,7 +18,7 @@ Rectangle {
id: prevBtn
anchors.verticalCenter: parent.verticalCenter
x: parent.width * 0.5 - chapterText.implicitWidth / 2 - width - 4
visible: bookController.hasBook && readingModel.hasChapters
visible: book.hasBook && readingModel.hasChapters
enabled: readingModel.currentChapter > 0
flat: true
padding: 0
@@ -40,7 +40,7 @@ Rectangle {
id: chapterText
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
text: bookController.hasBook && readingModel.hasChapters
text: book.hasBook && readingModel.hasChapters
? "Chapter " + (readingModel.currentChapter + 1) + " / " + readingModel.totalChapters
: ""
font.pixelSize: 11
@@ -53,7 +53,7 @@ Rectangle {
id: nextBtn
anchors.verticalCenter: parent.verticalCenter
x: parent.width * 0.5 + chapterText.implicitWidth / 2 + 4
visible: bookController.hasBook && readingModel.hasChapters
visible: book.hasBook && readingModel.hasChapters
enabled: readingModel.currentChapter < readingModel.totalChapters - 1
flat: true
padding: 0
@@ -75,8 +75,8 @@ Rectangle {
anchors.right: parent.right
anchors.rightMargin: 16
anchors.verticalCenter: parent.verticalCenter
visible: bookController.hasBook
text: bookController.hasBook
visible: book.hasBook
text: book.hasBook
? readingModel.currentPage + "/" + readingModel.totalPages
: ""
font.pixelSize: 11
+1 -1
View File
@@ -39,7 +39,7 @@ Rectangle {
text: {
switch (header.currentPage) {
case "settings": return "Settings"
case "reader": return bookController.bookTitle || ""
case "reader": return book.title || ""
default: return ""
}
}
+15 -30
View File
@@ -34,25 +34,21 @@ Rectangle {
}
function handleScrollUp() {
// Scroll up by approximately 2-3 lines
var lineHeight = appState.fontSize * appState.lineSpacing;
var scrollAmount = lineHeight * 3; // ~2-3 lines
var lineHeight = readingPreferences.fontSize * readingPreferences.lineSpacing;
var scrollAmount = lineHeight * 3;
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;
var scrollAmount = lineHeight * 3; // ~2-3 lines
var lineHeight = readingPreferences.fontSize * readingPreferences.lineSpacing;
var scrollAmount = lineHeight * 3;
var maxY = Math.max(0, chunkListView.contentHeight - chunkListView.height);
var targetY = Math.min(maxY, chunkListView.contentY + scrollAmount);
animateScrollTo(targetY);
}
// Helper function to animate scrolling
function animateScrollTo(targetY) {
// Stop any ongoing animation
scrollAnimation.stop();
scrollAnimation.to = targetY;
scrollAnimation.start();
@@ -64,7 +60,7 @@ Rectangle {
}
function updateContentWidth() {
bookController.setContentWidth(chunkListView.width - 18 - 2 * appState.horizontalMargin)
book.setContentWidth(chunkListView.width - 18 - 2 * readingPreferences.horizontalMargin)
}
Component.onCompleted: updateContentWidth()
@@ -87,8 +83,8 @@ Rectangle {
id: chunkListView
anchors.fill: parent
model: contentReady ? readingModel : null
header: Item { height: appState.verticalMargin }
footer: Item { height: appState.verticalMargin }
header: Item { height: readingPreferences.verticalMargin }
footer: Item { height: readingPreferences.verticalMargin }
cacheBuffer: 20
clip: true
@@ -108,16 +104,15 @@ Rectangle {
Text {
id: contentText
width: parent.width - 18 // subtract scrollbar
leftPadding: appState.horizontalMargin
rightPadding: appState.horizontalMargin
leftPadding: readingPreferences.horizontalMargin
rightPadding: readingPreferences.horizontalMargin
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
textFormat: Text.RichText
font.pixelSize: appState.fontSize
lineHeight: appState.lineSpacing
font.pixelSize: readingPreferences.fontSize
lineHeight: readingPreferences.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
@@ -177,21 +172,21 @@ Rectangle {
interval: 300
repeat: false
onTriggered: {
if (bookController.hasBook && contentReady && restoreReady) {
if (book.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)
book.saveCurrentPosition(topIdx, intraOffset)
}
}
}
Connections {
target: bookController
target: book
function onLoadingChanged() {
if (bookController.loading)
if (book.loading)
contentReady = false
}
}
@@ -209,16 +204,6 @@ Rectangle {
}
}
Connections {
target: appState
function onFontSizeChanged() {
readingModel.setFontParams(appState.fontSize, appState.lineSpacing)
}
function onLineSpacingChanged() {
readingModel.setFontParams(appState.fontSize, appState.lineSpacing)
}
}
Timer {
id: restoreTimer
interval: 1
+3 -3
View File
@@ -73,7 +73,7 @@ Rectangle {
}
SideBarButton {
visible: bookController.hasBook
visible: book.hasBook
iconText: "\ue5cd"
title: "Close Book"
onClicked: sidebar.closeBook()
@@ -114,7 +114,7 @@ Rectangle {
// TOC section — shown when the current book has a table of contents
Item {
visible: bookController.hasBook && bookController.toc.length > 0
visible: book.hasBook && book.toc.length > 0
anchors.top: navColumn.bottom
anchors.bottom: parent.bottom
width: parent.width
@@ -145,7 +145,7 @@ Rectangle {
anchors.bottom: parent.bottom
width: parent.width
clip: true
model: bookController.toc
model: book.toc
delegate: Rectangle {
width: ListView.view.width