Licensing GPLv3
[quicknewsreader] / qml / QuickNewsReader / content / view / CategoryDelegate.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
24     width: delegate.ListView.view.width; height: 60
25
26     Text {
27         text: name
28         color: delegate.ListView.isCurrentItem ? "white" : "black"
29         font { family: "Helvetica"; pixelSize: 16; bold: true }
30         anchors {
31             left: parent.left; leftMargin: 15
32             verticalCenter: parent.verticalCenter
33         }
34     }
35
36     BusyIndicator {
37         scale: 0.6
38         on: delegate.ListView.isCurrentItem && window.loading
39         anchors { right: parent.right; rightMargin: 10; verticalCenter: parent.verticalCenter }
40     }
41
42     Rectangle {
43         width: delegate.width; height: 1; color: "#cccccc"
44         anchors.bottom: delegate.bottom
45         visible: delegate.ListView.isCurrentItem ? false : true
46     }
47     Rectangle {
48         width: delegate.width; height: 1; color: "white"
49         visible: delegate.ListView.isCurrentItem ? false : true
50     }
51
52     MouseArea {
53         anchors.fill: delegate
54         onClicked: {
55             var currentSourceDepth = delegate.ListView.view.model.sourceDepth
56
57             if (listSourceModel[window.currentSourceIndex].listViews.length >= currentSourceDepth+1)
58             {
59                 // here we remove everything in viewsModel after index "nextSourceDepth"
60                 while(window.windowViewsModel.count>currentSourceDepth+1)
61                     window.windowViewsModel.remove(window.windowViewsModel.count-1)
62
63                 delegate.ListView.view.currentIndex = index
64                 var path = listSourceModel[window.currentSourceIndex].currentPath
65                 path[currentSourceDepth] = index
66                 listSourceModel[window.currentSourceIndex].currentPath = path.slice(0,currentSourceDepth+1)
67
68                 window.windowViewsModel.append({ component: listSourceModel[window.currentSourceIndex].listViews[currentSourceDepth].viewComponent,
69                                                  componentDepth: currentSourceDepth+1 })
70             }
71         }
72     }
73 }