Keyboard working everywhere

This commit is contained in:
Jeena 2015-02-08 23:46:46 +01:00
parent 6ffdd51bf0
commit 9279db22f5
2 changed files with 49 additions and 8 deletions

View file

@ -10,6 +10,8 @@ import TTRSS 1.0
ScrollView { ScrollView {
id: content id: content
property Post post property Post post
property ApplicationWindow app
property int headLinefontSize: 23 property int headLinefontSize: 23
property int textfontSize: 14 property int textfontSize: 14
property int scrollJump: 48 property int scrollJump: 48
@ -20,12 +22,30 @@ ScrollView {
transientScrollBars: true 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 } Label { id: fontLabel }
WebView { WebView {
id: webView id: webView
url: "content.html" url: "content.html"
// experimental.transparentBackground: true
// Enable communication between QML and WebKit
experimental.preferences.navigatorQtObjectEnabled: true;
property Post post: content.post property Post post: content.post
@ -41,8 +61,6 @@ ScrollView {
experimental.evaluateJavaScript("document.body.style.fontSize = '" + fontLabel.font.pointSize + "pt';"); experimental.evaluateJavaScript("document.body.style.fontSize = '" + fontLabel.font.pointSize + "pt';");
} }
// Enable communication between QML and WebKit
experimental.preferences.navigatorQtObjectEnabled: true;
onNavigationRequested: { onNavigationRequested: {
if (request.navigationType != WebView.LinkClickedNavigation) { if (request.navigationType != WebView.LinkClickedNavigation) {
@ -60,6 +78,25 @@ ScrollView {
} }
onPostChanged: setPost() 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)
}
}
} }
} }

View file

@ -4,9 +4,8 @@ import QtQuick.Layouts 1.1
import TTRSS 1.0 import TTRSS 1.0
ApplicationWindow { ApplicationWindow {
id: window id: app
title: "FeedMonkey" title: "FeedMonkey"
visible: true visible: true
contentItem.minimumWidth: 640 contentItem.minimumWidth: 640
@ -14,6 +13,10 @@ ApplicationWindow {
contentItem.implicitWidth: 1024 contentItem.implicitWidth: 1024
contentItem.implicitHeight: 800 contentItem.implicitHeight: 800
property Server server: server
property Sidebar sidebar: sidebar
property Content content: content
menuBar: TheMenuBar { menuBar: TheMenuBar {
id: menu id: menu
server: server server: server
@ -34,8 +37,8 @@ ApplicationWindow {
Sidebar { Sidebar {
id: sidebar id: sidebar
server: server
content: content content: content
server: server
Layout.minimumWidth: 200 Layout.minimumWidth: 200
implicitWidth: 300 implicitWidth: 300
@ -43,6 +46,7 @@ ApplicationWindow {
Content { Content {
id: content id: content
app: app
Layout.minimumWidth: 200 Layout.minimumWidth: 200
implicitWidth: 624 implicitWidth: 624
@ -50,7 +54,7 @@ ApplicationWindow {
Keys.onRightPressed: sidebar.next() Keys.onRightPressed: sidebar.next()
Keys.onLeftPressed: sidebar.previous() Keys.onLeftPressed: sidebar.previous()
/*
Keys.onDownPressed: content.scrollDown(content.scrollJump) Keys.onDownPressed: content.scrollDown(content.scrollJump)
Keys.onUpPressed: content.scrollUp(content.scrollJump) Keys.onUpPressed: content.scrollUp(content.scrollJump)
Keys.onSpacePressed: content.scrollDown(content.pageJump) Keys.onSpacePressed: content.scrollDown(content.pageJump)
@ -66,7 +70,7 @@ ApplicationWindow {
} else if (event.key === Qt.Key_PageDown) { } else if (event.key === Qt.Key_PageDown) {
content.scrollDown(content.pageJump) content.scrollDown(content.pageJump)
} }
}*/ }
} }
Login { Login {