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 {
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)
}
}
}
}

View file

@ -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 {