diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-07-13 01:02:21 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-07-14 01:23:10 +0200 |
commit | df326b81ddcafb45467c9e1e434c09e8b12a6baa (patch) | |
tree | 3b005fa68a3504f0b7454a4e1a8ef56c0dd7b9dd | |
parent | 1213815b42e94f41817b79fc9e311742a330d9ae (diff) | |
download | kube-df326b81ddcafb45467c9e1e434c09e8b12a6baa.tar.gz kube-df326b81ddcafb45467c9e1e434c09e8b12a6baa.zip |
Prepared WebEngine port and resize according to content
-rw-r--r-- | applications/mail/CMakeLists.txt | 6 | ||||
-rw-r--r-- | applications/mail/main.cpp | 2 | ||||
-rw-r--r-- | components/package/contents/ui/ContentView.qml | 53 | ||||
-rw-r--r-- | components/package/contents/ui/MailListView.qml | 4 | ||||
-rw-r--r-- | components/package/contents/ui/MailViewer.qml | 7 | ||||
-rw-r--r-- | components/package/contents/ui/MessagePartTree.qml | 11 | ||||
-rw-r--r-- | components/package/contents/ui/TextView.qml | 15 | ||||
-rw-r--r-- | components/package/contents/ui/WebView.qml | 50 |
8 files changed, 95 insertions, 53 deletions
diff --git a/applications/mail/CMakeLists.txt b/applications/mail/CMakeLists.txt index 97e418b6..7c6fe755 100644 --- a/applications/mail/CMakeLists.txt +++ b/applications/mail/CMakeLists.txt | |||
@@ -18,14 +18,14 @@ include(KDEInstallDirs) | |||
18 | include(KDECMakeSettings) | 18 | include(KDECMakeSettings) |
19 | include(KDECompilerSettings) | 19 | include(KDECompilerSettings) |
20 | 20 | ||
21 | find_package(Qt5 REQUIRED NO_MODULE COMPONENTS Core Quick Test Gui Widgets) | 21 | find_package(Qt5 REQUIRED NO_MODULE COMPONENTS Core Quick Test Gui Widgets WebEngine) |
22 | 22 | ||
23 | set (QT_MIN_VERSION "5.4.0") | 23 | set (QT_MIN_VERSION "5.6.0") |
24 | find_package(KF5 REQUIRED COMPONENTS Package) | 24 | find_package(KF5 REQUIRED COMPONENTS Package) |
25 | 25 | ||
26 | # install executable | 26 | # install executable |
27 | add_executable(${PROJECT_NAME} main.cpp) | 27 | add_executable(${PROJECT_NAME} main.cpp) |
28 | qt5_use_modules(${PROJECT_NAME} Gui Quick Widgets) | 28 | qt5_use_modules(${PROJECT_NAME} Gui Quick Widgets WebEngine) |
29 | target_link_libraries(${PROJECT_NAME} KF5::Package) | 29 | target_link_libraries(${PROJECT_NAME} KF5::Package) |
30 | 30 | ||
31 | install(TARGETS ${PROJECT_NAME} DESTINATION bin) | 31 | install(TARGETS ${PROJECT_NAME} DESTINATION bin) |
diff --git a/applications/mail/main.cpp b/applications/mail/main.cpp index 26353aa4..cb5350a2 100644 --- a/applications/mail/main.cpp +++ b/applications/mail/main.cpp | |||
@@ -5,6 +5,7 @@ | |||
5 | #include <KPackage/PackageLoader> | 5 | #include <KPackage/PackageLoader> |
6 | #include <QQuickImageProvider> | 6 | #include <QQuickImageProvider> |
7 | #include <QIcon> | 7 | #include <QIcon> |
8 | #include <QtWebEngine> | ||
8 | 9 | ||
9 | #include <QDebug> | 10 | #include <QDebug> |
10 | 11 | ||
@@ -34,6 +35,7 @@ public: | |||
34 | int main(int argc, char *argv[]) | 35 | int main(int argc, char *argv[]) |
35 | { | 36 | { |
36 | QApplication app(argc, argv); | 37 | QApplication app(argc, argv); |
38 | QtWebEngine::initialize(); | ||
37 | auto package = KPackage::PackageLoader::self()->loadPackage("KPackage/GenericQML", "org.kube.components.mail"); | 39 | auto package = KPackage::PackageLoader::self()->loadPackage("KPackage/GenericQML", "org.kube.components.mail"); |
38 | Q_ASSERT(package.isValid()); | 40 | Q_ASSERT(package.isValid()); |
39 | QQmlApplicationEngine engine; | 41 | QQmlApplicationEngine engine; |
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 | } |
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 { | |||
31 | property variant currentMail | 31 | property variant currentMail |
32 | property bool isDraft : false | 32 | property bool isDraft : false |
33 | 33 | ||
34 | onParentFolderChanged: { | ||
35 | currentMail = null | ||
36 | } | ||
37 | |||
34 | ListView { | 38 | ListView { |
35 | id: listView | 39 | id: listView |
36 | 40 | ||
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 { | |||
26 | spacing:2 | 26 | spacing:2 |
27 | MessagePartTree { | 27 | MessagePartTree { |
28 | id: topPartLoader | 28 | id: topPartLoader |
29 | width: rootRectangle.width | 29 | // width: rootRectangle.width |
30 | height: topPartLoader.desiredHeight | 30 | height: topPartLoader.contentHeight |
31 | width: topPartLoader.contentWidth >= rootRectangle.width ? topPartLoader.contentWidth : rootRectangle.width | ||
31 | } | 32 | } |
32 | TreeView { | 33 | TreeView { |
33 | visible: enablePartTreeView | 34 | visible: enablePartTreeView |
34 | width: 500 | 35 | width: rootRectangle.width |
35 | height: 400 | 36 | height: 400 |
36 | TableViewColumn { | 37 | TableViewColumn { |
37 | role: "type" | 38 | 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 { | |||
5 | id: root | 5 | id: root |
6 | property alias rootIndex: visualModel.rootIndex | 6 | property alias rootIndex: visualModel.rootIndex |
7 | property int nestingLevel: 0 | 7 | property int nestingLevel: 0 |
8 | property int desiredHeight: messagePartRect.height | 8 | property int contentHeight: messagePartRect.height |
9 | property int contentWidth: 0 | ||
9 | Rectangle { | 10 | Rectangle { |
10 | id: messagePartRect | 11 | id: messagePartRect |
11 | height: partListView.contentHeight | 12 | height: partListView.contentHeight |
@@ -24,6 +25,7 @@ Item { | |||
24 | anchors.top: delegateRect.top | 25 | anchors.top: delegateRect.top |
25 | anchors.left: delegateRect.left | 26 | anchors.left: delegateRect.left |
26 | width: messagePartRect.width | 27 | width: messagePartRect.width |
28 | height: contentHeight | ||
27 | content: model.text | 29 | content: model.text |
28 | isHtml: model.isHtml | 30 | isHtml: model.isHtml |
29 | visible: model.hasContent | 31 | visible: model.hasContent |
@@ -33,16 +35,19 @@ Item { | |||
33 | height = 0 | 35 | height = 0 |
34 | } | 36 | } |
35 | } | 37 | } |
38 | onContentWidthChanged: { | ||
39 | root.contentWidth = contentWidth > root.contentWidth ? contentWidth : root.contentWidth | ||
40 | } | ||
36 | contentType: model.type | 41 | contentType: model.type |
37 | } | 42 | } |
38 | Loader { | 43 | Loader { |
39 | id: partLoader | 44 | id: partLoader |
40 | anchors.top: contentView.bottom | 45 | anchors.top: contentView.bottom |
41 | anchors.left: contentView.left | 46 | anchors.left: contentView.left |
42 | width: messagePartRect.width | ||
43 | visible: model.hasModelChildren | 47 | visible: model.hasModelChildren |
44 | active: model.hasModelChildren | 48 | active: model.hasModelChildren |
45 | height: item ? item.desiredHeight : 0 | 49 | height: item ? item.contentHeight : 0 |
50 | width: messagePartRect.width | ||
46 | } | 51 | } |
47 | Component.onCompleted: { | 52 | Component.onCompleted: { |
48 | if (model.hasModelChildren) { | 53 | 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 @@ | |||
1 | import QtQuick 2.4 | ||
2 | import QtQuick.Controls 1.3 | ||
3 | |||
4 | Item { | ||
5 | id: root | ||
6 | property string content; | ||
7 | property int contentWidth: 0; | ||
8 | property int contentHeight: textView.contentHeight; | ||
9 | Text { | ||
10 | id: textView | ||
11 | wrapMode: Text.WordWrap | ||
12 | anchors.fill: parent | ||
13 | text: content | ||
14 | } | ||
15 | } | ||
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 @@ | |||
1 | import QtQuick 2.4 | ||
2 | import QtQuick.Controls 1.3 | ||
3 | import QtWebKit 3.0 | ||
4 | // import QtWebEngine 1.3 //This would give use contentsSize | ||
5 | // import QtWebEngine 1.2 | ||
6 | |||
7 | Item { | ||
8 | id: root | ||
9 | property string content; | ||
10 | // property int contentWidth: 500; | ||
11 | // property int contentHeight: 500; | ||
12 | property int contentWidth: htmlView.contentWidth; | ||
13 | property int contentHeight: htmlView.contentHeight; | ||
14 | // width: htmlView.width | ||
15 | // height: htmlView.height | ||
16 | WebView { | ||
17 | id: htmlView | ||
18 | anchors.top: parent.top | ||
19 | anchors.horizontalCenter: parent.horizontalCenter | ||
20 | width: contentWidth | ||
21 | height: contentHeight | ||
22 | onNavigationRequested: { | ||
23 | // detect URL scheme prefix, most likely an external link | ||
24 | var schemaRE = /^\w+:/; | ||
25 | if (schemaRE.test(request.url)) { | ||
26 | request.action = WebView.AcceptRequest; | ||
27 | } else { | ||
28 | request.action = WebView.IgnoreRequest; | ||
29 | // delegate request.url here | ||
30 | } | ||
31 | } | ||
32 | onLoadingChanged: { | ||
33 | console.warn("Error is ", loadRequest.errorString); | ||
34 | console.warn("Status is ", loadRequest.status); | ||
35 | } | ||
36 | Component.onCompleted: loadHtml(content, "file:///") | ||
37 | } | ||
38 | // WebEngineView { | ||
39 | // id: htmlView | ||
40 | // anchors.fill: parent | ||
41 | // onLoadingChanged: { | ||
42 | // console.warn("Error is ", loadRequest.errorString); | ||
43 | // console.warn("Status is ", loadRequest.status); | ||
44 | // } | ||
45 | // Component.onCompleted: loadHtml(content, "file:///") | ||
46 | // } | ||
47 | onContentChanged: { | ||
48 | htmlView.loadHtml(content, "file:///"); | ||
49 | } | ||
50 | } | ||