Upgrade from Webkit to WebEngine
This commit is contained in:
parent
81bac3ec8d
commit
c6c41c799f
6 changed files with 23 additions and 28 deletions
|
@ -1,5 +1,4 @@
|
|||
import QtWebKit 3.0
|
||||
import QtWebKit.experimental 1.0
|
||||
import QtWebEngine 1.0
|
||||
import QtQuick 2.0
|
||||
import QtQuick.Controls 1.3
|
||||
import QtQuick.Layouts 1.1
|
||||
|
@ -7,7 +6,7 @@ import QtQuick.Controls.Styles 1.3
|
|||
import QtQuick.Controls 1.3
|
||||
import TTRSS 1.0
|
||||
|
||||
ScrollView {
|
||||
Item {
|
||||
id: content
|
||||
property Post post
|
||||
property ApplicationWindow app
|
||||
|
@ -18,23 +17,19 @@ ScrollView {
|
|||
Layout.minimumWidth: 400
|
||||
onTextFontSizeChanged: webView.setDefaults()
|
||||
|
||||
style: ScrollViewStyle {
|
||||
transientScrollBars: true
|
||||
}
|
||||
|
||||
function scrollDown(jump) {
|
||||
if(!jump) {
|
||||
webView.experimental.evaluateJavaScript("window.scrollTo(0, document.body.scrollHeight - " + height + ");")
|
||||
webView.runJavaScript("window.scrollTo(0, document.body.scrollHeight - " + height + ");")
|
||||
} else {
|
||||
webView.experimental.evaluateJavaScript("window.scrollBy(0, " + jump + ");")
|
||||
webView.runJavaScript("window.scrollBy(0, " + jump + ");")
|
||||
}
|
||||
}
|
||||
|
||||
function scrollUp(jump) {
|
||||
if(!jump) {
|
||||
webView.experimental.evaluateJavaScript("window.scrollTo(0, 0);")
|
||||
webView.runJavaScript("window.scrollTo(0, 0);")
|
||||
} else {
|
||||
webView.experimental.evaluateJavaScript("window.scrollBy(0, -" + jump + ");")
|
||||
webView.runJavaScript("window.scrollBy(0, -" + jump + ");")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,41 +39,39 @@ ScrollView {
|
|||
|
||||
Label { id: fontLabel }
|
||||
|
||||
WebView {
|
||||
WebEngineView {
|
||||
id: webView
|
||||
anchors.fill: parent
|
||||
url: "../html/content.html"
|
||||
|
||||
// Enable communication between QML and WebKit
|
||||
experimental.preferences.navigatorQtObjectEnabled: true;
|
||||
|
||||
property Post post: content.post
|
||||
|
||||
function setPost() {
|
||||
if(post) {
|
||||
experimental.evaluateJavaScript("setArticle(" + post.jsonString + ")")
|
||||
runJavaScript("setArticle(" + post.jsonString + ")")
|
||||
} else {
|
||||
experimental.evaluateJavaScript("setArticle('logout')")
|
||||
runJavaScript("setArticle('logout')")
|
||||
}
|
||||
}
|
||||
|
||||
function setDefaults() {
|
||||
// font name needs to be enclosed in single quotes
|
||||
experimental.evaluateJavaScript("document.body.style.fontFamily = \"'" + fontLabel.font.family + "'\";");
|
||||
experimental.evaluateJavaScript("document.body.style.fontSize = '" + content.textFontSize + "pt';");
|
||||
runJavaScript("document.body.style.fontFamily = \"'" + fontLabel.font.family + "'\";");
|
||||
runJavaScript("document.body.style.fontSize = '" + content.textFontSize + "pt';");
|
||||
}
|
||||
|
||||
|
||||
onNavigationRequested: {
|
||||
if (request.navigationType != WebView.LinkClickedNavigation) {
|
||||
request.action = WebView.AcceptRequest;
|
||||
if (request.navigationType != WebEngineView.LinkClickedNavigation) {
|
||||
request.action = WebEngineView.AcceptRequest;
|
||||
} else {
|
||||
request.action = WebView.IgnoreRequest;
|
||||
request.action = WebEngineView.IgnoreRequest;
|
||||
Qt.openUrlExternally(request.url);
|
||||
}
|
||||
}
|
||||
|
||||
onLoadingChanged: {
|
||||
if(loadRequest.status === WebView.LoadSucceededStatus) {
|
||||
if(!loading) {
|
||||
setPost()
|
||||
setDefaults()
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ ScrollView {
|
|||
}
|
||||
|
||||
item.content.post = server.posts[currentIndex]
|
||||
content.flickableItem.contentY = 0
|
||||
//content.flickableItem.contentY = 0
|
||||
|
||||
previousPost = item.content.post
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue