diff options
-rw-r--r-- | components/package/contents/ui/ContentView.qml | 77 | ||||
-rw-r--r-- | components/package/contents/ui/MessagePartTree.qml | 66 |
2 files changed, 143 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 | } | ||
diff --git a/components/package/contents/ui/MessagePartTree.qml b/components/package/contents/ui/MessagePartTree.qml new file mode 100644 index 00000000..9a08b356 --- /dev/null +++ b/components/package/contents/ui/MessagePartTree.qml | |||
@@ -0,0 +1,66 @@ | |||
1 | import QtQuick 2.4 | ||
2 | import QtQuick.Controls 1.3 | ||
3 | |||
4 | Item { | ||
5 | id: root | ||
6 | property alias rootIndex: visualModel.rootIndex | ||
7 | property int nestingLevel: 0 | ||
8 | property int desiredHeight: messagePartRect.height | ||
9 | Rectangle { | ||
10 | id: messagePartRect | ||
11 | height: partListView.contentHeight | ||
12 | width: root.width | ||
13 | VisualDataModel { | ||
14 | id: visualModel | ||
15 | model: messageParser.partTree | ||
16 | delegate: Rectangle { | ||
17 | id: delegateRect | ||
18 | // visible: !model.isAttachment | ||
19 | width: childrenRect.width | ||
20 | height: childrenRect.height | ||
21 | // color: Qt.rgba(Math.random(),Math.random(),Math.random(),1) | ||
22 | ContentView { | ||
23 | id: contentView | ||
24 | anchors.top: delegateRect.top | ||
25 | anchors.left: delegateRect.left | ||
26 | width: messagePartRect.width | ||
27 | content: model.text | ||
28 | isHtml: model.isHtml | ||
29 | visible: model.hasContent | ||
30 | onVisibleChanged: { | ||
31 | //Resize to 0 if it is not visible so the partLoader has the right offset | ||
32 | if (!visible) { | ||
33 | height = 0 | ||
34 | } | ||
35 | } | ||
36 | contentType: model.type | ||
37 | } | ||
38 | Loader { | ||
39 | id: partLoader | ||
40 | anchors.top: contentView.bottom | ||
41 | anchors.left: contentView.left | ||
42 | width: messagePartRect.width | ||
43 | visible: model.hasModelChildren | ||
44 | active: model.hasModelChildren | ||
45 | height: item ? item.desiredHeight : 0 | ||
46 | } | ||
47 | Component.onCompleted: { | ||
48 | if (model.hasModelChildren) { | ||
49 | partLoader.source = "MessagePartTree.qml" | ||
50 | partLoader.item.rootIndex = visualModel.modelIndex(index) | ||
51 | partLoader.item.nestingLevel = root.nestingLevel + 1 | ||
52 | } | ||
53 | } | ||
54 | } | ||
55 | } | ||
56 | |||
57 | ListView { | ||
58 | id: partListView | ||
59 | model: visualModel | ||
60 | anchors.left: parent.left | ||
61 | anchors.top: parent.top | ||
62 | anchors.right: parent.right | ||
63 | height: parent.height | ||
64 | } | ||
65 | } | ||
66 | } | ||