diff --git a/Content.qml b/Content.qml index b26a350..637ea42 100644 --- a/Content.qml +++ b/Content.qml @@ -1,8 +1,12 @@ import QtWebKit 3.0 +import QtWebKit.experimental 1.0 WebView { - id: webview url: "content.html" + + // Enable communication between QML and WebKit + experimental.preferences.navigatorQtObjectEnabled: true; + onNavigationRequested: { if (request.navigationType != WebView.LinkClickedNavigation) { request.action = WebView.AcceptRequest; diff --git a/PostListItem.qml b/PostListItem.qml index d781d4a..63b3aed 100644 --- a/PostListItem.qml +++ b/PostListItem.qml @@ -4,7 +4,7 @@ Item { property ListView listView height: column.height + 10 - width: listView.parent.width + width: parent.parent.parent.width Rectangle { anchors.fill: parent @@ -16,6 +16,7 @@ Item { Column { id: column + width: parent.width Row { spacing: 10 @@ -51,7 +52,7 @@ Item { MouseArea { anchors.fill: parent onClicked: { - listView.currentIndex = index + parent.parent.parent.currentIndex = index } } } diff --git a/content.css b/content.css index 4c9a560..3643b4f 100644 --- a/content.css +++ b/content.css @@ -1,7 +1,7 @@ body { font-family: "Ubuntu", "Lucida Grande", "Tahoma", sans-serif; padding: 1em 2em 1em 2em; - background: red; + font-size: 1.6em; } body.darwin { font-family: "LucidaGrande", sans-serif; diff --git a/main.qml b/main.qml index 74fe353..608028d 100644 --- a/main.qml +++ b/main.qml @@ -34,10 +34,14 @@ ApplicationWindow { opacity: 0.5 } focus: true + onCurrentItemChanged: { + content.experimental.evaluateJavaScript("setArticle(" + server.posts[currentIndex].jsonString + ")") + } } } Content { + id: content Layout.minimumWidth: 50 Layout.fillWidth: true } @@ -64,9 +68,7 @@ ApplicationWindow { Component { id: delegate - PostListItem { - listView: listView - } + PostListItem {} } Component.onCompleted: { diff --git a/post.cpp b/post.cpp index cb6ac15..49617e8 100644 --- a/post.cpp +++ b/post.cpp @@ -1,5 +1,6 @@ #include "post.h" #include +#include Post::Post(QObject *parent) : QObject(parent) { @@ -22,6 +23,10 @@ Post::Post(QJsonObject post, QObject *parent) : QObject(parent) mExcerpt = post.value("excerpt").toString().trimmed(); mStarred = post.value("marked").toBool(); mRead = !post.value("unread").toBool(); + + QJsonDocument doc(post); + QString result(doc.toJson(QJsonDocument::Indented)); + mJsonString = result; } Post::~Post() diff --git a/post.h b/post.h index a759487..0a88f27 100644 --- a/post.h +++ b/post.h @@ -20,6 +20,7 @@ class Post : public QObject Q_PROPERTY(QString excerpt READ excerpt CONSTANT) Q_PROPERTY(bool starred READ starred NOTIFY starredChanged) Q_PROPERTY(bool read READ read NOTIFY readChanged) + Q_PROPERTY(QString jsonString READ jsonString CONSTANT) public: Post(QObject *parent = 0); @@ -36,6 +37,7 @@ public: QString excerpt() const { return mExcerpt; } bool starred() const { return mStarred; } bool read() const { return mRead; } + QString jsonString() const { return mJsonString; } signals: void starredChanged(bool); @@ -55,6 +57,7 @@ private: QString mExcerpt; bool mStarred; bool mRead; + QString mJsonString; }; #endif // POST_H