295b4406224b80f46d16f1c46cca76be7647108d
[quicknewsreader] / qml / QuickNewsReader / content / view / NewsDetail.qml
1 import QtQuick 1.0
2 //import QtWebKit 1.0
3
4 Item {
5     id: newsDetailRect
6     width: window.width; height: window.height
7
8     function getNewsModelItem(prop)
9     {
10         if( typeof currentSource.listModels[componentDepth-1] != "undefined" )
11             if( typeof currentSource.listModels[componentDepth-1][prop] != "undefined" )
12                 return currentSource.listModels[componentDepth-1][prop]
13
14         return ""
15     }
16
17     property string urllink: getNewsModelItem('urllink')
18     property string htmlcontent: getNewsModelItem('htmlcontent')
19     property string title: getNewsModelItem('title')
20     property string image: getNewsModelItem('image')
21
22     VisualItemModel {
23         id: itemModel
24
25         Item {
26             x: 0; y: 0
27             width: newsDetailRect.width
28             height: column.height + 10
29
30             Column {
31                 id: column
32                 x: 10; y: 10
33                 width: parent.width - 20
34
35                 Row {
36                     spacing: 5
37
38                     Image {
39                         id: detailImage
40                         source: image
41                     }
42
43                     Text {
44                         anchors.verticalCenter: detailImage.verticalCenter
45                         text: title; width: column.width - detailImage.width - 10; wrapMode: Text.WordWrap
46                         font { bold: true; family: "Helvetica"; pointSize: 16 }
47                     }
48                 }
49
50                 Text {
51                     id: detailText
52                     text: htmlcontent; width: newsDetailRect.width - 20; wrapMode: Text.WordWrap
53                     horizontalAlignment: Text.AlignJustify;
54                     font.family: "Helvetica"
55                 }
56             }
57
58             MouseArea {
59                 anchors.fill: column
60
61                 onClicked: {
62                     var currentSourceDepth = currentSource.listModels[componentDepth-1].sourceDepth
63
64                     if (listSourceModel[window.currentSourceIndex].listViews.length >= currentSourceDepth+1)
65                     {
66                         // here we remove everything in viewsModel after index "currentSourceDepth"
67                         while(window.windowViewsModel.count>currentSourceDepth+1)
68                             window.windowViewsModel.remove(window.windowViewsModel.count-1)
69
70                         var path = listSourceModel[window.currentSourceIndex].currentPath
71                         path[currentSourceDepth] = index
72                         listSourceModel[window.currentSourceIndex].currentPath = path.slice(0,currentSourceDepth+1)
73
74                         window.windowViewsModel.append({ component: listSourceModel[window.currentSourceIndex].listViews[currentSourceDepth].viewComponent,
75                                                          componentDepth: currentSourceDepth+1 })
76                     }
77                 }
78             }
79         }
80     }
81     ListView {
82         id: itemListView
83         anchors.fill: newsDetailRect
84         model: itemModel
85     }
86     ScrollBar { scrollArea: itemListView; height: itemListView.height; width: 8; anchors.right: itemListView.right }
87 }