first working showing post

This commit is contained in:
Jeena 2015-01-30 17:36:51 +01:00
parent 0405a8ba39
commit cc59671ff4
6 changed files with 22 additions and 7 deletions

View file

@ -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;

View file

@ -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
}
}
}

View file

@ -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;

View file

@ -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: {

View file

@ -1,5 +1,6 @@
#include "post.h"
#include <QDebug>
#include <QJsonDocument>
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()

3
post.h
View file

@ -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