From 9279db22f59fee750b8b0c393b7f1ee12cb155de Mon Sep 17 00:00:00 2001 From: Jeena Date: Sun, 8 Feb 2015 23:46:46 +0100 Subject: [PATCH] Keyboard working everywhere --- Content.qml | 43 ++++++++++++++++++++++++++++++++++++++++--- main.qml | 14 +++++++++----- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/Content.qml b/Content.qml index e7fd2f1..c751788 100644 --- a/Content.qml +++ b/Content.qml @@ -10,6 +10,8 @@ import TTRSS 1.0 ScrollView { id: content property Post post + property ApplicationWindow app + property int headLinefontSize: 23 property int textfontSize: 14 property int scrollJump: 48 @@ -20,12 +22,30 @@ ScrollView { transientScrollBars: true } + function scrollDown(jump) { + if(!jump) { + webView.experimental.evaluateJavaScript("window.scrollTo(0, document.body.scrollHeight - " + height + ");") + } else { + webView.experimental.evaluateJavaScript("window.scrollBy(0, " + jump + ");") + } + } + + function scrollUp(jump) { + if(!jump) { + webView.experimental.evaluateJavaScript("window.scrollTo(0, 0);") + } else { + webView.experimental.evaluateJavaScript("window.scrollBy(0, -" + jump + ");") + } + } + Label { id: fontLabel } WebView { id: webView url: "content.html" - // experimental.transparentBackground: true + + // Enable communication between QML and WebKit + experimental.preferences.navigatorQtObjectEnabled: true; property Post post: content.post @@ -41,8 +61,6 @@ ScrollView { experimental.evaluateJavaScript("document.body.style.fontSize = '" + fontLabel.font.pointSize + "pt';"); } - // Enable communication between QML and WebKit - experimental.preferences.navigatorQtObjectEnabled: true; onNavigationRequested: { if (request.navigationType != WebView.LinkClickedNavigation) { @@ -60,6 +78,25 @@ ScrollView { } onPostChanged: setPost() + + Keys.onRightPressed: app.sidebar.next() + Keys.onLeftPressed: app.sidebar.previous() + Keys.onDownPressed: content.scrollDown(content.scrollJump) + Keys.onUpPressed: content.scrollUp(content.scrollJump) + Keys.onSpacePressed: content.scrollDown(content.pageJump) + Keys.onEnterPressed: Qt.openUrlExternally(content.post.link) + Keys.onReturnPressed: Qt.openUrlExternally(content.post.link) + Keys.onPressed: { + if(event.key === Qt.Key_Home) { + content.scrollUp(); + } else if (event.key === Qt.Key_End) { + content.scrollDown(); + } else if (event.key === Qt.Key_PageUp) { + content.scrollUp(content.pageJump) + } else if (event.key === Qt.Key_PageDown) { + content.scrollDown(content.pageJump) + } + } } } diff --git a/main.qml b/main.qml index 38ed668..cb10350 100644 --- a/main.qml +++ b/main.qml @@ -4,9 +4,8 @@ import QtQuick.Layouts 1.1 import TTRSS 1.0 ApplicationWindow { - id: window + id: app title: "FeedMonkey" - visible: true contentItem.minimumWidth: 640 @@ -14,6 +13,10 @@ ApplicationWindow { contentItem.implicitWidth: 1024 contentItem.implicitHeight: 800 + property Server server: server + property Sidebar sidebar: sidebar + property Content content: content + menuBar: TheMenuBar { id: menu server: server @@ -34,8 +37,8 @@ ApplicationWindow { Sidebar { id: sidebar - server: server content: content + server: server Layout.minimumWidth: 200 implicitWidth: 300 @@ -43,6 +46,7 @@ ApplicationWindow { Content { id: content + app: app Layout.minimumWidth: 200 implicitWidth: 624 @@ -50,7 +54,7 @@ ApplicationWindow { Keys.onRightPressed: sidebar.next() Keys.onLeftPressed: sidebar.previous() - /* + Keys.onDownPressed: content.scrollDown(content.scrollJump) Keys.onUpPressed: content.scrollUp(content.scrollJump) Keys.onSpacePressed: content.scrollDown(content.pageJump) @@ -66,7 +70,7 @@ ApplicationWindow { } else if (event.key === Qt.Key_PageDown) { content.scrollDown(content.pageJump) } - }*/ + } } Login {