1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
/*
license GPL v3 ...........
description of this file:
a page for viewing a user selected RSS feed ;
Architecture:
page
{
ToolbarActions
Rectangle
{
label(RSS feed title)
}
ListView
{
}
Component(delegate)
XmlListModel(rss feed)
}
*/
import QtQuick 2.0
import QtQuick.XmlListModel 2.0
import Ubuntu.Components 0.1
import Ubuntu.Components.ListItems 0.1 as ListItem
Page {
id: page_feed
// width: 100
// height: 62
property string rssmodel_url: ""
property string rsstitle: ""
property int rss_index: 0
onRss_indexChanged:
{
rss_listview.currentIndex = rss_index
}
tools: ToolbarActions {
Action {
text: "action 1"
iconSource: Qt.resolvedUrl("avatar.png")
}
Action {
text: "action 2"
iconSource: Qt.resolvedUrl("avatar.png")
}
}
// Rectangle
// {
// id: bg
// anchors.fill: parent
// color: "white"
// }
////////////////////////////////////////////// shows the RSS feed title
Rectangle
{
id: rec_title
width: parent.width
height: label_title.height + units.gu(1)
color: "orange"
Label
{
id: label_title
anchors.centerIn: parent
width: parent.width - units.gu(2)
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
text: rsstitle
color: "white"
}
}
////////////////////////////////////////////// a listview to show the RSS content
ListView
{
id: rss_listview
width: parent.width
anchors.bottom: parent.bottom
anchors.bottomMargin: units.gu(1)
anchors.top: rec_title.bottom
anchors.topMargin: units.gu(2)
snapMode: ListView.SnapOneItem
// height: isList ? 0 : units.gu(30)
// opacity: isList ? 0 : 1
cacheBuffer: 90
// spacing: units.gu(2)
boundsBehavior: Flickable.StopAtBounds
orientation: ListView.Horizontal
// currentIndex: rss_index
contentHeight: parent.width * count
model: rssmodel
delegate: xmldelegate
}
////////////////////////////////////////////// delegate for ListView
Component
{
id: xmldelegate
Column
{
spacing: units.gu(2)
width: rss_listview.width
height: rss_listview.height
Label
{
fontSize: "large"
text: model_title
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width - units.gu(2)
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
color: "black"
}
Label
{
text:
{
if (description.split("</a>").length > 1)
return description.split("</a>")[1].split("</p>")[0] ;
else
return description ;
}
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width - units.gu(1)
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
color: "black"
MouseArea
{
anchors.fill: parent
onClicked:
{
console.log("current index : " + index) ;
}
}
}
}
// RssItemDelegate
// {
// width: units.gu(30)
// height: rss_listview.height
// rss_title: title
// rss_description:
// {
// if (description.split("</a>").length > 1)
// return description.split("</a>")[1].split("</p>")[0] ;
// else
// return description ;
// }
// }
}
////////////////////////////////////////////////// RSS xml model
XmlListModel
{
id: rssmodel
source: rssmodel_url
query: "/rss/channel/item"
XmlRole { name: "model_title"; query: "title/string()" }
XmlRole { name: "description"; query: "description/string()" }
}
}
|