diff options
Diffstat (limited to 'components/package/contents/ui/ContentView.qml')
-rw-r--r-- | components/package/contents/ui/ContentView.qml | 53 |
1 files changed, 9 insertions, 44 deletions
diff --git a/components/package/contents/ui/ContentView.qml b/components/package/contents/ui/ContentView.qml index d4ddabce..a8f4c437 100644 --- a/components/package/contents/ui/ContentView.qml +++ b/components/package/contents/ui/ContentView.qml | |||
@@ -1,6 +1,5 @@ | |||
1 | import QtQuick 2.4 | 1 | import QtQuick 2.4 |
2 | import QtQuick.Controls 1.3 | 2 | import QtQuick.Controls 1.3 |
3 | import QtWebKit 3.0 | ||
4 | 3 | ||
5 | Item { | 4 | Item { |
6 | id: root | 5 | id: root |
@@ -8,7 +7,8 @@ Item { | |||
8 | property bool isHtml; | 7 | property bool isHtml; |
9 | property string content; | 8 | property string content; |
10 | property string contentType; | 9 | property string contentType; |
11 | height: contentRect.height | 10 | property int contentWidth: contentLoader.item.contentWidth |
11 | property int contentHeight: contentLoader.item.contentHeight | ||
12 | Rectangle { | 12 | Rectangle { |
13 | id: contentRect | 13 | id: contentRect |
14 | 14 | ||
@@ -17,61 +17,26 @@ Item { | |||
17 | // border.color: "black" | 17 | // border.color: "black" |
18 | // radius: 5 | 18 | // radius: 5 |
19 | // anchors.leftMargin: nestingLevel * 5 | 19 | // anchors.leftMargin: nestingLevel * 5 |
20 | 20 | anchors.fill: parent | |
21 | height: contentLoader.height | ||
22 | width: root.width | ||
23 | 21 | ||
24 | Loader { | 22 | Loader { |
25 | id: contentLoader | 23 | id: contentLoader |
26 | anchors.top: contentRect.top | 24 | property string content: root.content |
27 | anchors.left: contentRect.left | 25 | anchors.fill: parent |
28 | width: contentRect.width | ||
29 | sourceComponent: isHtml ? htmlComponent : textComponent | 26 | 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 | } | 27 | } |
37 | 28 | ||
38 | Component { | 29 | Component { |
39 | id: textComponent | 30 | id: textComponent |
40 | Text { | 31 | TextView { |
41 | id: text | 32 | content: root.content |
42 | text: content | ||
43 | } | 33 | } |
44 | } | 34 | } |
45 | Component { | 35 | Component { |
46 | id: htmlComponent | 36 | id: htmlComponent |
47 | //We need the scrollview so the WebView can fully expand so we have access to the contentHeight | 37 | WebView { |
48 | //Otherwise it would just scale the content. | 38 | content: root.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 | } | 39 | } |
70 | } | 40 | } |
71 | } | 41 | } |
72 | onContentChanged: { | ||
73 | if (isHtml) { | ||
74 | contentLoader.item.flickableItem.loadHtml(content, "file:///"); | ||
75 | } | ||
76 | } | ||
77 | } | 42 | } |