lint refactor
This commit is contained in:
53 files changed
+891
-670
No files matched your search
@@ -1,67 +1,64 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Controls.Basic
|
||||
import Asteria
|
||||
|
||||
Rectangle {
|
||||
id: root
|
||||
focus: true
|
||||
|
||||
readonly property bool landscape: root.width > root.height
|
||||
property bool contentReady: false
|
||||
property int currentPair: 0
|
||||
|
||||
readonly property bool landscape: width > height
|
||||
|
||||
focus: true
|
||||
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 handlePageDown() { root.nextPair() }
|
||||
function handlePageUp() { root.previousPair() }
|
||||
function handleScrollDown() { root.nextPair() }
|
||||
function handleScrollUp() { root.previousPair() }
|
||||
|
||||
function nextPair() {
|
||||
if (currentPair < readingModel.totalPagePairs - 1)
|
||||
showPair(currentPair + 1)
|
||||
if (root.currentPair < ReadingModel.totalPagePairs - 1)
|
||||
root.showPair(root.currentPair + 1)
|
||||
}
|
||||
|
||||
function previousPair() {
|
||||
if (currentPair > 0)
|
||||
showPair(currentPair - 1)
|
||||
if (root.currentPair > 0)
|
||||
root.showPair(root.currentPair - 1)
|
||||
}
|
||||
|
||||
// Single entry point for displaying a pair: sets the index, refreshes the
|
||||
// displayed pair contents, and syncs scroll/position state.
|
||||
function showPair(pairIndex) {
|
||||
currentPair = pairIndex
|
||||
pageArea.pair = contentReady ? readingModel.pagePair(pairIndex) : []
|
||||
root.currentPair = pairIndex
|
||||
pageArea.pair = root.contentReady ? ReadingModel.pagePair(pairIndex) : []
|
||||
const pair = pageArea.pair
|
||||
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, pairIndex / Math.max(1, readingModel.totalPagePairs - 1))
|
||||
ReadingModel.setScrollInfo(firstChunk, pairIndex / Math.max(1, ReadingModel.totalPagePairs - 1))
|
||||
}
|
||||
|
||||
// Notify model when orientation changes (triggers pair rebuild).
|
||||
onLandscapeChanged: landscapeDebounce.restart()
|
||||
|
||||
// Initialise landscape state once visible.
|
||||
Component.onCompleted: ReadingModel.setMangaLandscape(root.landscape)
|
||||
|
||||
Timer {
|
||||
id: landscapeDebounce
|
||||
interval: 150
|
||||
repeat: false
|
||||
onTriggered: readingModel.setMangaLandscape(landscape)
|
||||
onTriggered: ReadingModel.setMangaLandscape(root.landscape)
|
||||
}
|
||||
|
||||
// Initialise landscape state once visible.
|
||||
Component.onCompleted: readingModel.setMangaLandscape(landscape)
|
||||
|
||||
// Page display area.
|
||||
Item {
|
||||
id: pageArea
|
||||
anchors.fill: parent
|
||||
anchors.margins: readingPreferences.verticalMargin
|
||||
|
||||
// Display pair, updated by showPair(). For RTL mode pages are reversed
|
||||
// (higher index on the left) via leftChunk/rightChunk below.
|
||||
@@ -70,47 +67,54 @@ Rectangle {
|
||||
property int leftChunk: {
|
||||
if (pair.length === 0) return -1
|
||||
if (pair.length === 1) return pair[0]
|
||||
return readingModel.mangaRTL ? pair[1] : 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]
|
||||
return ReadingModel.mangaRTL ? pair[0] : pair[1]
|
||||
}
|
||||
|
||||
property bool hasTwoPages: pair.length === 2
|
||||
|
||||
anchors {
|
||||
fill: parent
|
||||
margins: ReadingPreferences.verticalMargin
|
||||
}
|
||||
|
||||
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
|
||||
visible: pageArea.leftChunk >= 0
|
||||
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) : ""
|
||||
sourceSize: Qt.size(width, height)
|
||||
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
|
||||
visible: pageArea.rightChunk >= 0
|
||||
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) : ""
|
||||
sourceSize: Qt.size(width, height)
|
||||
source: pageArea.rightChunk >= 0 ? ReadingModel.imageUrlForChunk(pageArea.rightChunk) : ""
|
||||
}
|
||||
|
||||
// Loading indicator while images load.
|
||||
@@ -125,13 +129,14 @@ Rectangle {
|
||||
// Swipe / tap input.
|
||||
MouseArea {
|
||||
id: inputArea
|
||||
anchors.fill: parent
|
||||
z: 10
|
||||
|
||||
property real pressX: 0
|
||||
property real startPressX: 0
|
||||
property bool dragging: false
|
||||
|
||||
anchors.fill: parent
|
||||
z: 10
|
||||
|
||||
onPressed: function(mouse) {
|
||||
pressX = mouse.x
|
||||
startPressX = mouse.x
|
||||
@@ -147,10 +152,10 @@ Rectangle {
|
||||
const dx = mouse.x - startPressX
|
||||
if (Math.abs(dx) > root.width * 0.12) {
|
||||
// Swipe gesture.
|
||||
if (readingModel.mangaRTL) {
|
||||
if (dx < 0) nextPair(); else previousPair()
|
||||
if (ReadingModel.mangaRTL) {
|
||||
if (dx < 0) root.nextPair(); else root.previousPair()
|
||||
} else {
|
||||
if (dx > 0) nextPair(); else previousPair()
|
||||
if (dx > 0) root.nextPair(); else root.previousPair()
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -162,51 +167,56 @@ Rectangle {
|
||||
|
||||
onDoubleClicked: {
|
||||
clickDebounce.stop()
|
||||
window.visibility = (window.visibility === Window.FullScreen) ? Window.Windowed : Window.FullScreen
|
||||
if (root.Window.window) {
|
||||
root.Window.window.visibility = (root.Window.window.visibility === Window.FullScreen)
|
||||
? Window.Windowed : Window.FullScreen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: clickDebounce
|
||||
interval: 150
|
||||
|
||||
property real clickX: 0
|
||||
|
||||
interval: 150
|
||||
onTriggered: {
|
||||
const third = root.width / 3
|
||||
if (clickX < third) {
|
||||
// Left third tap.
|
||||
if (readingModel.mangaRTL) nextPair(); else previousPair()
|
||||
if (ReadingModel.mangaRTL) root.nextPair(); else root.previousPair()
|
||||
} else if (clickX > root.width - third) {
|
||||
// Right third tap.
|
||||
if (readingModel.mangaRTL) previousPair(); else nextPair()
|
||||
if (ReadingModel.mangaRTL) root.previousPair(); else root.nextPair()
|
||||
} else {
|
||||
// Middle — toggle chrome.
|
||||
window.toggleChrome()
|
||||
UiState.barsVisible = !UiState.barsVisible
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Restore position when a new book is loaded.
|
||||
Connections {
|
||||
target: readingModel
|
||||
target: ReadingModel
|
||||
function onRestoreReady(chunkIndex) {
|
||||
contentReady = true
|
||||
showPair(readingModel.pairIndexForChunk(chunkIndex))
|
||||
root.contentReady = true
|
||||
root.showPair(ReadingModel.pairIndexForChunk(chunkIndex))
|
||||
}
|
||||
function onTotalPagePairsChanged() {
|
||||
// Re-clamp after pair rebuild (resize / orientation flip).
|
||||
showPair(Math.min(currentPair, Math.max(0, readingModel.totalPagePairs - 1)))
|
||||
root.showPair(Math.min(root.currentPair, Math.max(0, ReadingModel.totalPagePairs - 1)))
|
||||
}
|
||||
function onPagePairsRebuilt(newPairIndex) {
|
||||
// setPageShift rebuilt the pairs; refresh even when the index is
|
||||
// unchanged since the pair contents may differ.
|
||||
showPair(newPairIndex)
|
||||
root.showPair(newPairIndex)
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: book
|
||||
target: Book
|
||||
function onLoadingChanged() {
|
||||
if (book.loading) contentReady = false
|
||||
if (Book.loading) root.contentReady = false
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user