From ba2f7207d8129022511ca2238fed6fad45799dff Mon Sep 17 00:00:00 2001 From: Agel Date: Sun, 29 Mar 2026 23:20:46 +0200 Subject: [PATCH] revamp shortcuts --- src/qml/Main.qml | 68 +++++++++++++++++++++++++++++++++ src/qml/components/PageView.qml | 28 +++++++++++++- src/qml/pages/ReaderPage.qml | 12 ++++-- 3 files changed, 103 insertions(+), 5 deletions(-) diff --git a/src/qml/Main.qml b/src/qml/Main.qml index 3fe3591..d87d729 100644 --- a/src/qml/Main.qml +++ b/src/qml/Main.qml @@ -101,6 +101,7 @@ ApplicationWindow { } ReaderPage { + id: readerPage anchors.fill: parent visible: window.currentPage === "reader" } @@ -130,14 +131,81 @@ ApplicationWindow { z: 3000 } + // Global keyboard shortcuts - work regardless of focus Shortcut { sequence: "F" + context: Qt.ApplicationShortcut onActivated: window.visibility = (window.visibility === Window.FullScreen) ? Window.Windowed : Window.FullScreen } Shortcut { sequence: "F11" + context: Qt.ApplicationShortcut onActivated: window.visibility = (window.visibility === Window.FullScreen) ? Window.Windowed : Window.FullScreen } + Shortcut { + sequence: "Up" + context: Qt.ApplicationShortcut + onActivated: { + if (currentPage === "reader" && readerPage?.pageView) { + readerPage.pageView.handleScrollUp(); + } + } + } + Shortcut { + sequence: "Down" + context: Qt.ApplicationShortcut + onActivated: { + if (currentPage === "reader" && readerPage?.pageView) { + readerPage.pageView.handleScrollDown(); + } + } + } + Shortcut { + sequence: "PgUp" + context: Qt.ApplicationShortcut + onActivated: { + if (currentPage === "reader" && readerPage?.pageView) { + readerPage.pageView.handlePageUp(); + } + } + } + Shortcut { + sequence: "PgDown" + context: Qt.ApplicationShortcut + onActivated: { + if (currentPage === "reader" && readerPage?.pageView) { + readerPage.pageView.handlePageDown(); + } + } + } + // Fallback shortcuts using alternative key names + Shortcut { + sequence: "Prior" + context: Qt.ApplicationShortcut + onActivated: { + if (currentPage === "reader" && readerPage?.pageView) { + readerPage.pageView.handlePageUp(); + } + } + } + Shortcut { + sequence: "Next" + context: Qt.ApplicationShortcut + onActivated: { + if (currentPage === "reader" && readerPage?.pageView) { + readerPage.pageView.handlePageDown(); + } + } + } + Shortcut { + sequence: "Space" + context: Qt.ApplicationShortcut + onActivated: { + if (currentPage === "reader" && readerPage) { + readerPage.pageView.handlePageDown(); + } + } + } Connections { target: bookController diff --git a/src/qml/components/PageView.qml b/src/qml/components/PageView.qml index 9650215..4e71b4e 100644 --- a/src/qml/components/PageView.qml +++ b/src/qml/components/PageView.qml @@ -5,8 +5,32 @@ import Asteria Rectangle { focus: true - Keys.onLeftPressed: readingModel.previousChapter() - Keys.onRightPressed: readingModel.nextChapter() + // Public methods for global keyboard navigation + function handlePageUp() { + var scrollAmount = chunkListView.height * 0.95; + chunkListView.contentY = Math.max(0, chunkListView.contentY - scrollAmount); + } + + function handlePageDown() { + var scrollAmount = chunkListView.height * 0.95; + var maxY = Math.max(0, chunkListView.contentHeight - chunkListView.height); + chunkListView.contentY = Math.min(maxY, chunkListView.contentY + scrollAmount); + } + + function handleScrollUp() { + // Scroll up by approximately 2-3 lines + var lineHeight = appState.fontSize * appState.lineSpacing; + var scrollAmount = lineHeight * 3; // ~2-3 lines + chunkListView.contentY = Math.max(0, chunkListView.contentY - scrollAmount); + } + + function handleScrollDown() { + // Scroll down by approximately 2-3 lines + var lineHeight = appState.fontSize * appState.lineSpacing; + var scrollAmount = lineHeight * 3; // ~2-3 lines + var maxY = Math.max(0, chunkListView.contentHeight - chunkListView.height); + chunkListView.contentY = Math.min(maxY, chunkListView.contentY + scrollAmount); + } gradient: Gradient { GradientStop { position: 0.0; color: Theme.gradientTop } diff --git a/src/qml/pages/ReaderPage.qml b/src/qml/pages/ReaderPage.qml index bb11147..7be3711 100644 --- a/src/qml/pages/ReaderPage.qml +++ b/src/qml/pages/ReaderPage.qml @@ -1,7 +1,13 @@ import QtQuick import Asteria -PageView { - anchors.fill: parent - focus: visible +Item { + id: readerPage + property alias pageView: internalPageView + + PageView { + id: internalPageView + anchors.fill: parent + focus: visible + } }