Manga rendering mode
This commit is contained in:
15 files changed
+935
-253
No files matched your search
@@ -0,0 +1,220 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
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
|
||||
property: "contentY"
|
||||
duration: 200
|
||||
easing.type: Easing.InOutQuad
|
||||
}
|
||||
|
||||
// Public methods for global keyboard navigation
|
||||
function handlePageUp() {
|
||||
var scrollAmount = chunkListView.height * 0.95;
|
||||
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() {
|
||||
var lineHeight = readingPreferences.fontSize * readingPreferences.lineSpacing;
|
||||
var scrollAmount = lineHeight * 3;
|
||||
var targetY = Math.max(0, chunkListView.contentY - scrollAmount);
|
||||
animateScrollTo(targetY);
|
||||
}
|
||||
|
||||
function handleScrollDown() {
|
||||
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);
|
||||
}
|
||||
|
||||
function animateScrollTo(targetY) {
|
||||
scrollAnimation.stop();
|
||||
scrollAnimation.to = targetY;
|
||||
scrollAnimation.start();
|
||||
}
|
||||
|
||||
gradient: Gradient {
|
||||
GradientStop { position: 0.0; color: ThemeManager.currentTheme.gradientTop }
|
||||
GradientStop { position: 1.0; color: ThemeManager.currentTheme.gradientBottom }
|
||||
}
|
||||
|
||||
function updateContentWidth() {
|
||||
book.setContentWidth(chunkListView.width - 18 - 2 * readingPreferences.horizontalMargin)
|
||||
}
|
||||
|
||||
Component.onCompleted: updateContentWidth()
|
||||
onWidthChanged: {
|
||||
resizing = true;
|
||||
remeasureTimer.restart()
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: remeasureTimer
|
||||
interval: 150
|
||||
repeat: false
|
||||
onTriggered: {
|
||||
updateContentWidth()
|
||||
resizing = false;
|
||||
}
|
||||
}
|
||||
|
||||
ListView {
|
||||
id: chunkListView
|
||||
anchors.fill: parent
|
||||
anchors.topMargin: readingPreferences.verticalMargin
|
||||
anchors.bottomMargin: readingPreferences.verticalMargin
|
||||
model: contentReady ? readingModel : null
|
||||
cacheBuffer: 20
|
||||
clip: true
|
||||
maximumFlickVelocity: 99999
|
||||
|
||||
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: readingPreferences.horizontalMargin
|
||||
rightPadding: readingPreferences.horizontalMargin
|
||||
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
|
||||
textFormat: Text.RichText
|
||||
font.pixelSize: readingPreferences.fontSize
|
||||
lineHeight: readingPreferences.lineSpacing
|
||||
color: ThemeManager.currentTheme.readingText
|
||||
text: model.content
|
||||
visible: model.content !== ""
|
||||
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()
|
||||
}
|
||||
|
||||
ScrollBar.vertical: ScrollBar {
|
||||
policy: ScrollBar.AsNeeded
|
||||
padding: 0
|
||||
contentItem: Rectangle {
|
||||
implicitWidth: 18
|
||||
radius: 3
|
||||
color: ThemeManager.currentTheme.scrollbarThumb
|
||||
}
|
||||
background: Rectangle {
|
||||
implicitWidth: 18
|
||||
color: ThemeManager.currentTheme.scrollbarTrack
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
anchors.rightMargin: 18
|
||||
z: 1
|
||||
onClicked: clickDebounce.restart()
|
||||
onDoubleClicked: {
|
||||
clickDebounce.stop()
|
||||
window.visibility = (window.visibility === Window.FullScreen) ? Window.Windowed : Window.FullScreen
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: clickDebounce
|
||||
interval: 150
|
||||
onTriggered: {
|
||||
window.barsVisible = !window.barsVisible
|
||||
window.sidebarOpen = !window.sidebarOpen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Timer {
|
||||
id: scrollTrackTimer
|
||||
interval: 300
|
||||
repeat: false
|
||||
onTriggered: {
|
||||
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)
|
||||
book.saveCurrentPosition(topIdx, intraOffset)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: book
|
||||
function onLoadingChanged() {
|
||||
if (book.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)
|
||||
}
|
||||
}
|
||||
|
||||
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