Readability integration - first draft
[quicknewsreader] / qml / QuickNewsReader / content / view / NewsDetail.qml
1 /***
2 ** Copyright (C) 2012 Christophe CHAPUIS <chris.chapuis _at_ gmail _dot_ com>
3 **
4 ** This package is free software; you can redistribute it and/or modify
5 ** it under the terms of the GNU General Public License as published by
6 ** the Free Software Foundation; either version 2 of the License, or
7 ** (at your option) any later version.
8 **
9 ** This package is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 ** GNU General Public License for more details.
13 **
14 ** You should have received a copy of the GNU General Public License
15 ** along with this package; if not, write to the Free Software
16 ** Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
17 **
18 ***/
19 import QtQuick 1.0
20 //import QtWebKit 1.0
21
22 Item {
23     id: newsDetailRect
24     width: window.width; height: window.height
25
26     function getNewsModelItem(prop)
27     {
28         if( typeof currentSource.listModels[componentDepth-1] != "undefined" )
29             if( typeof currentSource.listModels[componentDepth-1][prop] != "undefined" )
30                 return currentSource.listModels[componentDepth-1][prop]
31
32         return ""
33     }
34
35     property string urllink: getNewsModelItem('urllink')
36     property string htmlcontent: getNewsModelItem('htmlcontent')
37     property string title: getNewsModelItem('title')
38     property string image: getNewsModelItem('image')
39
40     VisualItemModel {
41         id: itemModel
42
43         Item {
44             x: 0; y: 0
45             width: newsDetailRect.width
46             height: column.height + 10
47
48             Column {
49                 id: column
50                 x: 10; y: 10
51                 width: parent.width - 20
52
53                 Row {
54                     spacing: 5
55
56                     Image {
57                         id: detailImage
58                         source: image
59                     }
60
61                     Text {
62                         anchors.verticalCenter: detailImage.verticalCenter
63                         text: title; width: column.width - detailImage.width - 10; wrapMode: Text.WordWrap
64                         font { bold: true; family: "Helvetica"; pointSize: 16 }
65                     }
66                 }
67
68                 Text {
69                     id: detailText
70                     text: htmlcontent; width: newsDetailRect.width - 20; wrapMode: Text.WordWrap
71                     horizontalAlignment: Text.AlignJustify;
72                     font.family: "Helvetica"
73                 }
74             }
75
76             MouseArea {
77                 anchors.fill: column
78
79                 onClicked: {
80                     var currentSourceDepth = currentSource.listModels[componentDepth-1].sourceDepth
81
82                     if (listSourceModel[window.currentSourceIndex].listViews.length >= currentSourceDepth+1)
83                     {
84                         // here we remove everything in viewsModel after index "currentSourceDepth"
85                         while(window.windowViewsModel.count>currentSourceDepth+1)
86                             window.windowViewsModel.remove(window.windowViewsModel.count-1)
87
88                         var path = listSourceModel[window.currentSourceIndex].currentPath
89                         path[currentSourceDepth] = index
90                         listSourceModel[window.currentSourceIndex].currentPath = path.slice(0,currentSourceDepth+1)
91
92                         window.windowViewsModel.append({ component: listSourceModel[window.currentSourceIndex].listViews[currentSourceDepth].viewComponent,
93                                                          componentDepth: currentSourceDepth+1 })
94                     }
95                 }
96             }
97         }
98     }
99     ListView {
100         id: itemListView
101         anchors.fill: newsDetailRect
102         model: itemModel
103     }
104     ScrollBar { scrollArea: itemListView; height: itemListView.height; width: 8; anchors.right: itemListView.right }
105 }