Manga rendering mode
This commit is contained in:
15 files changed
+935
-253
No files matched your search
@@ -0,0 +1,228 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import Asteria
|
||||
|
||||
Rectangle {
|
||||
id: root
|
||||
focus: true
|
||||
|
||||
// Keep the same public interface as ScrollPageView so PageView router delegates uniformly.
|
||||
property bool contentReady: false
|
||||
property bool resizing: false
|
||||
property bool restoreReady: false
|
||||
property int initialIndex: -1
|
||||
property int initialOffset: -1
|
||||
|
||||
property int currentPair: 0
|
||||
|
||||
readonly property bool landscape: width > height
|
||||
|
||||
gradient: Gradient {
|
||||
GradientStop { position: 0.0; color: ThemeManager.currentTheme.gradientTop }
|
||||
GradientStop { position: 1.0; color: ThemeManager.currentTheme.gradientBottom }
|
||||
}
|
||||
|
||||
// Keyboard navigation — same names as ScrollPageView so PageView can forward blindly.
|
||||
function handlePageDown() { nextPair() }
|
||||
function handlePageUp() { previousPair() }
|
||||
function handleScrollDown() { nextPair() }
|
||||
function handleScrollUp() { previousPair() }
|
||||
|
||||
function nextPair() {
|
||||
if (currentPair < readingModel.totalPagePairs - 1) {
|
||||
currentPair++
|
||||
onPairChanged()
|
||||
}
|
||||
}
|
||||
|
||||
function previousPair() {
|
||||
if (currentPair > 0) {
|
||||
currentPair--
|
||||
onPairChanged()
|
||||
}
|
||||
}
|
||||
|
||||
function onPairChanged() {
|
||||
const pair = readingModel.pagePair(currentPair)
|
||||
if (pair.length === 0) return
|
||||
const firstChunk = pair[0]
|
||||
// Keep scroll model in sync so Footer page counter and chapter tracking work.
|
||||
readingModel.setScrollInfo(firstChunk, currentPair / Math.max(1, readingModel.totalPagePairs - 1))
|
||||
book.saveCurrentPosition(firstChunk, 0, readingModel.pageShift)
|
||||
// Sync currentPage for footer display.
|
||||
// totalPages is already set to totalPagePairs by the model in manga mode.
|
||||
}
|
||||
|
||||
// Notify model when orientation changes (triggers pair rebuild).
|
||||
onLandscapeChanged: landscapeDebounce.restart()
|
||||
|
||||
Timer {
|
||||
id: landscapeDebounce
|
||||
interval: 150
|
||||
repeat: false
|
||||
onTriggered: readingModel.setMangaLandscape(landscape)
|
||||
}
|
||||
|
||||
// Initialise landscape state once visible.
|
||||
Component.onCompleted: readingModel.setMangaLandscape(landscape)
|
||||
|
||||
// Page display area.
|
||||
Item {
|
||||
id: pageArea
|
||||
anchors.fill: parent
|
||||
anchors.margins: readingPreferences.verticalMargin
|
||||
|
||||
// Build display pair: for RTL mode pages are reversed (higher index on the left).
|
||||
property var pair: contentReady ? readingModel.pagePair(currentPair) : []
|
||||
|
||||
property int leftChunk: {
|
||||
if (pair.length === 0) return -1
|
||||
if (pair.length === 1) return pair[0]
|
||||
return readingModel.mangaRTL ? pair[1] : pair[0]
|
||||
}
|
||||
property int rightChunk: {
|
||||
if (pair.length < 2) return -1
|
||||
return readingModel.mangaRTL ? pair[0] : pair[1]
|
||||
}
|
||||
|
||||
property bool hasTwoPages: pair.length === 2
|
||||
|
||||
Behavior on opacity { NumberAnimation { duration: 120 } }
|
||||
|
||||
// Left (or solo) page.
|
||||
Image {
|
||||
id: leftImg
|
||||
visible: pageArea.leftChunk >= 0
|
||||
x: 0
|
||||
y: 0
|
||||
width: pageArea.hasTwoPages ? parent.width / 2 : parent.width
|
||||
height: parent.height
|
||||
fillMode: Image.PreserveAspectFit
|
||||
// When paired, pin content to the spine (right edge) so there's no gap between pages.
|
||||
horizontalAlignment: pageArea.hasTwoPages ? Image.AlignRight : Image.AlignHCenter
|
||||
asynchronous: true
|
||||
cache: true
|
||||
source: pageArea.leftChunk >= 0 ? readingModel.imageUrlForChunk(pageArea.leftChunk) : ""
|
||||
}
|
||||
|
||||
// Right page (landscape two-page spread only).
|
||||
Image {
|
||||
id: rightImg
|
||||
visible: pageArea.rightChunk >= 0
|
||||
x: parent.width / 2
|
||||
y: 0
|
||||
width: parent.width / 2
|
||||
height: parent.height
|
||||
fillMode: Image.PreserveAspectFit
|
||||
// Pin content to the spine (left edge) so it meets the left page with no gap.
|
||||
horizontalAlignment: Image.AlignLeft
|
||||
asynchronous: true
|
||||
cache: true
|
||||
source: pageArea.rightChunk >= 0 ? readingModel.imageUrlForChunk(pageArea.rightChunk) : ""
|
||||
}
|
||||
|
||||
// Loading indicator while images load.
|
||||
BusyIndicator {
|
||||
anchors.centerIn: parent
|
||||
running: (leftImg.status === Image.Loading) || (rightImg.visible && rightImg.status === Image.Loading)
|
||||
visible: running
|
||||
z: 5
|
||||
}
|
||||
}
|
||||
|
||||
// Swipe / tap input.
|
||||
MouseArea {
|
||||
id: inputArea
|
||||
anchors.fill: parent
|
||||
z: 10
|
||||
|
||||
property real pressX: 0
|
||||
property real startPressX: 0
|
||||
property bool dragging: false
|
||||
|
||||
onPressed: function(mouse) {
|
||||
pressX = mouse.x
|
||||
startPressX = mouse.x
|
||||
dragging = false
|
||||
}
|
||||
|
||||
onPositionChanged: function(mouse) {
|
||||
if (Math.abs(mouse.x - startPressX) > 8)
|
||||
dragging = true
|
||||
}
|
||||
|
||||
onReleased: function(mouse) {
|
||||
const dx = mouse.x - startPressX
|
||||
if (Math.abs(dx) > root.width * 0.12) {
|
||||
// Swipe gesture.
|
||||
if (readingModel.mangaRTL) {
|
||||
if (dx < 0) nextPair(); else previousPair()
|
||||
} else {
|
||||
if (dx > 0) nextPair(); else previousPair()
|
||||
}
|
||||
return
|
||||
}
|
||||
if (dragging) return
|
||||
// Tap zones — only if not a swipe.
|
||||
clickDebounce.clickX = mouse.x
|
||||
clickDebounce.restart()
|
||||
}
|
||||
|
||||
onDoubleClicked: {
|
||||
clickDebounce.stop()
|
||||
window.visibility = (window.visibility === Window.FullScreen) ? Window.Windowed : Window.FullScreen
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: clickDebounce
|
||||
interval: 150
|
||||
property real clickX: 0
|
||||
onTriggered: {
|
||||
const third = root.width / 3
|
||||
if (clickX < third) {
|
||||
// Left third tap.
|
||||
if (readingModel.mangaRTL) nextPair(); else previousPair()
|
||||
} else if (clickX > root.width - third) {
|
||||
// Right third tap.
|
||||
if (readingModel.mangaRTL) previousPair(); else nextPair()
|
||||
} else {
|
||||
// Middle — toggle bars.
|
||||
window.barsVisible = !window.barsVisible
|
||||
window.sidebarOpen = !window.sidebarOpen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Restore position when a new book is loaded.
|
||||
Connections {
|
||||
target: readingModel
|
||||
function onRestoreReady(chunkIndex, intraOffset) {
|
||||
contentReady = true
|
||||
const pair = readingModel.pairIndexForChunk(chunkIndex)
|
||||
currentPair = pair
|
||||
restoreReady = true
|
||||
onPairChanged()
|
||||
}
|
||||
function onTotalPagePairsChanged() {
|
||||
// Re-clamp after pair rebuild (resize / orientation flip).
|
||||
currentPair = Math.min(currentPair, Math.max(0, readingModel.totalPagePairs - 1))
|
||||
}
|
||||
function onPagePairsRebuilt(newPairIndex) {
|
||||
// setPageShift rebuilt the pairs — the pair-content binding needs to re-evaluate
|
||||
// even when newPairIndex equals the existing currentPair (toggling shift can leave
|
||||
// the index unchanged while pair contents change). Two writes force two change
|
||||
// notifications; the binding is read once after the function returns with the
|
||||
// final value, so the -1 intermediate is never displayed.
|
||||
currentPair = -1
|
||||
currentPair = newPairIndex
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: book
|
||||
function onLoadingChanged() {
|
||||
if (book.loading) contentReady = false
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user