first working showing post
This commit is contained in:
parent
0405a8ba39
commit
cc59671ff4
6 changed files with 22 additions and 7 deletions
|
@ -1,8 +1,12 @@
|
||||||
import QtWebKit 3.0
|
import QtWebKit 3.0
|
||||||
|
import QtWebKit.experimental 1.0
|
||||||
|
|
||||||
WebView {
|
WebView {
|
||||||
id: webview
|
|
||||||
url: "content.html"
|
url: "content.html"
|
||||||
|
|
||||||
|
// Enable communication between QML and WebKit
|
||||||
|
experimental.preferences.navigatorQtObjectEnabled: true;
|
||||||
|
|
||||||
onNavigationRequested: {
|
onNavigationRequested: {
|
||||||
if (request.navigationType != WebView.LinkClickedNavigation) {
|
if (request.navigationType != WebView.LinkClickedNavigation) {
|
||||||
request.action = WebView.AcceptRequest;
|
request.action = WebView.AcceptRequest;
|
||||||
|
|
|
@ -4,7 +4,7 @@ Item {
|
||||||
property ListView listView
|
property ListView listView
|
||||||
|
|
||||||
height: column.height + 10
|
height: column.height + 10
|
||||||
width: listView.parent.width
|
width: parent.parent.parent.width
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
@ -16,6 +16,7 @@ Item {
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
id: column
|
id: column
|
||||||
|
width: parent.width
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
spacing: 10
|
spacing: 10
|
||||||
|
@ -51,7 +52,7 @@ Item {
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked: {
|
onClicked: {
|
||||||
listView.currentIndex = index
|
parent.parent.parent.currentIndex = index
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
body {
|
body {
|
||||||
font-family: "Ubuntu", "Lucida Grande", "Tahoma", sans-serif;
|
font-family: "Ubuntu", "Lucida Grande", "Tahoma", sans-serif;
|
||||||
padding: 1em 2em 1em 2em;
|
padding: 1em 2em 1em 2em;
|
||||||
background: red;
|
font-size: 1.6em;
|
||||||
}
|
}
|
||||||
body.darwin {
|
body.darwin {
|
||||||
font-family: "LucidaGrande", sans-serif;
|
font-family: "LucidaGrande", sans-serif;
|
||||||
|
|
8
main.qml
8
main.qml
|
@ -34,10 +34,14 @@ ApplicationWindow {
|
||||||
opacity: 0.5
|
opacity: 0.5
|
||||||
}
|
}
|
||||||
focus: true
|
focus: true
|
||||||
|
onCurrentItemChanged: {
|
||||||
|
content.experimental.evaluateJavaScript("setArticle(" + server.posts[currentIndex].jsonString + ")")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Content {
|
Content {
|
||||||
|
id: content
|
||||||
Layout.minimumWidth: 50
|
Layout.minimumWidth: 50
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
}
|
}
|
||||||
|
@ -64,9 +68,7 @@ ApplicationWindow {
|
||||||
|
|
||||||
Component {
|
Component {
|
||||||
id: delegate
|
id: delegate
|
||||||
PostListItem {
|
PostListItem {}
|
||||||
listView: listView
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
|
|
5
post.cpp
5
post.cpp
|
@ -1,5 +1,6 @@
|
||||||
#include "post.h"
|
#include "post.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
|
||||||
Post::Post(QObject *parent) : QObject(parent)
|
Post::Post(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
|
@ -22,6 +23,10 @@ Post::Post(QJsonObject post, QObject *parent) : QObject(parent)
|
||||||
mExcerpt = post.value("excerpt").toString().trimmed();
|
mExcerpt = post.value("excerpt").toString().trimmed();
|
||||||
mStarred = post.value("marked").toBool();
|
mStarred = post.value("marked").toBool();
|
||||||
mRead = !post.value("unread").toBool();
|
mRead = !post.value("unread").toBool();
|
||||||
|
|
||||||
|
QJsonDocument doc(post);
|
||||||
|
QString result(doc.toJson(QJsonDocument::Indented));
|
||||||
|
mJsonString = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Post::~Post()
|
Post::~Post()
|
||||||
|
|
3
post.h
3
post.h
|
@ -20,6 +20,7 @@ class Post : public QObject
|
||||||
Q_PROPERTY(QString excerpt READ excerpt CONSTANT)
|
Q_PROPERTY(QString excerpt READ excerpt CONSTANT)
|
||||||
Q_PROPERTY(bool starred READ starred NOTIFY starredChanged)
|
Q_PROPERTY(bool starred READ starred NOTIFY starredChanged)
|
||||||
Q_PROPERTY(bool read READ read NOTIFY readChanged)
|
Q_PROPERTY(bool read READ read NOTIFY readChanged)
|
||||||
|
Q_PROPERTY(QString jsonString READ jsonString CONSTANT)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Post(QObject *parent = 0);
|
Post(QObject *parent = 0);
|
||||||
|
@ -36,6 +37,7 @@ public:
|
||||||
QString excerpt() const { return mExcerpt; }
|
QString excerpt() const { return mExcerpt; }
|
||||||
bool starred() const { return mStarred; }
|
bool starred() const { return mStarred; }
|
||||||
bool read() const { return mRead; }
|
bool read() const { return mRead; }
|
||||||
|
QString jsonString() const { return mJsonString; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void starredChanged(bool);
|
void starredChanged(bool);
|
||||||
|
@ -55,6 +57,7 @@ private:
|
||||||
QString mExcerpt;
|
QString mExcerpt;
|
||||||
bool mStarred;
|
bool mStarred;
|
||||||
bool mRead;
|
bool mRead;
|
||||||
|
QString mJsonString;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // POST_H
|
#endif // POST_H
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue