Readability integration - first draft
[quicknewsreader] / qml / QuickNewsReader / content / view / NewsDelegate.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
21 Item {
22     id: delegate
23     height: column.height + 40
24     width: delegate.ListView.view.width
25
26     Column {
27         id: column
28         x: 10; y: 10
29         width: parent.width - 20
30
31         Text {
32             id: titleText
33             text: title; width: column.width; wrapMode: Text.WordWrap
34             font { bold: true; family: "Helvetica"; pointSize: 16 }
35         }
36
37
38         Row {
39             id: descriptionRow
40             spacing: 5
41
42             Image {
43                 id: detailImage
44                 source: (typeof image != "undefined") ? image: ""
45             }
46
47             Text {
48                 anchors.verticalCenter: descriptionRow.verticalCenter
49                 text: description; width: column.width - detailImage.width - 10; wrapMode: Text.WordWrap
50                 font.family: "Helvetica"
51             }
52         }
53     }
54
55     MouseArea {
56         anchors.fill: delegate
57
58         onClicked: {
59             var currentSourceDepth = delegate.ListView.view.model.sourceDepth
60
61             if (listSourceModel[window.currentSourceIndex].listViews.length >= currentSourceDepth+1)
62             {
63                 // here we remove everything in viewsModel after index "nextSourceDepth"
64                 while(window.windowViewsModel.count>currentSourceDepth+1)
65                     window.windowViewsModel.remove(window.windowViewsModel.count-1)
66
67                 delegate.ListView.view.currentIndex = index
68                 var path = listSourceModel[window.currentSourceIndex].currentPath
69                 path[currentSourceDepth] = index
70                 listSourceModel[window.currentSourceIndex].currentPath = path.slice(0,currentSourceDepth+1)
71
72                 window.windowViewsModel.append({ component: listSourceModel[window.currentSourceIndex].listViews[currentSourceDepth].viewComponent,
73                                                  componentDepth: currentSourceDepth+1 })
74             }
75         }
76     }
77
78     Rectangle {
79         width: parent.width; height: 1; color: "#cccccc"
80         anchors.bottom: parent.bottom
81     }
82 }