Some refactor
This commit is contained in:
37 files changed
+1599
-981
No files matched your search
+62
-52
@@ -17,49 +17,51 @@ ApplicationWindow {
|
||||
source: "qrc:/Asteria/src/assets/MaterialIconsOutlined-Regular.otf"
|
||||
}
|
||||
|
||||
property bool sidebarOpen: appState.sidebarOpen
|
||||
onSidebarOpenChanged: appState.sidebarOpen = sidebarOpen
|
||||
property bool sidebarOpen: uiState.sidebarOpen
|
||||
onSidebarOpenChanged: uiState.sidebarOpen = sidebarOpen
|
||||
property string currentPage: "starter"
|
||||
property bool barsVisible: true
|
||||
// Set to true on the first book open at startup so we restore the last page.
|
||||
property bool _startupRestore: false
|
||||
|
||||
onCurrentPageChanged: appState.lastPage = currentPage
|
||||
onCurrentPageChanged: uiState.lastPage = currentPage
|
||||
|
||||
Component.onCompleted: {
|
||||
width = appState.windowWidth
|
||||
height = appState.windowHeight
|
||||
if (appState.windowX >= 0 && appState.windowY >= 0) {
|
||||
x = appState.windowX
|
||||
y = appState.windowY
|
||||
}
|
||||
// Initialize theme from AppState
|
||||
if (appState.themeName !== "") {
|
||||
ThemeManager.currentThemeName = appState.themeName
|
||||
width = uiState.windowWidth
|
||||
height = uiState.windowHeight
|
||||
if (uiState.windowX >= 0 && uiState.windowY >= 0) {
|
||||
x = uiState.windowX
|
||||
y = uiState.windowY
|
||||
}
|
||||
if (uiState.themeName !== "")
|
||||
ThemeManager.currentThemeName = uiState.themeName
|
||||
|
||||
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: appState
|
||||
target: uiState
|
||||
function onThemeNameChanged() {
|
||||
ThemeManager.currentThemeName = appState.themeName
|
||||
ThemeManager.currentThemeName = uiState.themeName
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: geometrySaveTimer
|
||||
interval: 500
|
||||
interval: 250
|
||||
repeat: false
|
||||
onTriggered: {
|
||||
appState.windowWidth = window.width
|
||||
appState.windowHeight = window.height
|
||||
appState.windowX = window.x
|
||||
appState.windowY = window.y
|
||||
uiState.windowWidth = window.width
|
||||
uiState.windowHeight = window.height
|
||||
uiState.windowX = window.x
|
||||
uiState.windowY = window.y
|
||||
}
|
||||
}
|
||||
|
||||
onWidthChanged: geometrySaveTimer.restart()
|
||||
onWidthChanged: geometrySaveTimer.restart()
|
||||
onHeightChanged: geometrySaveTimer.restart()
|
||||
onXChanged: geometrySaveTimer.restart()
|
||||
onYChanged: geometrySaveTimer.restart()
|
||||
onXChanged: geometrySaveTimer.restart()
|
||||
onYChanged: geometrySaveTimer.restart()
|
||||
|
||||
Row {
|
||||
anchors.fill: parent
|
||||
@@ -73,10 +75,10 @@ ApplicationWindow {
|
||||
window.currentPage = page
|
||||
}
|
||||
onOpenFile: {
|
||||
bookController.browseAndOpen()
|
||||
book.browseAndOpen()
|
||||
}
|
||||
onCloseBook: {
|
||||
bookController.closeBook()
|
||||
book.close()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +123,7 @@ ApplicationWindow {
|
||||
|
||||
BusyIndicator {
|
||||
anchors.centerIn: parent
|
||||
running: bookController.loading || readingModel.measuring
|
||||
running: book.loading || readingModel.measuring
|
||||
visible: running
|
||||
z: 10
|
||||
}
|
||||
@@ -141,6 +143,32 @@ ApplicationWindow {
|
||||
z: 3000
|
||||
}
|
||||
|
||||
// Navigate once measurement (and position restoration) is done
|
||||
Connections {
|
||||
target: readingModel
|
||||
function onRestoreReady(chunkIndex, intraOffset) {
|
||||
if (!book.hasBook) return
|
||||
if (window._startupRestore) {
|
||||
window._startupRestore = false
|
||||
var savedPage = uiState.lastPage
|
||||
if (savedPage === "library" || savedPage === "settings")
|
||||
window.currentPage = savedPage
|
||||
else
|
||||
window.currentPage = "reader"
|
||||
} else {
|
||||
window.currentPage = "reader"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: book
|
||||
function onBookChanged() {
|
||||
if (!book.hasBook && window.currentPage === "reader")
|
||||
window.currentPage = "starter"
|
||||
}
|
||||
}
|
||||
|
||||
// Global keyboard shortcuts - work regardless of focus
|
||||
Shortcut {
|
||||
sequence: "F"
|
||||
@@ -188,7 +216,6 @@ ApplicationWindow {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Fallback shortcuts using alternative key names
|
||||
Shortcut {
|
||||
sequence: "Prior"
|
||||
context: Qt.ApplicationShortcut
|
||||
@@ -217,31 +244,6 @@ ApplicationWindow {
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: bookController
|
||||
function onBookReady() {
|
||||
if (bookController.startupRestore) {
|
||||
var savedPage = appState.lastPage
|
||||
if (savedPage === "library" || savedPage === "settings")
|
||||
window.currentPage = savedPage
|
||||
else
|
||||
window.currentPage = "reader"
|
||||
} else {
|
||||
window.currentPage = "reader"
|
||||
}
|
||||
}
|
||||
function onBookChanged() {
|
||||
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
|
||||
@@ -250,7 +252,15 @@ ApplicationWindow {
|
||||
onTriggered: {
|
||||
window.opacity = 1
|
||||
readerPage.pageView.updateContentWidth()
|
||||
bookController.uiReady()
|
||||
if (uiState.lastFilePath !== "") {
|
||||
window._startupRestore = true
|
||||
book.openFromPath(uiState.lastFilePath)
|
||||
} else {
|
||||
var savedPage = uiState.lastPage
|
||||
if (savedPage === "library" || savedPage === "settings")
|
||||
window.currentPage = savedPage
|
||||
window.sidebarOpen = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,27 +14,16 @@ QtObject {
|
||||
|
||||
function setDarkTheme() {
|
||||
currentThemeName = "dark"
|
||||
if (appState) {
|
||||
appState.themeName = "dark"
|
||||
}
|
||||
uiState.themeName = "dark"
|
||||
}
|
||||
|
||||
|
||||
function setLightTheme() {
|
||||
currentThemeName = "light"
|
||||
if (appState) {
|
||||
appState.themeName = "light"
|
||||
}
|
||||
uiState.themeName = "light"
|
||||
}
|
||||
|
||||
|
||||
function toggleTheme() {
|
||||
currentThemeName = currentThemeName === "dark" ? "light" : "dark"
|
||||
if (appState) {
|
||||
appState.themeName = currentThemeName
|
||||
}
|
||||
}
|
||||
|
||||
onCurrentThemeNameChanged: {
|
||||
// This ensures UI updates when theme changes
|
||||
// The actual theme switching happens through the currentTheme property
|
||||
uiState.themeName = currentThemeName
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 ""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -6,7 +6,7 @@ Rectangle {
|
||||
color: ThemeManager.currentTheme.backgroundDefault
|
||||
|
||||
Text {
|
||||
visible: appState.libraryModel.count === 0
|
||||
visible: 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.libraryModel.count > 0
|
||||
visible: libraryModel.count > 0
|
||||
anchors.fill: parent
|
||||
anchors.margins: 16
|
||||
spacing: 8
|
||||
clip: true
|
||||
model: appState.libraryModel
|
||||
model: libraryModel
|
||||
|
||||
delegate: Rectangle {
|
||||
id: bookRow
|
||||
@@ -92,14 +92,14 @@ Rectangle {
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
}
|
||||
background: Item {}
|
||||
onClicked: appState.removeLibraryBook(filePath)
|
||||
onClicked: libraryModel.removeBook(filePath)
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
z: -1
|
||||
onClicked: bookController.openBookFromPath(filePath)
|
||||
onClicked: book.openFromPath(filePath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ Rectangle {
|
||||
Timer {
|
||||
id: hmTimer
|
||||
interval: 250
|
||||
onTriggered: appState.horizontalMargin = hmSlider.value
|
||||
onTriggered: readingPreferences.horizontalMargin = hmSlider.value
|
||||
}
|
||||
|
||||
Slider {
|
||||
@@ -65,9 +65,9 @@ Rectangle {
|
||||
from: 0
|
||||
to: 120
|
||||
stepSize: 1
|
||||
value: appState.horizontalMargin
|
||||
value: readingPreferences.horizontalMargin
|
||||
onValueChanged: {
|
||||
if (value !== appState.horizontalMargin)
|
||||
if (value !== readingPreferences.horizontalMargin)
|
||||
hmTimer.restart()
|
||||
}
|
||||
}
|
||||
@@ -103,7 +103,7 @@ Rectangle {
|
||||
Timer {
|
||||
id: vmTimer
|
||||
interval: 250
|
||||
onTriggered: appState.verticalMargin = vmSlider.value
|
||||
onTriggered: readingPreferences.verticalMargin = vmSlider.value
|
||||
}
|
||||
|
||||
Slider {
|
||||
@@ -112,9 +112,9 @@ Rectangle {
|
||||
from: 0
|
||||
to: 80
|
||||
stepSize: 1
|
||||
value: appState.verticalMargin
|
||||
value: readingPreferences.verticalMargin
|
||||
onValueChanged: {
|
||||
if (value !== appState.verticalMargin)
|
||||
if (value !== readingPreferences.verticalMargin)
|
||||
vmTimer.restart()
|
||||
}
|
||||
}
|
||||
@@ -150,7 +150,7 @@ Rectangle {
|
||||
Timer {
|
||||
id: fsTimer
|
||||
interval: 250
|
||||
onTriggered: appState.fontSize = fsSlider.value
|
||||
onTriggered: readingPreferences.fontSize = fsSlider.value
|
||||
}
|
||||
|
||||
Slider {
|
||||
@@ -159,9 +159,9 @@ Rectangle {
|
||||
from: 10
|
||||
to: 32
|
||||
stepSize: 1
|
||||
value: appState.fontSize
|
||||
value: readingPreferences.fontSize
|
||||
onValueChanged: {
|
||||
if (value !== appState.fontSize)
|
||||
if (value !== readingPreferences.fontSize)
|
||||
fsTimer.restart()
|
||||
}
|
||||
}
|
||||
@@ -197,7 +197,7 @@ Rectangle {
|
||||
Timer {
|
||||
id: lsTimer
|
||||
interval: 250
|
||||
onTriggered: appState.lineSpacing = lsSlider.value
|
||||
onTriggered: readingPreferences.lineSpacing = lsSlider.value
|
||||
}
|
||||
|
||||
Slider {
|
||||
@@ -206,9 +206,9 @@ Rectangle {
|
||||
from: 0.5
|
||||
to: 3.0
|
||||
stepSize: 0.1
|
||||
value: appState.lineSpacing
|
||||
value: readingPreferences.lineSpacing
|
||||
onValueChanged: {
|
||||
if (Math.abs(value - appState.lineSpacing) > 0.01)
|
||||
if (Math.abs(value - readingPreferences.lineSpacing) > 0.01)
|
||||
lsTimer.restart()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user