-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathArticleViewPage.qml
63 lines (54 loc) · 2.09 KB
/
ArticleViewPage.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import QtQuick 2.2
import com.canonical.Oxide 1.0 as Oxide
import Ubuntu.Components 1.1
import Ubuntu.Components.Themes 0.1
Page {
visible: false
// This will need to be specified when the page is instantiated
property ListModel articleModel
// The specified index is retrieved from the model and displayed
// when this property's value is changed
property int articleIndex: -1
onArticleIndexChanged: {
// Obtain the article from the model
var article = articleModel.get(articleIndex);
// Set the title to that of the article
title = article.title;
// TODO: Oxide exposes a lot of this stuff, so we may not
// need all of the CSS injection.
// Build the long string of HTML (eek!) and insert it into the WebView
articleBody.loadHtml(
'<!DOCTYPE html>' +
'<html>' +
'<head>' +
'<meta charset="utf-8">' +
'<meta name="viewport" content="width=' + articleBody.width + '">' +
'<style>' +
'body {' +
'background-color: ' + Theme.palette.normal.background + ';' +
'color: ' + Theme.palette.selected.backgroundText + ';' +
'font-family: "Ubuntu Light";' +
'font-size: ' + FontUtils.sizeToPixels('medium') + 'px;' +
'font-weight: 100;' +
'}' +
'code, pre { white-space: pre-wrap; word-wrap: break-word; }' +
'img { display: block; margin: auto; max-width: 100%; }' +
'p { text-align: justify; }' +
'</style>' +
'</head>' +
'<body>' +
article.body +
'</body>' +
'</html>'
);
}
Oxide.WebView {
id: articleBody
anchors.fill: parent
// Ignore any navigation and instead open the browser
onNavigationRequested: {
request.action = Oxide.NavigationRequest.ActionReject;
Qt.openUrlExternally(request.url);
}
}
}