From df326b81ddcafb45467c9e1e434c09e8b12a6baa Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 13 Jul 2016 01:02:21 +0200 Subject: Prepared WebEngine port and resize according to content --- components/package/contents/ui/ContentView.qml | 53 ++++------------------ components/package/contents/ui/MailListView.qml | 4 ++ components/package/contents/ui/MailViewer.qml | 7 +-- components/package/contents/ui/MessagePartTree.qml | 11 +++-- components/package/contents/ui/TextView.qml | 15 ++++++ components/package/contents/ui/WebView.qml | 50 ++++++++++++++++++++ 6 files changed, 90 insertions(+), 50 deletions(-) create mode 100644 components/package/contents/ui/TextView.qml create mode 100644 components/package/contents/ui/WebView.qml (limited to 'components/package') 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 @@ import QtQuick 2.4 import QtQuick.Controls 1.3 -import QtWebKit 3.0 Item { id: root @@ -8,7 +7,8 @@ Item { property bool isHtml; property string content; property string contentType; - height: contentRect.height + property int contentWidth: contentLoader.item.contentWidth + property int contentHeight: contentLoader.item.contentHeight Rectangle { id: contentRect @@ -17,61 +17,26 @@ Item { // border.color: "black" // radius: 5 // anchors.leftMargin: nestingLevel * 5 - - height: contentLoader.height - width: root.width + anchors.fill: parent Loader { id: contentLoader - anchors.top: contentRect.top - anchors.left: contentRect.left - width: contentRect.width + property string content: root.content + anchors.fill: parent sourceComponent: isHtml ? htmlComponent : textComponent - height: isHtml ? item.flickableItem.contentHeight : text.height - onStatusChanged: { - if (isHtml) { - item.flickableItem.loadHtml(root.content, "file:///"); - } - } } Component { id: textComponent - Text { - id: text - text: content + TextView { + content: root.content } } Component { id: htmlComponent - //We need the scrollview so the WebView can fully expand so we have access to the contentHeight - //Otherwise it would just scale the content. - ScrollView { - horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff - verticalScrollBarPolicy: Qt.ScrollBarAlwaysOff - WebView { - id: htmlView - onNavigationRequested: { - // detect URL scheme prefix, most likely an external link - var schemaRE = /^\w+:/; - if (schemaRE.test(request.url)) { - request.action = WebView.AcceptRequest; - } else { - request.action = WebView.IgnoreRequest; - // delegate request.url here - } - } - onLoadingChanged: { - console.warn("Error is ", loadRequest.errorString); - console.warn("Status is ", loadRequest.status); - } - } + WebView { + content: root.content } } } - onContentChanged: { - if (isHtml) { - contentLoader.item.flickableItem.loadHtml(content, "file:///"); - } - } } diff --git a/components/package/contents/ui/MailListView.qml b/components/package/contents/ui/MailListView.qml index bc292705..d0278833 100644 --- a/components/package/contents/ui/MailListView.qml +++ b/components/package/contents/ui/MailListView.qml @@ -31,6 +31,10 @@ Controls.ScrollView { property variant currentMail property bool isDraft : false + onParentFolderChanged: { + currentMail = null + } + ListView { id: listView diff --git a/components/package/contents/ui/MailViewer.qml b/components/package/contents/ui/MailViewer.qml index d62daaf2..53808ddd 100644 --- a/components/package/contents/ui/MailViewer.qml +++ b/components/package/contents/ui/MailViewer.qml @@ -26,12 +26,13 @@ Item { spacing:2 MessagePartTree { id: topPartLoader - width: rootRectangle.width - height: topPartLoader.desiredHeight + // width: rootRectangle.width + height: topPartLoader.contentHeight + width: topPartLoader.contentWidth >= rootRectangle.width ? topPartLoader.contentWidth : rootRectangle.width } TreeView { visible: enablePartTreeView - width: 500 + width: rootRectangle.width height: 400 TableViewColumn { role: "type" diff --git a/components/package/contents/ui/MessagePartTree.qml b/components/package/contents/ui/MessagePartTree.qml index d44a1e5e..8bc13e6e 100644 --- a/components/package/contents/ui/MessagePartTree.qml +++ b/components/package/contents/ui/MessagePartTree.qml @@ -5,7 +5,8 @@ Item { id: root property alias rootIndex: visualModel.rootIndex property int nestingLevel: 0 - property int desiredHeight: messagePartRect.height + property int contentHeight: messagePartRect.height + property int contentWidth: 0 Rectangle { id: messagePartRect height: partListView.contentHeight @@ -24,6 +25,7 @@ Item { anchors.top: delegateRect.top anchors.left: delegateRect.left width: messagePartRect.width + height: contentHeight content: model.text isHtml: model.isHtml visible: model.hasContent @@ -33,16 +35,19 @@ Item { height = 0 } } + onContentWidthChanged: { + root.contentWidth = contentWidth > root.contentWidth ? contentWidth : root.contentWidth + } contentType: model.type } Loader { id: partLoader anchors.top: contentView.bottom anchors.left: contentView.left - width: messagePartRect.width visible: model.hasModelChildren active: model.hasModelChildren - height: item ? item.desiredHeight : 0 + height: item ? item.contentHeight : 0 + width: messagePartRect.width } Component.onCompleted: { if (model.hasModelChildren) { diff --git a/components/package/contents/ui/TextView.qml b/components/package/contents/ui/TextView.qml new file mode 100644 index 00000000..7c2f3153 --- /dev/null +++ b/components/package/contents/ui/TextView.qml @@ -0,0 +1,15 @@ +import QtQuick 2.4 +import QtQuick.Controls 1.3 + +Item { + id: root + property string content; + property int contentWidth: 0; + property int contentHeight: textView.contentHeight; + Text { + id: textView + wrapMode: Text.WordWrap + anchors.fill: parent + text: content + } +} diff --git a/components/package/contents/ui/WebView.qml b/components/package/contents/ui/WebView.qml new file mode 100644 index 00000000..fe3a8bcd --- /dev/null +++ b/components/package/contents/ui/WebView.qml @@ -0,0 +1,50 @@ +import QtQuick 2.4 +import QtQuick.Controls 1.3 +import QtWebKit 3.0 +// import QtWebEngine 1.3 //This would give use contentsSize +// import QtWebEngine 1.2 + +Item { + id: root + property string content; + // property int contentWidth: 500; + // property int contentHeight: 500; + property int contentWidth: htmlView.contentWidth; + property int contentHeight: htmlView.contentHeight; + // width: htmlView.width + // height: htmlView.height + WebView { + id: htmlView + anchors.top: parent.top + anchors.horizontalCenter: parent.horizontalCenter + width: contentWidth + height: contentHeight + onNavigationRequested: { + // detect URL scheme prefix, most likely an external link + var schemaRE = /^\w+:/; + if (schemaRE.test(request.url)) { + request.action = WebView.AcceptRequest; + } else { + request.action = WebView.IgnoreRequest; + // delegate request.url here + } + } + onLoadingChanged: { + console.warn("Error is ", loadRequest.errorString); + console.warn("Status is ", loadRequest.status); + } + Component.onCompleted: loadHtml(content, "file:///") + } + // WebEngineView { + // id: htmlView + // anchors.fill: parent + // onLoadingChanged: { + // console.warn("Error is ", loadRequest.errorString); + // console.warn("Status is ", loadRequest.status); + // } + // Component.onCompleted: loadHtml(content, "file:///") + // } + onContentChanged: { + htmlView.loadHtml(content, "file:///"); + } +} -- cgit v1.2.3