84 lines
2.5 KiB
QML
84 lines
2.5 KiB
QML
import QtQuick
|
|
import QtQuick.Controls
|
|
import Asteria
|
|
|
|
Rectangle {
|
|
gradient: Gradient {
|
|
GradientStop { position: 0.0; color: Theme.gradientTop }
|
|
GradientStop { position: 1.0; color: Theme.gradientBottom }
|
|
}
|
|
|
|
ListView {
|
|
id: chunkListView
|
|
anchors.fill: parent
|
|
anchors.leftMargin: 12
|
|
model: bookController.hasBook ? readingModel : null
|
|
cacheBuffer: 2000
|
|
clip: true
|
|
|
|
delegate: Text {
|
|
width: ListView.view.width - 18
|
|
rightPadding: 2
|
|
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
|
|
textFormat: Text.RichText
|
|
font.pixelSize: 16
|
|
lineHeight: 1.6
|
|
color: Theme.readingText
|
|
text: model.content
|
|
}
|
|
|
|
onContentYChanged: scrollTrackTimer.restart()
|
|
|
|
ScrollBar.vertical: ScrollBar {
|
|
policy: ScrollBar.AsNeeded
|
|
padding: 0
|
|
contentItem: Rectangle {
|
|
implicitWidth: 18
|
|
radius: 3
|
|
color: Theme.scrollbarThumb
|
|
}
|
|
background: Rectangle {
|
|
implicitWidth: 18
|
|
color: Theme.scrollbarTrack
|
|
}
|
|
}
|
|
|
|
// Placeholder when no book is open
|
|
Text {
|
|
anchors.centerIn: parent
|
|
visible: !bookController.hasBook
|
|
text: "Open a book to start reading"
|
|
font.pixelSize: 16
|
|
color: Theme.readingText
|
|
}
|
|
}
|
|
|
|
Timer {
|
|
id: scrollTrackTimer
|
|
interval: 300
|
|
repeat: false
|
|
onTriggered: {
|
|
var idx = chunkListView.indexAt(0, chunkListView.contentY)
|
|
appState.lastScrollIndex = idx
|
|
var item = chunkListView.itemAtIndex(idx)
|
|
appState.lastScrollOffset = item ? chunkListView.contentY - item.y : 0
|
|
appState.lastScrollPosition = chunkListView.contentY
|
|
}
|
|
}
|
|
|
|
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
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|