diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-04-29 16:58:09 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-04-29 16:58:09 +0200 |
commit | 21f7851f044cd8b6e38c821ce12d7e1b291cae27 (patch) | |
tree | fac2a5229e29ec99b4ad10fbafe3d83a850b132a /components/package/contents/ui/ContentView.qml | |
parent | 23d8c802eb2c0e60224a019c69d253c222010be9 (diff) | |
download | kube-21f7851f044cd8b6e38c821ce12d7e1b291cae27.tar.gz kube-21f7851f044cd8b6e38c821ce12d7e1b291cae27.zip |
Push missing files
Diffstat (limited to 'components/package/contents/ui/ContentView.qml')
-rw-r--r-- | components/package/contents/ui/ContentView.qml | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/components/package/contents/ui/ContentView.qml b/components/package/contents/ui/ContentView.qml new file mode 100644 index 00000000..d4ddabce --- /dev/null +++ b/components/package/contents/ui/ContentView.qml | |||
@@ -0,0 +1,77 @@ | |||
1 | import QtQuick 2.4 | ||
2 | import QtQuick.Controls 1.3 | ||
3 | import QtWebKit 3.0 | ||
4 | |||
5 | Item { | ||
6 | id: root | ||
7 | property int nestingLevel; | ||
8 | property bool isHtml; | ||
9 | property string content; | ||
10 | property string contentType; | ||
11 | height: contentRect.height | ||
12 | Rectangle { | ||
13 | id: contentRect | ||
14 | |||
15 | //Only for development | ||
16 | // border.width: 1 | ||
17 | // border.color: "black" | ||
18 | // radius: 5 | ||
19 | // anchors.leftMargin: nestingLevel * 5 | ||
20 | |||
21 | height: contentLoader.height | ||
22 | width: root.width | ||
23 | |||
24 | Loader { | ||
25 | id: contentLoader | ||
26 | anchors.top: contentRect.top | ||
27 | anchors.left: contentRect.left | ||
28 | width: contentRect.width | ||
29 | sourceComponent: isHtml ? htmlComponent : textComponent | ||
30 | height: isHtml ? item.flickableItem.contentHeight : text.height | ||
31 | onStatusChanged: { | ||
32 | if (isHtml) { | ||
33 | item.flickableItem.loadHtml(root.content, "file:///"); | ||
34 | } | ||
35 | } | ||
36 | } | ||
37 | |||
38 | Component { | ||
39 | id: textComponent | ||
40 | Text { | ||
41 | id: text | ||
42 | text: content | ||
43 | } | ||
44 | } | ||
45 | Component { | ||
46 | id: htmlComponent | ||
47 | //We need the scrollview so the WebView can fully expand so we have access to the contentHeight | ||
48 | //Otherwise it would just scale the content. | ||
49 | ScrollView { | ||
50 | horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff | ||
51 | verticalScrollBarPolicy: Qt.ScrollBarAlwaysOff | ||
52 | WebView { | ||
53 | id: htmlView | ||
54 | onNavigationRequested: { | ||
55 | // detect URL scheme prefix, most likely an external link | ||
56 | var schemaRE = /^\w+:/; | ||
57 | if (schemaRE.test(request.url)) { | ||
58 | request.action = WebView.AcceptRequest; | ||
59 | } else { | ||
60 | request.action = WebView.IgnoreRequest; | ||
61 | // delegate request.url here | ||
62 | } | ||
63 | } | ||
64 | onLoadingChanged: { | ||
65 | console.warn("Error is ", loadRequest.errorString); | ||
66 | console.warn("Status is ", loadRequest.status); | ||
67 | } | ||
68 | } | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | onContentChanged: { | ||
73 | if (isHtml) { | ||
74 | contentLoader.item.flickableItem.loadHtml(content, "file:///"); | ||
75 | } | ||
76 | } | ||
77 | } | ||